Skip to content

Commit

Permalink
Fix max elements for variants
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Jan 13, 2025
1 parent 7df7977 commit 379c997
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/fieldlayoutelements/VariantsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
Expand Down

0 comments on commit 379c997

Please sign in to comment.