[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/admin/includes/functions/ -> functions_prices.php (source)

   1  <?php
   2  //

   3  // +----------------------------------------------------------------------+

   4  // |zen-cart Open Source E-commerce                                       |

   5  // +----------------------------------------------------------------------+

   6  // | Copyright (c) 2003 The zen-cart developers                           |

   7  // |                                                                      |

   8  // | http://www.zen-cart.com/index.php                                    |

   9  // |                                                                      |

  10  // | Portions Copyright (c) 2003 osCommerce                               |

  11  // +----------------------------------------------------------------------+

  12  // | This source file is subject to version 2.0 of the GPL license,       |

  13  // | that is bundled with this package in the file LICENSE, and is        |

  14  // | available through the world-wide-web at the following url:           |

  15  // | http://www.zen-cart.com/license/2_0.txt.                             |

  16  // | If you did not receive a copy of the zen-cart license and are unable |

  17  // | to obtain it through the world-wide-web, please send a note to       |

  18  // | license@zen-cart.com so we can mail you a copy immediately.          |

  19  // +----------------------------------------------------------------------+

  20  // $Id: functions_prices.php 1969 2005-09-13 06:57:21Z drbyte $

  21  //

  22  //

  23  ////

  24  //get specials price or sale price

  25    function zen_get_products_special_price($product_id, $specials_price_only=false) {
  26      global $db;
  27      $product = $db->Execute("select products_price, products_model, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
  28  
  29      if ($product->RecordCount() > 0) {
  30  //        $product_price = $product->fields['products_price'];

  31          $product_price = zen_get_products_base_price($product_id);
  32      } else {
  33          return false;
  34      }
  35  
  36      $specials = $db->Execute("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status='1'");
  37      if ($specials->RecordCount() > 0) {
  38  //      if ($product->fields['products_priced_by_attribute'] == 1) {

  39            $special_price = $specials->fields['specials_new_products_price'];
  40      } else {
  41          $special_price = false;
  42      }
  43  
  44      if(substr($product->fields['products_model'], 0, 4) == 'GIFT') {    //Never apply a salededuction to Ian Wilson's Giftvouchers
  45        if (zen_not_null($special_price)) {
  46          return $special_price;
  47        } else {
  48          return false;
  49        }
  50      }
  51  
  52  // return special price only

  53      if ($specials_price_only==true) {
  54        if (zen_not_null($special_price)) {
  55          return $special_price;
  56        } else {
  57          return false;
  58        }
  59      } else {
  60  // get sale price

  61  
  62  // changed to use master_categories_id

  63  //      $product_to_categories = $db->Execute("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'");

  64  //      $category = $product_to_categories->fields['categories_id'];

  65  
  66        $product_to_categories = $db->Execute("select master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
  67        $category = $product_to_categories->fields['master_categories_id'];
  68  
  69        $sale = $db->Execute("select sale_specials_condition, sale_deduction_value, sale_deduction_type from " . TABLE_SALEMAKER_SALES . " where sale_categories_all like '%," . $category . ",%' and sale_status = '1' and (sale_date_start <= now() or sale_date_start = '0001-01-01') and (sale_date_end >= now() or sale_date_end = '0001-01-01') and (sale_pricerange_from <= '" . $product_price . "' or sale_pricerange_from = '0') and (sale_pricerange_to >= '" . $product_price . "' or sale_pricerange_to = '0')");
  70        if ($sale->RecordCount() < 1) {
  71           return $special_price;
  72        }
  73  
  74        if (!$special_price) {
  75          $tmp_special_price = $product_price;
  76        } else {
  77          $tmp_special_price = $special_price;
  78        }
  79        switch ($sale->fields['sale_deduction_type']) {
  80          case 0:
  81            $sale_product_price = $product_price - $sale->fields['sale_deduction_value'];
  82            $sale_special_price = $tmp_special_price - $sale->fields['sale_deduction_value'];
  83            break;
  84          case 1:
  85            $sale_product_price = $product_price - (($product_price * $sale->fields['sale_deduction_value']) / 100);
  86            $sale_special_price = $tmp_special_price - (($tmp_special_price * $sale->fields['sale_deduction_value']) / 100);
  87            break;
  88          case 2:
  89            $sale_product_price = $sale->fields['sale_deduction_value'];
  90            $sale_special_price = $sale->fields['sale_deduction_value'];
  91            break;
  92          default:
  93            return $special_price;
  94        }
  95  
  96        if ($sale_product_price < 0) {
  97          $sale_product_price = 0;
  98        }
  99  
 100        if ($sale_special_price < 0) {
 101          $sale_special_price = 0;
 102        }
 103  
 104        if (!$special_price) {
 105          return number_format($sale_product_price, 4, '.', '');
 106          } else {
 107          switch($sale->fields['sale_specials_condition']){
 108            case 0:
 109              return number_format($sale_product_price, 4, '.', '');
 110              break;
 111            case 1:
 112              return number_format($special_price, 4, '.', '');
 113              break;
 114            case 2:
 115              return number_format($sale_special_price, 4, '.', '');
 116              break;
 117            default:
 118              return number_format($special_price, 4, '.', '');
 119          }
 120        }
 121      }
 122    }
 123  
 124  
 125  ////

 126  // computes products_price + option groups lowest attributes price of each group when on

 127    function zen_get_products_base_price($products_id) {
 128      global $db;
 129        $product_check = $db->Execute("select products_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
 130  
 131  // is there a products_price to add to attributes

 132        $products_price = $product_check->fields['products_price'];
 133  
 134        // do not select display only attributes and attributes_price_base_included is true

 135        $product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, attributes_display_only, attributes_price_base_included from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id, price_prefix, options_values_price");
 136  
 137        $the_options_id= 'x';
 138        $the_base_price= 0;
 139  // add attributes price to price

 140        if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) {
 141          while (!$product_att_query->EOF) {
 142            if ( $the_options_id != $product_att_query->fields['options_id']) {
 143              $the_options_id = $product_att_query->fields['options_id'];
 144              $the_base_price += $product_att_query->fields['options_values_price'];
 145            }
 146            $product_att_query->MoveNext();
 147          }
 148  
 149          $the_base_price = $products_price + $the_base_price;
 150        } else {
 151          $the_base_price = $products_price;
 152        }
 153        return $the_base_price;
 154    }
 155  
 156  
 157  ////

 158  // Display Price Retail

 159  // Specials and Tax Included

 160    function zen_get_products_display_price($products_id) {
 161      global $db, $currencies;
 162  
 163  // 0 = normal shopping

 164  // 1 = Login to shop

 165  // 2 = Can browse but no prices

 166      // verify display of prices

 167        switch (true) {
 168          case (CUSTOMERS_APPROVAL == '1' and $_SESSION['customer_id'] == ''):
 169          // customer must be logged in to browse

 170          return '';
 171          break;
 172          case (CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == ''):
 173          // customer may browse but no prices

 174          return '';
 175          break;
 176          default:
 177          // proceed normally

 178          break;
 179        }
 180  
 181  // show case only

 182      if (STORE_STATUS != '0') {
 183        if (STORE_STATUS == '1') {
 184          return '';
 185        }
 186      }
 187  
 188      // $new_fields = ', product_is_free, product_is_call, product_is_showroom_only';

 189      $product_check = $db->Execute("select products_tax_class_id, products_price, products_priced_by_attribute, product_is_free, product_is_call from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'" . " limit 1");
 190  
 191      $show_display_price = '';
 192      $display_normal_price = zen_get_products_base_price($products_id);
 193      $display_special_price = zen_get_products_special_price($products_id, true);
 194      $display_sale_price = zen_get_products_special_price($products_id, false);
 195  
 196      $show_sale_discount = '';
 197      if (SHOW_SALE_DISCOUNT_STATUS == '1' and ($display_special_price != 0 or $display_sale_price != 0)) {
 198        if ($display_sale_price) {
 199          if (SHOW_SALE_DISCOUNT == 1) {
 200            if ($display_normal_price != 0) {
 201              $show_discount_amount = number_format(100 - (($display_sale_price / $display_normal_price) * 100),SHOW_SALE_DISCOUNT_DECIMALS);
 202            } else {
 203              $show_discount_amount = '';
 204            }
 205            $show_sale_discount = '<span class="productPriceDiscount">' . '<br />' . PRODUCT_PRICE_DISCOUNT_PREFIX . $show_discount_amount . PRODUCT_PRICE_DISCOUNT_PERCENTAGE . '</span>';
 206  
 207          } else {
 208            $show_sale_discount = '<span class="productPriceDiscount">' . '<br />' . PRODUCT_PRICE_DISCOUNT_PREFIX . $currencies->display_price(($display_normal_price - $display_sale_price), zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . PRODUCT_PRICE_DISCOUNT_AMOUNT . '</span>';
 209          }
 210        } else {
 211          if (SHOW_SALE_DISCOUNT == 1) {
 212            $show_sale_discount = '<span class="productPriceDiscount">' . '<br />' . PRODUCT_PRICE_DISCOUNT_PREFIX . number_format(100 - (($display_special_price / $display_normal_price) * 100),SHOW_SALE_DISCOUNT_DECIMALS) . PRODUCT_PRICE_DISCOUNT_PERCENTAGE . '</span>';
 213          } else {
 214            $show_sale_discount = '<span class="productPriceDiscount">' . '<br />' . PRODUCT_PRICE_DISCOUNT_PREFIX . $currencies->display_price(($display_normal_price - $display_special_price), zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . PRODUCT_PRICE_DISCOUNT_AMOUNT . '</span>';
 215          }
 216        }
 217      }
 218  
 219      if ($display_special_price) {
 220        $show_normal_price = '<span class="normalprice">' . $currencies->display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . ' </span>';
 221        if ($display_sale_price && $display_sale_price != $display_special_price) {
 222          $show_special_price = '&nbsp;' . '<span class="productSpecialPriceSale">' . $currencies->display_price($display_special_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . '</span>';
 223          if ($product_check->fields['product_is_free'] == '1') {
 224            $show_sale_price = '<br />' . '<span class="productSalePrice">' . PRODUCT_PRICE_SALE . '<s>' . $currencies->display_price($display_sale_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . '</s>' . '</span>';
 225          } else {
 226            $show_sale_price = '<br />' . '<span class="productSalePrice">' . PRODUCT_PRICE_SALE . $currencies->display_price($display_sale_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . '</span>';
 227          }
 228        } else {
 229          if ($product_check->fields['product_is_free'] == '1') {
 230            $show_special_price = '&nbsp;' . '<span class="productSpecialPrice">' . '<s>' . $currencies->display_price($display_special_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . '</s>' . '</span>';
 231          } else {
 232            $show_special_price = '&nbsp;' . '<span class="productSpecialPrice">' . $currencies->display_price($display_special_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . '</span>';
 233          }
 234          $show_sale_price = '';
 235        }
 236      } else {
 237        if ($display_sale_price) {
 238          $show_normal_price = '<span class="normalprice">' . $currencies->display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . ' </span>';
 239          $show_special_price = '';
 240          $show_sale_price = '<br />' . '<span class="productSalePrice">' . PRODUCT_PRICE_SALE . $currencies->display_price($display_sale_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . '</span>';
 241        } else {
 242          if ($product_check->fields['product_is_free'] == '1') {
 243            $show_normal_price = '<s>' . $currencies->display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . '</s>';
 244          } else {
 245            $show_normal_price = $currencies->display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id']));
 246          }
 247          $show_special_price = '';
 248          $show_sale_price = '';
 249        }
 250      }
 251  
 252      if ($display_normal_price == 0) {
 253        // don't show the $0.00

 254        $final_display_price = $show_special_price . $show_sale_price . $show_sale_discount;
 255      } else {
 256        $final_display_price = $show_normal_price . $show_special_price . $show_sale_price . $show_sale_discount;
 257      }
 258  
 259      // If Free, Show it

 260      if ($product_check->fields['product_is_free'] == '1') {
 261        if (OTHER_IMAGE_PRICE_IS_FREE_ON=='0') {
 262          $free_tag = '<br />' . PRODUCTS_PRICE_IS_FREE_TEXT;
 263        } else {
 264          $free_tag = '<br />' . zen_image(DIR_WS_TEMPLATE_IMAGES . OTHER_IMAGE_PRICE_IS_FREE, PRODUCTS_PRICE_IS_FREE_TEXT);
 265        }
 266      }
 267  
 268      // If Call for Price, Show it

 269      if ($product_check->fields['product_is_call']) {
 270        if (PRODUCTS_PRICE_IS_CALL_IMAGE_ON=='0') {
 271          $call_tag = '<br />' . PRODUCTS_PRICE_IS_CALL_FOR_PRICE_TEXT;
 272        } else {
 273          $call_tag = '<br />' . zen_image(DIR_WS_TEMPLATE_IMAGES . OTHER_IMAGE_CALL_FOR_PRICE, PRODUCTS_PRICE_IS_CALL_FOR_PRICE_TEXT);
 274        }
 275      }
 276  
 277      return $final_display_price . $free_tag . $call_tag;
 278    }
 279  
 280  ////

 281  // Is the product free?

 282    function zen_get_products_price_is_free($products_id) {
 283      global $db;
 284      $product_check = $db->Execute("select product_is_free from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'" . " limit 1");
 285      if ($product_check->fields['product_is_free'] == '1') {
 286        $the_free_price = true;
 287      } else {
 288        $the_free_price = false;
 289      }
 290      return $the_free_price;
 291    }
 292  
 293  ////

 294  // Is the product call for price?

 295    function zen_get_products_price_is_call($products_id) {
 296      global $db;
 297      $product_check = $db->Execute("select product_is_call from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'" . " limit 1");
 298      if ($product_check->fields['product_is_call'] == '1') {
 299        $the_call_price = true;
 300      } else {
 301        $the_call_price = false;
 302      }
 303      return $the_call_price;
 304    }
 305  
 306  ////

 307  // Is the product priced by attributes?

 308    function zen_get_products_price_is_priced_by_attributes($products_id) {
 309      global $db;
 310      $product_check = $db->Execute("select products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'" . " limit 1");
 311      if ($product_check->fields['products_priced_by_attribute'] == '1') {
 312        $the_products_priced_by_attribute = true;
 313      } else {
 314        $the_products_priced_by_attribute = false;
 315      }
 316      return $the_products_priced_by_attribute;
 317    }
 318  
 319  ////

 320  // Return a product's minimum quantity

 321  // TABLES: products

 322    function zen_get_products_quantity_order_min($product_id) {
 323      global $db;
 324  
 325      $the_products_quantity_order_min = $db->Execute("select products_id, products_quantity_order_min from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
 326      return $the_products_quantity_order_min->fields['products_quantity_order_min'];
 327    }
 328  
 329  
 330  ////

 331  // Return a product's minimum unit order

 332  // TABLES: products

 333    function zen_get_products_quantity_order_units($product_id) {
 334      global $db;
 335  
 336      $the_products_quantity_order_units = $db->Execute("select products_id, products_quantity_order_units from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
 337      return $the_products_quantity_order_units->fields['products_quantity_order_units'];
 338    }
 339  
 340  ////

 341  // Return a product's maximum quantity

 342  // TABLES: products

 343    function zen_get_products_quantity_order_max($product_id) {
 344      global $db;
 345  
 346      $the_products_quantity_order_max = $db->Execute("select products_id, products_quantity_order_max from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
 347      return $the_products_quantity_order_max->fields['products_quantity_order_max'];
 348    }
 349  
 350  ////

 351  // Find quantity discount quantity mixed and not mixed

 352    function zen_get_products_quantity_discount_mixed($product_id, $qty) {
 353      global $db;
 354      global $cart;
 355  
 356      $product_discounts = $db->Execute("select products_price, products_quantity_mixed, product_is_free from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
 357  
 358      if ($product_discounts->fields['products_quantity_mixed']) {
 359        if ($new_qty = $_SESSION['cart']->count_contents_qty($product_id)) {
 360          $qty = $new_qty;
 361        }
 362      }
 363      return $qty;
 364    }
 365  
 366  
 367  ////

 368  // Return a product's quantity box status

 369  // TABLES: products

 370    function zen_get_products_qty_box_status($product_id) {
 371      global $db;
 372  
 373      $the_products_qty_box_status = $db->Execute("select products_id, products_qty_box_status  from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
 374      return $the_products_qty_box_status->fields['products_qty_box_status'];
 375    }
 376  
 377  ////

 378  // Return a product mixed setting

 379  // TABLES: products

 380    function zen_get_products_quantity_mixed($product_id) {
 381      global $db;
 382  
 383      $the_products_quantity_mixed = $db->Execute("select products_id, products_quantity_mixed from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
 384      if ($the_products_quantity_mixed->fields['products_quantity_mixed'] == '1') {
 385        $look_up = true;
 386      } else {
 387        $look_up = false;
 388      }
 389      return $look_up;
 390    }
 391  
 392  
 393  ////

 394  // Return a products quantity minimum and units display

 395    function zen_get_products_quantity_min_units_display($product_id, $include_break = true, $shopping_cart_msg = false) {
 396      $check_min = zen_get_products_quantity_order_min($product_id);
 397      $check_units = zen_get_products_quantity_order_units($product_id);
 398  
 399      $the_min_units='';
 400  
 401      if ($check_min > 1 or $check_units > 1) {
 402        if ($check_min > 1) {
 403          $the_min_units .= PRODUCTS_QUANTITY_MIN_TEXT_LISTING . '&nbsp;' . $check_min;
 404        }
 405        if ($check_units > 1) {
 406          $the_min_units .= ($the_min_units ? ' ' : '' ) . PRODUCTS_QUANTITY_UNIT_TEXT_LISTING . '&nbsp;' . $check_units;
 407        }
 408  
 409        if (($check_min > 0 or $check_units > 0) and !zen_get_products_quantity_mixed($product_id)) {
 410          if ($include_break == true) {
 411            $the_min_units .= '<br />' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_OFF : TEXT_PRODUCTS_MIX_OFF_SHOPPING_CART);
 412          } else {
 413            $the_min_units .= '&nbsp;&nbsp;' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_OFF : TEXT_PRODUCTS_MIX_OFF_SHOPPING_CART);
 414          }
 415        } else {
 416          if ($include_break == true) {
 417            $the_min_units .= '<br />' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_ON : TEXT_PRODUCTS_MIX_ON_SHOPPING_CART);
 418          } else {
 419            $the_min_units .= '&nbsp;&nbsp;' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_ON : TEXT_PRODUCTS_MIX_ON_SHOPPING_CART);
 420          }
 421        }
 422      }
 423  
 424      // quantity max

 425      $check_max = zen_get_products_quantity_order_max($product_id);
 426  
 427      if ($check_max != 0) {
 428        if ($include_break == true) {
 429          $the_min_units .= ($the_min_units != '' ? '<br />' : '') . PRODUCTS_QUANTITY_MAX_TEXT_LISTING . '&nbsp;' . $check_max;
 430        } else {
 431          $the_min_units .= ($the_min_units != '' ? '&nbsp;&nbsp;' : '') . PRODUCTS_QUANTITY_MAX_TEXT_LISTING . '&nbsp;' . $check_max;
 432        }
 433      }
 434  
 435      return $the_min_units;
 436    }
 437  
 438  
 439  ////

 440  // Return quantity buy now

 441    function zen_get_buy_now_qty($product_id) {
 442      global $cart;
 443      $check_min = zen_get_products_quantity_order_min($product_id);
 444      $check_units = zen_get_products_quantity_order_units($product_id);
 445      $buy_now_qty=1;
 446  // works on Mixed ON

 447      switch (true) {
 448        case ($_SESSION['cart']->in_cart_mixed($product_id) == 0 ):
 449          if ($check_min >= $check_units) {
 450            $buy_now_qty = $check_min;
 451          } else {
 452            $buy_now_qty = $check_units;
 453          }
 454          break;
 455        case ($_SESSION['cart']->in_cart_mixed($product_id) < $check_min):
 456          $buy_now_qty = $check_min - $_SESSION['cart']->in_cart_mixed($product_id);
 457          break;
 458        case ($_SESSION['cart']->in_cart_mixed($product_id) > $check_min):
 459        // set to units or difference in units to balance cart

 460          $new_units = $check_units - fmod_round($_SESSION['cart']->in_cart_mixed($product_id), $check_units);
 461  //echo 'Cart: ' . $_SESSION['cart']->in_cart_mixed($product_id) . ' Min: ' . $check_min . ' Units: ' . $check_units . ' fmod: ' . fmod($_SESSION['cart']->in_cart_mixed($product_id), $check_units) . '<br />';

 462          $buy_now_qty = ($new_units > 0 ? $new_units : $check_units);
 463          break;
 464        default:
 465          $buy_now_qty = $check_units;
 466          break;
 467      }
 468      if ($buy_now_qty <= 0) {
 469        $buy_now_qty = 1;
 470      }
 471      return $buy_now_qty;
 472    }
 473  
 474  
 475  ////

 476  // compute product discount to be applied to attributes or other values

 477    function zen_get_discount_calc($product_id, $attributes_id = false, $attributes_amount = false, $check_qty= false) {
 478      global $discount_type_id, $sale_maker_discount;
 479      global $cart;
 480  
 481      // no charge

 482      if ($attributes_id > 0 and $attributes_amount == 0) {
 483        return 0;
 484      }
 485  
 486      $new_products_price = zen_get_products_base_price($product_id);
 487      $new_special_price = zen_get_products_special_price($product_id, true);
 488      $new_sale_price = zen_get_products_special_price($product_id, false);
 489  
 490      $discount_type_id = zen_get_products_sale_discount_type($product_id);
 491  
 492      if ($new_products_price != 0) {
 493        $special_price_discount = ($new_special_price != 0 ? ($new_special_price/$new_products_price) : 1);
 494      } else {
 495        $special_price_discount = '';
 496      }
 497      $sale_maker_discount = zen_get_products_sale_discount_type($product_id, '', 'amount');
 498  
 499      // percentage adjustment of discount

 500      if (($discount_type_id == 120 or $discount_type_id == 1209) or ($discount_type_id == 110 or $discount_type_id == 1109)) {
 501        $sale_maker_discount = ($sale_maker_discount != 0 ? (100 - $sale_maker_discount)/100 : 1);
 502      }
 503  
 504     $qty = $check_qty;
 505  
 506  // fix here

 507  // BOF: percentage discounts apply to price

 508      switch (true) {
 509        case (zen_get_discount_qty($product_id, $qty) and !$attributes_id):
 510          // discount quanties exist and this is not an attribute

 511          // $this->contents[$products_id]['qty']

 512          $check_discount_qty_price = zen_get_products_discount_price_qty($product_id, $qty, $attributes_amount);
 513  //echo 'How much 1 ' . $qty . ' : ' . $attributes_amount . ' vs ' . $check_discount_qty_price . '<br />';

 514          return $check_discount_qty_price;
 515          break;
 516  
 517        case (zen_get_discount_qty($product_id, $qty) and zen_get_products_price_is_priced_by_attributes($product_id)):
 518          // discount quanties exist and this is not an attribute

 519          // $this->contents[$products_id]['qty']

 520          $check_discount_qty_price = zen_get_products_discount_price_qty($product_id, $qty, $attributes_amount);
 521  //echo 'How much 2 ' . $qty . ' : ' . $attributes_amount . ' vs ' . $check_discount_qty_price . '<br />';

 522  
 523          return $check_discount_qty_price;
 524          break;
 525  
 526        case ($discount_type_id == 5):
 527          // No Sale and No Special

 528  //        $sale_maker_discount = 1;

 529          if (!$attributes_id) {
 530            $sale_maker_discount = $sale_maker_discount;
 531          } else {
 532            // compute attribute amount

 533            if ($attributes_amount != 0) {
 534              if ($special_price_discount != 0) {
 535                $calc = ($attributes_amount * $special_price_discount);
 536              } else {
 537                $calc = $attributes_amount;
 538              }
 539  
 540              $sale_maker_discount = $calc;
 541            } else {
 542              $sale_maker_discount = $sale_maker_discount;
 543            }
 544          }
 545  //echo 'How much 3 - ' . $qty . ' : ' . $product_id . ' : ' . $qty . ' x ' .  $attributes_amount . ' vs ' . $check_discount_qty_price . ' - ' . $sale_maker_discount . '<br />';

 546          break;
 547        case ($discount_type_id == 59):
 548          // No Sale and Special

 549  //        $sale_maker_discount = $special_price_discount;

 550          if (!$attributes_id) {
 551            $sale_maker_discount = $sale_maker_discount;
 552          } else {
 553            // compute attribute amount

 554            if ($attributes_amount != 0) {
 555              $calc = ($attributes_amount * $special_price_discount);
 556              $sale_maker_discount = $calc;
 557            } else {
 558              $sale_maker_discount = $sale_maker_discount;
 559            }
 560          }
 561          break;
 562  // EOF: percentage discount apply to price

 563  
 564  // BOF: percentage discounts apply to Sale

 565        case ($discount_type_id == 120):
 566          // percentage discount Sale and Special without a special

 567          if (!$attributes_id) {
 568            $sale_maker_discount = $sale_maker_discount;
 569          } else {
 570            // compute attribute amount

 571            if ($attributes_amount != 0) {
 572              $calc = ($attributes_amount * $sale_maker_discount);
 573              $sale_maker_discount = $calc;
 574            } else {
 575              $sale_maker_discount = $sale_maker_discount;
 576            }
 577          }
 578          break;
 579        case ($discount_type_id == 1209):
 580          // percentage discount on Sale and Special with a special

 581          if (!$attributes_id) {
 582            $sale_maker_discount = $sale_maker_discount;
 583          } else {
 584            // compute attribute amount

 585            if ($attributes_amount != 0) {
 586              $calc = ($attributes_amount * $special_price_discount);
 587              $calc2 = $calc - ($calc * $sale_maker_discount);
 588              $sale_maker_discount = $calc - $calc2;
 589            } else {
 590              $sale_maker_discount = $sale_maker_discount;
 591            }
 592          }
 593          break;
 594  // EOF: percentage discounts apply to Sale

 595  
 596  // BOF: percentage discounts skip specials

 597        case ($discount_type_id == 110):
 598          // percentage discount Sale and Special without a special

 599          if (!$attributes_id) {
 600            $sale_maker_discount = $sale_maker_discount;
 601          } else {
 602            // compute attribute amount

 603            if ($attributes_amount != 0) {
 604              $calc = ($attributes_amount * $sale_maker_discount);
 605              $sale_maker_discount = $calc;
 606            } else {
 607  //            $sale_maker_discount = $sale_maker_discount;

 608              if ($attributes_amount != 0) {
 609  //            $calc = ($attributes_amount * $special_price_discount);

 610  //            $calc2 = $calc - ($calc * $sale_maker_discount);

 611  //            $sale_maker_discount = $calc - $calc2;

 612                $calc = $attributes_amount - ($attributes_amount * $sale_maker_discount);
 613                $sale_maker_discount = $calc;
 614              } else {
 615                $sale_maker_discount = $sale_maker_discount;
 616              }
 617            }
 618          }
 619          break;
 620        case ($discount_type_id == 1109):
 621          // percentage discount on Sale and Special with a special

 622          if (!$attributes_id) {
 623            $sale_maker_discount = $sale_maker_discount;
 624          } else {
 625            // compute attribute amount

 626            if ($attributes_amount != 0) {
 627              $calc = ($attributes_amount * $special_price_discount);
 628  //            $calc2 = $calc - ($calc * $sale_maker_discount);

 629  //            $sale_maker_discount = $calc - $calc2;

 630              $sale_maker_discount = $calc;
 631            } else {
 632              $sale_maker_discount = $sale_maker_discount;
 633            }
 634          }
 635          break;
 636  // EOF: percentage discounts skip specials

 637  
 638  // BOF: flat amount discounts

 639        case ($discount_type_id == 20):
 640          // flat amount discount Sale and Special without a special

 641          if (!$attributes_id) {
 642            $sale_maker_discount = $sale_maker_discount;
 643          } else {
 644            // compute attribute amount

 645            if ($attributes_amount != 0) {
 646              $calc = ($attributes_amount - $sale_maker_discount);
 647              $sale_maker_discount = $calc;
 648            } else {
 649              $sale_maker_discount = $sale_maker_discount;
 650            }
 651          }
 652          break;
 653        case ($discount_type_id == 209):
 654          // flat amount discount on Sale and Special with a special

 655          if (!$attributes_id) {
 656            $sale_maker_discount = $sale_maker_discount;
 657          } else {
 658            // compute attribute amount

 659            if ($attributes_amount != 0) {
 660              $calc = ($attributes_amount * $special_price_discount);
 661              $calc2 = ($calc - $sale_maker_discount);
 662              $sale_maker_discount = $calc2;
 663            } else {
 664              $sale_maker_discount = $sale_maker_discount;
 665            }
 666          }
 667          break;
 668  // EOF: flat amount discounts

 669  
 670  // BOF: flat amount discounts Skip Special

 671        case ($discount_type_id == 10):
 672          // flat amount discount Sale and Special without a special

 673          if (!$attributes_id) {
 674            $sale_maker_discount = $sale_maker_discount;
 675          } else {
 676            // compute attribute amount

 677            if ($attributes_amount != 0) {
 678              $calc = ($attributes_amount - $sale_maker_discount);
 679              $sale_maker_discount = $calc;
 680            } else {
 681              $sale_maker_discount = $sale_maker_discount;
 682            }
 683          }
 684          break;
 685        case ($discount_type_id == 109):
 686          // flat amount discount on Sale and Special with a special

 687          if (!$attributes_id) {
 688            $sale_maker_discount = 1;
 689          } else {
 690            // compute attribute amount based on Special

 691            if ($attributes_amount != 0) {
 692              $calc = ($attributes_amount * $special_price_discount);
 693              $sale_maker_discount = $calc;
 694            } else {
 695              $sale_maker_discount = $sale_maker_discount;
 696            }
 697          }
 698          break;
 699  // EOF: flat amount discounts Skip Special

 700  
 701  // BOF: New Price amount discounts

 702        case ($discount_type_id == 220):
 703          // New Price amount discount Sale and Special without a special

 704          if (!$attributes_id) {
 705            $sale_maker_discount = $sale_maker_discount;
 706          } else {
 707            // compute attribute amount

 708            if ($attributes_amount != 0) {
 709              $calc = ($attributes_amount * $special_price_discount);
 710              $sale_maker_discount = $calc;
 711  //echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';

 712            } else {
 713              $sale_maker_discount = $sale_maker_discount;
 714            }
 715          }
 716          break;
 717        case ($discount_type_id == 2209):
 718          // New Price amount discount on Sale and Special with a special

 719          if (!$attributes_id) {
 720  //          $sale_maker_discount = $sale_maker_discount;

 721            $sale_maker_discount = $sale_maker_discount;
 722          } else {
 723            // compute attribute amount

 724            if ($attributes_amount != 0) {
 725              $calc = ($attributes_amount * $special_price_discount);
 726  //echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';

 727              $sale_maker_discount = $calc;
 728            } else {
 729              $sale_maker_discount = $sale_maker_discount;
 730            }
 731          }
 732          break;
 733  // EOF: New Price amount discounts

 734  
 735  // BOF: New Price amount discounts - Skip Special

 736        case ($discount_type_id == 210):
 737          // New Price amount discount Sale and Special without a special

 738          if (!$attributes_id) {
 739            $sale_maker_discount = $sale_maker_discount;
 740          } else {
 741            // compute attribute amount

 742            if ($attributes_amount != 0) {
 743              $calc = ($attributes_amount * $special_price_discount);
 744              $sale_maker_discount = $calc;
 745  //echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';

 746            } else {
 747              $sale_maker_discount = $sale_maker_discount;
 748            }
 749          }
 750          break;
 751        case ($discount_type_id == 2109):
 752          // New Price amount discount on Sale and Special with a special

 753          if (!$attributes_id) {
 754  //          $sale_maker_discount = $sale_maker_discount;

 755            $sale_maker_discount = $sale_maker_discount;
 756          } else {
 757            // compute attribute amount

 758            if ($attributes_amount != 0) {
 759              $calc = ($attributes_amount * $special_price_discount);
 760  //echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';

 761              $sale_maker_discount = $calc;
 762            } else {
 763              $sale_maker_discount = $sale_maker_discount;
 764            }
 765          }
 766          break;
 767  // EOF: New Price amount discounts - Skip Special

 768  
 769        case ($discount_type_id == 0 or $discount_type_id == 9):
 770        // flat discount

 771          return $sale_maker_discount;
 772          break;
 773        default:
 774          $sale_maker_discount = 7000;
 775          break;
 776      }
 777  
 778      return $sale_maker_discount;
 779    }
 780  
 781  ////

 782  // look up discount in sale makers - attributes only can have discounts if set as percentages

 783  // this gets the discount amount this does not determin when to apply the discount

 784    function zen_get_products_sale_discount_type($product_id = false, $categories_id = false, $return_value = false) {
 785      global $currencies;
 786      global $db;
 787  
 788  /*

 789  

 790  0 = flat amount off base price with a special

 791  1 = Percentage off base price with a special

 792  2 = New Price with a special

 793  

 794  5 = No Sale or Skip Products with Special

 795  

 796  special options + option * 10

 797  0 = Ignore special and apply to Price

 798  1 = Skip Products with Specials switch to 5

 799  2 = Apply to Special Price

 800  

 801  If a special exist * 10+9

 802  

 803  0*100 + 0*10 = flat apply to price = 0 or 9

 804  0*100 + 1*10 = flat skip Specials = 5 or 59

 805  0*100 + 2*10 = flat apply to special = 20 or 209

 806  

 807  1*100 + 0*10 = Percentage apply to price = 100 or 1009

 808  1*100 + 1*10 = Percentage skip Specials = 110 or 1109 / 5 or 59

 809  1*100 + 2*10 = Percentage apply to special = 120 or 1209

 810  

 811  2*100 + 0*10 = New Price apply to price = 200 or 2009

 812  2*100 + 1*10 = New Price skip Specials = 210 or 2109 / 5 or 59

 813  2*100 + 2*10 = New Price apply to Special = 220 or 2209

 814  

 815  */
 816  
 817  // get products category

 818      if ($categories_id == true) {
 819        $check_category = $categories_id;
 820      } else {
 821        $check_category = zen_get_products_category_id($product_id);
 822      }
 823  
 824      $deduction_type_array = array(array('id' => '0', 'text' => DEDUCTION_TYPE_DROPDOWN_0),
 825                                    array('id' => '1', 'text' => DEDUCTION_TYPE_DROPDOWN_1),
 826                                    array('id' => '2', 'text' => DEDUCTION_TYPE_DROPDOWN_2));
 827  
 828      $sale_exists = 'false';
 829      $sale_maker_discount = '';
 830      $sale_maker_special_condition = '';
 831      $salemaker_sales = $db->Execute("select sale_id, sale_status, sale_name, sale_categories_all, sale_deduction_value, sale_deduction_type, sale_pricerange_from, sale_pricerange_to, sale_specials_condition, sale_categories_selected, sale_date_start, sale_date_end, sale_date_added, sale_date_last_modified, sale_date_status_change from " . TABLE_SALEMAKER_SALES . " where sale_status='1'");
 832      while (!$salemaker_sales->EOF) {
 833        $categories = explode(',', $salemaker_sales->fields['sale_categories_all']);
 834          while (list($key,$value) = each($categories)) {
 835            if ($value == $check_category) {
 836            $sale_exists = 'true';
 837              $sale_maker_discount = $salemaker_sales->fields['sale_deduction_value'];
 838              $sale_maker_special_condition = $salemaker_sales->fields['sale_specials_condition'];
 839              $sale_maker_discount_type = $salemaker_sales->fields['sale_deduction_type'];
 840              break;
 841          }
 842        }
 843        $salemaker_sales->MoveNext();
 844      }
 845  
 846      $check_special = zen_get_products_special_price($product_id, true);
 847  
 848      if ($sale_exists == 'true' and $sale_maker_special_condition != 0) {
 849        $sale_maker_discount_type = (($sale_maker_discount_type * 100) + ($sale_maker_special_condition * 10));
 850      } else {
 851        $sale_maker_discount_type = 5;
 852      }
 853  
 854      if (!$check_special) {
 855        // do nothing

 856      } else {
 857        $sale_maker_discount_type = ($sale_maker_discount_type * 10) + 9;
 858      }
 859  
 860      switch (true) {
 861        case (!$return_value):
 862          return $sale_maker_discount_type;
 863          break;
 864        case ($return_value == 'amount'):
 865          return $sale_maker_discount;
 866          break;
 867        default:
 868          return 'Unknown Request';
 869          break;
 870      }
 871    }
 872  
 873  ////

 874  // look up discount in sale makers - attributes only can have discounts if set as percentages

 875  // this gets the discount amount this does not determin when to apply the discount

 876    function zen_get_products_sale_discount($product_id = false, $categories_id = false, $display_type = false) {
 877      global $currencies;
 878      global $db;
 879  
 880  // get products category

 881      if ($categories_id == true) {
 882        $check_category = $categories_id;
 883      } else {
 884        $check_category = zen_get_products_category_id($product_id);
 885      }
 886  
 887      $deduction_type_array = array(array('id' => '0', 'text' => DEDUCTION_TYPE_DROPDOWN_0),
 888                                    array('id' => '1', 'text' => DEDUCTION_TYPE_DROPDOWN_1),
 889                                    array('id' => '2', 'text' => DEDUCTION_TYPE_DROPDOWN_2));
 890  
 891      $sale_maker_discount = 0;
 892      $salemaker_sales = $db->Execute("select sale_id, sale_status, sale_name, sale_categories_all, sale_deduction_value, sale_deduction_type, sale_pricerange_from, sale_pricerange_to, sale_specials_condition, sale_categories_selected, sale_date_start, sale_date_end, sale_date_added, sale_date_last_modified, sale_date_status_change from " . TABLE_SALEMAKER_SALES . " where sale_status='1'");
 893      while (!$salemaker_sales->EOF) {
 894        $categories = explode(',', $salemaker_sales->fields['sale_categories_all']);
 895          while (list($key,$value) = each($categories)) {
 896            if ($value == $check_category) {
 897              $sale_maker_discount = $salemaker_sales->fields['sale_deduction_value'];
 898              $sale_maker_discount_type = $salemaker_sales->fields['sale_deduction_type'];
 899              break;
 900          }
 901        }
 902        $salemaker_sales->MoveNext();
 903      }
 904  
 905      switch(true) {
 906        // percentage discount only

 907        case ($sale_maker_discount_type == 1):
 908          $sale_maker_discount = (1 - ($sale_maker_discount / 100));
 909          break;
 910        case ($sale_maker_discount_type == 0 and $display_type == true):
 911          $sale_maker_discount = $sale_maker_discount;
 912          break;
 913        case ($sale_maker_discount_type == 0 and $display_type == false):
 914          $sale_maker_discount = $sale_maker_discount;
 915          break;
 916        case ($sale_maker_discount_type == 2 and $display_type == true):
 917          $sale_maker_discount = $sale_maker_discount;
 918          break;
 919        default:
 920          $sale_maker_discount = 1;
 921          break;
 922      }
 923  
 924      if ($display_type == true) {
 925        if ($sale_maker_discount != 1 and $sale_maker_discount !=0) {
 926          switch(true) {
 927            case ($sale_maker_discount_type == 0):
 928              $sale_maker_discount = $currencies->format($sale_maker_discount) . ' ' . $deduction_type_array[$sale_maker_discount_type]['text'];
 929              break;
 930            case ($sale_maker_discount_type == 2):
 931              $sale_maker_discount = $currencies->format($sale_maker_discount) . ' ' . $deduction_type_array[$sale_maker_discount_type]['text'];
 932              break;
 933            case ($sale_maker_discount_type == 1):
 934              $sale_maker_discount = number_format( (1.00 - $sale_maker_discount),2,".","") . ' ' . $deduction_type_array[$sale_maker_discount_type]['text'];
 935              break;
 936          }
 937        } else {
 938          $sale_maker_discount = '';
 939        }
 940      }
 941      return $sale_maker_discount;
 942    }
 943  
 944  ////

 945  // Actual Price Retail

 946  // Specials and Tax Included

 947    function zen_get_products_actual_price($products_id) {
 948      global $db, $currencies;
 949      $product_check = $db->Execute("select products_tax_class_id, products_price, products_priced_by_attribute, product_is_free, product_is_call from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'" . " limit 1");
 950  
 951      $show_display_price = '';
 952      $display_normal_price = zen_get_products_base_price($products_id);
 953      $display_special_price = zen_get_products_special_price($products_id, true);
 954      $display_sale_price = zen_get_products_special_price($products_id, false);
 955  
 956      $products_actual_price = $display_normal_price;
 957  
 958      if ($display_special_price) {
 959        $products_actual_price = $display_special_price;
 960      }
 961      if ($display_sale_price) {
 962        $products_actual_price = $display_sale_price;
 963      }
 964  
 965      // If Free, Show it

 966      if ($product_check->fields['product_is_free'] == '1') {
 967        $products_actual_price = 0;
 968      }
 969  
 970      return $products_actual_price;
 971    }
 972  
 973  ////

 974  // return attributes_price_factor

 975    function zen_get_attributes_price_factor($price, $special, $factor, $offset) {
 976      if (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL =='1' and $special) {
 977        // calculate from specials_new_products_price

 978        $calculated_price = $special * ($factor - $offset);
 979      } else {
 980        // calculate from products_price

 981        $calculated_price = $price * ($factor - $offset);
 982      }
 983  //    return '$price ' . $price . ' $special ' . $special . ' $factor ' . $factor . ' $offset ' . $offset;

 984      return $calculated_price;
 985    }
 986  
 987  
 988  ////

 989  // return attributes_qty_prices or attributes_qty_prices_onetime based on qty

 990    function zen_get_attributes_qty_prices_onetime($string, $qty) {
 991        $attribute_qty = split("[:,]" , $string);
 992        $size = sizeof($attribute_qty);
 993        for ($i=0, $n=$size; $i<$n; $i+=2) {
 994          $new_price = $attribute_qty[$i+1];
 995          if ($qty <= $attribute_qty[$i]) {
 996            $new_price = $attribute_qty[$i+1];
 997            break;
 998          }
 999        }
1000        return $new_price;
1001  }
1002  
1003  
1004  ////

1005  // Check specific attributes_qty_prices or attributes_qty_prices_onetime for a given quantity price

1006    function zen_get_attributes_quantity_price($check_what, $check_for) {
1007  // $check_what='1:3.00,5:2.50,10:2.25,20:2.00';

1008  // $check_for=50;

1009        $attribute_table_cost = split("[:,]" , $check_what);
1010        $size = sizeof($attribute_table_cost);
1011        for ($i=0, $n=$size; $i<$n; $i+=2) {
1012          if ($check_for >= $attribute_table_cost[$i]) {
1013            $attribute_quantity_check = $attribute_table_cost[$i];
1014            $attribute_quantity_price = $attribute_table_cost[$i+1];
1015          }
1016        }
1017  //          echo '<br>Cost ' . $check_for . ' - '  .  $attribute_quantity_check . ' x ' . $attribute_quantity_price;

1018       return $attribute_quantity_price;
1019    }
1020  
1021  
1022  ////

1023  // attributes final price

1024    function zen_get_attributes_price_final($attribute, $qty = 1, $pre_selected, $include_onetime = 'false') {
1025      global $db;
1026      global $cart;
1027  
1028      if ($pre_selected == '' or $attribute != $pre_selected->fields["products_attributes_id"]) {
1029        $pre_selected = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . $attribute . "'");
1030      } else {
1031        // use existing select

1032      }
1033  
1034      // normal attributes price

1035      if ($pre_selected->fields["price_prefix"] == '-') {
1036        $attributes_price_final -= $pre_selected->fields["options_values_price"];
1037      } else {
1038        $attributes_price_final += $pre_selected->fields["options_values_price"];
1039      }
1040      // qty discounts

1041      $attributes_price_final += zen_get_attributes_qty_prices_onetime($pre_selected->fields["attributes_qty_prices"], $qty);
1042  
1043      // price factor

1044      $display_normal_price = zen_get_products_actual_price($pre_selected->fields["products_id"]);
1045      $display_special_price = zen_get_products_special_price($pre_selected->fields["products_id"]);
1046  
1047      $attributes_price_final += zen_get_attributes_price_factor($display_normal_price, $display_special_price, $pre_selected->fields["attributes_price_factor"], $pre_selected->fields["attributes_price_factor_offset"]);
1048  
1049      // per word and letter charges

1050      if (zen_get_attributes_type($attribute) == PRODUCTS_OPTIONS_TYPE_TEXT) {
1051        // calc per word or per letter

1052      }
1053  
1054  // onetime charges

1055      if ($include_onetime == 'true') {
1056        $pre_selected_onetime = $pre_selected;
1057        $attributes_price_final += zen_get_attributes_price_final_onetime($pre_selected->fields["products_attributes_id"], 1, $pre_selected_onetime);
1058      }
1059  
1060      return $attributes_price_final;
1061    }
1062  
1063  
1064  ////

1065  // attributes final price onetime

1066    function zen_get_attributes_price_final_onetime($attribute, $qty= 1, $pre_selected_onetime) {
1067      global $db;
1068      global $cart;
1069  
1070      if ($pre_selected_onetime == '' or $attribute != $pre_selected_onetime->fields["products_attributes_id"]) {
1071        $pre_selected_onetime = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . $attribute . "'");
1072      } else {
1073        // use existing select

1074      }
1075  
1076  // one time charges

1077      // onetime charge

1078        $attributes_price_final_onetime += $pre_selected_onetime->fields["attributes_price_onetime"];
1079  
1080      // price factor

1081      $display_normal_price = zen_get_products_actual_price($pre_selected_onetime->fields["products_id"]);
1082      $display_special_price = zen_get_products_special_price($pre_selected_onetime->fields["products_id"]);
1083  
1084      // price factor one time

1085        $attributes_price_final_onetime += zen_get_attributes_price_factor($display_normal_price, $display_special_price, $pre_selected_onetime->fields["attributes_price_factor_onetime"], $pre_selected_onetime->fields["attributes_price_factor_onetime_offset"]);
1086  
1087      // onetime charge qty price

1088        $attributes_price_final_onetime += zen_get_attributes_qty_prices_onetime($pre_selected_onetime->fields["attributes_qty_prices_onetime"], 1);
1089  
1090        return $attributes_price_final_onetime;
1091      }
1092  
1093  
1094  ////

1095  // get attributes type

1096    function zen_get_attributes_type($check_attribute) {
1097      global $db;
1098      $check_options_id_query = $db->Execute("select options_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_attributes_id='" . $check_attribute . "'");
1099      $check_type_query = $db->Execute("select products_options_type from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id='" . $check_options_id_query->fields['options_id'] . "'");
1100      return $check_type_query->fields['products_options_type'];
1101    }
1102  
1103  
1104  ////

1105  // calculate words

1106    function zen_get_word_count($string, $free=0) {
1107      if ($string != '') {
1108        while (strstr($string, '  ')) $string = str_replace('  ', ' ', $string);
1109        $string = trim($string);
1110        $word_count = substr_count($string, ' ');
1111        return (($word_count+1) - $free);
1112      } else {
1113        // nothing to count

1114        return 0;
1115      }
1116    }
1117  
1118  
1119  ////

1120  // calculate words price

1121    function zen_get_word_count_price($string, $free=0, $price) {
1122      $word_count = zen_get_word_count($string, $free);
1123      if ($word_count >= 1) {
1124        return ($word_count * $price);
1125      } else {
1126        return 0;
1127      }
1128    }
1129  
1130  
1131  ////

1132  // calculate letters

1133    function zen_get_letters_count($string, $free=0) {
1134      while (strstr($string, '  ')) $string = str_replace('  ', ' ', $string);
1135      $string = trim($string);
1136      if (TEXT_SPACES_FREE == '1') {
1137        $letters_count = strlen(str_replace(' ', '', $string));
1138      } else {
1139        $letters_count = strlen($string);
1140      }
1141      if ($letters_count - $free >= 1) {
1142        return ($letters_count - $free);
1143      } else {
1144        return 0;
1145      }
1146    }
1147  
1148  
1149  ////

1150  // calculate letters price

1151    function zen_get_letters_count_price($string, $free=0, $price) {
1152        $letters_price = zen_get_letters_count($string, $free) * $price;
1153        if ($letters_price <= 0) {
1154          return 0;
1155        } else {
1156          return $letters_price;
1157        }
1158    }
1159  
1160  
1161  ////

1162  // compute discount based on qty

1163    function zen_get_products_discount_price_qty($product_id, $check_qty, $check_amount=0) {
1164      global $db;
1165        $product_id = (int)$product_id;
1166        $products_query = $db->Execute("select products_discount_type, products_discount_type_from, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'");
1167        $products_discounts_query = $db->Execute("select * from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id='" . $product_id . "' and discount_qty <='" . $check_qty . "' order by discount_qty desc");
1168  
1169        $display_price = zen_get_products_base_price($product_id);
1170        $display_specials_price = zen_get_products_special_price($product_id, true);
1171  
1172        switch ($products_query->fields['products_discount_type']) {
1173          // none

1174          case ($products_discounts_query->EOF):
1175            //no discount applies

1176            $discounted_price = zen_get_products_actual_price($product_id);
1177            break;
1178          case '0':
1179            $discounted_price = zen_get_products_actual_price($product_id);
1180            break;
1181          // percentage discount

1182          case '1':
1183            if ($products_query->fields['products_discount_type_from'] == '0') {
1184              // priced by attributes

1185              if ($check_amount != 0) {
1186                $discounted_price = $check_amount - ($check_amount * ($products_discounts_query->fields['discount_price']/100));
1187  //echo 'ID#' . $product_id . ' Amount is: ' . $check_amount . ' discount: ' . $discounted_price . '<br />';

1188  //echo 'I SEE 2 for ' . $products_query->fields['products_discount_type'] . ' - ' . $products_query->fields['products_discount_type_from'] . ' - '. $check_amount . ' new: ' . $discounted_price . ' qty: ' . $check_qty;

1189              } else {
1190                $discounted_price = $display_price - ($display_price * ($products_discounts_query->fields['discount_price']/100));
1191              }
1192            } else {
1193              if (!$display_specials_price) {
1194                // priced by attributes

1195                if ($check_amount != 0) {
1196                  $discounted_price = $check_amount - ($check_amount * ($products_discounts_query->fields['discount_price']/100));
1197                } else {
1198                  $discounted_price = $display_price - ($display_price * ($products_discounts_query->fields['discount_price']/100));
1199                }
1200              } else {
1201                $discounted_price = $display_specials_price - ($display_specials_price * ($products_discounts_query->fields['discount_price']/100));
1202              }
1203            }
1204  
1205            break;
1206          // actual price

1207          case '2':
1208            if ($products_query->fields['products_discount_type_from'] == '0') {
1209              $discounted_price = $products_discounts_query->fields['discount_price'];
1210            } else {
1211              $discounted_price = $products_discounts_query->fields['discount_price'];
1212            }
1213            break;
1214          // amount offprice

1215          case '3':
1216            if ($products_query->fields['products_discount_type_from'] == '0') {
1217              $discounted_price = $display_price - $products_discounts_query->fields['discount_price'];
1218            } else {
1219              if (!$display_specials_price) {
1220                $discounted_price = $display_price - $products_discounts_query->fields['discount_price'];
1221              } else {
1222                $discounted_price = $display_specials_price - $products_discounts_query->fields['discount_price'];
1223              }
1224            }
1225            break;
1226        }
1227  
1228        return $discounted_price;
1229    }
1230  
1231  
1232  ////

1233  // are there discount quanties

1234    function zen_get_discount_qty($product_id, $check_qty) {
1235      global $db;
1236  
1237      $product_id = (int)$product_id;
1238  
1239      $discounts_qty_query = $db->Execute("select * from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id='" . $product_id . "' and discount_qty != 0");
1240  //echo 'zen_get_discount_qty: ' . $product_id . ' - ' . $check_qty . '<br />';

1241      if ($discounts_qty_query->RecordCount() > 0 and $check_qty > 0) {
1242        return true;
1243      } else {
1244        return false;
1245      }
1246    }
1247  
1248  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics