Community Add-Ons

Maintainers: chrish123
Add file to this package
Top » Features

Auto Rename Product Names in Proper Case
for osCommerce Online Merchant v2.2

Download
by chrish123 / 31 Oct 2010

Automatically rename a products name to look neat using Proper Case with exception keywords to avoid "and" becoming "And" and "a" becoming "A" etc, simple 2 step install.

I sometimes swear I have OCD and hate untidyness and like automation, and seeing an image named as for instance "fred the ferrari wheel of fortune in red" looks really unprofessional and also not tidy.

This mod will save the text in the database as "Fred the Ferrari Wheel of Fortune in Red"


Add your own exception keywords to filter by adding to the exception words array easily


First open admin/functions/general.php and att the end before the closing ?> ADD:

//// function to rename product names!
function ucwords_cus($string, $array="empty"){
if (!is_array($array) && $array != "empty") $array = "off";
if ($array == "empty") { //default array with exception words:
$array = array();
$array[0] = "the";
$array[1] = "with";
$array[2] = "by";
$array[3] = "among";
$array[4] = "and";
$array[5] = "or";
$array[6] = "a";
$array[7] = "in";
}
$words = explode(" ", $string);
$tel = 0;
$add = "";
foreach ($words as $word){
if ($tel != 0) $add = " ";
//check if first letter of word is uppercase:
$firstletter = substr($word,0,1);
$firstletter_lowercase = strtolower($firstletter);
if ($firstletter != $firstletter_lowercase) {
$first = "uppercase";
} else $first = "lowercase";
//check if second letter of word is uppercase:
$secondletter = substr($word,1,1);
$secondletter_lowercase = strtolower($firstletter);
if ($secondletter != $secondletter_lowercase) {
$second = "uppercase";
} else $second = "lowercase";
//check if first two letters both are uppercase:
if ($first == "uppercase" && $second == "uppercase"){
//check if the word is one of the exception words:
$res = false;
if ($array != "off" && $tel != 0){ //only used excepted words filtering if no 0 was passed as second argument:
foreach ($array as $resword){
if (strtolower($word) == strtolower($resword)) $res = true;
}
}
if ($res){ //an exception word: convert to lowercase only:
$word = strtolower($word);
} else { //first convert entire word to lowercase, then capitalize first letter with ucfirst():
$word = ucfirst(strtolower($word));
}
}
$filtered .= $add.$word;
$tel = 1;
}
return $filtered;
}
//// end of function to rename product images

###################################################################

Next open admin/categories, find around line 300 somewhere before the code that reads if ($action == 'insert_product') {:

$languages = tep_get_languages();
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
$language_id = $languages[$i]['id'];

$sql_data_array = array('products_name' => tep_db_prepare_input($HTTP_POST_VARS['products_name'][$language_id]),


CHANGE TO:

$languages = tep_get_languages();
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
$language_id = $languages[$i]['id'];

$sql_data_array = array('products_name' => tep_db_prepare_input(ucwords_cus($HTTP_POST_VARS['products_name'][$language_id])),

Done, now add a product, save and look at how its neatly renaming products!

Zip contains same info!

Legend:  Download   Report

Expand All / Collapse All

Auto Rename Product Names in Proper Case chrish123 31 Oct 2010  

Automatically rename a products name to look neat using Proper Case with exception keywords to avoid "and" becoming "And" and "a" becoming "A" etc, simple 2 step install.

I sometimes swear I have OCD and hate untidyness and like automation, and seeing an image named as for instance "fred the ferrari wheel of fortune in red" looks really unprofessional and also not tidy.

This mod will save the text in the database as "Fred the Ferrari Wheel of Fortune in Red"


Add your own exception keywords to filter by adding to the exception words array easily


First open admin/functions/general.php and att the end before the closing ?> ADD:

//// function to rename product names!
function ucwords_cus($string, $array="empty"){
if (!is_array($array) && $array != "empty") $array = "off";
if ($array == "empty") { //default array with exception words:
$array = array();
$array[0] = "the";
$array[1] = "with";
$array[2] = "by";
$array[3] = "among";
$array[4] = "and";
$array[5] = "or";
$array[6] = "a";
$array[7] = "in";
}
$words = explode(" ", $string);
$tel = 0;
$add = "";
foreach ($words as $word){
if ($tel != 0) $add = " ";
//check if first letter of word is uppercase:
$firstletter = substr($word,0,1);
$firstletter_lowercase = strtolower($firstletter);
if ($firstletter != $firstletter_lowercase) {
$first = "uppercase";
} else $first = "lowercase";
//check if second letter of word is uppercase:
$secondletter = substr($word,1,1);
$secondletter_lowercase = strtolower($firstletter);
if ($secondletter != $secondletter_lowercase) {
$second = "uppercase";
} else $second = "lowercase";
//check if first two letters both are uppercase:
if ($first == "uppercase" && $second == "uppercase"){
//check if the word is one of the exception words:
$res = false;
if ($array != "off" && $tel != 0){ //only used excepted words filtering if no 0 was passed as second argument:
foreach ($array as $resword){
if (strtolower($word) == strtolower($resword)) $res = true;
}
}
if ($res){ //an exception word: convert to lowercase only:
$word = strtolower($word);
} else { //first convert entire word to lowercase, then capitalize first letter with ucfirst():
$word = ucfirst(strtolower($word));
}
}
$filtered .= $add.$word;
$tel = 1;
}
return $filtered;
}
//// end of function to rename product images

###################################################################

Next open admin/categories, find around line 300 somewhere before the code that reads if ($action == 'insert_product') {:

$languages = tep_get_languages();
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
$language_id = $languages[$i]['id'];

$sql_data_array = array('products_name' => tep_db_prepare_input($HTTP_POST_VARS['products_name'][$language_id]),


CHANGE TO:

$languages = tep_get_languages();
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
$language_id = $languages[$i]['id'];

$sql_data_array = array('products_name' => tep_db_prepare_input(ucwords_cus($HTTP_POST_VARS['products_name'][$language_id])),

Done, now add a product, save and look at how its neatly renaming products!

Zip contains same info!