0

I have created a custom product attribute and added the code below to display them within the grouped product table.

<td data-th="<?= $block->escapeHtml(__('Breaking Strain')) ?>" class="col item">
        <?= $my_attr = $this->getProduct()->getResource()->getAttributeRawValue($_item->getId(),'breakingstrain',$_item->getId()); ?>
</td>

(/public_html/vendor/magento/module-grouped-product/view/frontend/templates/product/view/type/grouped.phtml)

However not every product will use this custom attribute, so I don't want the td to be visible if there is no data set within the attribute.

2 Answers 2

0

You need to try this code.

<?php $my_attr = $this->getProduct()->getResource()->getAttributeRawValue($_item->getId(),'breakingstrain',$_item->getId()); ?>
<?php if($my_attr != '') : ?>
<td data-th="<?php echo $block->escapeHtml(__('Breaking Strain')) ?>" class="col item">
      <?php echo $my_attr ?>  
</td>
<?php endif; ?>
1
  • This works but gets the ID of the attribute, is there a way to get the value of the attribute?
    – 07lodgeT
    Sep 23, 2019 at 8:34
0

Try the below code:

<?php if($my_attr = $this->getProduct()->getResource()->getAttributeRawValue($_item->getId(),'breakingstrain',$_item->getId())): ?>
<td data-th="<?= $block->escapeHtml(__('Breaking Strain')) ?>" class="col item">
    <?= $my_attr; ?>
</td>
<?php endif; ?>

Your Answer

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

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