er_discount = 7000; break; } return $sale_maker_discount; } //// // look up discount in sale makers - attributes only can have discounts if set as percentages // this gets the discount amount this does not determin when to apply the discount function zen_get_products_sale_discount_type($product_id = false, $categories_id = false, $return_value = false) { global $currencies; global $db; /* 0 = flat amount off base price with a special 1 = Percentage off base price with a special 2 = New Price with a special 5 = No Sale or Skip Products with Special special options + option * 10 0 = Ignore special and apply to Price 1 = Skip Products with Specials switch to 5 2 = Apply to Special Price If a special exist * 10+9 0*100 + 0*10 = flat apply to price = 0 or 9 0*100 + 1*10 = flat skip Specials = 5 or 59 0*100 + 2*10 = flat apply to special = 20 or 209 1*100 + 0*10 = Percentage apply to price = 100 or 1009 1*100 + 1*10 = Percentage skip Specials = 110 or 1109 / 5 or 59 1*100 + 2*10 = Percentage apply to special = 120 or 1209 2*100 + 0*10 = New Price apply to price = 200 or 2009 2*100 + 1*10 = New Price skip Specials = 210 or 2109 / 5 or 59 2*100 + 2*10 = New Price apply to Special = 220 or 2209 */ // get products category if ($categories_id == true) { $check_category = $categories_id; } else { $check_category = zen_get_products_category_id($product_id); } /* $deduction_type_array = array(array('id' => '0', 'text' => DEDUCTION_TYPE_DROPDOWN_0), array('id' => '1', 'text' => DEDUCTION_TYPE_DROPDOWN_1), array('id' => '2', 'text' => DEDUCTION_TYPE_DROPDOWN_2)); */ $sale_exists = 'false'; $sale_maker_discount = ''; $sale_maker_special_condition = ''; $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'"); while (!$salemaker_sales->EOF) { $categories = explode(',', $salemaker_sales->fields['sale_categories_all']); while (list($key,$value) = each($categories)) { if ($value == $check_category) { $sale_exists = 'true'; $sale_maker_discount = $salemaker_sales->fields['sale_deduction_value']; $sale_maker_special_condition = $salemaker_sales->fields['sale_specials_condition']; $sale_maker_discount_type = $salemaker_sales->fields['sale_deduction_type']; break; } } $salemaker_sales->MoveNext(); } $check_special = zen_get_products_special_price($product_id, true); if ($sale_exists == 'true' and $sale_maker_special_condition != 0) { $sale_maker_discount_type = (($sale_maker_discount_type * 100) + ($sale_maker_special_condition * 10)); } else { $sale_maker_discount_type = 5; } if (!$check_special) { // do nothing } else { $sale_maker_discount_type = ($sale_maker_discount_type * 10) + 9; } switch (true) { case (!$return_value): return $sale_maker_discount_type; break; case ($return_value == 'amount'): return $sale_maker_discount; break; default: return 'Unknown Request'; break; } } //// // look up discount in sale makers - attributes only can have discounts if set as percentages // this gets the discount amount this does not determin when to apply the discount function zen_get_products_sale_discount($product_id = false, $categories_id = false, $display_type = false) { global $currencies; global $db; // NOT USED echo '
' . 'I SHOULD use zen_get_discount_calc' . '
'; /* 0 = flat amount off base price with a special 1 = Percentage off base price with a special 2 = New Price with a special 5 = No Sale or Skip Products with Special special options + option * 10 0 = Ignore special and apply to Price 1 = Skip Products with Specials switch to 5 2 = Apply to Special Price If a special exist * 10 0+7 + 0+10 = flat apply to price = 17 or 170 0+7 + 1+10 = flat skip Specials = 5 or 50 0+7 + 2+10 = flat apply to special = 27 or 270 1+7 + 0+10 = Percentage apply to price = 18 or 180 1+7 + 1+10 = Percentage skip Specials = 5 or 50 1+7 + 2+10 = Percentage apply to special = 20 or 200 2+7 + 0+10 = New Price apply to price = 19 or 190 2+7 + 1+10 = New Price skip Specials = 5 or 50 2+7 + 2+10 = New Price apply to Special = 21 or 210 */ /* // get products category if ($categories_id == true) { $check_category = $categories_id; } else { $check_category = zen_get_products_category_id($product_id); } $deduction_type_array = array(array('id' => '0', 'text' => DEDUCTION_TYPE_DROPDOWN_0), array('id' => '1', 'text' => DEDUCTION_TYPE_DROPDOWN_1), array('id' => '2', 'text' => DEDUCTION_TYPE_DROPDOWN_2)); $sale_maker_discount = 0; $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'"); while (!$salemaker_sales->EOF) { $categories = explode(',', $salemaker_sales->fields['sale_categories_all']); while (list($key,$value) = each($categories)) { if ($value == $check_category) { $sale_maker_discount = $salemaker_sales->fields['sale_deduction_value']; $sale_maker_discount_type = $salemaker_sales->fields['sale_deduction_type']; break; } } $salemaker_sales->MoveNext(); } switch(true) { // percentage discount only case ($sale_maker_discount_type == 1): $sale_maker_discount = (1 - ($sale_maker_discount / 100)); break; case ($sale_maker_discount_type == 0 and $display_type == true): $sale_maker_discount = $sale_maker_discount; break; case ($sale_maker_discount_type == 0 and $display_type == false): $sale_maker_discount = $sale_maker_discount; break; case ($sale_maker_discount_type == 2 and $display_type == true): $sale_maker_discount = $sale_maker_discount; break; default: $sale_maker_discount = 1; break; } if ($display_type == true) { if ($sale_maker_discount != 1 and $sale_maker_discount !=0) { switch(true) { case ($sale_maker_discount_type == 0): $sale_maker_discount = $currencies->format($sale_maker_discount) . ' ' . $deduction_type_array[$sale_maker_discount_type]['text']; break; case ($sale_maker_discount_type == 2): $sale_maker_discount = $currencies->format($sale_maker_discount) . ' ' . $deduction_type_array[$sale_maker_discount_type]['text']; break; case ($sale_maker_discount_type == 1): $sale_maker_discount = number_format( (1.00 - $sale_maker_discount),2,".","") . ' ' . $deduction_type_array[$sale_maker_discount_type]['text']; break; } } else { $sale_maker_discount = ''; } } return $sale_maker_discount; */ } //// // Actual Price Retail // Specials and Tax Included function zen_get_products_actual_price($products_id) { global $db, $currencies; $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"); $show_display_price = ''; $display_normal_price = zen_get_products_base_price($products_id); $display_special_price = zen_get_products_special_price($products_id, true); $display_sale_price = zen_get_products_special_price($products_id, false); $products_actual_price = $display_normal_price; if ($display_special_price) { $products_actual_price = $display_special_price; } if ($display_sale_price) { $products_actual_price = $display_sale_price; } // If Free, Show it if ($product_check->fields['product_is_free'] == '1') { $products_actual_price = 0; } return $products_actual_price; } //// // return attributes_price_factor function zen_get_attributes_price_factor($price, $special, $factor, $offset) { if (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL =='1' and $special) { // calculate from specials_new_products_price $calculated_price = $special * ($factor - $offset); } else { // calculate from products_price $calculated_price = $price * ($factor - $offset); } // return '$price ' . $price . ' $special ' . $special . ' $factor ' . $factor . ' $offset ' . $offset; return $calculated_price; } //// // return attributes_qty_prices or attributes_qty_prices_onetime based on qty function zen_get_attributes_qty_prices_onetime($string, $qty) { $attribute_qty = preg_split("[:,]" , $string); $new_price = 0; $size = sizeof($attribute_qty); // if an empty string is passed then $attributes_qty will consist of a 1 element array if ($size > 1) { for ($i=0, $n=$size; $i<$n; $i+=2) { $new_price = $attribute_qty[$i+1]; if ($qty <= $attribute_qty[$i]) { $new_price = $attribute_qty[$i+1]; break; } } } return $new_price; } //// // Check specific attributes_qty_prices or attributes_qty_prices_onetime for a given quantity price function zen_get_attributes_quantity_price($check_what, $check_for) { // $check_what='1:3.00,5:2.50,10:2.25,20:2.00'; // $check_for=50; $attribute_table_cost = split("[:,]" , $check_what); $size = sizeof($attribute_table_cost); for ($i=0, $n=$size; $i<$n; $i+=2) { if ($check_for >= $attribute_table_cost[$i]) { $attribute_quantity_check = $attribute_table_cost[$i]; $attribute_quantity_price = $attribute_table_cost[$i+1]; } } // echo '
Cost ' . $check_for . ' - ' . $attribute_quantity_check . ' x ' . $attribute_quantity_price; return $attribute_quantity_price; } //// // attributes final price function zen_get_attributes_price_final($attribute, $qty = 1, $pre_selected, $include_onetime = 'false') { global $db; global $cart; $attributes_price_final = 0; if ($pre_selected == '' or $attribute != $pre_selected->fields["products_attributes_id"]) { $pre_selected = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . $attribute . "'"); } else { // use existing select } // normal attributes price if ($pre_selected->fields["price_prefix"] == '-') { $attributes_price_final -= $pre_selected->fields["options_values_price"]; } else { $attributes_price_final += $pre_selected->fields["options_values_price"]; } // qty discounts $attributes_price_final += zen_get_attributes_qty_prices_onetime($pre_selected->fields["attributes_qty_prices"], $qty); // price factor $display_normal_price = zen_get_products_actual_price($pre_selected->fields["products_id"]); $display_special_price = zen_get_products_special_price($pre_selected->fields["products_id"]); $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"]); // per word and letter charges if (zen_get_attributes_type($attribute) == PRODUCTS_OPTIONS_TYPE_TEXT) { // calc per word or per letter } // onetime charges if ($include_onetime == 'true') { $pre_selected_onetime = $pre_selected; $attributes_price_final += zen_get_attributes_price_final_onetime($pre_selected->fields["products_attributes_id"], 1, $pre_selected_onetime); } return $attributes_price_final; } //// // attributes final price onetime function zen_get_attributes_price_final_onetime($attribute, $qty= 1, $pre_selected_onetime) { global $db; global $cart; if ($pre_selected_onetime == '' or $attribute != $pre_selected_onetime->fields["products_attributes_id"]) { $pre_selected_onetime = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . $attribute . "'"); } else { // use existing select } // one time charges // onetime charge $attributes_price_final_onetime += $pre_selected_onetime->fields["attributes_price_onetime"]; // price factor $display_normal_price = zen_get_products_actual_price($pre_selected_onetime->fields["products_id"]); $display_special_price = zen_get_products_special_price($pre_selected_onetime->fields["products_id"]); // price factor one time $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"]); // onetime charge qty price $attributes_price_final_onetime += zen_get_attributes_qty_prices_onetime($pre_selected_onetime->fields["attributes_qty_prices_onetime"], 1); return $attributes_price_final_onetime; } //// // get attributes type function zen_get_attributes_type($check_attribute) { global $db; $check_options_id_query = $db->Execute("select options_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_attributes_id='" . $check_attribute . "'"); $check_type_query = $db->Execute("select products_options_type from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id='" . $check_options_id_query->fields['options_id'] . "'"); return $check_type_query->fields['products_options_type']; } //// // calculate words function zen_get_word_count($string, $free=0) { if ($string != '') { while (strstr($string, ' ')) $string = str_replace(' ', ' ', $string); $string = trim($string); $word_count = substr_count($string, ' '); return (($word_count+1) - $free); } else { // nothing to count return 0; } } //// // calculate words price function zen_get_word_count_price($string, $free=0, $price) { $word_count = zen_get_word_count($string, $free); if ($word_count >= 1) { return ($word_count * $price); } else { return 0; } } //// // calculate letters function zen_get_letters_count($string, $free=0) { while (strstr($string, ' ')) $string = str_replace(' ', ' ', $string); $string = trim($string); if (TEXT_SPACES_FREE == '1') { $letters_count = strlen(str_replace(' ', '', $string)); } else { $letters_count = strlen($string); } if ($letters_count - $free >= 1) { return ($letters_count - $free); } else { return 0; } } //// // calculate letters price function zen_get_letters_count_price($string, $free=0, $price) { $letters_price = zen_get_letters_count($string, $free) * $price; if ($letters_price <= 0) { return 0; } else { return $letters_price; } } //// // compute discount based on qty function zen_get_products_discount_price_qty($product_id, $check_qty, $check_amount=0) { global $db, $cart; $new_qty = $_SESSION['cart']->in_cart_mixed_discount_quantity($product_id); // check for discount qty mix =============== removed by john ================== //if ($new_qty > $check_qty) { // $check_qty = $new_qty; //} $product_id = (int)$product_id; $products_query = $db->Execute("select products_discount_type, products_discount_type_from, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'"); $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"); $display_price = zen_get_products_base_price($product_id); $display_specials_price = zen_get_products_special_price($product_id, true); switch ($products_query->fields['products_discount_type']) { // none case ($products_discounts_query->EOF): //no discount applies $discounted_price = zen_get_products_actual_price($product_id); break; case '0': $discounted_price = zen_get_products_actual_price($product_id); break; // percentage discount case '1': if ($products_query->fields['products_discount_type_from'] == '0') { // priced by attributes if ($check_amount != 0) { $discounted_price = $check_amount - ($check_amount * ($products_discounts_query->fields['discount_price']/100)); //echo 'ID#' . $product_id . ' Amount is: ' . $check_amount . ' discount: ' . $discounted_price . '
'; //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; } else { $discounted_price = $display_price - ($display_price * ($products_discounts_query->fields['discount_price']/100)); } } else { if (!$display_specials_price) { // priced by attributes if ($check_amount != 0) { $discounted_price = $check_amount - ($check_amount * ($products_discounts_query->fields['discount_price']/100)); } else { $discounted_price = $display_price - ($display_price * ($products_discounts_query->fields['discount_price']/100)); } } else { $discounted_price = $display_specials_price - ($display_specials_price * ($products_discounts_query->fields['discount_price']/100)); } } break; // actual price case '2': if ($products_query->fields['products_discount_type_from'] == '0') { $discounted_price = $products_discounts_query->fields['discount_price']; } else { $discounted_price = $products_discounts_query->fields['discount_price']; } break; // amount offprice case '3': if ($products_query->fields['products_discount_type_from'] == '0') { $discounted_price = $display_price - $products_discounts_query->fields['discount_price']; } else { if (!$display_specials_price) { $discounted_price = $display_price - $products_discounts_query->fields['discount_price']; } else { $discounted_price = $display_specials_price - $products_discounts_query->fields['discount_price']; } } break; } return $discounted_price; } //// // are there discount quanties function zen_get_discount_qty($product_id, $check_qty) { global $db; $product_id = (int)$product_id; $discounts_qty_query = $db->Execute("select * from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id='" . $product_id . "' and discount_qty != 0"); //echo 'zen_get_discount_qty: ' . $product_id . ' - ' . $check_qty . '
'; if ($discounts_qty_query->RecordCount() > 0 and $check_qty > 0) { return true; } else { return false; } } //// // set the products_price_sorter function zen_update_products_price_sorter($product_id) { global $db; $products_price_sorter = zen_get_products_actual_price($product_id); $db->Execute("update " . TABLE_PRODUCTS . " set products_price_sorter='" . zen_db_prepare_input($products_price_sorter) . "' where products_id='" . $product_id . "'"); } //// // salemaker categories array function zen_parse_salemaker_categories($clist) { $clist_array = explode(',', $clist); // make sure no duplicate category IDs exist which could lock the server in a loop $tmp_array = array(); $n = sizeof($clist_array); for ($i=0; $i<$n; $i++) { if (!in_array($clist_array[$i], $tmp_array)) { $tmp_array[] = $clist_array[$i]; } } return $tmp_array; } //// // update salemaker product prices per category per product function zen_update_salemaker_product_prices($salemaker_id) { global $db; $zv_categories = $db->Execute("select sale_categories_selected from " . TABLE_SALEMAKER_SALES . " where sale_id = '" . $salemaker_id . "'"); $za_salemaker_categories = zen_parse_salemaker_categories($zv_categories->fields['sale_categories_selected']); $n = sizeof($za_salemaker_categories); for ($i=0; $i<$n; $i++) { $update_products_price = $db->Execute("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id='" . $za_salemaker_categories[$i] . "'"); while (!$update_products_price->EOF) { zen_update_products_price_sorter($update_products_price->fields['products_id']); $update_products_price->MoveNext(); } } } ?>
Warning: Cannot modify header information - headers already sent by (output started at /home/chocol5/public_html/includes/functions/functions_prices.php:568) in /home/chocol5/public_html/includes/init_includes/init_templates.php on line 78
Custom Chocolate Medallions from ChocoFavors.com
ChocoFavors ChocoFavors

Free Shipping

on order above $ 250