Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
discount_10percent.php
Go to the documentation of this file.
1 <?php
11 $salesRuleFactory = $objectManager->get(\Magento\SalesRule\Model\RuleFactory::class);
12 
15 
16 $data = [
17  'name' => 'Test Coupon',
18  'is_active' => true,
19  'website_ids' => [
21  \Magento\Store\Model\StoreManagerInterface::class
22  )->getStore()->getWebsiteId()
23  ],
26  'coupon_code' => uniqid(),
28  'discount_amount' => 10,
29  'discount_step' => 1
30 ];
31 
32 $salesRule->loadPost($data)->setUseAutoGeneration(false)->save();
33 $objectManager->get(\Magento\Framework\Registry::class)->unregister('Magento/Checkout/_file/discount_10percent');
34 $objectManager->get(\Magento\Framework\Registry::class)
35  ->register('Magento/Checkout/_file/discount_10percent', $salesRule->getRuleId());
$salesRuleFactory
$objectManager