2

After installing SUPEE 7405 my custom theme Sidebar Cart stopped deleting products. When delete button is clicked, throws an error: "Cannot remove the product". Looks like I need to add Form Key to the sidebar cart delete button code. Located in the custom theme. I think form key should look like this:

form_key/<?php echo $formKey = Mage::getSingleton('core/session')->getFormKey();?>

/frontend/CUSTOMTHEME/default/template/checkout/cart/sidebar/default.phtml

<a href="<?php
        $params = $this->getRequest()->getParams();
        if($params['isAjax'] == 1){
            $refererUrl = Mage::registry('referrer_url');
            if (empty($refererUrl)) {
                $refererUrl = Mage::getBaseUrl();
            }
            $deleteUrl = $this->getUrl(
                'checkout/cart/delete',
                array(
                    'id'=>$_item->getId(),
                    Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl($refererUrl)
                )
            );
        }else{
            $deleteUrl = $this->getDeleteUrl();
        }
        echo $deleteUrl; 
    ?>" title="<?php echo $this->__('Remove This Item') ?>" onclick="return confirm('<?php echo $this->__('Are you sure you would like to remove this item from the shopping cart?') ?>');" class="btn-remove"><?php echo $this->__('Remove This Item') ?></a>

Please help me out adding the form key. Many thanks in advance!

1 Answer 1

1

You are right. And this is how you do it:

Replace

$deleteUrl = $this->getUrl(
    'checkout/cart/delete',
    array(
        'id'=>$_item->getId(),
        Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl($refererUrl)
    )
);

with

$deleteUrl = $this->getUrl(
    'checkout/cart/delete',
    array(
        'id'=>$_item->getId(),
        Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl($refererUrl),
        Mage_Core_Model_Url::FORM_KEY => Mage::getSingleton('core/session')->getFormKey()
    )
);
5
  • Thank you for help, I've replaced the code as you've mentioned however the Ajax cart no longer adds any products to the cart. In other words, when I click "Add Product", the Ajax pop-up box is stuck at loading/adding product, but no product is added. I really appreciate your help!
    – Icon
    Mar 10, 2016 at 17:21
  • Ah, Magento 1.7 doesn't have the Mage_Core_Model_Url::FORM_KEY constant yet, replace that with the literal string 'form_key' Mar 10, 2016 at 19:14
  • To confirm, the line should look like this?: 'form_key' => Mage::getSingleton('core/session')->getFormKey()
    – Icon
    Mar 10, 2016 at 19:22
  • yes, cnofirmed. Mar 10, 2016 at 19:29
  • Great solution, works perfectly, MANY THANKS!
    – Icon
    Mar 14, 2016 at 17:31

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.