"Order" Object

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

"Order" Object

Post by vashts1980 » Fri Jun 10, 2011 10:13 am

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

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: "Order" Object

Post by AbleMods » Mon Jun 13, 2011 7:02 am

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.
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

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: "Order" Object

Post by vashts1980 » Mon Jun 13, 2011 8:33 am

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?

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: "Order" Object

Post by AbleMods » Mon Jun 13, 2011 8:49 am

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
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

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: "Order" Object

Post by vashts1980 » Mon Jun 13, 2011 9:07 am

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.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: "Order" Object

Post by AbleMods » Mon Jun 13, 2011 11:12 am

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.
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

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: "Order" Object

Post by vashts1980 » Mon Jun 13, 2011 11:36 am

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.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: "Order" Object

Post by AbleMods » Mon Jun 13, 2011 1:22 pm

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

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: "Order" Object

Post by vashts1980 » Mon Jun 13, 2011 1:25 pm

I did. It's at the end of the "if (response.Success)" block.

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: "Order" Object

Post by vashts1980 » Tue Jun 14, 2011 11:57 am

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?

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: "Order" Object

Post by vashts1980 » Tue Jun 14, 2011 12:29 pm

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?

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: "Order" Object

Post by AbleMods » Tue Jun 14, 2011 1:13 pm

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

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: "Order" Object

Post by vashts1980 » Tue Jun 14, 2011 1:53 pm

Ah, yes. I wasn't thinking about checking zero or null values. Thank you!

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: "Order" Object

Post by AbleMods » Tue Jun 14, 2011 8:36 pm

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

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: "Order" Object

Post by vashts1980 » Wed Jun 15, 2011 7:00 am

Hehe, yup.

Post Reply