Skip to main content

Delivery Pricing

::: Add a delivery pricing plugin :::

Delivery pricing adapter is used to do the actual delivery cost calculation. The adapter is run for every single item included in an order. in order to add a custom delivery price logic for orders you need to implement IDeliveryPricingAdapter. There can be more than one delivery pricing plugin configurations and all of them will be executed based on their orderIndex value. Delivery pricing adapter with lower orderIndex will be executed first

below is an example of delivery price for the above delivery adapter that will charge $50 as a delivery fee for orders that use ShopPickUp (the above adapter) for their delivery provider.


import {
DeliveryPricingAdapter,
DeliveryPricingSheet,
IDeliveryPricingAdapter,
} from '@unchainedshop/core-delivery';

export const ShopDeliveryFreePrice: IDeliveryPricingAdapter = {
key: 'ch.shop.delivery.pickup-fee',
version: '1.0.0',
label: 'Pickup Fee',
orderIndex: 10,

isActivatedFor: ({ provider }) => {
return provider.adapterKey === 'ch.shop.delivery.pickupr';
},

actions: (
context,
calculationSheet,
discounts,
) => {
const calculation = [];
const { currency } = context;
const resultSheet = DeliveryPricingSheet({ currency });
return {
getCalculation: () => calculation,
getContext: () => context,
calculate: async () => {
resultSheet.addFee({
amount: 50,
isNetPrice: false,
isTaxable: true,
meta: { adapter: 'delivery-price-key' },
});
return resultSheet.calculate();
},
};
},
};


  • isActivatedFor: DeliveryPricingAdapterContext: defines to which delivery adapters this delivery price adapter calculations should take place.
  • getCalculation: Calculation[]: returns all the fees that will are included for calculation through the adapter.
  • getContext: DeliveryPricingAdapterContext: returns the pricing adapter context
  • calculate: Calculation[]: calculated the delivery price based on the logic provided and returns the calculation breakdown (result sheet)