If this is your first visit, check our documentation. To post, register or login.
Forums / Upgrading to 2.x.x / Purchase Order Plugin for v 2.1

Purchase Order Plugin for v 2.1

Started by jg64 on 30 Jan 2025, 4:54 PM · Views: 1,662

Results 1 to 11 of 11
30 Jan 2025, 4:54 PM
#1
jg64 avatar

jg64

New Zenner

Join Date:
Jul 2015
Location:
Allentown, PA
Posts:
41
Plugin Contributions:
0

Purchase Order Plugin for v 2.1

We have been using ZenCart since 2009 and have always had a purchase order option for a payments. We are upgrading to v 2.1 from v 1.5.7c and see that the basic purchase order plugin has not been upgraded in some time. I downloaded the latest version and uploaded via ftp the 'includes' directory (to our test environment) as we have done in the past, on the hopes it might work with the new version -- no surprise -- no luck.
I am looking for someone to guide me, or assist me in upgrading this plugin to function with v 2.1. It is a critical component for our store and we work with municipalities and more than half of our sales are via purchase order.
I know it's a relatively simple plugin, as there are only two files - purchaseorder.php - in modules and language folders.
I would be very appreciative for any assistance. Dr. Byte - I know you assisted with the last version.
Thanks,
JG

31 Jan 2025, 4:06 PM
#2
jg64 avatar

jg64

New Zenner

Join Date:
Jul 2015
Location:
Allentown, PA
Posts:
41
Plugin Contributions:
0

Re: Purchase Order Plugin for v 2.1

I have made an attempt to update the /includes/modules/payment/purchaseorders.php code to work with ZenCart v2.1 and PHP v8.3. Here is what I have come up with:

 <?php
if (!defined('TABLE_CUSTOMERS')) {
  define('TABLE_CUSTOMERS', 'zen_customers');
}

if (!defined('TABLE_GROUP_PRICING')) {
  define('TABLE_GROUP_PRICING', 'zen_group_pricing');
}

class purchaseorder extends base {
  public $code;
  public $title;
  public $description;
  public $enabled;
  public $sort_order;
  public $order_status;

  public function __construct() {
    global $order;

    $this->code = 'purchaseorder';
    $this->title = MODULE_PAYMENT_PURCHASEORDER_TEXT_TITLE;
    $this->description = MODULE_PAYMENT_PURCHASEORDER_TEXT_DESCRIPTION;
    $this->sort_order = defined('MODULE_PAYMENT_PURCHASEORDER_SORT_ORDER') ? MODULE_PAYMENT_PURCHASEORDER_SORT_ORDER : 0;
    $this->enabled = (defined('MODULE_PAYMENT_PURCHASEORDER_STATUS') && MODULE_PAYMENT_PURCHASEORDER_STATUS == 'True');

    if ((int)MODULE_PAYMENT_PURCHASEORDER_ORDER_STATUS_ID > 0) {
      $this->order_status = MODULE_PAYMENT_PURCHASEORDER_ORDER_STATUS_ID;
    }
  }

  public function update_status() {
    global $order;

    if (($this->enabled == true) && ((int)MODULE_PAYMENT_PURCHASEORDER_ZONE > 0)) {
      $check_flag = false;
      $check_query = zen_db_query("SELECT zone_id FROM " . TABLE_ZONES_TO_GEO_ZONES . " WHERE geo_zone_id = '" . MODULE_PAYMENT_PURCHASEORDER_ZONE . "' AND zone_country_id = '" . $order->billing['country']['id'] . "' ORDER BY zone_id");
      while ($check = zen_db_fetch_array($check_query)) {
        if ($check['zone_id'] < 1) {
          $check_flag = true;
          break;
        } elseif ($check['zone_id'] == $order->billing['zone_id']) {
          $check_flag = true;
          break;
        }
      }

      if ($check_flag == false) {
        $this->enabled = false;
      }
    }
  }

  public function javascript_validation() {
    return false;
  }

  public function selection() {
    return array('id' => $this->code,
                 'module' => $this->title);
  }

  public function pre_confirmation_check() {
    return false;
  }

  public function confirmation() {
    return array('title' => $this->title);
  }

  public function process_button() {
    return false;
  }

  public function before_process() {
    return false;
  }

  public function after_process() {
    return false;
  }

  public function get_error() {
    return false;
  }

  public function check() {
    if (!isset($this->_check)) {
      $check_query = zen_db_query("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_PAYMENT_PURCHASEORDER_STATUS'");
      $this->_check = zen_db_num_rows($check_query);
    }
    return $this->_check;
  }

  public function install() {
    zen_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable Purchase Order Module', 'MODULE_PAYMENT_PURCHASEORDER_STATUS', 'True', 'Do you want to accept purchase order payments?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
    zen_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Sort order of display.', 'MODULE_PAYMENT_PURCHASEORDER_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    zen_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Payment Zone', 'MODULE_PAYMENT_PURCHASEORDER_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
    zen_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Set Order Status', 'MODULE_PAYMENT_PURCHASEORDER_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'zen_get_order_status_name', 'zen_cfg_pull_down_order_statuses(', now())");
  }

  public function remove() {
    zen_db_query("DELETE FROM " . TABLE_CONFIGURATION . " WHERE configuration_key in ('MODULE_PAYMENT_PURCHASEORDER_STATUS', 'MODULE_PAYMENT_PURCHASEORDER_SORT_ORDER', 'MODULE_PAYMENT_PURCHASEORDER_ZONE', 'MODULE_PAYMENT_PURCHASEORDER_ORDER_STATUS_ID')");
  }

  public function keys() {
    return array('MODULE_PAYMENT_PURCHASEORDER_STATUS', 'MODULE_PAYMENT_PURCHASEORDER_SORT_ORDER', 'MODULE_PAYMENT_PURCHASEORDER_ZONE', 'MODULE_PAYMENT_PURCHASEORDER_ORDER_STATUS_ID');
  }
}

When I uploaded it to the test store and logged in to the admin area - 'modules/payments' does not show the plugin, so I am unable to install it. Any suggestions on how to fix the code would be greatly appreciated. I would like to get this plugin upgraded to v2.1 for all.

31 Jan 2025, 5:31 PM
#3
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
509
Plugin Contributions:
1

Re: Purchase Order Plugin for v 2.1

I don't know if there is more missing but you need to define $_check as a variable. You probably got an error log file when you went in to admin>modules>payment. That should give you clues as to what is missing.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\

31 Jan 2025, 6:11 PM
#4
jg64 avatar

jg64

New Zenner

Join Date:
Jul 2015
Location:
Allentown, PA
Posts:
41
Plugin Contributions:
0

Re: Purchase Order Plugin for v 2.1

Mark,

I don't see anything in the logs for today. I'm looking in public_html/demo_store_directory/logs. I see no logs directory under the admin directory. Am I not looking in the right place?

31 Jan 2025, 7:31 PM
#5
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Re: Purchase Order Plugin for v 2.1

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

31 Jan 2025, 8:09 PM
#6
jg64 avatar

jg64

New Zenner

Join Date:
Jul 2015
Location:
Allentown, PA
Posts:
41
Plugin Contributions:
0

Re: Purchase Order Plugin for v 2.1

swguy...thanks for the reply. Yes, there are debug files in the log directory of my demo store:
index.html
index.php
myDEBUG-20250129-181404-056927.log
myDEBUG-20250129-181422-736257.log
myDEBUG-20250129-181435-105173.log
myDEBUG-adm-20250130-113851-648035-deprecated.log
myDEBUG-adm-20250130-113851-648035-warning.log
myDEBUG-adm-20250130-113907-420620-deprecated.log
myDEBUG-adm-20250130-113907-420620-warning.log
myDEBUG-adm-20250130-113913-770664-deprecated.log
myDEBUG-adm-20250130-113913-770664-warning.log
myDEBUG-adm-20250130-113945-317881-deprecated.log
myDEBUG-adm-20250130-113945-317881-warning.log
myDEBUG-adm-20250130-114025-896124-deprecated.log
myDEBUG-adm-20250130-114025-896124-warning.log
myDEBUG-adm-20250130-114029-175409-deprecated.log
myDEBUG-adm-20250130-114029-175409-warning.log
myDEBUG-adm-20250130-114040-734170-deprecated.log
myDEBUG-adm-20250130-114040-734170-warning.log
myDEBUG-adm-20250130-114113-617140-deprecated.log
myDEBUG-adm-20250130-114113-617140-warning.log
zcInstallDEBUG-1738094716-358847.log
zcInstallDEBUG-1738192331-4848.log
zca_bootstrap_20250128154244.log
There just aren't any from today and I've been updating the purchaseorders.php code and logging in to the admin area to try and install the plugin, but it's not there and there are no errors from today to help me along.
I am using vscode with copilot to write the updated file and debugging has given the following error: > PHP Warning: require_once(includes/configure.php): Failed to open stream: No such file or directory in xxxxxx/purchaseorder_plugin_v2.1/includes/modules/payment/purchaseorders.php on line 10

PHP Fatal error: Uncaught Error: Failed opening required 'includes/configure.php' (include_path='.:') in xxxxxx/purchaseorder_plugin_v2.1/includes/modules/payment/purchaseorders.php:10
Stack trace:
#0 {main}
thrown in xxxxxx/purchaseorder_plugin_v2.1/includes/modules/payment/purchaseorders.php on line 10
I added the following two lines to the code:

require_once('includes/configure.php');

require_once(DIR_WS_CLASSES . 'class.base.php');
``` but the configure.php file doesn't have 'DIR_WS_CLASSES' defined in it, so I feel like that is the wrong direction?
31 Jan 2025, 10:10 PM
#7
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

Re: Purchase Order Plugin for v 2.1

JG64:

...
PHP Warning: require_once(includes/configure.php): Failed to open stream: No such file or directory in xxxxxx/purchaseorder_plugin_v2.1/includes/modules/payment/purchaseorders.php on line 10
....
I added the following two lines to the code:

require_once('includes/configure.php');

require_once(DIR_WS_CLASSES . 'class.base.php');


someone correct me if i'm wrong, but a payment module is NOT a plugin  so unless your document root is:

xxxxxx/purchaseorder_plugin_v2.1

i would say yes you are on the wrong track.

one might need to add:

```php
require 'includes/application_top.php';

but definitely not for a payment module.

so if you are manually adding a configure.php to your code, as well as the class.base.php, i would again say you are on the wrong track.

have you tried the corrected file i sent you?

that worked with 0 errors for me.

best.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

1 Feb 2025, 11:20 AM
#8
jg64 avatar

jg64

New Zenner

Join Date:
Jul 2015
Location:
Allentown, PA
Posts:
41
Plugin Contributions:
0

Re: Purchase Order Plugin for v 2.1

Carl,
I didn't notice that you had attached a corrected file. I tried it and it installed! Thank you!
As it says, I'm new here.
The original purchase order module (purchase_order_basic_v1_1b) is available through the Plugins>Payments page. I named the one with my edits purchaseorder_plugin_v2.1 just to differentiate it.
Best,
Josh

1 Feb 2025, 2:29 PM
#9
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

Re: Purchase Order Plugin for v 2.1

:thumbsup:

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

1 Feb 2025, 3:44 PM
#10
brian70809 avatar

brian70809

New Zenner

Join Date:
Jun 2011
Posts:
85
Plugin Contributions:
0

Re: Purchase Order Plugin for v 2.1

Is this available for Download? I need to do the same thing!

1 Feb 2025, 10:36 PM
#11
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

Re: Purchase Order Plugin for v 2.1

brian70809:

Is this available for Download? I need to do the same thing!

it will be available here, once approved by the zc team.

best.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.