Releases: VirtoCommerce/vc-module-experience-api
Releases · VirtoCommerce/vc-module-experience-api
3.833.4
🐞 Bug fixes
- pass Cart currency to Tax evaluation context
3.800.13
3.844.0
3.800.12
🎯 Development
- don't resolve main FFC if in stock quantity = 0
3.833.3
🎯 Development
- don't resolve main FFC if in stock quantity = 0
3.843.0
🎯 Development
- (Adds a new FindExistingLineItemBeforeAdd method. It is responsible for finding an existing line item before adding a new one. If the method returns the line item, the new line item should be merged with the existing one.)
Use a Complex Key for Determining Line Item Uniqueness in the Cart
Overview
When adding new line items to the cart, especially when dealing with dynamic properties (e.g., service configurations, T-shirt prints), it's important to ensure that duplicate items are not added. By default, line items are identified by their product ID. However, this implementation requires checking both the product ID and dynamic properties to determine if the line item already exists.
Implementation Details
Steps to Use Dynamic Properties for Adding New Line Items:
- Create a Custom VC Module: Set up a new module and add a dependency on VirtoCommerce.XCart or relevant packages.
- Extend CartAggregate: Create a new class, CartAggregateEx, that extends the CartAggregate class.
- Override FindExistingLineItemBeforeAdd: Implement the custom logic to compare dynamic properties.
override protected LineItem FindExistingLineItemBeforeAdd(string newProductId, CartProduct newProduct, IList<DynamicPropertyValue> newDynamicProperties)
{
var newDynamicPropertiesKey = string.Join(",", newDynamicProperties?.Select(dp => $"{dp.Name}:{dp.Value}"));
return LineItems.FirstOrDefault(
x => x.ProductId == newProductId &&
string.Join(",", x.DynamicProperties
.Select(dp => $"{dp.Name}:{dp?.Values?.FirstOrDefault()}")) == newDynamicPropertiesKey);
}
- Register the Extension: Update the service registration to use the new CartAggregateEx class.
services.AddTransient<CartAggregate, CartAggregateEx>();