addio-admin-sdk 1.7.106 → 1.7.108

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/.env CHANGED
@@ -2,13 +2,14 @@ NEXT_PUBLIC_FIREBASE_CONFIG_API_KEY_DEV='AIzaSyBNtwzdIe2__HJD23S87RIbWbIqKQVtFiw
2
2
  NEXT_PUBLIC_FIREBASE_CONFIG_API_KEY_PROD='AIzaSyDK6WQZkCrsMGunAPHn9KkdCGPky4hTgL4'
3
3
  NEXT_PUBLIC_MESSAGING_SENDER_ID_DEV='188490998694'
4
4
  NEXT_PUBLIC_MESSAGING_SENDER_ID_PROD='725873016982'
5
- NEXT_PUBLIC_FIREBASE_APP_ID_DEV='1:188490998694:web:eecd719e7b18f38d272567'
6
5
  NEXT_PUBLIC_FIREBASE_APP_ID_PROD='1:725873016982:web:9b1f6d77819909e19102b7'
6
+ NEXT_PUBLIC_FIREBASE_APP_ID_DEV='1:188490998694:web:eecd719e7b18f38d272567'
7
7
  NEXT_PUBLIC_MEASUREMENT_ID_DEV='G-4BB66ZRTWZ'
8
8
  NEXT_PUBLIC_MEASUREMENT_ID_PROD='G-BB8HHZ466R'
9
+
9
10
  NEXT_PUBLIC_SERVICE_DATABASE_READ_PROVIDER=nobase
10
- NEXT_PUBLIC_SERVICE_DATABASE_WRITE_PROVIDER=nobase,firebase
11
+ NEXT_PUBLIC_SERVICE_DATABASE_WRITE_PROVIDER=nobase
11
12
  NEXT_PUBLIC_SERVICE_DATABASE_URL=https://db-test.addiocommerce.com/
12
- NEXT_PUBLIC_SERVICE_DATABASE_TOKEN=$SERVICE_DATABASE_TOKEN
13
13
  NEXT_PUBLIC_API_URL=https://api-test.addiocommerce.com/v1
14
- # NEXT_PUBLIC_API_URL=http://localhost:8080
14
+ NEXT_PUBLIC_SERVICE_DATABASE_TOKEN='337043a374-6f0be-5eb26-05be550631'
15
+ LOCAL_FIRESTORE=false
@@ -68,6 +68,12 @@ export default class Cart extends BaseServiceClass<ICart> {
68
68
  * @returns The Object managing the reservation for this cart
69
69
  */
70
70
  getReservedQuantities: () => Promise<CartReservedQuantities>;
71
+ /**
72
+ * Get a copy of all items in cart with property qte_reserved either set to current cart item properties, or removed completely from items
73
+ * @property action - If reserved quantities property should be set or removed
74
+ * @property itemsToUse - Optionnal. If undefined, uses current items in cart obj
75
+ */
76
+ getItemsWithUpdatedReservedQuantities: (action: 'set' | 'remove', itemsToUse?: ICartItem[]) => ICartItem[];
71
77
  canEnterPredefinedBox: (box: IPredefinedBox, subtotalToRespect?: number, weightToRespect?: number, totalItemsToRespect?: number, space?: Space) => boolean;
72
78
  getTotalHeight: (unit?: 'inches' | 'centimeters') => number;
73
79
  getTotalLength: (unit?: 'inches' | 'centimeters') => number;
@@ -431,6 +431,21 @@ class Cart extends baseService_1.BaseServiceClass {
431
431
  path: docPath
432
432
  }, this._user);
433
433
  };
434
+ /**
435
+ * Get a copy of all items in cart with property qte_reserved either set to current cart item properties, or removed completely from items
436
+ * @property action - If reserved quantities property should be set or removed
437
+ * @property itemsToUse - Optionnal. If undefined, uses current items in cart obj
438
+ */
439
+ this.getItemsWithUpdatedReservedQuantities = (action, itemsToUse) => {
440
+ const itemsToUpdate = itemsToUse || this.data().items;
441
+ if (action == 'set') {
442
+ return itemsToUpdate.map((i) => (Object.assign(Object.assign({}, i), { qte_reserved: i.qte })));
443
+ }
444
+ return itemsToUpdate.map((i) => {
445
+ const { qte_reserved } = i, rest = __rest(i, ["qte_reserved"]);
446
+ return rest;
447
+ });
448
+ };
434
449
  //#endregion
435
450
  //#region BOXES + SHIPPING
436
451
  this.canEnterPredefinedBox = (box, subtotalToRespect, weightToRespect, totalItemsToRespect, space) => {
@@ -1508,15 +1523,25 @@ class Cart extends baseService_1.BaseServiceClass {
1508
1523
  // Save inventory for cart items
1509
1524
  console.log('---------------');
1510
1525
  let delay5 = (0, moment_1.default)();
1511
- try {
1512
- // Adjust cart items inventory
1513
- await space.inventory.ajust(this.data().items, 'paid', this.data().cart_type, {
1514
- currentStoreId: this.data().current_store_id || ''
1515
- });
1526
+ // Check for space reserved quantities option
1527
+ // If defined for space, or if all items are already reserved, skip all inventory ajustments here - was already ajusted on items added to card!
1528
+ const spaceHasReservedQuantities = space.options.checkIfOptionIsSet('inventory.reserve_on_add_to_cart');
1529
+ const allItemsHaveReservedQuantities = this.data().items.every((i) => typeof i.qte_reserved == 'number' && i.qte_reserved == i.qte);
1530
+ if (spaceHasReservedQuantities || allItemsHaveReservedQuantities) {
1531
+ console.log(`skipping inventory update in createOrderWithSuccessfulPaymentPayload for space ${space.getName()}. Inventory ajusted on items added to cart!`);
1516
1532
  }
1517
- catch (error) {
1518
- console.log('error while updating inventory', error);
1519
- await (0, console_1.alertAdminV2)(`Error while updating inventory`, `We are here: /src/lib/Cart/index.ts#1574. We are in space ${space.data().id}. JSON error: ${JSON.stringify(error)}`, error.toString(), space.getRef());
1533
+ else {
1534
+ try {
1535
+ // Adjust cart items inventory
1536
+ await space.inventory.ajust(this.data().items, 'paid', this.data().cart_type, {
1537
+ currentStoreId: this.data().current_store_id || '',
1538
+ shouldCheckReservedQte: this.data().items.some((i) => typeof i.qte_reserved == 'number')
1539
+ });
1540
+ }
1541
+ catch (error) {
1542
+ console.log('error while updating inventory', error);
1543
+ await (0, console_1.alertAdminV2)(`Error while updating inventory`, `We are here: /src/lib/Cart/index.ts#2100. We are in space ${space.data().id}. JSON error: ${JSON.stringify(error)}`, error.toString(), space.getRef());
1544
+ }
1520
1545
  }
1521
1546
  console.log('adjusting inventory delay: ', (0, moment_1.default)().diff(delay5, 'seconds'));
1522
1547
  // -----------------------------------
@@ -1534,7 +1559,7 @@ class Cart extends baseService_1.BaseServiceClass {
1534
1559
  }
1535
1560
  }
1536
1561
  catch (error) {
1537
- await (0, console_1.alertAdminV2)(`Error while saving new cart`, `We are here: /src/lib/Cart/index.ts#1352. We are in space ${space.data().id}. JSON error: ${JSON.stringify(error)}`, error.toString(), space.getRef());
1562
+ await (0, console_1.alertAdminV2)(`Error while saving new cart`, `We are here: /src/lib/Cart/index.ts#2125. We are in space ${space.data().id}. JSON error: ${JSON.stringify(error)}`, error.toString(), space.getRef());
1538
1563
  throw error;
1539
1564
  }
1540
1565
  console.log('====================');