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;
?>
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值