cancel
Showing results for 
Search instead for 
Did you mean: 

Get Additional Attributes in Children of Grouped Product

Get Additional Attributes in Children of Grouped Product

Hello!

 

I am currently working on extending an existing module for Magento (the algolia search integration). In this module, I have access to a $subProducts variable containing a list of children products associated with a grouped product. The code the devs used is the following:

 

$subProducts = $typeInstance->getAssociatedProducts($product);

(more here: https://github.com/algolia/algoliasearch-magento-2/blob/d0ccc1d2cf9430c8a573a803fd1317419538a820/Hel...)

 

Anyhow, when I try to iterate through the $subProducts and try to access an attribute through $subProduct->getData("attribute_name_here"), I get a null value, with the exception of some attributes such as sku, for example.

 

How can I have access to other attributes in these sub products?

 

Thanks!

4 REPLIES 4

Re: Get Additional Attributes in Children of Grouped Product

It seems that adding a plugin or dependency injection (since I want this to happen only with this specific module) to customize

Magento\GroupedProduct\Model\Product\Type\Grouped::getAssociatedProductCollection

might solve the problem I am having; I thought there was some config option we could use to do this Smiley Wink

Re: Get Additional Attributes in Children of Grouped Product

Hi @magnetidog,

Can you try below code before adding plugin or dependency

$my_attr = $this->getProduct()->getResource()->getAttributeRawValue($_item->getId(),'attribute_code',$_item->getId());

I added this code in app\design\frontend\Company\theme\Magento_GroupedProduct\templates\product\view\type\grouped.phtml

My custom attribute code: attribute_code

 

Problem Solved! Click Kudos & Accept as Solution!

Re: Get Additional Attributes in Children of Grouped Product

Hello nishu, thanks - I had tried this already and was getting a "false" value.

Re: Get Additional Attributes in Children of Grouped Product

Hi @magnetidog,

 

I see. Can you please try below way to add custom attributes.

https://magento.stackexchange.com/questions/297551/get-grouped-products-associated-child-product-cus...

 

Prefer plugin way over preference.

Hope this helps you!

Problem Solved! Click Kudos & Accept as Solution!