-
Notifications
You must be signed in to change notification settings - Fork 172
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
Showing
19 changed files
with
237 additions
and
44 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
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
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
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
63 changes: 63 additions & 0 deletions
63
src/migrations/m240306_091057_move_element_ids_on_discount_to_columns.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,63 @@ | ||
<?php | ||
|
||
namespace craft\commerce\migrations; | ||
|
||
use craft\db\Migration; | ||
use craft\db\Query as Query; | ||
use craft\helpers\Json; | ||
|
||
/** | ||
* m240306_091057_move_element_ids_on_discount_to_columns migration. | ||
*/ | ||
class m240306_091057_move_element_ids_on_discount_to_columns extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp(): bool | ||
{ | ||
$discountCategoriesTable = '{{%commerce_discount_categories}}'; | ||
$discountPurchasablesTables = '{{%commerce_discount_purchasables}}'; | ||
$discountsTable = '{{%commerce_discounts}}'; | ||
|
||
$this->addColumn($discountsTable, 'purchasableIds', $this->text()->after('allPurchasables')); | ||
$this->addColumn($discountsTable, 'categoryIds', $this->text()->after('allCategories')); | ||
|
||
$purchasableIdsByDiscountId = (new Query()) | ||
->select(['discountId', 'purchasableId']) | ||
->from([$discountPurchasablesTables]) | ||
->collect(); | ||
|
||
$purchasableIdsByDiscountId = $purchasableIdsByDiscountId->groupBy('discountId')->map(function($row) { | ||
return array_column($row->toArray(), 'purchasableId'); | ||
}); | ||
|
||
$categoryIdsByDiscountId = (new Query()) | ||
->select(['discountId', 'categoryId']) | ||
->from([$discountCategoriesTable]) | ||
->collect(); | ||
|
||
$categoryIdsByDiscountId = $categoryIdsByDiscountId->groupBy('discountId')->map(function($row) { | ||
return array_column($row->toArray(), 'categoryId'); | ||
}); | ||
|
||
foreach ($purchasableIdsByDiscountId as $discountId => $purchasableIds) { | ||
$this->update($discountsTable, ['purchasableIds' => Json::encode($purchasableIds)], ['id' => $discountId]); | ||
} | ||
|
||
foreach ($categoryIdsByDiscountId as $discountId => $categoryIds) { | ||
$this->update($discountsTable, ['categoryIds' => Json::encode($categoryIds)], ['id' => $discountId]); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
echo "m240306_091057_move_element_ids_on_discount_to_columns cannot be reverted.\n"; | ||
return false; | ||
} | ||
} |
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
Oops, something went wrong.