You are here:  » Categories

Support Forum



Categories

Submitted by JasonG on Sun, 2011-08-14 17:56 in

I have named my categories and started mapping products and categories from various feeds, I have no realised the the category names I created need to be changed "removing one word" from those categories, how would I go about doing that, I don't want to delete them and start again if at all possible. Can't see a way in admion area, can it be done via the code?

Thanks
Stuart

Submitted by support on Mon, 2011-08-15 11:14

Hi Stuart,

It would be straight forward to do a bulk rename via a script; for example:

<?php
  header
("Content-Type: text/plain");
  require(
"includes/common.php");
  
$sql "SELECT id,name FROM `".$config_databaseTablePrefix."categories`";
  
database_querySelect($sql,$rows);
  foreach(
$rows as $row)
  {
    
$name $row["name"];
    
$name str_replace("Foo ","",$name);
    
$sql "UPDATE `".$config_databaseTablePrefix."categories`
              SET name='"
.database_safe($name)."' WHERE id='".$name."'";
    print 
$name."\n";
    
// database_queryModify($sql,$result);
  
}
  print 
"Done.";
?>

If the word is at the end or middle, it would be something like:

    $name = str_replace(" Bar","",$name);

(not the use of spaces as required to ensure that you don't end up with double spaces in the new name)

I would recommend backing up your Category Mapping with the Database Tool prior to running the above "just incase", but you'll notice that the database_queryModify line is commented out; so you can test the process without applying the changes first. Once you're happy the replacement is as you require remove the comment characters and run the script "for real"...

Cheers,
David.
--
PriceTapestry.com

Submitted by JasonG on Mon, 2011-08-15 12:09

Thanks David