public function testGetCollection()
 {
     $this->collectionMock->expects($this->once())->method('addAttributeToFilter');
     $this->productLinkRepositoryMock->expects($this->once())->method('getList')->willReturn([]);
     $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturn(1);
     $this->assertInstanceOf(Collection::class, $this->getModel()->getCollection());
 }
Пример #2
0
 /**
  * @param string $entityType
  * @param object $entity
  * @return \Magento\Catalog\Api\Data\ProductInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     /** @var \Magento\Catalog\Api\Data\ProductInterface $entity*/
     foreach ($this->productLinkRepository->getList($entity) as $link) {
         $this->productLinkRepository->delete($link);
     }
     foreach ($entity->getProductLinks() as $link) {
         $this->productLinkRepository->save($link);
     }
     return $entity;
 }
Пример #3
0
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->locatorMock = $this->getMockBuilder(LocatorInterface::class)->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['getId', 'getTypeId'])->getMockForAbstractClass();
     $this->productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID);
     $this->productMock->expects($this->any())->method('getTypeId')->willReturn(GroupedProductType::TYPE_CODE);
     $this->linkedProductMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['getId', 'getName', 'getPrice'])->getMockForAbstractClass();
     $this->linkedProductMock->expects($this->any())->method('getId')->willReturn(self::LINKED_PRODUCT_ID);
     $this->linkedProductMock->expects($this->any())->method('getName')->willReturn(self::LINKED_PRODUCT_NAME);
     $this->linkedProductMock->expects($this->any())->method('getPrice')->willReturn(self::LINKED_PRODUCT_PRICE);
     $this->linkMock = $this->getMockBuilder(ProductLinkInterface::class)->setMethods(['getLinkType', 'getLinkedProductSku', 'getPosition', 'getExtensionAttributes'])->getMockForAbstractClass();
     $this->linkExtensionMock = $this->getMockBuilder(ProductLinkExtensionInterface::class)->setMethods(['getQty'])->getMockForAbstractClass();
     $this->linkExtensionMock->expects($this->any())->method('getQty')->willReturn(self::LINKED_PRODUCT_QTY);
     $this->linkMock->expects($this->any())->method('getExtensionAttributes')->willReturn($this->linkExtensionMock);
     $this->linkMock->expects($this->any())->method('getPosition')->willReturn(self::LINKED_PRODUCT_POSITION);
     $this->linkMock->expects($this->any())->method('getLinkedProductSku')->willReturn(self::LINKED_PRODUCT_SKU);
     $this->linkMock->expects($this->any())->method('getLinkType')->willReturn(Grouped::LINK_TYPE);
     $this->linkRepositoryMock = $this->getMockBuilder(ProductLinkRepositoryInterface::class)->setMethods(['getList'])->getMockForAbstractClass();
     $this->linkRepositoryMock->expects($this->any())->method('getList')->with($this->productMock)->willReturn([$this->linkMock]);
     $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)->setMethods(['get'])->getMockForAbstractClass();
     $this->productRepositoryMock->expects($this->any())->method('get')->with(self::LINKED_PRODUCT_SKU)->willReturn($this->linkedProductMock);
     $this->storeMock = $this->getMockBuilder(StoreInterface::class)->setMethods(['getId'])->getMockForAbstractClass();
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->locatorMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
 }
Пример #4
0
 /**
  * Get product links info
  *
  * @return \Magento\Catalog\Api\Data\ProductLinkInterface[]
  */
 public function getProductLinks()
 {
     if ($this->_links === null) {
         $this->_links = $this->linkRepository->getList($this);
     }
     return $this->_links;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $productId = $product->getId();
     if (!$productId) {
         return $data;
     }
     $priceModifier = $this->getPriceModifier();
     /**
      * Set field name for modifier
      */
     $priceModifier->setData('name', 'price');
     foreach ($this->getDataScopes() as $dataScope) {
         $data[$productId]['links'][$dataScope] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== $dataScope) {
                 continue;
             }
             /** @var \Magento\Catalog\Model\Product $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId());
             $data[$productId]['links'][$dataScope][] = $this->fillData($linkedProduct, $linkItem);
         }
         if (!empty($data[$productId]['links'][$dataScope])) {
             $dataMap = $priceModifier->prepareDataSource(['data' => ['items' => $data[$productId]['links'][$dataScope]]]);
             $data[$productId]['links'][$dataScope] = $dataMap['data']['items'];
         }
     }
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId;
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId();
     return $data;
 }
 /**
  * Add specific filters
  *
  * @param Collection $collection
  * @return Collection
  */
 protected function addCollectionFilters(Collection $collection)
 {
     $relatedProducts = [];
     /** @var ProductLinkInterface $linkItem */
     foreach ($this->productLinkRepository->getList($this->getProduct()) as $linkItem) {
         if ($linkItem->getLinkType() !== $this->getLinkType()) {
             continue;
         }
         $relatedProducts[] = $this->productRepository->get($linkItem->getLinkedProductSku())->getId();
     }
     if ($relatedProducts) {
         $collection->addAttributeToFilter($collection->getIdFieldName(), ['nin' => [$relatedProducts]]);
     }
     return $collection;
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $modelId = $product->getId();
     if ($modelId) {
         $storeId = $this->locator->getStore()->getId();
         $data[$product->getId()]['links'][self::LINK_TYPE] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== self::LINK_TYPE) {
                 continue;
             }
             /** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId);
             $data[$modelId]['links'][self::LINK_TYPE][] = $this->fillData($linkedProduct, $linkItem);
         }
         $data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId;
     }
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $modelId = $product->getId();
     if ($modelId) {
         $storeId = $this->locator->getStore()->getId();
         /** @var \Magento\Framework\Currency $currency */
         $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode());
         $data[$product->getId()]['links'][self::LINK_TYPE] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== self::LINK_TYPE) {
                 continue;
             }
             /** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId);
             $data[$modelId]['links'][self::LINK_TYPE][] = ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()];
         }
         $data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId;
     }
     return $data;
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $productId = $product->getId();
     if (!$productId) {
         return $data;
     }
     foreach ($this->getDataScopes() as $dataScope) {
         $data[$productId]['links'][$dataScope] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== $dataScope) {
                 continue;
             }
             /** @var \Magento\Catalog\Model\Product $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId());
             $data[$productId]['links'][$dataScope][] = $this->fillData($linkedProduct, $linkItem);
         }
     }
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId;
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId();
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $productId = $product->getId();
     if (!$productId) {
         return $data;
     }
     foreach ($this->getDataScopes() as $dataScope) {
         $data[$productId]['links'][$dataScope] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== $dataScope) {
                 continue;
             }
             /** @var \Magento\Catalog\Model\Product $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId());
             $data[$productId]['links'][$dataScope][] = ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()];
         }
     }
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId;
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId();
     return $data;
 }