Shipping Classes
Adds weight, dimensions, and shipping class fields to Payload products and variants, storing values canonically in grams and millimetres for cart totalling.
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 profileBarcodes
Adds Code 128, EAN-13 and QR code generation to Payload product collections with a printable label page and optional admin print buttons.
AI Manager
Writes product titles, descriptions, attributes and translations into Payload fields via Claude, ChatGPT, Gemini or Kimi, and skips content it already generated.
EU VAT
Records EU VAT on Payload ecommerce orders: country rates, B2B reverse charge, VIES validation, and OSS reporting totals.
Stock Reservation
Validates variant stock and price before checkout and holds reserved inventory until payment settles, extending the official Payload ecommerce plugin.
Stock Alerts
Sends a shop one email when product or variant inventory crosses a low stock threshold, with backorder handling and a storefront-readable status field.
Shipping Rates
Adds shipping zones, rate calculation, and a quote endpoint to Payload ecommerce shops.