cancel
Showing results for 
Search instead for 
Did you mean: 

add product programmatically magento 2: Undefined property: stdClass::$reference

add product programmatically magento 2: Undefined property: stdClass::$reference

I went to the backend of magento I added a reference attribute for product, then I executed the script Programmatically to add product I put:

$_product->setName($product_data->_source->name);
$_product->setTypeId('simple');
$_product->setSku('sku'.$item);
$_product->setreference($product_data->_source>reference);
...
$_product->save();

but an error is displayed as following,

222.png

please how to add an attribute and access it with set

 thanks in advance

 

1 REPLY 1

Re: add product programmatically magento 2: Undefined property: stdClass::$reference

You have a PHP Syntax error in this line:

 

$_product->setreference($product_data->_source>reference);

You have a de-reference but are missing a hyphen. You wil also want to use a capital for setReference. It should instead be:

 

$_product->setReference($product_data->_source->reference);

I haven't looked into if this is actually the code you want to run but it clears up the syntax error. 

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!