-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3787 from craftcms/feature/pt-2323-5x-max-levels-…
…are-not-taken-into-account-for-structured [5.x] Product type’s max levels setting not being respected
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 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
43 changes: 43 additions & 0 deletions
43
src/migrations/m241128_174712_fix_maxLevels_structured_productTypes.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,43 @@ | ||
<?php | ||
|
||
namespace craft\commerce\migrations; | ||
|
||
use craft\commerce\db\Table; | ||
use craft\db\Migration; | ||
use craft\db\Query; | ||
use craft\db\Table as CraftTable; | ||
|
||
/** | ||
* m241128_174712_fix_maxLevels_structured_productTypes migration. | ||
*/ | ||
class m241128_174712_fix_maxLevels_structured_productTypes extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp(): bool | ||
{ | ||
// Get all product types from Commerce project config | ||
$structuredProductTypesWithMaxLevels = (new Query()) | ||
->from(Table::PRODUCTTYPES) | ||
->where(['isStructure' => true]) | ||
->andWhere(['not', ['maxLevels' => null]]) | ||
->collect(); | ||
|
||
// Loop through and update the `maxLevels` column in the `structures` table | ||
$structuredProductTypesWithMaxLevels->each(function($productType) { | ||
$this->update(CraftTable::STRUCTURES, ['maxLevels' => $productType['maxLevels']], ['id' => $productType['structureId']]); | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
echo "m241128_174712_fix_maxLevels_structured_productTypes 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