0

I have overwrited the bundle class usig di.xml

  preference for="Magento\Bundle\Block\Catalog\Product\View\Type\Bundle"type="Bachus\BundleContextPros\Block\Catalog\Product\View\Type\Bundle" />

in my custom module. Now I want to write a method in this class which will create my model (Bunleset) wchih I created In my cusotm module. I want to get some data form my custom table here.

my method in Bachus\BundleContextPros\Block\Catalog\Product\View\Type\Bundle.php

class Bundle extends \Magento\Catalog\Block\Product\View\AbstractView
{
 ...

 public function generateJsContext(){
        $model = new \Bachus\BundleContextPros\Model\Bundleset();

        foreach($this->getOptions() as $option){

            $title =  $option->getTitle();

            }
        return $title;
    }

but I get error like that:

Uncaught TypeError: Argument 1 passed to Magento\Framework\Model\AbstractModel::__construct() must be an instance of Magento\Framework\Model\Context, none given, called in

I know my model bundleset class, reasourcecollection etc. are ok beacuse I have followed Alanstorm CRUD tutoral And I can fetch the data in example blocks. But I need this data in Bundle class method to then display it on option.phtml. Please Help

  • Show your full class. – Sohel Rana Dec 3 '17 at 13:57
0

I fund the ansver which works

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$model = $objectManager->create('\Namespace\Modulename\Model\Modulename');

but on the oter topic people say that is not recomened and I schould overide _constructor so I did:

public function __construct(

    \Magento\Catalog\Block\Product\Context $context,
    \Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
    \Magento\Catalog\Helper\Product $catalogProduct,
    \Magento\Bundle\Model\Product\PriceFactory $productPrice,
    \Magento\Framework\Json\EncoderInterface $jsonEncoder,
    \Magento\Framework\Locale\FormatInterface $localeFormat,
    \Bachus\BundleContextPros\Model\Bundleset $bundlset, // my class

    array $data = []
) {

    $this->catalogProduct = $catalogProduct;
    $this->productPriceFactory = $productPrice;
    $this->jsonEncoder = $jsonEncoder;
    $this->localeFormat = $localeFormat;
    $this->bundleset = $bundlset; /// My custom model wich i want to load
    parent::__construct(
        $context,
        $arrayUtils,
        $data
    );
}

but I get errors

Fatal error: Uncaught TypeError: Argument 7 passed to Bachus\BundleContextPros\Block\Catalog\Product\View\Type\Bundle::__construct() must be an instance of Bachus\BundleContextPros\Model\Bundleset, array given, called in

Any Idea?

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.