Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
rules_sku_exclude.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
11  ->create(\Magento\Eav\Api\AttributeRepositoryInterface::class);
12 
15  'catalog_product',
16  'sku'
17 );
18 $data = $skuAttribute->getData();
19 $data['is_used_for_promo_rules'] = 1;
20 $skuAttribute->setData($data);
21 $skuAttribute->save();
22 
25 $salesRule->setData(
26  [
27  'name' => '20% Off',
28  'is_active' => 1,
29  'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID],
30  'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON,
31  'simple_action' => 'by_percent',
32  'discount_amount' => 20,
33  'discount_step' => 0,
34  'stop_rules_processing' => 1,
35  'website_ids' => [
36  \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
37  \Magento\Store\Model\StoreManagerInterface::class
38  )->getWebsite()->getId(),
39  ],
40  ]
41 );
42 
43 $salesRule->getConditions()->loadArray([
44  'type' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
45  'attribute' => null,
46  'operator' => null,
47  'value' => '1',
48  'is_value_processed' => null,
49  'aggregator' => 'all',
50  'conditions' =>
51  [
52  [
53  'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
54  'attribute' => null,
55  'operator' => null,
56  'value' => '1',
57  'is_value_processed' => null,
58  'aggregator' => 'all',
59  'conditions' =>
60  [
61  [
62  'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
63  'attribute' => 'sku',
64  'operator' => '!=',
65  'value' => 'product-bundle',
66  'is_value_processed' => false,
67  ],
68  ],
69  ],
70  ],
71 ]);
72 
73 $salesRule->save();
74 
77 
78 $registry->unregister('_fixture/Magento_SalesRule_Sku_Exclude');
79 $registry->register('_fixture/Magento_SalesRule_Sku_Exclude', $salesRule);
$skuAttribute