Zen Cart Logo
Forums / Bug Reports / Unknown constant (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL) in functions_prices.php

Unknown constant (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL) in functions_prices.php

Views: 1,713

Results 1 to 4 of 4
17 Dec 2013, 5:38 PM
#1
lat9 avatar

lat9

Administrator

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

Unknown constant (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL) in functions_prices.php

The function zen_get_attributes_price_factor in /includes/functions/functions_prices.php uses an unknown constant (highlighted):

////
// return attributes_price_factor
  function zen_get_attributes_price_factor($price, $special, $factor, $offset) {
    if (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL =='1' and $special) {
      // calculate from specials_new_products_price
      $calculated_price = $special * ($factor - $offset);
    } else {
      // calculate from products_price
      $calculated_price = $price * ($factor - $offset);
    }
//    return '$price ' . $price . ' $special ' . $special . ' $factor ' . $factor . ' $offset ' . $offset;
    return $calculated_price;
  }

I've used the Developers Tool Kit to no avail; it's not defined in the database, either.

17 Dec 2013, 7:07 PM
#2
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Unknown constant (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL) in functions_prices.php

Yup, I cannot find it in the code (or database) for 1.5.1 either. It is however set in the 1.5.2 release candidate ("/includes/classes/shopping_cart.php"). Looks to be an "override" of sorts... Maybe it would be better to just to see if the constant is defined rather then checking the value? Or refactoring the function and related code? Maybe another will have some additional insight for us :)

2 Feb 2014, 1:55 PM
#3
lat9 avatar

lat9

Administrator

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

Re: Unknown constant (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL) in functions_prices.php

There's an undefined constant (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL), used in /includes/functions/functions_prices.php (ca. line 1024); it exists neither in language files nor in the database:

  function zen_get_attributes_price_factor($price, $special, $factor, $offset) {
    if (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL =='1' and $special) {
      // calculate from specials_new_products_price
      $calculated_price = $special * ($factor - $offset);
    } else {
      // calculate from products_price
      $calculated_price = $price * ($factor - $offset);
    }
//    return '$price ' . $price . ' $special ' . $special . ' $factor ' . $factor . ' $offset ' . $offset;
    return $calculated_price;
  }

In the same file, there's also an uninitialized value in zen_get_attributes_price_final_onetime (line 1122); suggest changing

////
// attributes final price onetime
  function zen_get_attributes_price_final_onetime($attribute, $qty= 1, $pre_selected_onetime) {
    global $db;
    global $cart;

    if ($pre_selected_onetime == '' or $attribute != $pre_selected_onetime->fields["products_attributes_id"]) {
      $pre_selected_onetime = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . (int)$attribute . "'");
    } else {
      // use existing select
    }

// one time charges
    // onetime charge
      $attributes_price_final_onetime += $pre_selected_onetime->fields["attributes_price_onetime"];

    // price factor
    $display_normal_price = zen_get_products_actual_price($pre_selected_onetime->fields["products_id"]);
    $display_special_price = zen_get_products_special_price($pre_selected_onetime->fields["products_id"]);

to

////
// attributes final price onetime
  function zen_get_attributes_price_final_onetime($attribute, $qty= 1, $pre_selected_onetime) {
    global $db;
    global $cart;

    if ($pre_selected_onetime == '' or $attribute != $pre_selected_onetime->fields["products_attributes_id"]) {
      $pre_selected_onetime = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . (int)$attribute . "'");
    } else {
      // use existing select
    }

// one time charges
    // onetime charge
      $attributes_price_final_onetime = $pre_selected_onetime->fields["attributes_price_onetime"];

    // price factor
    $display_normal_price = zen_get_products_actual_price($pre_selected_onetime->fields["products_id"]);
    $display_special_price = zen_get_products_special_price($pre_selected_onetime->fields["products_id"]);
10 Sep 2017, 9:23 PM
#4
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,873
Plugin Contributions:
7

Re: Unknown constant (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL) in functions_prices.php

ZC155e
While doing a "Report All Errors" for some heads-up on potential future errors, I get this error flagged on a product page, nothing in cart, not logged in, php 7.1.8.

PHP Notice: Use of undefined constant ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL - assumed 'ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL' in .....\includes\functions\functions_prices.php on line 1024
So I find this thread.

ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL is defined on the fly in classes/shopping_cart, but evidently this is not soon enough in the process.