Skip to content

Commit e1f25c4

Browse files
committed
Product bundle: Extended OrderItem by xml formatted bundle item data. Updated frontend order details to show bundle item data.
1 parent 2d8ab12 commit e1f25c4

24 files changed

Lines changed: 449 additions & 124 deletions

File tree

src/Libraries/SmartStore.Core/CommonHelper.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Text.RegularExpressions;
1010
using System.Web;
1111
using SmartStore.Core.ComponentModel;
12+
using SmartStore.Core.Domain.Catalog;
1213
using SmartStore.Core.Domain.Shipping;
1314

1415
namespace SmartStore.Core
@@ -19,14 +20,17 @@ namespace SmartStore.Core
1920
public partial class CommonHelper
2021
{
2122
private static readonly ShippingOptionListTypeConverter s_soListTypeConverter = new ShippingOptionListTypeConverter();
23+
private static readonly ProductBundleDataListTypeConverter _productBundleListTypeConverter = new ProductBundleDataListTypeConverter();
2224
private static readonly Dictionary<Type, TypeConverter> s_customTypeConverters = new Dictionary<Type, TypeConverter>
2325
{
2426
{ typeof(List<int>), new GenericListTypeConverter<int>() },
2527
{ typeof(List<decimal>), new GenericListTypeConverter<decimal>() },
2628
{ typeof(List<string>), new GenericListTypeConverter<string>() },
2729
{ typeof(ShippingOption), new ShippingOptionTypeConverter() },
2830
{ typeof(List<ShippingOption>), s_soListTypeConverter },
29-
{ typeof(IList<ShippingOption>), s_soListTypeConverter }
31+
{ typeof(IList<ShippingOption>), s_soListTypeConverter },
32+
{ typeof(List<ProductBundleData>), _productBundleListTypeConverter },
33+
{ typeof(IList<ProductBundleData>), _productBundleListTypeConverter }
3034
};
3135

3236
/// <summary>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Globalization;
5+
using System.IO;
6+
using System.Text;
7+
using System.Xml.Serialization;
8+
9+
namespace SmartStore.Core.Domain.Catalog
10+
{
11+
public partial class ProductBundleData
12+
{
13+
public string Sku { get; set; }
14+
public string ProductName { get; set; }
15+
public string ProductSeName { get; set; }
16+
public bool VisibleIndividually { get; set; }
17+
public int Quantity { get; set; }
18+
public decimal PriceWithDiscount { get; set; }
19+
public int DisplayOrder { get; set; }
20+
public string AttributesInfo { get; set; }
21+
}
22+
23+
public class ProductBundleDataListTypeConverter : TypeConverter
24+
{
25+
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
26+
{
27+
if (sourceType == typeof(string))
28+
return true;
29+
30+
return base.CanConvertFrom(context, sourceType);
31+
}
32+
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
33+
{
34+
if (value is string)
35+
{
36+
List<ProductBundleData> bundleData = null;
37+
string rawValue = value as string;
38+
39+
if (rawValue.HasValue())
40+
{
41+
try
42+
{
43+
using (var reader = new StringReader(rawValue))
44+
{
45+
var xml = new XmlSerializer(typeof(List<ProductBundleData>));
46+
bundleData = (List<ProductBundleData>)xml.Deserialize(reader);
47+
}
48+
}
49+
catch { }
50+
}
51+
return bundleData;
52+
}
53+
return base.ConvertFrom(context, culture, value);
54+
}
55+
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
56+
{
57+
if (destinationType == typeof(string))
58+
{
59+
var bundleData = value as List<ProductBundleData>;
60+
61+
if (bundleData == null)
62+
return "";
63+
64+
var sb = new StringBuilder();
65+
using (var writer = new StringWriter(sb))
66+
{
67+
var xml = new XmlSerializer(typeof(List<ProductBundleData>));
68+
xml.Serialize(writer, value);
69+
return sb.ToString();
70+
}
71+
}
72+
return base.ConvertTo(context, culture, value, destinationType);
73+
}
74+
}
75+
}

src/Libraries/SmartStore.Core/Domain/Orders/OrderExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Linq;
3-
1+

42
namespace SmartStore.Core.Domain.Orders
53
{
64
public static class OrderExtensions
@@ -19,6 +17,5 @@ public static string GetOrderNumber(this Order order)
1917

2018
return order.OrderNumber;
2119
}
22-
2320
}
2421
}

src/Libraries/SmartStore.Core/Domain/Orders/OrderItem.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public partial class OrderItem : BaseEntity
9292
/// </summary>
9393
public decimal? ItemWeight { get; set; }
9494

95+
/// <summary>
96+
/// Gets or sets extra bundle data
97+
/// </summary>
98+
public string BundleData { get; set; }
99+
95100
/// <summary>
96101
/// Gets the order
97102
/// </summary>

src/Libraries/SmartStore.Core/SmartStore.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
<Compile Include="Data\Hooks\PreUpdateHook.cs" />
140140
<Compile Include="Data\IDbContext.cs" />
141141
<Compile Include="Data\RepositoryExtensions.cs" />
142+
<Compile Include="Domain\Catalog\ProductBundleData.cs" />
142143
<Compile Include="Domain\Catalog\ProductBundleItemAttributeFilter.cs" />
143144
<Compile Include="Domain\Catalog\ProductBundleItem.cs" />
144145
<Compile Include="Domain\Catalog\ProductType.cs" />

src/Libraries/SmartStore.Data/Mapping/Orders/OrderItemMap.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public OrderItemMap()
1111
this.HasKey(orderItem => orderItem.Id);
1212
this.Property(orderItem => orderItem.AttributeDescription);
1313
this.Property(orderItem => orderItem.AttributesXml);
14+
this.Property(orderItem => orderItem.BundleData).IsMaxLength();
1415

1516
this.Property(orderItem => orderItem.UnitPriceInclTax).HasPrecision(18, 4);
1617
this.Property(orderItem => orderItem.UnitPriceExclTax).HasPrecision(18, 4);

src/Libraries/SmartStore.Services/ExportImport/ExportManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@ public virtual string ExportOrdersToXml(IList<Order> orders)
10221022
xmlWriter.WriteElementString("DownloadCount", null, orderItem.DownloadCount.ToString());
10231023
xmlWriter.WriteElementString("IsDownloadActivated", null, orderItem.IsDownloadActivated.ToString());
10241024
xmlWriter.WriteElementString("LicenseDownloadId", null, orderItem.LicenseDownloadId.ToString());
1025+
xmlWriter.WriteElementString("BundleData", null, orderItem.BundleData);
10251026
xmlWriter.WriteEndElement();
10261027
}
10271028
xmlWriter.WriteEndElement();

src/Libraries/SmartStore.Services/Orders/OrderExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
4+
using SmartStore.Core;
5+
using SmartStore.Core.Domain.Catalog;
36
using SmartStore.Core.Domain.Orders;
47

58
namespace SmartStore.Services.Orders
@@ -165,6 +168,24 @@ public static int GetTotalNumberOfDeliveredItems(this OrderItem orderItem)
165168
return result;
166169
}
167170

171+
public static List<ProductBundleData> GetBundleData(this OrderItem orderItem)
172+
{
173+
if (orderItem != null && orderItem.BundleData.HasValue())
174+
{
175+
var data = CommonHelper.To<List<ProductBundleData>>(orderItem.BundleData);
176+
return data;
177+
}
178+
return new List<ProductBundleData>();
179+
}
180+
public static void SetBundleData(this OrderItem orderItem, List<ProductBundleData> bundleData)
181+
{
182+
string rawData = null;
183+
184+
if (bundleData != null && bundleData.Count > 0)
185+
rawData = CommonHelper.To<string>(bundleData);
186+
187+
orderItem.BundleData = rawData;
188+
}
168189

169190
/// <summary>
170191
/// Gets a value indicating whether an order has items to be added to a shipment

src/Libraries/SmartStore.Services/Orders/OrderProcessingService.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using SmartStore.Services.Security;
3131
using SmartStore.Services.Shipping;
3232
using SmartStore.Services.Tax;
33+
using SmartStore.Services.Seo;
3334

3435
namespace SmartStore.Services.Orders
3536
{
@@ -1082,6 +1083,37 @@ public virtual PlaceOrderResult PlaceOrder(ProcessPaymentRequest processPaymentR
10821083
LicenseDownloadId = 0,
10831084
ItemWeight = itemWeight,
10841085
};
1086+
1087+
if (sc.Product.ProductType == ProductType.BundledProduct && sc.ChildItems != null)
1088+
{
1089+
var listBundleData = new List<ProductBundleData>();
1090+
1091+
foreach (var childItem in sc.ChildItems)
1092+
{
1093+
string bundleItemName = childItem.BundleItem.GetLocalized(x => x.Name);
1094+
1095+
var bundleData = new ProductBundleData()
1096+
{
1097+
Sku = childItem.Product.Sku,
1098+
ProductName = (bundleItemName ?? childItem.Product.GetLocalized(x => x.Name)),
1099+
ProductSeName = childItem.Product.GetSeName(),
1100+
VisibleIndividually = childItem.Product.VisibleIndividually,
1101+
Quantity = childItem.BundleItem.Quantity,
1102+
DisplayOrder = childItem.BundleItem.DisplayOrder
1103+
};
1104+
1105+
bundleData.AttributesInfo = _productAttributeFormatter.FormatAttributes(childItem.Product, childItem.AttributesXml, order.Customer,
1106+
renderPrices: false, renderGiftCardAttributes: false, allowHyperlinks: false);
1107+
1108+
decimal bundleItemSubTotalWithDiscountBase = _taxService.GetProductPrice(childItem.Product, _priceCalculationService.GetSubTotal(childItem, true), out taxRate);
1109+
bundleData.PriceWithDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(bundleItemSubTotalWithDiscountBase, _workContext.WorkingCurrency);
1110+
1111+
listBundleData.Add(bundleData);
1112+
}
1113+
1114+
orderItem.SetBundleData(listBundleData);
1115+
}
1116+
10851117
order.OrderItems.Add(orderItem);
10861118
_orderService.UpdateOrder(order);
10871119

@@ -1146,7 +1178,8 @@ public virtual PlaceOrderResult PlaceOrder(ProcessPaymentRequest processPaymentR
11461178
DownloadCount = 0,
11471179
IsDownloadActivated = false,
11481180
LicenseDownloadId = 0,
1149-
ItemWeight = orderItem.ItemWeight
1181+
ItemWeight = orderItem.ItemWeight,
1182+
BundleData = orderItem.BundleData
11501183
};
11511184
order.OrderItems.Add(newOrderItem);
11521185
_orderService.UpdateOrder(order);

src/Libraries/SmartStore.Services/Orders/ShoppingCartService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ public virtual IList<string> Copy(ShoppingCartItem item, Customer customer, Shop
11021102
{
11031103
foreach (var childItem in item.ChildItems)
11041104
{
1105-
AddToCart(customer, childItem.Product, childItem.ShoppingCartType, storeId, childItem.AttributesXml, childItem.CustomerEnteredPrice,
1105+
AddToCart(customer, childItem.Product, cartType, storeId, childItem.AttributesXml, childItem.CustomerEnteredPrice,
11061106
childItem.Quantity, false, out childItemId, parentItemId, childItem.BundleItem);
11071107
}
11081108
}

0 commit comments

Comments
 (0)