Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create a configurable product with associated products?
    text
    copied!<p>The following code does create a configurable product, however, when I open the product in the backend, the following message appears:</p> <p>Select Configurable Attributes "Only attributes with scope "Global", input type "Dropdown" and Use To Create Configurable Product "Yes" are available." A single checkbox is displayed ("Colour Group"), which must be selected before continuing.</p> <p>When I click "Continue", all of the product data is there as expected EXCEPT for the associated products.</p> <pre><code>//Mage Product $mpr = Mage::getModel('catalog/product'); $mpr -&gt;setTypeId(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) -&gt;setTaxClassId(5) -&gt;setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) -&gt;setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED) -&gt;setWebsiteIds(array(1)) -&gt;setAttributeSetId(4) // You can determine this another way if you need to. -&gt;setSku("C12345") -&gt;setName("C12345") -&gt;setQty(25) -&gt;setShortDescription('short description') -&gt;setDescription('description') -&gt;setPrice(1) -&gt;setStockData(array( 'use_config_manage_stock' =&gt; 1, 'is_in_stock' =&gt; 1, 'is_salable' =&gt; 1, )); $productData = array( '7039604' =&gt; array('0' =&gt; array('attribute_id' =&gt; '85', 'label' =&gt; 'ROYAL','value_index' =&gt; '28563', 'is_percent' =&gt; 0, 'pricing_value' =&gt; '') ,'1' =&gt; array('attribute_id' =&gt; '192', 'label' =&gt; '14', 'value_index' =&gt; '28728', 'is_percent' =&gt; 0, 'pricing_value' =&gt; '') ) ); $attributeData = array( '0' =&gt; array( 'id' =&gt; NULL ,'label' =&gt; 'Color' ,'position' =&gt; NULL ,'values' =&gt; array( '0' =&gt; array('value_index' =&gt; 28563, 'label' =&gt; 'ROYAL', 'is_percent' =&gt; 0, 'pricing_value' =&gt; '0', 'attribute_id' =&gt; '85') ) ,'attribute_id' =&gt; 85 ,'attribute_code' =&gt; 'color' ,'frontend_label' =&gt; 'Color' ,'html_id' =&gt; 'config_super_product__attribute_0') ,'1' =&gt; array( 'id' =&gt; NULL ,'label' =&gt; 'Rivers Size' ,'position' =&gt; NULL ,'values' =&gt; array( '0' =&gt; array('value_index' =&gt; 28728, 'label' =&gt; '14', 'is_percent' =&gt; 0, 'pricing_value' =&gt; '0', 'attribute_id' =&gt; '192') ) ,'attribute_id' =&gt; 192 ,'attribute_code' =&gt; 'rivers_size' ,'frontend_label' =&gt; 'Rivers Size' ,'html_id' =&gt; 'config_super_product__attribute_1') ); $mpr-&gt;setConfigurableProductsData($productData); $mpr-&gt;setConfigurableAttributesData($attributeData); $mpr-&gt;setCanSaveConfigurableAttributes(true); $mpr-&gt;save(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload