-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd17e96
commit fb4cba2
Showing
4 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/migrations/m200617_172414_fix_country_state_sort_orders.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace craft\commerce\migrations; | ||
|
||
use craft\db\Migration; | ||
use craft\db\Query; | ||
|
||
/** | ||
* m200617_172414_fix_country_state_sort_orders migration. | ||
*/ | ||
class m200617_172414_fix_country_state_sort_orders extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp() | ||
{ | ||
$countries = (new Query()) | ||
->select(['*']) | ||
->from('{{%commerce_countries}}') | ||
->limit(null) | ||
->orderBy(['name' => SORT_ASC]) | ||
->where(['sortOrder' => null]) | ||
->all(); | ||
|
||
$sortNumber = 1000; //start at 1000 so it doesn't affect if any countries had a sort previous | ||
foreach ($countries as $country) { | ||
$this->update('{{%commerce_countries}}', ['sortOrder' => $sortNumber], ['id' => $country['id']]); | ||
$sortNumber++; | ||
} | ||
|
||
$states = (new Query()) | ||
->select(['*']) | ||
->from('{{%commerce_states}}') | ||
->limit(null) | ||
->orderBy(['name' => SORT_ASC]) | ||
->where(['sortOrder' => null]) | ||
->all(); | ||
|
||
$sortNumber = 1000; //start at 1000 so it doesn't affect if any states had a sort previous | ||
foreach ($states as $state) { | ||
$this->update('{{%commerce_states}}', ['sortOrder' => $sortNumber], ['id' => $state['id']]); | ||
$sortNumber++; | ||
} | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown() | ||
{ | ||
echo "m200617_172414_fix_country_state_sort_orders cannot be reverted.\n"; | ||
return false; | ||
} | ||
} |