public function testSaveProductsForDuplicate() { $mainProduct = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getIsDuplicate', '__sleep', '__wakeup', 'getTypeInstance', '_getWriteAdapter'])->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]); }
/** * {@inheritdoc} */ public function addChild($productSku, $childSku) { $product = $this->productRepository->get($productSku); $child = $this->productRepository->get($childSku); $childrenIds = array_values($this->configurableType->getChildrenIds($product->getId())[0]); if (in_array($child->getId(), $childrenIds)) { throw new StateException('Product has been already attached'); } $childrenIds[] = $child->getId(); $product->setAssociatedProductIds($childrenIds); $product->save(); return true; }
/** * {@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; }
/** * Prepare and retrieve options values with product data * * @param \Magento\Catalog\Model\Product $product * @return array */ public function getConfigurableOptions($product) { return $this->_catalogProductTypeConfigurable->getConfigurableOptions($product, $this->getUsedProductAttributes($product)); }