Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
VP-5616: Debug cart's configured groups cases
Browse files Browse the repository at this point in the history
  • Loading branch information
trueboroda committed Oct 27, 2020
1 parent 6b4af0b commit 937bada
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
18 changes: 13 additions & 5 deletions VirtoCommerce.Storefront.Model/Cart/Demo/ConfiguredGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ namespace VirtoCommerce.Storefront.Model.Cart.Demo
{
public class ConfiguredGroup : Entity
{
public ConfiguredGroup(int quantity, Currency currency, Money extendedPrice,
Money extendedPriceWithTax, Money taxTotal)
public ConfiguredGroup(int quantity, Currency currency, string productId)
{
Id = Guid.NewGuid().ToString("N");
ProductId = productId;
Quantity = quantity;
Currency = currency;
ExtendedPrice = extendedPrice;
ExtendedPriceWithTax = extendedPriceWithTax;
TaxTotal = taxTotal;

ExtendedPrice = new Money(currency);
ExtendedPriceWithTax = new Money(currency);
TaxTotal = new Money(currency);

ListPrice = new Money(currency);
ListPriceWithTax = new Money(currency);
SalePrice = new Money(currency);
SalePriceWithTax = new Money(currency);
PlacedPrice = new Money(currency);
PlacedPriceWithTax = new Money(currency);
}

public string ProductId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<ActionResult<AddItemsToCartResult>> AddItemsToCart([FromBody]

if (configuredGroup == null)
{
configuredGroup = new Model.Cart.Demo.ConfiguredGroup(firstItem.Quantity, WorkContext.CurrentCurrency, new Money(0m, currency), new Money(0m, currency), new Money(0m, currency));
configuredGroup = new Model.Cart.Demo.ConfiguredGroup(firstItem.Quantity, WorkContext.CurrentCurrency, configuredProductId);
cart.ConfiguredGroups.Add(configuredGroup);
}
else
Expand Down
13 changes: 7 additions & 6 deletions VirtoCommerce.Storefront/Domain/Cart/Demo/CartConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ public static cartDto.DemoCartConfiguredGroup ToConfiguredGroup(this ConfiguredG

public static ConfiguredGroup ToConfiguredGroup(this cartDto.DemoCartConfiguredGroup group, ShoppingCart cart)
{
var result = new ConfiguredGroup(
group.Quantity ?? 0, cart.Currency, new Money(group.ExtendedPrice ?? 0, cart.Currency),
new Money(group.ExtendedPriceWithTax ?? 0, cart.Currency),
new Money(group.TaxTotal ?? 0, cart.Currency))
var result = new ConfiguredGroup(group.Quantity ?? 0, cart.Currency, group.ProductId)
{
Id = group.Id,
ProductId = group.ProductId,
Id = group.Id,
CreatedBy = group.CreatedBy,
CreatedDate = group.CreatedDate ?? DateTime.UtcNow,
ModifiedBy = group.ModifiedBy,
ModifiedDate = group.ModifiedDate,

ExtendedPrice = new Money(group.ExtendedPrice ?? 0, cart.Currency),
ExtendedPriceWithTax = new Money(group.ExtendedPriceWithTax ?? 0, cart.Currency),
TaxTotal = new Money(group.TaxTotal ?? 0, cart.Currency),

ListPrice = new Money(group.ListPrice ?? 0, cart.Currency),
ListPriceWithTax = new Money(group.ListPriceWithTax ?? 0, cart.Currency),
SalePrice = new Money(group.SalePrice ?? 0, cart.Currency),
Expand Down
3 changes: 3 additions & 0 deletions VirtoCommerce.Storefront/Domain/Cart/Demo/DemoCartBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ public override Task ChangeItemQuantityAsync(ChangeCartItemQty changeItemQty)

if (configuredGroup != null)
{
configuredGroup.Quantity = changeItemQty.Quantity;

var groupItems = Cart.Items.Where(x => !string.IsNullOrEmpty(x.ConfiguredGropupId) &&
x.ConfiguredGropupId.Equals(configuredGroup.Id)).ToArray();

foreach (var lineItem in groupItems)
{
lineItem.Quantity = changeItemQty.Quantity;
Expand Down

0 comments on commit 937bada

Please sign in to comment.