B2B

B2B Shipping in Magento 2 — Bulky Goods, Freight, Rules, Surcharges

B2B Shipping in Magento 2 — Bulky Goods, Freight, Rules, Surcharges

Core Product Attributes: The Foundation

Handling complex B2B shipping scenarios starts with rich product data. Standard Magento attributes are a starting point, but for freight and bulky goods, you must extend the product attribute set. Key attributes include:

  • Dimensions (Length, Width, Height): Stored as decimals, these are critical for volumetric weight calculations and palletization logic. Use three separate `decimal` type attributes.
  • Weight: A standard attribute, but its accuracy is paramount. Ensure processes are in place to validate this data from your PIM or ERP.
  • Oversize/Bulky Flag: A `boolean` attribute (`is_oversize`) to quickly identify items that automatically disqualify for standard parcel services. This can be used to trigger different shipping rule evaluations.
  • Freight Class: A `select` attribute representing the National Motor Freight Classification (NMFC). This is essential for LTL (Less Than Truckload) freight rating.
  • Stackable: A `boolean` attribute (`is_stackable`) to inform palletization logic whether multiple units of this SKU can be stacked.
  • Shipping Surcharge: A `price` attribute to add a fixed handling fee per item, often used for items requiring special handling.

Shipping Classes and Regional Rules

Not all products ship the same way, and not all customers get the same rates. Shipping classes and regional rules are the primary tools for segmentation.

Shipping Classes

Create logical groups for products with similar shipping characteristics. These are not native Magento concepts but can be implemented via a custom `select` product attribute (`shipping_class`). Examples include:

  • Standard Parcel
  • Oversize Parcel
  • LTL Freight
  • Hazmat
  • White Glove Delivery

This attribute becomes a powerful input for your shipping rate calculation logic, allowing you to apply different rules or connect to different carrier APIs based on the class of items in the cart.

Zone and Region Rules

Magento's native table rates provide a basic foundation for zone-based shipping. However, B2B often requires more granularity. You can achieve this by:

  • Postcode Patterns: Storing patterns (e.g., `902*`, `SW*`) in your configuration to define delivery zones.
  • Country/State/County Combinations: Building logic that combines these standard address fields to create specific regions.
  • Customer Group Targeting: Applying specific shipping rules or methods only to certain customer groups, allowing for negotiated rates.

Freight Carriers and Accessorials

Integrating directly with freight carriers is essential for accurate rating. Unlike parcel services, freight quoting involves numerous additional services, known as accessorials.

Your integration must be able to quote for:

  • Liftgate Service: Required when the delivery location does not have a loading dock. This should be a checkbox option in the checkout.
  • Residential Delivery: Carriers charge more for deliveries to residential addresses. Your implementation must use address validation to determine this.
  • Inside Delivery: When the driver is required to bring the shipment inside the premises.
  • Delivery Appointment: If the recipient needs to schedule a specific delivery time.

These options should be presented at checkout, often as checkboxes that, when selected, trigger an AJAX call to re-quote the shipping cost with the added fees from the carrier's API.

Surcharges and Handling Fees

Complex rules often dictate additional fees beyond the carrier's rate. Your implementation should support surcharges based on:

  • Per-SKU: A simple `shipping_surcharge` attribute on the product.
  • Category: Applying a fee to all items within a specific category (e.g., "Glassware"). This requires custom logic that checks the categories of cart items.
  • Shipping Class: Adding a fee for all items in a "Hazmat" or "Refrigerated" class.
  • Cart Attributes: Applying a surcharge if the total weight exceeds a certain threshold or if the cart contains a mix of parcel and freight items.

Palletization and Cartonization

For multi-item orders, you must decide how to package them. This logic is complex and often resides in a WMS, but can be modeled in Magento.

Cartonization

This involves determining the optimal number and size of boxes for a shipment. A basic implementation uses an algorithm that iterates through cart items, adding their dimensions and weights to a virtual "box" until it's full, then starting a new one. This provides a more accurate package count to send to the carrier API.

Palletization

For LTL shipments, you need to determine how many pallets are required. The logic should consider:

  • Total order volume and weight.
  • The `is_stackable` attribute of the products.
  • Maximum pallet height and weight constraints (e.g., 48"x40"x60", 2000 lbs).

The output of this logic is a set of package dimensions and weights (one for each pallet) to be sent to the freight carrier's rating API.

Rule Evaluation and Conflict Resolution

With multiple rules, conflicts are inevitable. A priority system is crucial. Define an evaluation order, for example:

  1. Check for cart-level overrides (e.g., a free shipping coupon).
  2. Evaluate rules based on specific SKUs or product attributes.
  3. Evaluate rules based on shipping class.
  4. Evaluate rules based on customer group.
  5. Apply zone-based default rules.

The first rule that matches should be applied, and further processing stopped, or rules can be designed to be cumulative. Clearly define this logic in your implementation to avoid unexpected rate calculations.

Quoting: Carrier APIs vs. Table Rates

A hybrid approach is often best:

  • Carrier APIs: Use for live, dynamic rating of freight and parcel services. This is essential for accuracy, especially when fuel surcharges and accessorials are involved. Implement robust error handling for API timeouts or failures.
  • Table Rates: Use as a fallback mechanism when an API fails. Also suitable for simple scenarios, like standardized local delivery fees or zone-based pricing for your own truck fleet.

Address Validation

Before sending an address to a carrier API, validate it. Use services like UPS or USPS address validation APIs to standardize the address and, critically, to determine if it is residential or commercial. This classification directly impacts freight costs.

Performance and Caching

Complex rating logic can slow down the cart and checkout. To mitigate this:

  • Cache Carrier Responses: Cache shipping rate API responses for identical carts (same items, same destination postcode) for a short period (e.g., 15-30 minutes).
  • Pre-computed Rule Maps: For complex, non-API-based rules, consider a nightly process that pre-computes rule outcomes for common scenarios and stores them in an indexed table for faster lookups.

Checkout UI Patterns for Freight

The standard Magento checkout needs modification for freight:

  • Accessorial Checkboxes: As mentioned, use checkboxes for services like "Liftgate Required" or "Inside Delivery".
  • Delivery Windows: For services that allow it, provide a date picker or time slot selector for scheduled deliveries.
  • Clear Method Naming: Clearly distinguish between shipping methods. Instead of just "Freight," use descriptive names like "LTL Freight with Liftgate Service."

Admin Configuration

Your implementation must be configurable by administrators. Key `system.xml` configuration should include:

  • Carrier API credentials.
  • Enable/disable switches for different shipping methods and accessorials.
  • Default freight class, stackability, and dimensions for products where these are not set.
  • Configuration for surcharge amounts and the rules that trigger them.

Extensibility and Integration

Use Magento's extension points to build your logic:

  • `MagentoQuoteModelShippingRateResult`: This is where you will add your custom shipping methods and rates.
  • Plugins (Interceptors): Use `around` or `after` plugins on `MagentoShippingModelShipping::collectRates` to inject your custom rate collection logic.
  • Observers: The `sales_quote_collect_totals_before` event can be used to analyze the cart and add necessary data before shipping calculation begins.

ERP/WMS Integration

While Magento can handle rating, the fulfillment instructions (pallet configuration, accessorials selected) must be passed to your ERP or WMS. Ensure your order export process includes this data, often as custom attributes on the order or order item objects.

KPIs and Testing

To measure success and ensure accuracy, track:

  • Quoted vs. Actual Shipping Cost: The most important metric. Regularly compare the shipping cost quoted to the customer with the final invoice from the carrier.
  • API Response Times: Monitor the performance of carrier API calls to identify bottlenecks.
  • Checkout Abandonment Rate: A spike after implementation could indicate issues with shipping costs or UI complexity.

Thoroughly test your implementation with a matrix of scenarios: different product combinations, destinations, customer groups, and accessorial selections.

Previous ArticleCompany Accounts, Budgets & Approvals in Magento 2
Next ArticleB2B Checkout UX: Patterns that Convert