Zen Cart Logo
Forums / Bug Reports / *[Done v1.6.0] Incorrect comparison in ot_cod_fee.php

*[Done v1.6.0] Incorrect comparison in ot_cod_fee.php

Locked

Views: 1,244

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
5 Apr 2013, 7:35 PM
#1
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

*[Done v1.6.0] Incorrect comparison in ot_cod_fee.php

The file /includes/modules/order_totals/ot_cod_fee.php begins with

 class ot_cod_fee {
    var $title, $output;

    function ot_cod_fee() {
      $this->code = 'ot_cod_fee';
      $this->title = MODULE_ORDER_TOTAL_COD_TITLE;
      $this->description = MODULE_ORDER_TOTAL_COD_DESCRIPTION;
      $this->enabled = ((MODULE_ORDER_TOTAL_COD_STATUS == 'true') ? true : false);
      $this->sort_order = MODULE_ORDER_TOTAL_COD_SORT_ORDER;

      $this->output = array();
    }

    function process() {
      global $order, $currencies, $cod_cost, $cod_country, $shipping;

      if ($this->enabled == 'true') {
        //Will become true, if cod can be processed.
        $cod_country = false;

While this code magically operates, it is semantically incorrect. The function ot_cod_fee sets the enabled flag to either binary true or false, based on the text-based value in the database. The function process then proceeds to test whether it should process based on the text-based value. This only works because (binary)true == EVERYTHING and (binary)false == NOTHING.

Just to reduce confusion in the future, I suggest that the code be changed to

 class ot_cod_fee {
    var $title, $output;

    function ot_cod_fee() {
      $this->code = 'ot_cod_fee';
      $this->title = MODULE_ORDER_TOTAL_COD_TITLE;
      $this->description = MODULE_ORDER_TOTAL_COD_DESCRIPTION;
      $this->enabled = ((MODULE_ORDER_TOTAL_COD_STATUS == 'true') ? true : false);
      $this->sort_order = MODULE_ORDER_TOTAL_COD_SORT_ORDER;

      $this->output = array();
    }

    function process() {
      global $order, $currencies, $cod_cost, $cod_country, $shipping;

      if ($this->enabled) {
        //Will become true, if cod can be processed.
        $cod_country = false;
5 Apr 2013, 11:16 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: *[Done v1.6.0] Incorrect comparison in ot_cod_fee.php

Fix committed to v1.6.0