コード例 #1
0
 public function testGetItems()
 {
     $optionId = 1;
     $optionData = ['title' => 'test title'];
     $productSku = 'product_sku';
     $productMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductInterface');
     $productMock->expects($this->once())->method('getSku')->willReturn($productSku);
     $optionMock = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getOptionId', 'getData', 'getTitle', 'getDefaultTitle'], [], '', false);
     $optionsCollMock = $this->objectManager->getCollectionMock('Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', [$optionMock]);
     $this->typeMock->expects($this->once())->method('getOptionsCollection')->with($productMock)->willReturn($optionsCollMock);
     $optionMock->expects($this->exactly(2))->method('getOptionId')->willReturn($optionId);
     $optionMock->expects($this->once())->method('getData')->willReturn($optionData);
     $optionMock->expects($this->once())->method('getTitle')->willReturn(null);
     $optionMock->expects($this->once())->method('getDefaultTitle')->willReturn($optionData['title']);
     $linkMock = $this->getMock('\\Magento\\Bundle\\Api\\Data\\LinkInterface');
     $this->linkListMock->expects($this->once())->method('getItems')->with($productMock, $optionId)->willReturn([$linkMock]);
     $newOptionMock = $this->getMock('\\Magento\\Bundle\\Api\\Data\\OptionInterface');
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray')->with($newOptionMock, $optionData, '\\Magento\\Bundle\\Api\\Data\\OptionInterface')->willReturnSelf();
     $newOptionMock->expects($this->once())->method('setOptionId')->with($optionId)->willReturnSelf();
     $newOptionMock->expects($this->once())->method('setTitle')->with($optionData['title'])->willReturnSelf();
     $newOptionMock->expects($this->once())->method('setSku')->with($productSku)->willReturnSelf();
     $newOptionMock->expects($this->once())->method('setProductLinks')->with([$linkMock])->willReturnSelf();
     $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($newOptionMock);
     $this->assertEquals([$newOptionMock], $this->model->getItems($productMock));
 }
コード例 #2
0
 /**
  * @param \Magento\Catalog\Model\Product $subject
  * @param callable $proceed
  * @param int $modelId
  * @param null $field
  * @return \Magento\Catalog\Model\Product
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundLoad(\Magento\Catalog\Model\Product $subject, \Closure $proceed, $modelId, $field = null)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $proceed($modelId, $field);
     if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
         return $product;
     }
     $productExtension = $this->productExtensionFactory->create();
     $productExtension->setBundleProductOptions($this->productOptionList->getItems($product));
     $product->setExtensionAttributes($productExtension);
     return $product;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function getList($sku)
 {
     $product = $this->getProduct($sku);
     return $this->productOptionList->getItems($product);
 }
コード例 #4
0
 /**
  * @param ProductInterface $product
  * @return \Magento\Bundle\Api\Data\OptionInterface[]
  */
 public function getListByProduct(ProductInterface $product)
 {
     return $this->productOptionList->getItems($product);
 }