Skip to content

Commit 245f981

Browse files
committed
Added an article for order number customization
1 parent 1195e35 commit 245f981

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

15/umbraco-commerce/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* [List of notification events](key-concepts/events/list-of-notification-events.md)
7171
* [Fluent API](key-concepts/fluent-api.md)
7272
* [Order Calculation State](key-concepts/order-calculation-state.md)
73+
* [Order Number Customization](key-concepts/order-number-customization.md)
7374
* [Payment Forms](key-concepts/payment-forms.md)
7475
* [Payment Providers](key-concepts/payment-providers.md)
7576
* [Pipelines](key-concepts/pipelines.md)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
description: Learn how to customize the default order number generated in Umbraco Commerce.
3+
---
4+
5+
# Order Number Customization
6+
7+
In Umbraco Commerce, the default order number generation can be customized by implementing the `IOrderNumberGenerator` interface. This interface defines two methods: `GenerateCartNumber(Guid storeId)` and `GenerateOrderNumber(Guid storeId)`, which you can override to create a custom numbering system.​
8+
9+
## Implementing a Custom Order Number Generator
10+
11+
To create a custom order number generator, define a class that implements the `IOrderNumberGenerator` interface:
12+
13+
```cs
14+
using Umbraco.Commerce.Core.Generators;
15+
16+
public class CustomOrderNumberGenerator : IOrderNumberGenerator
17+
{
18+
public string GenerateCartNumber(Guid storeId)
19+
{
20+
// Implement custom logic for cart numbers
21+
}
22+
23+
public string GenerateOrderNumber(Guid storeId)
24+
{
25+
// Implement custom logic for order numbers
26+
}
27+
}
28+
```
29+
30+
## Registering the Custom Implementation
31+
32+
After creating your custom generator, register it in `Program.cs` to replace the default implementation:
33+
34+
```cs
35+
builder.Services.AddUnique<IOrderNumberGenerator, MyOrderNumberGenerator>();
36+
```
37+
38+
The `AddUnique` method ensures that your custom generator replaces the default `IOrderNumberGenerator`. For more details on dependency injection, see the [Dependency Injection](dependency-injection.md) article.
39+
40+
## Important Considerations
41+
42+
Before implementing a custom order number generator, be aware of the following:
43+
44+
- **Performance Implications:** Sequential order numbers may require database access to ensure uniqueness, which can become a performance bottleneck under heavy load. The default Umbraco Commerce generator uses a timestamp and random seed based algorithm to create numbers in memory, avoiding database hits.
45+
- **Order Number Gaps:** In Umbraco Commerce, order numbers are generated before redirecting to the payment gateway. If a customer cancels or modifies their order after an order number has been assigned, a new number is generated for the subsequent attempt, leading to gaps in the sequence. This behavior can be problematic if sequential numbering is used for official records like VAT receipts, as such records typically require continuous sequences without gaps.
46+
- **Accounting Considerations:** Umbraco Commerce is not designed as an accounting platform. If strict sequential numbering is required for accounting purposes, it is recommended to integrate with a dedicated accounting system to handle such requirements.
47+
48+
By understanding these factors, you can implement a custom order number generator that aligns with your specific requirements while maintaining optimal performance and compliance.

0 commit comments

Comments
 (0)