Not sure if this has been asked for before, but...
It would be nice if there was a filter that could, for example, check the 'name' field and if it finds the word 'MP3' change the category to 'My MP3 CAtegory' (or whatever).
Got some big feeds that have really dumb categories with all sorts of stuff in them.
Maybe there already is, please feel free to laugh at me if I am being stoopid.
nice - thats a much better solution.
thanks very much, I'll try it tomorrow
========
Zugatrons Gifts and Gadgets
Hi David
I intend to use this script to pull out features from descriptions and populate a new field.
I have created a new field "spinspeed" in the PTproducts table, amended the above script to reflect the new field (see below):
<?php
set_time_limit(0);
require("includes/common.php");
// build up the $cats array with reqired category names and keywords
$cats["1000 RPM"] = array("1000");
$cats["1200 RPM"] = array("1200");
$cats["1400 RPM"] = array("1400");
$cats["1600 RPM"] = array("1600");
$cats["1800 RPM"] = array("1800");
$cats["2000 RPM"] = array("2000");
foreach($cats as $k => $v)
{
$keywords = array();
foreach($v as $keyword)
{
$keywords[] = "description LIKE '%".$keyword."%'"
}
$where = implode($keywords," OR ");
$sql = "UPDATE PTproducts SET spinspeed='".$k."' WHERE ".$where;
database_queryModify($sql,$result);
}
?>
However I get an error at line 17...
Parse error: syntax error, unexpected '}'
Is there something else that I should do since I simply added an additional field to the PTproducts table rather than using an existing field?
Regards
Richard
Hi Richard,
There is a ";" missing on line 16 that will be the cause of that error, but I also noticed that the parameters to the implode() function are the wrong way round - have a go with:
<?php
set_time_limit(0);
require("includes/common.php");
// build up the $cats array with reqired category names and keywords
$cats["1000 RPM"] = array("1000");
$cats["1200 RPM"] = array("1200");
$cats["1400 RPM"] = array("1400");
$cats["1600 RPM"] = array("1600");
$cats["1800 RPM"] = array("1800");
$cats["2000 RPM"] = array("2000");
foreach($cats as $k => $v)
{
$keywords = array();
foreach($v as $keyword)
{
$keywords[] = "description LIKE '%".$keyword."%'";
}
$where = implode(" OR ",$keywords);
$sql = "UPDATE PTproducts SET spinspeed='".$k."' WHERE ".$where;
database_queryModify($sql,$result);
}
?>
Cheers,
David.
Hi David
Many thanks, works a treat :)
Hope you had a great holiday.
Regards
Richard
Hi,
This sort of processing is best done after import; otherwise you can run into memory issues etc.
If you're happy to maintain your list of words > categories within a script, then you can do something almost identical to a script I posted for another user recently...
http://www.pricetapestry.com/node/866
What you would need to do is something like this:
setcats.php: (run this in your Price Tapestry top level directory)
<?php
set_time_limit(0);
require("includes/common.php");
// build up the $cats array with reqired category names and keywords
$cats["My MP3 Category"] = array("MP3","iPod");
$cats["My HiFi Category"] = array("Tuner","Amplifier");
foreach($cats as $k => $v)
{
$keywords = array();
foreach($v as $keyword)
{
$keywords[] = "name LIKE '%".$keyword."%'"
}
$where = implode($keywords," OR ");
$sql = "UPDATE products SET category='".$k."' WHERE ".$where;
database_queryModify($sql,$result);
}
?>
Simply run this script manually after each import.
Hope this helps!
Cheers,
David.