如何以编程方式创建可配置产品

时间:2013-05-06 10:46:10

标签: magento

我想通过xml导入magento中的可配置产品。我已经导入了简单的产品。为了创建可配置的产品,我按照这里给出的过程http://www.magentocommerce.com/boards/viewthread/46844/。 有用。如果我删除

$data=array('5791'=>array('0'=>array('attribute_id'=>'491','label'=>'vhs','value_index'=>'5','is_percent'=>0,'pricing_value'=>'')),'5792'=>array('0'=>           array('attribute_id'=>'491','label'=>'dvd','value_index'=>'6','is_percent'=>0,'pricing_value'=>'')));
$product->setConfigurableProductsData($data);

仍然有效。这对我有好处。但我的问题是这段代码:

$data = array('0'=>array('id'=>NULL,'label'=>'Media Format','position'=> NULL,'values'=>array('0'=>array('value_index'=>852,'label'=>'vhs','is_percent'=>0,
  'pricing_value'=>'0','attribute_id'=>'182'),'1'=>array('value_index'=>853,'label'=>'dvd',
    'is_percent'=>0,'pricing_value'=>'0','attribute_id'=>'182')
),'attribute_id'=>182,'attribute_code'=>'media_format','frontend_label'=>'Media Format',
    'html_id'=>'config_super_product__attribute_0'));

我不能只使用$product->getTypeInstance()->setUsedProductAttributeIds(array(491)); 为可配置产品设置超级Attributeid = 491?为什么这里需要属性的细节? 任何人都可以帮我找到以编程方式创建可配置产品的最简单方法。

1 个答案:

答案 0 :(得分:0)

您必须看到此链接这是创建可配置产品的最简单方法,

http://blog.omnisubsole.com/2009/07/01/configurable-products-in-magento/

转到app / design / frontend / default / your thme / template / catalog / product然后打开list.phtml

$product=Mage::getModel('catalog/product')->load($product_id);
$productType=$product->getTypeID();
//Simple Product
if($productType == 'simple')
{   
 //get simple product code here
}                           
//Configurable Product
if($productType == 'configurable')
{   
 //get Configurable Product code here
}
相关问题