Adding an order via an external method

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
RevereRichard
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Mon Jun 02, 2008 2:20 pm

Adding an order via an external method

Post by RevereRichard » Tue Jul 08, 2008 5:21 pm

Hello,

I have need to create an order via a web service. I tried the following code for a test:

Order or = new Order();
or.UserId = UserID;
or.OrderDate = oDate;
LSDecimal lsd = new LSDecimal(oAmount);
or.TotalCharges = lsd;
or.Save();

and received the following error:
The INSERT statement conflicted with the FOREIGN KEY constraint "ac_Orders_ac_OrderNotes_FK1"

Any help?

Thanks,

-Richard

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

Re: Adding an order via an external method

Post by AbleMods » Tue Jul 08, 2008 10:28 pm

First of all, "or" is a *really* bad variable name - hopefully that's just an example for the post.

Second, where are you getting the user ID? Web services don't have a .Net user associated with them during the authentication process. Hopefully this is something that you are obtaining elsewhere in the web service.

I can't reproduce what you're trying to do because the code you've posted isn't functional by itself. I can't be of much help.

Creating a new order is just a matter of creating a new instance of the order class and calling the save method. But there are several fields in the data classes that are not actual fields in the tables - they are calculated fields and were not designed to populated directly.
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

RevereRichard
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Mon Jun 02, 2008 2:20 pm

Re: Adding an order via an external method

Post by RevereRichard » Tue Jul 08, 2008 11:56 pm

The variables UserID, oDate and oAmount are supplied by an external source. For the purposes of this discussion just assume they are correct.

static void test(int UserID, DateTime oDate, decimal oAmount)
{
above code...
}

heh. yes or was just an example. :lol:

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Adding an order via an external method

Post by jmestep » Wed Jul 09, 2008 7:10 am

When I look at orders placed by customers, there is an order not associated at the time. Maybe that is a requirement? And/or if you are trying to insert it, maybe the key for the order is not generated before the insert to the Order notes table?
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

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

Re: Adding an order via an external method

Post by AbleMods » Wed Jul 09, 2008 7:41 am

Ok I see what you are trying to do.

The orders data class doesn't work that way though. It's designed from the perspective of a shopping cart system. You can't just make a new order class, load up a few fields and save it - you have to create a basket instance and process it through the checkoutrequest handler. You can do it with products, users etc because they are sub-components. But an order class combines all the various aspects of AC7 together and is dependent on many other data classes being properly prepared in advance.

This snippet is from the ~/Admin/Orders/PlaceOrder2.aspx.cs code file. Study this code file and you should be able to figure out how to do it. The basket is populated in ../PlaceOrder1.aspx.cs.

Code: Select all

//PROCESS THE CHECKOUT
            _Basket.Recalculate();
            Payment payment = new Payment();
            payment.Amount = _Basket.Items.TotalPrice();
            CheckoutRequest checkoutRequest = new CheckoutRequest(null);
            CheckoutResponse checkoutResponse = _Basket.Checkout(checkoutRequest);
            if (checkoutResponse.Success)
            {
                Session.Remove("PlaceOrderUserId");
                Response.Redirect("ViewOrder.aspx?OrderId=" + checkoutResponse.OrderId);
            }
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

RevereRichard
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Mon Jun 02, 2008 2:20 pm

Re: Adding an order via an external method

Post by RevereRichard » Wed Jul 09, 2008 12:19 pm

Thanks, will look into it.

-R

Post Reply