Jump to content
Sign in to follow this  
Illicious

Description in Product Listing v.2 Help

Recommended Posts

Hi mate, yeah, I ahve that........ That's in the file :

 

// auto expire special products 

 require(DIR_WS_FUNCTIONS . 'specials.php'); 

 tep_expire_specials(); 



// calculate category path 

 if (isset($HTTP_GET_VARS['cPath'])) { 

   $cPath = $HTTP_GET_VARS['cPath']; 

 } elseif (isset($HTTP_GET_VARS['products_id']) && !isset($HTTP_GET_VARS['manufacturers_id'])) { 

   $cPath = tep_get_product_path($HTTP_GET_VARS['products_id']); 

 } else { 

   $cPath = ''; 

 } 



 if (tep_not_null($cPath)) { 

   $cPath_array = tep_parse_category_path($cPath); 

   $cPath = implode('_', $cPath_array); 

   $current_category_id = $cPath_array[(sizeof($cPath_array)-1)]; 

 } else { 

   $current_category_id = 0;

Share this post


Link to post
Share on other sites

By the way, I am using the latest snap shot..... Would using an older (your) application_top.php work do you think??

 

(I gave you the wrong email address, I am eddy@diecastcentral.net! - cheers!)

Share this post


Link to post
Share on other sites

Thing is i dont think mine is that old cus its the M1 release that im using.

 

Well if its defined in application_top then i have no other ideas.

 

I would scan your mods for the "tep_parse_category_path" and what mods use this or need altering in application_top.

Share this post


Link to post
Share on other sites

Try this. Go to your admin section and to Configuration> Product Listing> and set the order of the display of your product listing to a lower number to 250 or anything lower than 350.

 

Also its best if you keep the image and the price far apart preferably image to the far right and price to the far left.

 

Ill use my configuration as an example.

 

Display Product Image 1

Display Product Manufaturer Name 4

Display Product Model 0

Display Product Name 3

Display Product Price 5

Display Product Quantity 0

Display Product Weight 0

Display Buy Now column 2

Display Category/Manufacturer Filter (0=disable; 1=enable) 1

Location of Prev/Next Navigation Bar (1-top, 2-bottom, 3-both) 3

Display Product Description 99

Length of Truncated Product Description 310

 

Here 12345 is the order that shows Example1:

 

_(image=1)_BuyNow=2___Name=3___Manufature=4___Price=5__

___________Description should apear here.

 

If you wanna show more then put them in order Example2:

 

_(image=1)_BuyNow=2_Model=3_Name=4_Manufature=5_Price=6_

___________Description should apear here.

 

See if that works.

Share this post


Link to post
Share on other sites

Thanks for your help. I tried changing my catalog options to the ones that you suggested. Unfortunately it still seems to be an issue.

 

http://www.consolecorner.com/catalog/defau...t.php?cPath=1_4

 

Any help on this would be much appreciated, i am at a loss here. It works great if it is only displaying one product, but as soon as the second one comes in, it messes.

 

I am at a loss here, any help is much appreciated.

Thanks!

 

I'll post my code for product_listing.php

 

<?php

/*

 $Id: product_listing.php,v 1.41 2003/02/12 23:55:58 hpdl Exp $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2003 osCommerce



 Released under the GNU General Public License

*/

?>

<table border="0" width="100%" cellspacing="0" cellpadding="2">

<?php

 $listing_numrows_sql = $listing_sql;

 $listing_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $listing_sql, $listing_numrows);

// fix counted products

 $listing_numrows = tep_db_query($listing_numrows_sql);

 $listing_numrows = tep_db_num_rows($listing_numrows);



 if ( ($listing_numrows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {

?>

 <tr>

   <td><table border="0" width="100%" cellspacing="0" cellpadding="2">

     <tr>

       <td class="smallText"> <?php echo $listing_split->display_count($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?> </td>

       <td align="right" class="smallText"> <?php echo TEXT_RESULT_PAGE; ?> <?php echo $listing_split->display_links($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'], tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?> </td>

     </tr>

   </table></td>

 </tr>

 <tr>

   <td><?php echo tep_draw_separator(); ?></td>

 </tr>

<?php

 }

?>

 <tr>

   <td>

<?php

 $list_box_contents = array();

 $list_box_contents[] = array('params' => 'class="productListing-heading"');

 $cur_row = sizeof($list_box_contents) - 1;



 for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {

   switch ($column_list[$col]) {

     case 'PRODUCT_LIST_MODEL':

       $lc_text = TABLE_HEADING_MODEL;

       $lc_align = '';

       break;

     case 'PRODUCT_LIST_NAME':

       $lc_text = TABLE_HEADING_PRODUCTS;

       $lc_align = '';

       break;

     // Products Description Hack begins

     case 'PRODUCT_LIST_DESCRIPTION':

       break;

     // Products Description Hack ends

     case 'PRODUCT_LIST_MANUFACTURER':

       $lc_text = TABLE_HEADING_MANUFACTURER;

       $lc_align = '';

       break;

     case 'PRODUCT_LIST_PRICE':

       $lc_text = TABLE_HEADING_PRICE;

       $lc_align = 'right';

       break;

     case 'PRODUCT_LIST_QUANTITY':

       $lc_text = TABLE_HEADING_QUANTITY;

       $lc_align = 'right';

       break;

     case 'PRODUCT_LIST_WEIGHT':

       $lc_text = TABLE_HEADING_WEIGHT;

       $lc_align = 'right';

       break;

     case 'PRODUCT_LIST_IMAGE':

       $lc_text = TABLE_HEADING_IMAGE;

       $lc_align = 'center';

       break;

     case 'PRODUCT_LIST_BUY_NOW':

       $lc_text = TABLE_HEADING_BUY_NOW;

       $lc_align = 'center';

       break;

   }

   

   // Products Description Hack begins

   if ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW' &&

       $column_list[$col] != 'PRODUCT_LIST_IMAGE' &&

       $column_list[$col] != 'PRODUCT_LIST_DESCRIPTION')

     $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);

   if ($column_list[$col] != 'PRODUCT_LIST_DESCRIPTION') {

     $list_box_contents[$cur_row][] = array('align' => $lc_align,

                                            'params' => 'class="productListing-heading"',

                                            'text'  => " " . $lc_text . " ");

   }

   // Products Description Hack ends

   $list_box_contents[$cur_row][] = array('align' => $lc_align,

                                          'params' => 'class="productListing-heading"',

                                          'text' => ' ' . $lc_text . ' ');

 }



 if ($listing_numrows > 0) {

   $number_of_products = '0';

   $listing_query = tep_db_query($listing_sql);

   while ($listing = tep_db_fetch_array($listing_query)) {

     $number_of_products++;



     if (($number_of_products/2) == floor($number_of_products/2)) {

       $list_box_contents[] = array('params' => 'class="productListing-even"');

     } else {

       $list_box_contents[] = array('params' => 'class="productListing-odd"');

     }



     $cur_row = sizeof($list_box_contents) - 1;



     for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {

       $lc_align = '';

       // Products Description Hack begins

       $lc_params = '';

       // Products Description Hack ends



       switch ($column_list[$col]) {

         case 'PRODUCT_LIST_MODEL':

           $lc_align = '';

           $lc_text = ' ' . $listing['products_model'] . ' ';

           break;

         case 'PRODUCT_LIST_NAME':

           $lc_align = '';

           if (isset($HTTP_GET_VARS['manufacturers_id'])) {

             $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';

           } else {

             $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a> ';

           }

           break;

         // Products Description Hack begins

         case 'PRODUCT_LIST_DESCRIPTION':

           $lc_text = ' ' . osc_trunc_string(strip_tags($listing_values['products_description'], '<a><b><em><font><i><s><span><strong><sub><sup><u>'), PRODUCT_LIST_DESCRIPTION_LENGTH) . ' ';

           $col_to_span = sizeof($column_list)-1;

           if (PRODUCT_LIST_IMAGE > 0) {

             $col_to_span -= 1;

           }

           $lc_params = 'colspan="' . $col_to_span . '" ';

           break;

         // Products Description Hack ends

         case 'PRODUCT_LIST_MANUFACTURER':

           $lc_align = '';

           $lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a> ';

           break;

         case 'PRODUCT_LIST_PRICE':

           $lc_align = 'right';

           if (tep_not_null($listing['specials_new_products_price'])) {

             $lc_text = ' <s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span> ';

           } else {

             $lc_text = ' ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' ';

           }

           break;

         case 'PRODUCT_LIST_QUANTITY':

           $lc_align = 'right';

           $lc_text = ' ' . $listing['products_quantity'] . ' ';

           break;

         case 'PRODUCT_LIST_WEIGHT':

           $lc_align = 'right';

           $lc_text = ' ' . $listing['products_weight'] . ' ';

           break;

         case 'PRODUCT_LIST_IMAGE':

           $lc_align = 'center';

           if (isset($HTTP_GET_VARS['manufacturers_id'])) {

             $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';

           } else {

             $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a> ';

           }

           // Products Description Hack begins

           if (PRODUCT_LIST_DESCRIPTION > 0) {

             $lc_params = 'rowspan="2" ';

           }

           // Products Description Hack ends

           break;

         case 'PRODUCT_LIST_BUY_NOW':

           $lc_align = 'center';

           $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a> ';

           break;

       }



       // Products Description Hack begins

       $lc_params .= 'class="productListing-data"';

       if ($column_list[$col] == 'PRODUCT_LIST_DESCRIPTION') {

         $list_box_contents[$cur_row][] = array('align' => $lc_align,

                                                'params' => $lc_params,

                                                'text' => $lc_text,

                                                'desc_flag' => 'true');

       } else {

         $list_box_contents[$cur_row][] = array('align' => $lc_align,

                                                'params' => $lc_params,

                                                'text'  => $lc_text);

       }

       // Products Description Hack ends

     }

   }



   new tableBox($list_box_contents, true);



   echo '    </td>' . "n" .

        '  </tr>' . "n";

 } else {

?>

 <tr class="productListing-odd">

   <td class="smallText"> <?php echo (isset($HTTP_GET_VARS['manufacturers_id']) ? TEXT_NO_PRODUCTS2 : TEXT_NO_PRODUCTS); ?> </td>

 </tr>

<?php

 }

?>

 <tr>

   <td><?php echo tep_draw_separator(); ?></td>

 </tr>

<?php

 if ( ($listing_numrows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {

?>

 <tr>

   <td><table border="0" width="100%" cellspacing="0" cellpadding="2">

     <tr>

       <td class="smallText"> <?php echo $listing_split->display_count($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?> </td>

       <td align="right" class="smallText"> <?php echo TEXT_RESULT_PAGE; ?> <?php echo $listing_split->display_links($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'], tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?> </td>

     </tr>

   </table></td>

 </tr>

<?php

 }

?>

</table>

Share this post


Link to post
Share on other sites

Ok start by turning off the description.

 

If it lists normally then turn the description back on and set the description length to 10.

 

If it works keep increasin the number to 50, 100, 150, 200, 250, etc etc and see where it fails.

Share this post


Link to post
Share on other sites

thanks again,

yeah it happens as soon as the product description is turned on. No matter what length i truncate the description at.

Share this post


Link to post
Share on other sites

The problem is it's not adding the second <tr> for the description. Double check the changes you made to boxes.php.

 

Also see that no other contribution you're using is interfering with the process. (I recall one that was kind of a template/style changer that overrides the use of boxes.php completely. The boxes.php changes had to be made in the files it replaced it with instead.)


"It's a damn poor mind that can only think of one way to spell a word."

-- Andrew Jackson

Share this post


Link to post
Share on other sites

Great, yes it was the addition of an add-on :oops: that was causing the problem. Thanks for you help! Great contribution!

Share this post


Link to post
Share on other sites

Hi, I have almost got this working except I am getting the description added at the end of the row rather than on a new row. I am using the thema mod but I've modified the equivalent to boxes.php that is used in this mod.

 

I've double checked all the changes that I've made numerous times. Can anyone point me to the file I should be looking in to fix this problem of the missing <tr></tr> tags?

 

You can see the current state of things at http://shop.opticalfunk.com/default.php?cPath=3_13

 

Appreciate any help as this is driving me nuts :oops:


tobz

 

osCommerce Links

osCommerce Templates

osCommerce UK <-- This site is for sale!

Share this post


Link to post
Share on other sites

In typical style, I fixed the problem literally about 2 mins after posting here :x

 

I had made the changes in boxes.php to the equivalent file: catalog/includes/classes/thema_boxes.php

 

But I had forgotten that there is also a thema_boxes.php file for each theme so all I had to do was make the same mod to:

 

catalog/includes/classes/thema/1/thema_boxes.php

 

doh!


tobz

 

osCommerce Links

osCommerce Templates

osCommerce UK <-- This site is for sale!

Share this post


Link to post
Share on other sites

had made the changes in:

catalog/advanced_search_result.php

catalog/default.php

catalog/includes/classes/boxes.php

catalog/includes/functions/general.php

catalog/includes/modules/product_listing.php,

run the sql queries....but it dont work :-(

 

there a no descriptions in the porduct list.

 

http://www.perfect-bikes.de/catalog/default.php

 

thx martin

Share this post


Link to post
Share on other sites

I installed oscommerce-2.2ms1. It's still standard and first I tried to install product description but doesn't work!

Did some troubleshooting:

1 - with advanced search it works perfectly

2 - when click on catagory get blank screen

3 - clicking on product get blanc screen

 

I modified everything with BC and I think problem lies in general.php, because when I replace modified-general with deafult-general I get normal result when clicking on catagories or products.

 

As you can see I'm desperate and looking for answers!

 

Here' my general.php:

<?php

/*

$Id: general.php,v 1.188 2002/08/13 18:49:07 dgw_ Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Public License

*/

 

////

// Stop from parsing any further PHP code

function tep_exit() {

tep_session_close();

exit();

}

 

////

// Redirect to another page or site

function tep_redirect($url) {

header('Location: ' . $url);

tep_exit();

}

 

////

// Error message wrapper

// When optional parameters are provided, it closes the application

// (ie, halts the current application execution task)

function tep_error_message($error_message, $close_application = false, $close_application_error = '') {

echo $error_message;

 

if ($close_application) {

die($close_application_error);

}

}

 

////

// Return a random row from a database query

function tep_random_select($query) {

srand((double)microtime()*1000000); // seed the random number generator

$random_product = '';

$random_query = tep_db_query($query);

$num_rows = tep_db_num_rows($random_query);

if ($num_rows > 0) {

$random_row = @rand(0, ($num_rows - 1));

tep_db_data_seek($random_query, $random_row);

$random_product = tep_db_fetch_array($random_query);

}

return $random_product;

}

 

////

// Return a product's name

// TABLES: products

function tep_get_products_name($product_id) {

global $languages_id;

 

$product_query = tep_db_query("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . $product_id . "' and language_id = '" . $languages_id . "'");

$product = tep_db_fetch_array($product_query);

 

return $product['products_name'];

}

 

////

// Return a product's special price (returns nothing if there is no offer)

// TABLES: products

function tep_get_products_special_price($product_id) {

$product_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $product_id . "' and status");

$product = tep_db_fetch_array($product_query);

 

return $product['specials_new_products_price'];

}

 

////

// Return a product's stock

// TABLES: products

function tep_get_products_stock($products_id) {

$products_id = tep_get_prid($products_id);

$stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'");

$stock_values = tep_db_fetch_array($stock_query);

return $stock_values['products_quantity'];

}

 

////

// Check if the required stock is available

// If insufficent stock is available return an out of stock message

function tep_check_stock($products_id, $products_quantity) {

$stock_left = tep_get_products_stock($products_id) - $products_quantity;

$out_of_stock = '';

if ($stock_left < 0) {

$out_of_stock = '<span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>';

}

return $out_of_stock;

}

 

////

// Break a word in a string if it is longer than a specified length ($len)

function tep_break_string($string, $len, $break_char = '-') {

$l = 0;

$output = '';

for ($i=0; $i<strlen($string); $i++) {

$char = substr($string, $i, 1);

if ($char != ' ') {

$l++;

} else {

$l = 0;

}

if ($l > $len) {

$l = 1;

$output .= $break_char;

}

$output .= $char;

}

 

return $output;

}

 

////

// Return all HTTP GET variables, except those passed as a parameter

function tep_get_all_get_params($exclude_array = '') {

global $HTTP_GET_VARS;

 

if ($exclude_array == '') $exclude_array = array();

 

$get_url = '';

if (is_array($HTTP_GET_VARS)) {

reset($HTTP_GET_VARS);

while (list($key, $value) = each($HTTP_GET_VARS)) {

if ((strlen($value) > 0) && ($key != session_name()) && ($key != 'error') && (!in_array($key, $exclude_array))) {

$get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';

}

}

}

return $get_url;

}

 

////

// Returns an array with countries

// TABLES: countries

function tep_get_countries($countries_id = '', $with_iso_codes = false) {

$countries_array = array();

if ($countries_id) {

if ($with_iso_codes) {

$countries = tep_db_query("select countries_name, countries_iso_code_2, countries_iso_code_3 from " . TABLE_COUNTRIES . " where countries_id = '" . $countries_id . "' order by countries_name");

$countries_values = tep_db_fetch_array($countries);

$countries_array = array('countries_name' => $countries_values['countries_name'],

'countries_iso_code_2' => $countries_values['countries_iso_code_2'],

'countries_iso_code_3' => $countries_values['countries_iso_code_3']);

} else {

$countries = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . $countries_id . "'");

$countries_values = tep_db_fetch_array($countries);

$countries_array = array('countries_name' => $countries_values['countries_name']);

}

} else {

$countries = tep_db_query("select countries_id, countries_name from " . TABLE_COUNTRIES . " order by countries_name");

while ($countries_values = tep_db_fetch_array($countries)) {

$countries_array[] = array('countries_id' => $countries_values['countries_id'],

'countries_name' => $countries_values['countries_name']);

}

}

 

return $countries_array;

}

 

////

// Alias function to tep_get_countries, which also returns the countries iso codes

function tep_get_countries_with_iso_codes($countries_id) {

return tep_get_countries($countries_id, true);

}

 

////

// Generate a path to categories

function tep_get_path($current_category_id = '') {

global $cPath_array;

 

if ($current_category_id) {

if (sizeof($cPath_array) == 0) {

$cPath_new = $current_category_id;

} else {

$cPath_new = '';

$last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $cPath_array[(sizeof($cPath_array)-1)] . "'");

$last_category = tep_db_fetch_array($last_category_query);

$current_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $current_category_id . "'");

$current_category = tep_db_fetch_array($current_category_query);

if ($last_category['parent_id'] == $current_category['parent_id']) {

for ($i=0; $i<(sizeof($cPath_array)-1); $i++) {

$cPath_new .= '_' . $cPath_array[$i];

}

} else {

for ($i=0; $i<sizeof($cPath_array); $i++) {

$cPath_new .= '_' . $cPath_array[$i];

}

}

$cPath_new .= '_' . $current_category_id;

if (substr($cPath_new, 0, 1) == '_') {

$cPath_new = substr($cPath_new, 1);

}

}

} else {

$cPath_new = implode('_', $cPath_array);

}

 

return 'cPath=' . $cPath_new;

}

 

////

// Returns the clients browser

function tep_browser_detect($component) {

global $HTTP_USER_AGENT;

 

$result = stristr($HTTP_USER_AGENT, $component);

 

return $result;

}

 

////

// Alias function to tep_get_countries()

function tep_get_country_name($country_id) {

$country_array = tep_get_countries($country_id);

 

return $country_array['countries_name'];

}

 

////

// Returns the zone (State/Province) name

// TABLES: zones

function tep_get_zone_name($country_id, $zone_id, $default_zone) {

$zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $country_id . "' and zone_id = '" . $zone_id . "'");

if (tep_db_num_rows($zone_query)) {

$zone = tep_db_fetch_array($zone_query);

return $zone['zone_name'];

} else {

return $default_zone;

}

}

 

////

// Returns the zone (State/Province) code

// TABLES: zones

function tep_get_zone_code($country_id, $zone_id, $default_zone) {

$zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_country_id = '" . $country_id . "' and zone_id = '" . $zone_id . "'");

if (tep_db_num_rows($zone_query)) {

$zone = tep_db_fetch_array($zone_query);

return $zone['zone_code'];

} else {

return $default_zone;

}

}

 

////

// Wrapper function for round() for php3 compatibility

function tep_round($value, $precision) {

if (PHP_VERSION < 4) {

$exp = pow(10, $precision);

return round($value * $exp) / $exp;

} else {

return round($value, $precision);

}

}

 

////

// Returns the tax rate for a zone / class

// TABLES: tax_rates, zones_to_geo_zones

function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {

global $customer_zone_id, $customer_country_id;

 

if ( ($country_id == -1) && ($zone_id == -1) ) {

if (!tep_session_is_registered('customer_id')) {

$country_id = STORE_COUNTRY;

$zone_id = STORE_ZONE;

} else {

$country_id = $customer_country_id;

$zone_id = $customer_zone_id;

}

}

 

$tax_query = tep_db_query("select SUM(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za ON tr.tax_zone_id = za.geo_zone_id left join " . TABLE_GEO_ZONES . " tz ON tz.geo_zone_id = tr.tax_zone_id WHERE (za.zone_country_id IS NULL OR za.zone_country_id = '0' OR za.zone_country_id = '" . $country_id . "') AND (za.zone_id IS NULL OR za.zone_id = '0' OR za.zone_id = '" . $zone_id . "') AND tr.tax_class_id = '" . $class_id . "' GROUP BY tr.tax_priority");

if (tep_db_num_rows($tax_query)) {

$tax_multiplier = 0;

while ($tax = tep_db_fetch_array($tax_query)) {

$tax_multiplier += $tax['tax_rate'];

}

return $tax_multiplier;

} else {

return 0;

}

}

 

////

// Return the tax description for a zone / class

// TABLES: tax_rates;

function tep_get_tax_description($zone_id, $class_id) {

$tax_query = tep_db_query("select tax_description from " . TABLE_TAX_RATES . " where tax_zone_id = '" . $zone_id . "' and tax_class_id = '" . $class_id . "'");

if (tep_db_num_rows($tax_query)) {

$tax = tep_db_fetch_array($tax_query);

return $tax['tax_description'];

} else {

return TEXT_UNKNOWN_TAX_RATE;

}

}

 

////

// Add tax to a products price

function tep_add_tax($price, $tax) {

global $currencies;

 

if (DISPLAY_PRICE_WITH_TAX == true) {

return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + tep_calculate_tax($price, $tax);

} else {

return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);

}

}

 

// Calculates Tax rounding the result

function tep_calculate_tax($price, $tax) {

global $currencies;

 

return tep_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);

}

 

////

// Return the number of products in a category

// TABLES: products, products_to_categories, categories

function tep_count_products_in_category($category_id, $include_inactive = false) {

$products_count = 0;

if ($include_inactive) {

$products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . $category_id . "'");

} else {

$products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = 1 and p2c.categories_id = '" . $category_id . "'");

}

$products = tep_db_fetch_array($products_query);

$products_count += $products['total'];

 

if (USE_RECURSIVE_COUNT == 'true') {

$child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . "'");

if (tep_db_num_rows($child_categories_query)) {

while ($child_categories = tep_db_fetch_array($child_categories_query)) {

$products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive);

}

}

}

 

return $products_count;

}

 

////

// Return true if the category has subcategories

// TABLES: categories

function tep_has_category_subcategories($category_id) {

$child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . "'");

$child_category = tep_db_fetch_array($child_category_query);

 

if ($child_category['count'] > 0) {

return true;

} else {

return false;

}

}

 

////

// Returns the address_format_id for the given country

// TABLES: countries;

function tep_get_address_format_id($country_id) {

$address_format_query = tep_db_query("select address_format_id as format_id from " . TABLE_COUNTRIES . " where countries_id = '" . $country_id . "'");

if (tep_db_num_rows($address_format_query)) {

$address_format = tep_db_fetch_array($address_format_query);

return $address_format['format_id'];

} else {

return '1';

}

}

 

////

// Return a formatted address

// TABLES: address_format

function tep_address_format($address_format_id, $address, $html, $boln, $eoln) {

$address_format_query = tep_db_query("select address_format as format from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . $address_format_id . "'");

$address_format = tep_db_fetch_array($address_format_query);

 

$firstname = addslashes($address['firstname']);

$lastname = addslashes($address['lastname']);

$street = addslashes($address['street_address']);

$suburb = addslashes($address['suburb']);

$city = addslashes($address['city']);

$state = addslashes($address['state']);

$country_id = $address['country_id'];

$zone_id = $address['zone_id'];

$postcode = addslashes($address['postcode']);

$zip = $postcode;

$country = tep_get_country_name($country_id);

$state = tep_get_zone_code($country_id, $zone_id, $state);

 

if ($html) {

// HTML Mode

$HR = '<hr>';

$hr = '<hr>';

if ( ($boln == '') && ($eoln == "n") ) { // Values not specified, use rational defaults

$CR = '<br>';

$cr = '<br>';

$eoln = $cr;

} else { // Use values supplied

$CR = $eoln . $boln;

$cr = $CR;

}

} else {

// Text Mode

$CR = $eoln;

$cr = $CR;

$HR = '----------------------------------------';

$hr = '----------------------------------------';

}

 

$statecomma = '';

$streets = $street;

if ($suburb != '') $streets = $street . $cr . $suburb;

if ($firstname == '') $firstname = addslashes($address['name']);

if ($country == '') $country = addslashes($address['country']);

if ($state != '') $statecomma = $state . ', ';

 

$fmt = $address_format['format'];

eval("$address = "$fmt";");

$address = stripslashes($address);

 

return $boln . $address . $eoln;

}

 

////

// Return a formatted address

// TABLES: customers, address_book

function tep_address_label($customers_id, $address_id = 1, $html = false, $boln = '', $eoln = "n") {

$address_query = tep_db_query("select entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . $customers_id . "' and address_book_id = '" . $address_id . "'");

$address = tep_db_fetch_array($address_query);

$format_id = tep_get_address_format_id($address['country_id']);

return tep_address_format($format_id, $address, $html, $boln, $eoln);

}

 

////

// Return a formatted address

// TABLES: address_book, address_format

function tep_address_summary($customers_id, $address_id) {

$customers_id = tep_db_prepare_input($customers_id);

$address_id = tep_db_prepare_input($address_id);

 

$address_query = tep_db_query("select ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_state, ab.entry_country_id, ab.entry_zone_id, c.countries_name, c.address_format_id from " . TABLE_ADDRESS_BOOK . " ab, " . TABLE_COUNTRIES . " c where ab.address_book_id = '" . tep_db_input($address_id) . "' and ab.customers_id = '" . tep_db_input($customers_id) . "' and ab.entry_country_id = c.countries_id");

$address = tep_db_fetch_array($address_query);

 

$street_address = $address['entry_street_address'];

$suburb = $address['entry_suburb'];

$postcode = $address['entry_postcode'];

$city = $address['entry_city'];

$state = tep_get_zone_code($address['entry_country_id'], $address['entry_zone_id'], $address['entry_state']);

$country = $address['countries_name'];

 

$address_format_query = tep_db_query("select address_summary from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . $address['address_format_id'] . "'");

$address_format = tep_db_fetch_array($address_format_query);

 

// eval("$address = "{$address_format['address_summary']}";");

$address_summary = $address_format['address_summary'];

eval("$address = "$address_summary";");

 

return $address;

}

 

function tep_row_number_format($number) {

if ( ($number < 10) && (substr($number, 0, 1) != '0') ) $number = '0' . $number;

 

return $number;

}

 

function tep_get_categories($categories_array = '', $parent_id = '0', $indent = '') {

global $languages_id;

 

$parent_id = tep_db_prepare_input($parent_id);

 

if (!is_array($categories_array)) $categories_array = array();

 

$categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . tep_db_input($parent_id) . "' and c.categories_id = cd.categories_id and cd.language_id = '" . $languages_id . "' order by sort_order, cd.categories_name");

while ($categories = tep_db_fetch_array($categories_query)) {

$categories_array[] = array('id' => $categories['categories_id'],

'text' => $indent . $categories['categories_name']);

 

if ($categories['categories_id'] != $parent_id) {

$categories_array = tep_get_categories($categories_array, $categories['categories_id'], $indent . '  ');

}

}

 

return $categories_array;

}

 

function tep_get_manufacturers($manufacturers_array = '') {

if (!is_array($manufacturers_array)) $manufacturers_array = array();

 

$manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {

$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'], 'text' => $manufacturers['manufacturers_name']);

}

 

return $manufacturers_array;

}

 

////

// Return all subcategory IDs

// TABLES: categories

function tep_get_subcategories(&$subcategories_array, $parent_id = 0) {

$subcategories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . $parent_id . "'");

while ($subcategories = tep_db_fetch_array($subcategories_query)) {

$subcategories_array[sizeof($subcategories_array)] = $subcategories['categories_id'];

if ($subcategories['categories_id'] != $parent_id) {

tep_get_subcategories($subcategories_array, $subcategories['categories_id']);

}

}

}

 

// Output a raw date string in the selected locale date format

// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS

function tep_date_long($raw_date) {

if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;

 

$year = (int)substr($raw_date, 0, 4);

$month = (int)substr($raw_date, 5, 2);

$day = (int)substr($raw_date, 8, 2);

$hour = (int)substr($raw_date, 11, 2);

$minute = (int)substr($raw_date, 14, 2);

$second = (int)substr($raw_date, 17, 2);

 

return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year));

}

 

////

// Output a raw date string in the selected locale date format

// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS

// NOTE: Includes a workaround for dates before 01/01/1970 that fail on windows servers

function tep_date_short($raw_date) {

if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;

 

$year = substr($raw_date, 0, 4);

$month = (int)substr($raw_date, 5, 2);

$day = (int)substr($raw_date, 8, 2);

$hour = (int)substr($raw_date, 11, 2);

$minute = (int)substr($raw_date, 14, 2);

$second = (int)substr($raw_date, 17, 2);

 

if (ereg('WIN', PHP_OS) && $year <= 1970) {

return ereg_replace('2037' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)));

} else {

return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year));

}

}

 

////

// Parse search string into indivual objects

function tep_parse_search_string($search_str = '', &$objects) {

$search_str = trim(strtolower($search_str));

 

// Break up $search_str on whitespace; quoted string will be reconstructed later

$pieces = split('[[:space:]]+', $search_str);

 

$objects = array();

$tmpstring = '';

$flag = '';

 

for ($k=0; $k<count($pieces); $k++) {

while (substr($pieces[$k], 0, 1) == '(') {

$objects[] = '(';

if (strlen($pieces[$k]) > 1) {

$pieces[$k] = substr($pieces[$k], 1);

} else {

$pieces[$k] = '';

}

}

 

$post_objects = array();

 

while (substr($pieces[$k], -1) == ')') {

$post_objects[] = ')';

if (strlen($pieces[$k]) > 1) {

$pieces[$k] = substr($pieces[$k], 0, -1);

} else {

$pieces[$k] = '';

}

}

 

// Check individual words

 

if ( (substr($pieces[$k], -1) != '"') && (substr($pieces[$k], 0, 1) != '"') ) {

$objects[] = trim($pieces[$k]);

 

for ($j=0; $j<count($post_objects); $j++) {

$objects[] = $post_objects[$j];

}

} else {

/* This means that the $piece is either the beginning or the end of a string.

So, we'll slurp up the $pieces and stick them together until we get to the

end of the string or run out of pieces.

*/

 

// Make sure the $tmpstring is empty

$tmpstring = '';

 

// Add this word to the $tmpstring, starting the $tmpstring

 

$tmpstring .= trim(ereg_replace('"', ' ', $pieces[$k]));

 

// Check for one possible exception to the rule. That there is a single quoted word.

if (substr($pieces[$k], -1 ) == '"') {

// Turn the flag off for future iterations

$flag = 'off';

 

$objects[] = trim($pieces[$k]);

 

for ($j=0; $j<count($post_objects); $j++) {

$objects[] = $post_objects[$j];

}

 

unset($tmpstring);

 

// Stop looking for the end of the string and move onto the next word.

continue;

}

 

// Otherwise, turn on the flag to indicate no quotes have been found attached to this word in the string.

$flag = 'on';

 

// Move on to the next word

$k++;

 

// Keep reading until the end of the string as long as the $flag is on

 

while ( ($flag == 'on') && ($k < count($pieces)) ) {

while (substr($pieces[$k], -1) == ')') {

$post_objects[] = ')';

if (strlen($pieces[$k]) > 1) {

$pieces[$k] = substr($pieces[$k], 0, -1);

} else {

$pieces[$k] = '';

}

}

 

// If the word doesn't end in double quotes, append it to the $tmpstring.

if (substr($pieces[$k], -1) != '"') {

// Tack this word onto the current string entity

$tmpstring .= ' ' . $pieces[$k];

 

// Move on to the next word

$k++;

continue;

} else {

/* If the $piece ends in double quotes, strip the double quotes, tack the

$piece onto the tail of the string, push the $tmpstring onto the $haves,

kill the $tmpstring, turn the $flag "off", and return.

*/

$tmpstring .= ' ' . trim(ereg_replace('"', ' ', $pieces[$k]));

 

// Push the $tmpstring onto the array of stuff to search for

$objects[] = trim($tmpstring);

 

for ($j=0; $j<count($post_objects); $j++) {

$objects[] = $post_objects[$j];

}

 

unset($tmpstring);

 

// Turn off the flag to exit the loop

$flag = 'off';

}

}

}

}

 

// add default logical operators if needed

$temp = array();

for($i=0; $i<(count($objects)-1); $i++) {

$temp[sizeof($temp)] = $objects[$i];

 

if ( ($objects[$i] != 'and') &&

($objects[$i] != 'or') &&

($objects[$i] != '(') &&

($objects[$i] != ')') &&

($objects[$i+1] != 'and') &&

($objects[$i+1] != 'or') &&

($objects[$i+1] != '(') &&

($objects[$i+1] != ')') ) {

$temp[sizeof($temp)] = ADVANCED_SEARCH_DEFAULT_OPERATOR;

}

}

$temp[sizeof($temp)] = $objects[$i];

$objects = $temp;

 

$keyword_count = 0;

$operator_count = 0;

for($i=0; $i<count($objects); $i++) {

if ( ($objects[$i] == 'and') || ($objects[$i] == 'or') ) {

$operator_count ++;

} elseif ( ($objects[$i]) && ($objects[$i] != '(') && ($objects[$i] != ')') ) {

$keyword_count ++;

}

}

 

if ($operator_count < $keyword_count) {

return true;

} else {

return false;

}

}

 

////

// Check date

function tep_checkdate($date_to_check, $format_string, &$date_array) {

$separator_idx = -1;

 

$separators = array('-', ' ', '/', '.');

$month_abbr = array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');

$no_of_days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

 

$format_string = strtolower($format_string);

 

if (strlen($date_to_check) != strlen($format_string)) {

return false;

}

 

for ($i=0; $i<sizeof($separators); $i++) {

$pos_separator = strpos($date_to_check, $separators[$i]);

if ($pos_separator != false) {

$date_separator_idx = $i;

break;

}

}

 

for ($i=0; $i<sizeof($separators); $i++) {

$pos_separator = strpos($format_string, $separators[$i]);

if ($pos_separator != false) {

$format_separator_idx = $i;

break;

}

}

 

if ($date_separator_idx != $format_separator_idx) {

return false;

}

 

if ($date_separator_idx != -1) {

$format_string_array = explode( $separators[$date_separator_idx], $format_string );

if (sizeof($format_string_array) != 3) {

return false;

}

 

$date_to_check_array = explode( $separators[$date_separator_idx], $date_to_check );

if (sizeof($date_to_check_array) != 3) {

return false;

}

 

for ($i=0; $i<sizeof($format_string_array); $i++) {

if ($format_string_array[$i] == 'mm' || $format_string_array[$i] == 'mmm') $month = $date_to_check_array[$i];

if ($format_string_array[$i] == 'dd') $day = $date_to_check_array[$i];

if ( ($format_string_array[$i] == 'yyyy') || ($format_string_array[$i] == 'aaaa') ) $year = $date_to_check_array[$i];

}

} else {

if (strlen($format_string) == 8 || strlen($format_string) == 9) {

$pos_month = strpos($format_string, 'mmm');

if ($pos_month != false) {

$month = substr( $date_to_check, $pos_month, 3 );

for ($i=0; $i<sizeof($month_abbr); $i++) {

if ($month == $month_abbr[$i]) {

$month = $i;

break;

}

}

} else {

$month = substr($date_to_check, strpos($format_string, 'mm'), 2);

}

} else {

return false;

}

 

$day = substr($date_to_check, strpos($format_string, 'dd'), 2);

$year = substr($date_to_check, strpos($format_string, 'yyyy'), 4);

}

 

if (strlen($year) != 4) {

return false;

}

 

if (!settype($year, 'integer') || !settype($month, 'integer') || !settype($day, 'integer')) {

return false;

}

 

if ($month > 12 || $month < 1) {

return false;

}

 

if ($day < 1) {

return false;

}

 

if (tep_is_leap_year($year)) {

$no_of_days[1] = 29;

}

 

if ($day > $no_of_days[$month - 1]) {

return false;

}

 

$date_array = array($year, $month, $day);

 

return true;

}

 

////

// Check if year is a leap year

function tep_is_leap_year($year) {

if ($year % 100 == 0) {

if ($year % 400 == 0) return true;

} else {

if (($year % 4) == 0) return true;

}

 

return false;

}

 

////

// Return table heading with sorting capabilities

function tep_create_sort_heading($sortby, $colnum, $heading) {

global $PHP_SELF;

 

$sort_prefix = '';

$sort_suffix = '';

 

if ($sortby) {

$sort_prefix = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('page', 'info', 'x', 'y', 'sort')) . 'page=1&sort=' . $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a'), 'NONSSL') . '" title="' . TEXT_SORT_PRODUCTS . ($sortby == $colnum . 'd' || substr($sortby, 0, 1) != $colnum ? TEXT_ASCENDINGLY : TEXT_DESCENDINGLY) . TEXT_BY . $heading . '">' ;

$sort_suffix = (substr($sortby, 0, 1) == $colnum ? (substr($sortby, 1, 1) == 'a' ? '+' : '-') : '') . '</a>';

}

 

return $sort_prefix . $heading . $sort_suffix;

}

 

////

// Recursively go through the categories and retreive all parent categories IDs

// TABLES: categories

function tep_get_parent_categories(&$categories, $categories_id) {

$parent_categories_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $categories_id . "'");

while ($parent_categories = tep_db_fetch_array($parent_categories_query)) {

if ($parent_categories['parent_id'] == 0) return true;

$categories[sizeof($categories)] = $parent_categories['parent_id'];

if ($parent_categories['parent_id'] != $categories_id) {

tep_get_parent_categories($categories, $parent_categories['parent_id']);

}

}

}

 

////

// Construct a category path to the product

// TABLES: products_to_categories

function tep_get_product_path($products_id) {

$cPath = '';

 

$cat_count_sql = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $products_id . "'");

$cat_count_data = tep_db_fetch_array($cat_count_sql);

 

if ($cat_count_data['count'] == 1) {

$categories = array();

 

$cat_id_sql = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $products_id . "'");

$cat_id_data = tep_db_fetch_array($cat_id_sql);

tep_get_parent_categories($categories, $cat_id_data['categories_id']);

 

for ($i=sizeof($categories)-1; $i>=0; $i--) {

if ($cPath != '') $cPath .= '_';

$cPath .= $categories[$i];

}

if ($cPath != '') $cPath .= '_';

$cPath .= $cat_id_data['categories_id'];

}

 

return $cPath;

}

 

////

// Return a product ID with attributes

function tep_get_uprid($prid, $params) {

$uprid = $prid;

if ( (is_array($params)) && (!strstr($prid, '{')) ) {

while (list($option, $value) = each($params)) {

$uprid = $uprid . '{' . $option . '}' . $value;

}

}

 

return $uprid;

}

 

////

// Return a product ID from a product ID with attributes

function tep_get_prid($uprid) {

$pieces = split('[{]', $uprid, 2);

 

return $pieces[0];

}

 

////

// Return a customer greeting

function tep_customer_greeting() {

global $HTTP_COOKIE_VARS, $customer_id, $customer_first_name;

 

if ($HTTP_COOKIE_VARS['first_name']) {

$first_name = stripslashes($HTTP_COOKIE_VARS['first_name']);

} elseif ($customer_first_name) {

$first_name = $customer_first_name;

}

 

if ($first_name) {

$greeting_string = sprintf(TEXT_GREETING_PERSONAL, $first_name, tep_href_link(FILENAME_PRODUCTS_NEW, '', 'NONSSL'));

if (!$customer_id) {

$greeting_string .= '<br>' . sprintf(TEXT_GREETING_PERSONAL_RELOGON, $first_name, tep_href_link(FILENAME_LOGIN, '', 'SSL'));

}

} else {

$greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));

}

 

return $greeting_string;

}

 

////

//! Send email (text/html) using MIME

// This is the central mail function. The SMTP Server should be configured

// correct in php.ini

// Parameters:

// $to_name The name of the recipient, e.g. "Jan Wildeboer"

// $to_email_address The eMail address of the recipient,

// e.g. jan.wildeboer@gmx.de

// $email_subject The subject of the eMail

// $email_text The text of the eMail, may contain HTML entities

// $from_email_name The name of the sender, e.g. Shop Administration

// $from_email_adress The eMail address of the sender,

// e.g. info@mytepshop.com

 

function tep_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {

if (SEND_EMAILS != 'true') return false;

 

// Instantiate a new mail object

$message = new email(array('X-Mailer: osC mailer'));

 

// Build the text version

$text = strip_tags($email_text);

if (EMAIL_USE_HTML == 'true') {

$message->add_html($email_text, $text);

} else {

$message->add_text($text);

}

 

// Send message

$message->build_message();

$message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);

}

 

////

// Check if product has attributes

function tep_has_product_attributes($products_id) {

$attributes_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $products_id . "'");

$attributes = tep_db_fetch_array($attributes_query);

 

if ($attributes['count'] > 0) {

return true;

} else {

return false;

}

}

 

////

// Get the number of times a word/character is present in a string

function tep_word_count($string, $needle) {

$temp_array = split($needle, $string);

return sizeof($temp_array);

}

 

function tep_count_modules($modules = '') {

if (!$modules) return '0';

 

$modules_array = split(';', $modules);

 

return sizeof($modules_array);

}

 

function tep_count_payment_modules() {

return tep_count_modules(MODULE_PAYMENT_INSTALLED);

}

 

function tep_count_shipping_modules() {

return tep_count_modules(MODULE_SHIPPING_INSTALLED);

}

 

function tep_create_random_value($length, $type = 'mixed') {

if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false;

 

$rand_value = '';

mt_srand((double) microtime() * 1000000);

while (strlen($rand_value)<$length) {

if ($type == 'digits') {

$char = mt_rand(0,9);

} else {

$char = chr(mt_rand(0,255));

}

if ($type == 'mixed') {

if (eregi('^[a-z0-9]$', $char)) $rand_value .= $char;

} elseif ($type == 'chars') {

if (eregi('^[a-z]$', $char)) $rand_value .= $char;

} elseif ($type == 'digits') {

if (ereg('^[0-9]$', $char)) $rand_value .= $char;

}

}

 

return $rand_value;

}

 

function tep_output_warning($warning) {

new errorBox(array(array('text' => tep_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . ' ' . $warning)));

}

 

function tep_array_to_string($array, $exclude = '', $equals = '=', $separator = '&') {

if ($exclude == '') $exclude = array();

 

$get_string = '';

if (sizeof($array) > 0) {

while (list($key, $value) = each($array)) {

if ( (!in_array($key, $exclude)) && ($key != 'x') && ($key != 'y') ) {

$get_string .= $key . $equals . $value . $separator;

}

}

$remove_chars = strlen($separator);

$get_string = substr($get_string, 0, -$remove_chars);

}

 

return $get_string;

}

 

function tep_not_null($value) {

if (is_array($value)) {

if (sizeof($value) > 0) {

return true;

} else {

return false;

}

} else {

if (($value != '') && ($value != 'NULL') && (strlen(trim($value)) > 0)) {

return true;

} else {

return false;

}

}

}

 

////

// Output the tax percentage with optional padded decimals

function tep_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) {

if (strpos($value, '.')) {

$loop = true;

while ($loop) {

if (substr($value, -1) == '0') {

$value = substr($value, 0, -1);

} else {

$loop = false;

if (substr($value, -1) == '.') {

$value = substr($value, 0, -1);

}

}

}

}

 

if ($padding > 0) {

if ($decimal_pos = strpos($value, '.')) {

$decimals = strlen(substr($value, ($decimal_pos+1)));

for ($i=$decimals; $i<$padding; $i++) {

$value .= '0';

}

} else {

$value .= '.';

for ($i=0; $i<$padding; $i++) {

$value .= '0';

}

}

}

 

return $value;

}

 

////

// Checks to see if the currency code exists as a currency

// TABLES: currencies

function tep_currency_exists($code) {

$currency_code = tep_db_query("select currencies_id from " . TABLE_CURRENCIES . " where code = '" . $code . "'");

if (tep_db_num_rows($currency_code)) {

return $code;

} else {

return false;

}

}

 

function tep_string_to_int($string) {

return (int)$string;

}

 

////

// Products Description Hack begins

//

// grabs a length from a string, but goes back to the last space if it cut into

// the middle of a string. If the string is longer than that, cut, then add '...'

// to the end of the string, if the $more == 1

function osc_trunc_string($str="",$len=150,$more=1)

{

if ($str=="") return $str;

if (is_array($str)) return $str;

$str = trim($str);

// if it's les than the size given, then return it

if (strlen($str) <= $len) return $str;

// else get that size of text

$str = substr($str,0,$len);

// backtrack to the end of a word

if ($str != "") {

// check to see if there are any spaces left

if (!substr_count($str," ")) {

if ($more) $str .= "...";

return $str;

}

// backtrack

while(strlen($str) && ($str[strlen($str)-1] != " ")) {

$str = substr($str,0,-1);

}

$str = substr($str,0,-1);

if ($more) $str .= "...";

}

return $str;

}

// Products Description Hack ends

?>

Share this post


Link to post
Share on other sites

Is there way to put an out of stock message in product listing depending on the product's status?

Share this post


Link to post
Share on other sites

Got latest Snap,

 

Virgin snap with no other mods, and trying to install this.

 

Went and changed files using Beyond compare.

 

I think my problem lies in with product_listing.php file.

 

I have 1.41 version of above file, and can not get the description to show.

Anybody has 1.41 file with this already installed?

 

If so kindly post here.

 

Thx

Share this post


Link to post
Share on other sites

I just installed this contrib...evrything went very well except I forgot about the thema contrib I'm using.

 

So it's all working nicely, There's just one thing...I think it would look nicer if the description was placed in the same table cell as the product name.

 

Would that be difficult :?: I hope not :!:


Mary

Share this post


Link to post
Share on other sites

:) HI

Does anyone know if this works on oscommerce-2.2ms2 ???


I will proberly be baldheaded after riping my hear of

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×