Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
rule_by_attribute.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',
13  'is_active' => '1',
14  'stop_rules_processing' => 0,
15  'website_ids' => [1],
16  'customer_group_ids' => [0, 1],
17  'discount_amount' => 2,
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  ],
31  '1--1' => [
32  'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
33  'attribute' => 'test_attribute',
34  'operator' => '==',
35  'value' => 'test_attribute_value',
36  ],
37  ],
38 ]);
39 $rule->save();