Page 1 of 1
"Order" Object
Posted: Fri Jun 10, 2011 10:13 am
by vashts1980
I'm wanting to get certain information that's stored in the Order object, but I'm not sure how to call it. For example, I can get the current User object by calling Token.Instance.User. In C#, how would I grab the Order object so I can pass it to custom function?
--Mike
Re: "Order" Object
Posted: Mon Jun 13, 2011 7:02 am
by AbleMods
There is no "current" order object. It must be loaded specifically into an order object class like this:
Code: Select all
Order _Order = OrderDataSource.Load(1234); // Load Order ID 1234 into memory
At that point now you can work with the order itself by referencing the _Order variable.
Re: "Order" Object
Posted: Mon Jun 13, 2011 8:33 am
by vashts1980
Ah, ok. I was browsing through some of the AC7 files and came across this code...
Code: Select all
private Order _Order;
private int _OrderId = 0;
_OrderId = AlwaysConvert.ToInt(Request.QueryString["OrderId"]);
_Order = OrderDataSource.Load(_OrderId);
Would this be the best way to reference the current order and and grab the object to be passed?
Re: "Order" Object
Posted: Mon Jun 13, 2011 8:49 am
by AbleMods
vashts1980 wrote:Would this be the best way to reference the current order and and grab the object to be passed?
In the general sense, Yes that's the correct way.
However without knowing where you are putting this code, I cannot answer if it will work for pulling the "current" order. Since the order ID is being provided by the query string on the request URL, it could be used anywhere so long as the query string is passed a valid Order ID value.
Also, you'll probably want to test the order object for null to ensure the provided order ID was valid. Something like:
Code: Select all
_Order = OrderDataSource.Load(_OrderId);
if ( _Order == null)
return; // specified order ID could not be found
Re: "Order" Object
Posted: Mon Jun 13, 2011 9:07 am
by vashts1980
THis would all be in the OnePageCheckout.acsx.cs file. The variable declaration would most likely be made near the head of the file within the class and the grabbing of the actual object is planned to occur in the CHeckedOut function right before calling the custom function.
Re: "Order" Object
Posted: Mon Jun 13, 2011 11:12 am
by AbleMods
vashts1980 wrote:The variable declaration would most likely be made near the head of the file within the class and the grabbing of the actual object is planned to occur in the CHeckedOut function right before calling the custom function.
Ok. In that case though the OrderId will not be known as a query string parameter.
In void CheckedOut(), there is a variable defined as a parameter of the function. Expose that and you'll see there is an OrderId value associated with the checkout result. This value indicates the assigned order Id from a successful checkout process.
Might be easier to do it in receiptpage.ascx depending on your needs.
Re: "Order" Object
Posted: Mon Jun 13, 2011 11:36 am
by vashts1980
Ah! Ok.
I took a look at it, and this is what I came up with...
Code: Select all
int newOrderId = response.OrderId;
Order newOrder = OrderDataSource.Load(newOrderId);
And then I would just pass the Order object newOrder to my function.
Re: "Order" Object
Posted: Mon Jun 13, 2011 1:22 pm
by AbleMods
Exactly. Make sure you do it inside the if - successful portion, otherwise you risk sending a failed order to your new routine.
Re: "Order" Object
Posted: Mon Jun 13, 2011 1:25 pm
by vashts1980
I did. It's at the end of the "if (response.Success)" block.
Re: "Order" Object
Posted: Tue Jun 14, 2011 11:57 am
by vashts1980
One more question. I'll be wanting to reference the orders in another way, as well. I'll be pulling information in from an external ERP web app, which I believe I mentioned in a different post you responded to. Unfortunately, the order id numbers between the two systems won't match so I'll have to go by the order name/number instead (I pass that value from AC7 to the order number field in the ERP app). I'm still not too familiar with how to retrieve data from the database, so how would I be able to pull that order object in that manner?
Re: "Order" Object
Posted: Tue Jun 14, 2011 12:29 pm
by vashts1980
Nevermind, I think I just figured out what I needed to know...
Code: Select all
Order changeOrder = OrderDataSource.Load(OrderDataSource.LookupOrderId(int orderNumberVariable));
If I understand correctly, this would be a simple way to perform what I want to do, right?
Re: "Order" Object
Posted: Tue Jun 14, 2011 1:13 pm
by AbleMods
That will work. But it would be cleaner to do it like this:
Code: Select all
int _OrderId = OrderDataSource.LookupOrderId(_OrderNumberVariable);
if ( _OrderId != 0 )
{
Order changeOrder = OrderDataSource.Load(_OrderId);
if ( changeOrder != null )
{
< your code >
}
}
Re: "Order" Object
Posted: Tue Jun 14, 2011 1:53 pm
by vashts1980
Ah, yes. I wasn't thinking about checking zero or null values. Thank you!
Re: "Order" Object
Posted: Tue Jun 14, 2011 8:36 pm
by AbleMods
After a few hundred hours of chasing seemingly random issues with your code, you finally learn to take nothing for granted

Re: "Order" Object
Posted: Wed Jun 15, 2011 7:00 am
by vashts1980
Hehe, yup.