0

I want to add the product image to bundle product page for each option. I chose to extend class \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox

This class has no __construct method, but I have to use it because I want to use \Magento\Catalog\Helper\Image. When I define a construct method, the page crashes and throws an error Call to a member function dispatch() on null

If I call parent::__construct, I receive a type error indicating the __construct methods do not match.

I have read that if the parent class does not have a __construct class, that I do not have to call parent, but in my case I cannot get this simple modification to work.

class Checkbox extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox {

public function __construct(
    \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
    \Magento\Catalog\Helper\Image $imageHelper
){
    $this->_stockRegistry = $stockRegistry;
    $this->_imageHelper = $imageHelper;
}

1 Answer 1

0

The problem is that when you extend a class that extends from another class and has no __construct method, you must use the __construct of the parent which in this case is \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option

This fixed my issue.

Your Answer

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

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