protected ShipmentDetailsModel PrepareShipmentDetailsModel(Shipment shipment) { if (shipment == null) throw new ArgumentNullException("shipment"); var order = shipment.Order; if (order == null) throw new Exception("order cannot be loaded"); var model = new ShipmentDetailsModel(); model.Id = shipment.Id; if (shipment.ShippedDateUtc.HasValue) model.ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc); if (shipment.DeliveryDateUtc.HasValue) model.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc); //tracking number and shipment information model.TrackingNumber = shipment.TrackingNumber; var srcm = _shippingService.LoadShippingRateComputationMethodBySystemName(order.ShippingRateComputationMethodSystemName); if (srcm != null && srcm.PluginDescriptor.Installed && srcm.IsShippingRateComputationMethodActive(_shippingSettings)) { var shipmentTracker = srcm.ShipmentTracker; if (shipmentTracker != null) { model.TrackingNumberUrl = shipmentTracker.GetUrl(shipment.TrackingNumber); if (_shippingSettings.DisplayShipmentEventsToCustomers) { var shipmentEvents = shipmentTracker.GetShipmentEvents(shipment.TrackingNumber); if (shipmentEvents != null) foreach (var shipmentEvent in shipmentEvents) { var shipmentStatusEventModel = new ShipmentDetailsModel.ShipmentStatusEventModel(); var shipmentEventCountry = _countryService.GetCountryByTwoLetterIsoCode(shipmentEvent.CountryCode); shipmentStatusEventModel.Country = shipmentEventCountry != null ? shipmentEventCountry.GetLocalized(x => x.Name) : shipmentEvent.CountryCode; shipmentStatusEventModel.Date = shipmentEvent.Date; shipmentStatusEventModel.EventName = shipmentEvent.EventName; shipmentStatusEventModel.Location = shipmentEvent.Location; model.ShipmentStatusEvents.Add(shipmentStatusEventModel); } } } } //products in this shipment model.ShowSku = _catalogSettings.ShowProductSku; foreach (var sopv in shipment.ShipmentOrderProductVariants) { var opv = _orderService.GetOrderProductVariantById(sopv.OrderProductVariantId); if (opv == null) continue; var sopvModel = new ShipmentDetailsModel.ShipmentOrderProductVariantModel() { Id = sopv.Id, Sku = opv.ProductVariant.FormatSku(opv.AttributesXml, _productAttributeParser), ProductId = opv.ProductVariant.ProductId, ProductSeName = opv.ProductVariant.Product.GetSeName(), AttributeInfo = opv.AttributeDescription, QuantityOrdered = opv.Quantity, QuantityShipped = sopv.Quantity, }; //product name//product name if (!String.IsNullOrEmpty(opv.ProductVariant.GetLocalized(x => x.Name))) sopvModel.ProductName = string.Format("{0} ({1})", opv.ProductVariant.Product.GetLocalized(x => x.Name), opv.ProductVariant.GetLocalized(x => x.Name)); else sopvModel.ProductName = opv.ProductVariant.Product.GetLocalized(x => x.Name); model.Items.Add(sopvModel); } //order details model model.Order = PrepareOrderDetailsModel(order); return model; }
protected virtual ShipmentDetailsModel PrepareShipmentDetailsModel(Shipment shipment) { if (shipment == null) throw new ArgumentNullException("shipment"); var order = _orderService.GetOrderById(shipment.OrderId); if (order == null) throw new Exception("order cannot be loaded"); var model = new ShipmentDetailsModel(); model.Id = shipment.Id; if (shipment.ShippedDateUtc.HasValue) model.ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc); if (shipment.DeliveryDateUtc.HasValue) model.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc); //tracking number and shipment information if (!String.IsNullOrEmpty(shipment.TrackingNumber)) { model.TrackingNumber = shipment.TrackingNumber; var srcm = _shippingService.LoadShippingRateComputationMethodBySystemName(order.ShippingRateComputationMethodSystemName); if (srcm != null && srcm.PluginDescriptor.Installed && srcm.IsShippingRateComputationMethodActive(_shippingSettings)) { var shipmentTracker = srcm.ShipmentTracker; if (shipmentTracker != null) { model.TrackingNumberUrl = shipmentTracker.GetUrl(shipment.TrackingNumber); if (_shippingSettings.DisplayShipmentEventsToCustomers) { var shipmentEvents = shipmentTracker.GetShipmentEvents(shipment.TrackingNumber); if (shipmentEvents != null) { foreach (var shipmentEvent in shipmentEvents) { var shipmentStatusEventModel = new ShipmentDetailsModel.ShipmentStatusEventModel(); var shipmentEventCountry = _countryService.GetCountryByTwoLetterIsoCode(shipmentEvent.CountryCode); shipmentStatusEventModel.Country = shipmentEventCountry != null ? shipmentEventCountry.GetLocalized(x => x.Name) : shipmentEvent.CountryCode; shipmentStatusEventModel.Date = shipmentEvent.Date; shipmentStatusEventModel.EventName = shipmentEvent.EventName; shipmentStatusEventModel.Location = shipmentEvent.Location; model.ShipmentStatusEvents.Add(shipmentStatusEventModel); } } } } } } //products in this shipment model.ShowSku = _catalogSettings.ShowProductSku; foreach (var shipmentItem in shipment.ShipmentItems) { var orderItem = order.OrderItems.Where(x => x.Id == shipmentItem.OrderItemId).FirstOrDefault(); // _orderService.GetOrderItemById(shipmentItem.OrderItemId); if (orderItem == null) continue; var shipmentItemModel = new ShipmentDetailsModel.ShipmentItemModel { Id = shipmentItem.Id, Sku = orderItem.Product.FormatSku(orderItem.AttributesXml, _productAttributeParser), ProductId = orderItem.Product.Id, ProductName = orderItem.Product.GetLocalized(x => x.Name), ProductSeName = orderItem.Product.GetSeName(), AttributeInfo = orderItem.AttributeDescription, QuantityOrdered = orderItem.Quantity, QuantityShipped = shipmentItem.Quantity, }; //rental info if (orderItem.Product.IsRental) { var rentalStartDate = orderItem.RentalStartDateUtc.HasValue ? orderItem.Product.FormatRentalDate(orderItem.RentalStartDateUtc.Value) : ""; var rentalEndDate = orderItem.RentalEndDateUtc.HasValue ? orderItem.Product.FormatRentalDate(orderItem.RentalEndDateUtc.Value) : ""; shipmentItemModel.RentalInfo = string.Format(_localizationService.GetResource("Order.Rental.FormattedDate"), rentalStartDate, rentalEndDate); } model.Items.Add(shipmentItemModel); } //order details model model.Order = PrepareOrderDetailsModel(order); return model; }