If this is your first visit, check our documentation. To post, register or login.
Forums / Code Matters / 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

Started by lat9 on 5 Apr 2013, 7:35 PM · Views: 1,250

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,152
Plugin Contributions:
56

Post #1 by lat9

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,512
Plugin Contributions:
176

Post #2 by drbyte

Fix committed to v1.6.0

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.