我创建了新的可配置产品,并使用PHP附加了他们的简单产品.
现在当我编辑任何可配置产品时,我看到这个屏幕:

因此,在没有任何Magento文档的情况下,我在PHP中调用什么来以编程方式执行与上面的屏幕相同的功能?
我已经看到$configurable_product->setConfigurableProductsData()在一些例子中使用过,但不认为这是我需要的.
All*_*gor 11
您是对的,您正在创建可配置产品和子产品之间的关联/链接,但正在发生的是,当您创建可配置产品时,您没有设置setConfigurableAttributesData,它基本上为该可配置产品设置超级属性信息.
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();
}
Run Code Online (Sandbox Code Playgroud)
这个小片段应该让你到那里,如果你有任何问题或需要进一步的帮助,请告诉我.