We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    If you want to show the bundle product image when the child product added in the cart programmatically, please follow the below step.

    Step 1). Create file app/code/Magemonkeys/Cart/etc/di.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    	<type name="MagentoCheckoutCustomerDataAbstractItem">
    	     <plugin name="Change_Product_Image_In_Minicart" type="MagemonkeysCartPluginMinicartImage" sortOrder="1"/>
    	</type>
    </config>

    Step 2). Create file app/code/Magemonkeys/Cart/Plugin/Minicart/Image.php

    <?php
    namespace MagemonkeysCartPluginMinicart;
    class Image
    {
        public function aroundGetItemData($subject, $proceed, $item)
        {
            $result = $proceed($item);
            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $product = $objectManager->create('MagentoCatalogModelProduct')->load($result['product_id']);
            $parentId = $objectManager->create('MagentoGroupedProductModelProductTypeGrouped')->getParentIdsByChild($result['product_id']);
    
            /* thumb url */ 
            $storeManager = $objectManager->create('MagentoStoreModelStoreManagerInterface'); 
            $currentStore = $storeManager->getStore();
            $mediaUrl = $currentStore->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
    
            if (isset($parentId[0])) {
                $id = $parentId[0];
                $productdata = $objectManager->create('MagentoCatalogModelProduct')->load($id);
                $result['product_image']['src'] = $mediaUrl."catalog/product".$productdata->getThumbnail();
            }else{
                $result['product_image']['src'];
            }
            return $result;
        }
    }

     

    field_5bfb909c5ccae

      Get a Free Quote