Skip to content

Commit fc55647

Browse files
committed
Fixed missing cascade on shipping rules methodId FK
1 parent fc2533d commit fc55647

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes for Craft Commerce
22

3+
## Unreleased
4+
5+
- Fixed a SQL error that could occur when deleting a shipping method.
6+
37
## 4.9.3 - 2025-09-04
48

59
- Fixed a bug where the `commerce/cart/update-cart` action could return unnecessary validation errors. ([3873](https://github.com/craftcms/commerce/issues/3873))

src/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static function editions(): array
210210
/**
211211
* @inheritDoc
212212
*/
213-
public string $schemaVersion = '4.9.0.0';
213+
public string $schemaVersion = '4.9.0.1';
214214

215215
/**
216216
* @inheritdoc

src/migrations/Install.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ public function addForeignKeys(): void
993993
$this->addForeignKey(null, Table::SALE_PURCHASABLES, ['saleId'], Table::SALES, ['id'], 'CASCADE', 'CASCADE');
994994
$this->addForeignKey(null, Table::SALE_USERGROUPS, ['saleId'], Table::SALES, ['id'], 'CASCADE', 'CASCADE');
995995
$this->addForeignKey(null, Table::SALE_USERGROUPS, ['userGroupId'], '{{%usergroups}}', ['id'], 'CASCADE', 'CASCADE');
996-
$this->addForeignKey(null, Table::SHIPPINGRULES, ['methodId'], Table::SHIPPINGMETHODS, ['id']);
996+
$this->addForeignKey(null, Table::SHIPPINGRULES, ['methodId'], Table::SHIPPINGMETHODS, ['id'], 'CASCADE');
997997
$this->addForeignKey(null, Table::SHIPPINGRULES, ['shippingZoneId'], Table::SHIPPINGZONES, ['id'], 'SET NULL');
998998
$this->addForeignKey(null, Table::SHIPPINGRULE_CATEGORIES, ['shippingCategoryId'], Table::SHIPPINGCATEGORIES, ['id'], 'CASCADE');
999999
$this->addForeignKey(null, Table::SHIPPINGRULE_CATEGORIES, ['shippingRuleId'], Table::SHIPPINGRULES, ['id'], 'CASCADE');
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace craft\commerce\migrations;
4+
5+
use craft\commerce\db\Table;
6+
use craft\db\Migration;
7+
8+
/**
9+
* m250919_111358_fix_methodId_shipping_rules_fk migration.
10+
*/
11+
class m250919_111358_fix_methodId_shipping_rules_fk extends Migration
12+
{
13+
/**
14+
* @inheritdoc
15+
*/
16+
public function safeUp(): bool
17+
{
18+
$this->dropForeignKeyIfExists(Table::SHIPPINGRULES, ['methodId']);
19+
20+
$this->addForeignKey(null, Table::SHIPPINGRULES, ['methodId'], Table::SHIPPINGMETHODS, ['id'], 'CASCADE');
21+
22+
return true;
23+
}
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
public function safeDown(): bool
29+
{
30+
echo "m250919_111358_fix_methodId_shipping_rules_fk cannot be reverted.\n";
31+
return false;
32+
}
33+
}

0 commit comments

Comments
 (0)