rerobe-js-orm 2.5.5 → 2.5.6

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.
@@ -89,6 +89,12 @@ class OrderFromFormState extends OrderFactory_1.default {
89
89
  merchantId: ((_s = fs.props) === null || _s === void 0 ? void 0 : _s.merchantId) || '',
90
90
  tags: fs.fields.tags.selectedValues || [],
91
91
  refunds: ((_t = fs.props) === null || _t === void 0 ? void 0 : _t.refunds) || [],
92
+ subtotalPricePresentment: fs.props.subtotalPricePresentment,
93
+ totalDiscountPresentment: fs.props.totalDiscountPresentment,
94
+ totalPricePresentment: fs.props.totalPricePresentment,
95
+ totalRefundedPresentment: fs.props.totalRefundedPresentment,
96
+ totalShippingPricePresentment: fs.props.totalShippingPricePresentment,
97
+ totalTaxPresentment: fs.props.totalTaxPresentment,
92
98
  };
93
99
  return new Order_1.default(Object.assign({}, orderAttributes));
94
100
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.productOptions = exports.productIsOnSaleOptions = exports.discountTypeOptions = exports.conditionTypeOptions = exports.salesChannelOptions = exports.unisexJewelry = exports.mensJewelry = exports.jewelry = exports.unisexAccessories = exports.mensAccessories = exports.accessories = exports.unisexBags = exports.mensBags = exports.bags = exports.unisexShoes = exports.mensShoes = exports.shoes = exports.unisexClothing = exports.mensClothing = exports.clothing = exports.productCategories = exports.clothingMaterials = exports.shoeSizes = exports.jeanSizes = exports.gender = exports.conditions = exports.colors = exports.brands = exports.sizeCommentOptions = exports.clothingSizeOptions = exports.statusOptions = exports.publishTypeOptions = exports.availableForSaleOptions = void 0;
3
+ exports.productOptions = exports.productIsOnSaleOptions = exports.discountTypeOptions = exports.salesChannelOptions = exports.unisexJewelry = exports.mensJewelry = exports.jewelry = exports.unisexAccessories = exports.mensAccessories = exports.accessories = exports.unisexBags = exports.mensBags = exports.bags = exports.unisexShoes = exports.mensShoes = exports.shoes = exports.unisexClothing = exports.mensClothing = exports.clothing = exports.productCategories = exports.clothingMaterials = exports.shoeSizes = exports.jeanSizes = exports.gender = exports.conditions = exports.colors = exports.brands = exports.sizeCommentOptions = exports.clothingSizeOptions = exports.statusOptions = exports.publishTypeOptions = exports.availableForSaleOptions = void 0;
4
4
  const ProductStateManager_1 = require("../../models/ProductStateManager");
5
5
  const lodash_1 = require("lodash");
6
6
  const availableForSaleOptions = [
@@ -9,4 +9,8 @@ export default class OrderHelpers {
9
9
  getOrderInfoWithRefundsAndFulfillments(order: CompleteOrder): OrderWithRefundsAndFulfillmentsInfoObj;
10
10
  getUpdatedOrderObjWithRefunds(orderObj: CompleteOrder, refundObj: OrderRefund): CompleteOrder;
11
11
  getUpdatedOrderObjWithFulfillment(orderObj: CompleteOrder, fulfillmentObj: FulfillmentAdmin, totalUnfulfilledItems: number): CompleteOrder;
12
+ getSubtotalPrice(lineItems: ReRobeOrderLineItem[] | any[], userAvailableCredit?: number | string): number;
13
+ getCreditDiscount(lineItems: ReRobeOrderLineItem[] | undefined, userAvailableCredit: number | string): number;
14
+ getSaleDiscount(lineItems?: ReRobeOrderLineItem[]): number;
15
+ getDiscountAmount(lineItems?: ReRobeOrderLineItem[], userAvailableCredit?: number | string): number;
12
16
  }
@@ -84,6 +84,9 @@ class OrderHelpers {
84
84
  },
85
85
  shopifyProductId: product.shopifyId || null,
86
86
  productId: product.documentId,
87
+ status: product.status || '',
88
+ isOnSale: product.isOnSale || '',
89
+ salePrice: product.salePrice || '',
87
90
  };
88
91
  }
89
92
  toFixedPointPrice(price) {
@@ -193,5 +196,49 @@ class OrderHelpers {
193
196
  totalUnfulfilledItems - fulfilledItemsQuantity > 0 ? 'PARTIALLY_FULFILLED' : 'FULFILLED';
194
197
  return updatedOrder;
195
198
  }
199
+ getSubtotalPrice(lineItems, userAvailableCredit = 0) {
200
+ // Get subtotal without saleDiscount (products on sale) and creditDiscount (userAvailableCredit)
201
+ if (!lineItems || !lineItems.length) {
202
+ return 0;
203
+ }
204
+ const subtotalWithoutSaleDiscount = lineItems.reduce((acc, lineItem) => {
205
+ var _a;
206
+ const isSaleItem = lineItem.isOnSale === 'yes' && (lineItem.status === 'CLEARANCE' || lineItem.status === 'RESERVED');
207
+ const itemPrice = isSaleItem ? lineItem.salePrice : (_a = lineItem.originalTotalPrice) === null || _a === void 0 ? void 0 : _a.amount;
208
+ return acc + Number(itemPrice);
209
+ }, 0);
210
+ let subtotal = subtotalWithoutSaleDiscount;
211
+ if (userAvailableCredit && Number(userAvailableCredit) > 0) {
212
+ subtotal = subtotalWithoutSaleDiscount - Number(userAvailableCredit);
213
+ }
214
+ if (subtotal < 0) {
215
+ subtotal = 0;
216
+ }
217
+ return Number(Number(subtotal).toFixed(2));
218
+ }
219
+ getCreditDiscount(lineItems = [], userAvailableCredit) {
220
+ if (!userAvailableCredit || Number(userAvailableCredit) <= 0) {
221
+ return 0;
222
+ }
223
+ const subtotal = this.getSubtotalPrice(lineItems);
224
+ return subtotal > userAvailableCredit ? Number(userAvailableCredit) : subtotal;
225
+ }
226
+ getSaleDiscount(lineItems = []) {
227
+ return lineItems.reduce((acc, cur) => {
228
+ var _a;
229
+ const isSaleItem = cur.isOnSale === 'yes' && (cur.status === 'CLEARANCE' || cur.status === 'RESERVED');
230
+ let prodDiscount = 0;
231
+ if (isSaleItem) {
232
+ prodDiscount = Number((Number((_a = cur.originalTotalPrice) === null || _a === void 0 ? void 0 : _a.amount) - Number(cur.salePrice)).toFixed(2));
233
+ }
234
+ return acc + prodDiscount;
235
+ }, 0);
236
+ }
237
+ getDiscountAmount(lineItems = [], userAvailableCredit = 0) {
238
+ const creditDiscount = this.getCreditDiscount(lineItems, userAvailableCredit);
239
+ const saleDiscount = this.getSaleDiscount(lineItems);
240
+ const discount = Number(Number(creditDiscount + saleDiscount).toFixed(2));
241
+ return discount;
242
+ }
196
243
  }
197
244
  exports.default = OrderHelpers;
@@ -82,6 +82,12 @@ export default class Order extends Base {
82
82
  customerName: string;
83
83
  merchantId: string;
84
84
  refunds: OrderRefund[];
85
+ subtotalPricePresentment: Money;
86
+ totalDiscountPresentment: Money;
87
+ totalPricePresentment: Money;
88
+ totalRefundedPresentment: Money;
89
+ totalShippingPricePresentment: Money;
90
+ totalTaxPresentment: Money;
85
91
  constructor(props?: any);
86
92
  toObj(): ReRobeOrderObj;
87
93
  }
@@ -105,6 +105,24 @@ class Order extends Base_1.default {
105
105
  this.customerName = (props === null || props === void 0 ? void 0 : props.customerName) || '';
106
106
  this.merchantId = (props === null || props === void 0 ? void 0 : props.merchantId) || '';
107
107
  this.refunds = (props === null || props === void 0 ? void 0 : props.refunds) || [];
108
+ this.subtotalPricePresentment = (props === null || props === void 0 ? void 0 : props.subtotalPricePresentment) || {
109
+ amount: 0,
110
+ };
111
+ this.totalDiscountPresentment = (props === null || props === void 0 ? void 0 : props.totalDiscountPresentment) || {
112
+ amount: 0,
113
+ };
114
+ this.totalPricePresentment = (props === null || props === void 0 ? void 0 : props.totalPricePresentment) || {
115
+ amount: 0,
116
+ };
117
+ this.totalRefundedPresentment = (props === null || props === void 0 ? void 0 : props.totalRefundedPresentment) || {
118
+ amount: 0,
119
+ };
120
+ this.totalShippingPricePresentment = (props === null || props === void 0 ? void 0 : props.totalShippingPricePresentment) || {
121
+ amount: 0,
122
+ };
123
+ this.totalTaxPresentment = (props === null || props === void 0 ? void 0 : props.totalTaxPresentment) || {
124
+ amount: 0,
125
+ };
108
126
  }
109
127
  toObj() {
110
128
  const orderObj = {
@@ -150,6 +168,12 @@ class Order extends Base_1.default {
150
168
  customerName: this.customerName,
151
169
  merchantId: this.merchantId,
152
170
  refunds: this.refunds,
171
+ subtotalPricePresentment: this.subtotalPricePresentment,
172
+ totalDiscountPresentment: this.totalDiscountPresentment,
173
+ totalPricePresentment: this.totalPricePresentment,
174
+ totalRefundedPresentment: this.totalRefundedPresentment,
175
+ totalShippingPricePresentment: this.totalShippingPricePresentment,
176
+ totalTaxPresentment: this.totalTaxPresentment,
153
177
  };
154
178
  if (this.paymentType) {
155
179
  orderObj.paymentType = this.paymentType;
@@ -63,6 +63,12 @@ declare type ReRobeOrderObj = {
63
63
  refunds?: OrderRefund[];
64
64
  createdAt?: string;
65
65
  updatedAt?: string;
66
+ subtotalPricePresentment?: Money;
67
+ totalDiscountPresentment?: Money;
68
+ totalPricePresentment?: Money;
69
+ totalRefundedPresentment?: Money;
70
+ totalShippingPricePresentment?: Money;
71
+ totalTaxPresentment?: Money;
66
72
  };
67
73
  declare type OrderWithRefundsAndFulfillmentsInfoObj = {
68
74
  documentId?: string;
@@ -213,6 +219,9 @@ interface ReRobeOrderLineItem extends OrderLineItem {
213
219
  canceledQuantity?: number | string;
214
220
  fulfilledQuantity?: number | string;
215
221
  unfulfilledQuantity?: number | string;
222
+ status?: ProductSellStatusKeys | string;
223
+ isOnSale?: string;
224
+ salePrice?: string;
216
225
  }
217
226
  declare type OrderLineItemConnection = {
218
227
  edges: OrderLineItemEdge[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "2.5.5",
3
+ "version": "2.5.6",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",