Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,15 @@ protected function _initOldCustomOptions()
if (isset($oldCustomOptions[$productId][$customOption->getId()])) {
$oldCustomOptions[$productId][$customOption->getId()]['titles'][$storeId] = $customOption
->getTitle();
// Ensure sort_order is set for existing options
if (!isset($oldCustomOptions[$productId][$customOption->getId()]['sort_order'])) {
$oldCustomOptions[$productId][$customOption->getId()]['sort_order'] = $customOption->getSortOrder();
}
} else {
$oldCustomOptions[$productId][$customOption->getId()] = [
'titles' => [$storeId => $customOption->getTitle()],
'type' => $customOption->getType(),
'sort_order' => $customOption->getSortOrder(),
];
}
};
Expand Down Expand Up @@ -836,6 +841,15 @@ protected function _findExistingOptionId(array $newOptionData, array $newOptionT
$existingOptions = $this->getOldCustomOptions()[$productId];
foreach ($existingOptions as $optionId => $optionData) {
if ($optionData['type'] == $newOptionData['type']) {
// Primary matching: by sort_order if both are available and non-zero
if (isset($optionData['sort_order']) && isset($newOptionData['sort_order'])
&& $optionData['sort_order'] > 0 && $newOptionData['sort_order'] > 0
&& $optionData['sort_order'] == $newOptionData['sort_order']
) {
return $optionId;
}

// Fallback matching: by exact title match (original behavior for backward compatibility)
foreach ($newOptionTitles as $storeId => $title) {
if (isset($optionData['titles'][$storeId]) && $optionData['titles'][$storeId] === $title) {
return $optionId;
Expand Down