Skip to content

Commit

Permalink
feat: add section Id
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev committed Nov 26, 2024
1 parent dc05f46 commit cc695a4
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using VirtoCommerce.XCart.Core.Commands.BaseCommands;

namespace VirtoCommerce.XCart.Core.Commands;

public class ChangeCartConfiguredItemCommand : CartCommand
{
public string LineItemId { get; set; }

public int? Quantity { get; set; }
}
38 changes: 25 additions & 13 deletions src/VirtoCommerce.XCart.Core/ConfiguredLineItemContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public class ConfiguredLineItemContainer : ICloneable
public IList<string> ProductsIncludeFields { get; set; }

public CartProduct ConfigurableProduct { get; set; }
public IList<LineItem> Items { get; set; } = new List<LineItem>();

public LineItem AddItem(CartProduct cartProduct, int quantity)
private IList<SectionLineItem> _items { get; set; } = new List<SectionLineItem>();

public LineItem AddItem(CartProduct cartProduct, int quantity, string sectionId)
{
var lineItem = AbstractTypeFactory<LineItem>.TryCreateInstance();
lineItem.ProductId = cartProduct.Id;
Expand Down Expand Up @@ -51,7 +52,11 @@ public LineItem AddItem(CartProduct cartProduct, int quantity)
lineItem.ExtendedPrice = lineItem.PlacedPrice * lineItem.Quantity;
}

Items.Add(lineItem);
_items.Add(new SectionLineItem
{
Item = lineItem,
SectionId = sectionId,
});

return lineItem;
}
Expand Down Expand Up @@ -83,18 +88,19 @@ public ExpConfigurationLineItem CreateConfiguredLineItem()
lineItem.VendorId = ConfigurableProduct.Product.Vendor;

// create sub items
lineItem.ConfigurationItems = Items
lineItem.ConfigurationItems = _items
.Select(x =>
{
var subItem = AbstractTypeFactory<ConfigurationItem>.TryCreateInstance();

subItem.ProductId = x.ProductId;
subItem.Name = x.Name;
subItem.Sku = x.Sku;
subItem.ImageUrl = x.ImageUrl;
subItem.Quantity = x.Quantity;
subItem.CatalogId = x.CatalogId;
subItem.CategoryId = x.CategoryId;
subItem.SectionId = x.SectionId;
subItem.ProductId = x.Item.ProductId;
subItem.Name = x.Item.Name;
subItem.Sku = x.Item.Sku;
subItem.ImageUrl = x.Item.ImageUrl;
subItem.Quantity = x.Item.Quantity;
subItem.CatalogId = x.Item.CatalogId;
subItem.CategoryId = x.Item.CategoryId;

return subItem;
})
Expand All @@ -119,8 +125,8 @@ public void UpdatePrice(LineItem lineItem)
{
var configurableProductPrice = ConfigurableProduct.Price ?? new Xapi.Core.Models.ProductPrice(Currency);

lineItem.ListPrice = Items.Sum(x => x.ListPrice * x.Quantity) + configurableProductPrice.ListPrice.Amount;
lineItem.SalePrice = Items.Sum(x => x.SalePrice * x.Quantity) + configurableProductPrice.SalePrice.Amount;
lineItem.ListPrice = _items.Select(x => x.Item).Sum(x => x.ListPrice * x.Quantity) + configurableProductPrice.ListPrice.Amount;
lineItem.SalePrice = _items.Select(x => x.Item).Sum(x => x.SalePrice * x.Quantity) + configurableProductPrice.SalePrice.Amount;

lineItem.DiscountAmount = Math.Max(0, lineItem.ListPrice - lineItem.SalePrice);
lineItem.PlacedPrice = lineItem.ListPrice - lineItem.DiscountAmount;
Expand All @@ -144,5 +150,11 @@ public object Clone()
{
return MemberwiseClone();
}

private class SectionLineItem
{
public string SectionId { get; set; }
public LineItem Item { get; set; }
}
}
}
6 changes: 6 additions & 0 deletions src/VirtoCommerce.XCart.Core/ExpConfigurationLineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ namespace VirtoCommerce.XCart.Core
{
public class ExpConfigurationLineItem
{
public ExpConfigurationLineItem()
{

}

public string StoreId { get; set; }
public string UserId { get; set; }
public string CultureName { get; set; }


public LineItem Item { get; set; }
public Currency Currency { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using VirtoCommerce.CartModule.Core.Model;
using VirtoCommerce.CartModule.Core.Model;
using VirtoCommerce.Xapi.Core.Schemas;

namespace VirtoCommerce.XCart.Core.Schemas
Expand All @@ -9,6 +9,9 @@ public CartConfigurationItemType()
{
Field(x => x.Id, nullable: false).Description("Configuration item ID");
Field(x => x.Name, nullable: true).Description("Configuration item name");
Field(x => x.SectionId, nullable: true).Description("Configuration item section ID");
Field(x => x.ProductId, nullable: true).Description("Configuration item product ID");
Field(x => x.Quantity, nullable: true).Description("Configuration item quantity");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.Xapi.Core" Version="3.809.0" />
<PackageReference Include="VirtoCommerce.XCatalog.Core" Version="3.817.0" />
<PackageReference Include="VirtoCommerce.CartModule.Core" Version="3.820.0" />
<PackageReference Include="VirtoCommerce.CartModule.Core" Version="3.821.0-alpha.712-vcst-2093" />
<PackageReference Include="VirtoCommerce.PaymentModule.Core" Version="3.804.0" />
<PackageReference Include="VirtoCommerce.ShippingModule.Core" Version="3.802.0" />
<PackageReference Include="VirtoCommerce.InventoryModule.Core" Version="3.805.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ public async Task<ExpConfigurationLineItem> Handle(CreateConfiguredLineItemComma
productsRequest.LoadInventory = false;
var products = await _cartProductService.GetCartProductsByIdsAsync(productsRequest);

foreach (var productOption in request.ConfigurationSections.Select(x => x.Value))
foreach (var section in request.ConfigurationSections)
{
var productOption = section.Value;
var selectedProduct = products.FirstOrDefault(x => x.Product.Id == productOption.ProductId);
if (selectedProduct == null)
{
throw new OperationCanceledException($"Product with id {productOption.ProductId} not found");
}

_ = container.AddItem(selectedProduct, productOption.Quantity);
_ = container.AddItem(selectedProduct, productOption.Quantity, section.SectionId);
}

var configuredItem = container.CreateConfiguredLineItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<ProductConfigurationQueryResponse> Handle(GetProductConfigurat
{
if (productByIds.TryGetValue(option.ProductId, out var cartProduct))
{
var item = container.AddItem(cartProduct, option.Quantity);
var item = container.AddItem(cartProduct, option.Quantity, section.Id);
item.Id = option.Id;

var expConfigurationLineItem = new ExpConfigurationLineItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private async Task UpdateConfiguredLineItemPrice(CartAggregate aggregate)
var product = configProducts.FirstOrDefault(x => x.Product.Id == configurationItem.ProductId);
if (product != null)
{
contaner.AddItem(product, configurationItem.Quantity);
contaner.AddItem(product, configurationItem.Quantity, configurationItem.SectionId);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/VirtoCommerce.XCart.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<platformVersion>3.867.0</platformVersion>
<dependencies>
<dependency id="VirtoCommerce.Cart" version="3.820.0" />
<dependency id="VirtoCommerce.Cart" version="3.821.0" />
<dependency id="VirtoCommerce.Inventory" version="3.805.0" />
<dependency id="VirtoCommerce.Marketing" version="3.812.0" />
<dependency id="VirtoCommerce.Payment" version="3.804.0" />
Expand Down

0 comments on commit cc695a4

Please sign in to comment.