private OrderPackage ShipItems(Order order, string trackingNumber, string serviceProvider, string serviceCode, bool dontShip, string shippingMethodId = null) { var p = new OrderPackage { ShipDateUtc = DateTime.UtcNow, TrackingNumber = trackingNumber, ShippingProviderId = serviceProvider, ShippingProviderServiceCode = serviceCode, OrderId = order.bvin, ShippingMethodId = string.IsNullOrEmpty(shippingMethodId) == false ? shippingMethodId : string.Empty }; foreach (GridViewRow gvr in ItemsGridView.Rows) { if (gvr.RowType == DataControlRowType.DataRow) { var lineItemId = (long)ItemsGridView.DataKeys[gvr.RowIndex].Value; var lineItem = order.GetLineItem(lineItemId); if (lineItem == null || lineItem.IsNonShipping) { continue; } var qty = 0; var QtyToShip = (TextBox)gvr.FindControl("QtyToShip"); if (QtyToShip != null) { if (!int.TryParse(QtyToShip.Text, out qty)) { qty = 0; } } // Prevent shipping more than ordered if order is not recurring if (!order.IsRecurring && qty > lineItem.Quantity - lineItem.QuantityShipped) { qty = lineItem.Quantity - lineItem.QuantityShipped; } if (qty > 0) { p.Items.Add(new OrderPackageItem(lineItem.ProductId, lineItem.Id, qty)); p.Weight += lineItem.ProductShippingWeight * qty; } } } p.WeightUnits = WebAppSettings.ApplicationWeightUnits; if (p.Items.Count > 0) { order.Packages.Add(p); if (!dontShip) { HccApp.OrdersShipPackage(p, order); } HccApp.OrderServices.Orders.Update(order); } return(p); }
private OrderPackage ShipItems(Commerce.Orders.Order o, string trackingNumber, string serviceProvider, string serviceCode) { var p = new OrderPackage { ShipDateUtc = DateTime.UtcNow, TrackingNumber = trackingNumber, ShippingProviderId = serviceProvider, ShippingProviderServiceCode = serviceCode }; foreach (var li in o.Items) { if (li != null) { var qty = li.Quantity; p.Items.Add(new OrderPackageItem(li.ProductId, li.Id, qty)); p.Weight += li.ProductShippingWeight * qty; } } p.WeightUnits = WebAppSettings.ApplicationWeightUnits; o.Packages.Add(p); HccApp.OrdersShipPackage(p, o); o.EvaluateCurrentShippingStatus(); HccApp.OrderServices.Orders.Update(o); return(p); }