-
Notifications
You must be signed in to change notification settings - Fork 53
Add New Shipping Method
When selecting shipping_methods while checkout, there would be a process spinned for each listed shipping_method to calculate applicable shipping_cost.
All the shipping_methods which are applicable & respond with in allowed wait time (timeout) will be consolidated, and would be presented in checkout shipping step.
-
Create a module, preferably with new name of Shipping Method, say
new_shipping_method
and adduse Nectar.ShippingCalculator.Base
for overridable behavior# web/calculators/shipping_calculator/new_shipping_method.ex defmodule Nectar.ShippingCalculator.NewShippingMethod do use Nectar.ShippingCalculator.Base # calculate_shipping/1, applicable?/1 # can also be re-defined def shipping_rate(_order) do # Add your shipping_method cost logic cost = some_complex_logic Decimal.new(cost) end end
-
Register the new_shipping_method in available shipping_calculators
config :nectar, :shipping_calculators, ... new_shipping_method: Nectar.ShippingCalculator.NewShippingMethod, ...
-
Add the new_shipping_method in DB
%{name: "new_shipping_method", enabled: true}
-
Shipping Methods can be enabled/disabled from Settings
Note: the configuration key should be same as name of added shipping_method in DB or vice-versa.