Skip to content

Commit fe391c0

Browse files
author
Marcel Schmidt
committed
ShoppingCart > Added order totals event + store differentiation > possible to display shopping cart summary with order totals for any customer in any stores
1 parent 92e5510 commit fe391c0

5 files changed

Lines changed: 32 additions & 42 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using SmartStore.Core.Domain.Customers;
2+
using SmartStore.Core.Domain.Stores;
3+
4+
namespace SmartStore.Services.Cart
5+
{
6+
public class OrderTotalsEvent
7+
{
8+
public OrderTotalsEvent()
9+
{
10+
}
11+
12+
public Customer Customer { get; set; }
13+
14+
public int? StoreId { get; set; }
15+
}
16+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ IList<string> GetStandardWarnings(
8787
Customer customer,
8888
ShoppingCartType shoppingCartType,
8989
Product product,
90+
int storeId,
9091
string selectedAttributes,
9192
decimal customerEnteredPrice,
9293
int quantity);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ public virtual IList<string> GetStandardWarnings(
359359
Customer customer,
360360
ShoppingCartType shoppingCartType,
361361
Product product,
362+
int storeId,
362363
string selectedAttributes,
363364
decimal customerEnteredPrice,
364365
int quantity)
@@ -401,7 +402,7 @@ public virtual IList<string> GetStandardWarnings(
401402
}
402403

403404
// Store mapping
404-
if (!_storeMappingService.Authorize(product, _storeContext.CurrentStore.Id))
405+
if (!_storeMappingService.Authorize(product, storeId))
405406
{
406407
warnings.Add(T("ShoppingCart.ProductUnpublished"));
407408
}
@@ -471,7 +472,7 @@ public virtual IList<string> GetStandardWarnings(
471472
break;
472473
case ManageInventoryMethod.ManageStock:
473474
{
474-
if ((BackorderMode)product.BackorderMode == BackorderMode.NoBackorders)
475+
if (product.BackorderMode == BackorderMode.NoBackorders)
475476
{
476477
if (product.StockQuantity < quantity)
477478
{
@@ -833,7 +834,7 @@ public virtual IList<string> GetShoppingCartItemWarnings(
833834

834835
// standard properties
835836
if (getStandardWarnings)
836-
warnings.AddRange(GetStandardWarnings(customer, shoppingCartType, product, selectedAttributes, customerEnteredPrice, quantity));
837+
warnings.AddRange(GetStandardWarnings(customer, shoppingCartType, product, storeId, selectedAttributes, customerEnteredPrice, quantity));
837838

838839
// selected attributes
839840
if (getAttributesWarnings)

src/Libraries/SmartStore.Services/SmartStore.Services.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
<Compile Include="Cart\Rules\Impl\UserAgent\OSRule.cs" />
216216
<Compile Include="Cart\Rules\Impl\UserAgent\DeviceRule.cs" />
217217
<Compile Include="Cart\Rules\Impl\UserAgent\IsMobileRule.cs" />
218+
<Compile Include="Cart\OrderTotalsEvent.cs" />
218219
<Compile Include="Cart\ValidatingCartEvent.cs" />
219220
<Compile Include="Catalog\CategoryTreeChangeHandler.cs" />
220221
<Compile Include="Catalog\CatalogMessageFactoryExtensions.cs" />

src/Presentation/SmartStore.Web/Controllers/ShoppingCartController.cs

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
using SmartStore.Core.Domain.Media;
1515
using SmartStore.Core.Domain.Orders;
1616
using SmartStore.Core.Domain.Shipping;
17-
using SmartStore.Core.Domain.Stores;
1817
using SmartStore.Core.Domain.Tax;
1918
using SmartStore.Core.Html;
2019
using SmartStore.Core.Logging;
2120
using SmartStore.Core.Security;
21+
using SmartStore.Services.Cart;
2222
using SmartStore.Services.Catalog;
2323
using SmartStore.Services.Catalog.Extensions;
2424
using SmartStore.Services.Catalog.Modelling;
@@ -39,7 +39,6 @@
3939
using SmartStore.Web.Framework.Plugins;
4040
using SmartStore.Web.Framework.Security;
4141
using SmartStore.Web.Framework.Seo;
42-
using SmartStore.Web.Models.Checkout;
4342
using SmartStore.Web.Models.Media;
4443
using SmartStore.Web.Models.ShoppingCart;
4544

@@ -1647,23 +1646,10 @@ public ActionResult Cart(ProductVariantQuery query)
16471646
}
16481647

16491648
[ChildActionOnly]
1650-
public ActionResult OrderSummary(bool? prepareAndDisplayOrderReviewData, Customer customer = null)
1651-
{
1652-
var storeId = _storeContext.CurrentStore.Id;
1653-
if (customer == null || customer.Id == 0)
1654-
{
1655-
customer = Services.WorkContext.CurrentCustomer;
1656-
}
1657-
else
1658-
{
1659-
var buyerStoreId = _genericAttributeService.GetAttribute<int>("Customer", customer.Id, "CustomerStoreId");
1660-
if (buyerStoreId != default)
1661-
{
1662-
storeId = buyerStoreId;
1663-
}
1664-
}
1665-
1666-
var cart = customer.GetCartItems(ShoppingCartType.ShoppingCart, storeId);
1649+
public ActionResult OrderSummary(bool? prepareAndDisplayOrderReviewData, Customer customer = null, int? storeId = null)
1650+
{
1651+
customer = customer == null || customer.Id == 0 ? _workContext.CurrentCustomer : customer;
1652+
var cart = customer.GetCartItems(ShoppingCartType.ShoppingCart, storeId ?? _storeContext.CurrentStore.Id);
16671653
var model = new ShoppingCartModel();
16681654

16691655
PrepareShoppingCartModel(
@@ -1993,27 +1979,12 @@ public ActionResult GetEstimateShipping(EstimateShippingModel shippingModel, Pro
19931979
[ChildActionOnly]
19941980
public ActionResult OrderTotals(bool isEditable)
19951981
{
1996-
var currency = _workContext.WorkingCurrency;
1997-
var storeId = _storeContext.CurrentStore.Id;
1998-
var customer = ViewData["CurrentCustomer"] as Customer;
1999-
if (customer != null)
2000-
{
2001-
var buyerStoreId = _genericAttributeService.GetAttribute<int>("Customer", customer.Id, "CustomerStoreId");
2002-
if (buyerStoreId != default)
2003-
{
2004-
storeId = buyerStoreId;
2005-
}
1982+
var orderTotalsEvent = new OrderTotalsEvent();
1983+
Services.EventPublisher.Publish(orderTotalsEvent);
20061984

2007-
var currencyId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CurrencyId);
2008-
if (currencyId != default)
2009-
{
2010-
currency = _currencyService.GetCurrencyById(currencyId);
2011-
}
2012-
}
2013-
else
2014-
{
2015-
customer = _workContext.CurrentCustomer;
2016-
}
1985+
var currency = _workContext.WorkingCurrency;
1986+
var customer = orderTotalsEvent.Customer ?? _workContext.CurrentCustomer;
1987+
var storeId = orderTotalsEvent.StoreId ?? _storeContext.CurrentStore.Id;
20171988

20181989
var cart = customer.GetCartItems(ShoppingCartType.ShoppingCart, storeId);
20191990
var model = new OrderTotalsModel();

0 commit comments

Comments
 (0)