Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
cart_rule_100_percent_off.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
10 $registry = $objectManager->get(\Magento\Framework\Registry::class);
11 
13 $salesRule = $objectManager->create(\Magento\SalesRule\Model\Rule::class);
14 $salesRule->setData(
15  [
16  'name' => '100% Off for all orders',
17  'is_active' => 1,
18  'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID],
19  'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON,
20  'conditions' => [],
21  'simple_action' => 'by_percent',
22  'discount_amount' => 100,
23  'discount_step' => 0,
24  'stop_rules_processing' => 1,
25  'website_ids' => [
26  \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
27  \Magento\Store\Model\StoreManagerInterface::class
28  )->getWebsite()->getId(),
29  ],
30  'discount_qty' => 0,
31  'apply_to_shipping' => 1,
32  'simple_free_shipping' => 1,
33  ]
34 );
35 $salesRule->save();
36 $registry->unregister('Magento/SalesRule/_files/cart_rule_100_percent_off');
37 $registry->register('Magento/SalesRule/_files/cart_rule_100_percent_off', $salesRule->getRuleId());