Skip to content

Add New Shipping Method

Pikender Sharma edited this page Mar 22, 2016 · 2 revisions

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.

  1. Create a module, preferably with new name of Shipping Method, say new_shipping_method and add use 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
  2. Register the new_shipping_method in available shipping_calculators

    config :nectar, :shipping_calculators,
      ...
      new_shipping_method: Nectar.ShippingCalculator.NewShippingMethod,
      ...
  3. Add the new_shipping_method in DB %{name: "new_shipping_method", enabled: true}

  4. 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.

Clone this wiki locally