-
Notifications
You must be signed in to change notification settings - Fork 813
Added an article for replacing the Umbraco Commerce order number generator #6983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
245f981
Added an article for order number customization
eshanrnh 234217c
Incorporated the review comments
eshanrnh e7c2b18
Added filename to code block
eshanrnh d68456f
Incorporated review comments
eshanrnh 9d73ef7
Update 15/umbraco-commerce/how-to-guides/order-number-customization.md
eshanrnh d6eb859
Update 15/umbraco-commerce/how-to-guides/order-number-customization.md
eshanrnh 70b80ab
Incorporated comment
eshanrnh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
15/umbraco-commerce/how-to-guides/order-number-customization.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| --- | ||
| description: Learn how to customize the default order number generated in Umbraco Commerce. | ||
| --- | ||
|
|
||
| # Order Number Customization | ||
|
|
||
| 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. | ||
|
|
||
| ## Implementing a Custom Order Number Generator | ||
|
|
||
| To create a custom order number generator, define a class that implements the `IOrderNumberGenerator` interface, for example, `CustomOrderNumberGenerator.cs`: | ||
|
|
||
| {% code title="CustomOrderNumberGenerator.cs" %} | ||
|
|
||
| ```csharp | ||
| using Umbraco.Commerce.Core.Generators; | ||
|
|
||
| public class CustomOrderNumberGenerator : IOrderNumberGenerator | ||
| { | ||
| public string GenerateCartNumber(Guid storeId) | ||
| { | ||
| // Implement custom logic for cart numbers | ||
| } | ||
|
|
||
| public string GenerateOrderNumber(Guid storeId) | ||
| { | ||
| // Implement custom logic for order numbers | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| ## Registering the Custom Implementation | ||
|
|
||
| After creating your custom generator, register it in `Program.cs` to replace the default implementation: | ||
|
|
||
| ```cs | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| builder.Services.AddUnique<IOrderNumberGenerator, MyOrderNumberGenerator>(); | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| ## Important Considerations | ||
|
|
||
| Before implementing a custom order number generator, be aware of the following: | ||
|
|
||
| - **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. | ||
| - **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. | ||
| - **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. | ||
|
|
||
| By understanding these factors, you can implement a custom order number generator that aligns with your specific requirements while maintaining optimal performance and compliance. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.