Page 1 of 1
Problem Updating Shipping Status
Posted: Mon Apr 09, 2012 5:01 pm
by vashts1980
I've created a function that will retrieve orders with certain characteristics from different web-based software. The function then pulls the tracking numbers from these order records, adds the tracking numbers to the equivalent order in AbleCommerce, updates the AbleCommerce order shipping status to shipped, and saves the order. However, when I ran the first test, the tracking numbers were added, but the shipping status remained as unshipped. I've included a code snippet below. If anyone can pont me towards what I'm doing wrong that would be great.
Code: Select all
int acOrderId = OrderDataSource.LookupOrderId(acOrderNum);
Order updateOrder = OrderDataSource.Load(acOrderId);
List<String> tn = new List<String>();
// code to retrieve tracking numbers and add to List would be here
foreach (String trackNum in tn)
{
TrackingNumber trackingNum = new TrackingNumber();
trackingNum.TrackingNumberData = trackNum;
updateOrder.Shipments[0].TrackingNumbers.Add(trackingNum);
}
updateOrder.ShipmentStatus = OrderShipmentStatus.Shipped;
updateOrder.Save();
I also tried it by adding the following code, also with the same result...
Code: Select all
DateTime shipDate;
// the shipping date value is set here
changeOrder.Shipments[0].Ship(shipDate);
All of this is enclosed in try-catch blocks that call an e-mail submission method that I know works to inform me if there was any reported error. No errors are returned.
Re: Problem Updating Shipping Status
Posted: Mon Apr 09, 2012 6:46 pm
by david-ebt
Have you looked at the Admin\Orders\Shipments\ShipOrder.aspx.cs code? Here's a snippet:
Code: Select all
//Add the Tracking Number
int shipgwId = AlwaysConvert.ToInt(ShipGateway.SelectedValue);
string trackingData = AddTrackingNumber.Text;
if (!string.IsNullOrEmpty(trackingData))
{
TrackingNumber tnum = new TrackingNumber();
tnum.TrackingNumberData = trackingData;
tnum.ShipGatewayId = shipgwId;
tnum.OrderShipmentId = _OrderShipment.OrderShipmentId;
_OrderShipment.TrackingNumbers.Add(tnum);
}
//SHIP THE CURRENT SHIPMENT
_OrderShipment.Ship();
My initial guess is you'll need to set the shipping gateway ID. Do you have shipment gateways set up for each shipping carrier you're using?
Re: Problem Updating Shipping Status
Posted: Fri Apr 13, 2012 2:44 pm
by vashts1980
The shipping is being handled elsewhere, outside of AbleCommerce, and no shipping gateways have been set up.
Re: Problem Updating Shipping Status
Posted: Sat Apr 14, 2012 10:42 am
by david-ebt
In the tracking number data table, every tracking number record must have an OrderShipmentID it is associated with. The Shipping Gateway is optional. But you can set up shipping gateways in Able and not use them with the site. If you add shipping gateways, this will let the order page in My Account show a link to UPS/FedEx/etc with the tracking number.
Re: Problem Updating Shipping Status
Posted: Tue Apr 17, 2012 9:19 am
by vashts1980
Ok, I added the OderShipmentId to each tracking number record, but I still have the problem of the orders not being marked as shipped. I went and checked the logs and this is what I found...
From the error log:
Code: Select all
Error generating email messages for template 'Order Shipped Partial' having subject 'Part of your order has shipped from $store.Name'.
Code: Select all
Invocation of method 'ToString' in CommerceBuilder.Common.LSDecimal threw exception System.NullReferenceException : Object reference not set to an instance of an object.; Object reference not set to an instance of an object.
From the order history:
Code: Select all
The order has been partially shipped, 2 items remain unshipped.
The particular order which is referenced here only has one line item.
Re: Problem Updating Shipping Status
Posted: Tue Apr 17, 2012 9:33 am
by vashts1980
I dealt with some of that by going into the e-mail templates and removing the trigger from the e-mail template for partial orders. I'm just not sure why it's only partially shipping, though.
Re: Problem Updating Shipping Status
Posted: Tue Apr 17, 2012 4:01 pm
by david-ebt
Do you have more than one shipment for the order? The Ship() function looks at the shipments and if any of the shipment records are still shippable it marks the order an unshipped. Only if all of the shipments are shipped or do not contain any shippable products will it mark the order as shipped.
You can force the order to be shipped by using this code:
Code: Select all
OrderDataSource.UpdateShipmentStatus(order, OrderShipmentStatus.Shipped);
where "order" is your Order object.
Re: Problem Updating Shipping Status
Posted: Tue Apr 17, 2012 4:34 pm
by vashts1980
I did have it iterate through all of the Shipment objects in order.Shipments, but I still have the same issue. Also, I went to try out that force method of settign shipping, but I get an error that says
Code: Select all
'CommerceBuilder.Orders.OrderDataSource' does not contain a definition for 'UpdateShipmentStatus'
.
Re: Problem Updating Shipping Status
Posted: Tue Apr 17, 2012 5:13 pm
by david-ebt
My apologies. Try this
Code: Select all
order.ShipmentStatus = OrderShipmentStatus.Shipped;
order.Save();
Re: Problem Updating Shipping Status
Posted: Thu Apr 19, 2012 10:48 am
by vashts1980
This here is my functional code for handling the shipments for each order. The code you mentioned has been in here the whole time, actually, and it still thinks I'm only partially shipping the order.
Code: Select all
for (int ship = 0; ship < changeOrder.Shipments.Count; ship++)
{
foreach (String trackNum in tn)
{
TrackingNumber trackingNum = new TrackingNumber();
trackingNum.TrackingNumberData = trackNum;
trackingNum.OrderShipmentId = changeOrder.Shipments[ship].OrderShipmentId;
changeOrder.Shipments[ship].TrackingNumbers.Add(trackingNum);
}
}
for (int ship = 0; ship < changeOrder.Shipments.Count; ship++)
{
OrderShipment shipThis = OrderShipmentDataSource.Load(changeOrder.Shipments[ship].OrderShipmentId);
if (soToUpdate.shipDate != null)
{
shipThis.Ship(soToUpdate.shipDate);
}
else
shipThis.Ship();
}
changeOrder.ShipmentStatus = OrderShipmentStatus.Shipped;
changeOrder.Save();
Re: Problem Updating Shipping Status
Posted: Mon Apr 23, 2012 2:57 pm
by vashts1980
I went and revised my strategy for this problem. I ditched the DLL I was using and wrote an ASHX page to handle this, as it will allow me to update orders directly from the other system once they update. Here is my complete code for the ASHX page:
Code: Select all
<%@ WebHandler Language="C#" Class="OrderShipUpdate" %>
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using CommerceBuilder.Orders;
using CommerceBuilder.Shipping;
public class OrderShipUpdate : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
HttpRequest request = context.Request;
HttpResponse response = context.Response;
String trackingNums = request.Headers["trackingnums"];
String shipDate = request.Headers["shipdate"];
String orderNum = request.Headers["ordernum"];
response.ContentType = "text/xml";
response.ContentEncoding = Encoding.UTF8;
Int32 orderNumber = 0;
String ConvertError = "";
try
{
orderNumber = Convert.ToInt32(orderNum.Substring(2));
}
catch (Exception)
{
orderNumber = 0;
}
int acOrderId = OrderDataSource.LookupOrderId(orderNumber);
Order shippedOrder = new Order();
if (acOrderId != 0)
{
shippedOrder = OrderDataSource.Load(acOrderId);
if (shippedOrder != null)
{
List<String> tn = new List<String>();
if (trackingNums.Trim().Substring(0, 3).ToUpper() == "P/U")
trackingNums = "";
if (trackingNums.Trim() != "")
{
String[] TrackingNumbers = trackingNums.Split('/');
for (int nt = 0; nt < TrackingNumbers.Length; nt++)
{
String[] subTrackNums = TrackingNumbers[nt].Split(';');
for (int sub = 0; sub < subTrackNums.Length; sub++)
tn.Add(subTrackNums[sub].Replace("USPF", "UPSF").Trim());
}
}
for (int ship = 0; ship < shippedOrder.Shipments.Count; ship++)
{
OrderShipment shipment = OrderShipmentDataSource.Load(shippedOrder.Shipments[ship].OrderShipmentId);
foreach (OrderItem item in shipment.OrderItems)
{
item.Shippable = Shippable.Yes;
item.OrderShipmentId = shipment.OrderShipmentId;
for (int il = 0; il < shippedOrder.Items.Count; il++)
{
if (item.Sku == shippedOrder.Items[il].Sku)
{
item.Quantity = shippedOrder.Items[il].Quantity;
break;
}
}
item.Save();
}
if (tn.Count > 0 && tn.Count != shipment.TrackingNumbers.Count)
{
if (shipment.TrackingNumbers.Count > 0)
shipment.TrackingNumbers.DeleteAll();
foreach (String trackNum in tn)
{
TrackingNumber trackingNum = new TrackingNumber();
trackingNum.TrackingNumberData = trackNum;
trackingNum.OrderShipmentId = shipment.OrderShipmentId;
shipment.TrackingNumbers.Add(trackingNum);
}
}
shipment.Save();
shippedOrder.Save();
if (shipDate != null && shipDate != "")
{
shipment.Ship(DateTime.Parse(shipDate));
}
else
shipment.Ship();
}
shippedOrder = OrderDataSource.Load(shippedOrder.OrderId);
shippedOrder.ShipmentStatus = OrderShipmentStatus.Shipped;
shippedOrder.Save();
shippedOrder = OrderDataSource.Load(shippedOrder.OrderId);
if(shippedOrder.ShipmentStatus == OrderShipmentStatus.Shipped)
SendResponse(response, "SUCCESS");
else
SendResponse(response, "FAILED");
}
else
SendResponse(response, "FAILED");
}
else
SendResponse(response, "FAILED");
}
public bool IsReusable
{
get
{
return true;
}
}
private void SendResponse(HttpResponse response, String result)
{
String xmlResponse = "";
xmlResponse += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
xmlResponse += "<soapenv:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n";
xmlResponse += "\t<soapenv:Body>\n";
xmlResponse += "\t\t<Status>" + result + "</Status>\n";
xmlResponse += "\t</soapenv:Body>\n";
xmlResponse += "</soapenv:Envelope>\n";
response.Write(xmlResponse);
}
}
I still can't get the order to update to a "Shipped" status. I really need some help in getting this figured out.
Re: Problem Updating Shipping Status
Posted: Tue Apr 24, 2012 3:59 pm
by david-ebt
The only thing you don't have that we have in our code is to save the tracking number record. Try this:
Code: Select all
TrackingNumber trackingNum = new TrackingNumber();
trackingNum.TrackingNumberData = trackNum;
trackingNum.OrderShipmentId = shipment.OrderShipmentId;
trackingNum.Save();
shipment.TrackingNumbers.Add(trackingNum);
If that works, I would suggest you try removing some of your code. We're not doing anything with the order items. If the above change works, try removing this entire foreach block:
Code: Select all
foreach (OrderItem item in shipment.OrderItems)
Re: Problem Updating Shipping Status
Posted: Wed Apr 25, 2012 8:56 am
by vashts1980
Ah ha! That did it! Thank you!