diff --git a/CHANGELOG.md b/CHANGELOG.md index 70c98e7d78..c860dc2924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Fixed a bug where product type’s “Max Variants” setting was not being respected. ([#3845](https://github.com/craftcms/commerce/issues/3845)) - Fixed a bug where products could be duplicated without the “Create products” permissions. ([#3838](https://github.com/craftcms/commerce/issues/3838)) ## 5.2.11 - 2025-01-02 diff --git a/src/fieldlayoutelements/VariantsField.php b/src/fieldlayoutelements/VariantsField.php index 20af5277a6..a2a9bf4ffd 100644 --- a/src/fieldlayoutelements/VariantsField.php +++ b/src/fieldlayoutelements/VariantsField.php @@ -59,8 +59,12 @@ protected function inputHtml(ElementInterface $element = null, bool $static = fa Craft::$app->getView()->registerDeltaName($this->attribute()); + $maxVariants = $element->getType()->maxVariants; + return $element->getVariantManager()->getIndexHtml($element, [ 'canCreate' => !$static, + 'minElements' => 0, + 'maxElements' => $maxVariants ?? null, 'allowedViewModes' => [ElementIndexViewMode::Cards, ElementIndexViewMode::Table], 'sortable' => !$static, 'fieldLayouts' => [$element->getType()->getVariantFieldLayout()],