¨4.0.1¨
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import store from '../store';
|
||||
import store from "../store";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@@ -21,7 +21,7 @@ export default {
|
||||
},
|
||||
|
||||
cartIsNotEmpty() {
|
||||
return ! store.cartIsEmpty();
|
||||
return !store.cartIsEmpty();
|
||||
},
|
||||
|
||||
hasShippingMethod() {
|
||||
@@ -39,45 +39,48 @@ export default {
|
||||
|
||||
methods: {
|
||||
applyCoupon() {
|
||||
if (! this.couponCode) {
|
||||
if (!this.couponCode) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.loadingOrderSummary = true;
|
||||
this.applyingCoupon = true;
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: route('cart.coupon.store', { coupon: this.couponCode }),
|
||||
}).then((cart) => {
|
||||
this.couponCode = null;
|
||||
axios
|
||||
.post(route("cart.coupon.store"), { coupon: this.couponCode })
|
||||
.then((response) => {
|
||||
this.couponCode = null;
|
||||
this.couponError = null;
|
||||
|
||||
store.updateCart(cart);
|
||||
}).catch((xhr) => {
|
||||
this.couponError = xhr.responseJSON.message;
|
||||
}).always(() => {
|
||||
this.loadingOrderSummary = false;
|
||||
this.applyingCoupon = false;
|
||||
});
|
||||
store.updateCart(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.couponError = error.response.data.message;
|
||||
})
|
||||
.finally(() => {
|
||||
this.loadingOrderSummary = false;
|
||||
this.applyingCoupon = false;
|
||||
});
|
||||
},
|
||||
|
||||
removeCoupon() {
|
||||
this.loadingOrderSummary = true;
|
||||
|
||||
$.ajax({
|
||||
method: 'DELETE',
|
||||
url: route('cart.coupon.destroy'),
|
||||
}).then((cart) => {
|
||||
store.updateCart(cart);
|
||||
}).catch((xhr) => {
|
||||
this.$notify(xhr.responseJSON.message);
|
||||
}).always(() => {
|
||||
this.loadingOrderSummary = false;
|
||||
});
|
||||
axios
|
||||
.delete(route("cart.coupon.destroy"))
|
||||
.then((response) => {
|
||||
store.updateCart(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$notify(error.response.data.message);
|
||||
})
|
||||
.finally(() => {
|
||||
this.loadingOrderSummary = false;
|
||||
});
|
||||
},
|
||||
|
||||
updateShippingMethod(shippingMethodName) {
|
||||
if (! shippingMethodName) {
|
||||
async updateShippingMethod(shippingMethodName) {
|
||||
if (!shippingMethodName) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,16 +88,24 @@ export default {
|
||||
|
||||
this.changeShippingMethod(shippingMethodName);
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: route('cart.shipping_method.store', { shipping_method: shippingMethodName }),
|
||||
}).then((cart) => {
|
||||
store.updateCart(cart);
|
||||
}).catch((xhr) => {
|
||||
this.$notify(xhr.responseJSON.message);
|
||||
}).always(() => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
route("cart.shipping_method.store", {
|
||||
...(store.hasCoupon() && {
|
||||
coupon_code: store.getCoupon(),
|
||||
}),
|
||||
}),
|
||||
{
|
||||
shipping_method: shippingMethodName,
|
||||
}
|
||||
);
|
||||
|
||||
store.updateCart(response.data);
|
||||
} catch (error) {
|
||||
this.$notify(error.response.data.message);
|
||||
} finally {
|
||||
this.loadingOrderSummary = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
export default {
|
||||
methods: {
|
||||
productUrl({ product, variant }) {
|
||||
return route("products.show", {
|
||||
slug: product.slug,
|
||||
...(variant !== null && {
|
||||
variant: variant.uid,
|
||||
}),
|
||||
});
|
||||
},
|
||||
|
||||
hasBaseImage({ item }) {
|
||||
return item.base_image.length !== 0;
|
||||
},
|
||||
|
||||
baseImage(cartItem) {
|
||||
if (this.hasBaseImage(cartItem)) {
|
||||
return cartItem.item.base_image.path;
|
||||
}
|
||||
|
||||
return `${window.FleetCart.baseUrl}/build/assets/image-placeholder.png`;
|
||||
},
|
||||
|
||||
optionValues(option) {
|
||||
let values = [];
|
||||
|
||||
for (let value of option.values) {
|
||||
values.push(value.label);
|
||||
}
|
||||
|
||||
return values.join(", ");
|
||||
},
|
||||
|
||||
maxQuantity({ item }) {
|
||||
return item.is_in_stock && item.does_manage_stock ? item.qty : null;
|
||||
},
|
||||
|
||||
exceedsMaxStock({ item, qty }) {
|
||||
return item.does_manage_stock && item.qty < qty;
|
||||
},
|
||||
|
||||
isQtyIncreaseDisabled(cartItem) {
|
||||
return (
|
||||
this.maxQuantity(cartItem) !== null &&
|
||||
cartItem.qty >= cartItem.item.qty
|
||||
);
|
||||
},
|
||||
|
||||
changeQuantity(cartItem, qty) {
|
||||
if (isNaN(qty) || qty < 1) {
|
||||
qty = 1;
|
||||
|
||||
this.updateCart(cartItem, qty);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
cartItem.qty = qty;
|
||||
|
||||
if (this.exceedsMaxStock(cartItem)) {
|
||||
qty = cartItem.item.qty;
|
||||
|
||||
this.updateCart(cartItem, qty);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateCart(cartItem, qty);
|
||||
},
|
||||
|
||||
updateQuantity(cartItem, qty) {
|
||||
if (isNaN(qty) || qty < 1) {
|
||||
qty = 1;
|
||||
cartItem.qty = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
cartItem.qty = qty;
|
||||
|
||||
if (this.exceedsMaxStock(cartItem)) {
|
||||
cartItem.qty = cartItem.item.qty;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateCart(cartItem, qty);
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -26,7 +26,7 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
change(activeTab) {
|
||||
async change(activeTab) {
|
||||
if (this.activeTab === activeTab || activeTab === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -34,20 +34,17 @@ export default {
|
||||
this.loading = true;
|
||||
this.activeTab = activeTab;
|
||||
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: activeTab.url,
|
||||
}).then((products) => {
|
||||
if (this.selector().hasClass("slick-initialized")) {
|
||||
this.selector().slick("unslick");
|
||||
}
|
||||
const response = await axios.get(activeTab.url);
|
||||
|
||||
this.products = products;
|
||||
this.loading = false;
|
||||
if (this.selector().hasClass("slick-initialized")) {
|
||||
this.selector().slick("unslick");
|
||||
}
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.selector().slick(this.slickOptions());
|
||||
});
|
||||
this.products = response.data;
|
||||
this.loading = false;
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.selector().slick(this.slickOptions());
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
@@ -9,7 +9,16 @@ export default {
|
||||
|
||||
computed: {
|
||||
productUrl() {
|
||||
return route("products.show", this.product.slug);
|
||||
return route("products.show", {
|
||||
slug: this.product.slug,
|
||||
...(this.hasAnyVariant && {
|
||||
variant: this.item.uid,
|
||||
}),
|
||||
});
|
||||
},
|
||||
|
||||
hasAnyVariant() {
|
||||
return this.product.variant !== null;
|
||||
},
|
||||
|
||||
hasAnyOption() {
|
||||
@@ -20,16 +29,18 @@ export default {
|
||||
return !this.hasAnyOption;
|
||||
},
|
||||
|
||||
hasAnyMedia() {
|
||||
return this.item.media.length !== 0;
|
||||
},
|
||||
|
||||
hasBaseImage() {
|
||||
return this.product.base_image.length !== 0;
|
||||
return this.item.base_image.length !== 0;
|
||||
},
|
||||
|
||||
baseImage() {
|
||||
if (this.hasBaseImage) {
|
||||
return this.product.base_image.path;
|
||||
}
|
||||
|
||||
return `${window.FleetCart.baseUrl}/themes/storefront/public/images/image-placeholder.png`;
|
||||
return this.hasBaseImage
|
||||
? this.item.base_image.path
|
||||
: `${window.FleetCart.baseUrl}/build/assets/image-placeholder.png`;
|
||||
},
|
||||
|
||||
inWishlist() {
|
||||
@@ -53,24 +64,27 @@ export default {
|
||||
addToCart() {
|
||||
this.addingToCart = true;
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: route("cart.items.store", {
|
||||
product_id: this.product.id,
|
||||
qty: 1,
|
||||
}),
|
||||
})
|
||||
.then((cart) => {
|
||||
store.updateCart(cart);
|
||||
axios
|
||||
.post(
|
||||
route("cart.items.store", {
|
||||
product_id: this.product.id,
|
||||
qty: 1,
|
||||
...(this.hasAnyVariant && {
|
||||
variant_id: this.item.id,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((response) => {
|
||||
store.updateCart(response.data);
|
||||
|
||||
if (document.location.href !== route("cart.index")) {
|
||||
$(".header-cart").trigger("click");
|
||||
}
|
||||
})
|
||||
.catch((xhr) => {
|
||||
this.$notify(xhr.responseJSON.message);
|
||||
.catch((error) => {
|
||||
this.$notify(error.response.data.message);
|
||||
})
|
||||
.always(() => {
|
||||
.finally(() => {
|
||||
this.addingToCart = false;
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
export default {
|
||||
methods: {
|
||||
productUrl(product) {
|
||||
return route('products.show', product.slug);
|
||||
return route("products.show", {
|
||||
slug: product.slug,
|
||||
...(this.hasAnyVariant(product) && {
|
||||
variant: product.variant.uid,
|
||||
}),
|
||||
});
|
||||
},
|
||||
|
||||
hasAnyVariant(product) {
|
||||
return product.variant !== null;
|
||||
},
|
||||
|
||||
hasBaseImage(product) {
|
||||
return product.base_image.length !== 0;
|
||||
return this.hasAnyVariant(product)
|
||||
? product.variant.base_image.length !== 0
|
||||
: product.base_image.length !== 0;
|
||||
},
|
||||
|
||||
baseImage(product) {
|
||||
if (this.hasBaseImage(product)) {
|
||||
return product.base_image.path;
|
||||
return this.hasAnyVariant(product)
|
||||
? product.variant.base_image.path
|
||||
: product.base_image.path;
|
||||
}
|
||||
|
||||
return `${window.FleetCart.baseUrl}/themes/storefront/public/images/image-placeholder.png`;
|
||||
return `${window.FleetCart.baseUrl}/build/assets/image-placeholder.png`;
|
||||
},
|
||||
|
||||
productPrice(product) {
|
||||
return this.hasAnyVariant(product)
|
||||
? product.variant.formatted_price
|
||||
: product.formatted_price;
|
||||
},
|
||||
|
||||
productIsInStock(product) {
|
||||
return this.hasAnyVariant(product)
|
||||
? product.variant.is_in_stock
|
||||
: product.is_in_stock;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user