Add پس کرایه (freight collect) on shipping cost groups.
When enabled, checkout shipping amount is 0 while customers still see the پس کرایه label. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
7f6fa3672d
commit
41d3f8f4eb
@@ -80,6 +80,10 @@ export class CreateShippingCostGroupDto {
|
||||
@Min(0)
|
||||
defaultAmount!: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
pasKraye?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
@@ -136,6 +140,10 @@ export class UpdateShippingCostGroupDto {
|
||||
@Min(0)
|
||||
defaultAmount?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
pasKraye?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
|
||||
@@ -120,6 +120,8 @@ export class ShippingCostGroupsService {
|
||||
dto.provinceExceptions ?? [],
|
||||
);
|
||||
const isDefault = dto.isDefault === true;
|
||||
const pasKraye = dto.pasKraye === true;
|
||||
const defaultAmount = pasKraye ? 0 : dto.defaultAmount;
|
||||
|
||||
const created = await this.prisma.$transaction(async (tx) => {
|
||||
if (isDefault) {
|
||||
@@ -136,7 +138,8 @@ export class ShippingCostGroupsService {
|
||||
nameEn: dto.nameEn.trim(),
|
||||
description: dto.description?.trim() || null,
|
||||
methods,
|
||||
defaultAmount: dto.defaultAmount,
|
||||
defaultAmount,
|
||||
pasKraye,
|
||||
sortOrder: dto.sortOrder ?? 0,
|
||||
isActive: dto.isActive ?? true,
|
||||
isDefault,
|
||||
@@ -191,7 +194,13 @@ export class ShippingCostGroupsService {
|
||||
if (dto.methods !== undefined) {
|
||||
data.methods = this.normalizeMethods(dto.methods);
|
||||
}
|
||||
if (dto.defaultAmount !== undefined) {
|
||||
if (dto.pasKraye !== undefined) {
|
||||
data.pasKraye = dto.pasKraye;
|
||||
if (dto.pasKraye) {
|
||||
data.defaultAmount = 0;
|
||||
}
|
||||
}
|
||||
if (dto.defaultAmount !== undefined && dto.pasKraye !== true) {
|
||||
data.defaultAmount = dto.defaultAmount;
|
||||
}
|
||||
if (dto.sortOrder !== undefined) data.sortOrder = dto.sortOrder;
|
||||
@@ -319,6 +328,7 @@ export class ShippingCostGroupsService {
|
||||
methodId: string | null;
|
||||
methodLabel: string | null;
|
||||
amount: number;
|
||||
pasKraye: boolean;
|
||||
itemNames: string[];
|
||||
}>;
|
||||
}> {
|
||||
@@ -340,6 +350,7 @@ export class ShippingCostGroupsService {
|
||||
methodId: null,
|
||||
methodLabel: null,
|
||||
amount: 0,
|
||||
pasKraye: false,
|
||||
itemNames: input.cartItems.map((item) => item.productName),
|
||||
},
|
||||
],
|
||||
@@ -357,6 +368,7 @@ export class ShippingCostGroupsService {
|
||||
methodId: null,
|
||||
methodLabel: null,
|
||||
amount: 0,
|
||||
pasKraye: false,
|
||||
itemNames: input.cartItems.map((item) => item.productName),
|
||||
},
|
||||
],
|
||||
@@ -381,6 +393,7 @@ export class ShippingCostGroupsService {
|
||||
methodId: null,
|
||||
methodLabel: null,
|
||||
amount,
|
||||
pasKraye: false,
|
||||
itemNames: input.cartItems.map((item) => item.productName),
|
||||
},
|
||||
],
|
||||
@@ -402,6 +415,7 @@ export class ShippingCostGroupsService {
|
||||
title: string;
|
||||
methods: ShippingMethodId[];
|
||||
amount: number;
|
||||
pasKraye: boolean;
|
||||
itemNames: string[];
|
||||
isDefault: boolean;
|
||||
}
|
||||
@@ -419,17 +433,21 @@ export class ShippingCostGroupsService {
|
||||
if (existing) {
|
||||
existing.itemNames.push(item.productName);
|
||||
} else {
|
||||
const pasKraye = group.pasKraye === true;
|
||||
buckets.set(group.id, {
|
||||
groupId: group.id,
|
||||
title: group.isDefault
|
||||
? STORE_SHIPPING_TITLE
|
||||
: group.nameFa || group.nameEn,
|
||||
methods: group.methods,
|
||||
amount: this.resolveProvinceAmount(
|
||||
group.defaultAmount,
|
||||
group.provinceExceptions,
|
||||
provinceId,
|
||||
),
|
||||
amount: pasKraye
|
||||
? 0
|
||||
: this.resolveProvinceAmount(
|
||||
group.defaultAmount,
|
||||
group.provinceExceptions,
|
||||
provinceId,
|
||||
),
|
||||
pasKraye,
|
||||
itemNames: [item.productName],
|
||||
isDefault: group.isDefault,
|
||||
});
|
||||
@@ -442,6 +460,7 @@ export class ShippingCostGroupsService {
|
||||
title: STORE_SHIPPING_TITLE,
|
||||
methods: [],
|
||||
amount: 0,
|
||||
pasKraye: false,
|
||||
itemNames: ungroupedNames,
|
||||
isDefault: true,
|
||||
});
|
||||
@@ -459,6 +478,7 @@ export class ShippingCostGroupsService {
|
||||
methodId,
|
||||
methodLabel: methodId ? METHOD_LABELS_FA[methodId] : null,
|
||||
amount: bucket.amount,
|
||||
pasKraye: bucket.pasKraye,
|
||||
itemNames: bucket.itemNames,
|
||||
};
|
||||
});
|
||||
@@ -506,6 +526,7 @@ export class ShippingCostGroupsService {
|
||||
nameEn: string;
|
||||
methods: ShippingMethodId[];
|
||||
defaultAmount: number;
|
||||
pasKraye: boolean;
|
||||
provinceExceptions?: Array<{ provinceId: string; amount: number }>;
|
||||
}>,
|
||||
categoryIds: string[],
|
||||
@@ -545,6 +566,7 @@ export class ShippingCostGroupsService {
|
||||
sortOrder: group.sortOrder,
|
||||
isActive: group.isActive,
|
||||
isDefault: group.isDefault,
|
||||
pasKraye: group.pasKraye,
|
||||
categoryIds: group.categories.map((row) => row.categoryId.toString()),
|
||||
categories: group.categories.map((row) => ({
|
||||
id: row.category.id.toString(),
|
||||
|
||||
Reference in New Issue
Block a user