cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 Enterprise edition, get all custom attributes of product in the observer

Magento 2 Enterprise edition, get all custom attributes of product in the observer

My store has many GroupProduct and each one has many virtual products. This virtual products have custom attributes and some are required and some aren't.
 
[MyModule]/Setup/InstallData.php
Screen Shot 2017-09-19 at 4.14.35 PM.pngScreen Shot 2017-09-19 at 4.14.52 PM.png 
Screen Shot 2017-09-19 at 3.01.43 PM.pngScreen Shot 2017-09-19 at 3.03.26 PM.pngScreen Shot 2017-09-19 at 4.20.14 PM.png 
 
The goal is to save some of the product attributes in sales_order_item table.
 
product attribute -> quote_item -> sales_order_item
 
When the GroupProduct  is added to the cart the observer assigned to the event sales_quote_item_set_product is being executed for each item.
Then when I try to get a product attribute that is not required with the method $observer->getProduct()->getData('iesep_idioma') I get a null value. If I try to get an attribute that is required I do get the value.
 
 
How do I load the attributes that I need without loading the whole object?
 
[MyModule]/etc/events.php
Screen Shot 2017-09-19 at 4.22.59 PM.png
 
[MyModule]/Observer/salesQuoteItemSetCustomAttribute.php
Screen Shot 2017-09-19 at 2.57.27 PM.png