Shipping Classes

Adds weight, dimensions, and shipping class fields to Payload products and variants, storing values canonically in grams and millimetres for cart totalling.

Community 1 131/wk MIT v1.0.0

Installation

pnpm add payload-shipping-classes

About

Shipping Classes extends Payload products and variants with a weight, a size, and a shipping class. It targets the collections `@payloadcms/plugin-ecommerce` declares (`products` and `variants`) but works with any product collection that matches those slugs. Each product and variant gets a `weight` field, a `dimensions` group of length, width, and height, and a relationship to a `shipping-classes` collection. The entered value is kept as the shop typed it, and a second hidden, read-only value is written next to it in one fixed unit. Weights are stored canonically in grams and dimensions in millimetres, converted using the avoirdupois pound of 453.59237 g and the inch of exactly 25.4 mm, rounded to the nearest whole unit. A `beforeChange` hook recalculates the canonical values on every save, reading the incoming value when a partial update leaves it out and clearing it to `null` rather than `0` when the entered weight is cleared. Keeping the arithmetic on integers avoids the floating point drift that accumulates when decimals are added. A variant overrides the product measurement by measurement. A variant weight of `0` is an override, not a fallthrough; only `null`, `undefined`, a non-number, or a negative number falls through to the product. The dimensions group is resolved as a whole rather than face by face, so a variant that sets only `length` overrides the product's length, width, and height together. `resolveShippingLine` reports where each value came from as `'variant'`, `'product'`, or `'none'`. The plugin exports a pure `totalCartShipping` function that totals a cart's lines into `weightGrams`, `volumeMm3`, `quantity`, `shippingClasses`, and `unitsWithoutWeight`. That last field distinguishes a cart where every item was weighed from one where some were not, which matters for any rate calculator. The returned shape is plain JSON, so a consumer can read it without installing the package. Field names, collection slugs, units, and the shipping classes collection are all configurable, the plugin has no runtime dependencies, and it ships no admin components so it survives minor Payload releases.

Package info

Package name
payload-shipping-classes
Latest version
1.0.0
Unpacked size
32 kB
License
MIT
Weekly downloads
131
Last publish
Aug 21, 2026

More from Poseidonas

View profile