mc12345678 / Dynamic_Price_Updater

This module for Zen Cart automatically updates the product price when a atrribute is added to the product
Other
0 stars 0 forks source link

$product_id = 0 not trapped completely #20

Open torvista opened 4 years ago

torvista commented 4 years ago
  if (0 == $pid) {
    $load = false;
  } elseif (zen_get_products_price_is_call($pid) || zen_get_products_price_is_free($pid) || STORE_STATUS > 0) {
    $load = false;
  }
  $pidp = zen_get_products_display_price($pid);
  if (empty($pidp)) {
    $load = false;
  }

It does not abort when the pid is zero (such as page not found) and so causes various php notices from zen_get_products_display_price using 0. I did this:

    if ($pid === 0) {
        $load = false;
    } else {
        if (STORE_STATUS > 0 || zen_get_products_price_is_call($pid) || zen_get_products_price_is_free($pid)) {
            $load = false;
        }
        $pidp = zen_get_products_display_price($pid);
        if (empty($pidp)) {
            $load = false;
        }
    }
mc12345678 commented 4 years ago

While the above code:

  if (0 == $pid) {
    $load = false;
  } elseif (zen_get_products_price_is_call($pid) || zen_get_products_price_is_free($pid) || STORE_STATUS > 0) {
    $load = false;
  }
  $pidp = zen_get_products_display_price($pid);
  if (empty($pidp)) {
    $load = false;
  }

Is from version 3.2.0 and there is an updated logic for 3.2.1, one thing that was identified in creating that revision was that just because the current display price is 0 (value of $pidp), the product may have options that cause the price to be changed or become non-zero, therefore DPU should not be disabled just because the "base" or original price is 0 as provided/suggested above and/or in the above proposed correction. There may still be an aspect of that evaluation missing to where DPU remains active in a condition where attribute selection has not affect on price; however, one known/accepted condition is if the quantity of product can be adjusted such that the "price" of adding the product to the cart is shown for quantities including where/when there are variations of price based on the quantity of the product being added.

The current proposed code for 3.2.1 in this area is:

  if (0 == $pid) {
    $load = false;
  } elseif (zen_get_products_price_is_call($pid) || (zen_get_products_price_is_free($pid) && empty($optionIds)) || STORE_STATUS > 0) {
    $load = false;
  } else {
    if (!class_exists('DPU')) {
      if (is_file(DIR_FS_CATALOG . DIR_WS_CLASSES . 'dynamic_price_updater.php')) {
        require DIR_FS_CATALOG . DIR_WS_CLASSES . 'dynamic_price_updater.php';
      } else {
        $load = false;
      }
    }

    if (class_exists('DPU')) {
      $dpu = new DPU();
    }

    $optionIds = array();

    // Check to see if there are any price affecting conditions associated with the overall operation.
    // As part of the check assign the option name ids to $optionIds that affect price to be used later.

    // These values are not loaded in the process until after html_header.php which was what loaded this file.
    $products_qty_box_status = zen_products_lookup($pid, 'products_qty_box_status');
    $products_quantity_order_max = zen_products_lookup($pid, 'products_quantity_order_max');

    if ($load && !($optionIds = $dpu->getOptionPricedIds($pid)) && ($products_qty_box_status == 0 || $products_quantity_order_max == 1)) {
    // Checks for attributes that affect price including if text boxes.  If there are none that affect price and the quantity
    //   box is not shown, then go ahead and disable DPU as there is nothing available to adjust/modify price.
      $load = false;
    }
  }
  if (!empty($pid)) {
    $pidp = zen_get_products_display_price($pid);
  }
  if (empty($pidp) && empty($optionIds)) {
    $load = false;
  }

There may also be an efficiency gained by changing the sequence of testing against STORE_STATUS by placing that first in the list.

This was addressed/corrected in: https://github.com/mc12345678/Dynamic_Price_Updater/commit/877e66b3c616309d0205475247cff9e72cdeeeb2