Skip to content

Commit 8a129e6

Browse files
committed
New event MigrateShoppingCartEvent
1 parent a9aa55e commit 8a129e6

4 files changed

Lines changed: 59 additions & 2 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using SmartStore.Core.Domain.Customers;
2+
13
namespace SmartStore.Core.Domain.Orders
24
{
35
public class OrderPaidEvent
@@ -44,4 +46,26 @@ public Order Order
4446
get { return _order; }
4547
}
4648
}
49+
50+
public class MigrateShoppingCartEvent
51+
{
52+
private readonly Customer _fromCustomer;
53+
private readonly Customer _toCustomer;
54+
55+
public MigrateShoppingCartEvent(Customer fromCustomer, Customer toCustomer)
56+
{
57+
_fromCustomer = fromCustomer;
58+
_toCustomer = toCustomer;
59+
}
60+
61+
public Customer FromCustomer
62+
{
63+
get { return _fromCustomer; }
64+
}
65+
66+
public Customer ToCustomer
67+
{
68+
get { return _toCustomer; }
69+
}
70+
}
4771
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using SmartStore.Core.Domain.Orders;
1+
using SmartStore.Core.Domain.Customers;
2+
using SmartStore.Core.Domain.Orders;
23
using SmartStore.Core.Events;
34

45
namespace SmartStore.Services.Orders
@@ -35,5 +36,17 @@ public static void PublishOrderUpdated(this IEventPublisher eventPublisher, Orde
3536
if (order != null)
3637
eventPublisher.Publish(new OrderUpdatedEvent(order));
3738
}
39+
40+
/// <summary>
41+
/// Publishes the migrate shopping cart event.
42+
/// </summary>
43+
/// <param name="eventPublisher">The event publisher.</param>
44+
/// <param name="fromCustomer">The source customer entity.</param>
45+
/// <param name="toCustomer">The destination customer entity.</param>
46+
public static void PublishMigrateShoppingCart(this IEventPublisher eventPublisher, Customer fromCustomer, Customer toCustomer)
47+
{
48+
if (fromCustomer != null && toCustomer != null)
49+
eventPublisher.Publish(new MigrateShoppingCartEvent(fromCustomer, toCustomer));
50+
}
3851
}
3952
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ IList<string> UpdateShoppingCartItem(Customer customer, int shoppingCartItemId,
198198
/// <param name="toCustomer">To customer</param>
199199
void MigrateShoppingCart(Customer fromCustomer, Customer toCustomer);
200200

201+
/// <summary>
202+
/// Copies a shopping cart item.
203+
/// </summary>
204+
/// <param name="sci">Shopping cart item</param>
205+
/// <param name="customer">The customer</param>
206+
/// <param name="cartType">Shopping cart type</param>
207+
/// <param name="storeId">Store Id</param>
208+
/// <param name="addRequiredProductsIfEnabled">Add required products if enabled</param>
209+
/// <returns>List with add-to-cart warnings.</returns>
201210
IList<string> Copy(OrganizedShoppingCartItem sci, Customer customer, ShoppingCartType cartType, int storeId, bool addRequiredProductsIfEnabled);
202211
}
203212
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ public virtual void MigrateShoppingCart(Customer fromCustomer, Customer toCustom
11731173
throw new ArgumentNullException("toCustomer");
11741174

11751175
if (fromCustomer.Id == toCustomer.Id)
1176-
return; //the same customer
1176+
return;
11771177

11781178
var cartItems = fromCustomer.ShoppingCartItems.ToList().Organize().ToList();
11791179

@@ -1186,8 +1186,19 @@ public virtual void MigrateShoppingCart(Customer fromCustomer, Customer toCustom
11861186
{
11871187
DeleteShoppingCartItem(cartItem.Item);
11881188
}
1189+
1190+
_eventPublisher.PublishMigrateShoppingCart(fromCustomer, toCustomer);
11891191
}
11901192

1193+
/// <summary>
1194+
/// Copies a shopping cart item.
1195+
/// </summary>
1196+
/// <param name="sci">Shopping cart item</param>
1197+
/// <param name="customer">The customer</param>
1198+
/// <param name="cartType">Shopping cart type</param>
1199+
/// <param name="storeId">Store Id</param>
1200+
/// <param name="addRequiredProductsIfEnabled">Add required products if enabled</param>
1201+
/// <returns>List with add-to-cart warnings.</returns>
11911202
public virtual IList<string> Copy(OrganizedShoppingCartItem sci, Customer customer, ShoppingCartType cartType, int storeId, bool addRequiredProductsIfEnabled)
11921203
{
11931204
if (customer == null)

0 commit comments

Comments
 (0)