Commerce Server General - Creating a copy of an order

This is Interesting: Free IT Magazines  
Home > Archive > Commerce Server General > March 2006 > Creating a copy of an order





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Creating a copy of an order
Alejandro

2006-02-06, 5:53 pm

I want an admin user to be able to create a copy of an order and then be able
to modify it.
I don't know how to do it, I've created an OrderTemplate and then stored the
order forms, but I can't find the way to dump it in another order.
May be I'm not in the right way?
Neither do I know how to create a new PurchaseOrder, In that case may be I
could copy the order forms?
As you might have suspected, I'm new to commerce server (but working in an
existing project), so if you can also give me a link to a good tutorial it
will be great, I couldn't find anything good yet!
thanks
Ravi Shankar

2006-02-07, 2:48 am

Alejandro,

Use the Basket class
(http://msdn.microsoft.com/library/?....asp?frame=true),
specifically the Basket.Add(OrderTemplate) or Basket.Add(PurchaseOrder) to
load the template or order into the user basket for modification. Post
modification you'd need to re-run the basket, total, checkout or accept
pipelines before executing the BAsket.SaveAsOrder method to save the order.

A good tutotial for developers is available as part of the documentation at
http://msdn.microsoft.com/library/?....asp?frame=true
or you can use the sample sites or the starter site to get all this.
--
Ravi Shankar


"Alejandro" wrote:

> I want an admin user to be able to create a copy of an order and then be able
> to modify it.
> I don't know how to do it, I've created an OrderTemplate and then stored the
> order forms, but I can't find the way to dump it in another order.
> May be I'm not in the right way?
> Neither do I know how to create a new PurchaseOrder, In that case may be I
> could copy the order forms?
> As you might have suspected, I'm new to commerce server (but working in an
> existing project), so if you can also give me a link to a good tutorial it
> will be great, I couldn't find anything good yet!
> thanks

Alejandro

2006-02-07, 6:00 pm

I'm adding the purchase order to the basket, then executing pipelines info
and total (I'm not sure about it, but I've tried without them also and seems
the same) and I don't understand what's happening, any idea? I got that
error:

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: INSERT
statement conflicted with COLUMN FOREIGN KEY constraint
'FK_OrderFormLineItems_OrderGroup'. The conflict occurred in database
'commerce', table 'OrderGroup', column 'ordergroup_id'.[23000] The statement
has been terminated.[01000] INSERT statement conflicted with COLUMN FOREIGN
KEY constraint 'FK_OrderFormLineItems_OrderGroup'. The conflict occurred in
database 'commerce', table 'OrderGroup', column 'ordergroup_id'.



"Ravi Shankar" wrote:
[vbcol=seagreen]
> Alejandro,
>
> Use the Basket class
> (http://msdn.microsoft.com/library/?....asp?frame=true),
> specifically the Basket.Add(OrderTemplate) or Basket.Add(PurchaseOrder) to
> load the template or order into the user basket for modification. Post
> modification you'd need to re-run the basket, total, checkout or accept
> pipelines before executing the BAsket.SaveAsOrder method to save the order.
>
> A good tutotial for developers is available as part of the documentation at
> http://msdn.microsoft.com/library/?....asp?frame=true
> or you can use the sample sites or the starter site to get all this.
> --
> Ravi Shankar
>
>
> "Alejandro" wrote:
>
Ravi Shankar

2006-02-08, 7:48 am

Hi Alejandro,

when are you getting (at what statement ?) this error ?
Your call sequqnce should be something like

1. Basket.Load(PurchaseOrder)
2. Basket.Save
3. PurchaseOrder.item("order_status_code") = 8 // or whatever your order
status is for deleted orders
4. PurchaseOrder.Save()
5. Basket.RunPipeline(<---- basket.pcf --> )
6. Basket.RunPipeline(<---- total.pcf ---> )
..
..
Finally Basket.SaveAsOrder() to persist as new order onto the system.
--
Ravi Shankar


"Alejandro" wrote:
[vbcol=seagreen]
> I'm adding the purchase order to the basket, then executing pipelines info
> and total (I'm not sure about it, but I've tried without them also and seems
> the same) and I don't understand what's happening, any idea? I got that
> error:
>
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information about
> the error and where it originated in the code.
>
> Exception Details: System.Runtime.InteropServices.COMException: INSERT
> statement conflicted with COLUMN FOREIGN KEY constraint
> 'FK_OrderFormLineItems_OrderGroup'. The conflict occurred in database
> 'commerce', table 'OrderGroup', column 'ordergroup_id'.[23000] The statement
> has been terminated.[01000] INSERT statement conflicted with COLUMN FOREIGN
> KEY constraint 'FK_OrderFormLineItems_OrderGroup'. The conflict occurred in
> database 'commerce', table 'OrderGroup', column 'ordergroup_id'.
>
>
>
> "Ravi Shankar" wrote:
>
Alejandro

2006-03-01, 5:52 pm

I'm doing that:
po = ordersys.GetPurchaseOrder(userID, orderID);

po["order_status_code"]=4;
Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);
basket.Add(po);

PipelineInfo info = new PipelineInfo("basket");
basket.RunPipeline(info);

info = new PipelineInfo("total");
basket.RunPipeline(info);

basket.SaveAsOrder();

and getting in the last line the error:

Cannot insert the value NULL into column 'order_status_code', table
'NEJOnlineSite_commerce.dbo.OrderGroup'; column does not allow nulls. INSERT
fails.[23000] The statement has been terminated.[01000] Cannot insert the
value NULL into column 'order_status_code', table
'NEJOnlineSite_commerce.dbo.OrderGroup'; column does not allow nulls. INSERT
fails.


Any idea about why it doesn't find the order_status_code?
"Ravi Shankar" wrote:
[vbcol=seagreen]
> Hi Alejandro,
>
> when are you getting (at what statement ?) this error ?
> Your call sequqnce should be something like
>
> 1. Basket.Load(PurchaseOrder)
> 2. Basket.Save
> 3. PurchaseOrder.item("order_status_code") = 8 // or whatever your order
> status is for deleted orders
> 4. PurchaseOrder.Save()
> 5. Basket.RunPipeline(<---- basket.pcf --> )
> 6. Basket.RunPipeline(<---- total.pcf ---> )
> ..
> ..
> Finally Basket.SaveAsOrder() to persist as new order onto the system.
> --
> Ravi Shankar
>
>
> "Alejandro" wrote:
>
Ravi Shankar

2006-03-03, 6:18 pm

Alejandro,

You should use the
PurchaseOrder.OrderForms("default").Item("order_status_code") instead.

Actually you do not need to set the value to 4 (New Order) as the
Basket.SaveAsOrder does this for you.

If you're creating a fresh order post modification then your sequqnce should
be

po = OrderContext.GetPurchaseOrder(.., ..)
Basket.Load(..)
Basket.Add(po)
po.item("order_status_code") = * ' Whatever your deleted order code is
po.orderforms("default").item("order_status_code") = * ' same as above
po.save
po = nothing

basket.RunPipeline...
...
Basket.SaveAsOrder()

--
Ravi Shankar


"Alejandro" wrote:
[vbcol=seagreen]
> I'm doing that:
> po = ordersys.GetPurchaseOrder(userID, orderID);
>
> po["order_status_code"]=4;
> Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);
> basket.Add(po);
>
> PipelineInfo info = new PipelineInfo("basket");
> basket.RunPipeline(info);
>
> info = new PipelineInfo("total");
> basket.RunPipeline(info);
>
> basket.SaveAsOrder();
>
> and getting in the last line the error:
>
> Cannot insert the value NULL into column 'order_status_code', table
> 'NEJOnlineSite_commerce.dbo.OrderGroup'; column does not allow nulls. INSERT
> fails.[23000] The statement has been terminated.[01000] Cannot insert the
> value NULL into column 'order_status_code', table
> 'NEJOnlineSite_commerce.dbo.OrderGroup'; column does not allow nulls. INSERT
> fails.
>
>
> Any idea about why it doesn't find the order_status_code?
> "Ravi Shankar" wrote:
>
Ravi Shankar

2006-03-03, 6:18 pm

Found it... the documentation for changing the order_status_code... look it
up at
http://msdn.microsoft.com/library/d....asp?frame=true
--
Ravi Shankar


"Alejandro" wrote:
[vbcol=seagreen]
> I'm doing that:
> po = ordersys.GetPurchaseOrder(userID, orderID);
>
> po["order_status_code"]=4;
> Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);
> basket.Add(po);
>
> PipelineInfo info = new PipelineInfo("basket");
> basket.RunPipeline(info);
>
> info = new PipelineInfo("total");
> basket.RunPipeline(info);
>
> basket.SaveAsOrder();
>
> and getting in the last line the error:
>
> Cannot insert the value NULL into column 'order_status_code', table
> 'NEJOnlineSite_commerce.dbo.OrderGroup'; column does not allow nulls. INSERT
> fails.[23000] The statement has been terminated.[01000] Cannot insert the
> value NULL into column 'order_status_code', table
> 'NEJOnlineSite_commerce.dbo.OrderGroup'; column does not allow nulls. INSERT
> fails.
>
>
> Any idea about why it doesn't find the order_status_code?
> "Ravi Shankar" wrote:
>
Alejandro

2006-03-03, 6:18 pm

I'm doing that now:

po = ordersys.GetPurchaseOrder(userID, orderID);

Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);
basket.Add(po);

po["order_status_code"]=256;
po.OrderForms[0]["order_status_code"]=256;

po.Save();

po = null;
PipelineInfo info = new PipelineInfo("basket");
basket.RunPipeline(info);

info = new PipelineInfo("total");
basket.RunPipeline(info);

basket.SaveAsOrder();


and still getting the error about null order_status_code in the last line.

What I want to do is the following: an user has an order and he wants to do
a reorder, so the order must be copied as a new one, and he'll work in that
one.
I don't understand why should I mark the order as deleted!
And do you have any reference to understand that better? I copy your code
but I don't understand what is it exaclty doing!

thanks,
cucu


"Ravi Shankar" wrote:
[vbcol=seagreen]
> Found it... the documentation for changing the order_status_code... look it
> up at
> http://msdn.microsoft.com/library/d....asp?frame=true
> --
> Ravi Shankar
>
>
> "Alejandro" wrote:
>
Ravi Shankar

2006-03-03, 6:18 pm

Hi Alejandro,

I'll try an explain. In CS it is not an order as long as it stays a basket.
When you do a basket.saveasorder(), it gets persisted as an order (status =
4). Now how does this organization do order fulfillment ? In the simplest of
forms, someone keeps looking at the BizDesk and monitors "New Orders" and
probably takes a printout or something for picking, shipping, etc.

If a user wishes to modify the order.. then how does one indicate to the
backend that the previous order is NOT to be acted on ? In most scenarios,
there is a different system to do picking, shipping, financials etc. Marking
the order as deleted is just an indication that this order need not be acted
on. There is a call which allows you to delete the order from the DB but most
businesses do not do that since it impacts traceability..

To achieve this process there are two different ways. Most businesses that
allow modification of order have a limit beyond which an order in process
cannot be modified and is typically handled as sales returns or such.

What are the order modifications that may happen
1. Change in Product Quantity - this will impact the end price but if there
are discounts associated with quantity it may impact price of certain other
items (e.g.: if you have something like buy x qty of A and get 20% off on B)

2. Change in shipping instructions (destination, method, etc) - This might
impact taxation (inter-state and such), change in shipping terms and cost

3. Addition/deletion of a product - similar to point (1)

In CS, these computations are typically handled in the pipelines. There is
"RunPipeline" ability for purchaseOrder object you'd say, so why the basket.
For this you must understand what happens to the ordergroup as it transitions
from a basket to a order. The basket (so does the po) typically gets
initialized with all the addresses specified by the user. They may select one
for both shipping & billing in which case when the basket becomes an order,
all the addresses not referenced within the basket are removed before the PO
is written to the DB.

So the object that can cater to all possible modifications is the basket
which is why if an order needs to be modified you mark the previous placed
order as deleted, and add the contents to the cart. There is another
possiblity that the user may/may not confirm the modification in the same
session in which case a persisted cart still retains the contents... they may
come back after a day or so and confirm.

In a system we'd implemented we used to transmit the placed order to the
backend. When in the backend, the order was "picked" we sent a notification
back to CS which changed the order status to "process". A user could not
modify an order is the status was "process".

There are a lot of API available that alow for manipulation of the CS
objects. You need to think through the process and implement it using the
API's or custom code. What I'd written is not necessarily the only way or
rule by any measure.
--
Ravi Shankar


"Alejandro" wrote:
[vbcol=seagreen]
> I'm doing that now:
>
> po = ordersys.GetPurchaseOrder(userID, orderID);
>
> Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);
> basket.Add(po);
>
> po["order_status_code"]=256;
> po.OrderForms[0]["order_status_code"]=256;
>
> po.Save();
>
> po = null;
> PipelineInfo info = new PipelineInfo("basket");
> basket.RunPipeline(info);
>
> info = new PipelineInfo("total");
> basket.RunPipeline(info);
>
> basket.SaveAsOrder();
>
>
> and still getting the error about null order_status_code in the last line.
>
> What I want to do is the following: an user has an order and he wants to do
> a reorder, so the order must be copied as a new one, and he'll work in that
> one.
> I don't understand why should I mark the order as deleted!
> And do you have any reference to understand that better? I copy your code
> but I don't understand what is it exaclty doing!
>
> thanks,
> cucu
>
>
> "Ravi Shankar" wrote:
>
Alejandro

2006-03-13, 5:52 pm

Thanks a lot for the excellent explanation!! now I understand better the
theory...but unfortunatelly, still couldn't make it work!!

I'm doing that:

po = ordersys.GetPurchaseOrder(userID, orderID);

Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);

po["order_status_code"]=256;
po.OrderForms[0]["order_status_code"]=256;


basket.Add(po);


po.Save();

po = null;
PipelineInfo info = new PipelineInfo("basket");
basket.RunPipeline(info);

info = new PipelineInfo("total");
basket.RunPipeline(info);

basket.SaveAsOrder();

and getting the error "Cannot insert the value NULL into column
'order_status_code', table 'NEJOnlineSite_commerce.dbo.OrderGroup'; ..." on
the last line. But I tried debugging it, and
basket.OrderForms[0]["order_status_code"] worths 256, so I really don't
understand what's up!!
any idea about that?
thanks a lot!


"Ravi Shankar" wrote:
[vbcol=seagreen]
> Hi Alejandro,
>
> I'll try an explain. In CS it is not an order as long as it stays a basket.
> When you do a basket.saveasorder(), it gets persisted as an order (status =
> 4). Now how does this organization do order fulfillment ? In the simplest of
> forms, someone keeps looking at the BizDesk and monitors "New Orders" and
> probably takes a printout or something for picking, shipping, etc.
>
> If a user wishes to modify the order.. then how does one indicate to the
> backend that the previous order is NOT to be acted on ? In most scenarios,
> there is a different system to do picking, shipping, financials etc. Marking
> the order as deleted is just an indication that this order need not be acted
> on. There is a call which allows you to delete the order from the DB but most
> businesses do not do that since it impacts traceability..
>
> To achieve this process there are two different ways. Most businesses that
> allow modification of order have a limit beyond which an order in process
> cannot be modified and is typically handled as sales returns or such.
>
> What are the order modifications that may happen
> 1. Change in Product Quantity - this will impact the end price but if there
> are discounts associated with quantity it may impact price of certain other
> items (e.g.: if you have something like buy x qty of A and get 20% off on B)
>
> 2. Change in shipping instructions (destination, method, etc) - This might
> impact taxation (inter-state and such), change in shipping terms and cost
>
> 3. Addition/deletion of a product - similar to point (1)
>
> In CS, these computations are typically handled in the pipelines. There is
> "RunPipeline" ability for purchaseOrder object you'd say, so why the basket.
> For this you must understand what happens to the ordergroup as it transitions
> from a basket to a order. The basket (so does the po) typically gets
> initialized with all the addresses specified by the user. They may select one
> for both shipping & billing in which case when the basket becomes an order,
> all the addresses not referenced within the basket are removed before the PO
> is written to the DB.
>
> So the object that can cater to all possible modifications is the basket
> which is why if an order needs to be modified you mark the previous placed
> order as deleted, and add the contents to the cart. There is another
> possiblity that the user may/may not confirm the modification in the same
> session in which case a persisted cart still retains the contents... they may
> come back after a day or so and confirm.
>
> In a system we'd implemented we used to transmit the placed order to the
> backend. When in the backend, the order was "picked" we sent a notification
> back to CS which changed the order status to "process". A user could not
> modify an order is the status was "process".
>
> There are a lot of API available that alow for manipulation of the CS
> objects. You need to think through the process and implement it using the
> API's or custom code. What I'd written is not necessarily the only way or
> rule by any measure.
> --
> Ravi Shankar
>
>
> "Alejandro" wrote:
>
Ravi Shankar

2006-03-14, 2:48 am

Hi Alejandro,

please try the following sequence..

po = ordersys.GetPurchaseOrder(userID, orderID);

Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);

// Add the po to the basket & save the basket first.
basket.Add(po);
basket.save();
//
// Then change the status and save the PO
po["order_status_code"]=256;
po.OrderForms[0]["order_status_code"]=256;
po.Save();
po = null;

// now run the pipelines (preferably in the try {} catch block)
PipelineInfo info = new PipelineInfo("basket");
basket.RunPipeline(info);
//
// Ideally you should check for _basket_errors here
//
info = new PipelineInfo("total");
basket.RunPipeline(info);
basket.SaveAsOrder();

--
Ravi Shankar


"Alejandro" wrote:
[vbcol=seagreen]
> Thanks a lot for the excellent explanation!! now I understand better the
> theory...but unfortunatelly, still couldn't make it work!!
>
> I'm doing that:
>
> po = ordersys.GetPurchaseOrder(userID, orderID);
>
> Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);
>
> po["order_status_code"]=256;
> po.OrderForms[0]["order_status_code"]=256;
>
>
> basket.Add(po);
>
>
> po.Save();
>
> po = null;
> PipelineInfo info = new PipelineInfo("basket");
> basket.RunPipeline(info);
>
> info = new PipelineInfo("total");
> basket.RunPipeline(info);
>
> basket.SaveAsOrder();
>
> and getting the error "Cannot insert the value NULL into column
> 'order_status_code', table 'NEJOnlineSite_commerce.dbo.OrderGroup'; ..." on
> the last line. But I tried debugging it, and
> basket.OrderForms[0]["order_status_code"] worths 256, so I really don't
> understand what's up!!
> any idea about that?
> thanks a lot!
>
>
> "Ravi Shankar" wrote:
>
Alejandro

2006-03-14, 5:52 pm

Thanks a lot!
now it works, I had to copy also addresses and some other fields, but seems
to be working fine now.
I really appreciate your help, thanks again!!


"Ravi Shankar" wrote:
[vbcol=seagreen]
> Hi Alejandro,
>
> please try the following sequence..
>
> po = ordersys.GetPurchaseOrder(userID, orderID);
>
> Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);
>
> // Add the po to the basket & save the basket first.
> basket.Add(po);
> basket.save();
> //
> // Then change the status and save the PO
> po["order_status_code"]=256;
> po.OrderForms[0]["order_status_code"]=256;
> po.Save();
> po = null;
>
> // now run the pipelines (preferably in the try {} catch block)
> PipelineInfo info = new PipelineInfo("basket");
> basket.RunPipeline(info);
> //
> // Ideally you should check for _basket_errors here
> //
> info = new PipelineInfo("total");
> basket.RunPipeline(info);
> basket.SaveAsOrder();
>
> --
> Ravi Shankar
>
>
> "Alejandro" wrote:
>
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com