Obtenga la cantidad de producto en el carrito para cada producto [cerrado]
-
12-12-2019 - |
Pregunta
$cart = Mage::getModel('checkout/cart')->getQuote();
$cartTotal =$cart->getGrandTotal();
$cartItems = $cart->getAllItems();
foreach ($cartItems as $item)
{
$_product = $item->getProduct();
$id=$_product->getId();
$qty = $_product->getQty(); //get product Qty
$image=$_product->getImageUrl();
}
Solución
Vaibhav, por favor usa getAllVisibleItems
en cambio getAllItems
para no obtener una cantidad de un artículo del carrito, debe usar getQty()
$cart = Mage::getModel('checkout/cart')->getQuote();
$cartTotal =$cart->getGrandTotal();
$cartItems = $cart->getAllVisibleItems();
foreach ($cartItems as $item)
{
$_product = $item->getProduct();
$id=$_product->getId();
$qty = $item->getQty(); //get item qty
}
por conseguir current product qty
, necesitas cargar product model by sku
entonces consigue inventory
del objeto común
$_producObject = Mage::getModel('catalog/product')->loadByAttribute('sku',$item->getSku());
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_producObject);
echo "<pre>";
print_r($stock->getData());
echo "</pre>";
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange