Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
rules_category.php
Go to the documentation of this file.
1 <?php
9 $salesRule->setData(
10  [
11  'name' => '50% Off on Large Orders',
12  'is_active' => 1,
13  'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID],
14  'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON,
15  'simple_action' => 'by_percent',
16  'discount_amount' => 50,
17  'discount_step' => 0,
18  'stop_rules_processing' => 1,
19  'website_ids' => [
20  \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
21  \Magento\Store\Model\StoreManagerInterface::class
22  )->getWebsite()->getId()
23  ]
24  ]
25 );
26 
27 $salesRule->getConditions()->loadArray([
28  'type' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
29  'attribute' => null,
30  'operator' => null,
31  'value' => '1',
32  'is_value_processed' => null,
33  'aggregator' => 'all',
34  'conditions' =>
35  [
36  [
37  'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
38  'attribute' => null,
39  'operator' => null,
40  'value' => '1',
41  'is_value_processed' => null,
42  'aggregator' => 'all',
43  'conditions' =>
44  [
45  [
46  'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
47  'attribute' => 'category_ids',
48  'operator' => '==',
49  'value' => '66',
50  'is_value_processed' => false,
51  ],
52  ],
53  ],
54  ],
55 ]);
56 
57 $salesRule->save();
58 
60 $category->isObjectNew(true);
61 $category->setId(
62  66
63 )->setCreatedAt(
64  '2014-06-23 09:50:07'
65 )->setName(
66  'Category 1'
67 )->setParentId(
68  2
69 )->setPath(
70  '1/2/333'
71 )->setLevel(
72  2
73 )->setAvailableSortBy(
74  ['position', 'name']
75 )->setDefaultSortBy(
76  'name'
77 )->setIsActive(
78  true
79 )->setPosition(
80  1
81 )->save();
82 
85 
86 $registry->unregister('_fixture/Magento_SalesRule_Category');
87 $registry->register('_fixture/Magento_SalesRule_Category', $salesRule);
$registry
$salesRule
$category