Re: Optional Shipping Insurance Module Support Thread...
Quote:
Originally Posted by
dennisns7d
To eliminate the warning when using PHP 7+, change
Code:
function ot_insurance() {
to
Code:
function __construct() {
OK, but for Zen-cart version 1.5.8, when you replace the function name with __construct() the following errors are given when the Order Total Modules page is visited in the Admin. Evidently it is trying to get an order delivery country which does not exist
--> PHP Warning: Attempt to read property "delivery" on null in C:\xampp\htdocs\includes\modules\order_total\ot_insurance.php on line 37.
--> PHP Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\includes\modules\order_total\ot_insurance.php on line 37.
Line 37 is like this
PHP Code:
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . constant('MODULE_ORDER_TOTAL_INSURANCE_ZONE_' . $i) . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
Any ideas how to overcome this? Should there be an Admin page check?
Re: Optional Shipping Insurance Module Support Thread...
> Should there be an Admin page check?
Yep.
Re: Optional Shipping Insurance Module Support Thread...
Quote:
Originally Posted by
swguy
> Should there be an Admin page check?
Yep.
Thank you for the quick response. I was just not sure where to put the control. I am wondering if this is the right place to block out while in the admin section (added if control around ---> // Check if called in admin page):
PHP Code:
function __construct() {
global $order, $currencies, $db;
$this->code = 'ot_insurance';
$this->title = MODULE_ORDER_TOTAL_INSURANCE_TITLE;
$this->description = MODULE_ORDER_TOTAL_INSURANCE_DESCRIPTION;
$this->enabled = ((MODULE_ORDER_TOTAL_INSURANCE_STATUS == 'true') ? true : false);
$this->sort_order = MODULE_ORDER_TOTAL_INSURANCE_SORT_ORDER;
$this->credit_class = true;
$this->output = array();
$geozones = $db->Execute("SELECT * FROM " . TABLE_GEO_ZONES);
$this->num_zones = $geozones->RecordCount();
if (!defined('IS_ADMIN_FLAG') || (IS_ADMIN_FLAG === false)) { // Check if called in admin page
if ($this->enabled == true) {
$this->dest_zone = 0;
for ($i = 1; $i <= $this->num_zones; $i++) {
if ((int) constant('MODULE_ORDER_TOTAL_INSURANCE_ZONE_' . $i) > 0) {
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . constant('MODULE_ORDER_TOTAL_INSURANCE_ZONE_' . $i) . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$this->dest_zone = $i;
break;
}
elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
$this->dest_zone = $i;
break;
}
$check->MoveNext();
} // end while
} // END if ((int)constant('MODULE_ORDER_TOTAL_INSURANCE_ZONE_' . $i) > 0)
} // END for ($i=1; $i<=$this->num_zones; $i++)
if ($this->dest_zone < 1 && MODULE_ORDER_TOTAL_INSURANCE_ZONE_1 > 0) {
$this->enabled = false;
}
}
} // Check if called in admin page
}
Re: Optional Shipping Insurance Module Support Thread...
Quote:
Originally Posted by
swguy
> Should there be an Admin page check?
Yep.
Thank you for the quick reply. I was just not sure about where to put the control. Is it OK to block the following segment as it is done with the if block (marked with----> // Check if called in admin page)
PHP Code:
function __construct() {
global $order, $currencies, $db;
$this->code = 'ot_insurance';
$this->title = MODULE_ORDER_TOTAL_INSURANCE_TITLE;
$this->description = MODULE_ORDER_TOTAL_INSURANCE_DESCRIPTION;
$this->enabled = ((MODULE_ORDER_TOTAL_INSURANCE_STATUS == 'true') ? true : false);
$this->sort_order = MODULE_ORDER_TOTAL_INSURANCE_SORT_ORDER;
$this->credit_class = true;
$this->output = array();
$geozones = $db->Execute("SELECT * FROM " . TABLE_GEO_ZONES);
$this->num_zones = $geozones->RecordCount();
if (!defined('IS_ADMIN_FLAG') || (IS_ADMIN_FLAG === false)) { // Check if called in admin page
if ($this->enabled == true) {
$this->dest_zone = 0;
for ($i = 1; $i <= $this->num_zones; $i++) {
if ((int) constant('MODULE_ORDER_TOTAL_INSURANCE_ZONE_' . $i) > 0) {
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . constant('MODULE_ORDER_TOTAL_INSURANCE_ZONE_' . $i) . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$this->dest_zone = $i;
break;
}
elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
$this->dest_zone = $i;
break;
}
$check->MoveNext();
} // end while
} // END if ((int)constant('MODULE_ORDER_TOTAL_INSURANCE_ZONE_' . $i) > 0)
} // END for ($i=1; $i<=$this->num_zones; $i++)
if ($this->dest_zone < 1 && MODULE_ORDER_TOTAL_INSURANCE_ZONE_1 > 0) {
$this->enabled = false;
}
}
} // Check if called in admin page
}
Re: Optional Shipping Insurance Module Support Thread...
In ot_insurance.php (version 3.2.4) around line 245:
PHP Code:
$selected = ((isset($_SESSION['opt_insurance']) && $_SESSION['opt_insurance'] == '1') ? true : false);
$display_insurance = true;
if (($order_total_insurance >= MODULE_ORDER_TOTAL_INSURANCE_REQUIRED) || (($order_total_insurance <= MODULE_ORDER_TOTAL_INSURANCE_OVER) && (MODULE_ORDER_TOTAL_INSURANCE_OVER > 0) && ($order_total_insurance >= MODULE_ORDER_TOTAL_INSURANCE_REQUIRED))) {
$display_insurance = false;
}
What is the meaning of this if control?
Susbtituting with simple letters here is the simplified logic function:
(Let's say a is the upper limit and set to 10000, b is the lower limit and set to 100)
((ins>= a) || ((ins<=b) && (b>0) && (ins>=a)))
if ins>=a first part of the or function is fulfilled and result is true
if ins<a first part of or function valued false and the second part may never be true.
so mathematically this is equivalent of making only this logic control:
ins>=a
Am I missing something?
Re: Optional Shipping Insurance Module Support Thread...
Yeah it looks wrong to me too.
Re: Optional Shipping Insurance Module Support Thread...
@zamzom, this module hasn't been updated in a long time - perhaps you'd like to adopt it and make improvements?
https://docs.zen-cart.com/dev/plugins/adoption/