From c8d59fd9a7a48672964e7b3498e87b0f47000e19 Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 23 Jan 2025 11:01:42 +0100 Subject: [PATCH] compatibility with hyva advanced product options --- .../AdvancedProductOptionsSettings.php | 156 +++++++++--------- Model/Resolver/ProductExtendConfig.php | 51 +++--- Model/Resolver/SwatchMediaData.php | 15 +- README.md | 22 +-- composer.json | 2 +- 5 files changed, 128 insertions(+), 118 deletions(-) mode change 100644 => 100755 Model/Resolver/AdvancedProductOptionsSettings.php mode change 100644 => 100755 Model/Resolver/ProductExtendConfig.php diff --git a/Model/Resolver/AdvancedProductOptionsSettings.php b/Model/Resolver/AdvancedProductOptionsSettings.php old mode 100644 new mode 100755 index 752f007..0d832d6 --- a/Model/Resolver/AdvancedProductOptionsSettings.php +++ b/Model/Resolver/AdvancedProductOptionsSettings.php @@ -18,7 +18,6 @@ class AdvancedProductOptionsSettings implements ResolverInterface { protected SerializerInterface $serializer; protected array $data; - protected array $resultData = []; /** * AdvancedProductOptionsSettings constructor. @@ -53,89 +52,90 @@ public function resolve( array $value = null, array $args = null ): array { - try { - $resultData = []; - foreach ($this->data as $key => $helper) { - switch ($key) { - case 'features_helper': - $selectionLimitTemplateData = $this->serializer->serialize( - $helper->getSelectionLimitTemplateData() - ); + return $this->resolveData(); + } - //OptionFeatures section - $featuresData = [ - 'product_price_display_mode' => $helper->getProductPriceDisplayMode(), - 'is_enabled_additional_product_price_field' => - $helper->isEnabledAdditionalProductPriceField(), - 'additional_product_price_field_label' => - $helper->getAdditionalProductPriceFieldLabel(), - 'additional_product_price_field_mode' => - $helper->getAdditionalProductPriceFieldMode(), - 'is_qty_input_enabled' => $helper->isQtyInputEnabled(), - 'default_qty_label' => $helper->getDefaultQtyLabel(), - 'is_option_value_description_enabled' => $helper->isOptionValueDescriptionEnabled(), - 'is_option_description_enabled' => $helper->isOptionDescriptionEnabled(), - 'get_option_description_mode' => $helper->getOptionDescriptionMode(), - 'selection_limit_template_data' => $selectionLimitTemplateData, - 'base_image_thumbnail_height' => $helper->getBaseImageThumbnailHeight(), - 'base_image_thumbnail_width' => $helper->getBaseImageThumbnailWidth(), - 'tooltip_image_thumbnail_size' => $helper->getTooltipImageThumbnailSize(), - 'is_enabled_shareable_link' => $helper->isEnabledShareableLink(), - 'shareable_link_text' => $helper->getShareableLinkText(), - 'shareable_link_hint_text' => $helper->getShareableLinkHintText(), - 'shareable_link_success_text' => $helper->getShareableLinkSuccessText(), - 'is_load_linked_product_enabled' => $helper->isLoadLinkedProductEnabled(), - 'is_enabled_fide_value_price' => $helper->isEnabledHideValuePrice(), - 'is_enabled_hide_product_page_value_price' => - $helper->isEnabledHideProductPageValuePrice(), - 'is_enabled_customize_and_add_to_cart_button' => $helper->isEnabledCustAndAddToCartButton() + public function resolveData(): array + { + $resultData = []; + foreach ($this->data as $key => $helper) { + switch ($key) { + case 'features_helper': + $selectionLimitTemplateData = $this->serializer->serialize( + $helper->getSelectionLimitTemplateData() + ); - ]; + //OptionFeatures section + $featuresData = [ + 'product_price_display_mode' => $helper->getProductPriceDisplayMode(), + 'is_enabled_additional_product_price_field' => + $helper->isEnabledAdditionalProductPriceField(), + 'additional_product_price_field_label' => + $helper->getAdditionalProductPriceFieldLabel(), + 'additional_product_price_field_mode' => + $helper->getAdditionalProductPriceFieldMode(), + 'is_qty_input_enabled' => $helper->isQtyInputEnabled(), + 'default_qty_label' => $helper->getDefaultQtyLabel(), + 'is_option_value_description_enabled' => $helper->isOptionValueDescriptionEnabled(), + 'is_option_description_enabled' => $helper->isOptionDescriptionEnabled(), + 'get_option_description_mode' => $helper->getOptionDescriptionMode(), + 'selection_limit_template_data' => $selectionLimitTemplateData, + 'base_image_thumbnail_height' => $helper->getBaseImageThumbnailHeight(), + 'base_image_thumbnail_width' => $helper->getBaseImageThumbnailWidth(), + 'tooltip_image_thumbnail_size' => $helper->getTooltipImageThumbnailSize(), + 'is_enabled_shareable_link' => $helper->isEnabledShareableLink(), + 'shareable_link_text' => $helper->getShareableLinkText(), + 'shareable_link_hint_text' => $helper->getShareableLinkHintText(), + 'shareable_link_success_text' => $helper->getShareableLinkSuccessText(), + 'is_load_linked_product_enabled' => $helper->isLoadLinkedProductEnabled(), + 'is_enabled_fide_value_price' => $helper->isEnabledHideValuePrice(), + 'is_enabled_hide_product_page_value_price' => + $helper->isEnabledHideProductPageValuePrice(), + 'is_enabled_customize_and_add_to_cart_button' => $helper->isEnabledCustAndAddToCartButton() - //OptionSwatches section - $swatchesData = [ - 'is_show_swatch_title' => $helper->isShowSwatchTitle(), - 'is_show_swatch_price' => $helper->isShowSwatchPrice(), - 'swatch_width' => $helper->getSwatchWidth(), - 'swatch_height' => $helper->getSwatchHeight(), - 'text_swatch_max_width' => $helper->getTextSwatchMaxWidth() - ]; + ]; - $data = array_merge($featuresData, $swatchesData); - break; - case 'inventory_helper': - //OptionInventory Section - $data = [ - 'is_enabled_option_inventory' => - $helper->isEnabledOptionInventory(), - 'is_display_option_inventory_on_frontend' => - $helper->isDisplayOptionInventoryOnFrontend(), - 'is_display_out_of_stock_message' => - $helper->isDisplayOutOfStockMessage(), - 'is_display_out_of_stock_message_on_options_level' => - $helper->isDisplayOutOfStockMessageOnOptionsLevel(), - 'is_display_out_of_stock_options' => - $helper->isDisplayOutOfStockOptions(), - 'is_require_hidden_out_of_stock_options' => - $helper->isRequireHiddenOutOfStockOptions() - ]; - break; - case 'advanced_pricing_helper': - //OptionAdvancedPricing Section - $data = [ - 'is_special_price_enabled' => $helper->isSpecialPriceEnabled(), - 'is_tier_price_enabled' => $helper->isTierPriceEnabled(), - 'is_display_tier_price_table_needed' => $helper->isDisplayTierPriceTableNeeded() - ]; - break; - default: - throw new \Exception('Unexpected object key'); - } + //OptionSwatches section + $swatchesData = [ + 'is_show_swatch_title' => $helper->isShowSwatchTitle(), + 'is_show_swatch_price' => $helper->isShowSwatchPrice(), + 'swatch_width' => $helper->getSwatchWidth(), + 'swatch_height' => $helper->getSwatchHeight(), + 'text_swatch_max_width' => $helper->getTextSwatchMaxWidth() + ]; - $resultData = array_merge($resultData, $data); + $data = array_merge($featuresData, $swatchesData); + break; + case 'inventory_helper': + //OptionInventory Section + $data = [ + 'is_enabled_option_inventory' => + $helper->isEnabledOptionInventory(), + 'is_display_option_inventory_on_frontend' => + $helper->isDisplayOptionInventoryOnFrontend(), + 'is_display_out_of_stock_message' => + $helper->isDisplayOutOfStockMessage(), + 'is_display_out_of_stock_message_on_options_level' => + $helper->isDisplayOutOfStockMessageOnOptionsLevel(), + 'is_display_out_of_stock_options' => + $helper->isDisplayOutOfStockOptions(), + 'is_require_hidden_out_of_stock_options' => + $helper->isRequireHiddenOutOfStockOptions() + ]; + break; + case 'advanced_pricing_helper': + //OptionAdvancedPricing Section + $data = [ + 'is_special_price_enabled' => $helper->isSpecialPriceEnabled(), + 'is_tier_price_enabled' => $helper->isTierPriceEnabled(), + 'is_display_tier_price_table_needed' => $helper->isDisplayTierPriceTableNeeded() + ]; + break; + default: + throw new \Exception('Unexpected object key'); } - } catch (NoSuchEntityException $e) { - throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); + + $resultData = array_merge($resultData, $data); } return $resultData; diff --git a/Model/Resolver/ProductExtendConfig.php b/Model/Resolver/ProductExtendConfig.php old mode 100644 new mode 100755 index e76be38..167ef72 --- a/Model/Resolver/ProductExtendConfig.php +++ b/Model/Resolver/ProductExtendConfig.php @@ -113,28 +113,7 @@ public function resolve( $this->registry->register('current_product', $product); } - $regularPriceExclTax = $this->priceCurrency->convert( - $this->baseConfig->getProductRegularPrice($product, false) - ); - $regularPriceInclTax = $this->priceCurrency->convert( - $this->baseConfig->getProductRegularPrice($product, true) - ); - $finalPriceExclTax = $this->priceCurrency->convert( - $this->baseConfig->getProductFinalPrice($product, false, $qty) - ); - $finalPriceInclTax = $this->priceCurrency->convert( - $this->baseConfig->getProductFinalPrice($product, true, $qty) - ); - - $data['option_json_config'] = $this->viewOptions->getJsonConfig(); - $data['product_json_config'] = $this->baseConfig->getProductJsonConfig($product); - $data['locale_price_format'] = $this->getLocalePriceFormat(); - $data['product_final_price_incl_tax'] = $finalPriceInclTax; - $data['product_final_price_excl_tax'] = $finalPriceExclTax; - $data['product_regular_price_incl_tax'] = $regularPriceInclTax; - $data['product_regular_price_excl_tax'] = $regularPriceExclTax; - $data['price_display_mode'] = $this->baseConfig->getPriceDisplayMode(); - $data['catalog_price_contains_tax'] = $this->baseConfig->getCatalogPriceContainsTax(); + $data = $this->resolveData($product, $qty); } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); @@ -150,4 +129,32 @@ public function getLocalePriceFormat(): string return $this->serializer->serialize($data); } + + public function resolveData($product, $qty = 1): array + { + $regularPriceExclTax = $this->priceCurrency->convert( + $this->baseConfig->getProductRegularPrice($product, false) + ); + $regularPriceInclTax = $this->priceCurrency->convert( + $this->baseConfig->getProductRegularPrice($product, true) + ); + $finalPriceExclTax = $this->priceCurrency->convert( + $this->baseConfig->getProductFinalPrice($product, false, $qty) + ); + $finalPriceInclTax = $this->priceCurrency->convert( + $this->baseConfig->getProductFinalPrice($product, true, $qty) + ); + + $data['option_json_config'] = $this->viewOptions->getJsonConfig(); + $data['product_json_config'] = $this->baseConfig->getProductJsonConfig($product); + $data['locale_price_format'] = $this->getLocalePriceFormat(); + $data['product_final_price_incl_tax'] = $finalPriceInclTax; + $data['product_final_price_excl_tax'] = $finalPriceExclTax; + $data['product_regular_price_incl_tax'] = $regularPriceInclTax; + $data['product_regular_price_excl_tax'] = $regularPriceExclTax; + $data['price_display_mode'] = $this->baseConfig->getPriceDisplayMode(); + $data['catalog_price_contains_tax'] = $this->baseConfig->getCatalogPriceContainsTax(); + + return $data; + } } diff --git a/Model/Resolver/SwatchMediaData.php b/Model/Resolver/SwatchMediaData.php index 7cf41b4..6309a52 100644 --- a/Model/Resolver/SwatchMediaData.php +++ b/Model/Resolver/SwatchMediaData.php @@ -64,16 +64,19 @@ public function resolve( $product = $this->productRepository->get($productSku); $width = $args['width'] ?? 0; $height = $args['height'] ?? 0; - - $data = [ - 'swatch_media_data' => - $this->swatchData->getSwatchMediaData($product, $width, $height) - - ]; + $data = $this->resolveData($product, $width, $height); } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); } return $data; } + + public function resolveData($product, $width = 0, $height = 0): array + { + return [ + 'swatch_media_data' => + $this->swatchData->getSwatchMediaData($product, $width, $height) + ]; + } } diff --git a/README.md b/README.md index 3fe08ce..e6dd16a 100644 --- a/README.md +++ b/README.md @@ -808,10 +808,10 @@ Our module extends original Magento products GraphQL request to add our attribut ``` -Please also see additional GraphQL requests below: +Please also see additional GraphQL requests below: -### Dependency State: -Calculate the dependency and the default state. It returns the values that should be hidden and/or selected as the default, when the customers select certain options. +### Dependency State: +Calculate the dependency and the default state. It returns the values that should be hidden and/or selected as the default, when the customers select certain options.
Dependency state request @@ -894,17 +894,17 @@ The 'DependencyState' response contains the objects, which include the following The "preselected_values" duplicates the values, sent in the request, and adds the values, which should be shown and might be pre-selected. -If you do not want to use this approach to calculate the dependencies and the default state for some reasons, we added the 'dependency_rules' fields to the Products request and response *(see the Products request and response above for more details)*. +If you do not want to use this approach to calculate the dependencies and the default state for some reasons, we added the 'dependency_rules' fields to the Products request and response *(see the Products request and response above for more details)*. Otherwise, we recommend to remove the 'dependency_rules' fields from the Products request to improve the performance. The 'dependency_rules' is the JSON row with the array of the rules. Every rule is the array with the following structure: - **conditions** - it is the array with the conditions. The possible keys inside each condition: {"values":["2418"],"type":"!eq","id":73}, where
---- "id" - the option ID,
---- "values" - the IDs of the values,
---- "type" - possible values "eq" и "!eq", which means "equal", "not equal".
-The condition in this example will be valid if the value with ID "2418" of the option "73" is not selected. + --- "id" - the option ID,
+ --- "values" - the IDs of the values,
+ --- "type" - possible values "eq" и "!eq", which means "equal", "not equal".
+ The condition in this example will be valid if the value with ID "2418" of the option "73" is not selected. - **condition_type** - it is the logical operator, which is used to combine the conditions. Possible values: "OR", "AND". @@ -1112,10 +1112,10 @@ The 'ProductExtendConfig' response contains the params, which include the follow - **price_display_mode** - the int with price display mode param - **catalog_price_contains_tax** - the boolean with catalog price contains tax param -The 'option_json_config' has all value prices with included and excluded taxes, also has tier and special value data in +The 'option_json_config' has all value prices with included and excluded taxes, also has tier and special value data in ready to display format. -The 'product_json_config' contains advanced product option attributes, product tier price data, product type, +The 'product_json_config' contains advanced product option attributes, product tier price data, product type, regular and final prouct prices with inc. and excl. taxes and product price display mode. The 'locale_price_format' has params to display product price format. @@ -1163,7 +1163,7 @@ The 'ProductFinalPrice' request contains the next arguments: --- "170" and "175" - the option ID,
--- "1088" - the option value ID,
- **currentQty** - current product qty -Note: The values exist for "selectable" options only. For the option types like "field", the "value ID" will be empty. + Note: The values exist for "selectable" options only. For the option types like "field", the "value ID" will be empty. The 'ProductFinalPrice' response contains the actual base and final prices which will be calculated with selected options using this query, which include the following keys: diff --git a/composer.json b/composer.json index 9bb2835..e6dbd69 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "mageworx/module-optionfeatures" : ">=2.31.19" }, "type": "magento2-module", - "version": "2.2.0", + "version": "2.2.1", "license": [ "OSL-3.0", "AFL-3.0"