[英]Magento Get Child Product Variation
我覺得 Magento 的靈活性可以解決我的問題,但我還沒有找到任何東西。
所以基本上我需要獲取可配置產品的子產品的屬性值。 到目前為止,我所能做的就是在 view.phtml 文件中:
if ($_product->getTypeId() == 'configurable')
{
$confAttributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
print_r($confAttributes);
}
但那是來自父 scope 的東西。 基本上我的問題是我需要獲取子產品的圖像但是當我通過這樣的循環 go...
if ($_product->getTypeId() == 'configurable')
$_child_products = $_configurable_model->getUsedProducts(null, $_product);
for ($i = 0; $i < count ($_child_products); $i++){
<?php echo $this->helper('catalog/image')->init($_child_products[$i], 'image'); ?>
}
但是現在從子產品的角度來看是scope。 我需要以某種方式將子產品與其具有的屬性值相關聯(用於 jQuery 和圖像處理)。
那么有什么方法可以從 child_product 的角度獲取一些可以將其鏈接到屬性的信息?
這可能會幫助您:
$product = Mage::getModel('catalog/product')->load($id);
$childIds = Mage::getModel('catalog/product_type_grouped')
->getChildrenIds($product->getId());
$i = 1;
foreach ($childIds as $key => $val){
foreach($vals as $keyy => $vall){
$arr[$i] = $vall;
$i++;
}
}
$id -> 是組產品的產品 ID。
$arr -> 包含子產品 id 的數組。
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('price')
->addFieldToFilter('entity_id',array('in' =>array($arr)));
上面的代碼片段顯示了如何檢索子產品的方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.