I want to get all the details of an order as soon as it is placed. order number, amount, order items etc. I think there is an order pipeline that could be helpful.
Can you please guide me through .NET example to acheive this and how to integrate with uCommerce?
I want get details of an order which is placed right now. Let me explain more, I want to add orders in my some other software using API, so when an order is placed in ucommerce, i want to get details of this particular order and send to my API, so what I want is:
-- get the details of an order as soon as it is placed
-- ability to get the details of the order being placed in .NET
The simplest way to place an order from an external system is to wrap the uCommerce API in a webservice and that. The call would basically have to create a new basket, add some products to it, and finally execute the Basket pipeline and the Checkout Pipeline.
The code would look something like this. What I do is create a new order, save that, add a product called "MyProduct", and finally execute the basket pipeline to get my totals tallied and the checkout pipeline to get an order number assigned and a couple of other things.
var catalogGroup = ProductCatalogGroup.SingleOrDefault(g => g.Name.Equals("MyStore");
var catalog = ProductCatalog.SingleOrDefault(c => c.Name.Equals("MyCatalog"));
var order = new PurchaseOrder();
order.OrderStatusId = 1;// Order Status == Basket
order.ProductCatalogGroup = catalogGroup;
order.CurrencyId = catalog.PriceGroups.First().Currencies.First().CurrencyId;
order.BasketId = Guid.NewGuid();
order.CreatedDate = DateTime.Now;
order.Save();
order.AddProduct(catalog, Product.Single(x => x.Sku = "MyProduct"), 1, 10.00m, true);
var basketPipeline = PipelineFactory.Create<PurchaseOrder>("Basket");
PipelineExecutionResult result = basketPipeline.Execute(order);
var checkoutPipeline = PipelineFactory.Create<PurchaseOrder>("Checkout");
PipelineExecutionResult result = checkoutPipeline.Execute(order);
// order now contains a fresh purchase order that you can can use from your own code
Thanks for the help but my question was something way around. I do not want to add another order from external resource.
I want to get the order details at the time when order is placed within ucommerce and then send these order details to my external software through API.
If I can get the details of the order from ucommerce, I can take care of rest of the things.
You have a couple of options to support this. The easiest option is to grab new orders using a scheduled task. Basically you'll create a service which runs once an hours or more often if that's needed. The service will load all orders created between the last run time and the current one. Orders can be loaded by their CompletedDate which is set during checkout.
Another option is to hook into the Checkout pipeline and transfer the order as the final step of checkout. The only caveat to this approach is that pipelines are executed synchronously which means that if the system you're sending the order to is slow to respond the customer will notice.
You can read more abut pipelines in the article uCommerce Pipelines Explained. The pipeline you want is called Checkout. You can find the configuration for that in /Umbraco/uCommerce/Pipelines/Checkout.config.
Please just guide me through how can I get list of all the orders? I have written following code
UCommerce.Entities.PurchaseOrder po = new UCommerce.Entities.PurchaseOrder(); int orderId = po.OrderId; // this is showing 0 DateTime orderdate = po.CreatedDate; // this is showing a raw date
Please suggest how to get all the orders recursively?
You can accomplish that with the following piece of code. The idea here is that each time you load orders from the system you save the date and time in lastExecutedDate. Next time you run the code you only ask for orders placed after lastExecutionDate which will give you new orders only.
If you just want all orders in the system you can loose the .Where() part of the call, but I would advise against it as performance over time will degrade if you see any significant order volume which will cause you to load up more and more orders.
get order details
Hi
I want to get all the details of an order as soon as it is placed. order number, amount, order items etc. I think there is an order pipeline that could be helpful.
Can you please guide me through .NET example to acheive this and how to integrate with uCommerce?
Nauman
Hi Nauman,
Not sure what you need. Do you want the order completed or just to retrieve an order already placed?
Hi Soren
I want get details of an order which is placed right now. Let me explain more, I want to add orders in my some other software using API, so when an order is placed in ucommerce, i want to get details of this particular order and send to my API, so what I want is:
-- get the details of an order as soon as it is placed
-- ability to get the details of the order being placed in .NET
I hope this makes sense.
Regards
Nauman
Thanks for clarifying.
The simplest way to place an order from an external system is to wrap the uCommerce API in a webservice and that. The call would basically have to create a new basket, add some products to it, and finally execute the Basket pipeline and the Checkout Pipeline.
The code would look something like this. What I do is create a new order, save that, add a product called "MyProduct", and finally execute the basket pipeline to get my totals tallied and the checkout pipeline to get an order number assigned and a couple of other things.
Soren
Thanks for the help but my question was something way around. I do not want to add another order from external resource.
I want to get the order details at the time when order is placed within ucommerce and then send these order details to my external software through API.
If I can get the details of the order from ucommerce, I can take care of rest of the things.
Your help is highly appreciated.
Nauman
Sorry about that :)
You have a couple of options to support this. The easiest option is to grab new orders using a scheduled task. Basically you'll create a service which runs once an hours or more often if that's needed. The service will load all orders created between the last run time and the current one. Orders can be loaded by their CompletedDate which is set during checkout.
Another option is to hook into the Checkout pipeline and transfer the order as the final step of checkout. The only caveat to this approach is that pipelines are executed synchronously which means that if the system you're sending the order to is slow to respond the customer will notice.
Soren
Is there a ucommerce library that I can use in my .NET code that exposes the order placed last? If yes how can I use that?
Nauman
There is. If you reference the uCommerce.dll assembly you'll have access to the APIs.
Where to configure the .NET code so that it is called when order is placed.
Any help how I can access the checkout pipeline and get the order details?
Nauman
Soren, any help available please?
Hi Nauman,
You can read more abut pipelines in the article uCommerce Pipelines Explained. The pipeline you want is called Checkout. You can find the configuration for that in /Umbraco/uCommerce/Pipelines/Checkout.config.
Soren
Please just guide me through how can I get list of all the orders? I have written following code
Please suggest how to get all the orders recursively?
Nauman
You can accomplish that with the following piece of code. The idea here is that each time you load orders from the system you save the date and time in lastExecutedDate. Next time you run the code you only ask for orders placed after lastExecutionDate which will give you new orders only.
If you just want all orders in the system you can loose the .Where() part of the call, but I would advise against it as performance over time will degrade if you see any significant order volume which will cause you to load up more and more orders.
is working on a reply...