Skip to content

Commit edf6a22

Browse files
committed
Fixed cart items being null for cart update
1 parent df78f27 commit edf6a22

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/OminityApiClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class OminityApiClient
1818
/**
1919
* Version of our client.
2020
*/
21-
public const CLIENT_VERSION = "1.3.1";
21+
public const CLIENT_VERSION = "1.3.2";
2222

2323
/**
2424
* Endpoint of the remote API.

src/Resources/Commerce/Cart.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,18 @@ public function update()
319319
"currency" => $this->currency,
320320
"country" => $this->country,
321321
"shippingMethodId" => $this->shippingMethodId,
322-
"items" => array_map(function($item) {
322+
"items" => array_values(array_filter(array_map(function ($item) {
323+
if (!is_object($item) || empty($item->productId)) {
324+
return null;
325+
}
326+
323327
return array_filter([
324328
"id" => $item->id ?? null,
325329
"productId" => $item->productId,
326330
"productOfferId" => $item->productOfferId ?? null,
327331
"quantity" => $item->quantity ?? 1,
328-
], function($value) {
329-
return $value !== null;
330-
});
331-
}, $this->items),
332+
], static fn ($value) => $value !== null);
333+
}, is_array($this->items) ? $this->items : []))),
332334
"billingAddress" => $this->billingAddress ?? [],
333335
"shippingAddress" => $this->shippingAddress ?? [],
334336
"promotionCodes" => $this->promotionCodes ?? [],

0 commit comments

Comments
 (0)