Author Topic: In what php file is the order status processed?  (Read 2456 times)

Aeneas117

  • Beginner
  • *
  • Posts: 2
In what php file is the order status processed?
« on: April 05, 2011, 14:50:04 pm »
Hi everyone,

I was implementing a custom feature in Virtuemart 1.1.8. where the admin can add a amount that the user has to spend in the shop in order to get to a higher shopper group with a higher discount. The plan was to check to what group the user belongs at the moment that the admin updates the order status to "Shipped" to make sure that everything was paid.

The problem is that I don't sure where I have to put the code. I've been looking for the page that is called after the Update Status "button" is clicked. I think it is in ps_order.php , but I can't make it work. Here is the code I've used so far.
Code: [Select]
if($d["order_status"]=="S"){

//Determine the user ID that belongs to this order
$q = "SELECT user_id FROM #__{vm}_orders WHERE ";
$q .= "#__{vm}_orders.order_id='".$db->getEscaped($d['order_id'])."' ";
$db->query( $q );
$db->next_record();
$user_id = $db->f("user_id");

//Select all the order WHERE
//the orders are from this user,
//AND the order status = Shipped (and thus paid)
//AND the cdate > time()(current time at status update) - (number of days * 24(hours) * 60(minutes) * 60(seconds))

//$q = "SELECT * FROM #__{vm}_orders WHERE ";
$q = "SELECT SUM(order_total) as sum_totals FROM #__{vm}_orders WHERE ";
$q .= "#__{vm}_orders.user_id='".$user_id."' ";
$q .= "AND #__{vm}_orders.order_status= 'P' ";
$cur_time = time();
$min_time = $cur_time - (365 * 24 * 60 * 60);
$q .= "AND #__{vm}_orders.cdate>'".$min_time."' ";
$db->query( $q );
$db->next_record();
$sum_totals = $db->f("sum_totals");

$q = "SELECT * FROM #__{vm}_shopper_group WHERE #__{vm}_shopper_group.shopper_group_min_amt!> 0 ORDER BY #__{vm}_shopper_group.shopper_group_min_amt ASC ";
//$q .= "#__{vm}_shopper_group.shopper_group_min_amt!= 0";
$db->query( $q );
//$db->next_record();
$default = 1 ; // this way we know that if it is less then the min_amt we have to set the user to the default group
$placed = 0 ; // the user is not assigned to a group yet.
while($db->next_record()!=0 && $placed == 0){

if($sum_totals<$db->f("shopper_group_min_amt")){
if($default == 1){
//set the user group to default
$q = "SELECT shopper_group_id FROM #__{vm}_shopper_group WHERE #__{vm}_shopper_group.default = 0";
//$q .= "#__{vm}_shopper_group.shopper_group_min_amt!= 0";
$db->query( $q );
$db->next_record();

$db = new ps_DB;
$q = "UPDATE FROM #__{vm}_shopper_vendor_xref SET ";
 
//$q .= "#__{vm}_orders.user_id='".$user_id."' ";
$q .= "#__{vm}_shopper_vendor_xref.shopper_group_id='".$db->f("shopper_group_id")."' ";
$q .= "WHERE #__{vm}_shopper_vendor_xref.user_id='".$user_id."' ";
//$db->buildQuery('UPDATE', '#__{vm}_order_history', $fields );
$db->query($q);

$placed = 1; //user is placed in a group; stop the loop
}
else{
//place the user in the group with group_id = previous_id

$db = new ps_DB;
$q = "UPDATE FROM #__{vm}_shopper_vendor_xref SET ";
 
//$q .= "#__{vm}_orders.user_id='".$user_id."' ";
$q .= "#__{vm}_shopper_vendor_xref.shopper_group_id='".$previous_id."' ";
$q .= "WHERE #__{vm}_shopper_vendor_xref.user_id='".$user_id."' ";
//$db->buildQuery('UPDATE', '#__{vm}_order_history', $fields );
$db->query($q);

$placed = 1; //user is placed in a group; stop the loop  
}
}
else{
$previous_id = $db->f("shopper_group_id");
$default = 0;//next comparison has no default below
}

}
//$user_id = $db->f("user_id");

}
  If anyone knows where I have to place it, or sees something in my code that makes it not work, I'd really appreciate it.

Aeneas117

  • Beginner
  • *
  • Posts: 2
Re: In what php file is the order status processed?
« Reply #1 on: April 09, 2011, 13:04:15 pm »
Okay I fixed it. The status update does happen in ps_order.php. My code just had some very stupid mistakes and it depends on where you place it. It works great now!