Users can take advantage of the Infoplus scripting capability to automatically merge orders together without having to manually edit each of them. This article will explain one way that this can be accomplished through a custom field and a bit of code.
Due to the ever-changing nature of writing and maintaining scripts, Infoplus does not provide support in this area. We recommend someone in your IT Department handles scripting requests internally so that you keep all control over the process.
Note that changes made in Infoplus will NOT be communicated back to shopping cart connections automatically. |
First, create a Custom Field on your order table and give it an appropriate name, such as 'Merge With Order.' This field will be used to tell Infoplus what order you would like to merge into the order you are working with. For example, if you are attempting to merge order 1.000 into order 2.000, you can edit 2.000 (or whichever order you want to use) and enter 1.000 into this custom field. Make sure you include the .000.
Note that if you are attempting to merge more than two orders you would need additional custom fields to handle them. It is also worth mentioning that if you are attempting to merge orders with the same line items, you will get an error unless your site is configured to allow duplicate line items per order. If your site is not configured to allow this, you can enter a support ticket to request it.
Once you have the custom field created you will need to create a script to execute this task. Give the script an appropriate name, choose record for script type, order for record type and beta for the API Version.
Next, copy and paste the javascript code shown below and make sure that the variable looking for the custom field you created is named correctly and updated throughout the code. Here is where that variable is established:
var mergeWithOrder = order.customFields.get("mergeWithOrder");
No other variables in this script should need manipulated.
////////////////////////////////////////////////////////////////// // First we will make sure the order is in an 'On Order' status // ////////////////////////////////////////////////////////////////// if(order.status == "On Order") { /////////////////////////////////////////////////////// // Next we will get the order that we want to merge // // into this order via 'mergeWithOrder' custom field // /////////////////////////////////////////////////////// var mergeWithOrder = order.customFields.get("mergeWithOrder"); if(mergeWithOrder) { utils.log("Attempting to Merge Order with: " + mergeWithOrder); } else { utils.log("Did Not Find an Order to Merge With, Please Check the Merge With Order Field and Try Again"); return; } /////////////////////////////////////////////////////////////////////////// // use the API to lookup the order that we want to merge into this order // /////////////////////////////////////////////////////////////////////////// var mergeOrder = infoplusApi.getById("Order", mergeWithOrder); if(mergeOrder) { /////////////////////////////////////////////////////////////// // Make sure the order being merged is in an on order status // /////////////////////////////////////////////////////////////// if(mergeOrder.status == "On Order") { var orderLines = mergeOrder.lineItems; utils.log("Found " + orderLines.size()+ " Order Lines: " + orderLines); //////////////////////////////////////////////////////////////////////// // Loop through each line on the order to merge and add to this order // //////////////////////////////////////////////////////////////////////// for(var i=0; i<orderLines.size(); i++) { var lineToAdd = orderLines.get(i); utils.log("Adding line item: " + lineToAdd.sku); order.addToLineItems(lineToAdd); } ////////////////////////////////////////// // Now we will update the current order // ////////////////////////////////////////// utils.log("Adding line items: " + order.lineItems.size()); infoplusApi.update("Order", order); /////////////////// // Tag the order // /////////////////// infoplusApi.addTag("order", order.orderNo, "Merged Order"); ////////////////////////////////////// // delete the order that was merged // ////////////////////////////////////// infoplusApi.delete("Order", mergeOrder.orderNo); } else { utils.log("Order " + mergeWithOrder.orderNo + " is not in an On Order Status, Cannot Merge."); return; } } } else { utils.log("Order " + order.orderNo + " is not in an On Order Status, cannot merge"); }
To run this script, select the order that contains the 'Merge With' value and choose 'Run Script' from the action menu drop down. Choose the script you just created and hit submit.