Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
BobWez98 committed Nov 14, 2024
1 parent 79132b0 commit ba381d9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
10 changes: 1 addition & 9 deletions resources/js/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ function init() {
}
},

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
},

resizedPath(imagePath, size, store = null) {
if (!store) {
store = window.config.store
Expand All @@ -146,7 +138,7 @@ function init() {
},

canOrder() {
return this.cart.items.every(this.canOrderCartItem)
return this.cart.items.every((item) => item.is_available)
},
},
watch: {
Expand Down
24 changes: 24 additions & 0 deletions resources/js/stores/useCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ export const getAttributeValues = async function () {
return await fetchAttributeValuesMemo(window.config.cart_attributes)
}

export const checkAvailability = function (cartItem) {
// Here we polyfill the is_available field. We need to do this
// because the default is_available field supported by Magento
// always returns true, even when a product is out of stock. This
// should be fixed in the next Magento release.
console.log(cartItem)
if ('stock_item' in cartItem.product && 'in_stock' in cartItem.product.stock_item && cartItem.product.stock_item.in_stock !== null) {
return cartItem.product.stock_item.in_stock
}

// Without the use of compadre the in stock check can't be
// done. We will need to always allow users to go on to
// the checkout.
return true
}

export const cart = computed({
get() {
if (!cartStorage.value?.id && mask.value) {
Expand All @@ -101,12 +117,19 @@ export const cart = computed({
cartStorage.value.fixedProductTaxes = fixedProductTaxes
cartStorage.value.taxTotal = taxTotal


return cartStorage.value
},
set(value) {
getAttributeValues()
.then((response) => {
if (!response?.data?.customAttributeMetadata?.items) {
value.items = value.items.map((item) => {
item.is_available = checkAvailability(item)

return item
})

return
}

Expand All @@ -118,6 +141,7 @@ export const cart = computed({
)

value.items = value.items.map((cartItem) => {
item.is_available = checkAvailability(item)
cartItem.product.attribute_values = {}

for (const key in mapping) {
Expand Down
2 changes: 1 addition & 1 deletion resources/views/cart/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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)">
<div class="text-red-600" v-if="!item.is_available">
@lang('This product it out of stock, remove it to continue your order.')
</div>
</a>
Expand Down

0 comments on commit ba381d9

Please sign in to comment.