Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
cart_rule_free_shipping.php
Go to the documentation of this file.
1 <?php
8 
9 $salesRuleFactory = $objectManager->create(\Magento\SalesRule\Model\RuleFactory::class);
13  [
14  'name' => 'Free shipping if item price >10',
15  'is_active' => 1,
18  'conditions' => [
19  1 =>
20  [
21  'type' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
22  'attribute' => null,
23  'operator' => null,
24  'value' => '1',
25  'is_value_processed' => null,
26  'aggregator' => 'all',
27  ]
28 
29  ],
30  'actions' => [
31  1 => [
32  'type' => Magento\SalesRule\Model\Rule\Condition\Product\Combine::class,
33  'attribute' => null,
34  'operator' => null,
35  'value' => '1',
36  'is_value_processed' => null,
37  'aggregator' => 'all',
38  'conditions' => [
39  [
40  'type' => Magento\SalesRule\Model\Rule\Condition\Product::class,
41  'attribute' => 'quote_item_price',
42  'operator' => '==',
43  'value' => '7',
44  'is_value_processed' => false,
45  ]
46  ]
47  ]
48  ],
49  'is_advanced' => 1,
50  'simple_action' => 'by_percent',
51  'discount_amount' => 0,
52  'stop_rules_processing' => 0,
53  'discount_qty' => 0,
54  'discount_step' => 0,
55  'apply_to_shipping' => 1,
56  'times_used' => 0,
57  'is_rss' => 1,
58  'use_auto_generation' => 0,
59  'uses_per_coupon' => 0,
60  'simple_free_shipping' => 1,
61 
62  'website_ids' => [
64  \Magento\Store\Model\StoreManagerInterface::class
65  )->getWebsite()->getId()
66  ]
67  ];
68 $salesRule->loadPost($row);
69 $salesRule->save();
71 $registry = $objectManager->get(\Magento\Framework\Registry::class);
72 
73 $registry->unregister('cart_rule_free_shipping');
74 $registry->register('cart_rule_free_shipping', $salesRule);