diff --git a/vendor/magento/module-gift-card-graph-ql/Model/GiftCardDataProvider.php b/vendor/magento/module-gift-card-graph-ql/Model/GiftCardDataProvider.php new file mode 100644 index 00000000000..56c67eeab5c --- /dev/null +++ b/vendor/magento/module-gift-card-graph-ql/Model/GiftCardDataProvider.php @@ -0,0 +1,77 @@ + $optionValue) { + $optionData = explode('/', $uid); + if ($this->isProviderApplicable($optionData) === false) { + continue; + } + $this->validateInput($optionData); + + [$optionType, $optionId] = $optionData; + if ($optionType === Giftcard::TYPE_GIFTCARD) { + if ($optionId === Option::KEY_CUSTOM_GIFTCARD_AMOUNT) { + $giftCardOptionsData[Option::KEY_AMOUNT] = 'custom'; + } + $giftCardOptionsData[$optionId] = $optionValue; + } + } + + return $giftCardOptionsData; + } + + /** + * Checks whether this provider is applicable for the current option + * + * @param array $optionData + * @return bool + */ + private function isProviderApplicable(array $optionData): bool + { + return $optionData[0] === Giftcard::TYPE_GIFTCARD + && in_array($optionData[1], [ + Option::KEY_AMOUNT, + Option::KEY_CUSTOM_GIFTCARD_AMOUNT, + Option::KEY_SENDER_NAME, + Option::KEY_SENDER_EMAIL, + Option::KEY_RECIPIENT_NAME, + Option::KEY_RECIPIENT_EMAIL, + Option::KEY_MESSAGE + ], 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/vendor/magento/module-gift-card-graph-ql/etc/graphql/di.xml b/vendor/magento/module-gift-card-graph-ql/etc/graphql/di.xml index 81b4cc0f6cf..6f9cb929f0b 100644 --- a/vendor/magento/module-gift-card-graph-ql/etc/graphql/di.xml +++ b/vendor/magento/module-gift-card-graph-ql/etc/graphql/di.xml @@ -92,4 +92,11 @@ + + + + Magento\GiftCardGraphQl\Model\GiftCardDataProvider + + +