Zen Cart Logo
Forums / General Questions / Setting order status based on zone

Setting order status based on zone

Views: 1,424

Results 1 to 16 of 16
25 Jul 2012, 3:24 PM
#1
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Setting order status based on zone

I have a customer that wants to set a special order status for all orders with international shipping addresses. He wants this set when the order is placed. I thought I would just replicate the payment modules and set them to use an international zone. That works but if the payment method has a US address and the shipping is international then it breaks. Even if I were to modify the shipping module to set a status it would be changed by the payment modules. Anybody have any suggestions on how to attack this?

25 Jul 2012, 11:02 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Setting order status based on zone

Is there anything special about this particular order-status? Is it equivalent to "Pending" in its meaning? Or to something else?

26 Jul 2012, 12:10 AM
#3
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Setting order status based on zone

Same as pending. there's nothing special

26 Jul 2012, 2:06 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Setting order status based on zone

Which payment module(s) are being used?

26 Jul 2012, 2:30 AM
#5
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Setting order status based on zone

Authorize.net aim
moneyorder
and paypal express

26 Jul 2012, 3:02 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Setting order status based on zone

Um, all of those modules use "Pending" and "Processing" to mean specific things.

What's the business problem you're trying to solve here?

  • Is it simply that you want to do additional vetting before approving the order?
  • Is there a reason why the standard "Pending" status wouldn't work for that?
  • (ie: Do you get zillions of in-country orders that get set to "Pending" status for some reason that would make it specifically necessary to distinguish them?)
  • Is it just that you want each module to specifically throw the order into "Pending" status even for fully-paid orders (which would otherwise normally be set to "Processing") if the shipping address is to a country that's not the same as your store's country?

Do you handle any virtual products or downloadable items in this store?

26 Jul 2012, 4:34 AM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Setting order status based on zone

Adding this to the bottom of the update_status() method in each of those payment modules might work:```
// CHECK IF SHIPPING ADDRESS IS OUTSIDE THE STORE'S COUNTRY, AND OVERRIDE ORDER-STATUS TO PENDING REGARDLESS OF DEFAULTS
$sql = "select ab.entry_country_id, ab.entry_zone_id
from " . TABLE_ADDRESS_BOOK . " ab
where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
and ab.address_book_id = '" . (int)$_SESSION['sendto'] . "' LIMIT 1";
$result = $db->Execute($sql);
if ($result->RecordCount() > 0 && $result->fields['entry_country_id'] != STORE_COUNTRY) { // or might use SHIPPING_ORIGIN_COUNTRY
$this->order_status = 1;
}

26 Jul 2012, 12:55 PM
#8
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Setting order status based on zone

DrByte:

Um, all of those modules use "Pending" and "Processing" to mean specific things.

What's the business problem you're trying to solve here?

  • Is it simply that you want to do additional vetting before approving the order?
  • Is there a reason why the standard "Pending" status wouldn't work for that?
  • (ie: Do you get zillions of in-country orders that get set to "Pending" status for some reason that would make it specifically necessary to distinguish them?)
  • Is it just that you want each module to specifically throw the order into "Pending" status even for fully-paid orders (which would otherwise normally be set to "Processing") if the shipping address is to a country that's not the same as your store's country?

Do you handle any virtual products or downloadable items in this store?

Thanks Dr B,
The business problem is that the client uses table rate shipping to calculate shipping charges. This usually works well for him but occasionally he gets an order to ship to an international address that costs him $30-50 over the charges calculated by the table rate. I have tried to get him to use live rates to calculate the charges and I've installed Conor's Advanced shipper module. This would require the client to invest time to identify products that had special shipping requirements. He has not been willing to spend the time to do that. What he wants is for all orders shipping to international addresses to go into a special status. I've created an order status "Review Shipping" for that purpose. His shipping department would review all orders in that status to compare the table rate to the actual shipping charges. If needed they would contact the customer to adjust the shipping charges. I know that he could just instruct his shipping department to do that for all international orders but for whatever reason that is not how he wants to handle it.

I appreciate the code and will let you know if it works. Again thanks for the help.

26 Jul 2012, 2:19 PM
#9
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Setting order status based on zone

I was able to add the code and it works correctly if the customer has a single address book entry. If the delivery address for the order is different than the entry in the address book it won't necessarily work. Is there any way to tie this to the delivery address or address book entry actually used?

26 Jul 2012, 2:29 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Setting order status based on zone

$_SESSION['sendto'] is the ID of the address_book entry that the customer is using for the delivery address

26 Jul 2012, 4:10 PM
#11
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Setting order status based on zone

The problem with it not working may be related to the FEC mod being installed. I'll need to see if I can work around this. I'm going to do a fresh local install any verify that it does work and then go from there. Thanks Dr B

26 Jul 2012, 6:17 PM
#12
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Setting order status based on zone

Dr Byte,
I did a fresh local install using the demo products and no mods. I added the code and installed the payment module. I'm working with moneyorder.php. I created an account and put two addresses in the address book. I added some code to echo the session variable and the sql that's being generated. In all cases the results are what you would expect. The session variable sento accurately reflects the address book entry, the sql reflects the customerid and sento, and the status is being set to the correct value. Something later on in the process seems to be always setting the status back to the default status for the payment module. I've changed the default for the payent module several times to verify that this is what's being set. I added the code you provided at line 56 of includes/modules/payment/moneyorder.php just before the closing bracket for the update_status function. Have I inserted this at the wrong spot or is the status being modified somewhere else in the checkout process?

26 Jul 2012, 7:11 PM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Setting order status based on zone

Hmmm ... could be a chicken/egg thing. Try moving it into the constructor method instead. Just before the closing brace.

26 Jul 2012, 9:18 PM
#14
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Setting order status based on zone

Well I made an omelet. The status was being reset in includes/classes/order.php. I made the following change at line 335

	 // CHECK IF SHIPPING ADDRESS IS OUTSIDE THE STORE'S COUNTRY, AND OVERRIDE ORDER-STATUS TO PENDING REGARDLESS OF DEFAULTS
	 $order_status1 = DEFAULT_ORDERS_STATUS_ID;
    $sql = "select ab.entry_country_id, ab.entry_zone_id
            from " . TABLE_ADDRESS_BOOK . " ab
            where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
            and ab.address_book_id = '" . (int)$_SESSION['sendto'] . "' LIMIT 1";
    $result = $db->Execute($sql);
    if ($result->RecordCount() > 0 && $result->fields['entry_country_id'] != STORE_COUNTRY) {   // or might use SHIPPING_ORIGIN_COUNTRY
      $order_status1 = 5;
    }

    $this->info = array('order_status' => $order_status1,

By adding your code there I was able to make it work without modifying any payment modules. I really appreciate all the help and thought I'd post the solution here so others might use it.

26 Jul 2012, 9:35 PM
#15
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Setting order status based on zone

In that case it would be more efficient, and code-friendly, if you put it near the bottom of that function instead. ie: directly above the line that says ```
$this->notify('NOTIFY_ORDER_CART_FINISHED');


Or let's scramble that omelet even more ... Far better yet would be to make it into a notifier/observer function call which fires when the NOTIFY_ORDER_CART_FINISHED notifier is triggered, so that you don't have to alter any core code in orders.php at all. 
Two parts to that:
/includes/classes/observers/class.international_order_status.php
<?php /** * @package plugins * @copyright Copyright 2003-2012 Zen Cart Development Team * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * * Designed for v1.5.0 */ class international_order_status extends base { function __construct() { $this->attach($this, array('NOTIFY_ORDER_CART_FINISHED')); $this->order_status_for_international_customers = 5; } function update(&$class, $eventID, $paramsArray = array()) { global $db; // CHECK IF SHIPPING ADDRESS IS OUTSIDE THE STORE'S COUNTRY, AND OVERRIDE ORDER-STATUS TO PENDING REGARDLESS OF DEFAULTS $sql = "select ab.entry_country_id, ab.entry_zone_id from " . TABLE_ADDRESS_BOOK . " ab where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "' and ab.address_book_id = '" . (int)$_SESSION['sendto'] . "' LIMIT 1"; $result = $db->Execute($sql); if ($result->RecordCount() > 0 && $result->fields['entry_country_id'] != STORE_COUNTRY) { // or might use SHIPPING_ORIGIN_COUNTRY $class->info['order_status'] = $this->order_status_for_international_customers; } } } ```and /includes/auto_loaders/config.international_order_status.php:``` <?php /** * * @package plugins * @copyright Copyright 2003-2012 Zen Cart Development Team * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 */ /** * Designed for v1.5.0 */ if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } $autoLoadConfig[190][] = array('autoType'=>'class', 'loadFile'=>'observers/class.international_order_status.php'); $autoLoadConfig[190][] = array('autoType'=>'classInstantiate', 'className'=>'international_order_status', 'objectName'=>'international_order_status'); ```
27 Jul 2012, 12:13 PM
#16
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Setting order status based on zone

Well Dr Byte, you are a fine chef. Thanks for the help.