npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pinelab/vendure-plugin-shipping-extensions

v2.7.2

Published

Vendure plugin for configurable shipping calculators and eligibility checkers.

Downloads

293

Readme

Shipping Extenions Vendure Plugin

Official documentation here

A collection of shipping calculators, checkers and promotion conditions that help you create customizable shipping options:

  • Shipping eligibility checks based on the order weight and the order's country
  • Distance based Shipping calculator, to calculate your shipping price based on the distance from your store
  • A promotion condition that checks the order's shipping country. For example to only give free shipping to countries X, Y and Z

Getting started

  1. Add the following to the plugins in vendure-config.ts:
plugins: [
  ...
    ShippingExtensionsPlugin.init({
      /**
       * Weight unit used in the eligibility checker
       * and product customfield.
       * Only used for displaying purposes
       */
      weightUnit: "kg",
      /**
       * The name of the tab the customfield should be added to
       * This can be an existing tab
       */
      customFieldsTab: "Physical properties",
    }),
    AdminUiPlugin.init({
        ...
        app: compileUiExtensions({
          extensions: [
            ...
            ShippingExtensionsPlugin.ui
            ],
          ...
        }),
      })
  ...
]
  1. Start your server
  2. Login to the admin UI and go to Shipping methods
  3. Create a new shippingmethod
  4. Under Shipping eligibility checker you should see Check by weight and country
  5. Under Shipping calculator you should see Distance Based Shipping Calculator
  6. Under Promotions conditions you should see Order is in country condition.

Shipping by weight and country options

Some examples:

  • Create a shipping method for orders placed in Australia, with a total order weight between 10kg and 40kg
  • Create a shipping method for all orders except the ones placed in Canada and Norway, with a total order weight below 1100 grams

The weight of a product can be configured on the customfield Product.weight. You can configure the units to be in KG, grams or whatever unit you like.

Custom weight calculation

By default, the plugin will calculate the weight of an order based on the custom field weight:

  1. It will use the productVariant.customFields.weight of each order line
  2. If that's not set, it will look for the productVariant.product.customFields.weight of each order line.

If you'd like to change this behaviour, you can specify a custom weightCalculationFunction:

ShippingExtensionsPlugin.init({
          weightCalculationFunction: (order) => {
            // The order is hydrated with `order.lines.productVariant.product`
            let totalOrderWeight = 0;
            order.lines.forEach((line) => {
              // Do your calculation magic here.
              totalOrderWeight += line.myCustomWeightField
            });
            return totalWeight;
          },
      }),

Distance based shipping options

A configurable OrderAddressToGeolocationConversionStrategy is used to convert the shippingAddress of an Order to a geographic latitudinal and longitudinal, which in turn is used to calculate the distance. The built-in strategy converts a UK postalcode to a lat/lon.

To support distance based calculation in other countries you'd have to implement your own strategy:

import {OrderAddressToGeolocationConversionStrategy} from '@pinelab/vendure-plugin-shipping-extensions'
export class USStreetLineToGeolocationConversionStrategy implements OrderAddressToGeolocationConversionStrategy{
   async getGeoLocationForAddress(orderAddress: OrderAddress): Promise<GeoLocation> {
    const location=//...result of a possible API call or any other lookup method
    return {latitude: location.latitude, longitude: location.longitude}
   }
}

Zone aware shipping tax calculation

To calculate a shipping tax(TaxRate) based on the shipping or billing country of an order and a configurable TaxCategory, you can use the zone-aware-flat-rate-shipping-calculator included with this plugin.