¨4.0.1¨
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
import store from '../../store';
|
||||
import CartHelpersMixin from '../../mixins/CartHelpersMixin';
|
||||
import ProductHelpersMixin from '../../mixins/ProductHelpersMixin';
|
||||
import store from "../../store";
|
||||
import CartHelpersMixin from "../../mixins/CartHelpersMixin";
|
||||
import CartItemHelpersMixin from "../../mixins/CartItemHelpersMixin";
|
||||
|
||||
export default {
|
||||
mixins: [
|
||||
CartHelpersMixin,
|
||||
ProductHelpersMixin,
|
||||
],
|
||||
mixins: [CartHelpersMixin, CartItemHelpersMixin],
|
||||
|
||||
data() {
|
||||
return {
|
||||
@@ -34,47 +31,25 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
optionValues(option) {
|
||||
let values = [];
|
||||
|
||||
for (let value of option.values) {
|
||||
values.push(value.label);
|
||||
}
|
||||
|
||||
return values.join(', ');
|
||||
},
|
||||
|
||||
updateQuantity(cartItem, qty) {
|
||||
if (qty < 1 || this.exceedsMaxStock(cartItem, qty)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNaN(qty)) {
|
||||
qty = 1;
|
||||
}
|
||||
|
||||
updateCart(cartItem, qty) {
|
||||
this.loadingOrderSummary = true;
|
||||
|
||||
cartItem.qty = qty;
|
||||
|
||||
$.ajax({
|
||||
method: 'PUT',
|
||||
url: route('cart.items.update', { cartItemId: cartItem.id }),
|
||||
data: { qty: qty || 1 },
|
||||
}).then((cart) => {
|
||||
store.updateCart(cart);
|
||||
}).catch((xhr) => {
|
||||
this.$notify(xhr.responseJSON.message);
|
||||
}).always(() => {
|
||||
this.loadingOrderSummary = false;
|
||||
});
|
||||
axios
|
||||
.put(route("cart.items.update", { cartItemId: cartItem.id }), {
|
||||
qty: qty || 1,
|
||||
})
|
||||
.then((response) => {
|
||||
store.updateCart(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$notify(error.response.data.message);
|
||||
})
|
||||
.finally(() => {
|
||||
this.loadingOrderSummary = false;
|
||||
});
|
||||
},
|
||||
|
||||
exceedsMaxStock(cartItem, qty) {
|
||||
return cartItem.product.manage_stock && cartItem.product.qty < qty;
|
||||
},
|
||||
|
||||
remove(cartItem) {
|
||||
removeCartItem(cartItem) {
|
||||
this.loadingOrderSummary = true;
|
||||
|
||||
store.removeCartItem(cartItem);
|
||||
@@ -83,16 +58,19 @@ export default {
|
||||
this.crossSellProducts = [];
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
method: 'DELETE',
|
||||
url: route('cart.items.destroy', { cartItemId: cartItem.id }),
|
||||
}).then((cart) => {
|
||||
store.updateCart(cart);
|
||||
}).catch((xhr) => {
|
||||
this.$notify(xhr.responseJSON.message);
|
||||
}).always(() => {
|
||||
this.loadingOrderSummary = false;
|
||||
});
|
||||
axios
|
||||
.delete(
|
||||
route("cart.items.destroy", { cartItemId: cartItem.id })
|
||||
)
|
||||
.then((response) => {
|
||||
store.updateCart(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$notify(error.response.data.message);
|
||||
})
|
||||
.finally(() => {
|
||||
this.loadingOrderSummary = false;
|
||||
});
|
||||
},
|
||||
|
||||
clearCart() {
|
||||
@@ -102,29 +80,30 @@ export default {
|
||||
this.crossSellProducts = [];
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: route('cart.clear.store'),
|
||||
}).then((cart) => {
|
||||
store.updateCart(cart);
|
||||
}).catch((xhr) => {
|
||||
this.$notify(xhr.responseJSON.message);
|
||||
});
|
||||
axios
|
||||
.post(route("cart.clear.store"))
|
||||
.then((response) => {
|
||||
store.updateCart(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$notify(error.response.data.message);
|
||||
});
|
||||
},
|
||||
|
||||
changeShippingMethod(shippingMethodName) {
|
||||
this.shippingMethodName = shippingMethodName;
|
||||
},
|
||||
|
||||
fetchCrossSellProducts() {
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
url: route('cart.cross_sell_products.index'),
|
||||
}).then((crossSellProducts) => {
|
||||
this.crossSellProducts = crossSellProducts;
|
||||
}).catch((xhr) => {
|
||||
this.$notify(xhr.responseJSON.message);
|
||||
});
|
||||
async fetchCrossSellProducts() {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
route("cart.cross_sell_products.index")
|
||||
);
|
||||
|
||||
this.crossSellProducts = response.data;
|
||||
} catch (error) {
|
||||
this.$notify(error.response.data.message);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user