Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
two_rules.php
Go to the documentation of this file.
1 <?php
8 
10 $rule = Bootstrap::getObjectManager()->get(\Magento\CatalogRule\Model\RuleFactory::class)->create();
11 $rule->loadPost([
12  'name' => 'test_rule_one',
13  'is_active' => '1',
14  'stop_rules_processing' => 0,
15  'website_ids' => [1],
16  'customer_group_ids' => [0, 1],
17  'discount_amount' => 5,
18  'simple_action' => 'by_percent',
19  'from_date' => '',
20  'to_date' => '',
21  'sort_order' => 0,
22  'sub_is_enable' => 0,
23  'sub_discount_amount' => 0,
24  'conditions' => [
25  '1' => [
26  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
27  'aggregator' => 'all',
28  'value' => '1',
29  'new_child' => '',
30  'attribute' => null,
31  'operator' => null,
32  'is_value_processed' => null,
33  ],
34  ],
35 ]);
36 $rule->save();
37 $rule = Bootstrap::getObjectManager()->get(\Magento\CatalogRule\Model\RuleFactory::class)->create();
38 $rule->loadPost([
39  'name' => 'test_rule_two',
40  'is_active' => '1',
41  'stop_rules_processing' => 0,
42  'website_ids' => [1],
43  'customer_group_ids' => [0, 1],
44  'discount_amount' => 2,
45  'simple_action' => 'by_fixed',
46  'from_date' => '',
47  'to_date' => '',
48  'sort_order' => 0,
49  'sub_is_enable' => 0,
50  'sub_discount_amount' => 0,
51  'conditions' => [
52  '1' => [
53  'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
54  'aggregator' => 'all',
55  'value' => '1',
56  'new_child' => '',
57  'attribute' => null,
58  'operator' => null,
59  'is_value_processed' => null,
60  ],
61  ],
62  ]);
63 $rule->save();
$rule
Definition: two_rules.php:10