From d610f570206c54ab3586a572bc15c8265fac17b8 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Thu, 17 Oct 2024 15:28:13 +0800 Subject: [PATCH] Fixed sku getting too long In addition to the b38491e fix --- CHANGELOG.md | 4 ++ src/Plugin.php | 2 +- .../m241017_072151_fix_temp_skus.php | 43 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/migrations/m241017_072151_fix_temp_skus.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 32888d0ea2..7f50ed36e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft Commerce +## Unreleased + +- Fixed an SQL error that occurred when duplicating variants. ([#3727](https://github.com/craftcms/commerce/issues/3727)) + ## 5.2.0 - 2024-10-16 ### Store Management diff --git a/src/Plugin.php b/src/Plugin.php index 668a50d35c..0b9e573173 100755 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -254,7 +254,7 @@ public static function editions(): array /** * @inheritDoc */ - public string $schemaVersion = '5.2.0.3'; + public string $schemaVersion = '5.2.0.4'; /** * @inheritdoc diff --git a/src/migrations/m241017_072151_fix_temp_skus.php b/src/migrations/m241017_072151_fix_temp_skus.php new file mode 100644 index 0000000000..bb75d2eabb --- /dev/null +++ b/src/migrations/m241017_072151_fix_temp_skus.php @@ -0,0 +1,43 @@ +select(['id', 'sku']) + ->from('{{%commerce_purchasables}}') + ->where(['like', 'sku', '__temp_%', false]) + ->all(); + + // Need a unique one per purchasable + foreach ($purchasables as $purchasable) { + $newSku = Purchasable::tempSku(); + $this->update('{{%commerce_purchasables}}', ['sku' => $newSku], ['id' => $purchasable['id']]); + } + + return true; + } + + /** + * @inheritdoc + */ + public function safeDown(): bool + { + echo "m241017_072151_fix_temp_skus cannot be reverted.\n"; + return false; + } +}