2011-12-16 66 views
4

我已經創建了新的可配置產品,並將它們的簡單產品附加到了PHP中。Magento'選擇可配置屬性'與PHP

現在,當我修改任何配置的產品,我看到這樣的畫面:

Magento Select Configurable Attributes screen in admin

因此,在沒有任何Magento的文檔,我該怎麼調用PHP來實現同樣的功能與上述編程的屏幕?

我看過$configurable_product->setConfigurableProductsData()在一些例子中使用,但不認爲這是我需要的。

+0

您會看到,因爲您創建的configurabe產品和關聯的簡單產品有問題。再次檢查你的腳本,並確保從magento的角度來看它的一切都很好。 – Ovidiu 2011-12-16 20:45:55

+0

如果我選擇其中一個屬性,然後點擊相關產品,我可以看到我附加的簡單產品。因此,它看起來像是該協會在簡單的產品級別上工作,但它沒有在可配置產品上設置屬性。 – 2011-12-16 23:17:16

回答

11

你說得對,你正在創建配置和兒童產品,但所發生的事情之間的關聯/鏈接的是,當你創建你的配置的產品,你不設置的setConfigurableAttributesData,基本上設置爲可配置的superattribute信息產品。

foreach($configAttrCodes as $attrCode){ 

     $super_attribute= Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product',$attrCode->code); 
     $configurableAtt = Mage::getModel('catalog/product_type_configurable_attribute')->setProductAttribute($super_attribute); 

     $newAttributes[] = array(
      'id'    => $configurableAtt->getId(), 
      'label'   => $configurableAtt->getLabel(), 
      'position'  => $super_attribute->getPosition(), 
      'values'   => $configurableAtt->getPrices() ? $configProduct->getPrices() : array(), 
      'attribute_id' => $super_attribute->getId(), 
      'attribute_code' => $super_attribute->getAttributeCode(), 
      'frontend_label' => $super_attribute->getFrontend()->getLabel(), 
     ); 
    } 

    $existingAtt = $product->getTypeInstance()->getConfigurableAttributes(); 

    if(empty($existingAtt) && !empty($newAttributes)){ 
     $configProduct->setCanSaveConfigurableAttributes(true); 
     $configProduct->setConfigurableAttributesData($newAttributes); 
     $configProduct->save(); 

    } 

這是小片段應該讓你在那裏,讓我知道如果你有任何問題或需要進一步的幫助。