@unchainedshop/plugins
Version:
Because of a Typescript issue with upstream "postfinancecheckout", the Postfinance plugin has been disabled from transpilation, import the source ts files from src and enable node_module tsc or copy over the src/payment/postfinance-checkout to your projec
51 lines (41 loc) • 1.43 kB
text/typescript
import {
OrderDiscountDirector,
OrderDiscountAdapter,
ProductDiscountConfiguration,
IDiscountAdapter,
} from '@unchainedshop/core';
export const HalfPrice: IDiscountAdapter<ProductDiscountConfiguration> = {
...OrderDiscountAdapter,
key: 'shop.unchained.discount.half-price',
label: 'Half Price',
version: '1.0.0',
orderIndex: 10,
// return true if a discount is allowed to get added manually by a user
isManualAdditionAllowed: async () => {
return false;
},
// return true if a discount is allowed to get removed manually by a user
isManualRemovalAllowed: async () => {
return false;
},
actions: async ({ context }) => ({
...(await OrderDiscountAdapter.actions({ context })),
isValidForSystemTriggering: async () => {
const { order } = context;
const user = await context.modules.users.findUserById(order.userId);
const isUserEligibleForHalfPrice = user?.tags && user.tags.indexOf('half-price') !== -1;
return !!isUserEligibleForHalfPrice;
},
isValidForCodeTriggering: async () => {
return false;
},
// returns the appropriate discount context for a calculation adapter
discountForPricingAdapterKey({ pricingAdapterKey }) {
if (pricingAdapterKey === 'shop.unchained.pricing.product-discount') {
return { rate: 0.5 };
}
return null;
},
}),
};
OrderDiscountDirector.registerAdapter(HalfPrice);