Last active
January 14, 2019 15:58
-
-
Save petarBozovic/543935a5e51cf9fd1360bed6b481eb1a to your computer and use it in GitHub Desktop.
Remove Product from Cart (Magento 1.9)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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