Skip to content

Commit

Permalink
Resolves #1584 Show bundle item images in order details like in shopp…
Browse files Browse the repository at this point in the history
…ing cart details.
  • Loading branch information
mgesing committed Aug 28, 2019
1 parent c449202 commit 93eb443
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 61 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* #1669 Apply percentage discounts also on tier prices.
* #1618 Implement ACL and multistore capability on menu item level.
* #1683 Menu Builder items: implement support for icon (brand) color.
* #1584 Show bundle item images in order details like in shopping cart details.

### Improvements
* #1663 Make MeasureDimension and MeasureWeight localizable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
"Specifies whether to apply percentage discounts also on tier prices.",
"Legt fest, ob prozentuale Rabatte auch auf Staffelpreise angewendet werden sollen.");

builder.AddOrUpdate("Admin.Configuration.Settings.ShoppingCart.ShowProductBundleImagesOnShoppingCart",
"Show product images of bundle items",
"Produktbilder von Bundle-Bestandteilen anzeigen",
"Specifies whether to show product images of bundle items.",
"Legt fest, ob Produktbilder von Bundle-Bestandteilen angezeigt werden sollen.");

builder.Delete(
"Admin.Configuration.Measures.Weights.Fields.MarkAsPrimaryWeight",
"Admin.Configuration.Measures.Dimensions.Fields.MarkAsPrimaryDimension");
Expand Down
102 changes: 62 additions & 40 deletions src/Presentation/SmartStore.Web/Controllers/OrderHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SmartStore.Core.Domain.Catalog;
using SmartStore.Core.Domain.Common;
Expand Down Expand Up @@ -39,6 +40,7 @@ public partial class OrderHelper
private readonly ICurrencyService _currencyService;
private readonly IQuantityUnitService _quantityUnitService;
private readonly IPictureService _pictureService;
private readonly IProductService _productService;

public OrderHelper(
ICommonServices services,
Expand All @@ -52,7 +54,8 @@ public OrderHelper(
IPaymentService paymentService,
ICurrencyService currencyService,
IQuantityUnitService quantityUnitService,
IPictureService pictureService)
IPictureService pictureService,
IProductService productService)
{
_services = services;
_dateTimeHelper = dateTimeHelper;
Expand All @@ -66,6 +69,7 @@ public OrderHelper(
_currencyService = currencyService;
_quantityUnitService = quantityUnitService;
_pictureService = pictureService;
_productService = productService;

T = NullLocalizer.Instance;
}
Expand Down Expand Up @@ -144,41 +148,57 @@ private OrderDetailsModel.OrderItemModel PrepareOrderItemModel(
};

var quantityUnit = _quantityUnitService.GetQuantityUnitById(orderItem.Product.QuantityUnitId);
model.QuantityUnit = (quantityUnit == null ? "" : quantityUnit.GetLocalized(x => x.Name));
model.QuantityUnit = quantityUnit == null ? "" : quantityUnit.GetLocalized(x => x.Name);

if (orderItem.Product.ProductType == ProductType.BundledProduct && orderItem.BundleData.HasValue())
{
var bundleData = orderItem.GetBundleData();
var bundleItems = shoppingCartSettings.ShowProductBundleImagesOnShoppingCart
? _productService.GetBundleItems(orderItem.ProductId).ToDictionarySafe(x => x.Item.ProductId)
: new Dictionary<int, ProductBundleItemData>();

model.BundlePerItemPricing = orderItem.Product.BundlePerItemPricing;
model.BundlePerItemShoppingCart = bundleData.Any(x => x.PerItemShoppingCart);

foreach (var bundleItem in bundleData)
foreach (var bid in bundleData)
{
var bundleItemModel = new OrderDetailsModel.BundleItemModel
{
Sku = bundleItem.Sku,
ProductName = bundleItem.ProductName,
ProductSeName = bundleItem.ProductSeName,
VisibleIndividually = bundleItem.VisibleIndividually,
Quantity = bundleItem.Quantity,
DisplayOrder = bundleItem.DisplayOrder,
AttributeInfo = bundleItem.AttributesInfo
Sku = bid.Sku,
ProductName = bid.ProductName,
ProductSeName = bid.ProductSeName,
VisibleIndividually = bid.VisibleIndividually,
Quantity = bid.Quantity,
DisplayOrder = bid.DisplayOrder,
AttributeInfo = bid.AttributesInfo
};

bundleItemModel.ProductUrl = _productUrlHelper.GetProductUrl(bundleItem.ProductId, bundleItemModel.ProductSeName, bundleItem.AttributesXml);
bundleItemModel.ProductUrl = _productUrlHelper.GetProductUrl(bid.ProductId, bundleItemModel.ProductSeName, bid.AttributesXml);

if (model.BundlePerItemShoppingCart)
{
decimal priceWithDiscount = _currencyService.ConvertCurrency(bundleItem.PriceWithDiscount, order.CurrencyRate);
var priceWithDiscount = _currencyService.ConvertCurrency(bid.PriceWithDiscount, order.CurrencyRate);
bundleItemModel.PriceWithDiscount = _priceFormatter.FormatPrice(priceWithDiscount, true, order.CustomerCurrencyCode, language, false, false);
}

// Bundle item picture.
if (shoppingCartSettings.ShowProductBundleImagesOnShoppingCart && bundleItems.TryGetValue(bid.ProductId, out var bundleItem))
{
bundleItemModel.HideThumbnail = bundleItem.Item.HideThumbnail;

bundleItemModel.Picture = PrepareOrderItemPictureModel(
bundleItem.Item.Product,
mediaSettings.CartThumbBundleItemPictureSize,
bid.ProductName,
bid.AttributesXml,
catalogSettings);
}

model.BundleItems.Add(bundleItemModel);
}
}

// Unit price, subtotal
// Unit price, subtotal.
switch (order.CustomerTaxDisplayType)
{
case TaxDisplayType.ExcludingTax:
Expand Down Expand Up @@ -219,8 +239,7 @@ private OrderDetailsModel.OrderItemModel PrepareOrderItemModel(

public OrderDetailsModel PrepareOrderDetailsModel(Order order)
{
if (order == null)
throw new ArgumentNullException("order");
Guard.NotNull(order, nameof(order));

var store = _services.StoreService.GetStoreById(order.StoreId) ?? _services.StoreContext.CurrentStore;
var language = _services.WorkContext.WorkingLanguage;
Expand Down Expand Up @@ -249,7 +268,7 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)
model.DisplayPdfInvoice = pdfSettings.Enabled;
model.RenderOrderNotes = pdfSettings.RenderOrderNotes;

// Shipping info
// Shipping info.
model.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_services.Localization, _services.WorkContext);
if (order.ShippingStatus != ShippingStatus.ShippingNotRequired)
{
Expand All @@ -258,7 +277,7 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)
model.ShippingMethod = order.ShippingMethod;


// Shipments (only already shipped)
// Shipments (only already shipped).
var shipments = order.Shipments.Where(x => x.ShippedDateUtc.HasValue).OrderBy(x => x.CreatedOnUtc).ToList();
foreach (var shipment in shipments)
{
Expand All @@ -269,53 +288,54 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)
};

if (shipment.ShippedDateUtc.HasValue)
{
shipmentModel.ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc);
}
if (shipment.DeliveryDateUtc.HasValue)
{
shipmentModel.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc);
}

model.Shipments.Add(shipmentModel);
}
}

// Billing info
model.BillingAddress.PrepareModel(order.BillingAddress, false, addressSettings);

// VAT number
model.VatNumber = order.VatNumber;

//payment method
// Payment method.
var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName);
model.PaymentMethod = paymentMethod != null ? _pluginMediator.GetLocalizedFriendlyName(paymentMethod.Metadata) : order.PaymentMethodSystemName;
model.CanRePostProcessPayment = _paymentService.CanRePostProcessPayment(order);

// Purchase order number (we have to find a better to inject this information because it's related to a certain plugin)
// Purchase order number (we have to find a better to inject this information because it's related to a certain plugin).
if (paymentMethod != null && paymentMethod.Metadata.SystemName.Equals("SmartStore.PurchaseOrderNumber", StringComparison.InvariantCultureIgnoreCase))
{
model.DisplayPurchaseOrderNumber = true;
model.PurchaseOrderNumber = order.PurchaseOrderNumber;
}

// Totals
// Totals.
switch (order.CustomerTaxDisplayType)
{
case TaxDisplayType.ExcludingTax:
{
// Order subtotal
// Order subtotal.
var orderSubtotalExclTax = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate);
model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalExclTax, true, order.CustomerCurrencyCode, language, false, false);

// Discount (applied to order subtotal)
// Discount (applied to order subtotal).
var orderSubTotalDiscountExclTax = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate);
if (orderSubTotalDiscountExclTax > decimal.Zero)
{
model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTax, true, order.CustomerCurrencyCode, language, false, false);
}

// Order shipping
// Order shipping.
var orderShippingExclTax = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate);
model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingExclTax, true, order.CustomerCurrencyCode, language, false, false);

// Payment method additional fee
// Payment method additional fee.
var paymentMethodAdditionalFeeExclTax = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate);
if (paymentMethodAdditionalFeeExclTax != decimal.Zero)
{
Expand All @@ -327,22 +347,22 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)

case TaxDisplayType.IncludingTax:
{
// Order subtotal
// Order subtotal.
var orderSubtotalInclTax = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate);
model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalInclTax, true, order.CustomerCurrencyCode, language, true, false);

// Discount (applied to order subtotal)
// Discount (applied to order subtotal).
var orderSubTotalDiscountInclTax = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate);
if (orderSubTotalDiscountInclTax > decimal.Zero)
{
model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTax, true, order.CustomerCurrencyCode, language, true, false);
}

// Order shipping
// Order shipping.
var orderShippingInclTax = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate);
model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingInclTax, true, order.CustomerCurrencyCode, language, true, false);

// Payment method additional fee
// Payment method additional fee.
var paymentMethodAdditionalFeeInclTax = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate);
if (paymentMethodAdditionalFeeInclTax != decimal.Zero)
{
Expand All @@ -353,7 +373,7 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)
break;
}

// Tax
// Tax.
var displayTax = true;
var displayTaxRates = true;

Expand Down Expand Up @@ -397,14 +417,14 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)
model.DisplayTax = displayTax;


// Discount (applied to order total)
// Discount (applied to order total).
var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate);
if (orderDiscountInCustomerCurrency > decimal.Zero)
{
model.OrderTotalDiscount = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false, language);
}

// Gift cards
// Gift cards.
foreach (var gcuh in order.GiftCardUsageHistory)
{
var remainingAmountBase = gcuh.GiftCard.GetGiftCardRemainingAmount();
Expand All @@ -420,7 +440,7 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)
model.GiftCards.Add(gcModel);
}

// Reward points
// Reward points .
if (order.RedeemedRewardPointsEntry != null)
{
model.RedeemedRewardPoints = -order.RedeemedRewardPointsEntry.Points;
Expand All @@ -435,7 +455,7 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)
model.CreditBalance = _priceFormatter.FormatPrice(-convertedCreditBalance, true, order.CustomerCurrencyCode, false, language);
}

// Total
// Total.
var roundingAmount = decimal.Zero;
var orderTotal = order.GetOrderTotalInCustomerCurrency(_currencyService, _paymentService, out roundingAmount);

Expand All @@ -446,10 +466,10 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)
model.OrderTotalRounding = _priceFormatter.FormatPrice(roundingAmount, true, order.CustomerCurrencyCode, false, language);
}

// Checkout attributes
// Checkout attributes.
model.CheckoutAttributeInfo = HtmlUtils.ConvertPlainTextToTable(HtmlUtils.ConvertHtmlToPlainText(order.CheckoutAttributeDescription));

// Order notes
// Order notes.
foreach (var orderNote in order.OrderNotes
.Where(on => on.DisplayToCustomer)
.OrderByDescending(on => on.CreatedOnUtc)
Expand All @@ -465,10 +485,12 @@ public OrderDetailsModel PrepareOrderDetailsModel(Order order)
});
}


// purchased products
// Purchased products.
model.ShowSku = catalogSettings.ShowProductSku;
model.ShowProductImages = shoppingCartSettings.ShowProductImagesOnShoppingCart;
model.ShowProductBundleImages = shoppingCartSettings.ShowProductBundleImagesOnShoppingCart;
model.BundleThumbSize = mediaSettings.CartThumbBundleItemPictureSize;

var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null);

foreach (var orderItem in orderItems)
Expand Down
17 changes: 11 additions & 6 deletions src/Presentation/SmartStore.Web/Models/Order/OrderDetailsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using System.Collections.Generic;
using SmartStore.Core.Domain.Catalog;
using SmartStore.Core.Domain.Common;
using SmartStore.Services.Localization;
using SmartStore.Web.Framework.Modelling;
using SmartStore.Web.Models.Common;
using SmartStore.Web.Models.Media;
using SmartStore.Services.Localization;

namespace SmartStore.Web.Models.Order
{
public partial class OrderDetailsModel : EntityModelBase
public partial class OrderDetailsModel : EntityModelBase
{
public OrderDetailsModel()
{
Expand Down Expand Up @@ -78,8 +78,10 @@ public OrderDetailsModel()

public bool ShowSku { get; set; }
public bool ShowProductImages { get; set; }
public IList<OrderItemModel> Items { get; set; }
public bool ShowProductBundleImages { get; set; }
public int BundleThumbSize { get; set; }

public IList<OrderItemModel> Items { get; set; }
public IList<OrderNote> OrderNotes { get; set; }

#region Nested Classes
Expand All @@ -106,12 +108,13 @@ public OrderItemModel()
public bool BundlePerItemShoppingCart { get; set; }
public PictureModel Picture { get; set; }

public IList<BundleItemModel> BundleItems { get; set; }
public IList<BundleItemModel> BundleItems { get; set; }
}

public partial class BundleItemModel : ModelBase
{
public string Sku { get; set; }
public PictureModel Picture { get; set; }
public string Sku { get; set; }
public string ProductName { get; set; }
public string ProductSeName { get; set; }
public string ProductUrl { get; set; }
Expand All @@ -120,7 +123,8 @@ public partial class BundleItemModel : ModelBase
public int DisplayOrder { get; set; }
public string PriceWithDiscount { get; set; }
public string AttributeInfo { get; set; }
}
public bool HideThumbnail { get; set; }
}

public partial class TaxRate : ModelBase
{
Expand Down Expand Up @@ -149,6 +153,7 @@ public partial class ShipmentBriefModel : EntityModelBase
public DateTime? ShippedDate { get; set; }
public DateTime? DeliveryDate { get; set; }
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ShoppingCartItemModel()
}
public string Sku { get; set; }

public PictureModel Picture {get;set;}
public PictureModel Picture { get; set; }

public int ProductId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ShoppingCartItemModel()

public string Sku { get; set; }

public PictureModel Picture {get;set;}
public PictureModel Picture { get; set; }

public int ProductId { get; set; }

Expand Down
Loading

0 comments on commit 93eb443

Please sign in to comment.