UNPKG

@unchainedshop/plugins

Version:

Official plugin collection for the Unchained Engine with payment, delivery, and pricing adapters

34 lines (33 loc) 1.21 kB
import { OrderDiscountDirector, OrderDiscountAdapter, } from '@unchainedshop/core'; export const HalfPrice = { ...OrderDiscountAdapter, key: 'shop.unchained.discount.half-price', label: 'Half Price', version: '1.0.0', orderIndex: 10, isManualAdditionAllowed: async () => { return false; }, 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; }, discountForPricingAdapterKey({ pricingAdapterKey }) { if (pricingAdapterKey === 'shop.unchained.pricing.product-discount') { return { rate: 0.5 }; } return null; }, }), }; OrderDiscountDirector.registerAdapter(HalfPrice);