add extra price
This commit is contained in:
@@ -626,7 +626,15 @@ export const selectCartItems = (state: RootState) => state.order.items;
|
|||||||
|
|
||||||
export const selectCartTotal = (state: RootState) =>
|
export const selectCartTotal = (state: RootState) =>
|
||||||
state.order.items.reduce(
|
state.order.items.reduce(
|
||||||
(total, item) => total + item.price * item.quantity,
|
// (total, item) => total + item.price * item.quantity,
|
||||||
|
(total, item) => {
|
||||||
|
const extrasPrice = (item.extras || []).reduce(
|
||||||
|
(extraTotal, extraItem) => extraTotal + extraItem.price,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
const itemTotalPrice = (item.price + extrasPrice) * item.quantity;
|
||||||
|
return total + itemTotalPrice;
|
||||||
|
},
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ export default function Extra({
|
|||||||
setSelectedExtras,
|
setSelectedExtras,
|
||||||
}: {
|
}: {
|
||||||
extrasList: ExtraType[];
|
extrasList: ExtraType[];
|
||||||
selectedExtras: string[];
|
selectedExtras: ExtraType[];
|
||||||
setSelectedExtras: Dispatch<SetStateAction<string[]>>;
|
setSelectedExtras: Dispatch<SetStateAction<ExtraType[]>>;
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -51,8 +51,12 @@ export default function Extra({
|
|||||||
price: `+${value.price}`,
|
price: `+${value.price}`,
|
||||||
};
|
};
|
||||||
})}
|
})}
|
||||||
value={selectedExtras}
|
value={selectedExtras.map((ex) => ex.id.toString())}
|
||||||
onChange={(values: string[]) => setSelectedExtras(values)}
|
onChange={(values) =>
|
||||||
|
setSelectedExtras(
|
||||||
|
extrasList.filter((o) => values?.includes(o.id.toString())),
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { useMemo, useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useAppDispatch, useAppSelector } from "redux/hooks";
|
import { useAppDispatch, useAppSelector } from "redux/hooks";
|
||||||
import { colors, ProBlack2 } from "ThemeConstants";
|
import { colors, ProBlack2 } from "ThemeConstants";
|
||||||
import { Product, Variant } from "utils/types/appTypes";
|
import { Product, Variant, Extra as ExtraType } from "utils/types/appTypes";
|
||||||
import styles from "../product.module.css";
|
import styles from "../product.module.css";
|
||||||
|
|
||||||
export default function ProductFooter({
|
export default function ProductFooter({
|
||||||
@@ -22,7 +22,7 @@ export default function ProductFooter({
|
|||||||
product: Product;
|
product: Product;
|
||||||
isValid?: boolean;
|
isValid?: boolean;
|
||||||
selectedVariant?: Variant;
|
selectedVariant?: Variant;
|
||||||
selectedExtras: string[];
|
selectedExtras: ExtraType[];
|
||||||
selectedGroups: string[];
|
selectedGroups: string[];
|
||||||
quantity: number;
|
quantity: number;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import ArabicPrice from "components/ArabicPrice";
|
|||||||
import useBreakPoint from "hooks/useBreakPoint";
|
import useBreakPoint from "hooks/useBreakPoint";
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import { colors } from "ThemeConstants";
|
import { colors } from "ThemeConstants";
|
||||||
import { Product } from "utils/types/appTypes";
|
import { Product, Extra as ExtraType } from "utils/types/appTypes";
|
||||||
import BackButton from "../menu/components/BackButton";
|
import BackButton from "../menu/components/BackButton";
|
||||||
import Extra from "./components/Extra";
|
import Extra from "./components/Extra";
|
||||||
import ExtraGroups from "./components/ExtraGroups";
|
import ExtraGroups from "./components/ExtraGroups";
|
||||||
@@ -37,7 +37,7 @@ export default function ProductDetailPage({
|
|||||||
>({});
|
>({});
|
||||||
|
|
||||||
// State for selected extras
|
// State for selected extras
|
||||||
const [selectedExtras, setSelectedExtras] = useState<string[]>([]);
|
const [selectedExtras, setSelectedExtras] = useState<ExtraType[]>([]);
|
||||||
|
|
||||||
// State for selected extras by group
|
// State for selected extras by group
|
||||||
const [selectedExtrasByGroup, setSelectedExtrasByGroup] = useState<
|
const [selectedExtrasByGroup, setSelectedExtrasByGroup] = useState<
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ export interface CartItem {
|
|||||||
quantity: number;
|
quantity: number;
|
||||||
description: string;
|
description: string;
|
||||||
variant?: string;
|
variant?: string;
|
||||||
extras?: string[];
|
extras?: Extra[];
|
||||||
extrasgroup?: string[];
|
extrasgroup?: string[];
|
||||||
isHasLoyalty?: boolean;
|
isHasLoyalty?: boolean;
|
||||||
no_of_stamps_give?: number;
|
no_of_stamps_give?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user