Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_has_tier_price_show_as_low_as.php
Go to the documentation of this file.
1 <?php
7 use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
8 
10 
13 
16 $tierPriceFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory::class);
18  [
19  'data' => [
20  'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL,
21  'qty' => 2,
22  'value' => 8
23  ]
24  ]
25 );
26 $tierPrices[] = $tierPriceFactory->create(
27  [
28  'data' => [
29  'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL,
30  'qty' => 5,
31  'value' => 5
32  ]
33  ]
34 );
35 $tierPrices[] = $tierPriceFactory->create(
36  [
37  'data' => [
38  'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
39  'qty' => 3,
40  'value' => 5
41  ]
42  ]
43 );
44 
46 $tpExtensionAttributesFactory = $objectManager->create(ProductTierPriceExtensionFactory::class);
47 $tpExtensionAttributes = $tpExtensionAttributesFactory->create()->setPercentageValue(50);
48 
49 $tierPrices[] = $tierPriceFactory->create(
50  [
51  'data' => [
52  'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
53  'qty' => 10
54  ]
55  ]
56 )->setExtensionAttributes($tpExtensionAttributes);
57 
59 $product = $objectManager->create(\Magento\Catalog\Model\Product::class);
60 $product->isObjectNew(true);
61 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
62  ->setAttributeSetId(4)
63  ->setWebsiteIds([1])
64  ->setName('Simple Product')
65  ->setSku('tier_prices')
66  ->setPrice(10)
67  ->setWeight(1)
68  ->setShortDescription("Short description")
69  ->setTaxClassId(0)
70  ->setTierPrices($tierPrices)
71  ->setDescription('Description with <b>html tag</b>')
72  ->setMetaTitle('meta title')
73  ->setMetaKeyword('meta keyword')
74  ->setMetaDescription('meta description')
75  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
76  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
77  ->setStockData(
78  [
79  'use_config_manage_stock' => 1,
80  'qty' => 100,
81  'is_qty_decimal' => 0,
82  'is_in_stock' => 1,
83  ]
84  );
85 
87 $productRepositoryFactory = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);