Ottieni quantità prodotto nel carrello per ogni singolo prodotto [chiuso]
-
12-12-2019 - |
Domanda
$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();
}
Soluzione
Vaibhav, per favore usa getAllVisibleItems
Invece getAllItems
per non ottenere alcuna quantità di un articolo nel carrello devi ottenere utilizzando 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
}
Per ottenere current product qty
, devi caricare product model by sku
allora prendi inventory
da oggetto in stock
$_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>";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange