/** * Declare link model and initialize type attributes join * * @param \Magento\Catalog\Model\Product\Link $linkModel * @return $this */ public function setLinkModel(\Magento\Catalog\Model\Product\Link $linkModel) { $this->_linkModel = $linkModel; if ($linkModel->getLinkTypeId()) { $this->_linkTypeId = $linkModel->getLinkTypeId(); } return $this; }
public function testSaveProductRelations() { $data = [1]; $typeId = 1; $this->model->setData('link_type_id', $typeId); $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getRelatedLinkData', 'getUpSellLinkData', 'getCrossSellLinkData', '__wakeup'])->getMock(); $product->expects($this->any())->method('getRelatedLinkData')->will($this->returnValue($data)); $product->expects($this->any())->method('getUpSellLinkData')->will($this->returnValue($data)); $product->expects($this->any())->method('getCrossSellLinkData')->will($this->returnValue($data)); $map = [[$product, $data, Link::LINK_TYPE_RELATED, $this->resource], [$product, $data, Link::LINK_TYPE_UPSELL, $this->resource], [$product, $data, Link::LINK_TYPE_CROSSSELL, $this->resource]]; $this->resource->expects($this->any())->method('saveProductLinks')->will($this->returnValueMap($map)); $this->model->saveProductRelations($product); }
public function testAroundDeleteProductLink() { $subject = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Link::class)->disableOriginalConstructor()->getMock(); $subject->expects($this->any())->method('getIdFieldName')->willReturn('id'); $subject->expects($this->once())->method('load')->with($this->link, 155, 'id'); $this->link->expects($this->any())->method('getLinkTypeId')->willReturn(\Magento\GroupedProduct\Model\ResourceModel\Product\Link::LINK_TYPE_GROUPED); $this->link->expects($this->any())->method('getProductId')->willReturn(12); $this->link->expects($this->any())->method('getLinkedProductId')->willReturn(13); $this->relationProcessor->expects($this->once())->method('removeRelations')->with(12, 13); $this->assertEquals($subject, $this->object->aroundDeleteProductLink($subject, function () use($subject) { return $subject; }, 155)); }
public function testSaveProductRelations() { $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $this->saveProductLinksMock->expects($this->once())->method('execute')->with(\Magento\Catalog\Api\Data\ProductInterface::class, $product); $this->model->saveProductRelations($product); }
/** * {@inheritdoc} */ public function offsetGet($offset) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'offsetGet'); if (!$pluginInfo) { return parent::offsetGet($offset); } else { return $this->___callPlugins('offsetGet', func_get_args(), $pluginInfo); } }