php - How to get stock for configured item in cart? -


with simple product can this:

$quote = mage::getsingleton('checkout/session')->getquote(); $item = $quote->getitembyid($params['item']); // $params['item'] contains item id $product = $item->getproduct(); $stockqty = (int)mage::getmodel('cataloginventory/stock_item')->loadbyproduct($product)->getqty(); 

however, if item configured product, tries stock of parent configurable product, in cases has inventory of zero.

how can stock quantity of configured product, preferably without looping through configurable parent's child products?

you can set variable determines stock status depending on stock status of children of configurable product:

$instock = true; $quote = mage::getsingleton('checkout/session')->getquote(); $cart = mage::getmodel('checkout/cart')->getquote();  $item = $quote->getitembyid($params['item']); // $params['item'] contains item id $_product = $item->getproduct(); $configuredproduct = mage::getmodel('catalog/product_type_configurable')->setproduct($_product); $children = $configuredproduct->getusedproductcollection()->addattributetoselect("*")->addfilterbyrequiredoptions(); foreach($children $simpleproduct) {     foreach ($cart->getallitems() $item) {         if ($item->getproduct()->getid() != $simpleproduct->getid()) continue;          $stockqty = (int)mage::getmodel('cataloginventory/stock_item')->loadbyproduct($simpleproduct)->getqty();         if ($stockqty <= 0) {             $instock = false;             break;         }     }  } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -