Skip to content

Instantly share code, notes, and snippets.

@petarBozovic
Last active January 14, 2019 15:58
Show Gist options
  • Save petarBozovic/543935a5e51cf9fd1360bed6b481eb1a to your computer and use it in GitHub Desktop.
Save petarBozovic/543935a5e51cf9fd1360bed6b481eb1a to your computer and use it in GitHub Desktop.
Remove Product from Cart (Magento 1.9)
<?php
public function removeFromCart($productId){
$cart = Mage::helper('checkout/cart');
$items = $cart->getCart()->getItems();
foreach ($items as $item)
{
if ($item->getProductId() == $productId) {
$itemId = $item->getItemId();
$cart->getCart()->removeItem($itemId);
$item->isDeleted(true);
$cart->getQuote()->setTotalsCollectedFlag(null)->collectTotals()->save();
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment