@unchainedshop/core-orders 1.1.3 → 1.1.9
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/db/OrderDeliveriesCollection.d.ts +1 -3
- package/lib/db/OrderDiscountsCollection.d.ts +1 -3
- package/lib/db/OrderPaymentsCollection.d.ts +1 -3
- package/lib/db/OrderPositionsCollection.d.ts +1 -3
- package/lib/db/OrdersCollection.d.ts +1 -3
- package/lib/director/OrderPricingSheet.d.ts +0 -2
- package/lib/module/configureOrderDeliveriesModule.d.ts +2 -2
- package/lib/module/configureOrderDiscountsModule.d.ts +2 -2
- package/lib/module/configureOrderPaymentsModule.d.ts +2 -2
- package/lib/module/configureOrderPaymentsModule.js.map +1 -1
- package/lib/module/configureOrderPositionsModule.d.ts +2 -2
- package/lib/module/configureOrderPositionsModule.js.map +1 -1
- package/lib/module/configureOrdersModule-mutations.d.ts +4 -4
- package/lib/module/configureOrdersModule-processing.d.ts +3 -3
- package/lib/module/configureOrdersModule-queries.d.ts +1 -1
- package/lib/module/configureOrdersModule-transformations.d.ts +1 -1
- package/lib/module/configureOrdersModule.d.ts +1 -2
- package/lib/orders-settings.d.ts +1 -2
- package/license +274 -0
- package/package.json +11 -8
- package/src/module/configureOrderPaymentsModule.ts +3 -3
- package/src/module/configureOrderPositionsModule.ts +4 -3
- package/tests/orders-index.test.ts +2 -2
- package/tsconfig.build.json +12 -4
- package/.npm/package/README +0 -7
- package/.npm/package/npm-shrinkwrap.json +0 -190
- package/.versions +0 -54
- package/package.js +0 -33
- package/plugins/discount-100-off.ts +0 -44
- package/plugins/discount-half-price-manual.ts +0 -43
- package/plugins/discount-half-price.ts +0 -46
- package/plugins/order-delivery.ts +0 -45
- package/plugins/order-discount.ts +0 -158
- package/plugins/order-items-discount.ts +0 -116
- package/plugins/order-items.ts +0 -61
- package/plugins/order-payment.ts +0 -46
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { IOrderPricingAdapter, OrderPricingRowCategory } from '@unchainedshop/types/orders.pricing';
|
|
2
|
-
import { OrderPricingDirector, OrderPricingAdapter } from 'meteor/unchained:core-orders';
|
|
3
|
-
|
|
4
|
-
const resolveRatioAndTaxDivisorForPricingSheet = (pricing, total) => {
|
|
5
|
-
if (total === 0 || !pricing) {
|
|
6
|
-
return {
|
|
7
|
-
ratio: 1,
|
|
8
|
-
taxDivisor: 1,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
const tax = pricing.taxSum();
|
|
12
|
-
const gross = pricing.gross();
|
|
13
|
-
return {
|
|
14
|
-
ratio: gross / total,
|
|
15
|
-
taxDivisor: gross / (gross - tax),
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const resolveAmountAndTax = ({ ratio, taxDivisor }, amount) => {
|
|
20
|
-
const shareAmount = Number.isFinite(ratio) ? amount * ratio : 0;
|
|
21
|
-
const shareTaxAmount = Number.isFinite(taxDivisor) ? shareAmount - shareAmount / taxDivisor : 0;
|
|
22
|
-
return [shareAmount, shareTaxAmount];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const applyDiscountToMultipleShares = (shares, amount) => {
|
|
26
|
-
return shares.reduce(
|
|
27
|
-
([currentDiscountAmount, currentTaxAmount], share) => {
|
|
28
|
-
const [shareAmount, shareTaxAmount] = resolveAmountAndTax(share, amount);
|
|
29
|
-
return [currentDiscountAmount + shareAmount, currentTaxAmount + shareTaxAmount];
|
|
30
|
-
},
|
|
31
|
-
[0, 0],
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const calculateAmountToSplit = (configuration, amount) => {
|
|
36
|
-
const deductionAmount = configuration.rate
|
|
37
|
-
? amount * configuration.rate
|
|
38
|
-
: Math.min(configuration.fixedRate, amount);
|
|
39
|
-
|
|
40
|
-
return Math.max(0, deductionAmount - (configuration.alreadyDeducted || 0));
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const OrderItemsDiscount: IOrderPricingAdapter = {
|
|
44
|
-
...OrderPricingAdapter,
|
|
45
|
-
|
|
46
|
-
key: 'shop.unchained.pricing.order-items-discount',
|
|
47
|
-
version: '1.0',
|
|
48
|
-
label: 'Apply Discounts on Total Value Of Goods',
|
|
49
|
-
orderIndex: 89,
|
|
50
|
-
|
|
51
|
-
isActivatedFor: () => {
|
|
52
|
-
return true;
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
actions: (params) => {
|
|
56
|
-
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
57
|
-
const { order, orderPositions, modules } = params.context;
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
...pricingAdapter,
|
|
61
|
-
|
|
62
|
-
calculate: async () => {
|
|
63
|
-
// discounts need to provide a *fixedRate*
|
|
64
|
-
// if you want to add percentual discounts,
|
|
65
|
-
// add it to the order item calculation
|
|
66
|
-
|
|
67
|
-
const totalAmountOfItems = params.calculationSheet.sum({
|
|
68
|
-
category: OrderPricingRowCategory.Items,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const itemShares = orderPositions.map((orderPosition) =>
|
|
72
|
-
resolveRatioAndTaxDivisorForPricingSheet(
|
|
73
|
-
modules.orders.positions.pricingSheet(orderPosition, order.currency, params.context),
|
|
74
|
-
totalAmountOfItems,
|
|
75
|
-
),
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
let alreadyDeducted = 0;
|
|
79
|
-
|
|
80
|
-
params.discounts.forEach(({ configuration, discountId }) => {
|
|
81
|
-
// First, we deduce the discount from the items
|
|
82
|
-
const [itemsDiscountAmount, itemsTaxAmount] = applyDiscountToMultipleShares(
|
|
83
|
-
itemShares,
|
|
84
|
-
calculateAmountToSplit({ ...configuration, alreadyDeducted }, totalAmountOfItems),
|
|
85
|
-
);
|
|
86
|
-
alreadyDeducted = +itemsDiscountAmount;
|
|
87
|
-
|
|
88
|
-
const discountAmount = itemsDiscountAmount;
|
|
89
|
-
const taxAmount = itemsTaxAmount;
|
|
90
|
-
if (discountAmount) {
|
|
91
|
-
pricingAdapter.resultSheet().addDiscount({
|
|
92
|
-
amount: discountAmount * -1,
|
|
93
|
-
discountId,
|
|
94
|
-
meta: {
|
|
95
|
-
adapter: OrderItemsDiscount.key,
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
if (taxAmount !== 0) {
|
|
99
|
-
pricingAdapter.resultSheet().addTax({
|
|
100
|
-
amount: taxAmount * -1,
|
|
101
|
-
meta: {
|
|
102
|
-
discountId,
|
|
103
|
-
adapter: OrderItemsDiscount.key,
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return pricingAdapter.calculate();
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
OrderPricingDirector.registerAdapter(OrderItemsDiscount);
|
package/plugins/order-items.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { IOrderPricingAdapter } from '@unchainedshop/types/orders.pricing';
|
|
2
|
-
import { OrderPricingDirector, OrderPricingAdapter } from 'meteor/unchained:core-orders';
|
|
3
|
-
|
|
4
|
-
const OrderItems: IOrderPricingAdapter = {
|
|
5
|
-
...OrderPricingAdapter,
|
|
6
|
-
|
|
7
|
-
key: 'shop.unchained.pricing.order-items',
|
|
8
|
-
version: '1.0',
|
|
9
|
-
label: 'Add Total Value Of Goods to Order',
|
|
10
|
-
orderIndex: 0,
|
|
11
|
-
|
|
12
|
-
isActivatedFor: () => {
|
|
13
|
-
return true;
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
actions: (params) => {
|
|
17
|
-
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
18
|
-
const { order, orderPositions, modules } = params.context;
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
...pricingAdapter,
|
|
22
|
-
|
|
23
|
-
calculate: async () => {
|
|
24
|
-
// just sum up all products items prices, taxes & fees
|
|
25
|
-
const totalAndTaxesOfAllItems = orderPositions.reduce(
|
|
26
|
-
(current, orderPosition) => {
|
|
27
|
-
const pricing = modules.orders.positions.pricingSheet(
|
|
28
|
-
orderPosition,
|
|
29
|
-
order.currency,
|
|
30
|
-
params.context,
|
|
31
|
-
);
|
|
32
|
-
const tax = pricing.taxSum();
|
|
33
|
-
const items = pricing.gross();
|
|
34
|
-
return {
|
|
35
|
-
taxes: current.taxes + tax,
|
|
36
|
-
items: current.items + items,
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
taxes: 0,
|
|
41
|
-
items: 0,
|
|
42
|
-
},
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
pricingAdapter.resultSheet().addItems({
|
|
46
|
-
amount: totalAndTaxesOfAllItems.items,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (totalAndTaxesOfAllItems.taxes !== 0) {
|
|
50
|
-
pricingAdapter.resultSheet().addTax({
|
|
51
|
-
amount: totalAndTaxesOfAllItems.taxes,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return pricingAdapter.calculate();
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
OrderPricingDirector.registerAdapter(OrderItems);
|
package/plugins/order-payment.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { IOrderPricingAdapter } from '@unchainedshop/types/orders.pricing';
|
|
2
|
-
import { OrderPricingDirector, OrderPricingAdapter } from 'meteor/unchained:core-orders';
|
|
3
|
-
|
|
4
|
-
const OrderPayment: IOrderPricingAdapter = {
|
|
5
|
-
...OrderPricingAdapter,
|
|
6
|
-
|
|
7
|
-
key: 'shop.unchained.pricing.order-payment',
|
|
8
|
-
version: '1.0',
|
|
9
|
-
label: 'Add Payment Fees to Order',
|
|
10
|
-
orderIndex: 20,
|
|
11
|
-
|
|
12
|
-
isActivatedFor: () => {
|
|
13
|
-
return true;
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
actions: (params) => {
|
|
17
|
-
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
18
|
-
const { order, orderPayment, modules } = params.context;
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
...pricingAdapter,
|
|
22
|
-
|
|
23
|
-
calculate: async () => {
|
|
24
|
-
// just add tax + net price to order pricing
|
|
25
|
-
if (!orderPayment) return null;
|
|
26
|
-
|
|
27
|
-
const pricing = modules.orders.payments.pricingSheet(
|
|
28
|
-
orderPayment,
|
|
29
|
-
order.currency,
|
|
30
|
-
params.context,
|
|
31
|
-
);
|
|
32
|
-
const tax = pricing.taxSum();
|
|
33
|
-
const paymentFees = pricing.gross();
|
|
34
|
-
|
|
35
|
-
pricingAdapter.resultSheet().addPayment({ amount: paymentFees });
|
|
36
|
-
if (tax !== 0) {
|
|
37
|
-
pricingAdapter.resultSheet().addTax({ amount: tax });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return pricingAdapter.calculate();
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
OrderPricingDirector.registerAdapter(OrderPayment);
|