Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #3813 variant chips displaying incorrectly #3820

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion src/controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
8 changes: 0 additions & 8 deletions src/elements/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading