1

I'm trying to override following class

Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor

Using below code

<preference for="Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor"
                type="Vendor\Module\Model\Indexer\RuleProductPricesPersistor" />

But I'm getting following error

Type Error occurred when creating object: Magento\CatalogRule\Model\Indexer\ReindexRuleProductPrice, Argument 5 passed to Magento\CatalogRule\Model\Indexer\ReindexRuleProductPrice::__construct() must be an instance of Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor, instance of Vendor\Module\Model\Indexer\RuleProductPricesPersistor given, called in /var/www/html/MagentoCE230/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 116 [] []

I tried to clear generation folder and also ran setup:di:compile command. But it didn't work.

  • 1
    please add Vendor\Module\Model\Indexer\RuleProductPricesPersistor.php code Here – Waqar Ali Jul 30 at 9:24
  • are you trying to do a plugin or over write/preference? also can you add your construct method to the question – Korbin Jul 30 at 9:27
0
Vendor\Module\Model\Indexer\RuleProductPricesPersistor.php

Your child class should be like this

<?PHP

 use Magento\CatalogRule\Model\Indexer\IndexerTableSwapperInterface as TableSwapper;
 use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
 use Magento\Framework\App\ObjectManager;

class RuleProductPricesPersistor extends \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor
{

    public function __construct(
        \Magento\Framework\Stdlib\DateTime $dateFormat,
        \Magento\Framework\App\ResourceConnection $resource,
        ActiveTableSwitcher $activeTableSwitcher,
        TableSwapper $tableSwapper = null
    ) {
        parent:: __construct($dateFormat ,$resource , $activeTableSwitcher, $tableSwapper ;);
    }

    // add overrided Functions Here 

}
| improve this answer | |
0

Your RuleProductPricesPersistor.php code must look like this.

<?php
namespace Vendor\Module\Model\Indexer;

use Magento\CatalogRule\Model\Indexer\IndexerTableSwapperInterface as TableSwapper;
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
use Magento\Framework\App\ObjectManager;

class RuleProductPricesPersistor extends \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor
{
   public function __construct(
        \Magento\Framework\Stdlib\DateTime $dateFormat,
        \Magento\Framework\App\ResourceConnection $resource,
        ActiveTableSwitcher $activeTableSwitcher,
        TableSwapper $tableSwapper = null
    ) {
        parent:: __construct($dateFormat ,$resource , $activeTableSwitcher, $tableSwapper);
    }
}
| improve this answer | |

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.