1

I want to display custom product attribute of simple product on Grouped-product in Grouped phtml file (app\design\frontend\Company\theme\Magento_GroupedProduct\templates\product\view\type\grouped.phtml) but not getting success.

There are few simple products added in grouped product and all simple product have 1 attribute which i want to display on grouped-product-page.

Magento Version: 2.1.8 but I am ok if i got response for any magento 2.1.x version.

Any help would highly appreciated. Thanks.

  • 1
    can you share the code which you have used to display the custom attribute? – Agnes Sep 5 '17 at 12:50
2

I done with this code:

$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

1

I'm interested too in the question. The problem is that you can use the above code for "default" attributes, but not for custom attributes.

This works:

<?php if ($_hasAssociatedProducts): ?>
    <?php foreach ($_associatedProducts as $_item): ?>
        <?php 
         $attribute = $_item->getResource()->getAttribute('price'); 
         $attr_value = $attribute->getFrontend()->getValue($_item);
         ?> 
        <?php echo $attr_value; ?>

But this, not:

<?php if ($_hasAssociatedProducts): ?>
    <?php foreach ($_associatedProducts as $_item): ?>
        <?php 
         $attribute = $_item->getResource()->getAttribute('my_custom_attribute'); 
         $attr_value = $attribute->getFrontend()->getValue($_item);
         ?> 
        <?php echo $attr_value; ?>

I think the problem is that $_item is not a product object.

0

I am having the same issue: Magento 2.2.0. Created couple of custom attributes such as size, marker etc. Added to default set. But when call for display at the frontend, only the default attributes show up (SKU, Price etc). Did anyone figure out? Here is a part of the code I modified from the grouped.html. By the way, the same code worked well in Magento 1.8.1

    <tr>

        <?php if ($_product->isSaleable()): ?>
        <th class="col cat.no" scope="col"><?= /* @escapeNotVerified */ __('Cat. No.') ?></th>
        <th class="col size" scope="col"><?= /* @escapeNotVerified */ __('Size') ?></th>
        <th class="col marker" scope="col"><?= /* @escapeNotVerified */ __('Marker') ?></th>
        <th class="col price" scope="col"><?= /* @escapeNotVerified */ __('Price') ?></th>
        <th class="col qty" scope="col"><?= /* @escapeNotVerified */ __('Qty') ?></th>
        <?php endif; ?>



    </tr>
    </thead>

    <?php if ($_hasAssociatedProducts): ?>
    <?php foreach ($_associatedProducts as $_item): ?>
    <tbody>
        <tr>
        <?php if ($_product->isSaleable()): ?>
        <td><?php echo $this->escapeHtml($_item->getSKU()) ?></td>
        <td><?php echo $this->escapeHtml($_item->getName()) ?></td> 
        <td><?php echo $this->escapeHtml($_item->getMarker()) ?></td>
        <td><?php echo $this->escapeHtml($_item->getPrice()) ?></td>    
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review – Murtuza Zabuawala Nov 15 '17 at 2:18
  • 1
    Sorry, first time in my life posting anything here. Not enough credit. But the problem got fixed. Hope other people find it useful. – Luke Pulaski Nov 15 '17 at 3:45
0

Problem solved:

=> You have to hard code your custom attributes into file at line 211:

vendor/magento/module-grouped-product/Model/Product/Type/Grouped.php

       )->addAttributeToSelect(
            ['name', 'size', 'marker', 'price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id']

In my case it's the 'size" and 'marker" Please refer to:

https://github.com/magento/magento2/issues/12258

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.