How to get quantity of each product in cart magento 1.9
-
25-01-2021 - |
La solution 2
In this case, I use this code:
$sku = find_your_product_sku;
$sum =0;
$quote = Mage::helper('checkout/cart')->getCart()->getQuote();
foreach ($quote->getAllItems() as $item) {
$product = array (
'id' => $item->getSku(),
'quantity' => $item->getQty()
);
if ($product['id']==$sku) {
$sum += $product['quantity'];
}
}
Thanks Rohan and Pawan for helping me.
Autres conseils
You can get product quantity like this :
$quote = Mage::helper('checkout/cart')->getCart()->getQuote();
$product = [];
foreach ($quote->getAllItems() as $item) {
$product[]= array (
'id' => $item->getSku(),
'quantity' => $item->getQty()
);
}
$product_json = json_encode($product);
For get qty of specific product :
$quote = Mage::getSingleton('checkout/session')->getQuote();
$product = Mage::getModel('catalog/product')->load($product_id);
$_item = $quote->getItemByProduct($product);
$qty = $_item->getQty();
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange