我想将自定义属性的值设置为可配置产品的关联产品。
- I've created an attribute and attribute set
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();
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.