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
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 Code:
<?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.
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.
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?
Re: Purchase Order Plugin for v 2.1
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:
Quote:
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:
PHP 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?
Re: Purchase Order Plugin for v 2.1
Quote:
Originally Posted by
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:
PHP 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?
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 Code:
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.
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
Re: Purchase Order Plugin for v 2.1
Re: Purchase Order Plugin for v 2.1
Is this available for Download? I need to do the same thing!