File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
dev/tests/integration/testsuite/Magento/SalesRule/_files Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 66
77declare (strict_types=1 );
88
9+ use Magento \Framework \Api \Search \FilterGroup ;
10+ use Magento \Framework \Api \SearchCriteriaInterface ;
911use Magento \Framework \Exception \NoSuchEntityException ;
1012use Magento \Framework \Registry ;
1113use Magento \SalesRule \Api \RuleRepositoryInterface ;
1921/** @var RuleRepositoryInterface $ruleRepository */
2022$ ruleRepository = $ bootstrap ->get (RuleRepositoryInterface::class);
2123
22- $ ruleId = $ registry ->registry ('Magento/SalesRule/_files/cart_rule_40_percent_off ' );
23- if ($ ruleId ) {
24+ $ salesRuleName = '40% Off on Large Orders ' ;
25+ $ filterGroup = $ bootstrap ->get (FilterGroup::class);
26+ $ filterGroup ->setData ('name ' , $ salesRuleName );
27+ $ searchCriteria = $ bootstrap ->create (SearchCriteriaInterface::class);
28+ $ searchCriteria ->setFilterGroups ([$ filterGroup ]);
29+ $ items = $ ruleRepository ->getList ($ searchCriteria )->getItems ();
30+ if ($ items ) {
2431 try {
25- $ ruleRepository ->deleteById ($ ruleId );
26- $ registry ->unregister ('Magento/SalesRule/_files/cart_rule_40_percent_off ' );
32+ foreach ($ items as $ item ) {
33+ $ ruleRepository ->deleteById ($ item ->getRuleId ());
34+ }
2735 } catch (NoSuchEntityException $ e ) {
2836 }
2937}
You can’t perform that action at this time.
0 commit comments