Skip to content

Commit 1304e99

Browse files
Setting to display weight in shopping cart
1 parent f098906 commit 1304e99

8 files changed

Lines changed: 64 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ public ShoppingCartSettings()
142142
/// </summary>
143143
public bool ShowShortDesc { get; set; }
144144

145+
/// <summary>
146+
/// Gets or sets a value indicating whether to show the product weight in the order summary
147+
/// </summary>
148+
public bool ShowWeight { get; set; }
149+
145150
/// <summary>
146151
/// Gets or sets a value indicating whether to show the product short description in the order summary
147152
/// </summary>

src/Presentation/SmartStore.Web/Administration/Models/Settings/ShoppingCartSettingsModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public class ShoppingCartSettingsModel
6464
[SmartResourceDisplayName("Admin.Configuration.Settings.ShoppingCart.ShowShortDesc")]
6565
public bool ShowShortDesc { get; set; }
6666

67+
[SmartResourceDisplayName("Admin.Configuration.Settings.ShoppingCart.ShowWeight")]
68+
public bool ShowWeight { get; set; }
69+
6770
[SmartResourceDisplayName("Admin.Configuration.Settings.ShoppingCart.ShowBasePrice")]
6871
public bool ShowBasePrice { get; set; }
6972

src/Presentation/SmartStore.Web/Administration/Views/Setting/ShoppingCart.cshtml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@
186186
@Html.ValidationMessageFor(model => model.ShowBasePrice)
187187
</td>
188188
</tr>
189+
<tr>
190+
<td class="adminTitle">
191+
@Html.SmartLabelFor(model => model.ShowWeight)
192+
</td>
193+
<td class="adminData">
194+
@Html.SettingEditorFor(model => model.ShowWeight)
195+
@Html.ValidationMessageFor(model => model.ShowWeight)
196+
</td>
197+
</tr>
189198
<tr>
190199
<td class="adminTitle">
191200
@Html.SmartLabelFor(model => model.ShowLinkedAttributeValueQuantity)

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ private ShoppingCartModel.ShoppingCartItemModel PrepareShoppingCartItemModel(Org
232232
IsShipEnabled = product.IsShipEnabled,
233233
ShortDesc = product.GetLocalized(x => x.ShortDescription),
234234
ProductType = product.ProductType,
235-
BasePrice = product.GetBasePriceInfo(_localizationService, _priceFormatter)
235+
BasePrice = product.GetBasePriceInfo(_localizationService, _priceFormatter),
236+
Weight = product.Weight
236237
};
237238

238239
if (item.BundleItem != null)
@@ -589,6 +590,7 @@ protected void PrepareShoppingCartModel(ShoppingCartModel model,
589590
model.DisplayDeliveryTime = _shoppingCartSettings.ShowDeliveryTimes;
590591
model.DisplayShortDesc = _shoppingCartSettings.ShowShortDesc;
591592
model.DisplayBasePrice = _shoppingCartSettings.ShowBasePrice;
593+
model.DisplayWeight = _shoppingCartSettings.ShowWeight;
592594
model.IsEditable = isEditable;
593595
model.ShowProductImages = _shoppingCartSettings.ShowProductImagesOnShoppingCart;
594596
model.ShowProductBundleImages = _shoppingCartSettings.ShowProductBundleImagesOnShoppingCart;
@@ -1848,7 +1850,16 @@ public ActionResult OrderTotals(bool isEditable)
18481850
model.IsEditable = isEditable;
18491851

18501852
if (cart.Count > 0)
1851-
{
1853+
{
1854+
1855+
//weight
1856+
model.Weight = decimal.Zero;
1857+
1858+
foreach (var sci in cart)
1859+
{
1860+
model.Weight += sci.Item.Product.Weight * sci.Item.Quantity;
1861+
}
1862+
18521863
//subtotal
18531864
decimal subtotalBase = decimal.Zero;
18541865
decimal orderSubTotalDiscountAmountBase = decimal.Zero;
@@ -1941,6 +1952,8 @@ public ActionResult OrderTotals(bool isEditable)
19411952
model.DisplayTaxRates = displayTaxRates;
19421953
model.DisplayTax = displayTax;
19431954

1955+
model.DisplayWeight = _shoppingCartSettings.ShowWeight;
1956+
19441957
//total
19451958
decimal orderTotalDiscountAmountBase = decimal.Zero;
19461959
Discount orderTotalAppliedDiscount = null;

src/Presentation/SmartStore.Web/Models/ShoppingCart/OrderTotalsModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ public OrderTotalsModel()
2727
public IList<TaxRate> TaxRates { get; set; }
2828
public bool DisplayTax { get; set; }
2929
public bool DisplayTaxRates { get; set; }
30-
31-
30+
public bool DisplayWeight { get; set; }
31+
3232
public IList<GiftCard> GiftCards { get; set; }
3333

3434
public string OrderTotalDiscount { get; set; }
3535
public bool AllowRemovingOrderTotalDiscount { get; set; }
3636
public int RedeemedRewardPoints { get; set; }
3737
public string RedeemedRewardPointsAmount { get; set; }
3838
public string OrderTotal { get; set; }
39+
public decimal Weight { get; set; }
3940

4041
#region Nested classes
4142

src/Presentation/SmartStore.Web/Models/ShoppingCart/ShoppingCartModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public ShoppingCartModel()
4343
public int BundleThumbSize { get; set; }
4444
public bool DisplayDeliveryTime { get; set; }
4545
public bool DisplayShortDesc { get; set; }
46+
public bool DisplayWeight { get; set; }
4647
public bool DisplayBasePrice { get; set; }
4748

4849
public ButtonPaymentMethodModel ButtonPaymentMethods { get; set; }
@@ -91,14 +92,16 @@ public ShoppingCartItemModel()
9192

9293
public IList<string> Warnings { get; set; }
9394

95+
public decimal Weight { get; set; }
96+
9497
public bool IsShipEnabled { get; set; }
9598

9699
public string DeliveryTimeName { get; set; }
97100

98101
public string DeliveryTimeHexValue { get; set; }
99102

100103
public string ShortDesc { get; set; }
101-
104+
102105
public string BasePrice { get; set; }
103106

104107
public bool BundlePerItemPricing { get; set; }

src/Presentation/SmartStore.Web/Views/ShoppingCart/OrderSummary.cshtml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@
7575
</div>
7676
}
7777
</td>
78+
79+
@if (Model.DisplayWeight)
80+
{
81+
<td class="weight nobr">
82+
<span class="product-weight">@((item.Weight * item.Quantity).ToString("N2")) kg</span>
83+
</td>
84+
}
7885
<td class="unit-price nobr">
7986
<span class="product-unit-price">@item.UnitPrice</span>
8087
</td>
@@ -267,6 +274,13 @@
267274
<th>
268275
@T("ShoppingCart.Product(s)")
269276
</th>
277+
278+
@if (Model.DisplayWeight)
279+
{
280+
<th>
281+
@T("ShoppingCart.Weight")
282+
</th>
283+
}
270284
<th class="unit-price">
271285
@T("ShoppingCart.UnitPrice")
272286
</th>

src/Presentation/SmartStore.Web/Views/ShoppingCart/OrderTotals.cshtml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
<div class="total-info">
55
<table class="cart-total table">
66
<tbody>
7+
@if (Model.DisplayWeight)
8+
{
9+
<tr>
10+
<td class="cart-total-left">
11+
<span class="nobr">@T("ShoppingCart.Totals.Weight"):</span>
12+
</td>
13+
<td class="cart-total-right">
14+
<span class="product-weight">@(Model.Weight.ToString("N2")) kg</span>
15+
</td>
16+
</tr>
17+
}
718
<tr>
819
<td class="cart-total-left">
920
<span class="nobr">@T("ShoppingCart.Totals.SubTotal"):</span>

0 commit comments

Comments
 (0)