You are here:  » Category Name / Brand Name Clean Up Function


Category Name / Brand Name Clean Up Function

Submitted by Confuscius on Mon, 2006-08-28 11:00 in

Hi David

I'm having great fun playing with the script and have successfully automatically pulled together a number of feeds from a variety of places. On reviewing the results of my efforts, I seem to be spending most of my time trying to sort out the general non consistency of the merchants! For example, let's say we have a Category called "Kitchen Gadgets" - probably in the feeds we would get "KITCHEN GADGETS" or "Kitchen Gadgets" or "Kitchen gadgets" or "Kitchen > Gadgets" or "kitchen gadgets" or etc! I know that I can play with mapping the category names but it strikes me that a little Category Name Data tidy up function could be very useful (akin to the decimalise prices kind of approach). I can happily write the tidy up rules but would welcome advice on the best way to approach this within the script files.

e.g. Take the category field, convert all words to lower case, replace > with a space, trim the spaces, capitalise the first letter of each word, pass back the answer prior to data import.

Clearly the same approach would apply to tidying up the brands.

Thanks in advance.

Paul

Submitted by support on Mon, 2006-08-28 11:07

Hi Paul,

What i'd do is; firstly create a new function called tapestry_categorise() or something like that in includes/tapestry.php, for example:

<?php
  
function tapestry_categorise($text)
  {
    
$text str_replace(">"," ",$text);
    
// more rules as required
    
return $text;
  }
?>

Then, in includes/admin.php, look for the section of code that checks for a category value (line 168) add a call to the new function immediately before the call to the normalise function within the curly brackets, giving you this:

<?php
    
if ($admin_importFeed["field_category"])
    {
      
$record[$admin_importFeed["field_category"]] = tapestry_categorise($record[$admin_importFeed["field_category"]]);
      
$record[$admin_importFeed["field_category"]] = tapestry_normalise($record[$admin_importFeed["field_category"]]);
    }
?>

Hope this helps!
David.

Submitted by Confuscius on Mon, 2006-08-28 11:59

In a word - brilliant! Anyways, my first simplistic bash at this is below and whenever I see something messed up in the category / Brand list then it is simply a case of tracking through to the offending feed finding what is actually in the feed and then going back to add a new rule if necessary - this little tweak has saved me hours of unnecessary work , many thanks.

<?php
  
function tapestry_tidy_category($text)
  {
    
$text str_replace("&amp;","and",$text);
    
$text str_replace("&lt;"," ",$text);
    
$text str_replace("&gt;"," ",$text);
    
$text str_replace("/"," ",$text);
    
$text str_replace(">"," ",$text);
    
$text str_replace("<"," ",$text);
    
$text str_replace(","," ",$text);
    
$text str_replace("     "," ",$text);
    
$text str_replace("    "," ",$text);
    
$text str_replace("   "," ",$text);
    
$text str_replace("  "," ",$text);
    
$text strtolower(trim($text));
    
$text ucwords($text);
    return 
$text;
  }
?>