/** * Relate simple products to configurable * * @param ProductInterface $product * @param ProductExtensionInterface $extensionAttributes * @return void * @throws \Magento\Framework\Exception\LocalizedException */ private function setLinkedProducts(ProductInterface $product, ProductExtensionInterface $extensionAttributes) { $associatedProductIds = $product->hasData('associated_product_ids') ? $product->getData('associated_product_ids') : []; $variationsMatrix = $this->getVariationMatrixFromProduct($product); if ($associatedProductIds || $variationsMatrix) { $this->variationHandler->prepareAttributeSet($product); } if (!empty($variationsMatrix)) { $generatedProductIds = $this->variationHandler->generateSimpleProducts($product, $variationsMatrix); $associatedProductIds = array_merge($associatedProductIds, $generatedProductIds); } $extensionAttributes->setConfigurableProductLinks(array_filter($associatedProductIds)); }
/** * Relate simple products to configurable * * @param ProductInterface $product * @param ProductExtensionInterface $extensionAttributes * @return void * @throws \Magento\Framework\Exception\LocalizedException */ private function setLinkedProducts(ProductInterface $product, ProductExtensionInterface $extensionAttributes) { $associatedProductIds = $this->request->getPost('associated_product_ids', []); $variationsMatrix = $this->request->getParam('variations-matrix', []); if (!empty($variationsMatrix)) { $generatedProductIds = $this->variationHandler->generateSimpleProducts($product, $variationsMatrix); $associatedProductIds = array_merge($associatedProductIds, $generatedProductIds); } $extensionAttributes->setConfigurableProductLinks(array_filter($associatedProductIds)); }