Skip to content

Commit

Permalink
Merge pull request #3820 from craftcms/feature/pt-2346-5x-unable-to-e…
Browse files Browse the repository at this point in the history
…dit-product-variants-due-to-faulty-chip

Fixed #3813 variant chips displaying incorrectly
  • Loading branch information
nfourtythree authored Dec 17, 2024
2 parents 5eacab1 + 9f3989c commit 744dd56
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
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

0 comments on commit 744dd56

Please sign in to comment.