From 6d95aaa33087e9e1dedabbb7feea9378052ad773 Mon Sep 17 00:00:00 2001 From: Hassan Goodarzi Date: Thu, 12 Sep 2024 13:06:27 +0330 Subject: [PATCH 1/3] Implemented entered options data provider --- ...tCardProductEnteredOptionsDataProvider.php | 76 +++++++++++++++++++ README.md | 33 ++++++++ composer.json | 2 +- etc/graphql/di.xml | 7 ++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 Model/Cart/BuyRequest/GiftCardProductEnteredOptionsDataProvider.php diff --git a/Model/Cart/BuyRequest/GiftCardProductEnteredOptionsDataProvider.php b/Model/Cart/BuyRequest/GiftCardProductEnteredOptionsDataProvider.php new file mode 100644 index 0000000..2de7396 --- /dev/null +++ b/Model/Cart/BuyRequest/GiftCardProductEnteredOptionsDataProvider.php @@ -0,0 +1,76 @@ +getEnteredOptions() as $option) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $optionData = \explode('/', base64_decode($option->getUid())); + + if ($this->isProviderApplicable($optionData) === false) { + continue; + } + $this->validateInput($optionData); + + [$optionType, $optionId] = $optionData; + if ($optionType == self::OPTION_TYPE) { + $giftCardProductData[$optionId] = $option->getValue(); + } + } + + return $giftCardProductData; + } + + /** + * Checks whether this provider is applicable for the current option + * + * @param array $optionData + * @return bool + */ + private function isProviderApplicable(array $optionData): bool + { + if ($optionData[0] !== self::OPTION_TYPE) { + return false; + } + + return true; + } + + /** + * Validates the provided options structure + * + * @param array $optionData + * @throws LocalizedException + */ + private function validateInput(array $optionData): void + { + if (count($optionData) !== 2) { + throw new LocalizedException( + __('Wrong format of the entered option data') + ); + } + } +} diff --git a/README.md b/README.md index 4d1dd68..11144a0 100755 --- a/README.md +++ b/README.md @@ -586,3 +586,36 @@ mutation { } } ``` + +**7.** The **addProductsToCart** mutation allows you to add any product to the cart. + +Syntax: + +``` +mutation: {addProductsToCart(cartId: String! cartItems: [cartItemInput]!): AddProductsToCartOutput} +``` + +The cartItemInput object must contain the following attributes: + +``` +entered_options: [{uid: ID!, value: String!}] +quantity: Float! +sku: String! +``` + +**entered_options** + +You need to add gift card product cart item attributes array here, as uid and value. + +**uid** + +Base64 encoded cart item attribute starting with 'mw_giftcard/' prefix. For example: + +``` +mw_giftcard/mail_to_email +``` + +Base64 encoded uid +``` +Z2lmdGNhcmQvbWFpbF90b19lbWFpbA== +``` \ No newline at end of file diff --git a/composer.json b/composer.json index 37f1ada..8a01a4a 100755 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "magento/module-url-rewrite-graph-ql": ">= 100.4.2 < 100.5" }, "type": "magento2-module", - "version": "1.2.2", + "version": "1.2.3", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/etc/graphql/di.xml b/etc/graphql/di.xml index 9718f33..1e191f3 100755 --- a/etc/graphql/di.xml +++ b/etc/graphql/di.xml @@ -20,6 +20,13 @@ + + + + MageWorx\GiftCardsGraphQl\Model\Cart\BuyRequest\GiftCardProductEnteredOptionsDataProvider + + + From 14a742a5240bd25c98fcfbadbd68ead319e6efff Mon Sep 17 00:00:00 2001 From: Hassan Goodarzi Date: Thu, 12 Sep 2024 13:09:12 +0330 Subject: [PATCH 2/3] Implemented entered options data provider --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 11144a0..d516190 100755 --- a/README.md +++ b/README.md @@ -592,10 +592,10 @@ mutation { Syntax: ``` -mutation: {addProductsToCart(cartId: String! cartItems: [cartItemInput]!): AddProductsToCartOutput} +mutation: {addProductsToCart(cartId: String! cartItems: [CartItemInput]!): AddProductsToCartOutput} ``` -The cartItemInput object must contain the following attributes: +The CartItemInput object must contain the following attributes: ``` entered_options: [{uid: ID!, value: String!}] From ed69743907c1560835294834b6d05b54a00c3aa6 Mon Sep 17 00:00:00 2001 From: Hassan Goodarzi Date: Thu, 12 Sep 2024 13:20:23 +0330 Subject: [PATCH 3/3] Implemented entered options data provider --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d516190..c9f05c6 100755 --- a/README.md +++ b/README.md @@ -617,5 +617,5 @@ mw_giftcard/mail_to_email Base64 encoded uid ``` -Z2lmdGNhcmQvbWFpbF90b19lbWFpbA== +bXdfZ2lmdGNhcmQvbWFpbF90b19lbWFpbA== ``` \ No newline at end of file