Orchardcore shipping

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore shipping is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for the CrestApps Orchard Core Shipping module (CrestApps.OrchardCore.Shipping, Shipping.EasyPost, Shipping.Api). Covers ShippingZone and ShippingMethod with the Flat, Table, Free, LocalDelivery and Carrier rate providers, IShippingRateService, IShippingRateProvider with ShippingRateContext an

How to use this skill

Skill file

CrestApps Shipping

Shipping (new in CrestApps.OrchardCore 3.0) prices shipping and records shipments. Zones say where; each zone's methods say how and what it costs through rate providers. Products carry weight and shipping class in the Shipping part.

Where it fits in the commerce suite

| Module | Relationship |

| --- | --- |

| Commerce, Products (orchardcore-commerce, orchardcore-products) | Required |

| Orders (orchardcore-orders) | Required. Adds the Shipping step to an order's checkout and fills Order.Shipping, ShippingAddress, FulfillmentStatus |

| Addresses (orchardcore-addresses) | Required. Zones and rates work on the shared Address |

| Checkout (orchardcore-checkout) | The shipping line is a taxed billing item; the shipping address becomes the tax destination |

| Customers (orchardcore-customers) | Optional address book on the step, through IShippingAddressBook |

| Store Profile (orchardcore-commerce) | The ship-from address falls back to the store profile's address |

| Inventory (orchardcore-inventory) | Pickup locations take units from a stock location |

| Markets (orchardcore-markets) | Methods in the market's currency, else converted |

Features

| Feature ID | Name | Depends on |

| --- | --- | --- |

| CrestApps.OrchardCore.Shipping | Shipping | Commerce, Products, Orders, Addresses, OrchardCore.Contents |

| CrestApps.OrchardCore.Shipping.EasyPost | EasyPost | Shipping |

| CrestApps.OrchardCore.Shipping.Api | Shipping API | Shipping, Checkout API |

Guidelines

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "CrestApps.OrchardCore.Shipping"
      ],
      "disable": []
    },
    {
      "name": "ShippingZones",
      "Zones": [
        {
          "Name": "United States",
          "Countries": ["US"],
          "Methods": [
            { "Name": "Standard", "Description": "3 to 5 business days", "ProviderName": "Flat", "Properties": { "FlatRateSettings": { "Amount": 5, "PerItemAmount": 1 } } },
            { "Name": "Free over $100", "ProviderName": "Free", "Properties": { "FreeShippingSettings": { "MinimumSubtotal": 100 } } }
          ]
        },
        {
          "Name": "Everywhere else",
          "RestOfWorld": true,
          "Position": 99,
          "Methods": [
            { "Name": "International", "ProviderName": "Table", "Properties": { "TableRateSettings": { "Basis": 0, "Rows": [ { "From": 0, "Amount": 20 }, { "From": 2, "Amount": 35 } ] } } }
          ]
        }
      ]
    },
    {
      "name": "Settings",
      "ShippingSettings": {
        "WeightUnit": 0,
        "ShippingClasses": ["Bulky"],
        "Carriers": [
          { "Name": "UPS", "TrackingUrlTemplate": "https://www.ups.com/track?tracknum={0}" }
        ],
        "SendShippedEmails": true
      }
    }
  ]
}

The ShippingZones step creates or updates zones by ItemId or Name (names are unique); methods without a MethodId get one; provider settings go in Properties keyed by type name. The Shipping Zones deployment step exports every zone. TableRateSettings.Basis is Weight (0), Subtotal or Quantity.

Model

| Type | Key members |

| --- | --- |

| ShippingZone (INamedCatalog<ShippingZone>) | Name, Position, Countries (ISO alpha-2), Regions (ISO 3166-2 such as US-AK), RestOfWorld, Methods |

| ShippingMethod | MethodId, Name, Description, ProviderName, Enabled, Position, Currency (empty for any), TaxCategoryCode, ClassSurcharges; provider settings in its properties |

| ShippingPart | Weight (site unit), ShippingClass, VariantWeights, Length, Width, Height, VariantDimensions (ShippingDimensions by variant id); GetWeight(variantId), HasWeight(variantId), GetDimensions(variantId) (a variant's own first) |

| ShippingSettings (group shipping) | WeightUnit (Kilogram, Pound), ShippingClasses, Carriers, SendShippedEmails, PickupLocations (up to 20, with Fee, Instructions, StockLocationId), ShipFrom (falls back to the store profile address when empty), default parcel size, PackagingWeight |

Provider settings: FlatRateSettings (Amount, PerItemAmount), TableRateSettings (Basis, Rows of From and Amount, Maximum), FreeShippingSettings (MinimumSubtotal), LocalDeliverySettings (PostalCodes with 981* wildcards, Amount, FreeFromSubtotal, MinimumSubtotal), CarrierRateSettings (Carriers, MaxRates, MarkupPercent, MarkupAmount, FallbackAmount).

Rates

IShippingRateService.FindZoneAsync(address) returns the first zone by Position covering the address, else the rest-of-world zone. GetRatesAsync(ShippingRateRequest) asks each enabled method's provider; class surcharges are added and amounts rounded and never negative. A ShippingRateRequest has Destination, Currency and Lines (ShippingRequestLine with weight and class), plus Subtotal, TotalWeight and ItemCount.

Add a rate provider:

public sealed class PerKiloShippingProvider : IShippingRateProvider
{
    internal readonly IStringLocalizer S;

    public PerKiloShippingProvider(IStringLocalizer<PerKiloShippingProvider> stringLocalizer)
    {
        S = stringLocalizer;
    }

    public string Name => "PerKilo";

    public LocalizedString DisplayName => S["Per kilogram"];

    public LocalizedString Description => S["A base amount plus an amount for each kilogram."];

    public Task<IReadOnlyList<ShippingRate>> GetRatesAsync(ShippingRateContext context, CancellationToken cancellationToken = default)
    {
        var settings = context.Method.GetOrCreate<PerKiloRateSettings>();
        var amount = settings.BaseAmount + (settings.PerKilo * context.Request.TotalWeight);

        return Task.FromResult<IReadOnlyList<ShippingRate>>([context.CreateRate(amount)]);
    }
}

public sealed class PerKiloRateSettings
{
    public decimal BaseAmount { get; set; }

    public decimal PerKilo { get; set; }
}

Register with services.AddScoped<IShippingRateProvider, PerKiloShippingProvider>();, and add a DisplayDriver<ShippingMethod> that edits PerKiloRateSettings and renders only when ProviderName is PerKilo. CreateRate(amount, option, name) returns several rates from one method (RateId becomes {MethodId}:{option}).

Checkout

public sealed class DepotShippingAddressSource : IShippingAddressSource
{
    public Task<IReadOnlyList<ShippingAddressOption>> GetAddressesAsync(string userId, CancellationToken cancellationToken = default)
        => Task.FromResult<IReadOnlyList<ShippingAddressOption>>(
        [
            new ShippingAddressOption
            {
                AddressId = "depot-reno",
                Label = "Reno depot",
                Description = "Company depots",
                Address = new Address { Company = "Contoso", AddressLine1 = "2 Pine St", City = "Reno", Region = "NV", PostalCode = "89501", Country = "US" },
            },
        ]);
}

// services.AddScoped<IShippingAddressSource, DepotShippingAddressSource>();

Shipments

IShipmentService (in the caller's unit of work): GetRemainingAsync(order), CreateAsync(order, lines, details, ship) for a paid order (ship: false keeps a pending shipment that reserves the units, as Fulfillment Partners does before calling a partner, see orchardcore-fulfillment), ShipAsync, DeliverAsync, ReturnAsync, DeleteAsync. Each change updates Order.FulfillmentStatus (Unfulfilled, PartiallyFulfilled, Fulfilled). A tracking link must be http or https; an empty one comes from the carrier's TrackingUrlTemplate ({0} is the number).

public sealed class WarehouseShipmentHandler : ShipmentEventHandlerBase
{
    private readonly ILogger _logger;

    public WarehouseShipmentHandler(ILogger<WarehouseShipmentHandler> logger)
    {
        _logger = logger;
    }

    public override Task ShippedAsync(ShipmentContext context)
    {
        _logger.LogInformation("Order {OrderNumber} shipment {Number} left with {Carrier}.", context.Order.OrderNumber, context.Shipment.Number, context.Shipment.Carrier);

        return Task.CompletedTask;
    }
}

Register with services.AddScoped<IShipmentEventHandler, WarehouseShipmentHandler>();. Built in: the shipped email (order-shipped kind, once per shipment, ready-for-pickup wording for pickup orders), workflow events ShipmentCreatedEvent, ShipmentShippedEvent, ShipmentDeliveredEvent, ShipmentReturnedEvent, and webhooks. OrderShipmentsDisplayDriver adds OrderShipments_DetailAdmin and OrderShipments_Detail to the order pages.

Carriers and EasyPost

ICarrierProvider quotes carrier rates (QuoteAsync(CarrierShipmentRequest) returning a CarrierQuote) and buys labels (BuyLabelAsync(quoteId, rateId) returning a CarrierLabel). ICarrierProviderResolver returns the default enabled provider chosen on the Providers tab of Settings > Commerce > Shipping. The Carrier rate provider quotes through it with markup, caches quotes for ten minutes, and falls back to FallbackAmount or nothing.

EasyPost (CrestApps.OrchardCore.Shipping.EasyPost) keeps ApiKey and WebhookSecret protected (purpose EasyPostSettings), registers its webhook automatically when saved with a public https Base URL, and receives POST shipping/easypost/webhook signed with X-Hmac-Signature to update tracking and deliver shipments. Labels are bought from the order (shipping/shipments/{shipmentId}/label, FulfillOrders).

Shipping API

CrestApps.OrchardCore.Shipping.Api maps checkout/{id}/pickup-locations, POST checkout/{id}/shipping-rates, PUT checkout/{id}/shipping, the buyer's me/orders/{orderId}/shipments, and staff orders/{orderId}/shipments, shipments/{shipmentId}/ship and /deliver (FulfillOrders). See the API reference in orchardcore-commerce.

Admin and permissions

Commerce > Shipping (shipping/zones) lists zones in the order they are tried; Try rates (shipping/rates) quotes an address. With Reports, Shipping times (FulfillOrders) and, with Admin Dashboard, the Shipping Times widget.

With Data Pipelines Core on (Report Builder), the Shipping data source (Shipping) has Shipments and ShipmentLines (FulfillOrders) and ShippingZones and ShippingMethods (ManageShipping). Carrier accounts and quoted rates are not exposed. The ShippingReportBuilderReports recipe adds a Shipments by carrier report to the Store group. See orchardcore-report-builder.

Saving a deployment plan with the Shipping zones step returned a 500 before 3.0's fix (#1228); upgrade if you see it.

| Permission | Allows | Default roles |

| --- | --- | --- |

| ManageShipping | Zones, methods and Settings > Commerce > Shipping | Administrator, Store manager |

| FulfillOrders | Shipments on an order's page, labels, and (with Fulfillment Partners) sending orders to partners and Commerce > Fulfillment requests | Administrator, Store manager, Warehouse |

ShippingPermissions moved from the module to CrestApps.OrchardCore.Shipping.Core (same namespace CrestApps.OrchardCore.Shipping), so other modules can check FulfillOrders without referencing the Shipping module.

Product feeds

With Product Feeds on, ShippingProductFeedContributor adds to every feed item Weight (kg or lb, the store's unit) and Length, Width, Height (cm for kilograms, in otherwise) from ShippingPart, and ShippingPrice: the cheapest flat, table or free rate of the zone covering the store's own country (ship-from address, else the store profile) in the item's currency. Carrier rates are never asked; downloads and services get no shipping price. The Merchant Center feed writes shipping_weight, shipping_length, shipping_width and shipping_height; the AI agent feeds use the same values (see orchardcore-products, orchardcore-agentic-commerce).

Not included: return labels, dimensional-weight pricing, postal-code zones (use local delivery), pick lists.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.