I created a custom collection using below code.

        $catNum = 19; //The number of the category you want to load
        $category = Mage::getModel('catalog/category')->load($catNum);
        $products_best = Mage::getResourceModel('reports/product_collection')

        foreach ($products_best as $_product_best){
        $productt = Mage::getModel('catalog/product')->load($_product_best->getId());
            $urlll = Mage::helper('checkout/cart')->getAddUrl($productt);
            echo $_helper->productAttribute($_product_best, $_product_best->getName(), 'name')."<br>";

             echo $this->getPriceHtml($_product_best, true)."<br>";

             <img class="image" style="opacity: 1;" src="<?php echo $this->helper('catalog/image')->init($_product_best, 'small_image')->keepFrame(FALSE)->resize(336,157); ?>" 
                     alt="<?php echo $this->stripTags($this->getImageLabel($_product_best, 'small_image'), null, true) ?>"><br>
             <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $urlll; ?>')"><span><span><?php echo $this->__('Add to Carts') ?></span></span></button>

When i click add to cart button in the checkout page the message said that "product was added to your shopping cart" but below section there is nothing added to the card(shoppincart.png). How can i fix this issue.

enter image description here

1 Answer 1


try this

$key =  Mage::getSingleton('core/session')->getFormKey();

add key in url

onclick="setLocation('<?php echo Mage::getBaseUrl();?>checkout/cart/add/product/<?php echo $productt->getid();?>','form_key/<?php echo $key; ?>')" 
  • Thank you, This method not working.Once i add this code left side layered navigation is not working.
    – Mujahidh
    Commented Feb 2, 2016 at 10:36
  • update the answer try this it is working tested code.. Commented Feb 2, 2016 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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