Question

I'm programmatically adding products to Magento. I also have a dynamic array (for example: $skuForConfig = array(123, 124))

I use this to add them:

$productData = array();
foreach($skusForConfig as $skuForConfig){
    $productDataTemp = array(
         $skuForConfig => array('0' => array('attribute_id' => '1016', 'label' => 'Size','value_index' => '28563', 'is_percent' => 0, 'pricing_value' => ''))
    );
    array_push($productData, $productDataTemp);
}
$product->setConfigurableProductsData($productData);

So this is the 'dynamic' form for:

    $productData = array(
         '123' => array('0' => array('attribute_id' => '1016', 'label' => 'Size','value_index' => '28563', 'is_percent' => 0, 'pricing_value' => '')),
         '124' => array('0' => array('attribute_id' => '1016', 'label' => 'Size','value_index' => '28563', 'is_percent' => 0, 'pricing_value' => ''))
    );
$product->setConfigurableProductsData($productData);

But... it doesn't work :-(

Was it helpful?

Solution

Owww, ofcourse, found it... (I leave it on stackexchange though for people who need to know this too...)

$productData = array();
foreach($skusForConfig as $skuForConfig){
    $productData[$skuForConfig] = array('0' => array('attribute_id' => '1016', 'label' => 'Size','value_index' => '28563', 'is_percent' => 0, 'pricing_value' => ''));
}
$product->setConfigurableProductsData($productData);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top