Obtenez la quantité de produit dans le panier pour chaque produit [fermé]
-
12-12-2019 - |
Question
$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();
}
La solution
Vaibhav, veuillez utiliser getAllVisibleItems
plutôt getAllItems
pour obtenir aucune quantité d'article du panier, vous devez utiliser 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
}
Pour obtenir current product qty
, vous devez charger product model by sku
alors prends inventory
à partir d'un objet en 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>";
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange