@unchainedshop/plugins 4.6.1 → 4.6.2
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/delivery/post/adapter.d.ts +2 -0
- package/lib/delivery/post/adapter.js +22 -0
- package/lib/delivery/post/index.d.ts +4 -0
- package/lib/delivery/post/index.js +10 -0
- package/lib/delivery/send-message/adapter.d.ts +2 -0
- package/lib/delivery/send-message/adapter.js +39 -0
- package/lib/delivery/send-message/index.d.ts +4 -0
- package/lib/delivery/send-message/index.js +10 -0
- package/lib/delivery/stores/adapter.d.ts +2 -0
- package/lib/delivery/stores/adapter.js +42 -0
- package/lib/delivery/stores/index.d.ts +4 -0
- package/lib/delivery/stores/index.js +10 -0
- package/lib/enrollments/licensed/adapter.d.ts +6 -0
- package/lib/enrollments/licensed/adapter.js +51 -0
- package/lib/enrollments/licensed/index.d.ts +4 -0
- package/lib/enrollments/licensed/index.js +10 -0
- package/lib/files/gridfs/api.d.ts +7 -0
- package/lib/files/gridfs/api.js +163 -0
- package/lib/files/minio/adapter.d.ts +4 -0
- package/lib/files/minio/adapter.js +160 -0
- package/lib/files/minio/api.d.ts +2 -0
- package/lib/files/minio/api.js +41 -0
- package/lib/files/temp-upload/api.d.ts +6 -0
- package/lib/files/temp-upload/api.js +49 -0
- package/lib/files/temp-upload/index.d.ts +3 -0
- package/lib/files/temp-upload/index.js +15 -0
- package/lib/filters/local-search/adapter.d.ts +2 -0
- package/lib/filters/local-search/adapter.js +56 -0
- package/lib/filters/local-search/index.d.ts +4 -0
- package/lib/filters/local-search/index.js +16 -0
- package/lib/filters/strict-equal/adapter.d.ts +2 -0
- package/lib/filters/strict-equal/adapter.js +23 -0
- package/lib/filters/strict-equal/index.d.ts +4 -0
- package/lib/filters/strict-equal/index.js +10 -0
- package/lib/payment/apple-iap/api.d.ts +2 -0
- package/lib/payment/apple-iap/api.js +119 -0
- package/lib/payment/cryptopay/adapter.d.ts +2 -0
- package/lib/payment/cryptopay/adapter.js +157 -0
- package/lib/payment/cryptopay/api.d.ts +2 -0
- package/lib/payment/cryptopay/api.js +23 -0
- package/lib/payment/datatrans-v2/adapter.d.ts +2 -0
- package/lib/payment/datatrans-v2/adapter.js +406 -0
- package/lib/payment/datatrans-v2/api.d.ts +2 -0
- package/lib/payment/datatrans-v2/api.js +108 -0
- package/lib/payment/invoice/adapter.d.ts +2 -0
- package/lib/payment/invoice/adapter.js +26 -0
- package/lib/payment/invoice/index.d.ts +4 -0
- package/lib/payment/invoice/index.js +10 -0
- package/lib/payment/invoice-prepaid/adapter.d.ts +2 -0
- package/lib/payment/invoice-prepaid/adapter.js +29 -0
- package/lib/payment/invoice-prepaid/index.d.ts +4 -0
- package/lib/payment/invoice-prepaid/index.js +10 -0
- package/lib/payment/payrexx/adapter.d.ts +2 -0
- package/lib/payment/payrexx/adapter.js +161 -0
- package/lib/payment/payrexx/api.d.ts +2 -0
- package/lib/payment/payrexx/api.js +97 -0
- package/lib/payment/postfinance-checkout/adapter.d.ts +2 -0
- package/lib/payment/postfinance-checkout/adapter.js +189 -0
- package/lib/payment/postfinance-checkout/webhook.d.ts +2 -0
- package/lib/payment/postfinance-checkout/webhook.js +48 -0
- package/lib/payment/saferpay/webhook.d.ts +2 -0
- package/lib/payment/saferpay/webhook.js +64 -0
- package/lib/payment/stripe/adapter.d.ts +2 -0
- package/lib/payment/stripe/adapter.js +121 -0
- package/lib/payment/stripe/api.d.ts +6 -0
- package/lib/payment/stripe/api.js +165 -0
- package/lib/pricing/delivery-swiss-tax/adapter.d.ts +3 -0
- package/lib/pricing/delivery-swiss-tax/adapter.js +62 -0
- package/lib/pricing/delivery-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-swiss-tax/index.js +10 -0
- package/lib/pricing/discount-100-off/adapter.d.ts +3 -0
- package/lib/pricing/discount-100-off/adapter.js +30 -0
- package/lib/pricing/discount-100-off/index.d.ts +4 -0
- package/lib/pricing/discount-100-off/index.js +10 -0
- package/lib/pricing/discount-half-price-manual/adapter.d.ts +3 -0
- package/lib/pricing/discount-half-price-manual/adapter.js +30 -0
- package/lib/pricing/discount-half-price-manual/index.d.ts +4 -0
- package/lib/pricing/discount-half-price-manual/index.js +10 -0
- package/lib/pricing/free-delivery/adapter.d.ts +3 -0
- package/lib/pricing/free-delivery/adapter.js +27 -0
- package/lib/pricing/free-delivery/index.d.ts +4 -0
- package/lib/pricing/free-delivery/index.js +10 -0
- package/lib/pricing/free-payment/adapter.d.ts +3 -0
- package/lib/pricing/free-payment/adapter.js +27 -0
- package/lib/pricing/free-payment/index.d.ts +4 -0
- package/lib/pricing/free-payment/index.js +10 -0
- package/lib/pricing/order-delivery/adapter.d.ts +3 -0
- package/lib/pricing/order-delivery/adapter.js +33 -0
- package/lib/pricing/order-delivery/index.d.ts +4 -0
- package/lib/pricing/order-delivery/index.js +10 -0
- package/lib/pricing/order-discount/adapter.d.ts +3 -0
- package/lib/pricing/order-discount/adapter.js +74 -0
- package/lib/pricing/order-discount/index.d.ts +4 -0
- package/lib/pricing/order-discount/index.js +10 -0
- package/lib/pricing/order-items/adapter.d.ts +3 -0
- package/lib/pricing/order-items/adapter.js +43 -0
- package/lib/pricing/order-items/index.d.ts +4 -0
- package/lib/pricing/order-items/index.js +10 -0
- package/lib/pricing/order-payment/adapter.d.ts +3 -0
- package/lib/pricing/order-payment/adapter.js +33 -0
- package/lib/pricing/order-payment/index.d.ts +4 -0
- package/lib/pricing/order-payment/index.js +10 -0
- package/lib/pricing/product-catalog-price/adapter.d.ts +3 -0
- package/lib/pricing/product-catalog-price/adapter.js +60 -0
- package/lib/pricing/product-catalog-price/index.d.ts +4 -0
- package/lib/pricing/product-catalog-price/index.js +10 -0
- package/lib/pricing/product-discount/adapter.d.ts +3 -0
- package/lib/pricing/product-discount/adapter.js +69 -0
- package/lib/pricing/product-discount/index.d.ts +4 -0
- package/lib/pricing/product-discount/index.js +10 -0
- package/lib/pricing/product-price-rateconversion/adapter.d.ts +3 -0
- package/lib/pricing/product-price-rateconversion/adapter.js +53 -0
- package/lib/pricing/product-price-rateconversion/index.d.ts +4 -0
- package/lib/pricing/product-price-rateconversion/index.js +10 -0
- package/lib/pricing/product-swiss-tax/adapter.d.ts +3 -0
- package/lib/pricing/product-swiss-tax/adapter.js +76 -0
- package/lib/pricing/product-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/product-swiss-tax/index.js +10 -0
- package/lib/quotations/manual/adapter.d.ts +2 -0
- package/lib/quotations/manual/adapter.js +19 -0
- package/lib/quotations/manual/index.d.ts +4 -0
- package/lib/quotations/manual/index.js +10 -0
- package/lib/warehousing/erc-metadata/api.d.ts +12 -0
- package/lib/warehousing/erc-metadata/api.js +43 -0
- package/lib/warehousing/erc-metadata/index.d.ts +3 -0
- package/lib/warehousing/erc-metadata/index.js +15 -0
- package/lib/warehousing/eth-minter/adapter.d.ts +2 -0
- package/lib/warehousing/eth-minter/adapter.js +119 -0
- package/lib/warehousing/eth-minter/index.d.ts +4 -0
- package/lib/warehousing/eth-minter/index.js +10 -0
- package/lib/warehousing/store/adapter.d.ts +2 -0
- package/lib/warehousing/store/adapter.js +33 -0
- package/lib/warehousing/store/index.d.ts +4 -0
- package/lib/warehousing/store/index.js +10 -0
- package/lib/worker/budgetsms/adapter.d.ts +22 -0
- package/lib/worker/budgetsms/adapter.js +169 -0
- package/lib/worker/budgetsms/index.d.ts +4 -0
- package/lib/worker/budgetsms/index.js +10 -0
- package/lib/worker/bulk-export/adapter.d.ts +3 -0
- package/lib/worker/bulk-export/adapter.js +64 -0
- package/lib/worker/bulk-export/index.d.ts +4 -0
- package/lib/worker/bulk-export/index.js +10 -0
- package/lib/worker/bulk-import/adapter.d.ts +3 -0
- package/lib/worker/bulk-import/adapter.js +65 -0
- package/lib/worker/bulk-import/api.d.ts +7 -0
- package/lib/worker/bulk-import/api.js +53 -0
- package/lib/worker/bulk-import/index.d.ts +4 -0
- package/lib/worker/bulk-import/index.js +18 -0
- package/lib/worker/bulkgate/adapter.d.ts +12 -0
- package/lib/worker/bulkgate/adapter.js +91 -0
- package/lib/worker/bulkgate/index.d.ts +4 -0
- package/lib/worker/bulkgate/index.js +10 -0
- package/lib/worker/email/adapter.d.ts +9 -0
- package/lib/worker/email/adapter.js +150 -0
- package/lib/worker/email/index.d.ts +4 -0
- package/lib/worker/email/index.js +10 -0
- package/lib/worker/enrollment-order-generator/adapter.d.ts +4 -0
- package/lib/worker/enrollment-order-generator/adapter.js +77 -0
- package/lib/worker/enrollment-order-generator/index.d.ts +4 -0
- package/lib/worker/enrollment-order-generator/index.js +13 -0
- package/lib/worker/error-notifications/adapter.d.ts +10 -0
- package/lib/worker/error-notifications/adapter.js +62 -0
- package/lib/worker/error-notifications/index.d.ts +4 -0
- package/lib/worker/error-notifications/index.js +13 -0
- package/lib/worker/export-token/adapter.d.ts +4 -0
- package/lib/worker/export-token/adapter.js +25 -0
- package/lib/worker/export-token/index.d.ts +4 -0
- package/lib/worker/export-token/index.js +13 -0
- package/lib/worker/external/adapter.d.ts +3 -0
- package/lib/worker/external/adapter.js +13 -0
- package/lib/worker/external/index.d.ts +4 -0
- package/lib/worker/external/index.js +10 -0
- package/lib/worker/heartbeat/adapter.d.ts +8 -0
- package/lib/worker/heartbeat/adapter.js +26 -0
- package/lib/worker/heartbeat/index.d.ts +4 -0
- package/lib/worker/heartbeat/index.js +10 -0
- package/lib/worker/http-request/adapter.d.ts +8 -0
- package/lib/worker/http-request/adapter.js +55 -0
- package/lib/worker/http-request/index.d.ts +4 -0
- package/lib/worker/http-request/index.js +10 -0
- package/lib/worker/message/adapter.d.ts +11 -0
- package/lib/worker/message/adapter.js +42 -0
- package/lib/worker/message/index.d.ts +4 -0
- package/lib/worker/message/index.js +10 -0
- package/lib/worker/push-notification/adapter.d.ts +9 -0
- package/lib/worker/push-notification/adapter.js +87 -0
- package/lib/worker/push-notification/index.d.ts +4 -0
- package/lib/worker/push-notification/index.js +10 -0
- package/lib/worker/twilio/adapter.d.ts +8 -0
- package/lib/worker/twilio/adapter.js +59 -0
- package/lib/worker/twilio/index.d.ts +4 -0
- package/lib/worker/twilio/index.js +10 -0
- package/lib/worker/update-coinbase-rates/adapter.d.ts +4 -0
- package/lib/worker/update-coinbase-rates/adapter.js +61 -0
- package/lib/worker/update-coinbase-rates/index.d.ts +4 -0
- package/lib/worker/update-coinbase-rates/index.js +13 -0
- package/lib/worker/update-ecb-rates/adapter.d.ts +4 -0
- package/lib/worker/update-ecb-rates/adapter.js +94 -0
- package/lib/worker/update-ecb-rates/index.d.ts +4 -0
- package/lib/worker/update-ecb-rates/index.js +13 -0
- package/lib/worker/update-token-ownership/adapter.d.ts +5 -0
- package/lib/worker/update-token-ownership/adapter.js +58 -0
- package/lib/worker/update-token-ownership/index.d.ts +4 -0
- package/lib/worker/update-token-ownership/index.js +13 -0
- package/lib/worker/zombie-killer/adapter.d.ts +13 -0
- package/lib/worker/zombie-killer/adapter.js +90 -0
- package/lib/worker/zombie-killer/index.d.ts +4 -0
- package/lib/worker/zombie-killer/index.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { OrderPricingRowCategory, OrderPricingAdapter, DeliveryPricingSheet, PaymentPricingSheet, ProductPricingSheet, resolveRatioAndTaxDivisorForPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
3
|
+
export const OrderDiscount = {
|
|
4
|
+
...OrderPricingAdapter,
|
|
5
|
+
key: 'shop.unchained.pricing.order-discount',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
label: 'Apply Discounts on Total Order Value',
|
|
8
|
+
orderIndex: 40,
|
|
9
|
+
isActivatedFor: () => {
|
|
10
|
+
return true;
|
|
11
|
+
},
|
|
12
|
+
actions: (params) => {
|
|
13
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
14
|
+
const { order, orderDelivery, orderPositions, orderPayment } = params.context;
|
|
15
|
+
return {
|
|
16
|
+
...pricingAdapter,
|
|
17
|
+
calculate: async () => {
|
|
18
|
+
if (!order)
|
|
19
|
+
return pricingAdapter.calculate();
|
|
20
|
+
const totalAmountOfItems = params.calculationSheet.total({
|
|
21
|
+
category: OrderPricingRowCategory.Items,
|
|
22
|
+
useNetPrice: false,
|
|
23
|
+
}).amount;
|
|
24
|
+
const totalAmountOfPaymentAndDelivery = params.calculationSheet.total({
|
|
25
|
+
category: OrderPricingRowCategory.Payment,
|
|
26
|
+
useNetPrice: false,
|
|
27
|
+
}).amount +
|
|
28
|
+
params.calculationSheet.total({
|
|
29
|
+
category: OrderPricingRowCategory.Delivery,
|
|
30
|
+
useNetPrice: false,
|
|
31
|
+
}).amount;
|
|
32
|
+
const itemShares = orderPositions.map((orderPosition) => resolveRatioAndTaxDivisorForPricingSheet(ProductPricingSheet({
|
|
33
|
+
calculation: orderPosition.calculation,
|
|
34
|
+
currencyCode: order.currencyCode,
|
|
35
|
+
quantity: orderPosition.quantity,
|
|
36
|
+
}), totalAmountOfItems));
|
|
37
|
+
const deliveryShare = resolveRatioAndTaxDivisorForPricingSheet(DeliveryPricingSheet({
|
|
38
|
+
calculation: orderDelivery?.calculation || [],
|
|
39
|
+
currencyCode: order.currencyCode,
|
|
40
|
+
}), totalAmountOfPaymentAndDelivery);
|
|
41
|
+
const paymentShare = resolveRatioAndTaxDivisorForPricingSheet(PaymentPricingSheet({
|
|
42
|
+
calculation: orderPayment?.calculation || [],
|
|
43
|
+
currencyCode: order.currencyCode,
|
|
44
|
+
}), totalAmountOfPaymentAndDelivery);
|
|
45
|
+
let amountLeft = totalAmountOfPaymentAndDelivery + totalAmountOfItems;
|
|
46
|
+
params.discounts.forEach(({ configuration, discountId }) => {
|
|
47
|
+
const leftInDiscountToSplit = calcUtils.calculateAmountToSplit({ ...configuration }, Math.min(totalAmountOfItems, amountLeft));
|
|
48
|
+
const [itemsDiscountAmount, itemsTaxAmount] = calcUtils.applyDiscountToMultipleShares(itemShares, Math.max(0, Math.min(amountLeft, leftInDiscountToSplit)));
|
|
49
|
+
amountLeft -= itemsDiscountAmount;
|
|
50
|
+
const fixedRate = Number(configuration.fixedRate) > 0
|
|
51
|
+
? Math.max(0, configuration.fixedRate - itemsDiscountAmount)
|
|
52
|
+
: undefined;
|
|
53
|
+
const leftInFeesToSplit = calcUtils.calculateAmountToSplit({ ...configuration, fixedRate }, Math.min(totalAmountOfPaymentAndDelivery, amountLeft));
|
|
54
|
+
const [deliveryAndPaymentDiscountAmount, deliveryAndPaymentTaxAmount] = calcUtils.applyDiscountToMultipleShares([deliveryShare, paymentShare], Math.max(0, Math.min(amountLeft, leftInFeesToSplit)));
|
|
55
|
+
amountLeft -= deliveryAndPaymentDiscountAmount;
|
|
56
|
+
const discountAmount = (itemsDiscountAmount + deliveryAndPaymentDiscountAmount) * -1;
|
|
57
|
+
const taxAmount = (itemsTaxAmount + deliveryAndPaymentTaxAmount) * -1;
|
|
58
|
+
if (discountAmount) {
|
|
59
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
60
|
+
amount: discountAmount,
|
|
61
|
+
taxAmount,
|
|
62
|
+
discountId,
|
|
63
|
+
meta: {
|
|
64
|
+
adapter: OrderDiscount.key,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return pricingAdapter.calculate();
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
export default OrderDiscount;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { OrderDiscount } from "./adapter.js";
|
|
3
|
+
export const OrderDiscountPlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.order-discount',
|
|
5
|
+
label: 'Order Discount Pricing Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [OrderDiscount],
|
|
8
|
+
};
|
|
9
|
+
export default OrderDiscountPlugin;
|
|
10
|
+
export { OrderDiscount } from "./adapter.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { OrderPricingAdapter, ProductPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
export const OrderItems = {
|
|
3
|
+
...OrderPricingAdapter,
|
|
4
|
+
key: 'shop.unchained.pricing.order-items',
|
|
5
|
+
version: '1.0.0',
|
|
6
|
+
label: 'Add Total Value Of Goods to Order',
|
|
7
|
+
orderIndex: 0,
|
|
8
|
+
isActivatedFor: () => {
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
11
|
+
actions: (params) => {
|
|
12
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
13
|
+
const { order, orderPositions } = params.context;
|
|
14
|
+
return {
|
|
15
|
+
...pricingAdapter,
|
|
16
|
+
calculate: async () => {
|
|
17
|
+
const totalAndTaxesOfAllItems = orderPositions.reduce((current, orderPosition) => {
|
|
18
|
+
const pricing = ProductPricingSheet({
|
|
19
|
+
calculation: orderPosition.calculation,
|
|
20
|
+
currencyCode: order.currencyCode,
|
|
21
|
+
quantity: orderPosition.quantity,
|
|
22
|
+
});
|
|
23
|
+
const tax = pricing.taxSum();
|
|
24
|
+
const items = pricing.gross();
|
|
25
|
+
return {
|
|
26
|
+
taxes: current.taxes + tax,
|
|
27
|
+
items: current.items + items,
|
|
28
|
+
};
|
|
29
|
+
}, {
|
|
30
|
+
taxes: 0,
|
|
31
|
+
items: 0,
|
|
32
|
+
});
|
|
33
|
+
pricingAdapter.resultSheet().addItems({
|
|
34
|
+
amount: totalAndTaxesOfAllItems.items,
|
|
35
|
+
taxAmount: totalAndTaxesOfAllItems.taxes,
|
|
36
|
+
meta: { adapter: OrderItems.key },
|
|
37
|
+
});
|
|
38
|
+
return pricingAdapter.calculate();
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export default OrderItems;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { OrderItems } from "./adapter.js";
|
|
3
|
+
export const OrderItemsPlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.order-items',
|
|
5
|
+
label: 'Order Items Pricing Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [OrderItems],
|
|
8
|
+
};
|
|
9
|
+
export default OrderItemsPlugin;
|
|
10
|
+
export { OrderItems } from "./adapter.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OrderPricingAdapter, PaymentPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
export const OrderPayment = {
|
|
3
|
+
...OrderPricingAdapter,
|
|
4
|
+
key: 'shop.unchained.pricing.order-payment',
|
|
5
|
+
version: '1.0.0',
|
|
6
|
+
label: 'Add Payment Fees to Order',
|
|
7
|
+
orderIndex: 10,
|
|
8
|
+
isActivatedFor: () => {
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
11
|
+
actions: (params) => {
|
|
12
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
13
|
+
const { order, orderPayment } = params.context;
|
|
14
|
+
return {
|
|
15
|
+
...pricingAdapter,
|
|
16
|
+
calculate: async () => {
|
|
17
|
+
if (!orderPayment)
|
|
18
|
+
return null;
|
|
19
|
+
const pricing = PaymentPricingSheet({
|
|
20
|
+
calculation: orderPayment.calculation,
|
|
21
|
+
currencyCode: order.currencyCode,
|
|
22
|
+
});
|
|
23
|
+
const tax = pricing.taxSum();
|
|
24
|
+
const paymentFees = pricing.gross();
|
|
25
|
+
pricingAdapter
|
|
26
|
+
.resultSheet()
|
|
27
|
+
.addPayment({ amount: paymentFees, taxAmount: tax, meta: { adapter: OrderPayment.key } });
|
|
28
|
+
return pricingAdapter.calculate();
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export default OrderPayment;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { OrderPayment } from "./adapter.js";
|
|
3
|
+
export const OrderPaymentPlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.order-payment',
|
|
5
|
+
label: 'Order Payment Pricing Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [OrderPayment],
|
|
8
|
+
};
|
|
9
|
+
export default OrderPaymentPlugin;
|
|
10
|
+
export { OrderPayment } from "./adapter.js";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ProductPricingAdapter } from '@unchainedshop/core';
|
|
2
|
+
import { ProductType } from '@unchainedshop/core-products';
|
|
3
|
+
export const ProductPrice = {
|
|
4
|
+
...ProductPricingAdapter,
|
|
5
|
+
key: 'shop.unchained.pricing.product-price',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
label: 'Add Gross Price to Product',
|
|
8
|
+
orderIndex: 0,
|
|
9
|
+
isActivatedFor: () => {
|
|
10
|
+
return true;
|
|
11
|
+
},
|
|
12
|
+
actions: (params) => {
|
|
13
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
14
|
+
return {
|
|
15
|
+
...pricingAdapter,
|
|
16
|
+
calculate: async () => {
|
|
17
|
+
const { product, countryCode, currencyCode, quantity, modules } = params.context;
|
|
18
|
+
const price = await modules.products.prices.price(product, {
|
|
19
|
+
countryCode,
|
|
20
|
+
currencyCode,
|
|
21
|
+
quantity,
|
|
22
|
+
});
|
|
23
|
+
if (price) {
|
|
24
|
+
const itemTotal = price.amount * quantity;
|
|
25
|
+
pricingAdapter.resultSheet().addItem({
|
|
26
|
+
amount: itemTotal,
|
|
27
|
+
isTaxable: Boolean(price.isTaxable),
|
|
28
|
+
isNetPrice: Boolean(price.isNetPrice),
|
|
29
|
+
meta: { adapter: ProductPrice.key },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (product.type === ProductType.BUNDLE_PRODUCT) {
|
|
33
|
+
for (const bundleItem of product.bundleItems || []) {
|
|
34
|
+
const bundledProduct = await modules.products.findProduct({
|
|
35
|
+
productId: bundleItem.productId,
|
|
36
|
+
});
|
|
37
|
+
if (bundledProduct) {
|
|
38
|
+
const bundleItemPrice = await modules.products.prices.price(bundledProduct, {
|
|
39
|
+
countryCode,
|
|
40
|
+
currencyCode,
|
|
41
|
+
quantity: bundleItem.quantity * quantity,
|
|
42
|
+
});
|
|
43
|
+
if (bundleItemPrice) {
|
|
44
|
+
const bundleItemTotal = bundleItemPrice.amount * bundleItem.quantity * quantity;
|
|
45
|
+
pricingAdapter.resultSheet().addItem({
|
|
46
|
+
amount: bundleItemTotal,
|
|
47
|
+
isTaxable: Boolean(bundleItemPrice.isTaxable),
|
|
48
|
+
isNetPrice: Boolean(bundleItemPrice.isNetPrice),
|
|
49
|
+
meta: { adapter: ProductPrice.key },
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return pricingAdapter.calculate();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
export default ProductPrice;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { ProductPrice } from "./adapter.js";
|
|
3
|
+
export const ProductPricePlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.product-catalog',
|
|
5
|
+
label: 'Product Catalog Price Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [ProductPrice],
|
|
8
|
+
};
|
|
9
|
+
export default ProductPricePlugin;
|
|
10
|
+
export { ProductPrice } from "./adapter.js";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
2
|
+
import { ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
|
|
3
|
+
export const ProductDiscount = {
|
|
4
|
+
...ProductPricingAdapter,
|
|
5
|
+
key: 'shop.unchained.pricing.product-discount',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
label: 'Apply Discounts on Product Price',
|
|
8
|
+
orderIndex: 30,
|
|
9
|
+
isActivatedFor: () => {
|
|
10
|
+
return true;
|
|
11
|
+
},
|
|
12
|
+
actions: (params) => {
|
|
13
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
14
|
+
const addDiscounts = (discount, total, resolvedConfiguration) => {
|
|
15
|
+
const { discountId } = discount;
|
|
16
|
+
const { isNetPrice = false, taxRate, ...meta } = resolvedConfiguration;
|
|
17
|
+
const amount = calcUtils.applyRate(resolvedConfiguration, total);
|
|
18
|
+
const isTaxable = taxRate === undefined || taxRate === null;
|
|
19
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
20
|
+
amount: amount * -1,
|
|
21
|
+
discountId,
|
|
22
|
+
isNetPrice,
|
|
23
|
+
isTaxable,
|
|
24
|
+
meta: { adapter: ProductDiscount.key, ...meta },
|
|
25
|
+
});
|
|
26
|
+
if (!isTaxable && taxRate) {
|
|
27
|
+
const taxAmount = calcUtils.getTaxAmount(amount, taxRate, isNetPrice);
|
|
28
|
+
pricingAdapter.resultSheet().addTax({
|
|
29
|
+
amount: taxAmount * -1,
|
|
30
|
+
rate: taxRate,
|
|
31
|
+
discountId,
|
|
32
|
+
baseCategory: ProductPricingRowCategory.Discount,
|
|
33
|
+
meta: { adapter: ProductDiscount.key, discountId, ...meta },
|
|
34
|
+
});
|
|
35
|
+
if (!isNetPrice) {
|
|
36
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
37
|
+
amount: taxAmount,
|
|
38
|
+
discountId,
|
|
39
|
+
isNetPrice: false,
|
|
40
|
+
isTaxable: false,
|
|
41
|
+
meta: { adapter: ProductDiscount.key, discountId, ...meta },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
...pricingAdapter,
|
|
48
|
+
calculate: async () => {
|
|
49
|
+
params.discounts.forEach((discount) => {
|
|
50
|
+
if (!discount)
|
|
51
|
+
return;
|
|
52
|
+
const { configuration } = discount;
|
|
53
|
+
const resolvedConfiguration = configuration.customPriceConfigurationResolver
|
|
54
|
+
? configuration.customPriceConfigurationResolver(params.context.product, params.context.quantity, params.context.configuration)
|
|
55
|
+
: configuration;
|
|
56
|
+
if (!resolvedConfiguration)
|
|
57
|
+
return;
|
|
58
|
+
const total = params.calculationSheet.total({
|
|
59
|
+
category: ProductPricingRowCategory.Item,
|
|
60
|
+
useNetPrice: resolvedConfiguration.isNetPrice,
|
|
61
|
+
});
|
|
62
|
+
addDiscounts(discount, total.amount, resolvedConfiguration);
|
|
63
|
+
});
|
|
64
|
+
return pricingAdapter.calculate();
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
export default ProductDiscount;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { ProductDiscount } from "./adapter.js";
|
|
3
|
+
export const ProductDiscountPlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.product-discount',
|
|
5
|
+
label: 'Product Discount Pricing Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [ProductDiscount],
|
|
8
|
+
};
|
|
9
|
+
export default ProductDiscountPlugin;
|
|
10
|
+
export { ProductDiscount } from "./adapter.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ProductPricingAdapter } from '@unchainedshop/core';
|
|
2
|
+
export const ProductPriceRateConversion = {
|
|
3
|
+
...ProductPricingAdapter,
|
|
4
|
+
key: 'shop.unchained.pricing.rate-conversion',
|
|
5
|
+
version: '1.0.0',
|
|
6
|
+
label: 'Generic rate conversion plugin that converts between rates if entry in DB exists.',
|
|
7
|
+
orderIndex: 10,
|
|
8
|
+
isActivatedFor: () => {
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
11
|
+
actions: (params) => {
|
|
12
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
13
|
+
const { modules } = params.context;
|
|
14
|
+
return {
|
|
15
|
+
...pricingAdapter,
|
|
16
|
+
calculate: async () => {
|
|
17
|
+
const { product, countryCode, quantity, currencyCode: targetCurrency } = params.context;
|
|
18
|
+
const { calculation = [] } = params.calculationSheet;
|
|
19
|
+
if (calculation?.length) {
|
|
20
|
+
return pricingAdapter.calculate();
|
|
21
|
+
}
|
|
22
|
+
const productPrice = await modules.products.prices.price(product, {
|
|
23
|
+
countryCode,
|
|
24
|
+
quantity,
|
|
25
|
+
});
|
|
26
|
+
if (!productPrice) {
|
|
27
|
+
return pricingAdapter.calculate();
|
|
28
|
+
}
|
|
29
|
+
const fromCurrencyObj = await modules.currencies.findCurrency({
|
|
30
|
+
isoCode: productPrice.currencyCode,
|
|
31
|
+
});
|
|
32
|
+
const targetCurrencyObj = await modules.currencies.findCurrency({
|
|
33
|
+
isoCode: targetCurrency,
|
|
34
|
+
});
|
|
35
|
+
if (!targetCurrencyObj?.isActive || !fromCurrencyObj?.isActive)
|
|
36
|
+
return pricingAdapter.calculate();
|
|
37
|
+
const rateData = await modules.products.prices.rates.getRate(fromCurrencyObj, targetCurrencyObj);
|
|
38
|
+
if (rateData && rateData.rate > 0) {
|
|
39
|
+
const convertedAmount = Math.round(productPrice.amount * rateData.rate);
|
|
40
|
+
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
41
|
+
pricingAdapter.resultSheet().addItem({
|
|
42
|
+
amount: convertedAmount * quantity,
|
|
43
|
+
isTaxable: Boolean(productPrice?.isTaxable),
|
|
44
|
+
isNetPrice: Boolean(productPrice?.isNetPrice),
|
|
45
|
+
meta: { adapter: ProductPriceRateConversion.key, rate: rateData.rate },
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return pricingAdapter.calculate();
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
export default ProductPriceRateConversion;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { ProductPriceRateConversion } from "./adapter.js";
|
|
3
|
+
export const ProductPriceRateConversionPlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.rate-conversion',
|
|
5
|
+
label: 'Product Price Rate Conversion Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [ProductPriceRateConversion],
|
|
8
|
+
};
|
|
9
|
+
export default ProductPriceRateConversionPlugin;
|
|
10
|
+
export { ProductPriceRateConversion } from "./adapter.js";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
|
|
2
|
+
import { resolveTaxCategoryFromDeliveryProvider, resolveTaxCategoryFromProduct, SwissTaxCategories, } from "../tax/ch.js";
|
|
3
|
+
import isDeliveryAddressInCountry from "../utils/isDeliveryAddressInCountry.js";
|
|
4
|
+
export const ProductSwissTax = {
|
|
5
|
+
...ProductPricingAdapter,
|
|
6
|
+
key: 'shop.unchained.pricing.product-swiss-tax',
|
|
7
|
+
version: '1.0.0',
|
|
8
|
+
label: 'Apply Swiss Tax on Product',
|
|
9
|
+
orderIndex: 80,
|
|
10
|
+
isActivatedFor: () => {
|
|
11
|
+
return true;
|
|
12
|
+
},
|
|
13
|
+
actions: (params) => {
|
|
14
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
15
|
+
const { context } = params;
|
|
16
|
+
return {
|
|
17
|
+
...pricingAdapter,
|
|
18
|
+
calculate: async () => {
|
|
19
|
+
const orderDelivery = context.order?.deliveryId
|
|
20
|
+
? await context.modules.orders.deliveries.findDelivery({
|
|
21
|
+
orderDeliveryId: context.order?.deliveryId,
|
|
22
|
+
})
|
|
23
|
+
: null;
|
|
24
|
+
if (!isDeliveryAddressInCountry({
|
|
25
|
+
...context,
|
|
26
|
+
orderDelivery,
|
|
27
|
+
}, ['CH', 'LI'])) {
|
|
28
|
+
return pricingAdapter.calculate();
|
|
29
|
+
}
|
|
30
|
+
let taxCategory = resolveTaxCategoryFromProduct(context.product);
|
|
31
|
+
if (!taxCategory) {
|
|
32
|
+
const provider = orderDelivery?.deliveryProviderId
|
|
33
|
+
? await context.modules.delivery.findProvider({
|
|
34
|
+
deliveryProviderId: orderDelivery?.deliveryProviderId,
|
|
35
|
+
})
|
|
36
|
+
: null;
|
|
37
|
+
if (provider)
|
|
38
|
+
taxCategory = resolveTaxCategoryFromDeliveryProvider(provider);
|
|
39
|
+
}
|
|
40
|
+
if (!taxCategory)
|
|
41
|
+
taxCategory = SwissTaxCategories.DEFAULT;
|
|
42
|
+
const taxRate = taxCategory.rate(context.order?.ordered);
|
|
43
|
+
ProductPricingAdapter.log(`ProductSwissTax -> Tax Multiplicator: ${taxRate}`);
|
|
44
|
+
params.calculationSheet.filterBy({ isTaxable: true }).forEach(({ isNetPrice, ...row }) => {
|
|
45
|
+
if (!isNetPrice) {
|
|
46
|
+
const taxAmount = row.amount - row.amount / (1 + taxRate);
|
|
47
|
+
pricingAdapter.resultSheet().calculation.push({
|
|
48
|
+
...row,
|
|
49
|
+
amount: -taxAmount,
|
|
50
|
+
isTaxable: false,
|
|
51
|
+
isNetPrice: false,
|
|
52
|
+
meta: { adapter: ProductSwissTax.key },
|
|
53
|
+
});
|
|
54
|
+
pricingAdapter.resultSheet().addTax({
|
|
55
|
+
amount: taxAmount,
|
|
56
|
+
rate: taxRate,
|
|
57
|
+
baseCategory: ProductPricingRowCategory.Item,
|
|
58
|
+
meta: { adapter: ProductSwissTax.key },
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const taxAmount = row.amount * taxRate;
|
|
63
|
+
pricingAdapter.resultSheet().addTax({
|
|
64
|
+
amount: taxAmount,
|
|
65
|
+
rate: taxRate,
|
|
66
|
+
baseCategory: ProductPricingRowCategory.Item,
|
|
67
|
+
meta: { adapter: ProductSwissTax.key },
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return pricingAdapter.calculate();
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
export default ProductSwissTax;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { ProductSwissTax } from "./adapter.js";
|
|
3
|
+
export const ProductSwissTaxPlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.product-swiss-tax',
|
|
5
|
+
label: 'Product Swiss Tax Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [ProductSwissTax],
|
|
8
|
+
};
|
|
9
|
+
export default ProductSwissTaxPlugin;
|
|
10
|
+
export { ProductSwissTax } from "./adapter.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { QuotationAdapter } from '@unchainedshop/core';
|
|
2
|
+
export const ManualOffering = {
|
|
3
|
+
...QuotationAdapter,
|
|
4
|
+
key: 'shop.unchained.quotations.manual',
|
|
5
|
+
version: '1.0.0',
|
|
6
|
+
label: 'Manual Offerings',
|
|
7
|
+
orderIndex: 0,
|
|
8
|
+
isActivatedFor: () => true,
|
|
9
|
+
actions: (params) => {
|
|
10
|
+
return {
|
|
11
|
+
...QuotationAdapter.actions(params),
|
|
12
|
+
quote: async () => {
|
|
13
|
+
return {
|
|
14
|
+
expires: new Date(new Date().getTime() + 3600 * 1000),
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { ManualOffering } from "./adapter.js";
|
|
3
|
+
export const ManualOfferingPlugin = {
|
|
4
|
+
key: 'shop.unchained.quotations.manual',
|
|
5
|
+
label: 'Manual Offering Quotation Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [ManualOffering],
|
|
8
|
+
};
|
|
9
|
+
export default ManualOfferingPlugin;
|
|
10
|
+
export { ManualOffering } from "./adapter.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
+
export declare function ercMetadataHandler(request: Request, context: UnchainedCore & {
|
|
3
|
+
params: Record<string, string>;
|
|
4
|
+
locale?: Intl.Locale;
|
|
5
|
+
loaders?: {
|
|
6
|
+
productLoader: {
|
|
7
|
+
load: (params: {
|
|
8
|
+
productId: string;
|
|
9
|
+
}) => Promise<any>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}): Promise<Response>;
|