Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_with_tier_pricing.php
Go to the documentation of this file.
1 <?php
7 /*
8  * Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
9  * bundled items should not contain products with required custom options.
10  * However, if to create such a bundle product, it will be always out of stock.
11  */
12 require __DIR__ . '/../../../Magento/Catalog/_files/products.php';
13 
16 $product->setTypeId('bundle')
17  ->setAttributeSetId(4)
18  ->setWebsiteIds([1])
19  ->setName('Bundle Product')
20  ->setSku('bundle-product')
21  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
22  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
23  ->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
24  ->setBundleOptionsData(
25  [
26  [
27  'title' => 'Bundle Product Items',
28  'default_title' => 'Bundle Product Items',
29  'type' => 'select', 'required' => 1,
30  'delete' => '',
31  ],
32  ]
33  )
34  ->setBundleSelectionsData(
35  [[['product_id' => 1, 'selection_qty' => 1, 'selection_can_change_qty' => 1, 'delete' => '']]]
36  // fixture product
37  )->setTierPrice(
38  [
39  [
40  'website_id' => 0,
41  'cust_group' => \Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL,
42  'price_qty' => 2,
43  'price' => 8,
44  'percentage_value' => 8
45  ],
46  [
47  'website_id' => 0,
48  'cust_group' => \Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL,
49  'price_qty' => 5,
50  'price' => 30,
51  'percentage_value' => 30
52  ],
53  [
54  'website_id' => 0,
55  'cust_group' => \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID,
56  'price_qty' => 3,
57  'price' => 20,
58  'percentage_value' => 20
59  ],
60  ]
61  )
62  ->save();
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60