在Magento中,将属性添加到可配置产品的关联产品

3
我想将自定义属性的值设置为可配置产品的关联产品。
  1. I've created an attribute and attribute set
  2. When I create a configurable product I select the attribute set needed for later selecting the values of each one.

    $product = Mage::getModel('catalog/product');
    $stockData = $product->getStockData();
    $stockData['qty'] = $qty;
    $stockData['is_in_stock'] = 1;
    $stockData['manage_stock'] = 1;
    $stockData['use_config_manage_stock'] = 1;
    $today = "'".date("Y-m-d")."'";
    $product->setStoreId(0)
        ->setTypeId("configurable")  
        ->setAttributeSetId($attribute_set_id)
        ->setName($es_name)
        ->setDescription($es_description)
        ->setShortDescription($es_short_description)
        ->setSku($sku)
        ->setWeight(1.0)
        ->setStatus(2)  
        ->setVisibility(4) 
        ->setPrice($price)
        ->setTaxClassId($tax_class)  // Impuestos
        ->setStockData($stockData)   // Stock
        ->setCategoryIds($categories) 
        ->setWebsiteIDs(array(1))  // Website total
        ->setData('news_from_date', $today)
            ->save();
    
  3. I have to create as many associated products as attributes selected of the attribute set. For example: custom_attribute with options 40,41,42. So I must create a simple product with my custom_attribute and value and don't know how to do it. For example: create a simple product the same as the configurable with my custom_attribute 40 and another with value 42. Knowing that one or more attributes can be associated to the same attribute set and everything must be created dinamically.

是否有类似 $product->setAttribute("custom_attribute",$value) 这样的东西存在?
1个回答

0

是的,而且你已经在使用它了。Magento使用魔术方法 - 要将属性custom_attribute的值设置为$value,请执行以下操作:

$product->setCustomAttribute($value)

要将 some_other_thing 的值设置为 $value,请执行以下操作:

$product->setSomeOtherThing($value)

看到模式了吗?
或者,您可以直接使用setData方法:
$product->setData('custom_attribute', $value)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接