Poseidonas

payload shipping classes

by Poseidonas
Stores & catalogs
v3
>=3.88 <4
MIT

Overview

Summary generated from the README

Adds weight, dimensions and a shipping class relationship to products and variants, with variant values overriding the product's. Entered values are converted to grams and millimetres by a beforeChange hook so totals stay on whole numbers. Requires Payload 3.88 or newer and the official ecommerce plugin, and exports a pure function that totals a cart.

Features

  • Weight in g, kg, oz or lb and dimensions in mm, cm, m or in, converted to grams and millimetres on save
  • Variant values override product values measurement by measurement, with dimensions resolved as a whole group
  • Shipping classes collection with a unique slug, referenced from products and variants
  • Cart totaling function returns weight, volume, classes and a count of units without weight
  • Configurable field names, collection slugs and units, plus a disabled mode that keeps the schema
  • No runtime dependencies and no admin components

Use cases

  • Record parcel weight and size on products so a rate calculator can total a cart
  • Group products into shipping classes such as fragile or oversized for delivery pricing
  • Detect carts containing unweighed items before quoting a shipping price

From the author

Weight, dimensions and a shipping class on Payload products and variants, stored in one canonical unit.

Installation

npm i payload-shipping-classes

2

Stars

0

Forks

0

Open Issues

2 weeks ago

Last Updated

10

Weekly Downloads

v1.0.1

npm Version

30.6 KB

Unpacked Size

0

Dependencies

GitHub stars

2+1 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20262
Dec 5, 20262
Dec 4, 20262
Dec 3, 20262
Dec 2, 20262
Dec 1, 20262
Nov 30, 20262
Nov 29, 20262
Nov 28, 20262
Nov 27, 20262
Nov 26, 20262
Nov 25, 20262
Nov 24, 20262
Nov 23, 20262
Nov 22, 20262
Nov 21, 20262
Nov 20, 20262
Nov 19, 20262
Nov 18, 20262
Nov 17, 20262
Nov 16, 20262
Nov 15, 20262
Nov 14, 20262
Nov 13, 20262
Nov 12, 20262
Nov 11, 20262
Nov 10, 20262
Nov 9, 20262
Nov 8, 20262
Nov 7, 20262
Nov 6, 20262
Nov 5, 20262
Nov 4, 20262
Nov 3, 20262
Nov 2, 20262
Nov 1, 20262
Oct 31, 20262
Oct 30, 20262
Oct 29, 20262
Oct 28, 20262
Oct 27, 20262
Oct 26, 20262
Oct 25, 20262
Oct 24, 20262
Oct 23, 20262
Oct 22, 20262
Oct 21, 20262
Oct 20, 20262
Oct 19, 20262
Oct 18, 20261
Oct 17, 20261
Oct 16, 20261
Oct 15, 20261
Oct 14, 20261
Oct 13, 20261
Oct 12, 20261
Oct 11, 20261
Oct 10, 20261
Oct 9, 20261
Oct 8, 20261
Oct 7, 20261
Oct 6, 20261
Oct 5, 20261
Oct 4, 20261
Oct 3, 20261
Oct 2, 20261
Oct 1, 20261
Sep 30, 20261
Sep 29, 20261
Sep 28, 20261
Sep 27, 20261
Sep 26, 20261
Sep 25, 20261
Sep 24, 20261
Sep 23, 20261
Sep 22, 20261
Sep 21, 20261
Sep 20, 20261
Sep 19, 20261
Sep 18, 20261
Sep 17, 20261
Sep 16, 20261
Sep 15, 20261
Sep 14, 20261
Sep 13, 20261
Sep 12, 20261
Sep 11, 20261
Sep 10, 20261
Sep 9, 20261
Sep 8, 20261
Sep 7, 20261
npm weekly downloads

12−2 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202612
Dec 5, 20268
Dec 4, 20268
Dec 3, 202610
Dec 2, 202611
Dec 1, 202611
Nov 30, 202611
Nov 29, 202612
Nov 28, 202623
Nov 27, 202631
Nov 26, 2026202
Nov 25, 2026200
Nov 24, 2026199
Nov 23, 2026198
Nov 22, 2026195
Nov 21, 2026184
Nov 20, 2026176
Nov 19, 20263
Nov 18, 20263
Nov 17, 20263
Nov 16, 20265
Nov 15, 20265
Nov 14, 20265
Nov 13, 20265
Nov 12, 20265
Nov 11, 20265
Nov 10, 20265
Nov 9, 20264
Nov 8, 20264
Nov 7, 20265
Nov 6, 20264
Nov 5, 20265
Nov 4, 20265
Nov 3, 20265
Nov 2, 20266
Nov 1, 20266
Oct 31, 20265
Oct 30, 20265
Oct 29, 20263
Oct 28, 20263
Oct 27, 20264
Oct 26, 20263
Oct 25, 20262
Oct 24, 20263
Oct 23, 20263
Oct 22, 20264
Oct 21, 20264
Oct 20, 20263
Oct 19, 20262
Oct 18, 20262
Oct 17, 20262
Oct 16, 20262
Oct 15, 20263
Oct 14, 20263
Oct 13, 20263
Oct 12, 20263
Oct 11, 20264
Oct 10, 20263
Oct 9, 20263
Oct 8, 20262
Oct 7, 20262
Oct 6, 20264
Oct 5, 20264
Oct 4, 20264
Oct 3, 20265
Oct 2, 20268
Oct 1, 20267
Sep 30, 20267
Sep 29, 20266
Sep 28, 20266
Sep 27, 20266
Sep 26, 20268
Sep 25, 20267
Sep 24, 20267
Sep 23, 20268
Sep 22, 20269
Sep 21, 20269
Sep 20, 202611
Sep 19, 20268
Sep 18, 20267
Sep 17, 20269
Sep 16, 202616
Sep 15, 202615
Sep 14, 202618
Sep 13, 202615
Sep 12, 202617
Sep 11, 202618
Sep 10, 202616
Sep 9, 20269
Sep 8, 202611
Sep 7, 202614

Each point is npm's rolling 7-day download count.

Health Score

72/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1340410496-root.svg)](https://payloaddirectory.dev/plugins/1340410496-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1340410496-root"><img src="https://payloaddirectory.dev/badge/1340410496-root.svg" alt="Payload Directory"></a>
Updated Nov 17, 2026Created Aug 20, 2026Published Nov 17, 2026

README

payload-shipping-classes

npm node license payload

Gives Payload products and variants a weight, a size and a shipping class, stored in one canonical unit, so that whatever prices the delivery can add a cart up without having to ask what the numbers mean.

  • Works with @payloadcms/plugin-ecommerce and with any collection that holds products
  • Weight entered in g, kg, oz or lb, dimensions in mm, cm, m or in, stored in grams and millimetres
  • A variant overrides its product, measurement by measurement
  • Exports a pure function that totals a cart, so a rate calculator can read the result without installing this package
  • No runtime dependencies
  • No admin components, so it survives minor releases

Install

Requires Payload 3.88 or newer and @payloadcms/plugin-ecommerce 3.88 or newer. Verified against Payload 3.88.0 with the official plugin installed.

pnpm add payload-shipping-classes
import { shippingClassesPlugin } from 'payload-shipping-classes'

export default buildConfig({
  plugins: [
    shippingClassesPlugin({
      weightUnit: 'kg',
      dimensionUnit: 'cm',
    }),
  ],
})

A product now has a Weight (kg) field, a Dimensions (cm) group and a shipping class. A variant has the same three, and whatever it fills in wins over the product.

What was measured

Measured on 19 August 2026 against the published contents of @payloadcms/[email protected].

A product has no weight and no size. These are all the fields the official plugin puts on a product and on a variant:

CollectionFields the plugin adds
productsinventory, enableVariants, variantTypes, variants, and priceIn<CODE> with priceIn<CODE>Enabled for each supported currency
variantstitle, product, options, inventory, and priceIn<CODE> with priceIn<CODE>Enabled for each supported currency

Searching the whole published package for weight finds two occurrences, both of them font-weight in a stylesheet. dimension does not occur at all. There is nothing on a product that describes the parcel it will travel in.

A number without a unit cannot be added up. A single weight field of 2 means two grams to one shop and two pounds to the next, and it changes meaning the day a shop switches unit. So the entered value is kept as the shop typed it, and a second, hidden value is written next to it in one fixed unit. Every calculation reads the hidden one.

EnteredUnitStored
1.25kg1250 g
750g750 g
5lb2268 g
1oz28 g
2.5cm25 mm
12in305 mm

Conversion uses the international avoirdupois pound of 453.59237 g and the inch of exactly 25.4 mm, then rounds to the nearest gram or millimetre. The largest error a conversion can introduce is half a gram, which is finer than any carrier weighs.

Totals stay on the integers. Adding ten weights of 0.001 kg in JavaScript gives 0.010000000000000002, and three of 0.1 kg give 0.30000000000000004. Adding ten of 1 g gives 10. Conversion rounds once, when the value is stored, and every addition after that is between whole numbers.

Resolution order

For each of the three measurements, independently, in this order and no other:

  1. the variant's own value, when the variant is present and its value is a finite number of zero or more
  2. otherwise the product's value, under the same test
  3. otherwise nothing, and the line is reported as having no value for that measurement

Two consequences follow, and both are deliberate:

  • A variant weight of 0 is an override. A weightless variant of a heavy product weighs nothing. Only null, undefined, a missing field, a value that is not a number, or a negative number falls through to the product.
  • The dimensions group is resolved as a whole, not face by face. A variant that sets only length overrides the product's length, width and height together, leaving width and height empty. Partial groups are never merged, because a box with one dimension from the variant and two from the product is not a box anyone measured.

resolveShippingLine reports where each value came from, as 'variant', 'product' or 'none', so a shop can see the rule applied rather than infer it.

Totalling a cart

import { totalCartShipping } from 'payload-shipping-classes'

const totals = totalCartShipping([
  { product: greenMug, quantity: 2, variant: largeGreenMug },
  { product: giftCard, quantity: 1 },
])
{
  weightGrams: 1400,
  volumeMm3: 2400000,
  quantity: 3,
  shippingClasses: ['fragile'],
  unitsWithoutWeight: 1,
  lines: [ ... ]
}

unitsWithoutWeight is the point of the function. A cart that weighs 1400 g and a cart that weighs 1400 g plus one item nobody ever weighed are different carts, and a rate calculator that cannot tell them apart will quote a price for a parcel it has not seen.

The returned shape is the whole contract. A consumer needs weightGrams, shippingClasses and unitsWithoutWeight, all three plain JSON, and needs no import from this package to read them.

Options

OptionDefaultMeaning
canonicalDimensionsFieldName'dimensionsMm'Hidden group holding the dimensions in millimetres
canonicalWeightFieldName'weightGrams'Hidden field holding the weight in grams
dimensionstrueSet to false to add the weight and the class but no dimensions
dimensionsFieldName'dimensions'Group holding the entered dimensions
dimensionUnit'cm'One of mm, cm, m, in
disabledfalseStops the canonical values being recalculated but keeps every field, so the database keeps its shape
productsSlug'products'Slug of the products collection
shippingClassesOverrides{}Merged over the generated collection, applied last
shippingClassesSlug'shipping-classes'Collection holding the classes
shippingClassFieldName'shippingClass'Relationship field on products and variants
variantsSlug'variants'Slug of the variants collection. Ignored when the shop has no variants
weightFieldName'weight'Field holding the entered weight
weightUnit'kg'One of g, kg, oz, lb

An unusable value is replaced by its default rather than applied. An unknown unit falls back to kg or cm, and a name given as an empty string falls back to its default name.

What it adds to your database

CollectionFieldTypeNotes
your products collectionweightnumberentered in the configured unit, minimum 0
your products collectionweightGramsnumberwhole grams, hidden and read only, written by the plugin
your products collectiondimensionsgroup of length, width, heightentered in the configured unit, minimum 0
your products collectiondimensionsMmgroup of length, width, heightwhole millimetres, hidden and read only, written by the plugin
your products collectionshippingClassrelationshipindexed, optional
your variants collectionthe same fiveadded only when the collection exists
shipping-classesnametextrequired
shipping-classesslugtextrequired, unique, indexed. Filled from the name when left empty
shipping-classesdescriptiontextareaoptional

The canonical values are recalculated in a beforeChange hook on every save, from the entered value in the incoming data, or from the stored one when a partial update leaves it out. Clearing a weight clears the canonical weight to null rather than to 0.

The shipping-classes collection is readable by anyone and writable by any authenticated user. Pass shippingClassesOverrides with your own access to narrow that to your administrators.

Without payload-shipping-rates

This package prices nothing. On its own it records a weight, a size and a class, and totals a cart on request. Nothing else in a Payload install reads those fields until something is installed that does.

payload-shipping-rates reads weightGrams and shippingClass by those names, but it does not import this package and does not require it. Either package can be installed without the other.

Honest limits

Changing a unit does not rewrite what is already stored. The canonical value is recalculated when a document is saved. If a shop switches weightUnit from kg to lb with products already in the database, those products keep a canonical weight calculated under the old unit until each one is saved again. Switch the unit before entering data, or resave the catalogue afterwards.

Existing products have no weight. The plugin only writes a canonical value when a document is saved. Products already in the database keep an empty weight and an empty weightGrams until they are next edited.

Whole grams and whole millimetres. A weight is stored to the nearest gram and a length to the nearest millimetre. A shop weighing single seed beads in ounces will see the rounding; a shop shipping parcels will not.

Dimensions are recorded, not used. volumeMm3 is the sum of length times width times height for every line that has all three. It is not a volumetric weight, not a girth, and not a packing calculation. Nothing here decides which box the order goes in.

One class per product. A product or a variant carries a single shipping class. There is no notion of a product being both fragile and oversized, and no per class surcharge here, because pricing does not live in this package.

The slug is what gets referenced. A rate calculator matches classes by slug. Renaming a class is safe; changing its slug breaks anything that referred to the old one.

License

MIT. Copyright George Vasiliades, https://github.com/Poseidonas

Similar plugins