diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f492d723f..0a27faa719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Fixed a bug where a structured product type’s “Max Levels” setting wasn’t being respected. ([#3785](https://github.com/craftcms/commerce/issues/3785)) - Fixed a bug where users could access the Commerce user screen when the current user didn’t have permission. ## 5.2.6 - 2024-11-26 diff --git a/src/Plugin.php b/src/Plugin.php index e8764107b6..8fef95aa8d 100755 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -257,7 +257,7 @@ public static function editions(): array /** * @inheritDoc */ - public string $schemaVersion = '5.2.0.5'; + public string $schemaVersion = '5.2.7.0'; /** * @inheritdoc diff --git a/src/migrations/m241128_174712_fix_maxLevels_structured_productTypes.php b/src/migrations/m241128_174712_fix_maxLevels_structured_productTypes.php new file mode 100644 index 0000000000..f07f69385d --- /dev/null +++ b/src/migrations/m241128_174712_fix_maxLevels_structured_productTypes.php @@ -0,0 +1,43 @@ +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; + } +} diff --git a/src/services/ProductTypes.php b/src/services/ProductTypes.php index ec5cd855da..d771561364 100755 --- a/src/services/ProductTypes.php +++ b/src/services/ProductTypes.php @@ -475,7 +475,7 @@ public function handleChangedProductType(ConfigEvent $event): void $structureUid = $data['structure']['uid']; $structure = Craft::$app->getStructures()->getStructureByUid($structureUid, true) ?? new Structure(['uid' => $structureUid]); $isNewStructure = empty($structure->id); - $structure->maxLevels = $data['structure']['maxLevels'] ?? null; + $structure->maxLevels = $data['maxLevels'] ?? null; Craft::$app->getStructures()->saveStructure($structure); $productTypeRecord->structureId = $structure->id; } else {