How we added B2B to nopCommerce without editing a single core file
Trade buyers don't shop like retail customers. They know their part numbers, they have negotiated prices, they need someone else to approve big orders, and they pay on account. nopCommerce is a solid .NET store, but out of the box it's built for retail.
We spent the last months building Cartenvo B2B, a trade theme plus five plugins that add quick order by SKU, company accounts, contract pricing, order approvals and pay on account. One rule shaped everything: we never edit a single nopCommerce file. Store owners must be able to upgrade nopCommerce without merging our changes.
Here's what that looked like in practice, and a few things that bit us along the way.
The order of preference
When we need to change behaviour, we reach for these in order and stop at the first one that works:
- An event (
IConsumer<EntityInsertedEvent<Order>>and friends) - A widget zone
- A theme view override
- An action or result filter
- A rule in our own shared pipeline
Overriding a view is cheap today and expensive on every upgrade, so we keep a list of every view we override and restyle with CSS wherever both versions' markup allows.
One plugin owns the service replacements
Contract prices, cart rules and back orders all need to change how nopCommerce prices and validates the cart. If three plugins each replaced IPriceCalculationService or IShoppingCartService, the last one registered would win and the others would silently stop working.
So exactly one plugin (our Toolkit) decorates nopCommerce services, and it exposes small extension points that the other plugins implement:
public interface IPriceSource { int Order { get; } // lower is asked first string Name { get; } // for diagnostics, e.g. "Contract price" Task<PriceCandidate> GetPriceAsync(PriceContext context); } public interface ICartRule { int Order { get; } Task<IList<string>> ValidateItemAsync(CartItemRuleContext context); Task<IList<string>> ValidateCartAsync(CartRuleContext context); Task<bool> CanModifyItemAsync(ShoppingCartItem item); } The Toolkit ships its own rules (pack sizes, minimum order value), and the accounts plugin adds a price source for company prices and cart rules for company buying and approvals. Each is a plain services.AddScoped<IPriceSource, CompanyPriceSource>(), and the Toolkit asks all of them in order.
One lesson here: work out the company from the customer you're given, never from the signed-in user. When a manager approves an order, the cart being priced belongs to the buyer who placed it, not to the manager clicking the button. Every context object carries the customer for exactly that reason.
Two nopCommerce versions, one codebase
We support nopCommerce 5.00 (.NET 10) and 4.90 (.NET 9). The differences between them live in one folder behind interfaces like IPlatformInfo. A CI check fails the build if #if NOP490 appears anywhere else, which keeps version checks from spreading through the code.
For shipping, nopCommerce's uploader reads an uploadedItems.json in the zip and installs only the entries whose SupportedVersion matches the running store. So one download holds both builds and the store picks the right one; customers never have to guess which zip they need.
Things that bit us
Migration timestamps must be unique across plugins. nopCommerce records a FluentMigrator migration by its timestamp alone. Two plugins with a migration at the same timestamp means whichever installs second never runs its migration, and there's no error. We now have a check that scans every plugin for duplicates.
Plugin load order matters. If plugin B references types from plugin A, A's assembly must load first or the store won't start. nopCommerce loads plugins by DisplayOrder in plugin.json, so dependencies get lower numbers, and a convention test enforces it. References between our plugins use Private="false" so each assembly is loaded exactly once.
Three databases means no raw SQL. Store owners run SQL Server, MySQL and PostgreSQL. Everything goes through IRepository<T> and FluentMigrator, enums are stored as int, and end-to-end tests run against all three databases on both versions.
Retail must never notice. Every B2B feature can be switched off, and guests and retail customers always get standard nopCommerce behaviour. That's easy to promise and easy to break, so it has tests too.
Try it
There's a live demo where you're signed in as a trade buyer: b2b.cartenvo.com. Try pasting a few SKUs into quick order, or look at the company dashboard.
Features, screenshots and licensing are on our website: store.cartenvo.com/themes/cartenvo-b2b.
If you've extended nopCommerce yourself, I'd like to hear how you handled service replacements between plugins. It was the design decision we went back and forth on most.