protected virtual 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 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 = _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); }
protected ShipmentDetailsModel PrepareShipmentDetailsModel(Shipment shipment) { if (shipment == null) { throw new ArgumentNullException("shipment"); } var order = shipment.Order; if (order == null) { throw new SmartException(T("Order.NotFound", shipment.OrderId)); } var store = Services.StoreService.GetStoreById(order.StoreId) ?? Services.StoreContext.CurrentStore; var catalogSettings = Services.Settings.LoadSetting <CatalogSettings>(store.Id); var shippingSettings = Services.Settings.LoadSetting <ShippingSettings>(store.Id); var model = new ShipmentDetailsModel { Id = shipment.Id, TrackingNumber = shipment.TrackingNumber, TrackingNumberUrl = shipment.TrackingUrl }; 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); } var srcm = _shippingService.LoadShippingRateComputationMethodBySystemName(order.ShippingRateComputationMethodSystemName); if (srcm != null && srcm.IsShippingRateComputationMethodActive(shippingSettings)) { var shipmentTracker = srcm.Value.ShipmentTracker; if (shipmentTracker != null) { // The URL entered by the merchant takes precedence over an automatically generated URL. if (model.TrackingNumberUrl.IsEmpty()) { model.TrackingNumberUrl = shipmentTracker.GetUrl(shipment.TrackingNumber); } if (shippingSettings.DisplayShipmentEventsToCustomers) { var shipmentEvents = shipmentTracker.GetShipmentEvents(shipment.TrackingNumber); if (shipmentEvents != null) { foreach (var shipmentEvent in shipmentEvents) { var shipmentEventCountry = _countryService.GetCountryByTwoLetterIsoCode(shipmentEvent.CountryCode); var shipmentStatusEventModel = new ShipmentDetailsModel.ShipmentStatusEventModel { Country = shipmentEventCountry != null?shipmentEventCountry.GetLocalized(x => x.Name) : shipmentEvent.CountryCode, Date = shipmentEvent.Date, EventName = shipmentEvent.EventName, Location = shipmentEvent.Location }; model.ShipmentStatusEvents.Add(shipmentStatusEventModel); } } } } } // Products in this shipment. model.ShowSku = catalogSettings.ShowProductSku; foreach (var shipmentItem in shipment.ShipmentItems) { var orderItem = _orderService.GetOrderItemById(shipmentItem.OrderItemId); if (orderItem == null) { continue; } orderItem.Product.MergeWithCombination(orderItem.AttributesXml); var shipmentItemModel = new ShipmentDetailsModel.ShipmentItemModel { Id = shipmentItem.Id, Sku = orderItem.Product.Sku, ProductId = orderItem.Product.Id, ProductName = orderItem.Product.GetLocalized(x => x.Name), ProductSeName = orderItem.Product.GetSeName(), AttributeInfo = orderItem.AttributeDescription, QuantityOrdered = orderItem.Quantity, QuantityShipped = shipmentItem.Quantity }; shipmentItemModel.ProductUrl = _productUrlHelper.GetProductUrl(shipmentItemModel.ProductSeName, orderItem); model.Items.Add(shipmentItemModel); } model.Order = _orderHelper.PrepareOrderDetailsModel(order); return(model); }
public async Task <ShipmentDetailsModel> Handle(GetShipmentDetails request, CancellationToken cancellationToken) { if (request.Shipment == null) { throw new ArgumentNullException("shipment"); } var model = new ShipmentDetailsModel(); model.Id = request.Shipment.Id; model.ShipmentNumber = request.Shipment.ShipmentNumber; if (request.Shipment.ShippedDateUtc.HasValue) { model.ShippedDate = _dateTimeHelper.ConvertToUserTime(request.Shipment.ShippedDateUtc.Value, DateTimeKind.Utc); } if (request.Shipment.DeliveryDateUtc.HasValue) { model.DeliveryDate = _dateTimeHelper.ConvertToUserTime(request.Shipment.DeliveryDateUtc.Value, DateTimeKind.Utc); } //tracking number and shipment information if (!string.IsNullOrEmpty(request.Shipment.TrackingNumber)) { model.TrackingNumber = request.Shipment.TrackingNumber; var srcm = _shippingService.LoadShippingRateComputationMethodBySystemName(request.Order.ShippingRateComputationMethodSystemName); if (srcm != null && srcm.PluginDescriptor.Installed && srcm.IsShippingRateComputationMethodActive(_shippingSettings)) { var shipmentTracker = srcm.ShipmentTracker; if (shipmentTracker != null) { model.TrackingNumberUrl = await shipmentTracker.GetUrl(request.Shipment.TrackingNumber); if (_shippingSettings.DisplayShipmentEventsToCustomers) { var shipmentEvents = await shipmentTracker.GetShipmentEvents(request.Shipment.TrackingNumber); if (shipmentEvents != null) { foreach (var shipmentEvent in shipmentEvents) { var shipmentStatusEventModel = new ShipmentDetailsModel.ShipmentStatusEventModel(); shipmentStatusEventModel.Date = shipmentEvent.Date; shipmentStatusEventModel.EventName = shipmentEvent.EventName; shipmentStatusEventModel.Location = shipmentEvent.Location; model.ShipmentStatusEvents.Add(shipmentStatusEventModel); } } } } } } //products in this shipment model.ShowSku = _catalogSettings.ShowSkuOnProductDetailsPage; foreach (var shipmentItem in request.Shipment.ShipmentItems) { var orderItem = request.Order.OrderItems.Where(x => x.Id == shipmentItem.OrderItemId).FirstOrDefault(); if (orderItem == null) { continue; } var product = await _productService.GetProductByIdIncludeArch(orderItem.ProductId); var shipmentItemModel = new ShipmentDetailsModel.ShipmentItemModel { Id = shipmentItem.Id, Sku = product.FormatSku(orderItem.AttributesXml, _productAttributeParser), ProductId = orderItem.ProductId, ProductName = product.GetLocalized(x => x.Name, request.Language.Id), ProductSeName = product.GetSeName(request.Language.Id), AttributeInfo = orderItem.AttributeDescription, QuantityOrdered = orderItem.Quantity, QuantityShipped = shipmentItem.Quantity, }; model.Items.Add(shipmentItemModel); } //shipment notes model.ShipmentNotes = await PrepareShipmentNotesModel(request); //order details model model.Order = await PrepareOrderModel(request); return(model); }
public virtual async Task <ShipmentDetailsModel> PrepareShipmentDetails(Shipment shipment) { if (shipment == null) { throw new ArgumentNullException("shipment"); } var order = await _orderService.GetOrderById(shipment.OrderId); if (order == null) { throw new Exception("order cannot be loaded"); } var model = new ShipmentDetailsModel(); model.Id = shipment.Id; model.ShipmentNumber = shipment.ShipmentNumber; 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 = await shipmentTracker.GetUrl(shipment.TrackingNumber); if (_shippingSettings.DisplayShipmentEventsToCustomers) { var shipmentEvents = await shipmentTracker.GetShipmentEvents(shipment.TrackingNumber); if (shipmentEvents != null) { foreach (var shipmentEvent in shipmentEvents) { var shipmentStatusEventModel = new ShipmentDetailsModel.ShipmentStatusEventModel(); var shipmentEventCountry = await _countryService.GetCountryByTwoLetterIsoCode(shipmentEvent.CountryCode); shipmentStatusEventModel.Country = shipmentEventCountry != null ? shipmentEventCountry.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id) : 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.ShowSkuOnProductDetailsPage; foreach (var shipmentItem in shipment.ShipmentItems) { var orderItem = order.OrderItems.Where(x => x.Id == shipmentItem.OrderItemId).FirstOrDefault(); if (orderItem == null) { continue; } var product = await _productService.GetProductByIdIncludeArch(orderItem.ProductId); var shipmentItemModel = new ShipmentDetailsModel.ShipmentItemModel { Id = shipmentItem.Id, Sku = product.FormatSku(orderItem.AttributesXml, _productAttributeParser), ProductId = orderItem.ProductId, ProductName = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id), ProductSeName = product.GetSeName(_workContext.WorkingLanguage.Id), AttributeInfo = orderItem.AttributeDescription, QuantityOrdered = orderItem.Quantity, QuantityShipped = shipmentItem.Quantity, }; model.Items.Add(shipmentItemModel); } //order details model model.Order = await PrepareOrderDetails(order); return(model); }
/// <summary> /// Prepare the shipment details model /// </summary> /// <param name="shipment">Shipment</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the shipment details model /// </returns> public virtual async Task <ShipmentDetailsModel> PrepareShipmentDetailsModelAsync(Shipment shipment) { if (shipment == null) { throw new ArgumentNullException(nameof(shipment)); } var order = await _orderService.GetOrderByIdAsync(shipment.OrderId); if (order == null) { throw new Exception("order cannot be loaded"); } var model = new ShipmentDetailsModel { Id = shipment.Id }; if (shipment.ShippedDateUtc.HasValue) { model.ShippedDate = await _dateTimeHelper.ConvertToUserTimeAsync(shipment.ShippedDateUtc.Value, DateTimeKind.Utc); } if (shipment.ReadyForPickupDateUtc.HasValue) { model.ReadyForPickupDate = await _dateTimeHelper.ConvertToUserTimeAsync(shipment.ReadyForPickupDateUtc.Value, DateTimeKind.Utc); } if (shipment.DeliveryDateUtc.HasValue) { model.DeliveryDate = await _dateTimeHelper.ConvertToUserTimeAsync(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc); } //tracking number and shipment information if (!string.IsNullOrEmpty(shipment.TrackingNumber)) { model.TrackingNumber = shipment.TrackingNumber; var shipmentTracker = await _shipmentService.GetShipmentTrackerAsync(shipment); if (shipmentTracker != null) { model.TrackingNumberUrl = await shipmentTracker.GetUrlAsync(shipment.TrackingNumber, shipment); if (_shippingSettings.DisplayShipmentEventsToCustomers) { var shipmentEvents = await shipmentTracker.GetShipmentEventsAsync(shipment.TrackingNumber, shipment); if (shipmentEvents != null) { foreach (var shipmentEvent in shipmentEvents) { var shipmentStatusEventModel = new ShipmentDetailsModel.ShipmentStatusEventModel(); var shipmentEventCountry = await _countryService.GetCountryByTwoLetterIsoCodeAsync(shipmentEvent.CountryCode); shipmentStatusEventModel.Country = shipmentEventCountry != null ? await _localizationService.GetLocalizedAsync(shipmentEventCountry, x => x.Name) : shipmentEvent.CountryCode; shipmentStatusEventModel.Status = shipmentEvent.Status; shipmentStatusEventModel.Date = shipmentEvent.Date; shipmentStatusEventModel.EventName = shipmentEvent.EventName; shipmentStatusEventModel.Location = shipmentEvent.Location; model.ShipmentStatusEvents.Add(shipmentStatusEventModel); } } } } } //products in this shipment model.ShowSku = _catalogSettings.ShowSkuOnProductDetailsPage; foreach (var shipmentItem in await _shipmentService.GetShipmentItemsByShipmentIdAsync(shipment.Id)) { var orderItem = await _orderService.GetOrderItemByIdAsync(shipmentItem.OrderItemId); if (orderItem == null) { continue; } var product = await _productService.GetProductByIdAsync(orderItem.ProductId); var shipmentItemModel = new ShipmentDetailsModel.ShipmentItemModel { Id = shipmentItem.Id, Sku = await _productService.FormatSkuAsync(product, orderItem.AttributesXml), ProductId = product.Id, ProductName = await _localizationService.GetLocalizedAsync(product, x => x.Name), ProductSeName = await _urlRecordService.GetSeNameAsync(product), AttributeInfo = orderItem.AttributeDescription, QuantityOrdered = orderItem.Quantity, QuantityShipped = shipmentItem.Quantity, }; //rental info if (product.IsRental) { var rentalStartDate = orderItem.RentalStartDateUtc.HasValue ? _productService.FormatRentalDate(product, orderItem.RentalStartDateUtc.Value) : ""; var rentalEndDate = orderItem.RentalEndDateUtc.HasValue ? _productService.FormatRentalDate(product, orderItem.RentalEndDateUtc.Value) : ""; shipmentItemModel.RentalInfo = string.Format(await _localizationService.GetResourceAsync("Order.Rental.FormattedDate"), rentalStartDate, rentalEndDate); } model.Items.Add(shipmentItemModel); } //order details model model.Order = await PrepareOrderDetailsModelAsync(order); return(model); }
protected async Task <ShipmentDetailsModel> PrepareShipmentDetailsModelAsync(Shipment shipment) { Guard.NotNull(shipment, nameof(shipment)); var order = shipment.Order; if (order == null) { throw new SmartException(T("Order.NotFound", shipment.OrderId)); } var currentStore = Services.StoreContext.CurrentStore; var store = currentStore.Id != order.StoreId ? (await _db.Stores.FindByIdAsync(order.StoreId, false) ?? currentStore) : currentStore; var settingFactory = Services.SettingFactory; var catalogSettings = await settingFactory.LoadSettingsAsync <CatalogSettings>(store.Id); var shippingSettings = await settingFactory.LoadSettingsAsync <ShippingSettings>(store.Id); var model = new ShipmentDetailsModel { Id = shipment.Id, TrackingNumber = shipment.TrackingNumber, TrackingNumberUrl = shipment.TrackingUrl }; 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); } var srcm = _providerManager.GetProvider <IShippingRateComputationMethod>(order.ShippingRateComputationMethodSystemName, store.Id); if (srcm != null && srcm.IsShippingRateComputationMethodActive(shippingSettings)) { var shipmentTracker = srcm.Value.ShipmentTracker; if (shipmentTracker != null) { // The URL entered by the merchant takes precedence over an automatically generated URL. if (model.TrackingNumberUrl.IsEmpty()) { model.TrackingNumberUrl = shipmentTracker.GetUrl(shipment.TrackingNumber); } if (shippingSettings.DisplayShipmentEventsToCustomers) { var shipmentEvents = await shipmentTracker.GetShipmentEventsAsync(shipment.TrackingNumber); if (shipmentEvents != null) { foreach (var shipmentEvent in shipmentEvents) { var shipmentEventCountry = await _db.Countries .AsNoTracking() .ApplyIsoCodeFilter(shipmentEvent.CountryCode) .FirstOrDefaultAsync(); var shipmentStatusEventModel = new ShipmentDetailsModel.ShipmentStatusEventModel { Country = shipmentEventCountry != null?shipmentEventCountry.GetLocalized(x => x.Name) : shipmentEvent.CountryCode, Date = shipmentEvent.Date, EventName = shipmentEvent.EventName, Location = shipmentEvent.Location }; model.ShipmentStatusEvents.Add(shipmentStatusEventModel); } } } } } // Products in this shipment. model.ShowSku = catalogSettings.ShowProductSku; foreach (var shipmentItem in shipment.ShipmentItems) { var orderItem = await _db.OrderItems .Include(x => x.Product) .FindByIdAsync(shipmentItem.OrderItemId, false); if (orderItem == null) { continue; } var attributeCombination = await _productAttributeMaterializer.FindAttributeCombinationAsync(orderItem.Product.Id, orderItem.AttributeSelection); orderItem.Product.MergeWithCombination(attributeCombination); var shipmentItemModel = new ShipmentDetailsModel.ShipmentItemModel { Id = shipmentItem.Id, Sku = orderItem.Product.Sku, ProductId = orderItem.Product.Id, ProductName = orderItem.Product.GetLocalized(x => x.Name), ProductSeName = await orderItem.Product.GetActiveSlugAsync(), AttributeInfo = orderItem.AttributeDescription, QuantityOrdered = orderItem.Quantity, QuantityShipped = shipmentItem.Quantity }; shipmentItemModel.ProductUrl = await _productUrlHelper.GetProductUrlAsync(shipmentItemModel.ProductSeName, orderItem); model.Items.Add(shipmentItemModel); } model.Order = await _orderHelper.PrepareOrderDetailsModelAsync(order); return(model); }
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 store = _storeService.GetStoreById(order.StoreId) ?? _services.StoreContext.CurrentStore; var catalogSettings = _services.Settings.LoadSetting <CatalogSettings>(store.Id); var shippingSettings = _services.Settings.LoadSetting <ShippingSettings>(store.Id); 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.IsShippingRateComputationMethodActive(shippingSettings)) { var shipmentTracker = srcm.Value.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 = _orderService.GetOrderItemById(shipmentItem.OrderItemId); if (orderItem == null) { continue; } orderItem.Product.MergeWithCombination(orderItem.AttributesXml); var shipmentItemModel = new ShipmentDetailsModel.ShipmentItemModel() { Id = shipmentItem.Id, Sku = orderItem.Product.Sku, ProductId = orderItem.Product.Id, ProductName = orderItem.Product.GetLocalized(x => x.Name), ProductSeName = orderItem.Product.GetSeName(), AttributeInfo = orderItem.AttributeDescription, QuantityOrdered = orderItem.Quantity, QuantityShipped = shipmentItem.Quantity, }; model.Items.Add(shipmentItemModel); } //order details model model.Order = PrepareOrderDetailsModel(order); return(model); }
protected ShipmentDetailsModel PrepareShipmentDetailsModel(Shipment shipment) { if (shipment == null) { throw new ArgumentNullException("shipment"); } var order = shipment.Order; if (order == null) { throw new SmartException(T("Order.NotFound", shipment.OrderId)); } var store = _storeService.GetStoreById(order.StoreId) ?? _services.StoreContext.CurrentStore; var catalogSettings = _services.Settings.LoadSetting <CatalogSettings>(store.Id); var shippingSettings = _services.Settings.LoadSetting <ShippingSettings>(store.Id); var model = new ShipmentDetailsModel { Id = shipment.Id, TrackingNumber = shipment.TrackingNumber }; 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); } var srcm = _shippingService.LoadShippingRateComputationMethodBySystemName(order.ShippingRateComputationMethodSystemName); if (srcm != null && srcm.IsShippingRateComputationMethodActive(shippingSettings)) { var shipmentTracker = srcm.Value.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 shipmentEventCountry = _countryService.GetCountryByTwoLetterIsoCode(shipmentEvent.CountryCode); var shipmentStatusEventModel = new ShipmentDetailsModel.ShipmentStatusEventModel { Country = (shipmentEventCountry != null ? shipmentEventCountry.GetLocalized(x => x.Name) : shipmentEvent.CountryCode), Date = shipmentEvent.Date, EventName = shipmentEvent.EventName, Location = shipmentEvent.Location }; model.ShipmentStatusEvents.Add(shipmentStatusEventModel); } } } } } //products in this shipment model.ShowSku = catalogSettings.ShowProductSku; foreach (var shipmentItem in shipment.ShipmentItems) { var orderItem = _orderService.GetOrderItemById(shipmentItem.OrderItemId); if (orderItem == null) { continue; } orderItem.Product.MergeWithCombination(orderItem.AttributesXml); var attributeQueryData = new List <List <int> >(); var shipmentItemModel = new ShipmentDetailsModel.ShipmentItemModel { Id = shipmentItem.Id, Sku = orderItem.Product.Sku, ProductId = orderItem.Product.Id, ProductName = orderItem.Product.GetLocalized(x => x.Name), ProductSeName = orderItem.Product.GetSeName(), AttributeInfo = orderItem.AttributeDescription, QuantityOrdered = orderItem.Quantity, QuantityShipped = shipmentItem.Quantity }; if (orderItem.Product.ProductType != ProductType.BundledProduct) { _productAttributeParser.DeserializeQueryData(attributeQueryData, orderItem.AttributesXml, orderItem.ProductId); } else if (orderItem.Product.BundlePerItemPricing && orderItem.BundleData.HasValue()) { var bundleData = orderItem.GetBundleData(); bundleData.ForEach(x => _productAttributeParser.DeserializeQueryData(attributeQueryData, x.AttributesXml, x.ProductId, x.BundleItemId)); } shipmentItemModel.ProductUrl = _productAttributeParser.GetProductUrlWithAttributes(attributeQueryData, shipmentItemModel.ProductSeName); model.Items.Add(shipmentItemModel); } model.Order = PrepareOrderDetailsModel(order); return(model); }