Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SimpleWithOptionsTierPriceWithDimensionTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
14 use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
17 
21 class SimpleWithOptionsTierPriceWithDimensionTest extends \PHPUnit\Framework\TestCase
22 {
26  private $productRepository;
27 
31  private $objectManager;
32 
36  private $productCollectionFactory;
37 
41  protected function setUp()
42  {
43  $this->objectManager = Bootstrap::getObjectManager();
44  $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
45  $this->productCollectionFactory = $this->objectManager->create(CollectionFactory::class);
46  }
47 
53  public function testTierPrice()
54  {
55  $tierPriceValue = 9.00;
56 
57  $tierPrice = $this->objectManager->create(ProductTierPriceInterfaceFactory::class)
58  ->create();
59  $tierPrice->setCustomerGroupId(Group::CUST_GROUP_ALL);
60  $tierPrice->setQty(1.00);
61  $tierPrice->setValue($tierPriceValue);
62  $tierPriceManagement = $this->objectManager->create(ScopedProductTierPriceManagementInterface::class);
63  $tierPriceManagement->add('simple333', $tierPrice);
64 
65  $productCollection = $this->productCollectionFactory->create();
66  $productCollection->addIdFilter(333);
67  $productCollection->addPriceData();
68  $productCollection->load();
70  $product = $productCollection->getFirstItem();
71  $tierPrice = $product->getPriceInfo()
72  ->getPrice(TierPrice::PRICE_CODE)
73  ->getValue();
74 
75  $this->assertEquals($tierPriceValue, $tierPrice);
76 
77  $tierPrice = $product->getTierPrice(1);
78  $this->assertEquals($tierPriceValue, $tierPrice);
79 
80  $tierPrices = $product->getData('tier_price');
81  $this->assertEquals($tierPriceValue, $tierPrices[0]['price']);
82 
83  $minPrice = $product->getData('min_price');
84  $this->assertEquals($tierPriceValue, $minPrice);
85  }
86 }