Hello Magento Friends,
Today I am going to throw light on How to Get Bundle Product Option Image in Magento 2.
Magento 2 supports various types of products one of them is bundled products. Bundled products are a group of products that customers can choose their own products to make a bundle. Learn – How to Create Bundled Product Programmatically in Magento 2
Bundle products have an image gallery on the product page. You can add product options images to the main image gallery. When the user selects a particular product option, it should update the selected option as the main image from the gallery.
To fulfill the above requirements, follow the below steps.
Step 1: Move to the below path
app\code\Vendor\Extension\Block\Product\Type\Bundleoption.php
Add the code as mentioned below
<?php namespace Vendor\Extension\Block\Product\Type; Class Bundleoption extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle { protected $helperbundleimage; public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Bundle\Model\Product\PriceFactory $productPrice, \Magento\Framework\Json\EncoderInterface $jsonEncoder, \Magento\Framework\Stdlib\ArrayUtils $arrayUtils, \Magento\Catalog\Helper\Product $catalogProduct, \Magento\Framework\Locale\FormatInterface $localeFormat, array $data = [] ) { $this->helperbundleimage = $context->getImageHelper(); parent::__construct( $context, $arrayUtils, $catalogProduct, $productPrice, $jsonEncoder, $localeFormat, $data ); } }
Step 2: Now Create a Simple function with 2 parameters, or else you can get the product object from where you can get it.
public function getBundleOptionImage($_product, $type) { return $this->helperbundleimage ->init($_product,$type, ['height' => 140,'width'=> 140]) ->getUrl(); }
Hence, this way you can Get Bundle Product Option Image in Magento 2. If you face any difficulty, let me know in the comment box. Share the article with your friends. I will be back with another Magento solution, till then stay updated with us.
Happy Coding!
Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…
In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…
October was an exciting month for MageComp! From significant updates across our Magento 2 extension…
In modern web development, seamless navigation and state management are crucial for delivering a smooth…
Magento Open Source 2.4.8 beta version released on October 8, 2024. The latest release of…
Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…
View Comments
Hi Dhiren
Let’s say I wanted to display my product option just like the product list view. with all the information and a checkbox to add it to the bundle - is this something you could help me with?