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;
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
add a comment |
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
add a comment |
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
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
magento2 database
asked Apr 25 at 6:49
Sudhanshu BajajSudhanshu Bajaj
556
556
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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"
];
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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"
];
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
add a comment |
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"
];
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
add a comment |
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"
];
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"
];
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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