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 edavydova/4ff008841ea022fc701d4c164b4f9227 to your computer and use it in GitHub Desktop.
Save edavydova/4ff008841ea022fc701d4c164b4f9227 to your computer and use it in GitHub Desktop.
diff --git a/app/addons/commerceml/src/Importers/ProductImporter.php b/app/addons/commerceml/src/Importers/ProductImporter.php
index 345cd76327..efc564f76e 100644
--- a/app/addons/commerceml/src/Importers/ProductImporter.php
+++ b/app/addons/commerceml/src/Importers/ProductImporter.php
@@ -218,9 +218,16 @@ class ProductImporter
$current_pair_ids = [];
$detailed_image_data_list = [];
$pair_data_list = [];
+ $pair_position = 0;
if ($current_product_data && $strategy === 'append') {
$current_pair_ids = array_column($current_product_data['images'], 'pair_id', 'image_path');
+ $current_pair_positions = array_column($current_product_data['images'], 'position', 'pair_id');
+ $pair_position = empty($current_pair_positions) ? 0 : max($current_pair_positions) + 1;
+ }
+
+ if (!empty($current_product_data['images']) && $strategy === 'replace') {
+ $this->product_storage->removeImagePairs(array_column($current_product_data['images'], 'pair_id', 'image_path'));
}
/** @var \Tygh\Addons\CommerceML\Dto\ImageDto $image */
@@ -237,6 +244,7 @@ class ProductImporter
if (isset($current_image['type'])) {
$type = $current_image['type'];
+ $pair_position = isset($current_image['position']) ? $current_image['position'] : $pair_position;
} elseif (empty($current_pair_ids) && empty($pair_data_list)) {
$type = ImagePairTypes::MAIN;
} else {
@@ -244,8 +252,9 @@ class ProductImporter
}
$pair_data_list[] = [
- 'pair_id' => $pair_id,
- 'type' => $type
+ 'pair_id' => $pair_id,
+ 'type' => $type,
+ 'position' => $pair_position
];
$detailed_image_data_list[] = [
@@ -253,6 +262,7 @@ class ProductImporter
'path' => $filepath,
'size' => filesize($filepath)
];
+ $pair_position++;
}
if (!$pair_data_list) {
@@ -264,13 +274,6 @@ class ProductImporter
$pair_data_list,
$detailed_image_data_list
);
-
- if (empty($current_product_data['images']) || $strategy !== 'replace') {
- return;
- }
-
- $current_pair_ids = array_column($current_product_data['images'], 'pair_id', 'image_path');
- $this->product_storage->removeImagePairs($current_pair_ids);
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment