View Single Post
  #1  
Old 11-17-2003, 12:42 PM
 
chikira chikira is offline
 

Advanced Member
  
Join Date: Jul 2003
Posts: 42
 

Default Combine orders in PRO

I don't know if anyone would find this useful but someone may. I had a client who supply's performance automotive parts from many manufacturers. To keep life simple I made them use X-Cart and treat every manufacture as a seperate provider. However when it came to the email notifications it produced 1 email for each manufacturer and when a customer ordered 10 products for 10 manufacturers that was a lot of mail!

I struggled with finding a way to combine multiple orders into 1 main order and only send 1 email out for both customer and admin.

I managed to figure it out after many pizzas, gallons of coffee and a few less hairs that I started with!

First of all I placed the code below into /payment/payment_ccend.php

Find the code that starts :

Quote:
if(!$fatal)
{
$order_status = ($bill_error) ? "F" : "P";

$advinfo = "";
$advinfo[] = "Reason: ".$bill_output["billmes"];
if($bill_output["avsmes"]) $advinfo[] = "AVS info: ".$bill_output["avsmes"];
if($bill_output["cvvmes"]) $advinfo[] = "CVV info: ".$bill_output["cvvmes"];

and replace with :

Quote:
if(!$fatal)
{
$order_status = ($bill_error) ? "F" : "P";

$advinfo = "";
$advinfo[] = "Reason: ".$bill_output["billmes"];
if($bill_output["avsmes"]) $advinfo[] = "AVS info: ".$bill_output["avsmes"];
if($bill_output["cvvmes"]) $advinfo[] = "CVV info: ".$bill_output["cvvmes"];
//New Merge Order Code
if (count($orderids)>1){mergeorders($orderids);}
$cart="";

This calls a new function in the /includes/func.php we will create in a moment. you also need to change the line that says:

Quote:
func_header_location("../customer/cart.php?".$sessurl."mode=order_message&orderids=" .$_orderids);

To:

Quote:
func_header_location("../customer/cart.php?".$sessurl."mode=order_message&orderids=" .$orderids[0]);

Now we need to add the function to the bottom of the func.php located in the /includes folder.

Just add this code to the bottom of the page before the last "?>".

Quote:
function mergeorders($orderids){
global $cart;
$primaryordernumber=$orderids[0];


for($t=0; $t<count($orderids); $t++) {

$currentorder=$orderids[$t];

if ($t>0){

$query="update xcart_order_details set orderid='$primaryordernumber', provider='MAR' where orderid = '$currentorder'";
$result = MYSQL_QUERY($query);

$oquery="delete from xcart_orders where orderid='$currentorder'";
$oresult = MYSQL_QUERY($oquery);

}else{
$query="update xcart_order_details set provider='MAR' where orderid = '$currentorder'";
$result = MYSQL_QUERY($query);

$oquery="update xcart_orders set total='".$cart[total_cost]."', giftcert_discount='".$cart[giftcert_discount]."', giftcert_ids='".$cart[applied_giftcerts]."', subtotal='".$cart[sub_total]."', discount='".$cart[discount]."', coupon='".$cart[coupon]."', coupon_discount='".$cart[coupon_discount]."', shipping_cost='".$cart[shipping_cost]."', tax='".$cart[tax_cost]."' where orderid = '$currentorder'";
$oresult = MYSQL_QUERY($oquery);
}

}//end for loop

$orderids="";
$orderids=array();
array_push($orderids, $primaryordernumber);


}

I am sure someone can imporve the code, I just thought I would throw it out there.

Basically this takes each of the order id's and creates a primary order id based on the first id in the list. It then assigns all the ordered parts to this primary order ID and takes the totals from the cart and assigns it directly to the primary order ID. the final step is to remove all extra orders.

This has worked fine in version 3.4x and as the cart finishes processing it only sees 1 order and sends out 1 email to the admin and to the customer.

Please let me know if anyone uses this code and finds it useful.
__________________
Insert into Round_Hole where object=\"Square_Peg\" order by Brute_Force
Reply With Quote