Developer forum

Forum » Integration » Order Destination Provider With 1 Order Line

Order Destination Provider With 1 Order Line

Casper Andersen
Reply

Hi DynamicWeb

 

I am having some trouble getting my custom destination provider to create an order with an order line.

The problem is that first i run through my mappings on the EcomOrders table, and add the information to my Order object. While i do this, i create a new OrderID with the code Dynamicweb.eCommerce.Common.NumberGenerator.GetNumber("ORDER");

and at the same time i create an OrderLine and assign it the OrderLineOrderID i just created for my Order, all this seems to work fine. But if i only run this for my EcomOrders table, then the information added to the EcomOrderLines table is not saved, so my question is how do i in my destination provider create an order with an orderline and getting both saved?

If anyone has some sample integration code i could look at that would be great. 


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Casper,
try this code for saving a new order line to order:

OrderLine orderLine = new OrderLine();
//set your orerline properties
///
orderLine.Type = ((int)OrderLineType.Product).ToString();
//associate with order
orderLine.Order = order;
order.OrderLines.Add(orderLine);
order.Save();
Regards, Dmitrij

 
Casper Andersen
Reply

Hi Dmitriy

 

i Fear i may have said something wrong here, my bad. What i actually am doing, is creating my own Source provider that will generate orders and i want to send the orders to the standard Order destination provider.

The problem i am having is that i am getting my data from a CRM system, and then creating my Orders and OrderLines and then passing that information into my GetNext method where i then map the fields required. Problem here is that because i using the table EcomOrders and EcomOrderLines, the integration wants to run twice. I fixed this by adding this if statement around my SourceProvider

if (mapping.SourceTable.Name == "EcomOrders")
 {

// Do Stuff

}

And all the Orders are added finem but not the OrderLines.

 

Sorry for the confusion.

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Casper,
can you share your source codes?
Regards, Dmitrij

 
Casper Andersen
Reply

Hope this clears things up a bit

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

HI Casper,
maybe you are doing some things wrong. If you are writting your own source provider for reading the new orders that need to be then exported to Dynamicweb order provider
then you do not need to save the order with order lines itself to Dynamicweb as this will be done in the destination Order provider,
so you need to implement the GetNext method that will output the "Orders" and "OrderLines" in your Source reader.
To load data just once you can implement the loading in the SourceProvider: LoadSettings(Job job) method
In the GetReader pass your data object
public ISourceReader GetReader(Mapping mapping)
        {
            return new ExampleSourceReader(mapping, _objectWithOrdersAndOrderlines);
        }
In the SourceReader:
public ExampleSourceReader(Mapping mapping, objectWithOrdersAndOrderlines)
        {
            //Usually, there will be a contructor that takes a mapping as an argument.
            _mapping = mapping;

if (mapping.SourceTable.Name == "EcomOrders")
 {

// Do Stuff for getting the orders from your passed objectWithOrdersAndOrderlines

}else{
//get your OrderLines

}

        }
public Dictionary<string, object> GetNext()
        {
            Dictionary<string, object> result = new Dictionary<string, object>();
//return the results - enumerate you data object, increase counter and return the next data
//for the exporting orders case
            result.Add("OrderID", "1");
            result.Add("OrderComplete", 0);
//some other fields

//for the exporting orderlines case
            result.Add("OrderLineID", "1");
            result.Add("OrderLineOrderID", "1");
//some other fields

            return result;
        }

Regards,
Dmitrij

Votes for this answer: 1
 
Casper Andersen
Reply

sorry for the late reply, but things have been hectic as always :) Anyway this was exactley what i needed, adding the order and orderline to my custom object in the LoadSettings section made it so all the data was ready, and when the sourcetable was EcomOrders i just added all the order from my custom object and when it was EcomOrderLines i added the order lines.

Thanks a lot for all your help!

 

You must be logged in to post in the forum