Hi David!
I would like to put several categories in the product table separated by a comma (,) and then make the script explode the field and recognize each category has a single one.
The way to put a comma will be using the search and replace and other filters. But how can I make the script explode the field and recognize each category has a single one, fully searchable and indexable like all the other?
Best regards,
Pedro
Hi David, once again, thank you for your support.
Although, now I'm afraid about the performance issue. My website is not niche related and it is very large. So I was thinking maybe in another alternative. The products table could have 4 different independent categories: category1, category2, category3, category4, all indexed fields.
Then, when the product is being imported, the script could explode the categories name (already prepared to do this) by a comma, and import the first four categories into each field (ignoring the other).
Then, when searching, the script could use any category field as a normal category, indepedent of each other. This would make the product appear in more than one category but that is exactly what happens in every store and it works great.
Is this an easy thing to do? Can you help me with it?
This would, in my opinion, solve the need to use multi-level categories. Because the webmaster could organize the categories as we would like and create some complex multi-level categories, manually, creating links to each category!
I look forward to your reply,
Pedro
I'm sorry David, nevermind my previous post, this way is fine as I'll only use it in my niche websites. Thank you very much!
David you're AWESOME!
This works like a charm! And I get to see what people are searching for. Check it out : {link saved}
Thanks again!
Hi Pedro,
This can be done reasonably easily, but keep an eye on performance - i'd only really recommend this approach for a niche site.
Search is the more straight forward. To make sure that the category:Category Name: search query supports the comma separated format, look for the following code at line 88 of search.php:
$where .= " ".$field." = '".database_safe($parts[$i])."' ";
...and REPLACE that with:
if ($field=="category")
{
$where .= " category LIKE '%".database_safe($parts[$i])."%' ";
}
else
{
$where .= " ".$field." = '".database_safe($parts[$i])."' ";
}
For the category index page, look for the following code at line 10 of categories.php:
foreach($rows as $product)
...and REPLACE with:
$allCategories = array();
foreach($rows as $product)
{
$categories = explode(",",$product["category"]);
foreach($categories as $category)
{
$allCategories[$category] = $category;
}
}
ksort($allCategories);
$rows = array();
foreach($allCategories as $category)
{
$rows[] = array("category"=>$category);
}
foreach($rows as $product)
Cheers,
David.
--
PriceTapestry.com