Skip to content

Commit

Permalink
Fixed sku getting too long
Browse files Browse the repository at this point in the history
In addition to the b38491e fix
  • Loading branch information
lukeholder committed Oct 17, 2024
1 parent b38491e commit d610f57
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions src/migrations/m241017_072151_fix_temp_skus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace craft\commerce\migrations;

use Craft;
use craft\commerce\helpers\Purchasable;
use craft\db\Migration;

/**
* m241017_072151_fix_temp_skus migration.
*/
class m241017_072151_fix_temp_skus extends Migration
{
/**
* @inheritdoc
*/
public function safeUp(): bool
{
// get any sku that starts with __temp_ in the purchasables table, loop over them and replace with a new SKU
$purchasables = (new \craft\db\Query())
->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;
}
}

0 comments on commit d610f57

Please sign in to comment.