asv-hlps-market 1.0.41 → 1.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/shopping/hlpShopping.d.ts +1 -2
- package/lib/cjs/shopping/hlpShopping.js +0 -6
- package/lib/cjs/shopping/shoppingStore.d.ts +34 -0
- package/lib/cjs/shopping/shoppingStore.js +112 -0
- package/lib/cjs/shops/hlpShop.d.ts +2 -10
- package/lib/cjs/shops/hlpShop.js +2 -70
- package/lib/cjs/shops/models/Shop.d.ts +1 -0
- package/lib/esm/shopping/hlpShopping.d.ts +1 -2
- package/lib/esm/shopping/hlpShopping.js +0 -6
- package/lib/esm/shopping/shoppingStore.d.ts +34 -0
- package/lib/esm/shopping/shoppingStore.js +96 -0
- package/lib/esm/shops/hlpShop.d.ts +2 -10
- package/lib/esm/shops/hlpShop.js +2 -67
- package/lib/esm/shops/models/Shop.d.ts +1 -0
- package/package.json +3 -3
|
@@ -4,10 +4,9 @@ import CartItem from "./models/CartItem";
|
|
|
4
4
|
declare class HlpShopping {
|
|
5
5
|
addToCart: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
6
6
|
updateCartQtity: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
7
|
-
calculateStockOrQtityLimitCounts
|
|
7
|
+
private calculateStockOrQtityLimitCounts;
|
|
8
8
|
getTotalAmount: (cartItems: CartItem[], client: User) => number;
|
|
9
9
|
getPrice: (item: CartItem) => number;
|
|
10
|
-
getAddShopLabel: (marketCode: string, status?: "edit") => "Ajouter une agence" | "modifier l'agence" | "Ajouter un shop" | "Modifier le shop";
|
|
11
10
|
}
|
|
12
11
|
declare const _default: HlpShopping;
|
|
13
12
|
export default _default;
|
|
@@ -56,12 +56,6 @@ class HlpShopping {
|
|
|
56
56
|
}
|
|
57
57
|
return item.product.price;
|
|
58
58
|
};
|
|
59
|
-
this.getAddShopLabel = (marketCode, status) => {
|
|
60
|
-
if (["immo", "veh"].includes(marketCode)) {
|
|
61
|
-
return status !== "edit" ? "Ajouter une agence" : "modifier l'agence";
|
|
62
|
-
}
|
|
63
|
-
return status !== "edit" ? "Ajouter un shop" : "Modifier le shop";
|
|
64
|
-
};
|
|
65
59
|
}
|
|
66
60
|
calculateStockOrQtityLimitCounts(item, qtity) {
|
|
67
61
|
// const qty = +item.qtityOdr + qtity;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Product from "../products/models/Product";
|
|
2
|
+
import CartItem from "./models/CartItem";
|
|
3
|
+
export interface ShoppingStore {
|
|
4
|
+
cartItems: CartItem[];
|
|
5
|
+
isProductInCart: boolean;
|
|
6
|
+
actions: {
|
|
7
|
+
addProductToCart: (val: Product) => void;
|
|
8
|
+
removeProductFromCart: (productId: number) => void;
|
|
9
|
+
increaseCartItemQtity: (productId: number) => void;
|
|
10
|
+
checkProductInCart: (productId: number) => void;
|
|
11
|
+
decreaseCartItemQtity: (productId: number) => void;
|
|
12
|
+
resetAllProductsInCart: () => void;
|
|
13
|
+
updateSpePrice: (productId: number, price: number) => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare const updateProductQtity: (cartItems: CartItem[], productId: number, updateType: "increase" | "decrease") => CartItem[];
|
|
17
|
+
export declare const updateProductSpePrice: (cartItems: CartItem[], productId: number, spePrice: number) => CartItem[];
|
|
18
|
+
export declare const increaseCartItemQtity: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
19
|
+
export declare const removeProductFromCart: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
20
|
+
export declare const decreaseCartItemQtity: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
21
|
+
export declare const shoppingStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ShoppingStore>>;
|
|
22
|
+
export declare const useShoppingActions: () => {
|
|
23
|
+
addProductToCart: (val: Product) => void;
|
|
24
|
+
removeProductFromCart: (productId: number) => void;
|
|
25
|
+
increaseCartItemQtity: (productId: number) => void;
|
|
26
|
+
checkProductInCart: (productId: number) => void;
|
|
27
|
+
decreaseCartItemQtity: (productId: number) => void;
|
|
28
|
+
resetAllProductsInCart: () => void;
|
|
29
|
+
updateSpePrice: (productId: number, price: number) => void;
|
|
30
|
+
};
|
|
31
|
+
export declare const useCartItems: () => CartItem[];
|
|
32
|
+
export declare const useCartItemsCount: () => number;
|
|
33
|
+
export declare const useCartItemQtityById: (productId: number | undefined) => number;
|
|
34
|
+
export declare const isInCart: (productId: number) => CartItem;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.isInCart = exports.useCartItemQtityById = exports.useCartItemsCount = exports.useCartItems = exports.useShoppingActions = exports.shoppingStore = exports.decreaseCartItemQtity = exports.removeProductFromCart = exports.increaseCartItemQtity = exports.updateProductSpePrice = exports.updateProductQtity = void 0;
|
|
16
|
+
const zustand_1 = require("zustand");
|
|
17
|
+
const shallow_1 = require("zustand/react/shallow");
|
|
18
|
+
const hlpShopping_1 = __importDefault(require("./hlpShopping"));
|
|
19
|
+
const updateProductQtity = (cartItems, productId, updateType) => {
|
|
20
|
+
return cartItems === null || cartItems === void 0 ? void 0 : cartItems.map((item) => {
|
|
21
|
+
if (item.product.id === productId) {
|
|
22
|
+
return Object.assign(Object.assign({}, item), { qtityOdr: updateType === "increase" ? item.qtityOdr + 1 : item.qtityOdr - 1 });
|
|
23
|
+
}
|
|
24
|
+
return item;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.updateProductQtity = updateProductQtity;
|
|
28
|
+
const updateProductSpePrice = (cartItems, productId, spePrice) => {
|
|
29
|
+
return cartItems === null || cartItems === void 0 ? void 0 : cartItems.map((item) => {
|
|
30
|
+
if (item.product.id === productId) {
|
|
31
|
+
return Object.assign(Object.assign({}, item), { specialPrice: spePrice });
|
|
32
|
+
}
|
|
33
|
+
return item;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
exports.updateProductSpePrice = updateProductSpePrice;
|
|
37
|
+
const checkProductInCart = (cartItems, productId) => {
|
|
38
|
+
return cartItems.find((x) => x.product.id === productId) ? true : false;
|
|
39
|
+
};
|
|
40
|
+
const increaseCartItemQtity = (cartItems, productId) => {
|
|
41
|
+
return (0, exports.updateProductQtity)(cartItems, productId, "increase");
|
|
42
|
+
};
|
|
43
|
+
exports.increaseCartItemQtity = increaseCartItemQtity;
|
|
44
|
+
const removeProductFromCart = (cartItems, productId) => {
|
|
45
|
+
return cartItems.filter((item) => item.product.id !== productId);
|
|
46
|
+
};
|
|
47
|
+
exports.removeProductFromCart = removeProductFromCart;
|
|
48
|
+
const decreaseCartItemQtity = (cartItems, productId) => {
|
|
49
|
+
var _a;
|
|
50
|
+
const ifQtity = ((_a = cartItems.find((x) => x.product.id === productId)) === null || _a === void 0 ? void 0 : _a.qtityOdr) === 1;
|
|
51
|
+
if (ifQtity) {
|
|
52
|
+
return (0, exports.removeProductFromCart)(cartItems, productId);
|
|
53
|
+
}
|
|
54
|
+
return (0, exports.updateProductQtity)(cartItems, productId, "decrease");
|
|
55
|
+
};
|
|
56
|
+
exports.decreaseCartItemQtity = decreaseCartItemQtity;
|
|
57
|
+
exports.shoppingStore = (0, zustand_1.create)((set, get) => ({
|
|
58
|
+
cartItems: [],
|
|
59
|
+
isProductInCart: false,
|
|
60
|
+
actions: {
|
|
61
|
+
// addProductToCart: (product) =>
|
|
62
|
+
// set({
|
|
63
|
+
// cartItems: !get()?.cartItems?.find((x) => x.product.id === product.id)
|
|
64
|
+
// ? [...get()?.cartItems, { product: product, qtityOdr: 1 }]
|
|
65
|
+
// : increaseCartItemQtity([...get()?.cartItems], product?.id),
|
|
66
|
+
// }),
|
|
67
|
+
addProductToCart: (product) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
var _a;
|
|
69
|
+
return set({
|
|
70
|
+
cartItems: yield hlpShopping_1.default.addToCart((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, product, 1),
|
|
71
|
+
});
|
|
72
|
+
}),
|
|
73
|
+
increaseCartItemQtity: (productId) => {
|
|
74
|
+
var _a;
|
|
75
|
+
set({
|
|
76
|
+
cartItems: (0, exports.increaseCartItemQtity)((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
decreaseCartItemQtity: (productId) => {
|
|
80
|
+
var _a;
|
|
81
|
+
set({
|
|
82
|
+
cartItems: (0, exports.decreaseCartItemQtity)((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
updateSpePrice: (productId, price) => {
|
|
86
|
+
var _a;
|
|
87
|
+
set({
|
|
88
|
+
cartItems: (0, exports.updateProductSpePrice)((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId, price),
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
checkProductInCart: (productId) => {
|
|
92
|
+
var _a;
|
|
93
|
+
set({
|
|
94
|
+
isProductInCart: checkProductInCart((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
removeProductFromCart: (productId) => set({
|
|
98
|
+
cartItems: [...get().cartItems.filter((item) => item.product.id !== productId)],
|
|
99
|
+
}),
|
|
100
|
+
resetAllProductsInCart: () => set({ cartItems: [] }),
|
|
101
|
+
},
|
|
102
|
+
}));
|
|
103
|
+
const useShoppingActions = () => (0, exports.shoppingStore)((state) => state.actions);
|
|
104
|
+
exports.useShoppingActions = useShoppingActions;
|
|
105
|
+
const useCartItems = () => (0, exports.shoppingStore)((0, shallow_1.useShallow)((state) => state.cartItems));
|
|
106
|
+
exports.useCartItems = useCartItems;
|
|
107
|
+
const useCartItemsCount = () => (0, exports.shoppingStore)((state) => state.cartItems.length);
|
|
108
|
+
exports.useCartItemsCount = useCartItemsCount;
|
|
109
|
+
const useCartItemQtityById = (productId) => (0, exports.shoppingStore)((state) => { var _a; return (_a = state.cartItems.find((item) => item.product.id === productId)) === null || _a === void 0 ? void 0 : _a.qtityOdr; });
|
|
110
|
+
exports.useCartItemQtityById = useCartItemQtityById;
|
|
111
|
+
const isInCart = (productId) => (0, exports.useCartItems)().find((x) => x.product.id === productId);
|
|
112
|
+
exports.isInCart = isInCart;
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import Product from "../products/models/Product";
|
|
3
|
-
import CartItem from "../shopping/models/CartItem";
|
|
4
|
-
declare class HlpShop {
|
|
5
|
-
addToCart: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
6
|
-
updateCartQtity: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
7
|
-
calculateStockOrQtityLimitCounts(item: CartItem, qtity: number): CartItem | boolean;
|
|
8
|
-
getTotalAmount: (cartItems: CartItem[], client: User) => number;
|
|
9
|
-
getPrice: (item: CartItem) => number;
|
|
1
|
+
declare class HlpShopping {
|
|
10
2
|
getAddShopLabel: (marketCode: string, status?: "edit") => "Ajouter une agence" | "modifier l'agence" | "Ajouter un shop" | "Modifier le shop";
|
|
11
3
|
}
|
|
12
|
-
declare const _default:
|
|
4
|
+
declare const _default: HlpShopping;
|
|
13
5
|
export default _default;
|
package/lib/cjs/shops/hlpShop.js
CHANGED
|
@@ -1,61 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
|
|
16
|
-
class SaleItems {
|
|
17
|
-
}
|
|
18
|
-
class HlpShop {
|
|
3
|
+
class HlpShopping {
|
|
19
4
|
constructor() {
|
|
20
|
-
this.addToCart = (cartItems, product, qtity) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
let nCartItems = [];
|
|
22
|
-
const nItem = cartItems.find((item) => { var _a; return ((_a = item === null || item === void 0 ? void 0 : item.product) === null || _a === void 0 ? void 0 : _a.id) === product.id; }) || null;
|
|
23
|
-
if (!nItem) {
|
|
24
|
-
nCartItems = [...cartItems, { product, qtityOdr: 1 }];
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
nCartItems = yield this.updateCartQtity(cartItems, product, qtity);
|
|
28
|
-
}
|
|
29
|
-
// sessionStorage.setItem("basket", JSON.stringify(nCartItems));
|
|
30
|
-
return nCartItems;
|
|
31
|
-
});
|
|
32
|
-
this.updateCartQtity = (cartItems, product, qtity) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const index = cartItems.findIndex((item) => item.product.id === product.id);
|
|
34
|
-
// const qtyInCart = +cartItems[index].qtityOdr + qtity;
|
|
35
|
-
cartItems[index].qtityOdr = qtity;
|
|
36
|
-
const qtyInCart = +cartItems[index].qtityOdr;
|
|
37
|
-
const stock = this.calculateStockOrQtityLimitCounts(cartItems[index], +qtity);
|
|
38
|
-
// ------ if product has promo ------
|
|
39
|
-
if (qtyInCart > 0 && stock) {
|
|
40
|
-
cartItems[index].qtityOdr = qtyInCart;
|
|
41
|
-
}
|
|
42
|
-
// sessionStorage.setItem('basket', JSON.stringify(cartItems));
|
|
43
|
-
return cartItems;
|
|
44
|
-
});
|
|
45
|
-
this.getTotalAmount = (cartItems, client) => {
|
|
46
|
-
return cartItems.reduce((prev, curr) => {
|
|
47
|
-
if (curr.specialPrice > 0) {
|
|
48
|
-
return Math.ceil(prev + this.getPrice(curr) * curr.qtityOdr);
|
|
49
|
-
}
|
|
50
|
-
return Math.ceil(prev + this.getPrice(curr) * curr.qtityOdr);
|
|
51
|
-
}, 0);
|
|
52
|
-
};
|
|
53
|
-
this.getPrice = (item) => {
|
|
54
|
-
if (item.specialPrice > 0) {
|
|
55
|
-
return item.specialPrice;
|
|
56
|
-
}
|
|
57
|
-
return item.product.price;
|
|
58
|
-
};
|
|
59
5
|
this.getAddShopLabel = (marketCode, status) => {
|
|
60
6
|
if (["immo", "veh"].includes(marketCode)) {
|
|
61
7
|
return status !== "edit" ? "Ajouter une agence" : "modifier l'agence";
|
|
@@ -63,20 +9,6 @@ class HlpShop {
|
|
|
63
9
|
return status !== "edit" ? "Ajouter un shop" : "Modifier le shop";
|
|
64
10
|
};
|
|
65
11
|
}
|
|
66
|
-
calculateStockOrQtityLimitCounts(item, qtity) {
|
|
67
|
-
// const qty = +item.qtityOdr + qtity;
|
|
68
|
-
const qty = +item.qtityOdr;
|
|
69
|
-
// const qtyLimitByClient = +item.product.stores[0].qtityLimit;
|
|
70
|
-
const stockSalable = +hlpProduct_1.default.getStockSalable(item.product);
|
|
71
|
-
const stock = stockSalable;
|
|
72
|
-
// qtyLimitByClient > 0 && stockSalable >= qtyLimitByClient ? qtyLimitByClient : stockSalable;
|
|
73
|
-
if (stock < qty) {
|
|
74
|
-
// this.modalService.confirmError(" Stock ou quantité limitée à " + stock, "Quantité limitée");s
|
|
75
|
-
item.qtityOdr = stock;
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
12
|
}
|
|
81
|
-
exports.default = new
|
|
13
|
+
exports.default = new HlpShopping();
|
|
82
14
|
// export default new HlpShop(httpService);
|
|
@@ -4,10 +4,9 @@ import CartItem from "./models/CartItem";
|
|
|
4
4
|
declare class HlpShopping {
|
|
5
5
|
addToCart: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
6
6
|
updateCartQtity: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
7
|
-
calculateStockOrQtityLimitCounts
|
|
7
|
+
private calculateStockOrQtityLimitCounts;
|
|
8
8
|
getTotalAmount: (cartItems: CartItem[], client: User) => number;
|
|
9
9
|
getPrice: (item: CartItem) => number;
|
|
10
|
-
getAddShopLabel: (marketCode: string, status?: "edit") => "Ajouter une agence" | "modifier l'agence" | "Ajouter un shop" | "Modifier le shop";
|
|
11
10
|
}
|
|
12
11
|
declare const _default: HlpShopping;
|
|
13
12
|
export default _default;
|
|
@@ -51,12 +51,6 @@ class HlpShopping {
|
|
|
51
51
|
}
|
|
52
52
|
return item.product.price;
|
|
53
53
|
};
|
|
54
|
-
this.getAddShopLabel = (marketCode, status) => {
|
|
55
|
-
if (["immo", "veh"].includes(marketCode)) {
|
|
56
|
-
return status !== "edit" ? "Ajouter une agence" : "modifier l'agence";
|
|
57
|
-
}
|
|
58
|
-
return status !== "edit" ? "Ajouter un shop" : "Modifier le shop";
|
|
59
|
-
};
|
|
60
54
|
}
|
|
61
55
|
calculateStockOrQtityLimitCounts(item, qtity) {
|
|
62
56
|
// const qty = +item.qtityOdr + qtity;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Product from "../products/models/Product";
|
|
2
|
+
import CartItem from "./models/CartItem";
|
|
3
|
+
export interface ShoppingStore {
|
|
4
|
+
cartItems: CartItem[];
|
|
5
|
+
isProductInCart: boolean;
|
|
6
|
+
actions: {
|
|
7
|
+
addProductToCart: (val: Product) => void;
|
|
8
|
+
removeProductFromCart: (productId: number) => void;
|
|
9
|
+
increaseCartItemQtity: (productId: number) => void;
|
|
10
|
+
checkProductInCart: (productId: number) => void;
|
|
11
|
+
decreaseCartItemQtity: (productId: number) => void;
|
|
12
|
+
resetAllProductsInCart: () => void;
|
|
13
|
+
updateSpePrice: (productId: number, price: number) => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare const updateProductQtity: (cartItems: CartItem[], productId: number, updateType: "increase" | "decrease") => CartItem[];
|
|
17
|
+
export declare const updateProductSpePrice: (cartItems: CartItem[], productId: number, spePrice: number) => CartItem[];
|
|
18
|
+
export declare const increaseCartItemQtity: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
19
|
+
export declare const removeProductFromCart: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
20
|
+
export declare const decreaseCartItemQtity: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
21
|
+
export declare const shoppingStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ShoppingStore>>;
|
|
22
|
+
export declare const useShoppingActions: () => {
|
|
23
|
+
addProductToCart: (val: Product) => void;
|
|
24
|
+
removeProductFromCart: (productId: number) => void;
|
|
25
|
+
increaseCartItemQtity: (productId: number) => void;
|
|
26
|
+
checkProductInCart: (productId: number) => void;
|
|
27
|
+
decreaseCartItemQtity: (productId: number) => void;
|
|
28
|
+
resetAllProductsInCart: () => void;
|
|
29
|
+
updateSpePrice: (productId: number, price: number) => void;
|
|
30
|
+
};
|
|
31
|
+
export declare const useCartItems: () => CartItem[];
|
|
32
|
+
export declare const useCartItemsCount: () => number;
|
|
33
|
+
export declare const useCartItemQtityById: (productId: number | undefined) => number;
|
|
34
|
+
export declare const isInCart: (productId: number) => CartItem;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { create } from "zustand";
|
|
11
|
+
import { useShallow } from "zustand/react/shallow";
|
|
12
|
+
import hlpShopping from "./hlpShopping";
|
|
13
|
+
export const updateProductQtity = (cartItems, productId, updateType) => {
|
|
14
|
+
return cartItems === null || cartItems === void 0 ? void 0 : cartItems.map((item) => {
|
|
15
|
+
if (item.product.id === productId) {
|
|
16
|
+
return Object.assign(Object.assign({}, item), { qtityOdr: updateType === "increase" ? item.qtityOdr + 1 : item.qtityOdr - 1 });
|
|
17
|
+
}
|
|
18
|
+
return item;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const updateProductSpePrice = (cartItems, productId, spePrice) => {
|
|
22
|
+
return cartItems === null || cartItems === void 0 ? void 0 : cartItems.map((item) => {
|
|
23
|
+
if (item.product.id === productId) {
|
|
24
|
+
return Object.assign(Object.assign({}, item), { specialPrice: spePrice });
|
|
25
|
+
}
|
|
26
|
+
return item;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const checkProductInCart = (cartItems, productId) => {
|
|
30
|
+
return cartItems.find((x) => x.product.id === productId) ? true : false;
|
|
31
|
+
};
|
|
32
|
+
export const increaseCartItemQtity = (cartItems, productId) => {
|
|
33
|
+
return updateProductQtity(cartItems, productId, "increase");
|
|
34
|
+
};
|
|
35
|
+
export const removeProductFromCart = (cartItems, productId) => {
|
|
36
|
+
return cartItems.filter((item) => item.product.id !== productId);
|
|
37
|
+
};
|
|
38
|
+
export const decreaseCartItemQtity = (cartItems, productId) => {
|
|
39
|
+
var _a;
|
|
40
|
+
const ifQtity = ((_a = cartItems.find((x) => x.product.id === productId)) === null || _a === void 0 ? void 0 : _a.qtityOdr) === 1;
|
|
41
|
+
if (ifQtity) {
|
|
42
|
+
return removeProductFromCart(cartItems, productId);
|
|
43
|
+
}
|
|
44
|
+
return updateProductQtity(cartItems, productId, "decrease");
|
|
45
|
+
};
|
|
46
|
+
export const shoppingStore = create((set, get) => ({
|
|
47
|
+
cartItems: [],
|
|
48
|
+
isProductInCart: false,
|
|
49
|
+
actions: {
|
|
50
|
+
// addProductToCart: (product) =>
|
|
51
|
+
// set({
|
|
52
|
+
// cartItems: !get()?.cartItems?.find((x) => x.product.id === product.id)
|
|
53
|
+
// ? [...get()?.cartItems, { product: product, qtityOdr: 1 }]
|
|
54
|
+
// : increaseCartItemQtity([...get()?.cartItems], product?.id),
|
|
55
|
+
// }),
|
|
56
|
+
addProductToCart: (product) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
var _a;
|
|
58
|
+
return set({
|
|
59
|
+
cartItems: yield hlpShopping.addToCart((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, product, 1),
|
|
60
|
+
});
|
|
61
|
+
}),
|
|
62
|
+
increaseCartItemQtity: (productId) => {
|
|
63
|
+
var _a;
|
|
64
|
+
set({
|
|
65
|
+
cartItems: increaseCartItemQtity((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
decreaseCartItemQtity: (productId) => {
|
|
69
|
+
var _a;
|
|
70
|
+
set({
|
|
71
|
+
cartItems: decreaseCartItemQtity((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
updateSpePrice: (productId, price) => {
|
|
75
|
+
var _a;
|
|
76
|
+
set({
|
|
77
|
+
cartItems: updateProductSpePrice((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId, price),
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
checkProductInCart: (productId) => {
|
|
81
|
+
var _a;
|
|
82
|
+
set({
|
|
83
|
+
isProductInCart: checkProductInCart((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
removeProductFromCart: (productId) => set({
|
|
87
|
+
cartItems: [...get().cartItems.filter((item) => item.product.id !== productId)],
|
|
88
|
+
}),
|
|
89
|
+
resetAllProductsInCart: () => set({ cartItems: [] }),
|
|
90
|
+
},
|
|
91
|
+
}));
|
|
92
|
+
export const useShoppingActions = () => shoppingStore((state) => state.actions);
|
|
93
|
+
export const useCartItems = () => shoppingStore(useShallow((state) => state.cartItems));
|
|
94
|
+
export const useCartItemsCount = () => shoppingStore((state) => state.cartItems.length);
|
|
95
|
+
export const useCartItemQtityById = (productId) => shoppingStore((state) => { var _a; return (_a = state.cartItems.find((item) => item.product.id === productId)) === null || _a === void 0 ? void 0 : _a.qtityOdr; });
|
|
96
|
+
export const isInCart = (productId) => useCartItems().find((x) => x.product.id === productId);
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import Product from "../products/models/Product";
|
|
3
|
-
import CartItem from "../shopping/models/CartItem";
|
|
4
|
-
declare class HlpShop {
|
|
5
|
-
addToCart: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
6
|
-
updateCartQtity: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
7
|
-
calculateStockOrQtityLimitCounts(item: CartItem, qtity: number): CartItem | boolean;
|
|
8
|
-
getTotalAmount: (cartItems: CartItem[], client: User) => number;
|
|
9
|
-
getPrice: (item: CartItem) => number;
|
|
1
|
+
declare class HlpShopping {
|
|
10
2
|
getAddShopLabel: (marketCode: string, status?: "edit") => "Ajouter une agence" | "modifier l'agence" | "Ajouter un shop" | "Modifier le shop";
|
|
11
3
|
}
|
|
12
|
-
declare const _default:
|
|
4
|
+
declare const _default: HlpShopping;
|
|
13
5
|
export default _default;
|
package/lib/esm/shops/hlpShop.js
CHANGED
|
@@ -1,56 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import hlpProduct from "../products/hlpProduct";
|
|
11
|
-
class SaleItems {
|
|
12
|
-
}
|
|
13
|
-
class HlpShop {
|
|
1
|
+
class HlpShopping {
|
|
14
2
|
constructor() {
|
|
15
|
-
this.addToCart = (cartItems, product, qtity) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
let nCartItems = [];
|
|
17
|
-
const nItem = cartItems.find((item) => { var _a; return ((_a = item === null || item === void 0 ? void 0 : item.product) === null || _a === void 0 ? void 0 : _a.id) === product.id; }) || null;
|
|
18
|
-
if (!nItem) {
|
|
19
|
-
nCartItems = [...cartItems, { product, qtityOdr: 1 }];
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
nCartItems = yield this.updateCartQtity(cartItems, product, qtity);
|
|
23
|
-
}
|
|
24
|
-
// sessionStorage.setItem("basket", JSON.stringify(nCartItems));
|
|
25
|
-
return nCartItems;
|
|
26
|
-
});
|
|
27
|
-
this.updateCartQtity = (cartItems, product, qtity) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
const index = cartItems.findIndex((item) => item.product.id === product.id);
|
|
29
|
-
// const qtyInCart = +cartItems[index].qtityOdr + qtity;
|
|
30
|
-
cartItems[index].qtityOdr = qtity;
|
|
31
|
-
const qtyInCart = +cartItems[index].qtityOdr;
|
|
32
|
-
const stock = this.calculateStockOrQtityLimitCounts(cartItems[index], +qtity);
|
|
33
|
-
// ------ if product has promo ------
|
|
34
|
-
if (qtyInCart > 0 && stock) {
|
|
35
|
-
cartItems[index].qtityOdr = qtyInCart;
|
|
36
|
-
}
|
|
37
|
-
// sessionStorage.setItem('basket', JSON.stringify(cartItems));
|
|
38
|
-
return cartItems;
|
|
39
|
-
});
|
|
40
|
-
this.getTotalAmount = (cartItems, client) => {
|
|
41
|
-
return cartItems.reduce((prev, curr) => {
|
|
42
|
-
if (curr.specialPrice > 0) {
|
|
43
|
-
return Math.ceil(prev + this.getPrice(curr) * curr.qtityOdr);
|
|
44
|
-
}
|
|
45
|
-
return Math.ceil(prev + this.getPrice(curr) * curr.qtityOdr);
|
|
46
|
-
}, 0);
|
|
47
|
-
};
|
|
48
|
-
this.getPrice = (item) => {
|
|
49
|
-
if (item.specialPrice > 0) {
|
|
50
|
-
return item.specialPrice;
|
|
51
|
-
}
|
|
52
|
-
return item.product.price;
|
|
53
|
-
};
|
|
54
3
|
this.getAddShopLabel = (marketCode, status) => {
|
|
55
4
|
if (["immo", "veh"].includes(marketCode)) {
|
|
56
5
|
return status !== "edit" ? "Ajouter une agence" : "modifier l'agence";
|
|
@@ -58,20 +7,6 @@ class HlpShop {
|
|
|
58
7
|
return status !== "edit" ? "Ajouter un shop" : "Modifier le shop";
|
|
59
8
|
};
|
|
60
9
|
}
|
|
61
|
-
calculateStockOrQtityLimitCounts(item, qtity) {
|
|
62
|
-
// const qty = +item.qtityOdr + qtity;
|
|
63
|
-
const qty = +item.qtityOdr;
|
|
64
|
-
// const qtyLimitByClient = +item.product.stores[0].qtityLimit;
|
|
65
|
-
const stockSalable = +hlpProduct.getStockSalable(item.product);
|
|
66
|
-
const stock = stockSalable;
|
|
67
|
-
// qtyLimitByClient > 0 && stockSalable >= qtyLimitByClient ? qtyLimitByClient : stockSalable;
|
|
68
|
-
if (stock < qty) {
|
|
69
|
-
// this.modalService.confirmError(" Stock ou quantité limitée à " + stock, "Quantité limitée");s
|
|
70
|
-
item.qtityOdr = stock;
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
10
|
}
|
|
76
|
-
export default new
|
|
11
|
+
export default new HlpShopping();
|
|
77
12
|
// export default new HlpShop(httpService);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "asv-hlps-market",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"description": "some markets tools",
|
|
5
5
|
"main": "./lib/cjs/index.js",
|
|
6
6
|
"module": "./lib/esm/index.js",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"author": "Aril Vignon",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"typescript": "^5.
|
|
19
|
+
"typescript": "^5.9.2"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"asv-hlps": "^1.4.
|
|
22
|
+
"asv-hlps": "^1.4.62"
|
|
23
23
|
}
|
|
24
24
|
}
|