Skip to content

Commit

Permalink
Fixed #3758 variant query performance
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Nov 13, 2024
1 parent 83b9a4c commit 46cc29d
Show file tree
Hide file tree
Showing 2 changed files with 12 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 variant query performance degradation bug. ([#3758](https://github.com/craftcms/commerce/issues/3758))
- Fixed a bug where purchasables were showing incorrectly on the Edit Order screen. ([#3756](https://github.com/craftcms/commerce/issues/3756))

## 5.2.2.1 - 2024-11-08
Expand Down
11 changes: 11 additions & 0 deletions src/elements/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ public function attributes(): array
*/
public function getFieldLayout(): ?FieldLayout
{
$fieldLayout = parent::getFieldLayout();

if ($fieldLayout) {
// Variant field layouts are stored on the product type so retrieving the field layout by ID does not set the provider
$productType = collect(Plugin::getInstance()->getProductTypes()->getAllProductTypes())->firstWhere('variantFieldLayoutId', $fieldLayout->id);
if ($productType) {
$fieldLayout->provider = $productType;
return $fieldLayout;
}
}

try {
if ($this->getOwner() === null) {
return parent::getFieldLayout();
Expand Down

0 comments on commit 46cc29d

Please sign in to comment.