0

I want the product image to change on "catalog-category-view" depending on whether the product is 'grouped' or 'simple'.

In Magento_Catalog\templates\product\list.phtml the product image is called by

<?php echo $productImage->toHtml(); ?>

which calls image_with_borders.phtml

Here i tried something like that:

<?php 
$_productCollection = $block->getLoadedProductCollection();
$is_grouped = $_productCollection ->getTypeId() == 'grouped'; 
if ($is_grouped != 1): 
    echo "yes"; //example
else :                                   
    echo "no";  //example                       
endif;
?>

But i always get:

Fatal error: Uncaught Error: Call to a member function getTypeId() on null

How can i achieve this? I'm using that sort of code in list.phtml to differentiate between grouped and simple products and it'S working.

Specs: Magento Ver.-2.3.4 | PHP 7.2

0

Another way to check the product is grouped or not.

<?php if( $_product->getTypeId() == 'simple' ): ?>
//your code for simple products only
<?php endif; ?>

<?php if( $_product->getTypeId() == 'grouped' ): ?>
//your code for grouped products only
<?php endif; ?>

So on. Place this code in the catalog/product/view.phtml

Hope this help you

Thanks...

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.