Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
rules_group_any_categories_price_address.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' => 'any',
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  ],
54  [
55  'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
56  'attribute' => 'payment_method',
57  'operator' => '==',
58  'value' => 'braintree_paypal'
59  ],
60  [
61  'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
62  'attribute' => 'shipping_method',
63  'operator' => '==',
64  'value' => 'fedex_FEDEX_2_DAY'
65  ],
66  [
67  'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
68  'attribute' => 'postcode',
69  'operator' => '==',
70  'value' => '78000'
71  ],
72  [
73  'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
74  'attribute' => 'region',
75  'operator' => '==',
76  'value' => 'HD'
77  ],
78  [
79  'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
80  'attribute' => 'region_id',
81  'operator' => '==',
82  'value' => '56'
83  ],
84  [
85  'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
86  'attribute' => 'country_id',
87  'operator' => '==',
88  'value' => 'US'
89  ]
90  ],
91 ]);
92 
93 $salesRule->save();
94 
97 
98 $registry->unregister('_fixture/Magento_SalesRule_Group_Multiple_Categories');
99 $registry->register('_fixture/Magento_SalesRule_Group_Multiple_Categories', $salesRule);