ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/functions/functions_prices.php
Go to the documentation of this file.
00001 <?php
00009 
00010 //get specials price or sale price
00011   function zen_get_products_special_price($product_id, $specials_price_only=false) {
00012     global $db;
00013     $product = $db->Execute("select products_price, products_model, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
00014 
00015     if ($product->RecordCount() > 0) {
00016 //        $product_price = $product->fields['products_price'];
00017       $product_price = zen_get_products_base_price($product_id);
00018     } else {
00019       return false;
00020     }
00021 
00022     $specials = $db->Execute("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status='1'");
00023     if ($specials->RecordCount() > 0) {
00024 //      if ($product->fields['products_priced_by_attribute'] == 1) {
00025         $special_price = $specials->fields['specials_new_products_price'];
00026     } else {
00027       $special_price = false;
00028     }
00029 
00030     if(substr($product->fields['products_model'], 0, 4) == 'GIFT') {    //Never apply a salededuction to Ian Wilson's Giftvouchers
00031       if (zen_not_null($special_price)) {
00032         return $special_price;
00033       } else {
00034         return false;
00035       }
00036     }
00037 
00038 // return special price only
00039     if ($specials_price_only==true) {
00040       if (zen_not_null($special_price)) {
00041         return $special_price;
00042       } else {
00043         return false;
00044       }
00045     } else {
00046 // get sale price
00047 
00048 // changed to use master_categories_id
00049 //      $product_to_categories = $db->Execute("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'");
00050 //      $category = $product_to_categories->fields['categories_id'];
00051 
00052       $product_to_categories = $db->Execute("select master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
00053       $category = $product_to_categories->fields['master_categories_id'];
00054 
00055       $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')");
00056       if ($sale->RecordCount() < 1) {
00057          return $special_price;
00058       }
00059 
00060       if (!$special_price) {
00061         $tmp_special_price = $product_price;
00062       } else {
00063         $tmp_special_price = $special_price;
00064       }
00065       switch ($sale->fields['sale_deduction_type']) {
00066         case 0:
00067           $sale_product_price = $product_price - $sale->fields['sale_deduction_value'];
00068           $sale_special_price = $tmp_special_price - $sale->fields['sale_deduction_value'];
00069           break;
00070         case 1:
00071           $sale_product_price = $product_price - (($product_price * $sale->fields['sale_deduction_value']) / 100);
00072           $sale_special_price = $tmp_special_price - (($tmp_special_price * $sale->fields['sale_deduction_value']) / 100);
00073           break;
00074         case 2:
00075           $sale_product_price = $sale->fields['sale_deduction_value'];
00076           $sale_special_price = $sale->fields['sale_deduction_value'];
00077           break;
00078         default:
00079           return $special_price;
00080       }
00081 
00082       if ($sale_product_price < 0) {
00083         $sale_product_price = 0;
00084       }
00085 
00086       if ($sale_special_price < 0) {
00087         $sale_special_price = 0;
00088       }
00089 
00090       if (!$special_price) {
00091         return number_format($sale_product_price, 4, '.', '');
00092       } else {
00093         switch($sale->fields['sale_specials_condition']){
00094           case 0:
00095             return number_format($sale_product_price, 4, '.', '');
00096             break;
00097           case 1:
00098             return number_format($special_price, 4, '.', '');
00099             break;
00100           case 2:
00101             return number_format($sale_special_price, 4, '.', '');
00102             break;
00103           default:
00104             return number_format($special_price, 4, '.', '');
00105         }
00106       }
00107     }
00108   }
00109 
00110 
00112 // computes products_price + option groups lowest attributes price of each group when on
00113   function zen_get_products_base_price($products_id) {
00114     global $db;
00115       $product_check = $db->Execute("select products_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
00116 
00117 // is there a products_price to add to attributes
00118       $products_price = $product_check->fields['products_price'];
00119 
00120       // do not select display only attributes and attributes_price_base_included is true
00121       $product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, attributes_display_only, attributes_price_base_included, round(concat(price_prefix, options_values_price), 5) as value 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, value");
00122 
00123       $the_options_id= 'x';
00124       $the_base_price= 0;
00125 // add attributes price to price
00126       if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) {
00127         while (!$product_att_query->EOF) {
00128           if ( $the_options_id != $product_att_query->fields['options_id']) {
00129             $the_options_id = $product_att_query->fields['options_id'];
00130             $the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
00131           }
00132           $product_att_query->MoveNext();
00133         }
00134 
00135         $the_base_price = $products_price + $the_base_price;
00136       } else {
00137         $the_base_price = $products_price;
00138       }
00139       return $the_base_price;
00140   }
00141 
00142 
00144 // Display Price Retail
00145 // Specials and Tax Included
00146   function zen_get_products_display_price($products_id) {
00147     global $db, $currencies;
00148 
00149 // never mask prices in admin
00150 if (false) {
00151 // 0 = normal shopping
00152 // 1 = Login to shop
00153 // 2 = Can browse but no prices
00154     // verify display of prices
00155       switch (true) {
00156         case (CUSTOMERS_APPROVAL == '1' and $_SESSION['customer_id'] == ''):
00157         // customer must be logged in to browse
00158         return '';
00159         break;
00160         case (CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == ''):
00161         // customer may browse but no prices
00162         return '';
00163         break;
00164         default:
00165         // proceed normally
00166         break;
00167       }
00168 
00169 // show case only
00170     if (STORE_STATUS != '0') {
00171       if (STORE_STATUS == '1') {
00172         return '';
00173       }
00174     }
00175 }
00176     // $new_fields = ', product_is_free, product_is_call, product_is_showroom_only';
00177     $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 = '" . (int)$products_id . "'" . " limit 1");
00178 
00179     $show_display_price = '';
00180     $display_normal_price = zen_get_products_base_price($products_id);
00181     $display_special_price = zen_get_products_special_price($products_id, true);
00182     $display_sale_price = zen_get_products_special_price($products_id, false);
00183 
00184     $show_sale_discount = '';
00185     if (SHOW_SALE_DISCOUNT_STATUS == '1' and ($display_special_price != 0 or $display_sale_price != 0)) {
00186       if ($display_sale_price) {
00187         if (SHOW_SALE_DISCOUNT == 1) {
00188           if ($display_normal_price != 0) {
00189             $show_discount_amount = number_format(100 - (($display_sale_price / $display_normal_price) * 100),SHOW_SALE_DISCOUNT_DECIMALS);
00190           } else {
00191             $show_discount_amount = '';
00192           }
00193           $show_sale_discount = '<span class="productPriceDiscount">' . '<br />' . PRODUCT_PRICE_DISCOUNT_PREFIX . $show_discount_amount . PRODUCT_PRICE_DISCOUNT_PERCENTAGE . '</span>';
00194 
00195         } else {
00196           $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>';
00197         }
00198       } else {
00199         if (SHOW_SALE_DISCOUNT == 1) {
00200           $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>';
00201         } else {
00202           $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>';
00203         }
00204       }
00205     }
00206 
00207     if ($display_special_price) {
00208       $show_normal_price = '<span class="normalprice">' . $currencies->display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . ' </span>';
00209       if ($display_sale_price && $display_sale_price != $display_special_price) {
00210         $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>';
00211         if ($product_check->fields['product_is_free'] == '1') {
00212           $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>';
00213         } else {
00214           $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>';
00215         }
00216       } else {
00217         if ($product_check->fields['product_is_free'] == '1') {
00218           $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>';
00219         } else {
00220           $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>';
00221         }
00222         $show_sale_price = '';
00223       }
00224     } else {
00225       if ($display_sale_price) {
00226         $show_normal_price = '<span class="normalprice">' . $currencies->display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . ' </span>';
00227         $show_special_price = '';
00228         $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>';
00229       } else {
00230         if ($product_check->fields['product_is_free'] == '1') {
00231           $show_normal_price = '<s>' . $currencies->display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . '</s>';
00232         } else {
00233           $show_normal_price = $currencies->display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id']));
00234         }
00235         $show_special_price = '';
00236         $show_sale_price = '';
00237       }
00238     }
00239 
00240     if ($display_normal_price == 0) {
00241       // don't show the $0.00
00242       $final_display_price = $show_special_price . $show_sale_price . $show_sale_discount;
00243     } else {
00244       $final_display_price = $show_normal_price . $show_special_price . $show_sale_price . $show_sale_discount;
00245     }
00246 
00247     // If Free, Show it
00248     if ($product_check->fields['product_is_free'] == '1') {
00249       if (OTHER_IMAGE_PRICE_IS_FREE_ON=='0') {
00250         $free_tag = '<br />' . PRODUCTS_PRICE_IS_FREE_TEXT;
00251       } else {
00252         $free_tag = '<br />' . zen_image(DIR_WS_TEMPLATE_IMAGES . OTHER_IMAGE_PRICE_IS_FREE, PRODUCTS_PRICE_IS_FREE_TEXT);
00253       }
00254     }
00255 
00256     // If Call for Price, Show it
00257     if ($product_check->fields['product_is_call']) {
00258       if (PRODUCTS_PRICE_IS_CALL_IMAGE_ON=='0') {
00259         $call_tag = '<br />' . PRODUCTS_PRICE_IS_CALL_FOR_PRICE_TEXT;
00260       } else {
00261         $call_tag = '<br />' . zen_image(DIR_WS_TEMPLATE_IMAGES . OTHER_IMAGE_CALL_FOR_PRICE, PRODUCTS_PRICE_IS_CALL_FOR_PRICE_TEXT);
00262       }
00263     }
00264 
00265     return $final_display_price . $free_tag . $call_tag;
00266   }
00267 
00269 // Is the product free?
00270   function zen_get_products_price_is_free($products_id) {
00271     global $db;
00272     $product_check = $db->Execute("select product_is_free from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'" . " limit 1");
00273     if ($product_check->fields['product_is_free'] == '1') {
00274       $the_free_price = true;
00275     } else {
00276       $the_free_price = false;
00277     }
00278     return $the_free_price;
00279   }
00280 
00282 // Is the product call for price?
00283   function zen_get_products_price_is_call($products_id) {
00284     global $db;
00285     $product_check = $db->Execute("select product_is_call from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'" . " limit 1");
00286     if ($product_check->fields['product_is_call'] == '1') {
00287       $the_call_price = true;
00288     } else {
00289       $the_call_price = false;
00290     }
00291     return $the_call_price;
00292   }
00293 
00295 // Is the product priced by attributes?
00296   function zen_get_products_price_is_priced_by_attributes($products_id) {
00297     global $db;
00298     $product_check = $db->Execute("select products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'" . " limit 1");
00299     if ($product_check->fields['products_priced_by_attribute'] == '1') {
00300       $the_products_priced_by_attribute = true;
00301     } else {
00302       $the_products_priced_by_attribute = false;
00303     }
00304     return $the_products_priced_by_attribute;
00305   }
00306 
00308 // Return a product's minimum quantity
00309 // TABLES: products
00310   function zen_get_products_quantity_order_min($product_id) {
00311     global $db;
00312 
00313     $the_products_quantity_order_min = $db->Execute("select products_id, products_quantity_order_min from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
00314     return $the_products_quantity_order_min->fields['products_quantity_order_min'];
00315   }
00316 
00317 
00319 // Return a product's minimum unit order
00320 // TABLES: products
00321   function zen_get_products_quantity_order_units($product_id) {
00322     global $db;
00323 
00324     $the_products_quantity_order_units = $db->Execute("select products_id, products_quantity_order_units from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
00325     return $the_products_quantity_order_units->fields['products_quantity_order_units'];
00326   }
00327 
00329 // Return a product's maximum quantity
00330 // TABLES: products
00331   function zen_get_products_quantity_order_max($product_id) {
00332     global $db;
00333 
00334     $the_products_quantity_order_max = $db->Execute("select products_id, products_quantity_order_max from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
00335     return $the_products_quantity_order_max->fields['products_quantity_order_max'];
00336   }
00337 
00339 // Return a product's quantity box status
00340 // TABLES: products
00341   function zen_get_products_qty_box_status($product_id) {
00342     global $db;
00343 
00344     $the_products_qty_box_status = $db->Execute("select products_id, products_qty_box_status  from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
00345     return $the_products_qty_box_status->fields['products_qty_box_status'];
00346   }
00347 
00349 // Return a product mixed setting
00350 // TABLES: products
00351   function zen_get_products_quantity_mixed($product_id) {
00352     global $db;
00353 
00354     $the_products_quantity_mixed = $db->Execute("select products_id, products_quantity_mixed from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
00355     if ($the_products_quantity_mixed->fields['products_quantity_mixed'] == '1') {
00356       $look_up = true;
00357     } else {
00358       $look_up = false;
00359     }
00360     return $look_up;
00361   }
00362 
00363 
00365 // Return a products quantity minimum and units display
00366   function zen_get_products_quantity_min_units_display($product_id, $include_break = true, $shopping_cart_msg = false) {
00367     $check_min = zen_get_products_quantity_order_min($product_id);
00368     $check_units = zen_get_products_quantity_order_units($product_id);
00369 
00370     $the_min_units='';
00371 
00372     if ($check_min > 1 or $check_units > 1) {
00373       if ($check_min > 1) {
00374         $the_min_units .= PRODUCTS_QUANTITY_MIN_TEXT_LISTING . '&nbsp;' . $check_min;
00375       }
00376       if ($check_units > 1) {
00377         $the_min_units .= ($the_min_units ? ' ' : '' ) . PRODUCTS_QUANTITY_UNIT_TEXT_LISTING . '&nbsp;' . $check_units;
00378       }
00379 
00380       if (($check_min > 0 or $check_units > 0) and !zen_get_products_quantity_mixed($product_id)) {
00381         if ($include_break == true) {
00382           $the_min_units .= '<br />' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_OFF : TEXT_PRODUCTS_MIX_OFF_SHOPPING_CART);
00383         } else {
00384           $the_min_units .= '&nbsp;&nbsp;' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_OFF : TEXT_PRODUCTS_MIX_OFF_SHOPPING_CART);
00385         }
00386       } else {
00387         if ($include_break == true) {
00388           $the_min_units .= '<br />' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_ON : TEXT_PRODUCTS_MIX_ON_SHOPPING_CART);
00389         } else {
00390           $the_min_units .= '&nbsp;&nbsp;' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_ON : TEXT_PRODUCTS_MIX_ON_SHOPPING_CART);
00391         }
00392       }
00393     }
00394 
00395     // quantity max
00396     $check_max = zen_get_products_quantity_order_max($product_id);
00397 
00398     if ($check_max != 0) {
00399       if ($include_break == true) {
00400         $the_min_units .= ($the_min_units != '' ? '<br />' : '') . PRODUCTS_QUANTITY_MAX_TEXT_LISTING . '&nbsp;' . $check_max;
00401       } else {
00402         $the_min_units .= ($the_min_units != '' ? '&nbsp;&nbsp;' : '') . PRODUCTS_QUANTITY_MAX_TEXT_LISTING . '&nbsp;' . $check_max;
00403       }
00404     }
00405 
00406     return $the_min_units;
00407   }
00408 
00409 
00411 // Return quantity buy now
00412   function zen_get_buy_now_qty($product_id) {
00413     global $cart;
00414     $check_min = zen_get_products_quantity_order_min($product_id);
00415     $check_units = zen_get_products_quantity_order_units($product_id);
00416     $buy_now_qty=1;
00417 // works on Mixed ON
00418     switch (true) {
00419       case ($_SESSION['cart']->in_cart_mixed($product_id) == 0 ):
00420         if ($check_min >= $check_units) {
00421           $buy_now_qty = $check_min;
00422         } else {
00423           $buy_now_qty = $check_units;
00424         }
00425         break;
00426       case ($_SESSION['cart']->in_cart_mixed($product_id) < $check_min):
00427         $buy_now_qty = $check_min - $_SESSION['cart']->in_cart_mixed($product_id);
00428         break;
00429       case ($_SESSION['cart']->in_cart_mixed($product_id) > $check_min):
00430       // set to units or difference in units to balance cart
00431         $new_units = $check_units - fmod_round($_SESSION['cart']->in_cart_mixed($product_id), $check_units);
00432 //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 />';
00433         $buy_now_qty = ($new_units > 0 ? $new_units : $check_units);
00434         break;
00435       default:
00436         $buy_now_qty = $check_units;
00437         break;
00438     }
00439     if ($buy_now_qty <= 0) {
00440       $buy_now_qty = 1;
00441     }
00442     return $buy_now_qty;
00443   }
00444 
00445 
00447 // compute product discount to be applied to attributes or other values
00448   function zen_get_discount_calc($product_id, $attributes_id = false, $attributes_amount = false, $check_qty= false) {
00449     global $discount_type_id, $sale_maker_discount;
00450     global $cart;
00451 
00452     // no charge
00453     if ($attributes_id > 0 and $attributes_amount == 0) {
00454       return 0;
00455     }
00456 
00457     $new_products_price = zen_get_products_base_price($product_id);
00458     $new_special_price = zen_get_products_special_price($product_id, true);
00459     $new_sale_price = zen_get_products_special_price($product_id, false);
00460 
00461     $discount_type_id = zen_get_products_sale_discount_type($product_id);
00462 
00463     if ($new_products_price != 0) {
00464       $special_price_discount = ($new_special_price != 0 ? ($new_special_price/$new_products_price) : 1);
00465     } else {
00466       $special_price_discount = '';
00467     }
00468     $sale_maker_discount = zen_get_products_sale_discount_type($product_id, '', 'amount');
00469 
00470     // percentage adjustment of discount
00471     if (($discount_type_id == 120 or $discount_type_id == 1209) or ($discount_type_id == 110 or $discount_type_id == 1109)) {
00472       $sale_maker_discount = ($sale_maker_discount != 0 ? (100 - $sale_maker_discount)/100 : 1);
00473     }
00474 
00475    $qty = $check_qty;
00476 
00477 // fix here
00478 // BOF: percentage discounts apply to price
00479     switch (true) {
00480       case (zen_get_discount_qty($product_id, $qty) and !$attributes_id):
00481         // discount quanties exist and this is not an attribute
00482         // $this->contents[$products_id]['qty']
00483         $check_discount_qty_price = zen_get_products_discount_price_qty($product_id, $qty, $attributes_amount);
00484 //echo 'How much 1 ' . $qty . ' : ' . $attributes_amount . ' vs ' . $check_discount_qty_price . '<br />';
00485         return $check_discount_qty_price;
00486         break;
00487 
00488       case (zen_get_discount_qty($product_id, $qty) and zen_get_products_price_is_priced_by_attributes($product_id)):
00489         // discount quanties exist and this is not an attribute
00490         // $this->contents[$products_id]['qty']
00491         $check_discount_qty_price = zen_get_products_discount_price_qty($product_id, $qty, $attributes_amount);
00492 //echo 'How much 2 ' . $qty . ' : ' . $attributes_amount . ' vs ' . $check_discount_qty_price . '<br />';
00493 
00494         return $check_discount_qty_price;
00495         break;
00496 
00497       case ($discount_type_id == 5):
00498         // No Sale and No Special
00499 //        $sale_maker_discount = 1;
00500         if (!$attributes_id) {
00501           $sale_maker_discount = $sale_maker_discount;
00502         } else {
00503           // compute attribute amount
00504           if ($attributes_amount != 0) {
00505             if ($special_price_discount != 0) {
00506               $calc = ($attributes_amount * $special_price_discount);
00507             } else {
00508               $calc = $attributes_amount;
00509             }
00510 
00511             $sale_maker_discount = $calc;
00512           } else {
00513             $sale_maker_discount = $sale_maker_discount;
00514           }
00515         }
00516 //echo 'How much 3 - ' . $qty . ' : ' . $product_id . ' : ' . $qty . ' x ' .  $attributes_amount . ' vs ' . $check_discount_qty_price . ' - ' . $sale_maker_discount . '<br />';
00517         break;
00518       case ($discount_type_id == 59):
00519         // No Sale and Special
00520 //        $sale_maker_discount = $special_price_discount;
00521         if (!$attributes_id) {
00522           $sale_maker_discount = $sale_maker_discount;
00523         } else {
00524           // compute attribute amount
00525           if ($attributes_amount != 0) {
00526             $calc = ($attributes_amount * $special_price_discount);
00527             $sale_maker_discount = $calc;
00528           } else {
00529             $sale_maker_discount = $sale_maker_discount;
00530           }
00531         }
00532         break;
00533 // EOF: percentage discount apply to price
00534 
00535 // BOF: percentage discounts apply to Sale
00536       case ($discount_type_id == 120):
00537         // percentage discount Sale and Special without a special
00538         if (!$attributes_id) {
00539           $sale_maker_discount = $sale_maker_discount;
00540         } else {
00541           // compute attribute amount
00542           if ($attributes_amount != 0) {
00543             $calc = ($attributes_amount * $sale_maker_discount);
00544             $sale_maker_discount = $calc;
00545           } else {
00546             $sale_maker_discount = $sale_maker_discount;
00547           }
00548         }
00549         break;
00550       case ($discount_type_id == 1209):
00551         // percentage discount on Sale and Special with a special
00552         if (!$attributes_id) {
00553           $sale_maker_discount = $sale_maker_discount;
00554         } else {
00555           // compute attribute amount
00556           if ($attributes_amount != 0) {
00557             $calc = ($attributes_amount * $special_price_discount);
00558             $calc2 = $calc - ($calc * $sale_maker_discount);
00559             $sale_maker_discount = $calc - $calc2;
00560           } else {
00561             $sale_maker_discount = $sale_maker_discount;
00562           }
00563         }
00564         break;
00565 // EOF: percentage discounts apply to Sale
00566 
00567 // BOF: percentage discounts skip specials
00568       case ($discount_type_id == 110):
00569         // percentage discount Sale and Special without a special
00570         if (!$attributes_id) {
00571           $sale_maker_discount = $sale_maker_discount;
00572         } else {
00573           // compute attribute amount
00574           if ($attributes_amount != 0) {
00575             $calc = ($attributes_amount * $sale_maker_discount);
00576             $sale_maker_discount = $calc;
00577           } else {
00578 //            $sale_maker_discount = $sale_maker_discount;
00579             if ($attributes_amount != 0) {
00580 //            $calc = ($attributes_amount * $special_price_discount);
00581 //            $calc2 = $calc - ($calc * $sale_maker_discount);
00582 //            $sale_maker_discount = $calc - $calc2;
00583               $calc = $attributes_amount - ($attributes_amount * $sale_maker_discount);
00584               $sale_maker_discount = $calc;
00585             } else {
00586               $sale_maker_discount = $sale_maker_discount;
00587             }
00588           }
00589         }
00590         break;
00591       case ($discount_type_id == 1109):
00592         // percentage discount on Sale and Special with a special
00593         if (!$attributes_id) {
00594           $sale_maker_discount = $sale_maker_discount;
00595         } else {
00596           // compute attribute amount
00597           if ($attributes_amount != 0) {
00598             $calc = ($attributes_amount * $special_price_discount);
00599 //            $calc2 = $calc - ($calc * $sale_maker_discount);
00600 //            $sale_maker_discount = $calc - $calc2;
00601             $sale_maker_discount = $calc;
00602           } else {
00603             $sale_maker_discount = $sale_maker_discount;
00604           }
00605         }
00606         break;
00607 // EOF: percentage discounts skip specials
00608 
00609 // BOF: flat amount discounts
00610       case ($discount_type_id == 20):
00611         // flat amount discount Sale and Special without a special
00612         if (!$attributes_id) {
00613           $sale_maker_discount = $sale_maker_discount;
00614         } else {
00615           // compute attribute amount
00616           if ($attributes_amount != 0) {
00617             $calc = ($attributes_amount - $sale_maker_discount);
00618             $sale_maker_discount = $calc;
00619           } else {
00620             $sale_maker_discount = $sale_maker_discount;
00621           }
00622         }
00623         break;
00624       case ($discount_type_id == 209):
00625         // flat amount discount on Sale and Special with a special
00626         if (!$attributes_id) {
00627           $sale_maker_discount = $sale_maker_discount;
00628         } else {
00629           // compute attribute amount
00630           if ($attributes_amount != 0) {
00631             $calc = ($attributes_amount * $special_price_discount);
00632             $calc2 = ($calc - $sale_maker_discount);
00633             $sale_maker_discount = $calc2;
00634           } else {
00635             $sale_maker_discount = $sale_maker_discount;
00636           }
00637         }
00638         break;
00639 // EOF: flat amount discounts
00640 
00641 // BOF: flat amount discounts Skip Special
00642       case ($discount_type_id == 10):
00643         // flat amount discount Sale and Special without a special
00644         if (!$attributes_id) {
00645           $sale_maker_discount = $sale_maker_discount;
00646         } else {
00647           // compute attribute amount
00648           if ($attributes_amount != 0) {
00649             $calc = ($attributes_amount - $sale_maker_discount);
00650             $sale_maker_discount = $calc;
00651           } else {
00652             $sale_maker_discount = $sale_maker_discount;
00653           }
00654         }
00655         break;
00656       case ($discount_type_id == 109):
00657         // flat amount discount on Sale and Special with a special
00658         if (!$attributes_id) {
00659           $sale_maker_discount = 1;
00660         } else {
00661           // compute attribute amount based on Special
00662           if ($attributes_amount != 0) {
00663             $calc = ($attributes_amount * $special_price_discount);
00664             $sale_maker_discount = $calc;
00665           } else {
00666             $sale_maker_discount = $sale_maker_discount;
00667           }
00668         }
00669         break;
00670 // EOF: flat amount discounts Skip Special
00671 
00672 // BOF: New Price amount discounts
00673       case ($discount_type_id == 220):
00674         // New Price amount discount Sale and Special without a special
00675         if (!$attributes_id) {
00676           $sale_maker_discount = $sale_maker_discount;
00677         } else {
00678           // compute attribute amount
00679           if ($attributes_amount != 0) {
00680             $calc = ($attributes_amount * $special_price_discount);
00681             $sale_maker_discount = $calc;
00682 //echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';
00683           } else {
00684             $sale_maker_discount = $sale_maker_discount;
00685           }
00686         }
00687         break;
00688       case ($discount_type_id == 2209):
00689         // New Price amount discount on Sale and Special with a special
00690         if (!$attributes_id) {
00691 //          $sale_maker_discount = $sale_maker_discount;
00692           $sale_maker_discount = $sale_maker_discount;
00693         } else {
00694           // compute attribute amount
00695           if ($attributes_amount != 0) {
00696             $calc = ($attributes_amount * $special_price_discount);
00697 //echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';
00698             $sale_maker_discount = $calc;
00699           } else {
00700             $sale_maker_discount = $sale_maker_discount;
00701           }
00702         }
00703         break;
00704 // EOF: New Price amount discounts
00705 
00706 // BOF: New Price amount discounts - Skip Special
00707       case ($discount_type_id == 210):
00708         // New Price amount discount Sale and Special without a special
00709         if (!$attributes_id) {
00710           $sale_maker_discount = $sale_maker_discount;
00711         } else {
00712           // compute attribute amount
00713           if ($attributes_amount != 0) {
00714             $calc = ($attributes_amount * $special_price_discount);
00715             $sale_maker_discount = $calc;
00716 //echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';
00717           } else {
00718             $sale_maker_discount = $sale_maker_discount;
00719           }
00720         }
00721         break;
00722       case ($discount_type_id == 2109):
00723         // New Price amount discount on Sale and Special with a special
00724         if (!$attributes_id) {
00725 //          $sale_maker_discount = $sale_maker_discount;
00726           $sale_maker_discount = $sale_maker_discount;
00727         } else {
00728           // compute attribute amount
00729           if ($attributes_amount != 0) {
00730             $calc = ($attributes_amount * $special_price_discount);
00731 //echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';
00732             $sale_maker_discount = $calc;
00733           } else {
00734             $sale_maker_discount = $sale_maker_discount;
00735           }
00736         }
00737         break;
00738 // EOF: New Price amount discounts - Skip Special
00739 
00740       case ($discount_type_id == 0 or $discount_type_id == 9):
00741       // flat discount
00742         return $sale_maker_discount;
00743         break;
00744       default:
00745         $sale_maker_discount = 7000;
00746         break;
00747     }
00748 
00749     return $sale_maker_discount;
00750   }
00751 
00753 // look up discount in sale makers - attributes only can have discounts if set as percentages
00754 // this gets the discount amount this does not determin when to apply the discount
00755   function zen_get_products_sale_discount_type($product_id = false, $categories_id = false, $return_value = false) {
00756     global $currencies;
00757     global $db;
00758 
00759 /*
00760 
00761 0 = flat amount off base price with a special
00762 1 = Percentage off base price with a special
00763 2 = New Price with a special
00764 
00765 5 = No Sale or Skip Products with Special
00766 
00767 special options + option * 10
00768 0 = Ignore special and apply to Price
00769 1 = Skip Products with Specials switch to 5
00770 2 = Apply to Special Price
00771 
00772 If a special exist * 10+9
00773 
00774 0*100 + 0*10 = flat apply to price = 0 or 9
00775 0*100 + 1*10 = flat skip Specials = 5 or 59
00776 0*100 + 2*10 = flat apply to special = 20 or 209
00777 
00778 1*100 + 0*10 = Percentage apply to price = 100 or 1009
00779 1*100 + 1*10 = Percentage skip Specials = 110 or 1109 / 5 or 59
00780 1*100 + 2*10 = Percentage apply to special = 120 or 1209
00781 
00782 2*100 + 0*10 = New Price apply to price = 200 or 2009
00783 2*100 + 1*10 = New Price skip Specials = 210 or 2109 / 5 or 59
00784 2*100 + 2*10 = New Price apply to Special = 220 or 2209
00785 
00786 */
00787 
00788 // get products category
00789     if ($categories_id == true) {
00790       $check_category = $categories_id;
00791     } else {
00792       $check_category = zen_get_products_category_id($product_id);
00793     }
00794 
00795     $deduction_type_array = array(array('id' => '0', 'text' => DEDUCTION_TYPE_DROPDOWN_0),
00796                                   array('id' => '1', 'text' => DEDUCTION_TYPE_DROPDOWN_1),
00797                                   array('id' => '2', 'text' => DEDUCTION_TYPE_DROPDOWN_2));
00798 
00799     $sale_exists = 'false';
00800     $sale_maker_discount = '';
00801     $sale_maker_special_condition = '';
00802     $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'");
00803     while (!$salemaker_sales->EOF) {
00804       $categories = explode(',', $salemaker_sales->fields['sale_categories_all']);
00805       while (list($key,$value) = each($categories)) {
00806         if ($value == $check_category) {
00807           $sale_exists = 'true';
00808           $sale_maker_discount = $salemaker_sales->fields['sale_deduction_value'];
00809           $sale_maker_special_condition = $salemaker_sales->fields['sale_specials_condition'];
00810           $sale_maker_discount_type = $salemaker_sales->fields['sale_deduction_type'];
00811           break;
00812         }
00813       }
00814       $salemaker_sales->MoveNext();
00815     }
00816 
00817     $check_special = zen_get_products_special_price($product_id, true);
00818 
00819     if ($sale_exists == 'true' and $sale_maker_special_condition != 0) {
00820       $sale_maker_discount_type = (($sale_maker_discount_type * 100) + ($sale_maker_special_condition * 10));
00821     } else {
00822       $sale_maker_discount_type = 5;
00823     }
00824 
00825     if (!$check_special) {
00826       // do nothing
00827     } else {
00828       $sale_maker_discount_type = ($sale_maker_discount_type * 10) + 9;
00829     }
00830 
00831     switch (true) {
00832       case (!$return_value):
00833         return $sale_maker_discount_type;
00834         break;
00835       case ($return_value == 'amount'):
00836         return $sale_maker_discount;
00837         break;
00838       default:
00839         return 'Unknown Request';
00840         break;
00841     }
00842   }
00843 
00845 // look up discount in sale makers - attributes only can have discounts if set as percentages
00846 // this gets the discount amount this does not determin when to apply the discount
00847   function zen_get_products_sale_discount($product_id = false, $categories_id = false, $display_type = false) {
00848     global $currencies;
00849     global $db;
00850 
00851 // get products category
00852     if ($categories_id == true) {
00853       $check_category = $categories_id;
00854     } else {
00855       $check_category = zen_get_products_category_id($product_id);
00856     }
00857 
00858     $deduction_type_array = array(array('id' => '0', 'text' => DEDUCTION_TYPE_DROPDOWN_0),
00859                                   array('id' => '1', 'text' => DEDUCTION_TYPE_DROPDOWN_1),
00860                                   array('id' => '2', 'text' => DEDUCTION_TYPE_DROPDOWN_2));
00861 
00862     $sale_maker_discount = 0;
00863     $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'");
00864     while (!$salemaker_sales->EOF) {
00865       $categories = explode(',', $salemaker_sales->fields['sale_categories_all']);
00866       while (list($key,$value) = each($categories)) {
00867         if ($value == $check_category) {
00868           $sale_maker_discount = $salemaker_sales->fields['sale_deduction_value'];
00869           $sale_maker_discount_type = $salemaker_sales->fields['sale_deduction_type'];
00870           break;
00871         }
00872       }
00873       $salemaker_sales->MoveNext();
00874     }
00875 
00876     switch(true) {
00877       // percentage discount only
00878       case ($sale_maker_discount_type == 1):
00879         $sale_maker_discount = (1 - ($sale_maker_discount / 100));
00880         break;
00881       case ($sale_maker_discount_type == 0 and $display_type == true):
00882         $sale_maker_discount = $sale_maker_discount;
00883         break;
00884       case ($sale_maker_discount_type == 0 and $display_type == false):
00885         $sale_maker_discount = $sale_maker_discount;
00886         break;
00887       case ($sale_maker_discount_type == 2 and $display_type == true):
00888         $sale_maker_discount = $sale_maker_discount;
00889         break;
00890       default:
00891         $sale_maker_discount = 1;
00892         break;
00893     }
00894 
00895     if ($display_type == true) {
00896       if ($sale_maker_discount != 1 and $sale_maker_discount !=0) {
00897         switch(true) {
00898           case ($sale_maker_discount_type == 0):
00899             $sale_maker_discount = $currencies->format($sale_maker_discount) . ' ' . $deduction_type_array[$sale_maker_discount_type]['text'];
00900             break;
00901           case ($sale_maker_discount_type == 2):
00902             $sale_maker_discount = $currencies->format($sale_maker_discount) . ' ' . $deduction_type_array[$sale_maker_discount_type]['text'];
00903             break;
00904           case ($sale_maker_discount_type == 1):
00905             $sale_maker_discount = number_format( (1.00 - $sale_maker_discount),2,".","") . ' ' . $deduction_type_array[$sale_maker_discount_type]['text'];
00906             break;
00907         }
00908       } else {
00909         $sale_maker_discount = '';
00910       }
00911     }
00912     return $sale_maker_discount;
00913   }
00914 
00916 // Actual Price Retail
00917 // Specials and Tax Included
00918   function zen_get_products_actual_price($products_id) {
00919     global $db, $currencies;
00920     $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 = '" . (int)$products_id . "'" . " limit 1");
00921 
00922     $show_display_price = '';
00923     $display_normal_price = zen_get_products_base_price($products_id);
00924     $display_special_price = zen_get_products_special_price($products_id, true);
00925     $display_sale_price = zen_get_products_special_price($products_id, false);
00926 
00927     $products_actual_price = $display_normal_price;
00928 
00929     if ($display_special_price) {
00930       $products_actual_price = $display_special_price;
00931     }
00932     if ($display_sale_price) {
00933       $products_actual_price = $display_sale_price;
00934     }
00935 
00936     // If Free, Show it
00937     if ($product_check->fields['product_is_free'] == '1') {
00938       $products_actual_price = 0;
00939     }
00940 
00941     return $products_actual_price;
00942   }
00943 
00945 // return attributes_price_factor
00946   function zen_get_attributes_price_factor($price, $special, $factor, $offset) {
00947     if (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL =='1' and $special) {
00948       // calculate from specials_new_products_price
00949       $calculated_price = $special * ($factor - $offset);
00950     } else {
00951       // calculate from products_price
00952       $calculated_price = $price * ($factor - $offset);
00953     }
00954 //    return '$price ' . $price . ' $special ' . $special . ' $factor ' . $factor . ' $offset ' . $offset;
00955     return $calculated_price;
00956   }
00957 
00958 
00960 // return attributes_qty_prices or attributes_qty_prices_onetime based on qty
00961   function zen_get_attributes_qty_prices_onetime($string, $qty) {
00962       $attribute_qty = preg_split("/[:,]/" , $string);
00963       $size = sizeof($attribute_qty);
00964       for ($i=0, $n=$size; $i<$n; $i+=2) {
00965         $new_price = $attribute_qty[$i+1];
00966         if ($qty <= $attribute_qty[$i]) {
00967           $new_price = $attribute_qty[$i+1];
00968           break;
00969         }
00970       }
00971       return $new_price;
00972 }
00973 
00974 
00976 // Check specific attributes_qty_prices or attributes_qty_prices_onetime for a given quantity price
00977   function zen_get_attributes_quantity_price($check_what, $check_for) {
00978 // $check_what='1:3.00,5:2.50,10:2.25,20:2.00';
00979 // $check_for=50;
00980       $attribute_table_cost = preg_split("/[:,]/" , $check_what);
00981       $size = sizeof($attribute_table_cost);
00982       for ($i=0, $n=$size; $i<$n; $i+=2) {
00983         if ($check_for >= $attribute_table_cost[$i]) {
00984           $attribute_quantity_check = $attribute_table_cost[$i];
00985           $attribute_quantity_price = $attribute_table_cost[$i+1];
00986         }
00987       }
00988 //          echo '<br>Cost ' . $check_for . ' - '  .  $attribute_quantity_check . ' x ' . $attribute_quantity_price;
00989      return $attribute_quantity_price;
00990   }
00991 
00992 
00994 // attributes final price
00995   function zen_get_attributes_price_final($attribute, $qty = 1, $pre_selected, $include_onetime = 'false') {
00996     global $db;
00997     global $cart;
00998 
00999     if ($pre_selected == '' or $attribute != $pre_selected->fields["products_attributes_id"]) {
01000       $pre_selected = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . (int)$attribute . "'");
01001     } else {
01002       // use existing select
01003     }
01004 
01005     // normal attributes price
01006     if ($pre_selected->fields["price_prefix"] == '-') {
01007       $attributes_price_final -= $pre_selected->fields["options_values_price"];
01008     } else {
01009       $attributes_price_final += $pre_selected->fields["options_values_price"];
01010     }
01011     // qty discounts
01012     $attributes_price_final += zen_get_attributes_qty_prices_onetime($pre_selected->fields["attributes_qty_prices"], $qty);
01013 
01014     // price factor
01015     $display_normal_price = zen_get_products_actual_price($pre_selected->fields["products_id"]);
01016     $display_special_price = zen_get_products_special_price($pre_selected->fields["products_id"]);
01017 
01018     $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"]);
01019 
01020     // per word and letter charges
01021     if (zen_get_attributes_type($attribute) == PRODUCTS_OPTIONS_TYPE_TEXT) {
01022       // calc per word or per letter
01023     }
01024 
01025 // onetime charges
01026     if ($include_onetime == 'true') {
01027       $pre_selected_onetime = $pre_selected;
01028       $attributes_price_final += zen_get_attributes_price_final_onetime($pre_selected->fields["products_attributes_id"], 1, $pre_selected_onetime);
01029     }
01030 
01031     return $attributes_price_final;
01032   }
01033 
01034 
01036 // attributes final price onetime
01037   function zen_get_attributes_price_final_onetime($attribute, $qty= 1, $pre_selected_onetime) {
01038     global $db;
01039     global $cart;
01040 
01041     if ($pre_selected_onetime == '' or $attribute != $pre_selected_onetime->fields["products_attributes_id"]) {
01042       $pre_selected_onetime = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . (int)$attribute . "'");
01043     } else {
01044       // use existing select
01045     }
01046 
01047 // one time charges
01048     // onetime charge
01049       $attributes_price_final_onetime += $pre_selected_onetime->fields["attributes_price_onetime"];
01050 
01051     // price factor
01052     $display_normal_price = zen_get_products_actual_price($pre_selected_onetime->fields["products_id"]);
01053     $display_special_price = zen_get_products_special_price($pre_selected_onetime->fields["products_id"]);
01054 
01055     // price factor one time
01056       $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"]);
01057 
01058     // onetime charge qty price
01059       $attributes_price_final_onetime += zen_get_attributes_qty_prices_onetime($pre_selected_onetime->fields["attributes_qty_prices_onetime"], 1);
01060 
01061       return $attributes_price_final_onetime;
01062     }
01063 
01064 
01066 // get attributes type
01067   function zen_get_attributes_type($check_attribute) {
01068     global $db;
01069     $check_options_id_query = $db->Execute("select options_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_attributes_id='" . (int)$check_attribute . "'");
01070     $check_type_query = $db->Execute("select products_options_type from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id='" . (int)$check_options_id_query->fields['options_id'] . "'");
01071     return $check_type_query->fields['products_options_type'];
01072   }
01073 
01074 
01076 // calculate words
01077   function zen_get_word_count($string, $free=0) {
01078     if ($string != '') {
01079       while (strstr($string, '  ')) $string = str_replace('  ', ' ', $string);
01080       $string = trim($string);
01081       $word_count = substr_count($string, ' ');
01082       return (($word_count+1) - $free);
01083     } else {
01084       // nothing to count
01085       return 0;
01086     }
01087   }
01088 
01089 
01091 // calculate words price
01092   function zen_get_word_count_price($string, $free=0, $price) {
01093     $word_count = zen_get_word_count($string, $free);
01094     if ($word_count >= 1) {
01095       return ($word_count * $price);
01096     } else {
01097       return 0;
01098     }
01099   }
01100 
01101 
01103 // calculate letters
01104   function zen_get_letters_count($string, $free=0) {
01105     while (strstr($string, '  ')) $string = str_replace('  ', ' ', $string);
01106     $string = trim($string);
01107     if (TEXT_SPACES_FREE == '1') {
01108       $letters_count = strlen(str_replace(' ', '', $string));
01109     } else {
01110       $letters_count = strlen($string);
01111     }
01112     if ($letters_count - $free >= 1) {
01113       return ($letters_count - $free);
01114     } else {
01115       return 0;
01116     }
01117   }
01118 
01119 
01121 // calculate letters price
01122   function zen_get_letters_count_price($string, $free=0, $price) {
01123       $letters_price = zen_get_letters_count($string, $free) * $price;
01124       if ($letters_price <= 0) {
01125         return 0;
01126       } else {
01127         return $letters_price;
01128       }
01129   }
01130 
01131 
01133 // compute discount based on qty
01134   function zen_get_products_discount_price_qty($product_id, $check_qty, $check_amount=0) {
01135     global $db;
01136       $product_id = (int)$product_id;
01137       $products_query = $db->Execute("select products_discount_type, products_discount_type_from, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id='" . (int)$product_id . "'");
01138       $products_discounts_query = $db->Execute("select * from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id='" . (int)$product_id . "' and discount_qty <='" . zen_db_input($check_qty) . "' order by discount_qty desc");
01139 
01140       $display_price = zen_get_products_base_price($product_id);
01141       $display_specials_price = zen_get_products_special_price($product_id, true);
01142 
01143       switch ($products_query->fields['products_discount_type']) {
01144         // none
01145         case ($products_discounts_query->EOF):
01146           //no discount applies
01147           $discounted_price = zen_get_products_actual_price($product_id);
01148           break;
01149         case '0':
01150           $discounted_price = zen_get_products_actual_price($product_id);
01151           break;
01152         // percentage discount
01153         case '1':
01154           if ($products_query->fields['products_discount_type_from'] == '0') {
01155             // priced by attributes
01156             if ($check_amount != 0) {
01157               $discounted_price = $check_amount - ($check_amount * ($products_discounts_query->fields['discount_price']/100));
01158 //echo 'ID#' . $product_id . ' Amount is: ' . $check_amount . ' discount: ' . $discounted_price . '<br />';
01159 //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;
01160             } else {
01161               $discounted_price = $display_price - ($display_price * ($products_discounts_query->fields['discount_price']/100));
01162             }
01163           } else {
01164             if (!$display_specials_price) {
01165               // priced by attributes
01166               if ($check_amount != 0) {
01167                 $discounted_price = $check_amount - ($check_amount * ($products_discounts_query->fields['discount_price']/100));
01168               } else {
01169                 $discounted_price = $display_price - ($display_price * ($products_discounts_query->fields['discount_price']/100));
01170               }
01171             } else {
01172               $discounted_price = $display_specials_price - ($display_specials_price * ($products_discounts_query->fields['discount_price']/100));
01173             }
01174           }
01175 
01176           break;
01177         // actual price
01178         case '2':
01179           if ($products_query->fields['products_discount_type_from'] == '0') {
01180             $discounted_price = $products_discounts_query->fields['discount_price'];
01181           } else {
01182             $discounted_price = $products_discounts_query->fields['discount_price'];
01183           }
01184           break;
01185         // amount offprice
01186         case '3':
01187           if ($products_query->fields['products_discount_type_from'] == '0') {
01188             $discounted_price = $display_price - $products_discounts_query->fields['discount_price'];
01189           } else {
01190             if (!$display_specials_price) {
01191               $discounted_price = $display_price - $products_discounts_query->fields['discount_price'];
01192             } else {
01193               $discounted_price = $display_specials_price - $products_discounts_query->fields['discount_price'];
01194             }
01195           }
01196           break;
01197       }
01198 
01199       return $discounted_price;
01200   }
01201 
01202 
01204 // are there discount quanties
01205   function zen_get_discount_qty($product_id, $check_qty) {
01206     global $db;
01207 
01208     $product_id = (int)$product_id;
01209 
01210     $discounts_qty_query = $db->Execute("select * from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id='" . (int)$product_id . "' and discount_qty != 0");
01211 //echo 'zen_get_discount_qty: ' . $product_id . ' - ' . $check_qty . '<br />';
01212     if ($discounts_qty_query->RecordCount() > 0 and $check_qty > 0) {
01213       return true;
01214     } else {
01215       return false;
01216     }
01217   }
01218 
 All Data Structures Namespaces Files Functions Variables Enumerations