public function testSaveProductsForDuplicate() { $mainProduct = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getIsDuplicate', '__sleep', '__wakeup', 'getTypeInstance', 'getConnection'])->disableOriginalConstructor()->getMock(); $mainProduct->expects($this->once())->method('getIsDuplicate')->will($this->returnValue(true)); $mainProduct->expects($this->never())->method('getTypeInstance')->will($this->returnSelf()); $this->configurable->saveProducts($mainProduct, [1, 2, 3]); }
public function testSaveProducts() { /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $mainProduct */ $mainProduct = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->setMethods(['__sleep', '__wakeup', 'getData'])->disableOriginalConstructor()->getMock(); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn('link'); $mainProduct->expects($this->once())->method('getData')->with('link')->willReturn(3); $this->configurable->saveProducts($mainProduct, [1, 2, 3]); }
public function testSaveProducts() { /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $mainProduct */ $mainProduct = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->setMethods(['__sleep', '__wakeup', 'getData'])->disableOriginalConstructor()->getMock(); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn('link'); $mainProduct->expects($this->once())->method('getData')->with('link')->willReturn(3); $select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock(); $this->connection->method('select')->willReturn($select); $select->method('from')->willReturnSelf(); $select->method('where')->willReturnSelf(); $statement = $this->getMockBuilder(\Zend_Db_Statement::class)->disableOriginalConstructor()->getMock(); $select->method('query')->willReturn($statement); $statement->method('fetchAll')->willReturn([1]); $this->configurable->saveProducts($mainProduct, [1, 2, 3]); }
/** * @param ProductInterface $entity * @param array $arguments * @return ProductInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($entity, $arguments = []) { if ($entity->getTypeId() !== Configurable::TYPE_CODE) { return $entity; } $extensionAttributes = $entity->getExtensionAttributes(); if ($extensionAttributes === null) { return $entity; } if ($extensionAttributes->getConfigurableProductOptions() !== null) { $this->deleteConfigurableProductAttributes($entity); } $configurableOptions = (array) $extensionAttributes->getConfigurableProductOptions(); if (!empty($configurableOptions)) { $this->saveConfigurableProductAttributes($entity, $configurableOptions); } $configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks(); $this->resourceModel->saveProducts($entity, $configurableLinks); return $entity; }
/** * {@inheritdoc} */ public function delete(OptionInterface $option) { $product = $this->getProductById($option->getProductId()); try { $this->configurableTypeResource->saveProducts($product, []); } catch (\Exception $exception) { throw new StateException(__('Cannot delete variations from product: %1', $option->getProductId())); } try { $this->optionResource->delete($option); } catch (\Exception $exception) { throw new StateException(__('Cannot delete option with id: %1', $option->getId())); } return true; }