Skip to content

Commit

Permalink
Fixed #3253 consistent decoding of line item snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Oct 30, 2023
1 parent 9591d9d commit 2d0a70b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fixed a PHP error that occurred when sending an email with a missing PDF filename format. ([#3309](https://github.com/craftcms/commerce/issues/3309))
- Product GQL queries now support `promotable`, `availableForPurchase`, `freeShipping`, `defaultSku`, `defaultPrice`, `defaultVariant`, `defaultHeight`, `defaultLength`, `defaultWidth`, and `defaultWeight` params. ([#3307](https://github.com/craftcms/commerce/pull/3307))
- Fixed an incorrect validation error that occurred when saving a Shipping Zone. ([#3317](https://github.com/craftcms/commerce/issues/3317))
- Fixed a bug where a line item’s snapshot wasn’t being decoded. ([#3253](https://github.com/craftcms/commerce/issues/3253))

## 4.3.1 - 2023-10-18

Expand Down
5 changes: 5 additions & 0 deletions src/services/LineItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ public function getLineItemById(int $id): ?LineItem
->where(['id' => $id])
->one();

if ($result) {
// Unpack the snapshot
$result['snapshot'] = Json::decodeIfJson($result['snapshot']);
}

return $result ? new LineItem($result) : null;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/services/LineItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ public function testGetLineItemById(): void
self::assertEquals($lineItems[0]->qty, $lineItem->qty);
}

public function testSnapshotUnpacking(): void
{
/** @var Order $order */
$order = $this->fixtureData->getElement('completed-new');
$lineItemById = $this->service->getLineItemById($order->getLineItems()[0]->id);
$lineItemFromAll = collect($this->service->getAllLineItemsByOrderId($order->id))->firstWhere('id', $lineItemById->id);

self::assertIsArray($lineItemById->snapshot);
self::assertIsArray($lineItemFromAll->snapshot);
self::assertEquals($lineItemById->snapshot, $lineItemFromAll->snapshot);
}

public function testCreateLineItem(): void
{
/** @var Order $order */
Expand Down

0 comments on commit 2d0a70b

Please sign in to comment.