Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
rules_categories.php
Go to the documentation of this file.
1 <?php
9 $salesRule->setData(
10  [
11  'name' => '50% Off on Large Orders',
12  'is_active' => 1,
13  'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID],
14  'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON,
15  'simple_action' => 'by_percent',
16  'discount_amount' => 50,
17  'discount_step' => 0,
18  'stop_rules_processing' => 1,
19  'website_ids' => [
20  \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
21  \Magento\Store\Model\StoreManagerInterface::class
22  )->getWebsite()->getId()
23  ]
24  ]
25 );
26 
27 $salesRule->getConditions()->loadArray([
28  'type' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
29  'attribute' => null,
30  'operator' => null,
31  'value' => '1',
32  'is_value_processed' => null,
33  'aggregator' => 'all',
34  'conditions' =>
35  [
36  [
37  'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
38  'attribute' => null,
39  'operator' => null,
40  'value' => '1',
41  'is_value_processed' => null,
42  'aggregator' => 'all',
43  'conditions' =>
44  [
45  [
46  'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
47  'attribute' => 'category_ids',
48  'operator' => '==',
49  'value' => '2',
50  'is_value_processed' => false,
51  ],
52  [
53  'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
54  'attribute' => 'category_ids',
55  'operator' => '==',
56  'value' => '3',
57  'is_value_processed' => false,
58  ],
59  ],
60  ],
61  ],
62 ]);
63 
64 $salesRule->save();
65 
68 
69 $registry->unregister('_fixture/Magento_SalesRule_Multiple_Categories');
70 $registry->register('_fixture/Magento_SalesRule_Multiple_Categories', $salesRule);
$salesRule