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
Adding an order via an external method
-
- Ensign (ENS)
- Posts: 19
- Joined: Mon Jun 02, 2008 2:20 pm
Re: Adding an order via an external method
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.
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
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
-
- Ensign (ENS)
- Posts: 19
- Joined: Mon Jun 02, 2008 2:20 pm
Re: Adding an order via an external method
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.
static void test(int UserID, DateTime oDate, decimal oAmount)
{
above code...
}
heh. yes or was just an example.

- 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
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
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
Re: Adding an order via an external method
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.
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
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
-
- Ensign (ENS)
- Posts: 19
- Joined: Mon Jun 02, 2008 2:20 pm
Re: Adding an order via an external method
Thanks, will look into it.
-R
-R