"Order" Object
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
"Order" Object
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
--Mike
Re: "Order" Object
There is no "current" order object. It must be loaded specifically into an order object class like this:
At that point now you can work with the order itself by referencing the _Order variable.
Code: Select all
Order _Order = OrderDataSource.Load(1234); // Load Order ID 1234 into memory
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: "Order" Object
Ah, ok. I was browsing through some of the AC7 files and came across this code...
Would this be the best way to reference the current order and and grab the object to be passed?
Code: Select all
private Order _Order;
private int _OrderId = 0;
_OrderId = AlwaysConvert.ToInt(Request.QueryString["OrderId"]);
_Order = OrderDataSource.Load(_OrderId);
Re: "Order" Object
In the general sense, Yes that's the correct way.vashts1980 wrote:Would this be the best way to reference the current order and and grab the object to be passed?
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
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: "Order" Object
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
Ok. In that case though the OrderId will not be known as a query string parameter.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.
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.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: "Order" Object
Ah! Ok.
I took a look at it, and this is what I came up with...
And then I would just pass the Order object newOrder to my function.
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);
Re: "Order" Object
Exactly. Make sure you do it inside the if - successful portion, otherwise you risk sending a failed order to your new routine.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: "Order" Object
I did. It's at the end of the "if (response.Success)" block.
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: "Order" Object
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?
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: "Order" Object
Nevermind, I think I just figured out what I needed to know...
If I understand correctly, this would be a simple way to perform what I want to do, right?
Code: Select all
Order changeOrder = OrderDataSource.Load(OrderDataSource.LookupOrderId(int orderNumberVariable));
Re: "Order" Object
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 >
}
}
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: "Order" Object
Ah, yes. I wasn't thinking about checking zero or null values. Thank you!
Re: "Order" Object
After a few hundred hours of chasing seemingly random issues with your code, you finally learn to take nothing for granted 

Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: "Order" Object
Hehe, yup.