读书人

magento 获取产品存货量以及configura

发布时间: 2012-12-22 12:05:06 作者: rapoo

magento 获取产品存货量以及configurable product 下associated children product信息

Magento Get Product Stock Quantity

To get the quantity in stock for a particular product in Magento use the following code -

$qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
?

来源:http://www.codeboss.in/web-funda/2011/03/03/magento-get-product-stock-quantity/


Magento: How to get all associated children product of a configurable product?

?

Here is the code to fetch all the children products that are associated with a configurable product.

Here goes the code :)

?

/** * Load product by product id */$product = Mage::getModel('catalog/product')->load(YOUR_PRODUCT_ID); /** * Get child products id (only ids)$childIds = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($product->getId()); /** * Get children products (all associated children products data) */$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
?

来源: http://blog.chapagain.com.np/magento-how-to-get-all-associated-children-product-of-a-configurable-product/

?

实例1:

Get Configurable Product (or) Associated Product details in Magento Product page

?

In this post, I’ll explain about how to get Configurable/associated/grouped product details in Magento product page?

//Note: In the below code if there is any ` (bactics) symbol, replace it to single quotes. $conf_pro = Mage::getModel('catalog/product')->load($_product->getId());$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$conf_pro); //print_r($childProducts); // Print and see the array indexes and fetch details according to your requirement foreach($childProducts as $child) { echo $child['name'];} //Get the configurable attribute name of the product in product view page:$configurable = $_product->getTypeInstance();$attributes = $configurable->getConfigurableAttributes($_product);foreach ($attributes as $attribute) {    print $attribute->getLabel();    print "<br />";}


实例2:?

<?php $_product = $this->getProduct(); ?><?php$children = array();$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$_product);foreach($childProducts as $child):$qty  = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($child)->getQty();$size = $child->getResource()->getAttribute('size')->getFrontend()->getValue($child);$children[$size]['title'] = $child->getName();$children[$size]['size']  = $size;$children[$size]['qty']   = $qty;endforeach;echo '<pre>'; print_r($children); echo '</pre>';  die;?>
?

?

?

读书人网 >编程

热点推荐