Skip to content

Commit 8099471

Browse files
[6.x] Fix "Recursion detected" error with cart endpoints (#1025)
* Fix "Recursion detected" error with cart endpoints * wip * this should still be `data` * Ignore `.phpunit.cache` * we're not returning `cart` from delete endpoint anymore When you're deleting something, you shouldn't really get anything back. * Use the "local" cart, rather than fetching it from the cart driver
1 parent 5701081 commit 8099471

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package-lock.json
77
.idea
88
.antlers.json
99
composer.lock
10+
.phpunit.cache
1011

1112
tests/__fixtures__/users/*.yaml
1213

src/Http/Controllers/CartController.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function index(IndexRequest $request)
2424
return [
2525
'data' => $this->getCart()
2626
->toAugmentedCollection()
27+
->withRelations(['customer', 'customer_id'])
2728
->withShallowNesting()
2829
->toArray(),
2930
];
@@ -58,7 +59,11 @@ public function update(UpdateRequest $request)
5859

5960
return $this->withSuccess($request, [
6061
'message' => __('Cart Updated'),
61-
'cart' => $cart->toAugmentedArray(),
62+
'cart' => $cart
63+
->toAugmentedCollection()
64+
->withRelations(['customer', 'customer_id'])
65+
->withShallowNesting()
66+
->toArray(),
6267
]);
6368
}
6469

@@ -72,7 +77,6 @@ public function destroy(DestroyRequest $request)
7277

7378
return $this->withSuccess($request, [
7479
'message' => __('Cart Deleted'),
75-
'cart' => null,
7680
]);
7781
}
7882

src/Http/Controllers/CartItemController.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ public function store(StoreRequest $request)
119119

120120
return $this->withSuccess($request, [
121121
'message' => __('Added to Cart'),
122-
'cart' => $cart->fresh()->toAugmentedArray(),
122+
'cart' => $cart
123+
->toAugmentedCollection()
124+
->withRelations(['customer', 'customer_id'])
125+
->withShallowNesting()
126+
->toArray(),
123127
]);
124128
}
125129

@@ -163,7 +167,11 @@ public function update(UpdateRequest $request, string $requestItem)
163167

164168
return $this->withSuccess($request, [
165169
'message' => __('Line Item Updated'),
166-
'cart' => $cart->toAugmentedArray(),
170+
'cart' => $cart
171+
->toAugmentedCollection()
172+
->withRelations(['customer', 'customer_id'])
173+
->withShallowNesting()
174+
->toArray(),
167175
]);
168176
}
169177

@@ -175,7 +183,11 @@ public function destroy(DestroyRequest $request, string $item)
175183

176184
return $this->withSuccess($request, [
177185
'message' => __('Item Removed from Cart'),
178-
'cart' => $cart->toAugmentedArray(),
186+
'cart' => $cart
187+
->toAugmentedCollection()
188+
->withRelations(['customer', 'customer_id'])
189+
->withShallowNesting()
190+
->toArray(),
179191
]);
180192
}
181193

src/Http/Controllers/CheckoutController.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ public function __invoke(CheckoutRequest $request)
5252

5353
return $this->withSuccess($request, [
5454
'message' => __('Checkout Complete!'),
55-
'cart' => $this->order->toAugmentedArray(),
55+
'cart' => $this->order
56+
->toAugmentedCollection()
57+
->withRelations(['customer', 'customer_id'])
58+
->withShallowNesting()
59+
->toArray(),
5660
'is_checkout_request' => true,
5761
]);
5862
}

src/Http/Controllers/CouponController.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public function store(StoreRequest $request)
2525

2626
return $this->withSuccess($request, [
2727
'message' => __('Coupon added to cart'),
28-
'cart' => $this->getCart()->toAugmentedArray(),
28+
'cart' => $cart
29+
->toAugmentedCollection()
30+
->withRelations(['customer', 'customer_id'])
31+
->withShallowNesting()
32+
->toArray(),
2933
]);
3034
}
3135

@@ -41,7 +45,11 @@ public function destroy(DestroyRequest $request)
4145

4246
return $this->withSuccess($request, [
4347
'message' => __('Coupon removed from cart'),
44-
'cart' => $this->getCart()->toAugmentedArray(),
48+
'cart' => $cart
49+
->toAugmentedCollection()
50+
->withRelations(['customer', 'customer_id'])
51+
->withShallowNesting()
52+
->toArray(),
4553
]);
4654
}
4755
}

tests/Http/Controllers/CartControllerTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@
674674
$response->assertJsonStructure([
675675
'status',
676676
'message',
677-
'cart',
678677
]);
679678

680679
$cart = $cart->fresh();

0 commit comments

Comments
 (0)