Skip to content

Commit

Permalink
[6.x] Fix "Recursion detected" error with cart endpoints (#1025)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
duncanmcclean committed Mar 1, 2024
1 parent 5701081 commit 8099471
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package-lock.json
.idea
.antlers.json
composer.lock
.phpunit.cache

tests/__fixtures__/users/*.yaml

Expand Down
8 changes: 6 additions & 2 deletions src/Http/Controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function index(IndexRequest $request)
return [
'data' => $this->getCart()
->toAugmentedCollection()
->withRelations(['customer', 'customer_id'])
->withShallowNesting()
->toArray(),
];
Expand Down Expand Up @@ -58,7 +59,11 @@ public function update(UpdateRequest $request)

return $this->withSuccess($request, [
'message' => __('Cart Updated'),
'cart' => $cart->toAugmentedArray(),
'cart' => $cart
->toAugmentedCollection()
->withRelations(['customer', 'customer_id'])
->withShallowNesting()
->toArray(),
]);
}

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

return $this->withSuccess($request, [
'message' => __('Cart Deleted'),
'cart' => null,
]);
}

Expand Down
18 changes: 15 additions & 3 deletions src/Http/Controllers/CartItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ public function store(StoreRequest $request)

return $this->withSuccess($request, [
'message' => __('Added to Cart'),
'cart' => $cart->fresh()->toAugmentedArray(),
'cart' => $cart
->toAugmentedCollection()
->withRelations(['customer', 'customer_id'])
->withShallowNesting()
->toArray(),
]);
}

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

return $this->withSuccess($request, [
'message' => __('Line Item Updated'),
'cart' => $cart->toAugmentedArray(),
'cart' => $cart
->toAugmentedCollection()
->withRelations(['customer', 'customer_id'])
->withShallowNesting()
->toArray(),
]);
}

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

return $this->withSuccess($request, [
'message' => __('Item Removed from Cart'),
'cart' => $cart->toAugmentedArray(),
'cart' => $cart
->toAugmentedCollection()
->withRelations(['customer', 'customer_id'])
->withShallowNesting()
->toArray(),
]);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Http/Controllers/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public function __invoke(CheckoutRequest $request)

return $this->withSuccess($request, [
'message' => __('Checkout Complete!'),
'cart' => $this->order->toAugmentedArray(),
'cart' => $this->order
->toAugmentedCollection()
->withRelations(['customer', 'customer_id'])
->withShallowNesting()
->toArray(),
'is_checkout_request' => true,
]);
}
Expand Down
12 changes: 10 additions & 2 deletions src/Http/Controllers/CouponController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public function store(StoreRequest $request)

return $this->withSuccess($request, [
'message' => __('Coupon added to cart'),
'cart' => $this->getCart()->toAugmentedArray(),
'cart' => $cart
->toAugmentedCollection()
->withRelations(['customer', 'customer_id'])
->withShallowNesting()
->toArray(),
]);
}

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

return $this->withSuccess($request, [
'message' => __('Coupon removed from cart'),
'cart' => $this->getCart()->toAugmentedArray(),
'cart' => $cart
->toAugmentedCollection()
->withRelations(['customer', 'customer_id'])
->withShallowNesting()
->toArray(),
]);
}
}
1 change: 0 additions & 1 deletion tests/Http/Controllers/CartControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,6 @@
$response->assertJsonStructure([
'status',
'message',
'cart',
]);

$cart = $cart->fresh();
Expand Down

0 comments on commit 8099471

Please sign in to comment.