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/
Re: Optional Shipping Insurance Module Support Thread...
Did anyone ever get this working for 1.5.8a on PHP 8+? If so can you share your modified plugin files?
Re: Optional Shipping Insurance Module Support Thread...
So I installed a fresh copy of zen cart 1.5.8a and have been trying to get this to work and I can't seem to figure it out. I renamed the function 'function ot_insurance()' to 'public function __construct()' and no matter what I do it never shows up in the order totals modules section in the admin. How is zen cart populating that list? The ot_insurance.php file is present in includes/modules/order_total/ot_shipping.php and the language file is in includes/languages/english/modules/order_total/ot_insurance.php. I've cleared the site's php cache and still I just see the 4 default order total modules. How are people getting by without shipping insurance functionality with this version?
Re: Optional Shipping Insurance Module Support Thread...
After some manual SQLing I was able to get it to appear. I don't think 1.5.8a knows to run the install function first, or maybe it's because it is below allow of the other stuff but zen cart is trying to read every variable which doesn't exist until you manually add all the configuration values into the database. I'm one step closer to getting this to work.