diff --git a/src/app/cart/components/ShippingMethodSelector.tsx b/src/app/cart/components/ShippingMethodSelector.tsx
index 4796e7d..1b74380 100644
--- a/src/app/cart/components/ShippingMethodSelector.tsx
+++ b/src/app/cart/components/ShippingMethodSelector.tsx
@@ -273,6 +273,11 @@ const ShippingMethodSelector = ({
ارزانترین
)}
+ {shipper.payDeliveryFeeOnDelivery && (
+
+ پرداخت در محل
+
+ )}
زمان ارسال: {shipper.shippingDaysRange?.join(' تا ') || 'نامشخص'}
@@ -282,14 +287,24 @@ const ShippingMethodSelector = ({
- {shipper.totalShippingCost.toLocaleString('fa-IR')} تومان
- {priceDifference > 0 && (
-
- +{priceDifference.toLocaleString('fa-IR')} تومان
-
+ {shipper.payDeliveryFeeOnDelivery ? (
+
+ {shipper.totalShippingCost.toLocaleString('fa-IR')} تومان در محل
+
+ ) : (
+ <>
+ {shipper.totalShippingCost.toLocaleString('fa-IR')} تومان
+ {priceDifference > 0 && (
+
+ +{priceDifference.toLocaleString('fa-IR')} تومان
+
+ )}
+ >
)}
- هزینه ارسال کل این فروشگاه
+ {shipper.payDeliveryFeeOnDelivery
+ ? 'هزینه ارسال هنگام تحویل پرداخت میشود'
+ : 'هزینه ارسال کل این فروشگاه'}
diff --git a/src/app/cart/payment/page.tsx b/src/app/cart/payment/page.tsx
index 74adcb2..87ec625 100644
--- a/src/app/cart/payment/page.tsx
+++ b/src/app/cart/payment/page.tsx
@@ -6,6 +6,7 @@ import TitleBack from '../components/TitleBack'
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
import DiscountCard from '../components/DiscountCard'
import { usePaymentMethods, useGetCart, useShippingCost, useCheckoutCart } from '../hooks/useCartData'
+import { ShopShippingType } from '../types/Types'
import { useState } from 'react'
import { toast } from '@/components/Toast'
import { useGetProfile } from '@/app/profile/hooks/useProfileData'
@@ -50,12 +51,24 @@ const CartPayment: NextPage = () => {
const savedShipments = typeof window !== 'undefined' ? localStorage.getItem('selectedShipments') : null
const selectedShipments = savedShipments ? JSON.parse(savedShipments) : {}
- // محاسبه هزینه ارسال بر اساس انتخابهای کاربر
- const totalShippingCost = shippingData?.results?.shipping?.reduce((total, shop) => {
+ const getSelectedShipper = (shop: ShopShippingType) => {
const selectedShipperId = selectedShipments[shop.shopId]
- const selectedShipper = shop.shippers?.find(shipper => shipper.shipperId === selectedShipperId)
- return total + (selectedShipper?.totalShippingCost || shop.shippers?.[0]?.totalShippingCost || 0)
- }, 0) || 0
+ return shop.shippers?.find(shipper => shipper.shipperId === selectedShipperId) || shop.shippers?.[0]
+ }
+
+ const shippingTotals = shippingData?.results?.shipping?.reduce((totals, shop) => {
+ const shipper = getSelectedShipper(shop)
+ if (!shipper) return totals
+ if (shipper.payDeliveryFeeOnDelivery) {
+ totals.onDelivery += shipper.totalShippingCost
+ } else {
+ totals.online += shipper.totalShippingCost
+ }
+ return totals
+ }, { online: 0, onDelivery: 0 }) || { online: 0, onDelivery: 0 }
+
+ const totalShippingCost = shippingTotals.online
+ const shippingCostOnDelivery = shippingTotals.onDelivery
// محاسبه قیمت نهایی
const finalTotal = (cart?.payable_price || 0) + totalShippingCost
@@ -132,6 +145,7 @@ const CartPayment: NextPage = () => {
itemsPrice={cart?.retail_price || 0}
discount={cart.total_discount}
shippingCost={totalShippingCost}
+ shippingCostOnDelivery={shippingCostOnDelivery}
total={finalTotal}
onConfirm={handlePayment}
confirmLabel="پرداخت"
diff --git a/src/app/cart/shipping/page.tsx b/src/app/cart/shipping/page.tsx
index 03a2541..9f532ec 100644
--- a/src/app/cart/shipping/page.tsx
+++ b/src/app/cart/shipping/page.tsx
@@ -7,6 +7,7 @@ import TitleBack from '../components/TitleBack'
import ShippingMethodSelector from '../components/ShippingMethodSelector'
import { Location } from 'iconsax-react'
import { useGetCart, useSaveShipmentCart, useShippingCost } from '../hooks/useCartData'
+import { ShopShippingType } from '../types/Types'
// import { CartItemType } from '../types/Types'
import { useGetProfile } from '@/app/profile/hooks/useProfileData'
import Link from 'next/link'
@@ -143,11 +144,24 @@ const CartShipping: NextPage = () => {
}
// محاسبه هزینه ارسال بر اساس انتخابهای کاربر
- const totalShippingCost = shippingData?.results?.shipping?.reduce((total, shop) => {
+ const getSelectedShipper = (shop: ShopShippingType) => {
const selectedShipperId = selectedShipments[shop.shopId]
- const selectedShipper = shop.shippers?.find(shipper => shipper.shipperId === selectedShipperId)
- return total + (selectedShipper?.totalShippingCost || shop.shippers?.[0]?.totalShippingCost || 0)
- }, 0) || 0
+ return shop.shippers?.find(shipper => shipper.shipperId === selectedShipperId) || shop.shippers?.[0]
+ }
+
+ const shippingTotals = shippingData?.results?.shipping?.reduce((totals, shop) => {
+ const shipper = getSelectedShipper(shop)
+ if (!shipper) return totals
+ if (shipper.payDeliveryFeeOnDelivery) {
+ totals.onDelivery += shipper.totalShippingCost
+ } else {
+ totals.online += shipper.totalShippingCost
+ }
+ return totals
+ }, { online: 0, onDelivery: 0 }) || { online: 0, onDelivery: 0 }
+
+ const totalShippingCost = shippingTotals.online
+ const shippingCostOnDelivery = shippingTotals.onDelivery
// محاسبه قیمت نهایی
const finalTotal = (cart?.payable_price || 0) + totalShippingCost
@@ -205,6 +219,7 @@ const CartShipping: NextPage = () => {
itemsPrice={cart?.retail_price || 0}
discount={cart?.total_discount || 0}
shippingCost={totalShippingCost}
+ shippingCostOnDelivery={shippingCostOnDelivery}
total={finalTotal}
onConfirm={handleProceedToPayment}
confirmLabel="پرداخت"
diff --git a/src/app/cart/types/Types.ts b/src/app/cart/types/Types.ts
index fccff57..1f04fc4 100644
--- a/src/app/cart/types/Types.ts
+++ b/src/app/cart/types/Types.ts
@@ -60,6 +60,7 @@ export type CartItemType = {
description: string;
deliveryTime: number;
deliveryType: string;
+ payDeliveryFeeOnDelivery?: boolean;
}>;
warranty: {
_id: number;
@@ -224,6 +225,7 @@ export type ShipperType = {
shipperName: string;
shippingDaysRange: string[];
totalShippingCost: number;
+ payDeliveryFeeOnDelivery: boolean;
items: ShippingItemType[];
};
diff --git a/src/app/profile/orders/[id]/invoice/page.tsx b/src/app/profile/orders/[id]/invoice/page.tsx
index e36b003..e206b70 100644
--- a/src/app/profile/orders/[id]/invoice/page.tsx
+++ b/src/app/profile/orders/[id]/invoice/page.tsx
@@ -42,6 +42,7 @@ const OrderInvoicePage = () => {
const totalDiscount = order.payment.priceDetails.total_discount
const couponDiscount = order.payment.priceDetails.coupon_discount
const shippingCost = order.payment.priceDetails.shipping_cost
+ const shippingCostOnDelivery = order.payment.priceDetails.shipping_cost_on_delivery || 0
const totalPrice = order.payment.totalPrice
return (
@@ -212,6 +213,12 @@ const OrderInvoicePage = () => {
هزینه ارسال:
{NumberFormat(shippingCost)} تومان
+ {shippingCostOnDelivery > 0 && (
+ {
width: `${dropdownPosition.width}px`
}}
>
- {isLoading ? (
+ {isSearching ? (
در حال جستجو...
diff --git a/src/share/components/MobileSearch.tsx b/src/share/components/MobileSearch.tsx
index 1f77399..6ea7cd8 100644
--- a/src/share/components/MobileSearch.tsx
+++ b/src/share/components/MobileSearch.tsx
@@ -8,17 +8,16 @@ import Image from 'next/image'
const MobileSearch: FC = () => {
const [isSearchOpen, setIsSearchOpen] = useState(false)
+ const [inputValue, setInputValue] = useState('')
const [searchQuery, setSearchQuery] = useState('')
const router = useRouter()
const { data: searchResults, isLoading } = useProductSearch(searchQuery)
-
- const handleSearch = (value: string) => {
- setSearchQuery(value)
- }
+ const isSearching = inputValue.length > 0 && (isLoading || inputValue !== searchQuery)
const handleClose = () => {
setIsSearchOpen(false)
+ setInputValue('')
setSearchQuery('')
}
@@ -36,8 +35,9 @@ const MobileSearch: FC = () => {
variant='search'
placeholder='جستجو'
autoFocus
- value={searchQuery}
- onChange={(e) => handleSearch(e.target.value)}
+ value={inputValue}
+ onChange={(e) => setInputValue(e.target.value)}
+ onChangeSearchFinal={setSearchQuery}
/>