Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #9761 #9774

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

- [Updating Dependencies](#updating-dependencies)
- [The `Webkul\Checkout\Cart` class](#the-cart-class)
- [Shop API Response Updates](#the-shop-api-response-updates)

</div>

Expand Down Expand Up @@ -403,6 +404,29 @@ All methods from the following traits have been relocated to the `Webkul\Checkou
<a name="shop"></a>
### Shop

<a name="the-shop-api-response-updates"></a>
#### Shop API Response Updates

**Impact Probability: High**

1. The response for the Shop route `shop.api.checkout.cart.store` API has been updated. If you are consuming this API, please make the necessary changes. we have refined the exception handling to provide more specific error responses and HTTP_BAD_REQUEST status code, ensuring better feedback for users.

```diff
- catch (\Exception $exception) {
- return new JsonResource([
- 'redirect_uri' => route('shop.product_or_category.index', $product->product->url_key),
- 'message' => $exception->getMessage(),
- ]);
- }

+ catch (\Exception $exception) {
+ return response()->json([
+ 'redirect_uri' => route('shop.product_or_category.index', $product->url_key),
+ 'message' => $exception->getMessage(),
+ ], Response::HTTP_BAD_REQUEST);
+ }
```

<a name="shop-customized-datagrid-parameters-updated"></a>
#### Shop Customized Datagrid Parameters Updated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public function store()
], $response));
} catch (\Exception $exception) {
return response()->json([
'redirect_uri' => request()->get('is_buy_now') ? route('shop.product_or_category.index', $product->url_key) : null,
'message' => trans('shop::app.checkout.cart.inactive-add'),
'redirect_uri' => route('shop.product_or_category.index', $product->url_key),
'message' => $exception->getMessage(),
], Response::HTTP_BAD_REQUEST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,13 @@ class="primary-button whitespace-nowrap px-8 py-2.5"
},

addToCart() {

this.isAddingToCart = true;

this.$axios.post('{{ route("shop.api.checkout.cart.store") }}', {
'quantity': 1,
'product_id': this.product.id,
})
.then(response => {
if (response.data.data.redirect_uri) {
window.location.href = response.data.data.redirect_uri;
}

if (response.data.message) {
this.$emitter.emit('update-mini-cart', response.data.data );

Expand All @@ -374,9 +369,13 @@ class="primary-button whitespace-nowrap px-8 py-2.5"
this.isAddingToCart = false;
})
.catch(error => {
this.isAddingToCart = false;

this.$emitter.emit('add-flash', { type: 'error', message: error.response.data.message });

if (error.response.data.redirect_uri) {
window.location.href = error.response.data.redirect_uri;
}

this.isAddingToCart = false;
});
},
},
Expand Down