目录
#region web私有方法
/// <summary>
/// </summary>
static List<CartItemModel> GenerateCartItem(IEnumerable<ShoppingCartItem> cartItems)
{
var productService = _iProductService;
var groupCartByProduct = cartItems.GroupBy(i => i.ProductId).ToList();//按照商品分组
var products = cartItems.Select(item =>
{
var product = productService.GetProduct(item.ProductId);
var sku = productService.GetSku(item.SkuId);
ProductTypeInfo typeInfo = ServiceProvider.Instance<ITypeService>.Create.GetTypeByProductId(item.ProductId);
string colorAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
string sizeAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
string shopBranchName = "";
if (item.ShopBranchId.HasValue && item.ShopBranchId.Value > 0)
{
var shopBranchInfo = _iShopBranchService.GetShopBranchById(item.ShopBranchId.Value);
if (shopBranchInfo != null)
shopBranchName = shopBranchInfo.ShopBranchName;
}
#region 阶梯价--张宇枫
var price = sku.SalePrice;
if (product.IsOpenLadder)
{
var quantity =
groupCartByProduct.Where(i => i.Key == item.ProductId)
.ToList()
.Sum(cartitem => cartitem.Sum(i => i.Quantity));
price = ProductManagerApplication.GetProductLadderPrice(item.ProductId, quantity);
}
#endregion
string skuDetails = "";
if (!string.IsNullOrWhiteSpace(sku.Size))
{
if (!string.IsNullOrWhiteSpace(skuDetails))
{
skuDetails += "、";
}
skuDetails += sku.Size;
}
if (!string.IsNullOrWhiteSpace(sku.Color))
{
if (!string.IsNullOrWhiteSpace(skuDetails))
{
skuDetails += "、";
}
skuDetails += sku.Color;
}
if (!string.IsNullOrWhiteSpace(sku.Version))
{
if (!string.IsNullOrWhiteSpace(skuDetails))
{
skuDetails += "、";
}
skuDetails += sku.Version;
}
return new CartItemModel()
{
skuId = item.SkuId,
id = product.Id,
imgUrl = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_100),
name = product.ProductName,
price = price,
shopId = product.ShopId,
count = item.Quantity,
productCode = product.ProductCode,
color = sku.Color,
size = sku.Size,
version = sku.Version,
skuDetails = skuDetails,
IsSelf = product.Himall_Shops.IsSelf,
ColorAlias = colorAlias,
SizeAlias = sizeAlias,
VersionAlias = versionAlias,
ShopBranchId = item.ShopBranchId,
ShopBranchName = shopBranchName,
IsOpenLadder = product.IsOpenLadder,
FreightTemplateId = product.FreightTemplateId
};
}).ToList();
return products;
}
/// <summary>