0

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

6
  • Add more information – zed Blackbeard Mar 20 '18 at 14:35
  • let us know in which format you are getting you $dimension value. Please add the array – Abhishek Panchal Mar 20 '18 at 14:55
  • format of dimension <Dimensions> 2&L x 3&W </Dimensions> – Devidas Mar 20 '18 at 15:03
  • are you trying to save to product or trying to assign size attribute options? – sandip Mar 21 '18 at 0:44
  • save to product – Devidas Mar 21 '18 at 6:33
0

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.