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

[2.x] Disable checkout button and add notice if not in stock #627

Merged
merged 18 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
12 changes: 12 additions & 0 deletions resources/js/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ function init() {
this.scrollLock = bool
}
},

canOrderCartItem(item) {
if ('stock_item' in item.product && 'in_stock' in item.product.stock_item && item.product.stock_item.in_stock !== null) {
return item.product.stock_item.in_stock
}

return true
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Cart Store may be a more logical place for this.
We're already adding additional data to items here

value.items = value.items.map((cartItem) => {

Maybe we could do it in a way to polyfill the currently broken is_available so once we drop support for Magento versions that do have it in it's broken state we can remove this code without breaking changes to the frontend

},
computed: {
// Wrap the local storage in getter and setter functions so you do not have to interact using .value
Expand All @@ -125,6 +133,10 @@ function init() {
hasCart() {
return this.cart?.id && this.cart.items.length
},

canOrder() {
return this.cart.items.every(this.canOrderCartItem)
},
},
watch: {
loadingCount: function (count) {
Expand Down
3 changes: 3 additions & 0 deletions resources/views/cart/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class="mx-auto"
<div class="flex flex-col items-start">
<a :href="item.product.url_key + item.product.url_suffix | url" class="font-bold" dusk="cart-item-name">
@{{ item.product.name }}
<div class="text-red-600" v-if="!canOrderCartItem(item)">
@lang('This product it out of stock, remove it to continue your order.')
</div>
</a>
<div v-for="option in item.configurable_options">
@{{ option.option_label }}: @{{ option.value_label }}
Expand Down
1 change: 1 addition & 0 deletions resources/views/cart/queries/cart.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ items {
}
@if (Rapidez::checkCompadreVersion('0.0.1'))
stock_item {
in_stock
max_sale_qty
min_sale_qty
qty_increments
Expand Down
13 changes: 10 additions & 3 deletions resources/views/cart/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
</div>
</dl>

<x-rapidez::button href="{{ route('checkout') }}" dusk="checkout" class="w-full text-center">
@lang('Checkout')
</x-rapidez::button>
<div class="w-full" :class="{ 'cursor-not-allowed': !canOrder }">
<x-rapidez::button
dusk="checkout"
href="{{ route('checkout') }}"
class="w-full text-center"
v-bind:class="{ 'pointer-events-none': !canOrder }"
>
@lang('Checkout')
</x-rapidez::button>
</div>
Loading