Orchardcore products

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore products is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for the CrestApps Orchard Core Products module and its search modules. Covers ProductPart and ProductPartSettings (price, currency, SKU, sales mode, price display, PriceOptional), the Currencies catalog, ProductPricePart, ProductVariantsPart, IProductSnapshotResolver, IPriceResolver, IBuyerPri

How to use this skill

Skill file

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

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

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

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

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.