My add to cart url returns this. When i click it the products doesn't get added because it's invalid. This happens in the homepage.


In url "/uenc/aHR0cDovL2xvY2FsaG9zdC9tYWdlL2luZGV4LnBocC9wYWNrYWdlcy9wYWNrYWdlL2luZGV4Lw,,/" =>',,' causing issue.

First in my code it was using $this->getAddToCartUrl($_product) because of this issue i replaced it with this Mage::helper('checkout/cart')->getAddUrl($_product) Still the problem exists.

I clear cache but not working. Anyone have idea?

  • Please check form key exist – Sunil Patel Nov 13 '17 at 20:53

First, create the product, then pass this product object to the checkout/cart helper to get the add to cart url.

$product=Mage::getModel('catalog/product')->load($productId);//load the product by product id
$product=Mage::getModel('catalog/product')->loadByAttribute('sku',$skuNum);//or load the product by sku number
$product=Mage::getModel('catalog/product')->setStoreId($storeId)->loadByAttribute('sku',$skuNum);//or load the product from a given store id

echo Mage::helper('checkout/cart')->getAddUrl($product);//Get the add to cart url

and second one is below

<?php echo Mage::getUrl('checkout/cart/add', array('product'=>$_product->getId(),'qty'=>1, 'form_key' => Mage::getSingleton('core/session')->getFormKey())) ?>
$collection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('email_sent',array('null' => true));

foreach ($collection as $key => $value) {
    $order = Mage::getModel("sales/order")->load($value->getEntityId());
    try {
        echo "Order successfully sentn";
    } catch (Exception $e) {
        echo $e->getMessage();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.