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 6
6
7
7
declare (strict_types=1 );
8
8
9
+ use Magento \Framework \Api \Search \FilterGroup ;
10
+ use Magento \Framework \Api \SearchCriteriaInterface ;
9
11
use Magento \Framework \Exception \NoSuchEntityException ;
10
12
use Magento \Framework \Registry ;
11
13
use Magento \SalesRule \Api \RuleRepositoryInterface ;
19
21
/** @var RuleRepositoryInterface $ruleRepository */
20
22
$ ruleRepository = $ bootstrap ->get (RuleRepositoryInterface::class);
21
23
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 ) {
24
31
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
+ }
27
35
} catch (NoSuchEntityException $ e ) {
28
36
}
29
37
}
You can’t perform that action at this time.
0 commit comments