Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SimpleWithOptionsTierPriceTest.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
12 use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
15 
16 class SimpleWithOptionsTierPriceTest extends \PHPUnit\Framework\TestCase
17 {
21  private $productRepository;
22 
26  private $objectManager;
27 
31  private $productCollectionFactory;
32 
33  protected function setUp()
34  {
35  $this->objectManager = Bootstrap::getObjectManager();
36  $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
37  $this->productCollectionFactory = $this->objectManager->create(CollectionFactory::class);
38  }
39 
44  public function testTierPrice()
45  {
46  $tierPriceValue = 9.00;
47 
48  $tierPrice = $this->objectManager->create(ProductTierPriceInterfaceFactory::class)
49  ->create();
50  $tierPrice->setCustomerGroupId(Group::CUST_GROUP_ALL);
51  $tierPrice->setQty(1.00);
52  $tierPrice->setValue($tierPriceValue);
53  $tierPriceManagement = $this->objectManager->create(ScopedProductTierPriceManagementInterface::class);
54  $tierPriceManagement->add('simple333', $tierPrice);
55 
56  $productCollection = $this->productCollectionFactory->create();
57  $productCollection->addIdFilter(333);
58  $productCollection->addPriceData();
59  $productCollection->load();
61  $product = $productCollection->getFirstItem();
62  $tierPrice = $product->getPriceInfo()
63  ->getPrice(TierPrice::PRICE_CODE)
64  ->getValue();
65 
66  $this->assertEquals($tierPriceValue, $tierPrice);
67 
68  $tierPrice = $product->getTierPrice(1);
69  $this->assertEquals($tierPriceValue, $tierPrice);
70 
71  $tierPrices = $product->getData('tier_price');
72  $this->assertEquals($tierPriceValue, $tierPrices[0]['price']);
73 
74  $minPrice = $product->getData('min_price');
75  $this->assertEquals($tierPriceValue, $minPrice);
76  }
77 }