Skip to content

Commit

Permalink
compatibility with hyva advanced product options
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-sss committed Jan 23, 2025
1 parent 81b2f00 commit c8d59fd
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 118 deletions.
156 changes: 78 additions & 78 deletions Model/Resolver/AdvancedProductOptionsSettings.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class AdvancedProductOptionsSettings implements ResolverInterface
{
protected SerializerInterface $serializer;
protected array $data;
protected array $resultData = [];

/**
* AdvancedProductOptionsSettings constructor.
Expand Down Expand Up @@ -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;
Expand Down
51 changes: 29 additions & 22 deletions Model/Resolver/ProductExtendConfig.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
15 changes: 9 additions & 6 deletions Model/Resolver/SwatchMediaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
];
}
}
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,10 @@ Our module extends original Magento products GraphQL request to add our attribut
```
</details>

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.

<details>
<summary>Dependency state request</summary>
Expand Down Expand Up @@ -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 <br />
--- "id" - the option ID, <br />
--- "values" - the IDs of the values, <br />
--- "type" - possible values "eq" и "!eq", which means "equal", "not equal". <br />
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, <br />
--- "values" - the IDs of the values, <br />
--- "type" - possible values "eq" и "!eq", which means "equal", "not equal". <br />
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".

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1163,7 +1163,7 @@ The 'ProductFinalPrice' request contains the next arguments:
--- "170" and "175" - the option ID, <br />
--- "1088" - the option value ID, <br />
- **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:

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c8d59fd

Please sign in to comment.