Question

I want to set one string value to sizes attribute in drop-down ?

           //get sage dimension value
           $dimension = $value->Dimensions;    

            //set value
            $product->setStoreIds(array(0,1));
            $product->setWebsiteIds(array(1));
            $inStock = 1;                            
            $product->setSku($product_sku);
            $product->setName($finalpname);
            $product->setAttributeSetId(4);                        
            $product->setTypeId('simple');              
            $product->setStockData(
                array(
                    'use_config_manage_stock' => 0,
                    'manage_stock' => 1,
                    'is_in_stock' => $inStock,
                    'qty' => $minqty
                )
            );

             //set dimension value to sizes dropdown attribute
            $product->setSizes($dimension);

            $product->save();   

Below attribute not set in drop-down.

$product->setSizes($dimension);

Any idea, how can I set dimension value in sizes attribute?

output:-

enter image description here

Actual Output:-

enter image description here

Was it helpful?

Solution

I get the Size of attribute values and I have checked the post value match to the attribute list. If matched then set the value to the product

foreach ($result as $key=>$value) {
  if ($value['value'] == $dimension ) 
  {
    $size_option_id = $value['option_id'];
  }
}

$product->setSizes($size_option_id);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top