1

I'm trying to get the attributes values of the simple products in a grouped product to display on the detailpage (of the grouped product), but it is not working.

At the moment i have the following code in Magento_GroupedProduct/templates/product/view/type/grouped.phtml.

<?php foreach ($_associatedProducts as $_item): ?>          
  <?php $item = $objectManager->get('Magento\Catalog\Model\Product')->load($_item->getId()); 
    $item->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($item) .' <br />';

I'm getting the value of the attribute now, but it looks like it's not "resetting" the value. I have 3 simple products where only 2 of them have a value for the attribute set in the admin backend. Nevertheless does the third product has the attribute value of the second one.

I hope anyone could help me to fix this problem (and maybe with better code then the objectManager). Thanks in advance

6
  • It looks like your attribute type is select, isn't it?
    – PY Yick
    Commented Jun 30, 2017 at 9:58
  • @PYYick Yes, the attribute type is dropdown (select). Commented Jun 30, 2017 at 12:28
  • @PYYick Should i make it an other type then? Or do you have any other solutions? Commented Jul 7, 2017 at 6:09
  • Just rewrite the codes is OK.
    – PY Yick
    Commented Jul 7, 2017 at 7:16
  • @PYYick What do you mean with "rewrite the codes"? Is it possible that you provide an example code? Commented Jul 13, 2017 at 7:46

0

Your Answer

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

Browse other questions tagged or ask your own question.