From 46cc29dd14a68ec52d5147bc417b3020f86f0641 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Wed, 13 Nov 2024 08:43:04 +0000 Subject: [PATCH] Fixed #3758 variant query performance --- CHANGELOG.md | 1 + src/elements/Variant.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 286e463c03..4e346b8587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/elements/Variant.php b/src/elements/Variant.php index b9f1233ecd..f1b8816b92 100755 --- a/src/elements/Variant.php +++ b/src/elements/Variant.php @@ -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();