0

I created a preference override for Magento\Quote\Model\Quote\Item\CartItemPersister in my own module. But I get this error in the browser developer console:

Total: Type Error occurred when creating object: Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor, Argument 3 passed to Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor::__construct() must be an instance of Magento\Quote\Model\Quote\Item\CartItemPersister

instance of Company\Configurator\Rewrite\Magento\Quote\Model\Quote\Item\CartItemPersister given

app/code/Company/Configurator/etc/di.xml

<?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\Quote\Model\Quote\Item\CartItemPersister"
                type="Company\Configurator\Rewrite\Magento\Quote\Model\Quote\Item\CartItemPersister"/>
      ...

It seems like I also have to override Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor and swap to my rewrite class there, but this does not seem to be the official way?

UPDATE: I've completly overriden Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor but now I get

Total: Type Error occurred when creating object: Magento\Quote\Model\QuoteRepository\LoadHandler\Interceptor, Argument 1 passed to Magento\Quote\Model\QuoteRepository\LoadHandler\Interceptor::__construct() must be an instance of Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor, instance of Company\Configurator\Rewrite\Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor given, called in /var/www/company/m2/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121

Whats the best way to solve this?

2 Answers 2

1

I was able to solve it with a plugin instead of an override

0

In this case, your only option would be to create a subclass of Magento\Quote\Model\Quote\Item\CartItemPersister and implement your changes there. This can get messy when the parent class implements a lot of private methods which usually means that you need to copy the parent class to the subclass and then add your customizations on top.

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.