diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d7712966..d31298de4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Fixed a PHP error when eager loading a variant’s owner. ([#3817](https://github.com/craftcms/commerce/issues/3817)) +- Fixed a bug where variant chips were displaying incorrectly. ([#3813](https://github.com/craftcms/commerce/issues/3813)) ## 5.2.9.1 - 2024-12-13 diff --git a/src/controllers/OrdersController.php b/src/controllers/OrdersController.php index e51dabb2b5..b0b73d8d95 100644 --- a/src/controllers/OrdersController.php +++ b/src/controllers/OrdersController.php @@ -18,6 +18,7 @@ use craft\commerce\db\Table; use craft\commerce\elements\db\PurchasableQuery; use craft\commerce\elements\Order; +use craft\commerce\elements\Variant; use craft\commerce\enums\InventoryTransactionType; use craft\commerce\enums\LineItemType; use craft\commerce\errors\CurrencyException; @@ -613,9 +614,16 @@ private function _orderToArray(Order $order): array continue; } - $purchasableCpEditUrlByPurchasableId[$purchasable->id] = $purchasable->getCpEditUrl(); + if ($purchasable instanceof Variant) { + $product = $purchasable->getOwner(); + $purchasableCpEditUrlByPurchasableId[$purchasable->id] = $product?->getCpEditUrl() ?? null; + } else { + $purchasableCpEditUrlByPurchasableId[$purchasable->id] = $purchasable->getCpEditUrl(); + } } + $purchasableCpEditUrlByPurchasableId = array_filter($purchasableCpEditUrlByPurchasableId); + $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); diff --git a/src/elements/Variant.php b/src/elements/Variant.php index 4c9a78a613..f3845878ae 100755 --- a/src/elements/Variant.php +++ b/src/elements/Variant.php @@ -740,14 +740,6 @@ public function canView(User $user): bool return $product->canView($user); } - /** - * @inheritdoc - */ - public function getCpEditUrl(): ?string - { - return $this->getOwner() ? $this->getOwner()->getCpEditUrl() : null; - } - /** * @inheritdoc */