I\'ve just installed Magento Community Edition ver 1.8.0.0 (default settings).
System -> Configuration -> Sales -> Checkout -> Checkout Options
What I actually did in the end was compare the new changes with the old code and I discovered the add to cart button was set to type="button" and was not submitting.
Changing the button to simply type="submit" and no other changes actually made it work this is in [theme]/template/catalog/product/view/addtocart
may have to move from base folder if non-existent
This is how I am doing it in Magento 1.8.1
<a href="<?= $this->getAddtoCartUrl($_product, array('qty' => $_price['price_qty'])) ?>">
See http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Block_Product_Abstract.html#getAddToCartUrl
Use "Add To Cart" link for your product any where on a Magento website::
The following code may helpful:
$product = Mage::getModel('catalog/product')->load($YourProductID);
echo Mage::helper('checkout/cart')->getAddUrl($product);
From magento 1.8 need to add form key $formKey = Mage::getSingleton('core/session')->getFormKey();?>
to url
This works best for me in Magento C 1.8
<?php
$formKey = Mage::getSingleton('core/session')->getFormKey();?>
<form action="/checkout/cart/add/product/<?php echo $productid; ?>" method="post">
<input type="hidden" name="form_key" value="<?php echo $formKey; ?>" />
<input type="text" name="qty"> QTY
<input type="submit" value="Add to basket" />
</form>
What I did is to override the Magento CartController
with a custom module.
I created a file inside:
\app\code\local\Namespace\AddProductFromUrl\controllers\Checkout\CartController.php
<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class Namespace_AddProductFromUrl_Checkout_CartController extends Mage_Checkout_CartController {
# overloaded addAction
public function addAction() {
// generate form_key if missing or invalid
if (!($formKey = $this->getRequest()->getParam('form_key', null)) || $formKey != Mage::getSingleton('core/session')->getFormKey()) {
$this->getRequest()->setParams(array('form_key' =>Mage::getSingleton('core/session')->getFormKey()));
}
// do parent actions
parent::addAction();
}
}
?>
(The module need to have config.xml and enabled under etc/modules/
as for every magento custom module. Change Namespace
with the one you use.)
That works perfectly just like magento 1.7 and with minimal impact; the form_key
is generated if missing and that's it.
The following can be used with qty set:
$product = Mage::getModel('catalog/product')->load($getProductID);
echo Mage::helper('checkout/cart')->getAddUrl($product, array('qty'=>$getQty));