親と子供が知っている場合は、構成可能なオプションと値を取得します
-
16-10-2019 - |
質問
構成可能な製品IDと関連する児童製品IDがある場合、その組み合わせに使用される特定の属性IDとオプションをどのように決定できますか?
解決
構成可能な製品IDがあると仮定しましょう $mainProductId
そして、児童製品IDはです $childId
.
このような構成可能な属性を取得できます。
$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($mainProductId);
$attributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
これで、このような子供の製品価値を取得できます。
$child = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($childId);
foreach ($attributes as $attribute){
//this will get you the id of the option
echo $attribute['store_label'].':'.$child->getData($attribute['attribute_code'])."<br />";
//if you want the label of the option use the foreach below.
foreach ($attribute['values'] as $value){
$childValue = $child->getData($attribute['attribute_code']);
if ($value['value_index'] == $childValue){
echo $attribute['store_label'].':'.$value['store_label']."<br />";
}
}
}
所属していません magento.stackexchange