1

I am working on to create a simple product programmatically.

I have created 2 custom Attribute

  1. Select(select_testing)
  2. MultiSelect(multiselect_testing)

select_testing attribute value ==> 1, 2, ,3, 4. multiselect_testing attribute value --> 1, 2, 3, 4.

So, I try to add Product using following code.

  $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // instance of object manager
  $simple_product = $_objectManager->create('\Magento\Catalog\Model\Product');
  $simple_product->setSku('test-sku');
  $simple_product->setName('SimpleProduct');
  $simple_product->setRkTesting('Rk Testing');
  $simple_product->setSelectTesting('1');
  $simple_product->setMultiselectTesting(array("1","2"));
  $simple_product->setYesTesting(1);
  $simple_product->save();

But, Select and Multiselect attribute value not save.

Suggest me, how to add Select and multiselect Attribute value.

2 Answers 2

1

You should use

Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend

as 'backend_model' for your "multiple" attribute

and update attribute by follow:

$_product->addAttributeUpdate('attribute_code', 'value', $storeId);
0

You have to pass the values comma separated not array. $simple_product->setMultiselectTesting('1,2,3');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.