diff --git a/vendor/magento/module-configurable-product-graph-ql/Plugin/Quote/UpdateCustomizedOptions.php b/vendor/magento/module-configurable-product-graph-ql/Plugin/Quote/UpdateCustomizedOptions.php new file mode 100644 index 00000000000..de049bf36f2 --- /dev/null +++ b/vendor/magento/module-configurable-product-graph-ql/Plugin/Quote/UpdateCustomizedOptions.php @@ -0,0 +1,88 @@ +productRepository = $productRepository; + $this->superAttributeDataProvider = $superAttributeDataProvider; + } + + /** + * Parses the product data after update cart event and checking customized options super attribute + * + * @param Quote $subject + * @param int $itemId + * @param DataObject $buyRequest + * @param null|array|DataObject $params + * @return void + * @throws LocalizedException + * @throws NoSuchEntityException + * @throws GraphQlInputException + * @throws GraphQlNoSuchEntityException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function beforeUpdateItem( + Quote $subject, + int $itemId, + DataObject $buyRequest, + DataObject $params = null + ): void { + $item = $subject->getItemById($itemId); + if ($item) { + $productId = $item->getProduct()->getId(); + $product = clone $this->productRepository->getById($productId, false, $subject->getStore()->getId()); + if ($item->getProductType() === Configurable::TYPE_CODE && count($product->getOptions()) > 0) { + $cartItemData = []; + $cartItemData['model'] = $subject; + if (count($item->getChildren()) > 0) { + $currentItem = current($item->getChildren()); + $cartItemData['data']['sku'] = $currentItem->getSku(); + } else { + $cartItemData['data']['sku'] = $item->getSku(); + } + $cartItemData['data']['quantity'] = $buyRequest->getQty(); + $cartItemData['parent_sku'] = $product->getSku(); + $superAttributeDetails = $this->superAttributeDataProvider->execute($cartItemData); + $buyRequest->addData($superAttributeDetails); + } + } + } +} diff --git a/vendor/magento/module-configurable-product-graph-ql/etc/graphql/di.xml b/vendor/magento/module-configurable-product-graph-ql/etc/graphql/di.xml index 227817b3887..67321d40172 100644 --- a/vendor/magento/module-configurable-product-graph-ql/etc/graphql/di.xml +++ b/vendor/magento/module-configurable-product-graph-ql/etc/graphql/di.xml @@ -59,4 +59,7 @@ + + +