0
Model\Reorder\Data\ReorderOutput must be compatible with Magento\Sales\Model\Reorder\Reorder::execute(string $orderNumber, string $storeId): Magento\Sales\Model\Reorder\Data\ReorderOutput

I am getting the above error while trying to override the module. I am trying with the preference to override the execute method.

code:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <preference for="Magento\Sales\Model\Reorder\Reorder" type="Test\CustomReorder\Model\Reorder\Reorder"/>
</config>

file:

 <?php

namespace Test\CustomReorder\Model;

class Reorder extends \Magento\Sales\Model\Reorder\Reorder
{
 public function execute(string $orderNumber, string $storeId): Data\ReorderOutput
    { 
       $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('confirmed');
die('abc');      
    }
}
1
  • Show your code here.
    – Sohel Rana
    Commented Jul 31, 2021 at 6:39

3 Answers 3

0

Instead of preference try to use Before or After plugins. Full instruction: https://www.mageplaza.com/magento-2-module-development/magento-2-plugin-interceptor.html

Just find which method you need override and create after/before (don't use around) plugin for them.

1
  • On my side I'm always using preferences, it's always the better and quickest way to know that all the file is extended. I think plugin would be more if you just want to modify an output for example. I would say it just depends on what he wants to do with his data.
    – Claims
    Commented Aug 2, 2021 at 9:18
0

You are just missing to call the parent constructor.

So your Reorder class needs to have a __construct method in wich one you will at least have the following :__construct(...)

Where ... will be the list of the parent constructor. If you are using an ide like PhpStorm he should fill all the paremeters for you using the extends.

0

Try to use below override class i.e. Test\CustomReorder\Model\Reorder\Render.php. It would only works for valid for Magento 2.4.x only.

Also, double confirm the type="Test\CustomReorder\Model\Reorder\Reorder in the di.xml as well and check namespace in PHP class.

<?php
namespace Test\CustomReorder\Model\Reorder;


use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\Cart\CustomerCartResolver;
use Magento\Quote\Model\GuestCart\GuestCartResolver;
use Magento\Sales\Helper\Reorder as ReorderHelper;
use Magento\Sales\Model\OrderFactory;

class Reorder extends \Magento\Sales\Model\Reorder\Reorder
{

    public function __construct(OrderFactory $orderFactory, CustomerCartResolver $customerCartProvider, GuestCartResolver $guestCartResolver, CartRepositoryInterface $cartRepository, ReorderHelper $reorderHelper, \Psr\Log\LoggerInterface $logger, ProductCollectionFactory $productCollectionFactory)
    {
        parent::__construct($orderFactory, $customerCartProvider, $guestCartResolver, $cartRepository, $reorderHelper, $logger, $productCollectionFactory);
    }

    public function execute(string $orderNumber, string $storeId): Data\ReorderOutput
    {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('confirmed');
        die('abc');
    }
}

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.