Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Combine orders in PRO

 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #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
  #2  
Old 11-17-2003, 01:57 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

I don't have a use for this but nice work and very, very ingenious.

This is really cool! Thanks for contributing.

Reply With Quote
  #3  
Old 11-18-2003, 07:47 AM
 
chikira chikira is offline
 

Advanced Member
  
Join Date: Jul 2003
Posts: 42
 

Default Bug Fix

Thanks ADP, I have a few other side projects that I will release over the next few weeks. Including a CMS manager with built in HTML editor.

For everyone else there is a small bug in the code. In /payment/paymentccend.php change the section that says

Quote:
if (count($orderids)>1){mergeorders($orderids);}

To

Quote:
mergeorders($orderids);

I found out that the shipping costs do not get calculated properly on some versions of xcart when they only have an order for a single provider. This forces all orders to go through the merge processor and figures out all the costs accordingly. Please post any other bugs here if there are any and I will be happy to figure it out for you.
__________________
Insert into Round_Hole where object=\"Square_Peg\" order by Brute_Force
Reply With Quote
  #4  
Old 11-19-2003, 08:20 AM
 
chikira chikira is offline
 

Advanced Member
  
Join Date: Jul 2003
Posts: 42
 

Default CMS Manager

I have just release another mod I was working on, a CMS manager for 3.4x.

http://forum.x-cart.com/viewtopic.php?t=7111

Check it out.
__________________
Insert into Round_Hole where object=\"Square_Peg\" order by Brute_Force
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:46 PM.

   

 
X-Cart forums © 2001-2020