CrestApps Products
Products (new in CrestApps.OrchardCore 3.0) turns any content type into a product by attaching ProductPart. It owns prices, currencies, variants, the sellable snapshot, the price seam and the front-end product listing. It never calculates tax or takes payment.
Where it fits in the commerce suite
| Module | Relationship |
| --- | --- |
| Commerce (orchardcore-commerce) | Required shell |
| Carts, Orders (orchardcore-carts, orchardcore-orders) | Sell products with one-time prices through a cart |
| Subscriptions (orchardcore-subscriptions) | Sells products with recurring prices; plan types carry the Product part |
| Inventory (orchardcore-inventory) | Implements IProductAvailabilityProvider and the In stock filter |
| Markets (orchardcore-markets) | Implements IShopperCurrency and IProductSaleRestriction |
| Shipping (orchardcore-shipping) | Adds weights and classes through ShippingPart |
| Taxation (orchardcore-taxation) | Classifies products through TaxationPart; ProductTaxableItemProvider |
| Accounts B2B (CrestApps.OrchardCore.Accounts.B2B, replaces Companies) | Implements IBuyerPriceProvider for business account price lists |
| Learning Commerce (orchardcore-learning) | Puts ProductPart and LearningProductPart on courses and learning paths; a paid order enrolls the buyer or gives an account course seats |
Features
| Feature ID | Name | Depends on |
| --- | --- | --- |
| CrestApps.OrchardCore.Products | Products | Commerce |
| CrestApps.OrchardCore.Products.Listing | Product Listing | Products, OrchardCore.Contents, OrchardCore.Title, OrchardCore.Autoroute |
| CrestApps.OrchardCore.Products.Recommendations | Product Recommendations | Product Listing, Resources |
| CrestApps.OrchardCore.Products.Comparison | Product Comparison | Product Listing |
| CrestApps.OrchardCore.Products.Grouped | Grouped Products | Product Listing, Resources |
| CrestApps.OrchardCore.Products.Bundles | Product Bundles | Product Listing, Resources |
| CrestApps.OrchardCore.Products.Feeds | Product Feeds | Products |
| CrestApps.OrchardCore.Products.Api | Catalog API | Product Listing |
| CrestApps.OrchardCore.Products.Lucene | Product Search (Lucene) | Product Listing, OrchardCore.Lucene |
| CrestApps.OrchardCore.Products.Elasticsearch | Product Search (Elasticsearch) | Product Listing, OrchardCore.Elasticsearch |
| CrestApps.OrchardCore.Products.AzureAI | Product Search (Azure AI Search) | Product Listing, OrchardCore.Indexing, OrchardCore.AzureAI |
Guidelines
- Install
CrestApps.OrchardCore.Products(and any search module package) in the web/startup project. - Resolve prices through
IPriceResolverand sellable data throughIProductSnapshotResolver; never readProductPart.Pricedirectly to charge. - Prices are
decimaland always travel with their currency (PriceResult). - A product owns its currency; only Markets converts into a shopper's currency.
- Sales mode and price rules are enforced on the server: a snapshot is refused for a product that can't be bought.
- All recipe JSON must be wrapped in
{ "steps": [...] }. - All C# classes must use the
sealedmodifier, except View Models.
ProductPart
| Property | Notes |
| --- | --- |
| Price (decimal?) | In the product's own currency; required when it can be bought or its price shown |
| Currency | ISO 4217; falls back to ProductPartSettings.DefaultCurrency |
| Sku, CompareAtPrice | Optional; compare-at is shown struck through when higher |
| IsPurchasable | Used when the type's sales mode is PerItem |
| PriceDisplay | Used when the type allows a per-item override |
| Featured, Position | Merchandising order for every listing |
| SalePrice, SaleStartsUtc, SaleEndsUtc | Scheduled sale |
| MinQuantity, MaxQuantity, QuantityStep, PriceTiers, RoleDiscounts | Quantity rules and volume or role discounts |
| AddOns | ProductAddOn text or checkbox extras priced per unit, per person or as a percent |
| ExternalUrl, ExternalButtonText | External product; can't be bought here |
ProductPartSettings: Type (ProductType: Undefined, Good, Service, Digital), DefaultCurrency, SalesMode (Purchasable, ListingOnly, PerItem), PriceDisplay (Show, OnRequest, Hidden), OnRequestLabel, AllowPriceDisplayOverride, PriceOptional (a product of the type may be saved without a price; such a product cannot be bought and shows no price, CanBePurchased false and GetPriceDisplay Hidden; Learning Commerce turns it on for courses and learning paths). ProductPart and its settings live in CrestApps.OrchardCore.Products.Core (namespace CrestApps.OrchardCore.Products.Core.Models).
internal sealed class ProductTypeMigrations : DataMigration
{
private readonly IContentDefinitionManager _contentDefinitionManager;
public ProductTypeMigrations(IContentDefinitionManager contentDefinitionManager)
{
_contentDefinitionManager = contentDefinitionManager;
}
public async Task<int> CreateAsync()
{
await _contentDefinitionManager.AlterTypeDefinitionAsync("Mug", type => type
.Creatable()
.Listable()
.WithPart("TitlePart")
.WithPart("ProductPart", part => part
.WithSettings(new ProductPartSettings
{
Type = ProductType.Good,
DefaultCurrency = "USD",
SalesMode = ProductSalesMode.Purchasable,
})));
return 1;
}
}
The same type in a recipe, with a product item:
{
"steps": [
{
"name": "ContentDefinition",
"ContentTypes": [
{
"Name": "Mug",
"DisplayName": "Mug",
"Settings": {
"ContentTypeSettings": { "Creatable": true, "Listable": true, "Draftable": true }
},
"ContentTypePartDefinitionRecords": [
{ "PartName": "TitlePart", "Name": "TitlePart", "Settings": {} },
{
"PartName": "ProductPart",
"Name": "ProductPart",
"Settings": {
"ProductPartSettings": { "Type": "Good", "DefaultCurrency": "USD", "SalesMode": "Purchasable", "PriceDisplay": "Show" },
"ProductPageSettings": { "ShowDetails": true }
}
}
]
}
],
"ContentParts": []
},
{
"name": "content",
"data": [
{
"ContentItemId": "mug00000000000000000000001",
"ContentType": "Mug",
"DisplayText": "Contoso mug",
"Published": true,
"Latest": true,
"TitlePart": { "Title": "Contoso mug" },
"ProductPart": { "Price": 12, "Currency": "USD", "Sku": "MUG-01", "IsPurchasable": true }
}
]
}
]
}
With CrestApps.OrchardCore.Recipes enabled, JSON Schema is contributed for ProductPart and the Currencies step (see orchardcore-crestapps-recipes).
Currencies
Commerce > Currencies manages the ISO codes editors may pick; new tenants are seeded with USD, EUR and GBP. The catalog feeds ProductPart.Currency, ProductPartSettings.DefaultCurrency and SubscriptionSettings.Currency.
{
"steps": [
{
"name": "Currencies",
"Currencies": [
{ "Name": "USD", "DisplayName": "US Dollar" },
{ "Name": "CAD", "DisplayName": "Canadian Dollar" }
]
}
]
}
A Currencies deployment step exports the catalog.
Several prices and variants
ProductPricePart(Product prices) holdsPricesofProductPrice:PriceId(stable for life),Name,Currency,Amount,Kind(one-time or recurring),Interval,BillingDuration,BillingCycleLimit,TrialDays,StartDayDelay,SetupFee,AllowCustomAmountwithMinimumAmountandMaximumAmount,AllowQuantitywithMaximumQuantity,IsDefault,IsActive,EffectiveFromUtc,EffectiveToUtc. A recurring price makes a product subscribable. Rules are enforced when the price is resolved; withdrawing a price deactivates it. A product without prices sells atProductPart.Price.ProductVariantsPartsells one product in versions. Option names belong to the type (ProductVariantsPartSettings.Options, each optionally filterable); each product holds its values and oneProductVariantper combination (VariantId, values, optionalSku,Price,CompareAtPrice,SalePrice,ImagePath,Enabled). The snapshot resolver refuses a variant product without an enabledVariantId, and a variant's own price wins over the prices list.
The sellable snapshot and price seams
| Type | Role |
| --- | --- |
| ISellableProduct | Immutable snapshot: item id and version, type, SKU, title, unit price, currency, product type, tax codes, variant |
| IProductSnapshotResolver | Resolves the snapshot from a ProductSnapshotContext (item, currency, quantity, SKU, variant); returns none when it can't be bought |
| IPriceResolver | Returns a currency-tagged PriceResult (UnitPrice, Currency, Quantity, Subtotal); applies variants, sales, volume and role discounts, buyer prices and market conversion |
| IBuyerPriceProvider | Gives the current buyer their own unit price |
| IProductAvailabilityProvider | Says how many can be bought (Inventory implements it) |
| IProductSaleRestriction | Says why a product can't be sold to this shopper (see orchardcore-markets) |
| IShopperCurrency | Shopper currency and conversion (see orchardcore-markets) |
A buyer-specific price, such as a members' discount:
public sealed class MemberPriceProvider : IBuyerPriceProvider
{
private readonly IHttpContextAccessor _httpContextAccessor;
public MemberPriceProvider(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public ValueTask<decimal?> GetUnitPriceAsync(BuyerPriceContext context, CancellationToken cancellationToken = default)
{
if (_httpContextAccessor.HttpContext?.User?.IsInRole("Member") == true)
{
return ValueTask.FromResult<decimal?>(decimal.Round(context.UnitPrice * 0.9m, 2));
}
return ValueTask.FromResult<decimal?>(null);
}
}
Register with services.AddScoped<IBuyerPriceProvider, MemberPriceProvider>();. Product feeds never ask buyer price providers. Replace IPriceResolver only for a whole new pricing engine.
Product Listing
Create a Product Listing content item (ProductListing type) from Commerce > Product Listings. Fields on a product type gain Product listing settings (Filterable, Sortable, Searchable, Show on product cards, Show in specifications, labels, units, swatch colors). Filters are GET query values, so every state is a bookmarkable URL; q, sort, view, page and page-size are reserved. Each published product has one search record in the tenant database; a listing can instead search a Lucene, Elasticsearch or Azure AI Search index of the ProductSearch type, with database fallback.
Extension points:
| To | Use |
| --- | --- |
| Add data to a product's search record | IProductSearchDocumentContributor.ContributeAsync(contentItem, document) |
| Offer that data as an automatic filter or sort | IProductListingEntryProvider |
| Support another field type | IProductAttributeValueProvider (with FieldValueReader) |
| Rebuild records when something else changes | IProductSearchIndexRefresher.RefreshAsync(contentItemIds) or RequestRebuildAsync() |
| Draw a filter differently | Register a style in ProductFacetStyleOptions and add a ProductFacet-{Style} template |
| Add a button to product cards and pages | A display driver placing a shape at Location("ProductAction", "Actions") |
| Add another search server | IProductIndexSearchService under the provider name, plus a ProductSearchIndexProfileHandlerBase |
public sealed class GiftWrapActionDriver : ContentPartDisplayDriver<ProductPart>
{
public override IDisplayResult Display(ProductPart part, BuildPartDisplayContext context)
=> Initialize<GiftWrapActionViewModel>("GiftWrapAction", model => model.ContentItemId = part.ContentItem.ContentItemId)
.Location("ProductAction", "Actions");
}
Listing configuration, theming shapes, search servers and SEO are in references/product-listing.md. Merchandising features, feeds, import and the Catalog API are in references/merchandising-and-feeds.md.
Report Builder data source and structured data
- With Data Pipelines Core (
OrchardCore.DataPipelines.Core) on, as the Report Builder does, Products registers the Products data source (Products) withProducts,ProductVariantsandProductPrices; Product Bundles addsProductBundleItemsand Product Listing addsProductAttributes. It uses content permissions (View content per product type; latest versions, drafts included, for types the user may edit), so rows are never grouped in the database. Order lines join onProducts/Products/ContentItemIdandProducts/ProductVariants/VariantId. Seeorchardcore-report-builder. - With Advanced SEO (
CrestApps.OrchardCore.Seo) on,ProductStructuredDataProviderpublishes everyProductPartitem as a schema.orgProductnode (sku, andbrand,gtin,mpnfrom the feed part) with oneOffer(current price,priceCurrency, inventoryavailability,itemCondition,priceValidUntilfor a sale with an end date) or anAggregateOfferfor variants; hidden, on-request and recurring prices publish no offer. Reviews addsaggregateRating. See orchardcore-advanced-seo.
Samples
| Recipe | Creates |
| --- | --- |
| Product listing: online store sample | Store Product type, 30 products, a Shop listing at /shop, carts, orders, customers, stock, shipping zones, reviews and coupons |
| Product listing: real estate sample | Property type listed but never sold, a Homes for sale listing at /homes |
| Product listing: vehicle dealership sample | Vehicle type, some sold online, a Vehicles listing at /vehicles |
The samples need a Bootstrap 5 front-end theme such as TheTheme.
Permissions
Products use Orchard Core content permissions. ManageProductFeeds (Product Feeds) opens Settings > Commerce > Product feeds.
For other modules' line editors (such as an invoice's product picker), GET {admin}/api/crestapps/products/{contentItemId}/line (route CrestApps.Products.ProductLine, needs Edit content) returns the product as a document line: id, name, sku, price, currency and taxCategoryCode (when the Taxation part is taxable).
Upgrading within the 3.0 line
IProductPositionProviderwas removed; useProductPart.FeaturedandProductPart.Position, or setProductSearchDocument.Positionfrom a contributor.- The built-in
/ServicePlanspage was removed; plans list through a Product Listing. - Money is
decimaleverywhere (ProductPart.Price), andProductPartmoved toCrestApps.OrchardCore.Products.Core(stored content is unaffected). - The product picker search endpoint (
Admin/api/crestapps/products/search) moved to the Product Listing feature. CurrencyScalemoved toCrestApps.OrchardCore.Abstractions(namespaceCrestApps.OrchardCore.Currencies), so the catalog rounds prices without referencing payments.- A product picked on a bundle with the How many box left empty now counts as one instead of failing validation.
ProductFeedItemand the feed contracts moved toCrestApps.OrchardCore.Products.Core.Feeds(IProductFeedService,IProductFeedItemContributor,ProductFeedItemIds,IProductItemIdResolver), so other modules read the feed without referencing the Products module. See references/merchandising-and-feeds.md.- The
ProductPriceParteditor shows and takes offer dates (EffectiveFrom,EffectiveTo) in the site's time zone; they are stored in UTC as before. - A product page without images no longer shows an empty picture frame.