Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vyacheslavkor/d5ffc4bf9d289fe0799ae5d2bf18d75e to your computer and use it in GitHub Desktop.
Save Vyacheslavkor/d5ffc4bf9d289fe0799ae5d2bf18d75e to your computer and use it in GitHub Desktop.
diff --git a/app/addons/commerceml/src/HookHandlers/ProductHookHandler.php b/app/addons/commerceml/src/HookHandlers/ProductHookHandler.php
index bf23cbc42f..4a662baa4a 100644
--- a/app/addons/commerceml/src/HookHandlers/ProductHookHandler.php
+++ b/app/addons/commerceml/src/HookHandlers/ProductHookHandler.php
@@ -37,29 +37,37 @@ class ProductHookHandler
*/
public static function onUpdateProductFeaturesValuePre(
$product_id,
- array $product_features,
+ array &$product_features,
array &$add_new_variant,
$lang_code,
array $params,
array $product_category_ids,
array $product_categories_paths
) {
- $feature_ids = array_keys($product_features);
- $feature_types = fn_get_product_feature_types_by_feature_ids($feature_ids);
- $number_feature_types = array_filter($feature_types, static function ($feature_type) {
- return $feature_type === ProductFeatures::NUMBER_SELECTBOX;
- });
+ if (!empty($params['commerceml_import'])) {
+ $feature_ids = array_keys($product_features);
+ $feature_types = fn_get_product_feature_types_by_feature_ids($feature_ids);
+ $number_feature_types = array_filter($feature_types, static function ($feature_type) {
+ return $feature_type === ProductFeatures::NUMBER_SELECTBOX;
+ });
- if (!empty($number_feature_types)) {
- $number_feature_ids = array_keys($number_feature_types);
- list($feature_variants) = fn_get_product_feature_variants(['feature_id' => $number_feature_ids]);
+ if (!empty($number_feature_types)) {
+ $number_feature_ids = array_keys($number_feature_types);
+ list($feature_variants) = fn_get_product_feature_variants(['feature_id' => $number_feature_ids]);
- foreach ($number_feature_ids as $feature_id) {
- if (in_array($product_features[$feature_id], array_column($feature_variants, 'variant'))) {
- continue;
- }
+ foreach ($number_feature_ids as $feature_id) {
+ if (in_array($product_features[$feature_id], array_column($feature_variants, 'variant'))) {
+ foreach ($feature_variants as $feature_variant) {
+ if ($feature_variant['variant'] === $product_features[$feature_id]) {
+ $product_features[$feature_id] = (string) $feature_variant['variant_id'];
+ break;
+ }
+ }
+ continue;
+ }
- $add_new_variant[$feature_id]['variant'] = $product_features[$feature_id];
+ $add_new_variant[$feature_id]['variant'] = $product_features[$feature_id];
+ }
}
}
diff --git a/app/addons/commerceml/src/Importers/ProductImporter.php b/app/addons/commerceml/src/Importers/ProductImporter.php
index e0f5a828f1..e1815c64b4 100644
--- a/app/addons/commerceml/src/Importers/ProductImporter.php
+++ b/app/addons/commerceml/src/Importers/ProductImporter.php
@@ -889,7 +889,10 @@ class ProductImporter
if ($product_feature_values) {
$product_data['product_features'] = $product_feature_values;
- $product_data['product_features_params'] = ['commerceml_update_product_feature_categories' => true];
+ $product_data['product_features_params'] = [
+ 'commerceml_update_product_feature_categories' => true,
+ 'commerceml_import' => true
+ ];
}
return $product_data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment