magento 제품 재고량 및 configurable product에서 associated children product 정보 얻기
3229 단어 children
$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;
?>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[CS] DOM Day-18DOM JavaScript를 이용해 Element 속성값을 얻어내거나, 변경하는 방법 HTML문서의 구조와 관계를 객체(Object)로 표현한 모델입니다. id : practice class : highlight, ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.