New problem, I try to insert shipment but get this error:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_ShipmentItem_Shipment_ShipmentId". The conflict occurred in database "databse_db_production", table "dbo.Shipment", column 'Id'. The statement has been terminated.
Thank you, I copied code from shipstation plugin and wonder if that fails to: try { var order = _orderService.GetOrderByGuid(Guid.Parse(orderNumber));
if (order == null) return;
var shipments = _shipmentService.GetShipmentsByOrderId(order.Id);
if (!shipments.Any()) { var shipment = new Shipment { CreatedOnUtc = DateTime.UtcNow, ShippedDateUtc = DateTime.UtcNow, OrderId = order.Id, TrackingNumber = trackingNumber };
decimal totalWeight = 0;
foreach (var orderItem in _orderService.GetOrderItems(order.Id)) { var product = _productService.GetProductById(orderItem.ProductId);
//is shippable if (!product.IsShipEnabled) continue;
//ensure that this product can be shipped (have at least one item to ship) var maxQtyToAdd = _orderService.GetTotalNumberOfItemsCanBeAddedToShipment(orderItem); if (maxQtyToAdd <= 0) continue;
var warehouseId = product.WarehouseId;
//ok. we have at least one item. let's create a shipment (if it does not exist)
var orderItemTotalWeight = orderItem.ItemWeight * orderItem.Quantity; if (orderItemTotalWeight.HasValue) totalWeight += orderItemTotalWeight.Value;
//create a shipment item var shipmentItem = new ShipmentItem { OrderItemId = orderItem.Id, Quantity = orderItem.Quantity, WarehouseId = warehouseId };
Yes it does have the same problem - Here is a quick fix
/// <summary> /// Create or upadete shipping /// </summary> /// <param name="orderNumber"></param> /// <param name="carrier"></param> /// <param name="service"></param> /// <param name="trackingNumber"></param> public void CreateOrUpadeteShipping(string orderNumber, string carrier, string service, string trackingNumber) { try { var order = _orderService.GetOrderByGuid(Guid.Parse(orderNumber));
if (order == null) return;
var shipments = _shipmentService.GetShipmentsByOrderId(order.Id);
if (!shipments.Any()) { var shipment = new Shipment { CreatedOnUtc = DateTime.UtcNow, ShippedDateUtc = DateTime.UtcNow, OrderId = order.Id, TrackingNumber = trackingNumber };
_shipmentService.InsertShipment(shipment);
var newShipment = _shipmentService.GetShipmentsByOrderId(order.Id).FirstOrDefault();
decimal totalWeight = 0;
foreach (var orderItem in _orderService.GetOrderItems(order.Id)) { var product = _productService.GetProductById(orderItem.ProductId);
//is shippable if (!product.IsShipEnabled) continue;
//ensure that this product can be shipped (have at least one item to ship) var maxQtyToAdd = _orderService.GetTotalNumberOfItemsCanBeAddedToShipment(orderItem); if (maxQtyToAdd <= 0) continue;
var warehouseId = product.WarehouseId;
//ok. we have at least one item. let's create a shipment (if it does not exist)
var orderItemTotalWeight = orderItem.ItemWeight * orderItem.Quantity; if (orderItemTotalWeight.HasValue) totalWeight += orderItemTotalWeight.Value;
//create a shipment item var shipmentItem = new ShipmentItem { OrderItemId = orderItem.Id, Quantity = orderItem.Quantity, WarehouseId = warehouseId, ShipmentId = newShipment.Id };
Yes it does have the same problem - Here is a quick fix
/// <summary> /// Create or upadete shipping /// </summary> /// <param name="orderNumber"></param> /// <param name="carrier"></param> /// <param name="service"></param> /// <param name="trackingNumber"></param> public void CreateOrUpadeteShipping(string orderNumber, string carrier, string service, string trackingNumber) { try { var order = _orderService.GetOrderByGuid(Guid.Parse(orderNumber));
if (order == null) return;
var shipments = _shipmentService.GetShipmentsByOrderId(order.Id);
if (!shipments.Any()) { var shipment = new Shipment { CreatedOnUtc = DateTime.UtcNow, ShippedDateUtc = DateTime.UtcNow, OrderId = order.Id, TrackingNumber = trackingNumber };
_shipmentService.InsertShipment(shipment);
var newShipment = _shipmentService.GetShipmentsByOrderId(order.Id).FirstOrDefault();
decimal totalWeight = 0;
foreach (var orderItem in _orderService.GetOrderItems(order.Id)) { var product = _productService.GetProductById(orderItem.ProductId);
//is shippable if (!product.IsShipEnabled) continue;
//ensure that this product can be shipped (have at least one item to ship) var maxQtyToAdd = _orderService.GetTotalNumberOfItemsCanBeAddedToShipment(orderItem); if (maxQtyToAdd <= 0) continue;
var warehouseId = product.WarehouseId;
//ok. we have at least one item. let's create a shipment (if it does not exist)
var orderItemTotalWeight = orderItem.ItemWeight * orderItem.Quantity; if (orderItemTotalWeight.HasValue) totalWeight += orderItemTotalWeight.Value;
//create a shipment item var shipmentItem = new ShipmentItem { OrderItemId = orderItem.Id, Quantity = orderItem.Quantity, WarehouseId = warehouseId, ShipmentId = newShipment.Id };
For the life of me, I can't get this working. I uninstalled the plugin. Downloaded a fresh copy of the plugin. Made changes under the 4.3 version as above. Saved. Uploaded plugin with saved changes. Installed, connect back to shipstaion. Sent notification from shipstation. Same error in the log.