コード例 #1
0
 public function testGetJsonConfigFixedPriceBundle()
 {
     $baseAmount = 123;
     $basePriceValue = 123123;
     $selections = [$this->createOptionSelection(1123, 'Selection 1', 23, [['price' => new MagentoObject(['base_amount' => $baseAmount, 'value' => $basePriceValue])]], true, true)];
     $bundleProductPrice = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Product\\Price')->disableOriginalConstructor()->setMethods(['getLowestPrice'])->getMock();
     $bundleProductPrice->expects($this->at(0))->method('getLowestPrice')->with($this->product, $baseAmount)->will($this->returnValue(999));
     $bundleProductPrice->expects($this->at(1))->method('getLowestPrice')->with($this->product, $basePriceValue)->will($this->returnValue(888));
     $this->bundleProductPriceFactory->expects($this->once())->method('create')->will($this->returnValue($bundleProductPrice));
     $options = [$this->createOption(1, 'Title `1', $selections)];
     $finalPriceMock = $this->getPriceMock(['getPriceWithoutOption' => new MagentoObject(['value' => 100, 'base_amount' => 100])]);
     $regularPriceMock = $this->getPriceMock(['getAmount' => new MagentoObject(['value' => 110, 'base_amount' => 110])]);
     $prices = ['bundle_option' => $this->getAmountPriceMock($baseAmount, $regularPriceMock, [['item' => $selections[0], 'value' => $basePriceValue, 'base_amount' => 321321]]), \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE => $finalPriceMock, \Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE => $regularPriceMock];
     $priceInfo = $this->getPriceInfoMock($prices);
     $this->product->expects($this->once())->method('hasPreconfiguredValues')->will($this->returnValue(true));
     $preconfiguredValues = new \Magento\Framework\DataObject(['bundle_option' => [1 => 123123111]]);
     $this->product->expects($this->once())->method('getPreconfiguredValues')->will($this->returnValue($preconfiguredValues));
     $this->_bundleBlock = $this->setupBundleBlock($options, $priceInfo, \Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED);
     $jsonConfig = $this->_bundleBlock->getJsonConfig();
     $this->assertEquals(110, $jsonConfig['prices']['oldPrice']['amount']);
     $this->assertEquals(100, $jsonConfig['prices']['basePrice']['amount']);
     $this->assertEquals(100, $jsonConfig['prices']['finalPrice']['amount']);
 }