cancel
Showing results for 
Search instead for 
Did you mean: 

Product Recommendation

Product Recommendation

Hii,

 

I have installed product recommendation extension in Magento but it is not working on my storefront, what should I do?

2 REPLIES 2

Re: Product Recommendation

Which product recommendation extension and what is exactly the issue?

Founder at https://agency418.com

Re: Product Recommendation

Hello @ashwindcou720e 

 

Third-Party Extensions: Extensions from vendors like Amasty, Aheadworks, Mageplaza, and others that provide configurable product recommendation solutions.

 

Install the Extension: Use Composer or manually upload the module, and then run:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

Magento Version Compatibility

Ensure the extension supports your Magento version. If not, contact the vendor for an updated version.

 

You can modify or override the templates to fetch and display the first child's image URL.


Modify the Code: Use the following logic to fetch the first child's image.

<?php
use Magento\Catalog\Model\Product\Type\Configurable;

$product = $_product; // Assuming $_product is the product object in the loop.

if ($product->getTypeId() === 'configurable') {
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $configurable = $objectManager->create(Configurable::class);
    $productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);

    // Get child products
    $childIds = $configurable->getChildrenIds($product->getId())[0];
    if (!empty($childIds)) {
        $firstChildId = reset($childIds);
        $childProduct = $productRepository->getById($firstChildId);

        // Get child product's image
        $firstChildImageUrl = $childProduct->getMediaConfig()->getMediaUrl($childProduct->getImage());
    }
}

// Fallback to parent image if no child image is available
$imageUrl = $firstChildImageUrl ?? $product->getMediaConfig()->getMediaUrl($product->getImage());
?>
<img src="<?= $imageUrl ?>" alt="<?= $product->getName() ?>" />

 

​Hope it helps ! 

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

 

 

 

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9