Magento 2 : Delete all Calalog Price Rules ProgrammaticallyHow to override Catalog Price Rules?Reindex catalog rules eats up all the RAMIs there any API for creating and editing catalog price rules in Magento 2.2.xMagento Cart Price rulesHow to trigger custom field reindex for catalog product rules on product save?Magento 2: How to validate cart price rule in product view?Related Product Rules not showing up in magento2?Magento2 catalogrule promotions, ability to choose price or special_price?Possible to combine Category Rules with Cart Rules?Cannot select conditions for Cart and Catalog Price Rules

How do I tell my manager that he's wrong?

How to pass attribute when redirecting from lwc to aura component

Are Boeing 737-800’s grounded?

Single Colour Mastermind Problem

What is the difference between `a[bc]d` (brackets) and `ab,cd` (braces)?

Illegal assignment from SObject to Contact

How can I get precisely a certain cubic cm by changing the following factors?

When to use 1/Ka vs Kb

Find the coordinate of two line segments that are perpendicular

Is it possible to measure lightning discharges as Nikola Tesla?

Please, smoke with good manners

Did Henry V’s archers at Agincourt fight with no pants / breeches on because of dysentery?

What is a Recurrent Neural Network?

Does jamais mean always or never in this context?

Modify locally tikzset

How to create an ad-hoc wireless network in Ubuntu

In the time of the mishna, were there Jewish cities without courts?

Is it possible to Ready a spell to be cast just before the start of your next turn by having the trigger be an ally's attack?

You look catfish vs You look like a catfish

Any examples of headwear for races with animal ears?

How does a Swashbuckler rogue "fight with two weapons while safely darting away"?

Why do computer-science majors learn calculus?

Why does nature favour the Laplacian?

I listed a wrong degree date on my background check. What will happen?



Magento 2 : Delete all Calalog Price Rules Programmatically


How to override Catalog Price Rules?Reindex catalog rules eats up all the RAMIs there any API for creating and editing catalog price rules in Magento 2.2.xMagento Cart Price rulesHow to trigger custom field reindex for catalog product rules on product save?Magento 2: How to validate cart price rule in product view?Related Product Rules not showing up in magento2?Magento2 catalogrule promotions, ability to choose price or special_price?Possible to combine Category Rules with Cart Rules?Cannot select conditions for Cart and Catalog Price Rules






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















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









share|improve this question




























    1















    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









    share|improve this question
























      1












      1








      1








      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









      share|improve this question














      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






      magento2 database






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 25 at 6:49









      Sudhanshu BajajSudhanshu Bajaj

      556




      556




















          1 Answer
          1






          active

          oldest

          votes


















          2















          Custom action to delete all the rules




          Try following way:



          use MagentoCatalogRuleApiCatalogRuleRepositoryInterface;
          use MagentoCatalogRuleModelResourceModelRuleCollection as RuleCollection;
          use MagentoCatalogRuleModelResourceModelRuleCollectionFactory as RuleCollectionFactory;


          Di



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



          Now:



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



          OR




          Truncate all Catalog Price Rule tables




          /** @var array List of all the Catalog Price Rule tables */
          public $catalogrule_tables = [
          "catalogrule",
          "catalogrule_customer_group",
          "catalogrule_group_website",
          "catalogrule_group_website_replica",
          "catalogrule_product_price",
          "catalogrule_product_price_replica",
          "catalogrule_product",
          "catalogrule_product_replica",
          "catalogrule_website"
          ];





          share|improve this answer

























          • 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








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272372%2fmagento-2-delete-all-calalog-price-rules-programmatically%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2















          Custom action to delete all the rules




          Try following way:



          use MagentoCatalogRuleApiCatalogRuleRepositoryInterface;
          use MagentoCatalogRuleModelResourceModelRuleCollection as RuleCollection;
          use MagentoCatalogRuleModelResourceModelRuleCollectionFactory as RuleCollectionFactory;


          Di



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



          Now:



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



          OR




          Truncate all Catalog Price Rule tables




          /** @var array List of all the Catalog Price Rule tables */
          public $catalogrule_tables = [
          "catalogrule",
          "catalogrule_customer_group",
          "catalogrule_group_website",
          "catalogrule_group_website_replica",
          "catalogrule_product_price",
          "catalogrule_product_price_replica",
          "catalogrule_product",
          "catalogrule_product_replica",
          "catalogrule_website"
          ];





          share|improve this answer

























          • 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















          2















          Custom action to delete all the rules




          Try following way:



          use MagentoCatalogRuleApiCatalogRuleRepositoryInterface;
          use MagentoCatalogRuleModelResourceModelRuleCollection as RuleCollection;
          use MagentoCatalogRuleModelResourceModelRuleCollectionFactory as RuleCollectionFactory;


          Di



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



          Now:



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



          OR




          Truncate all Catalog Price Rule tables




          /** @var array List of all the Catalog Price Rule tables */
          public $catalogrule_tables = [
          "catalogrule",
          "catalogrule_customer_group",
          "catalogrule_group_website",
          "catalogrule_group_website_replica",
          "catalogrule_product_price",
          "catalogrule_product_price_replica",
          "catalogrule_product",
          "catalogrule_product_replica",
          "catalogrule_website"
          ];





          share|improve this answer

























          • 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













          2












          2








          2








          Custom action to delete all the rules




          Try following way:



          use MagentoCatalogRuleApiCatalogRuleRepositoryInterface;
          use MagentoCatalogRuleModelResourceModelRuleCollection as RuleCollection;
          use MagentoCatalogRuleModelResourceModelRuleCollectionFactory as RuleCollectionFactory;


          Di



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



          Now:



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



          OR




          Truncate all Catalog Price Rule tables




          /** @var array List of all the Catalog Price Rule tables */
          public $catalogrule_tables = [
          "catalogrule",
          "catalogrule_customer_group",
          "catalogrule_group_website",
          "catalogrule_group_website_replica",
          "catalogrule_product_price",
          "catalogrule_product_price_replica",
          "catalogrule_product",
          "catalogrule_product_replica",
          "catalogrule_website"
          ];





          share|improve this answer
















          Custom action to delete all the rules




          Try following way:



          use MagentoCatalogRuleApiCatalogRuleRepositoryInterface;
          use MagentoCatalogRuleModelResourceModelRuleCollection as RuleCollection;
          use MagentoCatalogRuleModelResourceModelRuleCollectionFactory as RuleCollectionFactory;


          Di



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



          Now:



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



          OR




          Truncate all Catalog Price Rule tables




          /** @var array List of all the Catalog Price Rule tables */
          public $catalogrule_tables = [
          "catalogrule",
          "catalogrule_customer_group",
          "catalogrule_group_website",
          "catalogrule_group_website_replica",
          "catalogrule_product_price",
          "catalogrule_product_price_replica",
          "catalogrule_product",
          "catalogrule_product_replica",
          "catalogrule_website"
          ];






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 25 at 9:31









          Sudhanshu Bajaj

          556




          556










          answered Apr 25 at 7:14









          Sohel RanaSohel Rana

          23.7k34461




          23.7k34461












          • 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

















          • 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
















          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





          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





          If any thirdparty module uses any event then this way well be safe.

          – Sohel Rana
          Apr 25 at 8:52

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272372%2fmagento-2-delete-all-calalog-price-rules-programmatically%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Sum ergo cogito? 1 nng

          419 nièngy_Soadمي 19bal1.5o_g

          Queiggey Chernihivv 9NnOo i Zw X QqKk LpB