0

I am currently developing Magento 1.9 (yes I know it's outdated) and they have requested remove from cart buttons on the category page (list.phtml), however, I cannot seem to find a way to add the button.

I have successfully added the button to the page, but can't seem to get the actual like to be correct with the correct data, I believe this to be because I cannot match the quote id to the product id correctly, however it also seems that this gives a much shorter form key than what is normally used by Magento.

$productid = $_product->getId();
<a href="<?php echo $this->getUrl('checkout/cart/delete', array('id' => $productid, Mage_Core_Model_Url::FORM_KEY => $this->_getSingletonModel('core/session')->getFormKey())); ?>">X</a>

Any help would be much appreciated

0

This could help you.

Override below file

/app/design/frontend/rwd/default/template/catalog/product/list.phtml

Put below code in **<ul class="add-to-links">**

<?php
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
    $productName = $item->getProduct()->getName();
    if($productName  ==  $_product->getName()){ ?>
        <a href="<?= $this->getBaseUrl().'custommodule/index/deleteItem/id/'.$item->getId() ?>" class="link-wishlist"><?php echo $this->__('Remove form cart') ?></a>
    <?php   }
} ?>

Now in your custom controller place this function:

public function deleteItemAction() {
    $cartItemId = $this->getRequest()->getParam('id');
    $cartHelper = Mage::helper('checkout/cart');
    $cartHelper->getCart()->removeItem($cartItemId)->save();
    $this->_redirectReferer(); 
}

I have tested it's working properly.

  • Thank you very much this worked perfectly. – Mage Noob Jul 2 at 11:08
  • Welcome, Please mark as right answer and also upvote if it helps you. :) – Ravi Soni Jul 2 at 11:11

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.