|
|
@@ -6,13 +6,14 @@ import { ProductOption, ResolvedVariant } from "@/components/catalog/type";
|
|
|
import { ProductAddToCart } from "@/app/(public)/product/_components/ProductAddToCart";
|
|
|
import { useCustomToast } from "@utils/hooks/useToast";
|
|
|
import { useAddProduct } from "@utils/hooks/useAddToCart";
|
|
|
-import { redirect, RedirectType } from "next/navigation";
|
|
|
+import { useRouter } from "next/navigation";
|
|
|
import InstallmentPopup from "./popup/InstallmentPopup";
|
|
|
import Guide from "./popup/Guide";
|
|
|
import ProductText from "./ProductText";
|
|
|
import NewUserBanner from "./NewUserBanner";
|
|
|
import PromotionDiscountCardProps from "./PromotionDiscountCardProps ";
|
|
|
import Image from "next/image";
|
|
|
+import {useConfig} from "@/utils/hooks/useConfig";
|
|
|
import {
|
|
|
isValueAvailable,
|
|
|
isOptionValueAvailable,
|
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
findNearestAvailableVariant,
|
|
|
} from "@/utils/variantTools";
|
|
|
import { Price } from "@components/theme/ui/Price";
|
|
|
+import { overlayLoading } from "@/components/theme/ui/kernel/loading/api";
|
|
|
|
|
|
export function ProductInformation({
|
|
|
name,
|
|
|
@@ -29,15 +31,18 @@ export function ProductInformation({
|
|
|
productOptions,
|
|
|
flexibleVariants,
|
|
|
isSaleable,
|
|
|
+ shortDescription,
|
|
|
}: {
|
|
|
name: string;
|
|
|
productId: number;
|
|
|
productOptions: ProductOption[];
|
|
|
flexibleVariants: ResolvedVariant[];
|
|
|
isSaleable: string | undefined;
|
|
|
+ shortDescription:string;
|
|
|
}) {
|
|
|
- const { isCartLoading, onAddToCart } = useAddProduct();
|
|
|
+ const { appendProductToCart } = useAddProduct();
|
|
|
const { showToast } = useCustomToast();
|
|
|
+ const router = useRouter();
|
|
|
|
|
|
// 记录当前哪个选项组刚刚被点击(用于实现“点击组内全部可点”)
|
|
|
const [lastClickedOptionId, setLastClickedOptionId] = useState<number>(
|
|
|
@@ -196,45 +201,53 @@ export function ProductInformation({
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- async function addProductToCart(action: string = "addtocart") {
|
|
|
- const params = {
|
|
|
- productId: String(productId),
|
|
|
- quantity: productQty,
|
|
|
- variantId: currentVariantInfo.variant?._id,
|
|
|
- };
|
|
|
- const res = await onAddToCart(params);
|
|
|
- console.log("onAddToCart result --- ", res);
|
|
|
- if (action === "buynow") {
|
|
|
- if (res) {
|
|
|
- const responseData = res.data?.createAddProductInCart?.addProductInCart;
|
|
|
- if (responseData && responseData.success) {
|
|
|
- redirect("/checkout?step=address", RedirectType.push);
|
|
|
+ async function addProductToCart(action:string = 'addtocart') {
|
|
|
+ overlayLoading.start();
|
|
|
+ const res = await appendProductToCart({
|
|
|
+ productId: productId,
|
|
|
+ quantity: productQty,
|
|
|
+ variantId: currentVariantInfo.variant?._id,
|
|
|
+ });
|
|
|
+ console.log('onAddToCart result --- ', res);
|
|
|
+ overlayLoading.stop();
|
|
|
+ if(action === 'buynow') {
|
|
|
+ if(res.data) {
|
|
|
+ const responseData = res.data;
|
|
|
+ if(responseData.success) {
|
|
|
+ router.push('/checkout?step=address');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
const addToCartHandler = async () => {
|
|
|
- if (!isCurrentSelectionAvailable) {
|
|
|
- showToast("The selected options are not available!", "warning");
|
|
|
- return;
|
|
|
- }
|
|
|
+
|
|
|
+ if(!isCurrentSelectionAvailable) {
|
|
|
+ showToast("The selected options are not available!", "warning");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (currentVariantInfo.variant && !isCartLoading) {
|
|
|
- addProductToCart();
|
|
|
- }
|
|
|
+ if(currentVariantInfo.variant) {
|
|
|
+ addProductToCart();
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
+
|
|
|
const buyNowHandler = () => {
|
|
|
if (!isCurrentSelectionAvailable) {
|
|
|
showToast("The selected options are not available!", "warning");
|
|
|
return;
|
|
|
}
|
|
|
- if (currentVariantInfo.variant && !isCartLoading) {
|
|
|
+ if (currentVariantInfo.variant) {
|
|
|
addProductToCart("buynow");
|
|
|
}
|
|
|
};
|
|
|
- const currencySymbol = "$";
|
|
|
+ const {getCurrentCurrencyItem} = useConfig();
|
|
|
+ const currentCurrency = getCurrentCurrencyItem();
|
|
|
+ const currencySymbol = currentCurrency.symbol;
|
|
|
+ const currencyCode = currentCurrency.code;
|
|
|
+
|
|
|
+ // const currencySymbol = "$";
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
@@ -242,12 +255,12 @@ export function ProductInformation({
|
|
|
<h3 className="text-ly-14 text-black mt-4 leading-ly-22">
|
|
|
{name} {isSaleable}
|
|
|
</h3>
|
|
|
- <ProductText ProductText="" />
|
|
|
+ <ProductText ProductText={shortDescription} />
|
|
|
<div className="flex items-center mt-2">
|
|
|
<Price
|
|
|
className="text-ly-16 leading-ly-24 font-bold"
|
|
|
amount={String(currentVariantInfo.totalNowPrice)}
|
|
|
- currencyCode="USD"
|
|
|
+ currencyCode={currencyCode}
|
|
|
/>
|
|
|
{currentVariantInfo.totalLinePrice !==
|
|
|
currentVariantInfo.totalNowPrice && (
|
|
|
@@ -255,17 +268,17 @@ export function ProductInformation({
|
|
|
<Price
|
|
|
className="text-ly-12 leading-ly-20 text-ly-gray line-through ml-1"
|
|
|
amount={String(currentVariantInfo.totalLinePrice)}
|
|
|
- currencyCode="USD"
|
|
|
+ currencyCode={currencyCode}
|
|
|
/>
|
|
|
<Price
|
|
|
className="text-ly-12 leading-ly-20 text-ly-gray line-through ml-1"
|
|
|
amount={String(currentVariantInfo.totalLinePrice)}
|
|
|
- currencyCode="USD"
|
|
|
+ currencyCode={currencyCode}
|
|
|
/>
|
|
|
<Price
|
|
|
className="text-ly-12 leading-ly-16 bg-ly-gold pr-1.5 pl-1.5 ml-3"
|
|
|
amount={String(currentVariantInfo.save)}
|
|
|
- currencyCode="USD"
|
|
|
+ currencyCode={currencyCode}
|
|
|
/>
|
|
|
</>
|
|
|
)}
|
|
|
@@ -420,9 +433,9 @@ export function ProductInformation({
|
|
|
</div>
|
|
|
<ProductAddToCart
|
|
|
isAvailable={isCurrentSelectionAvailable}
|
|
|
- isLoading={isCartLoading}
|
|
|
onAddToCart={addToCartHandler}
|
|
|
onBuyNow={buyNowHandler}
|
|
|
+ currencyCode={currencyCode}
|
|
|
priceInfo={{
|
|
|
totalNowPrice: currentVariantInfo.totalNowPrice,
|
|
|
totalLinePrice: currentVariantInfo.totalLinePrice,
|