diff --git a/CHANGELOG.md b/CHANGELOG.md index 248983ea..0dd227d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -499,3 +499,7 @@ ### Version 104.3.10 : * AMC-479: Reset product UUID when URL has been updated + +### Version 104.3.11 : +* PGTO-398: keep the swatch option if exists +* AMC-483: Single store mode feature diff --git a/Helper/Store.php b/Helper/Store.php index 22cbfee7..2ea13c78 100644 --- a/Helper/Store.php +++ b/Helper/Store.php @@ -111,6 +111,10 @@ public function getStores($arrayKey = 'store_id') continue; } + if ($this->storeManager->isSingleStoreMode() && (int)$websiteId !== 0) { + continue; + } + /** @var string $currency */ $currency = $website->getBaseCurrencyCode(); /** @var string[] $siblings */ diff --git a/Job/Option.php b/Job/Option.php index 1a58156c..f3ba26b7 100644 --- a/Job/Option.php +++ b/Job/Option.php @@ -554,11 +554,12 @@ public function insertSwatchOption(): void $dataToInsert = []; foreach ($swatchesAttributesData as $swatchesAttributeData) { + $optionTypeAndValue = $this->getTypeAndValue($swatchesAttributes, $swatchesAttributeData); $dataToInsert[] = [ 'option_id' => $swatchesAttributeData['option_id'], 'store_id' => $swatchesAttributeData['store_id'], - 'type' => ($swatchesAttributes[$swatchesAttributeData['attribute']] === Swatch::SWATCH_TYPE_TEXTUAL_ATTRIBUTE_FRONTEND_INPUT) ? Swatch::SWATCH_TYPE_TEXTUAL : Swatch::SWATCH_TYPE_EMPTY, - 'value' => ($swatchesAttributes[$swatchesAttributeData['attribute']] === Swatch::SWATCH_TYPE_TEXTUAL_ATTRIBUTE_FRONTEND_INPUT) ? $swatchesAttributeData['value'] : null, + 'type' => $optionTypeAndValue['type'], + 'value' => $optionTypeAndValue['value'], ]; } @@ -575,6 +576,42 @@ public function insertSwatchOption(): void } } + /** + * Dispatch logic for getting type / value for each type of swatch option + */ + public function getTypeAndValue(array $swatchesAttributes, array $swatchesAttributeData): array + { + // If swatch attribute is a textual swatch returning textual data + if ($swatchesAttributes[$swatchesAttributeData['attribute']] === Swatch::SWATCH_TYPE_TEXTUAL_ATTRIBUTE_FRONTEND_INPUT) { + return [ + 'type' => Swatch::SWATCH_TYPE_TEXTUAL, + 'value' => $swatchesAttributeData['value'], + ]; + } + + // Keep the current data for visual swatch + /** @var AdapterInterface $connection */ + $connection = $this->entitiesHelper->getConnection(); + $current = $connection->fetchRow( + $connection->select() + ->from($this->entitiesHelper->getTable('eav_attribute_option_swatch'), ['value', 'type']) + ->where('store_id = ?', $swatchesAttributeData['store_id']) + ->where('option_id = ?', $swatchesAttributeData['option_id']) + ->limit(1) + ); + if (!empty($current)) { + return [ + 'type' => $current['type'], + 'value' => $current['value'], + ]; + } + + // Init default data + return [ + 'type' => Swatch::SWATCH_TYPE_EMPTY, + 'value' => null, + ]; + } /** * Drop temporary table diff --git a/composer.json b/composer.json index 30d1f4ac..b89c3e00 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "nyholm/psr7": "^1.5" }, "type": "magento2-module", - "version": "104.3.10", + "version": "104.3.11", "license": [ "OSL-3.0", "AFL-3.0"