本文整理汇总了C#中Nop.Core.Domain.Shipping.Shipment类的典型用法代码示例。如果您正苦于以下问题:C# Shipment类的具体用法?C# Shipment怎么用?C# Shipment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Shipment类属于Nop.Core.Domain.Shipping命名空间,在下文中一共展示了Shipment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteShipment
/// <summary>
/// Deletes a shipment
/// </summary>
/// <param name="shipment">Shipment</param>
public virtual void DeleteShipment(Shipment shipment)
{
if (shipment == null)
throw new ArgumentNullException("shipment");
_shipmentRepository.Delete(shipment);
//event notification
_eventPublisher.EntityDeleted(shipment);
}
示例2: Can_save_and_load_shipment
public void Can_save_and_load_shipment()
{
var shipment = new Shipment
{
Order = GetTestOrder(),
TrackingNumber = "TrackingNumber 1",
ShippedDateUtc = new DateTime(2010, 01, 01),
DeliveryDateUtc = new DateTime(2010, 01, 02),
};
var fromDb = SaveAndLoadEntity(shipment);
fromDb.ShouldNotBeNull();
fromDb.TrackingNumber.ShouldEqual("TrackingNumber 1");
fromDb.ShippedDateUtc.ShouldEqual(new DateTime(2010, 01, 01));
fromDb.DeliveryDateUtc.ShouldEqual(new DateTime(2010, 01, 02));
}
示例3: Can_save_and_load_shipment
public void Can_save_and_load_shipment()
{
var shipment = new Shipment
{
Order = GetTestOrder(),
TrackingNumber = "TrackingNumber 1",
TotalWeight = 9.87M,
ShippedDateUtc = new DateTime(2010, 01, 01),
DeliveryDateUtc = new DateTime(2010, 01, 02),
AdminComment = "AdminComment 1",
CreatedOnUtc = new DateTime(2010, 01, 03),
};
var fromDb = SaveAndLoadEntity(shipment);
fromDb.ShouldNotBeNull();
fromDb.TrackingNumber.ShouldEqual("TrackingNumber 1");
fromDb.TotalWeight.ShouldEqual(9.87M);
fromDb.ShippedDateUtc.ShouldEqual(new DateTime(2010, 01, 01));
fromDb.DeliveryDateUtc.ShouldEqual(new DateTime(2010, 01, 02));
fromDb.AdminComment.ShouldEqual("AdminComment 1");
fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 03));
}
示例4: Can_save_and_load_shipment_with_products
public void Can_save_and_load_shipment_with_products()
{
var shipment = new Shipment
{
Order = GetTestOrder(),
TrackingNumber = "TrackingNumber 1",
ShippedDateUtc = new DateTime(2010, 01, 01),
DeliveryDateUtc = new DateTime(2010, 01, 02),
};
shipment.ShipmentOrderProductVariants.Add(new ShipmentOrderProductVariant()
{
OrderProductVariantId = 1,
Quantity = 2,
});
var fromDb = SaveAndLoadEntity(shipment);
fromDb.ShouldNotBeNull();
fromDb.ShipmentOrderProductVariants.ShouldNotBeNull();
(fromDb.ShipmentOrderProductVariants.Count == 1).ShouldBeTrue();
fromDb.ShipmentOrderProductVariants.First().Quantity.ShouldEqual(2);
}
示例5: AddShipmentTokens
public virtual void AddShipmentTokens(IList<Token> tokens, Shipment shipment, int languageId)
{
tokens.Add(new Token("Shipment.ShipmentNumber", shipment.Id.ToString()));
tokens.Add(new Token("Shipment.TrackingNumber", shipment.TrackingNumber));
tokens.Add(new Token("Shipment.Product(s)", ProductListToHtmlTable(shipment, languageId), true));
tokens.Add(new Token("Shipment.URLForCustomer", string.Format("{0}orderdetails/shipment/{1}", GetStoreUrl(shipment.Order.StoreId), shipment.Id), true));
//event notification
_eventPublisher.EntityTokensAdded(shipment, tokens);
}
示例6: SendOrderShippedSMSNotification
/// <summary>
/// Sends an SMS notification when order is shipped.
/// Configuration is obtained from Configuration->Settings->SMS
/// </summary>
/// <param name="shipment"></param>
public virtual void SendOrderShippedSMSNotification(Order order, Shipment ship)
{
string text = String.Format(_smsSettings.MessageTemplate, ship.TrackingNumber);
_smsSender.SendSMS(_smsSettings.From, order.ShippingAddress.PhoneNumber, text);
}
示例7: SendShipmentSentCustomerNotification
/// <summary>
/// Sends a shipment sent notification to a customer
/// </summary>
/// <param name="shipment">Shipment</param>
/// <param name="languageId">Message language identifier</param>
/// <returns>Queued email identifier</returns>
public virtual int SendShipmentSentCustomerNotification(Shipment shipment, int languageId)
{
if (shipment == null)
throw new ArgumentNullException("shipment");
var order = shipment.Order;
if (order == null)
throw new Exception("Order cannot be loaded");
languageId = EnsureLanguageIsActive(languageId);
var messageTemplate = GetLocalizedActiveMessageTemplate("ShipmentSent.CustomerNotification", languageId);
if (messageTemplate == null)
return 0;
var shipmentTokens = GenerateTokens(shipment, languageId);
//event notification
_eventPublisher.MessageTokensAdded(messageTemplate, shipmentTokens);
var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);
var toEmail = order.BillingAddress.Email;
var toName = string.Format("{0} {1}", order.BillingAddress.FirstName, order.BillingAddress.LastName);
return SendNotification(messageTemplate, emailAccount,
languageId, shipmentTokens,
toEmail, toName);
}
示例8: Ship
/// <summary>
/// Send a shipment
/// </summary>
/// <param name="shipment">Shipment</param>
/// <param name="notifyCustomer">True to notify customer</param>
public virtual void Ship(Shipment shipment, bool notifyCustomer)
{
if (shipment == null)
throw new ArgumentNullException("shipment");
var order = _orderService.GetOrderById(shipment.OrderId);
if (order == null)
throw new Exception("Order cannot be loaded");
if (shipment.ShippedDateUtc.HasValue)
throw new Exception("This shipment is already shipped");
shipment.ShippedDateUtc = DateTime.UtcNow;
_shipmentService.UpdateShipment(shipment);
//process products with "Multiple warehouse" support enabled
foreach (var item in shipment.ShipmentItems)
{
var orderItem = _orderService.GetOrderItemById(item.OrderItemId);
_productService.BookReservedInventory(orderItem.Product, item.WarehouseId, -item.Quantity);
}
//check whether we have more items to ship
if (order.HasItemsToAddToShipment() || order.HasItemsToShip())
order.ShippingStatusId = (int)ShippingStatus.PartiallyShipped;
else
order.ShippingStatusId = (int)ShippingStatus.Shipped;
_orderService.UpdateOrder(order);
//add a note
order.OrderNotes.Add(new OrderNote
{
Note = string.Format("Shipment# {0} has been sent", shipment.Id),
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow
});
_orderService.UpdateOrder(order);
if (notifyCustomer)
{
//notify customer
int queuedEmailId = _workflowMessageService.SendShipmentSentCustomerNotification(shipment, order.CustomerLanguageId);
if (queuedEmailId > 0)
{
order.OrderNotes.Add(new OrderNote
{
Note = string.Format("\"Shipped\" email (to customer) has been queued. Queued email identifier: {0}.", queuedEmailId),
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow
});
_orderService.UpdateOrder(order);
}
}
//event
_eventPublisher.PublishShipmentSent(shipment);
//check order status
CheckOrderStatus(order);
}
示例9: PrepareShipmentModel
protected ShipmentModel PrepareShipmentModel(Shipment shipment, bool prepareProducts)
{
//measures
var baseWeight = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId);
var baseWeightIn = baseWeight != null ? baseWeight.Name : "";
var baseDimension = _measureService.GetMeasureDimensionById(_measureSettings.BaseDimensionId);
var baseDimensionIn = baseDimension != null ? baseDimension.Name : "";
var model = new ShipmentModel()
{
Id = shipment.Id,
OrderId = shipment.OrderId,
TrackingNumber = shipment.TrackingNumber,
TotalWeight = shipment.TotalWeight.HasValue ? string.Format("{0:F2} [{1}]", shipment.TotalWeight, baseWeightIn) : "",
ShippedDate = shipment.ShippedDateUtc.HasValue ? _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc).ToString() : _localizationService.GetResource("Admin.Orders.Shipments.ShippedDate.NotYet"),
CanShip = !shipment.ShippedDateUtc.HasValue,
DeliveryDate = shipment.DeliveryDateUtc.HasValue ? _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc).ToString() : _localizationService.GetResource("Admin.Orders.Shipments.DeliveryDate.NotYet"),
CanDeliver = shipment.ShippedDateUtc.HasValue && !shipment.DeliveryDateUtc.HasValue,
DisplayPdfPackagingSlip = _pdfSettings.Enabled,
};
if (prepareProducts)
{
foreach (var sopv in shipment.ShipmentOrderProductVariants)
{
var opv = _orderService.GetOrderProductVariantById(sopv.OrderProductVariantId);
if (opv == null)
continue;
//quantities
var qtyInThisShipment = sopv.Quantity;
var maxQtyToAdd = opv.GetTotalNumberOfItemsCanBeAddedToShipment();
var qtyOrdered = opv.Quantity;
var qtyInAllShipments = opv.GetTotalNumberOfItemsInAllShipment();
var sopvModel = new ShipmentModel.ShipmentOrderProductVariantModel()
{
Id = sopv.Id,
OrderProductVariantId = opv.Id,
ProductVariantId = opv.ProductVariantId,
Sku = opv.ProductVariant.Sku,
AttributeInfo = opv.AttributeDescription,
ItemWeight = opv.ItemWeight.HasValue ? string.Format("{0:F2} [{1}]", opv.ItemWeight, baseWeightIn) : "",
ItemDimensions = string.Format("{0:F2} x {1:F2} x {2:F2} [{3}]", opv.ProductVariant.Length, opv.ProductVariant.Width, opv.ProductVariant.Height, baseDimensionIn),
QuantityOrdered = qtyOrdered,
QuantityInThisShipment = qtyInThisShipment,
QuantityInAllShipments = qtyInAllShipments,
QuantityToAdd = maxQtyToAdd,
};
//product name
if (!String.IsNullOrEmpty(opv.ProductVariant.Name))
sopvModel.FullProductName = string.Format("{0} ({1})", opv.ProductVariant.Product.Name,
opv.ProductVariant.Name);
else
sopvModel.FullProductName = opv.ProductVariant.Product.Name;
model.Products.Add(sopvModel);
}
}
return model;
}
示例10: SendShipmentDeliveredCustomerNotification
/// <summary>
/// Sends a shipment delivered notification to a customer
/// </summary>
/// <param name="shipment">Shipment</param>
/// <param name="languageId">Message language identifier</param>
/// <returns>Queued email identifier</returns>
public virtual int SendShipmentDeliveredCustomerNotification(Shipment shipment, int languageId)
{
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) ?? _storeContext.CurrentStore;
languageId = EnsureLanguageIsActive(languageId, store.Id);
var messageTemplate = GetActiveMessageTemplate("ShipmentDelivered.CustomerNotification", store.Id);
if (messageTemplate == null)
return 0;
//email account
var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);
//tokens
var tokens = new List<Token>();
_messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
_messageTokenProvider.AddShipmentTokens(tokens, shipment, languageId);
_messageTokenProvider.AddOrderTokens(tokens, shipment.Order, languageId);
_messageTokenProvider.AddCustomerTokens(tokens, shipment.Order.Customer);
//event notification
_eventPublisher.MessageTokensAdded(messageTemplate, tokens);
var toEmail = order.BillingAddress.Email;
var toName = string.Format("{0} {1}", order.BillingAddress.FirstName, order.BillingAddress.LastName);
return SendNotification(messageTemplate, emailAccount,
languageId, tokens,
toEmail, toName);
}
示例11: AddShipmentTokens
public virtual void AddShipmentTokens(IList<Token> tokens, Shipment shipment, int languageId)
{
tokens.Add(new Token("Shipment.ShipmentNumber", shipment.Id.ToString()));
tokens.Add(new Token("Shipment.TrackingNumber", shipment.TrackingNumber));
var trackingNumberUrl = "";
if (!String.IsNullOrEmpty(shipment.TrackingNumber))
{
//we cannot inject IShippingService into constructor because it'll cause circular references.
//that's why we resolve it here this way
var shippingService = EngineContext.Current.Resolve<IShippingService>();
var srcm = shippingService.LoadShippingRateComputationMethodBySystemName(shipment.Order.ShippingRateComputationMethodSystemName);
if (srcm != null &&
srcm.PluginDescriptor.Installed &&
srcm.IsShippingRateComputationMethodActive(_shippingSettings))
{
var shipmentTracker = srcm.ShipmentTracker;
if (shipmentTracker != null)
{
trackingNumberUrl = shipmentTracker.GetUrl(shipment.TrackingNumber);
}
}
}
tokens.Add(new Token("Shipment.TrackingNumberURL", trackingNumberUrl, true));
tokens.Add(new Token("Shipment.Product(s)", ProductListToHtmlTable(shipment, languageId), true));
tokens.Add(new Token("Shipment.URLForCustomer", string.Format("{0}orderdetails/shipment/{1}", GetStoreUrl(shipment.Order.StoreId), shipment.Id), true));
//event notification
_eventPublisher.EntityTokensAdded(shipment, tokens);
}
示例12: InstallOrders
//.........这里部分代码省略.........
ItemWeight = null,
RentalStartDateUtc = null,
RentalEndDateUtc = null
};
_orderItemRepository.Insert(fourthOrderItem2);
//item Fahrenheit 451 by Ray Bradbury
var fourthOrderItem3 = new OrderItem()
{
OrderItemGuid = Guid.NewGuid(),
Order = fourthOrder,
ProductId = _productRepository.Table.First(p => p.Name.Equals("Fahrenheit 451 by Ray Bradbury")).Id,
UnitPriceInclTax = 27M,
UnitPriceExclTax = 27M,
PriceInclTax = 27M,
PriceExclTax = 27M,
OriginalProductCost = decimal.Zero,
AttributeDescription = string.Empty,
AttributesXml = string.Empty,
Quantity = 1,
DiscountAmountInclTax = decimal.Zero,
DiscountAmountExclTax = decimal.Zero,
DownloadCount = 0,
IsDownloadActivated = false,
LicenseDownloadId = 0,
ItemWeight = null,
RentalStartDateUtc = null,
RentalEndDateUtc = null
};
_orderItemRepository.Insert(fourthOrderItem3);
//shipments
//shipment 1
var fourthOrderShipment1 = new Shipment
{
Order = fourthOrder,
TrackingNumber = string.Empty,
TotalWeight = 4M,
ShippedDateUtc = DateTime.UtcNow,
DeliveryDateUtc = DateTime.UtcNow,
AdminComment = string.Empty,
CreatedOnUtc = DateTime.UtcNow
};
_shipmentRepository.Insert(fourthOrderShipment1);
var fourthOrderShipment1Item1 = new ShipmentItem()
{
OrderItemId = fourthOrderItem1.Id,
Quantity = 1,
WarehouseId = 0,
Shipment = fourthOrderShipment1
};
_shipmentItemRepository.Insert(fourthOrderShipment1Item1);
var fourthOrderShipment1Item2 = new ShipmentItem()
{
OrderItemId = fourthOrderItem2.Id,
Quantity = 1,
WarehouseId = 0,
Shipment = fourthOrderShipment1
};
_shipmentItemRepository.Insert(fourthOrderShipment1Item2);
//shipment 2
var fourthOrderShipment2 = new Shipment
{
示例13: PrepareShipmentDetailsModel
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;
}
示例14: PrepareShipmentModel
protected virtual ShipmentModel PrepareShipmentModel(Shipment shipment, bool prepareProducts, bool prepareShipmentEvent = false)
{
//measures
var baseWeight = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId);
var baseWeightIn = baseWeight != null ? baseWeight.Name : "";
var baseDimension = _measureService.GetMeasureDimensionById(_measureSettings.BaseDimensionId);
var baseDimensionIn = baseDimension != null ? baseDimension.Name : "";
var model = new ShipmentModel
{
Id = shipment.ID,
OrderId = shipment.OrderId,
TrackingNumber = shipment.TrackingNumber,
TotalWeight = shipment.TotalWeight.HasValue ? string.Format("{0:F2} [{1}]", shipment.TotalWeight, baseWeightIn) : "",
ShippedDate = shipment.ShippedDateUtc.HasValue ? _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc).ToString() : _localizationService.GetResource("Admin.Orders.Shipments.ShippedDate.NotYet"),
ShippedDateUtc = shipment.ShippedDateUtc,
CanShip = !shipment.ShippedDateUtc.HasValue,
DeliveryDate = shipment.DeliveryDateUtc.HasValue ? _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc).ToString() : _localizationService.GetResource("Admin.Orders.Shipments.DeliveryDate.NotYet"),
DeliveryDateUtc = shipment.DeliveryDateUtc,
CanDeliver = shipment.ShippedDateUtc.HasValue && !shipment.DeliveryDateUtc.HasValue,
AdminComment = shipment.AdminComment,
};
if (prepareProducts)
{
foreach (var shipmentItem in shipment.ShipmentItems)
{
var orderItem = _orderService.GetOrderItemById(shipmentItem.OrderItemId);
if (orderItem == null)
continue;
//quantities
var qtyInThisShipment = shipmentItem.Quantity;
var maxQtyToAdd = orderItem.GetTotalNumberOfItemsCanBeAddedToShipment();
var qtyOrdered = orderItem.Quantity;
var qtyInAllShipments = orderItem.GetTotalNumberOfItemsInAllShipment();
var warehouse = _shippingService.GetWarehouseById(shipmentItem.WarehouseId);
var shipmentItemModel = new ShipmentModel.ShipmentItemModel
{
Id = shipmentItem.ID,
OrderItemId = orderItem.ID,
ProductId = orderItem.ProductId,
ProductName = orderItem.Product.Name,
Sku = orderItem.Product.FormatSku(orderItem.AttributesXml, _productAttributeParser),
AttributeInfo = orderItem.AttributeDescription,
ShippedFromWarehouse = warehouse != null ? warehouse.Name : null,
ShipSeparately = orderItem.Product.ShipSeparately,
ItemWeight = orderItem.ItemWeight.HasValue ? string.Format("{0:F2} [{1}]", orderItem.ItemWeight, baseWeightIn) : "",
ItemDimensions = string.Format("{0:F2} x {1:F2} x {2:F2} [{3}]", orderItem.Product.Length, orderItem.Product.Width, orderItem.Product.Height, baseDimensionIn),
QuantityOrdered = qtyOrdered,
QuantityInThisShipment = qtyInThisShipment,
QuantityInAllShipments = qtyInAllShipments,
QuantityToAdd = maxQtyToAdd,
};
//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);
}
}
if (prepareShipmentEvent && !String.IsNullOrEmpty(shipment.TrackingNumber))
{
var order = shipment.Order;
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.DisplayShipmentEventsToStoreOwner)
{
var shipmentEvents = shipmentTracker.GetShipmentEvents(shipment.TrackingNumber);
if (shipmentEvents != null)
{
foreach (var shipmentEvent in shipmentEvents)
{
var shipmentStatusEventModel = new ShipmentModel.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);
}
}
}
}
//.........这里部分代码省略.........
示例15: AddShipment
public ActionResult AddShipment(int orderId, FormCollection form, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
return AccessDeniedView();
var order = _orderService.GetOrderById(orderId);
if (order == null)
//No order found with the specified id
return RedirectToAction("List");
//a vendor should have access only to his products
if (_workContext.CurrentVendor != null && !HasAccessToOrder(order))
return RedirectToAction("List");
var orderItems = order.OrderItems;
//a vendor should have access only to his products
if (_workContext.CurrentVendor != null)
{
orderItems = orderItems.Where(HasAccessToOrderItem).ToList();
}
Shipment shipment = null;
decimal? totalWeight = null;
foreach (var orderItem in orderItems)
{
//is shippable
if (!orderItem.Product.IsShipEnabled)
continue;
//ensure that this product can be shipped (have at least one item to ship)
var maxQtyToAdd = orderItem.GetTotalNumberOfItemsCanBeAddedToShipment();
if (maxQtyToAdd <= 0)
continue;
int qtyToAdd = 0; //parse quantity
foreach (string formKey in form.AllKeys)
if (formKey.Equals(string.Format("qtyToAdd{0}", orderItem.ID), StringComparison.InvariantCultureIgnoreCase))
{
int.TryParse(form[formKey], out qtyToAdd);
break;
}
int warehouseId = 0;
if (orderItem.Product.ManageInventoryMethod == ManageInventoryMethod.ManageStock &&
orderItem.Product.UseMultipleWarehouses)
{
//multiple warehouses supported
//warehouse is chosen by a store owner
foreach (string formKey in form.AllKeys)
if (formKey.Equals(string.Format("warehouse_{0}", orderItem.ID), StringComparison.InvariantCultureIgnoreCase))
{
int.TryParse(form[formKey], out warehouseId);
break;
}
}
else
{
//multiple warehouses are not supported
warehouseId = orderItem.Product.WarehouseId;
}
foreach (string formKey in form.AllKeys)
if (formKey.Equals(string.Format("qtyToAdd{0}", orderItem.ID), StringComparison.InvariantCultureIgnoreCase))
{
int.TryParse(form[formKey], out qtyToAdd);
break;
}
//validate quantity
if (qtyToAdd <= 0)
continue;
if (qtyToAdd > maxQtyToAdd)
qtyToAdd = maxQtyToAdd;
//ok. we have at least one item. let's create a shipment (if it does not exist)
var orderItemTotalWeight = orderItem.ItemWeight.HasValue ? orderItem.ItemWeight * qtyToAdd : null;
if (orderItemTotalWeight.HasValue)
{
if (!totalWeight.HasValue)
totalWeight = 0;
totalWeight += orderItemTotalWeight.Value;
}
if (shipment == null)
{
var trackingNumber = form["TrackingNumber"];
var adminComment = form["AdminComment"];
shipment = new Shipment
{
OrderId = order.ID,
TrackingNumber = trackingNumber,
TotalWeight = null,
ShippedDateUtc = null,
DeliveryDateUtc = null,
AdminComment = adminComment,
CreatedOnUtc = DateTime.UtcNow,
};
}
//create a shipment item
var shipmentItem = new ShipmentItem
//.........这里部分代码省略.........