This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VP-5616: Change Cart models. Change cart converters.
- Loading branch information
1 parent
af5095f
commit 2768ea7
Showing
8 changed files
with
173 additions
and
33 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
VirtoCommerce.Storefront.Model/Cart/Demo/ConfiguredGroup.cs
This file contains 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,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using VirtoCommerce.Storefront.Model.Catalog; | ||
using VirtoCommerce.Storefront.Model.Common; | ||
|
||
namespace VirtoCommerce.Storefront.Model.Cart.Demo | ||
{ | ||
public class ConfiguredGroup : Entity | ||
{ | ||
public ConfiguredGroup(int quantity, Currency currency, Money extendedPrice, | ||
Money extendedPriceWithTax, Money taxTotal) | ||
{ | ||
Quantity = quantity; | ||
Currency = currency; | ||
ExtendedPrice = extendedPrice; | ||
ExtendedPriceWithTax = extendedPriceWithTax; | ||
TaxTotal = taxTotal; | ||
} | ||
|
||
|
||
public DateTime CreatedDate { get; set; } | ||
|
||
public DateTime? ModifiedDate { get; set; } | ||
|
||
public string CreatedBy { get; set; } | ||
|
||
public string ModifiedBy { get; set; } | ||
|
||
[JsonRequired] | ||
public virtual IList<LineItem> Items { get; set; } = new List<LineItem>(); | ||
|
||
[JsonRequired] | ||
public int Quantity { get; set; } | ||
|
||
#region Pricing | ||
|
||
[JsonRequired] | ||
public Currency Currency { get; set; } | ||
|
||
public Money ListPrice { get; set; } | ||
|
||
public Money ListPriceWithTax { get; set; } | ||
|
||
public Money SalePrice { get; set; } | ||
|
||
public Money SalePriceWithTax { get; set; } | ||
|
||
public Money PlacedPrice { get; set; } | ||
|
||
public Money PlacedPriceWithTax { get; set; } | ||
|
||
[JsonRequired] | ||
public Money ExtendedPrice { get; set; } | ||
|
||
[JsonRequired] | ||
public Money ExtendedPriceWithTax { get; set; } | ||
|
||
#endregion | ||
|
||
#region Taxation | ||
|
||
[JsonRequired] | ||
public Money TaxTotal { get; set; } | ||
|
||
#endregion | ||
|
||
public ICollection<ProductPart> Parts { get; set; } = new List<ProductPart>(); | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
VirtoCommerce.Storefront.Model/Cart/Demo/ConfiguredItem.cs
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
81 changes: 81 additions & 0 deletions
81
VirtoCommerce.Storefront/Domain/Cart/Demo/CartConverter.cs
This file contains 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,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using VirtoCommerce.Storefront.Common; | ||
using VirtoCommerce.Storefront.Model; | ||
using VirtoCommerce.Storefront.Model.Cart; | ||
using VirtoCommerce.Storefront.Model.Cart.Demo; | ||
using VirtoCommerce.Storefront.Model.Catalog; | ||
using VirtoCommerce.Storefront.Model.Common; | ||
using VirtoCommerce.Storefront.Model.Marketing; | ||
using VirtoCommerce.Storefront.Model.Security; | ||
using VirtoCommerce.Storefront.Model.Stores; | ||
using VirtoCommerce.Storefront.Model.Tax; | ||
using cartDto = VirtoCommerce.Storefront.AutoRestClients.CartModuleApi.Models; | ||
|
||
|
||
namespace VirtoCommerce.Storefront.Domain | ||
{ | ||
|
||
public static partial class CartConverter | ||
{ | ||
public static cartDto.DemoCartConfiguredGroup ToConfiguredGroup(this ConfiguredGroup group) | ||
{ | ||
foreach (var lineItem in group.Items) | ||
{ | ||
lineItem.Id = lineItem.Id ?? Guid.NewGuid().ToString("N"); | ||
} | ||
|
||
return new cartDto.DemoCartConfiguredGroup | ||
{ | ||
Id = group.Id ?? Guid.NewGuid().ToString("N"), | ||
ItemIds = group.Items.Select(x => x.Id).ToList(), | ||
CreatedBy = group.CreatedBy, | ||
CreatedDate = group.CreatedDate, | ||
ModifiedBy = group.ModifiedBy, | ||
ModifiedDate = group.ModifiedDate, | ||
Currency = group.Currency.Code, | ||
ExtendedPrice = (double)group.ExtendedPrice.InternalAmount, | ||
ExtendedPriceWithTax = (double)group.ExtendedPriceWithTax.InternalAmount, | ||
ListPrice = (double)group.ListPrice.InternalAmount, | ||
ListPriceWithTax = (double)group.ListPriceWithTax.InternalAmount, | ||
PlacedPrice = (double)group.PlacedPrice.InternalAmount, | ||
PlacedPriceWithTax = (double)group.PlacedPriceWithTax.InternalAmount, | ||
SalePrice = (double)group.SalePrice.InternalAmount, | ||
SalePriceWithTax = (double)group.SalePriceWithTax.InternalAmount, | ||
TaxTotal = (double)group.TaxTotal.InternalAmount, | ||
Quantity = group.Quantity | ||
}; | ||
} | ||
|
||
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)) | ||
{ | ||
Id = group.Id, | ||
CreatedBy = group.CreatedBy, | ||
CreatedDate = group.CreatedDate ?? DateTime.UtcNow, | ||
ModifiedBy = group.ModifiedBy, | ||
ModifiedDate = group.ModifiedDate, | ||
ListPrice = new Money(group.ListPrice ?? 0, cart.Currency), | ||
ListPriceWithTax = new Money(group.ListPriceWithTax ?? 0, cart.Currency), | ||
SalePrice = new Money(group.SalePrice ?? 0, cart.Currency), | ||
SalePriceWithTax = new Money(group.SalePriceWithTax ?? 0, cart.Currency), | ||
PlacedPrice = new Money(group.PlacedPrice ?? 0, cart.Currency), | ||
PlacedPriceWithTax = new Money(group.PlacedPriceWithTax ?? 0, cart.Currency), | ||
Currency = cart.Currency, | ||
|
||
}; | ||
|
||
foreach (var item in group.ItemIds.Select(id => cart.Items.First(x => x.Id == id))) | ||
{ | ||
result.Items.Add(item); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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