/** * @param \Magento\Catalog\Api\Data\ProductInterface $product * @return \Magento\Bundle\Api\Data\OptionInterface[] */ public function getItems(\Magento\Catalog\Api\Data\ProductInterface $product) { $optionCollection = $this->type->getOptionsCollection($product); $optionList = []; /** @var \Magento\Bundle\Model\Option $option */ foreach ($optionCollection as $option) { $productLinks = $this->linkList->getItems($product, $option->getOptionId()); /** @var \Magento\Bundle\Api\Data\OptionInterface $optionDataObject */ $optionDataObject = $this->optionFactory->create(); $this->dataObjectHelper->populateWithArray($optionDataObject, $option->getData(), '\\Magento\\Bundle\\Api\\Data\\OptionInterface'); $optionDataObject->setOptionId($option->getOptionId())->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())->setSku($product->getSku())->setProductLinks($productLinks); $optionList[] = $optionDataObject; } return $optionList; }
public function testLinksList() { $optionId = 665; $this->productTypeMock->expects($this->once())->method('getSelectionsCollection')->with([$optionId], $this->productMock)->willReturn([$this->selectionMock]); $this->productMock->expects($this->exactly(2))->method('getPriceType')->willReturn('price_type'); $this->selectionMock->expects($this->once())->method('getSelectionPriceType')->willReturn('selection_price_type'); $this->selectionMock->expects($this->once())->method('getSelectionPriceValue')->willReturn(12); $this->selectionMock->expects($this->once())->method('getData')->willReturn(['some data']); $this->selectionMock->expects($this->once())->method('getIsDefault')->willReturn(true); $this->selectionMock->expects($this->once())->method('getSelectionQty')->willReturn(66); $this->selectionMock->expects($this->once())->method('getSelectionCanChangeQty')->willReturn(22); $this->linkBuilderMock->expects($this->once())->method('populateWithArray')->with(['some data'])->willReturnSelf(); $this->linkBuilderMock->expects($this->once())->method('setIsDefault')->with(true)->willReturnSelf(); $this->linkBuilderMock->expects($this->once())->method('setQty')->with(66)->willReturnSelf(); $this->linkBuilderMock->expects($this->once())->method('setIsDefined')->with(22)->willReturnSelf(); $this->linkBuilderMock->expects($this->once())->method('setPrice')->with(12)->willReturnSelf(); $this->linkBuilderMock->expects($this->once())->method('setPriceType')->with('selection_price_type')->willReturnSelf(); $this->linkBuilderMock->expects($this->once())->method('create')->willReturnSelf(); $this->assertEquals([$this->linkBuilderMock], $this->model->getItems($this->productMock, $optionId)); }