I know we have Delete Rule option when we edit any Catalog Price Rule. But I need to delete all Calalog Price Rules programmatically because there is no option to delete all rules.

Solutions may be :

  • What if I truncate all the tables related to catalogrule and run indexer:reindex
  • Programmatically delete all rules and run indexer:reindex

Custom action to delete all the rules

Try following way:

use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface;
use Magento\CatalogRule\Model\ResourceModel\Rule\Collection as RuleCollection;
use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory as RuleCollectionFactory;


public function __construct(
    CatalogRuleRepositoryInterface $catalogRuleRepository,
    RuleCollectionFactory $ruleCollectionFactory
) {
    $this->catalogRuleRepository = $catalogRuleRepository;
    $this->ruleCollectionFactory = $ruleCollectionFactory;


/** @var RuleCollection $ruleCollection */
$ruleCollection = $this->ruleCollectionFactory->create();
foreach ($ruleCollection as $rule) {


Truncate all Catalog Price Rule tables

/** @var array List of all the Catalog Price Rule tables */
public $catalogrule_tables = [
  • Thanks Sohel Rana. What if we programmatically truncate all the catalogrule tables ? Will it be fast as well ? – Sudhanshu Bajaj Apr 25 at 7:41
  • If any thirdparty module uses any event then this way well be safe. – Sohel Rana Apr 25 at 8:52

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.