/** * Create selection price list for the retrieved options * * @param \Magento\Bundle\Model\Option $option * @param Product $bundleProduct * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] */ public function createSelectionPriceList($option, $bundleProduct) { $priceList = []; $selections = $option->getSelections(); if ($selections === null) { return $priceList; } /* @var $selection \Magento\Bundle\Model\Selection|\Magento\Catalog\Model\Product */ foreach ($selections as $selection) { if (!$selection->isSalable()) { // @todo CatalogInventory Show out of stock Products continue; } $priceList[] = $this->selectionFactory->create($bundleProduct, $selection, $selection->getSelectionQty()); } return $priceList; }
/** * @dataProvider getTestDataForCalculation */ public function testCalculation($optionList, $expected) { $storeId = 1; $this->saleableItemMock->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $this->selectionFactoryMock->expects($this->any())->method('create')->will($this->returnArgument(1)); $this->baseCalculator->expects($this->atLeastOnce())->method('getAmount')->will($this->returnValue($this->createAmountMock(['amount' => 0.0]))); $options = []; foreach ($optionList as $optionData) { $options[] = $this->createOptionMock($optionData); } /** @var \PHPUnit_Framework_MockObject_MockObject $optionsCollection */ $optionsCollection = $this->getMock('Magento\\Bundle\\Model\\Resource\\Option\\Collection', [], [], '', false); $optionsCollection->expects($this->atLeastOnce())->method('appendSelections')->will($this->returnSelf()); $optionsCollection->expects($this->atLeastOnce())->method('getIterator')->will($this->returnValue(new \ArrayIterator($options))); /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Type\AbstractType $typeMock */ $typeMock = $this->getMock('Magento\\Bundle\\Model\\Product\\Type', [], [], '', false); $typeMock->expects($this->any())->method('setStoreFilter')->with($storeId, $this->saleableItemMock); $typeMock->expects($this->any())->method('getOptionsCollection')->with($this->saleableItemMock)->will($this->returnValue($optionsCollection)); $this->saleableItemMock->expects($this->any())->method('getTypeInstance')->will($this->returnValue($typeMock)); $this->assertEquals($expected['min'], $this->bundleOptionPrice->getValue()); $this->assertEquals($expected['max'], $this->bundleOptionPrice->getMaxValue()); }
/** * @expectedException \InvalidArgumentException */ public function testCreateException() { $this->objectManagerMock->expects($this->once())->method('create')->with($this->equalTo(BundleSelectionFactory::SELECTION_CLASS_DEFAULT), $this->equalTo(['test' => 'some value', 'bundleProduct' => $this->bundleMock, 'saleableItem' => $this->selectionMock, 'quantity' => 2.0]))->will($this->returnValue(new \stdClass())); $this->bundleSelectionFactory->create($this->bundleMock, $this->selectionMock, 2.0, ['test' => 'some value']); }
/** * Get selection amount * * @param \Magento\Bundle\Model\Selection $selection * @return \Magento\Framework\Pricing\Amount\AmountInterface */ public function getOptionSelectionAmount($selection) { $selectionPrice = $this->selectionFactory->create($this->product, $selection, $selection->getSelectionQty()); return $selectionPrice->getAmount(); }