0

Using magento 2.4.3 EE I have extended a class

namespace Vendor\module\Block\Product\View\Type\Bundle\Option;

use Vendor\module\Model\Attribute\Source\Order;

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

public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Json\EncoderInterface $jsonEncoder,
        \Magento\Catalog\Helper\Data $catalogData,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Stdlib\StringUtils $string,
        \Magento\Framework\Math\Random $mathRandom,
        \Magento\Checkout\Helper\Cart $cartHelper,
        \Magento\Tax\Helper\Data $taxData,
        \Magento\Framework\Pricing\Helper\Data $pricingHelper,
        \Bss\ProductStockAlert\Helper\Data $helper,
        array $data = []
    ) {
        $this->helper = $helper;
        parent::__construct(
            $context,
            $jsonEncoder,
            $catalogData,
            $registry,
            $string,
            $mathRandom,
            $cartHelper,
            $taxData,
            $pricingHelper,
            $data
        );
    }

this class extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox it has no constructor defined.

not sure if i need to add parent construct in this vendor/module file or not ?

3
  • What if class is extended to another class that also have parent construct ? Then the custom modules's class must have parent construct or not ?
    – magedev
    2 days ago
  • i am not getting any error even if i have not added few args in parent construct. compared to the main class. Still do i need to add those args s main class ?
    – magedev
    22 hours ago
  • any thoughts on this ?
    – magedev
    22 hours ago
1

Your this file :

\Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox

Extended from another file and that file have constructor then you need to pass those parameter from here.

5
  • Thanks & that file is Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option right ? So the module's file must have the constructor args same as this Option class also in same order.
    – magedev
    Oct 14 at 7:15
  • yes, if answer help accepted as solution and upvote as well, so that will help other in community. Oct 14 at 7:18
  • Thanks for the answer.
    – magedev
    Oct 14 at 7:22
  • What if class is extended to another class that also have parent construct ? Then the custom modules's class must have parent construct or not ?
    – magedev
    2 days ago
  • i am not getting any error even if i have not added few args in parent construct. compared to the main class. Still do i need to add those args s main class ?
    – magedev
    yesterday
1

If the parent class does not have __construct() method, then it is not necessary to add parent __construct() method in your class.

In that case, you only need to add __construct() method in your class if your class needs to add any new dependency.

If the parent class has __construct() method defined, and you are using __construct() method in your class, then you need to use parent::__construct() method with all dependencies defined in the parent class's __construct() method.

1
  • Thanks for the answer. perfect answer.
    – magedev
    Oct 14 at 7:23

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.