Erhalten Sie eine konfigurierbare Option und den Wert, wenn übergeordnetes und untergeordnetes bekannt ist

magento.stackexchange https://magento.stackexchange.com/questions/5296

  •  16-10-2019
  •  | 
  •  

Frage

Wenn ich eine konfigurierbare Produkt -ID und eine zugehörige Kinderprodukt -ID habe, wie kann ich dann die spezifische Attribut -ID und Optionen für diese Kombination bestimmen?

War es hilfreich?

Lösung

Nehmen wir an, dass die konfigurierbare Produkt -ID ist $mainProductId und die Kinderprodukt -ID ist $childId.
Sie können die konfigurierbaren Attribute wie diese erhalten:

$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($mainProductId);
$attributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product); 

Jetzt können Sie die Kinderproduktwerte wie diese erhalten:

$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 />";
        }
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top