Ejemplo n.º 1
0
 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);
     $linkMock = $this->getMock('Magento\\Bundle\\Api\\Data\\LinkInterface');
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray')->with($linkMock, ['some data'], '\\Magento\\Bundle\\Api\\Data\\LinkInterface')->willReturnSelf();
     $linkMock->expects($this->once())->method('setIsDefault')->with(true)->willReturnSelf();
     $linkMock->expects($this->once())->method('setQty')->with(66)->willReturnSelf();
     $linkMock->expects($this->once())->method('setIsDefined')->with(22)->willReturnSelf();
     $linkMock->expects($this->once())->method('setPrice')->with(12)->willReturnSelf();
     $linkMock->expects($this->once())->method('setPriceType')->with('selection_price_type')->willReturnSelf();
     $this->linkFactoryMock->expects($this->once())->method('create')->willReturn($linkMock);
     $this->assertEquals([$linkMock], $this->model->getItems($this->productMock, $optionId));
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function get($sku, $optionId)
 {
     $product = $this->getProduct($sku);
     /** @var \Magento\Bundle\Model\Option $option */
     $option = $this->type->getOptionsCollection($product)->getItemById($optionId);
     if (!$option || !$option->getId()) {
         throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
     }
     $productLinks = $this->linkList->getItems($product, $optionId);
     /** @var \Magento\Bundle\Api\Data\OptionInterface $option */
     $optionDataObject = $this->optionFactory->create();
     $this->dataObjectHelper->populateWithArray($optionDataObject, $option->getData(), '\\Magento\\Bundle\\Api\\Data\\OptionInterface');
     $optionDataObject->setOptionId($option->getId())->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())->setSku($product->getSku())->setProductLinks($productLinks);
     return $optionDataObject;
 }