|
@@ -16,7 +16,6 @@ import {
|
|
|
getFirstAvailable,
|
|
getFirstAvailable,
|
|
|
getAvailableVariants,
|
|
getAvailableVariants,
|
|
|
isCombinationAvailable,
|
|
isCombinationAvailable,
|
|
|
- formatFlexibleVariants,
|
|
|
|
|
findNearestAvailableVariant
|
|
findNearestAvailableVariant
|
|
|
} from "@/utils/variantTools";
|
|
} from "@/utils/variantTools";
|
|
|
import { Price } from "@components/theme/ui/Price";
|
|
import { Price } from "@components/theme/ui/Price";
|
|
@@ -95,7 +94,7 @@ export function ProductInformation({
|
|
|
const handleOptionClick = (optionId: number, valueId: number) => {
|
|
const handleOptionClick = (optionId: number, valueId: number) => {
|
|
|
// 更新前需要判断当前选中的组合是否可以购买,如果可以购买正常更新;如果不能购买查找可以购买的组合然后更新
|
|
// 更新前需要判断当前选中的组合是否可以购买,如果可以购买正常更新;如果不能购买查找可以购买的组合然后更新
|
|
|
let newSelected: Record<number, number> = {...selected,[optionId]: valueId};
|
|
let newSelected: Record<number, number> = {...selected,[optionId]: valueId};
|
|
|
- let selectedValueIds = Object.values(newSelected);
|
|
|
|
|
|
|
+ const selectedValueIds = Object.values(newSelected);
|
|
|
if(!isCombinationAvailable(selectedValueIds, availableVariants)) {
|
|
if(!isCombinationAvailable(selectedValueIds, availableVariants)) {
|
|
|
newSelected = findNearestAvailableVariant(optionId,valueId,{...newSelected},productOptions,availableVariants);
|
|
newSelected = findNearestAvailableVariant(optionId,valueId,{...newSelected},productOptions,availableVariants);
|
|
|
}
|
|
}
|
|
@@ -127,7 +126,7 @@ export function ProductInformation({
|
|
|
let totalLinePrice = 0;
|
|
let totalLinePrice = 0;
|
|
|
let totalNowPrice = 0;
|
|
let totalNowPrice = 0;
|
|
|
let save = 0;
|
|
let save = 0;
|
|
|
- let variant = flexibleVariants.find((v) => {
|
|
|
|
|
|
|
+ const variant = flexibleVariants.find((v) => {
|
|
|
const vIds = v.optionValues.map((ov) => ov.id);
|
|
const vIds = v.optionValues.map((ov) => ov.id);
|
|
|
return selectedIds.length === vIds.length && selectedIds.every((id) => vIds.includes(id));
|
|
return selectedIds.length === vIds.length && selectedIds.every((id) => vIds.includes(id));
|
|
|
});
|
|
});
|
|
@@ -153,10 +152,10 @@ export function ProductInformation({
|
|
|
}, [selected, flexibleVariants, productQty]);
|
|
}, [selected, flexibleVariants, productQty]);
|
|
|
|
|
|
|
|
|
|
|
|
|
- let classNameOptionValueBtn = "text-ly-14 leading-ly-24 border border-solid rounded-lg pt-1.5 pb-1.5 pl-3 pr-3 bg-white";
|
|
|
|
|
|
|
+ const classNameOptionValueBtn = "text-ly-14 leading-ly-24 border border-solid rounded-lg pt-1.5 pb-1.5 pl-3 pr-3 bg-white";
|
|
|
|
|
|
|
|
|
|
|
|
|
- let handlerProductQty = (action: string) => {
|
|
|
|
|
|
|
+ const handlerProductQty = (action: string) => {
|
|
|
if (action === "increase") {
|
|
if (action === "increase") {
|
|
|
setProductQty(productQty + 1);
|
|
setProductQty(productQty + 1);
|
|
|
} else if (action === "decrease" && productQty > 1) {
|
|
} else if (action === "decrease" && productQty > 1) {
|
|
@@ -166,12 +165,12 @@ export function ProductInformation({
|
|
|
|
|
|
|
|
async function addProductToCart(action:string = 'addtocart') {
|
|
async function addProductToCart(action:string = 'addtocart') {
|
|
|
|
|
|
|
|
- let params = {
|
|
|
|
|
|
|
+ const params = {
|
|
|
productId: String(productId),
|
|
productId: String(productId),
|
|
|
quantity: productQty,
|
|
quantity: productQty,
|
|
|
variantId: currentVariantInfo.variant?._id,
|
|
variantId: currentVariantInfo.variant?._id,
|
|
|
};
|
|
};
|
|
|
- let res = await onAddToCart(params);
|
|
|
|
|
|
|
+ const res = await onAddToCart(params);
|
|
|
console.log('onAddToCart result --- ', res);
|
|
console.log('onAddToCart result --- ', res);
|
|
|
if(action === 'buynow') {
|
|
if(action === 'buynow') {
|
|
|
if(res) {
|
|
if(res) {
|
|
@@ -183,7 +182,7 @@ export function ProductInformation({
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let addToCartHandler = async () => {
|
|
|
|
|
|
|
+ const addToCartHandler = async () => {
|
|
|
|
|
|
|
|
if(!isCurrentSelectionAvailable) {
|
|
if(!isCurrentSelectionAvailable) {
|
|
|
showToast("The selected options are not available!", "warning");
|
|
showToast("The selected options are not available!", "warning");
|
|
@@ -195,7 +194,7 @@ export function ProductInformation({
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- let buyNowHandler = () => {
|
|
|
|
|
|
|
+ const buyNowHandler = () => {
|
|
|
if(!isCurrentSelectionAvailable) {
|
|
if(!isCurrentSelectionAvailable) {
|
|
|
showToast("The selected options are not available!", "warning");
|
|
showToast("The selected options are not available!", "warning");
|
|
|
return;
|
|
return;
|