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.
Weight, dimensions and a shipping class on Payload products and variants, stored in one canonical unit.
Installation
npm i payload-shipping-classes2
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
2+1 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 2 |
| Dec 5, 2026 | 2 |
| Dec 4, 2026 | 2 |
| Dec 3, 2026 | 2 |
| Dec 2, 2026 | 2 |
| Dec 1, 2026 | 2 |
| Nov 30, 2026 | 2 |
| Nov 29, 2026 | 2 |
| Nov 28, 2026 | 2 |
| Nov 27, 2026 | 2 |
| Nov 26, 2026 | 2 |
| Nov 25, 2026 | 2 |
| Nov 24, 2026 | 2 |
| Nov 23, 2026 | 2 |
| Nov 22, 2026 | 2 |
| Nov 21, 2026 | 2 |
| Nov 20, 2026 | 2 |
| Nov 19, 2026 | 2 |
| Nov 18, 2026 | 2 |
| Nov 17, 2026 | 2 |
| Nov 16, 2026 | 2 |
| Nov 15, 2026 | 2 |
| Nov 14, 2026 | 2 |
| Nov 13, 2026 | 2 |
| Nov 12, 2026 | 2 |
| Nov 11, 2026 | 2 |
| Nov 10, 2026 | 2 |
| Nov 9, 2026 | 2 |
| Nov 8, 2026 | 2 |
| Nov 7, 2026 | 2 |
| Nov 6, 2026 | 2 |
| Nov 5, 2026 | 2 |
| Nov 4, 2026 | 2 |
| Nov 3, 2026 | 2 |
| Nov 2, 2026 | 2 |
| Nov 1, 2026 | 2 |
| Oct 31, 2026 | 2 |
| Oct 30, 2026 | 2 |
| Oct 29, 2026 | 2 |
| Oct 28, 2026 | 2 |
| Oct 27, 2026 | 2 |
| Oct 26, 2026 | 2 |
| Oct 25, 2026 | 2 |
| Oct 24, 2026 | 2 |
| Oct 23, 2026 | 2 |
| Oct 22, 2026 | 2 |
| Oct 21, 2026 | 2 |
| Oct 20, 2026 | 2 |
| Oct 19, 2026 | 2 |
| Oct 18, 2026 | 1 |
| Oct 17, 2026 | 1 |
| Oct 16, 2026 | 1 |
| Oct 15, 2026 | 1 |
| Oct 14, 2026 | 1 |
| Oct 13, 2026 | 1 |
| Oct 12, 2026 | 1 |
| Oct 11, 2026 | 1 |
| Oct 10, 2026 | 1 |
| Oct 9, 2026 | 1 |
| Oct 8, 2026 | 1 |
| Oct 7, 2026 | 1 |
| Oct 6, 2026 | 1 |
| Oct 5, 2026 | 1 |
| Oct 4, 2026 | 1 |
| Oct 3, 2026 | 1 |
| Oct 2, 2026 | 1 |
| Oct 1, 2026 | 1 |
| Sep 30, 2026 | 1 |
| Sep 29, 2026 | 1 |
| Sep 28, 2026 | 1 |
| Sep 27, 2026 | 1 |
| Sep 26, 2026 | 1 |
| Sep 25, 2026 | 1 |
| Sep 24, 2026 | 1 |
| Sep 23, 2026 | 1 |
| Sep 22, 2026 | 1 |
| Sep 21, 2026 | 1 |
| Sep 20, 2026 | 1 |
| Sep 19, 2026 | 1 |
| Sep 18, 2026 | 1 |
| Sep 17, 2026 | 1 |
| Sep 16, 2026 | 1 |
| Sep 15, 2026 | 1 |
| Sep 14, 2026 | 1 |
| Sep 13, 2026 | 1 |
| Sep 12, 2026 | 1 |
| Sep 11, 2026 | 1 |
| Sep 10, 2026 | 1 |
| Sep 9, 2026 | 1 |
| Sep 8, 2026 | 1 |
| Sep 7, 2026 | 1 |
12−2 since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 12 |
| Dec 5, 2026 | 8 |
| Dec 4, 2026 | 8 |
| Dec 3, 2026 | 10 |
| Dec 2, 2026 | 11 |
| Dec 1, 2026 | 11 |
| Nov 30, 2026 | 11 |
| Nov 29, 2026 | 12 |
| Nov 28, 2026 | 23 |
| Nov 27, 2026 | 31 |
| Nov 26, 2026 | 202 |
| Nov 25, 2026 | 200 |
| Nov 24, 2026 | 199 |
| Nov 23, 2026 | 198 |
| Nov 22, 2026 | 195 |
| Nov 21, 2026 | 184 |
| Nov 20, 2026 | 176 |
| Nov 19, 2026 | 3 |
| Nov 18, 2026 | 3 |
| Nov 17, 2026 | 3 |
| Nov 16, 2026 | 5 |
| Nov 15, 2026 | 5 |
| Nov 14, 2026 | 5 |
| Nov 13, 2026 | 5 |
| Nov 12, 2026 | 5 |
| Nov 11, 2026 | 5 |
| Nov 10, 2026 | 5 |
| Nov 9, 2026 | 4 |
| Nov 8, 2026 | 4 |
| Nov 7, 2026 | 5 |
| Nov 6, 2026 | 4 |
| Nov 5, 2026 | 5 |
| Nov 4, 2026 | 5 |
| Nov 3, 2026 | 5 |
| Nov 2, 2026 | 6 |
| Nov 1, 2026 | 6 |
| Oct 31, 2026 | 5 |
| Oct 30, 2026 | 5 |
| Oct 29, 2026 | 3 |
| Oct 28, 2026 | 3 |
| Oct 27, 2026 | 4 |
| Oct 26, 2026 | 3 |
| Oct 25, 2026 | 2 |
| Oct 24, 2026 | 3 |
| Oct 23, 2026 | 3 |
| Oct 22, 2026 | 4 |
| Oct 21, 2026 | 4 |
| Oct 20, 2026 | 3 |
| Oct 19, 2026 | 2 |
| Oct 18, 2026 | 2 |
| Oct 17, 2026 | 2 |
| Oct 16, 2026 | 2 |
| Oct 15, 2026 | 3 |
| Oct 14, 2026 | 3 |
| Oct 13, 2026 | 3 |
| Oct 12, 2026 | 3 |
| Oct 11, 2026 | 4 |
| Oct 10, 2026 | 3 |
| Oct 9, 2026 | 3 |
| Oct 8, 2026 | 2 |
| Oct 7, 2026 | 2 |
| Oct 6, 2026 | 4 |
| Oct 5, 2026 | 4 |
| Oct 4, 2026 | 4 |
| Oct 3, 2026 | 5 |
| Oct 2, 2026 | 8 |
| Oct 1, 2026 | 7 |
| Sep 30, 2026 | 7 |
| Sep 29, 2026 | 6 |
| Sep 28, 2026 | 6 |
| Sep 27, 2026 | 6 |
| Sep 26, 2026 | 8 |
| Sep 25, 2026 | 7 |
| Sep 24, 2026 | 7 |
| Sep 23, 2026 | 8 |
| Sep 22, 2026 | 9 |
| Sep 21, 2026 | 9 |
| Sep 20, 2026 | 11 |
| Sep 19, 2026 | 8 |
| Sep 18, 2026 | 7 |
| Sep 17, 2026 | 9 |
| Sep 16, 2026 | 16 |
| Sep 15, 2026 | 15 |
| Sep 14, 2026 | 18 |
| Sep 13, 2026 | 15 |
| Sep 12, 2026 | 17 |
| Sep 11, 2026 | 18 |
| Sep 10, 2026 | 16 |
| Sep 9, 2026 | 9 |
| Sep 8, 2026 | 11 |
| Sep 7, 2026 | 14 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1340410496-root)<a href="https://payloaddirectory.dev/plugins/1340410496-root"><img src="https://payloaddirectory.dev/badge/1340410496-root.svg" alt="Payload Directory"></a>README
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.
@payloadcms/plugin-ecommerce and with any collection that holds productsg, kg, oz or lb, dimensions in mm, cm, m or in, stored in grams and millimetresRequires 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.
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:
| Collection | Fields the plugin adds |
|---|---|
products | inventory, enableVariants, variantTypes, variants, and priceIn<CODE> with priceIn<CODE>Enabled for each supported currency |
variants | title, 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.
| Entered | Unit | Stored |
|---|---|---|
1.25 | kg | 1250 g |
750 | g | 750 g |
5 | lb | 2268 g |
1 | oz | 28 g |
2.5 | cm | 25 mm |
12 | in | 305 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.
For each of the three measurements, independently, in this order and no other:
Two consequences follow, and both are deliberate:
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.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.
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.
| Option | Default | Meaning |
|---|---|---|
canonicalDimensionsFieldName | 'dimensionsMm' | Hidden group holding the dimensions in millimetres |
canonicalWeightFieldName | 'weightGrams' | Hidden field holding the weight in grams |
dimensions | true | Set 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 |
disabled | false | Stops 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.
| Collection | Field | Type | Notes |
|---|---|---|---|
| your products collection | weight | number | entered in the configured unit, minimum 0 |
| your products collection | weightGrams | number | whole grams, hidden and read only, written by the plugin |
| your products collection | dimensions | group of length, width, height | entered in the configured unit, minimum 0 |
| your products collection | dimensionsMm | group of length, width, height | whole millimetres, hidden and read only, written by the plugin |
| your products collection | shippingClass | relationship | indexed, optional |
| your variants collection | the same five | added only when the collection exists | |
shipping-classes | name | text | required |
shipping-classes | slug | text | required, unique, indexed. Filled from the name when left empty |
shipping-classes | description | textarea | optional |
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.
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.
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.
MIT. Copyright George Vasiliades, https://github.com/Poseidonas
ecommerce
Ecommerce utilities for Payload with idempotent Stripe confirmation, orders, carts and inventory handling
10019.0k/wk46.1kv3 v4
payload stock reservation
Validates variant stock and price at checkout and holds stock until payment settles or the hold expires
76152/wk1v3
payload fulfillment
Extra order states, transition history, internal notes and tracking fields for Payload ecommerce orders
7332/wk1v3
payload ecommerce
Products, carts, orders and coupons for Payload 3 with server-side helpers and stock tracking
72537/wk2v3
payload stock alerts
Low stock threshold alerts by email and backorder handling for Payload ecommerce products and variants
7222/wk1v3
payload refunds
Full and partial refunds per order line for Payload ecommerce, with optional restock and an append-only audit trail
6915/wk1v3