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, FullProductName = opv.ProductVariant.FullProductName, Sku = opv.ProductVariant.FormatSku(opv.AttributesXml, _productAttributeParser), 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, }; model.Products.Add(sopvModel); } } return model; }
public ActionResult AddShipment(int orderId) { 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 model = new ShipmentModel() { OrderId = order.Id, }; //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 orderProductVariants = order.OrderProductVariants; //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { orderProductVariants = orderProductVariants.Where(opv => HasAccessToOrderProductVariant(opv)).ToList(); } foreach (var opv in orderProductVariants) { //we can ship only shippable products if (!opv.ProductVariant.IsShipEnabled) continue; //quantities var qtyInThisShipment = 0; var maxQtyToAdd = opv.GetTotalNumberOfItemsCanBeAddedToShipment(); var qtyOrdered = opv.Quantity; var qtyInAllShipments = opv.GetTotalNumberOfItemsInAllShipment(); //ensure that this product variant can be added to a shipment if (maxQtyToAdd <= 0) continue; var sopvModel = new ShipmentModel.ShipmentOrderProductVariantModel() { OrderProductVariantId = opv.Id, ProductVariantId = opv.ProductVariantId, FullProductName = opv.ProductVariant.FullProductName, Sku = opv.ProductVariant.FormatSku(opv.AttributesXml, _productAttributeParser), 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, }; model.Products.Add(sopvModel); } return View(model); }
public ActionResult SetTrackingNumber(ShipmentModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var shipment = _shipmentService.GetShipmentById(model.Id); if (shipment == null) //No shipment found with the specified id return RedirectToAction("List"); //a vendor should have access only to his products if (_workContext.CurrentVendor != null && !HasAccessToShipment(shipment)) return RedirectToAction("List"); shipment.TrackingNumber = model.TrackingNumber; _shipmentService.UpdateShipment(shipment); return RedirectToAction("ShipmentDetails", new { id = shipment.Id }); }