I try to add a new product in a afterSave plugin for Magento\Quote\Api\CartItemRepositoryInterface, but I get:

Type Error occurred when creating object: Company\Quote\Plugin\RalSpecialColorPriceSurcharge, Argument 3 passed to Company\Quote\Plugin\RalSpecialColorPriceSurcharge::__construct() must be an instance of Magento\Catalog\Model\ProductFactory, instance of Magento\Framework\App\Config given, called


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Quote\Api\CartItemRepositoryInterface">
        <plugin name="company_quote_ral_specialcolor_price_surcharge" 



namespace Company\Quote\Plugin;

use \Magento\Catalog\Model\ProductFactory;

class RalSpecialColorPriceSurcharge
     * @var Company\Quote\Model\Config\Settings
    private $settings;

    public function __construct(
        \Magento\Catalog\Model\ProductFactory $productFactory,
    ) {
        $this->productFactory = $productFactory;

  • What is your plugin method, show that?
    – Sohel Rana
    Commented Nov 5, 2020 at 14:35
  • It is not relevant, it breaks in the constructor already, I am not even using the productFactory in the plugin method yet. If I remove it from the constructor then the code works again.
    – Black
    Commented Nov 5, 2020 at 14:41

1 Answer 1


I figured it out. The problem was, that I executed bin/magento setup:di:compile earlier, which means that the code is getting compiled into the static files and loaded from there.

So if you call it once, then you always have to call it again after making changes to the constructor.

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.