Skip to content

Commit 7c9d9d3

Browse files
Enforce a bundle id if bundle items are passed
1 parent 372785e commit 7c9d9d3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Umbraco.Commerce.Cart/Web/Api/Controllers/AddToCartUccApiController.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,26 @@ public async Task<IActionResult> AddToCart(
3333
{
3434
await umbracoCommerceApi.Uow.ExecuteAsync(async uow =>
3535
{
36+
// If we have bundle items, enforce a bundle reference
37+
var bundleReference = model.BundleItems is { Count: > 0 }
38+
? model.BundleReference ?? Guid.NewGuid().ToString()
39+
: model.BundleReference;
40+
3641
var order = await umbracoCommerceApi.GetOrCreateCurrentOrderAsync(store.Id)!
3742
.AsWritableAsync(uow)
3843
.AddProductAsync(
3944
model.ProductReference,
4045
model.ProductVariantReference,
4146
model.Quantity ?? 1,
4247
model.Properties ?? EMPTY_PROPERTIES,
43-
model.BundleReference);
48+
bundleReference);
4449

4550
if (model.BundleItems is { Count: > 0 })
4651
{
4752
foreach (var bundleItem in model.BundleItems)
4853
{
4954
await order.AddProductToBundleAsync(
50-
model.BundleReference,
55+
bundleReference,
5156
bundleItem.ProductReference,
5257
bundleItem.Quantity ?? 1,
5358
bundleItem.Properties ?? EMPTY_PROPERTIES);

0 commit comments

Comments
 (0)