Categorised featured products sections?
I read that you could have multiple rows of featured products, what I was wondering is if you could have different categories for each row?
Video games seems like an obvious example - how would you have one row of featured PS3 games and then below that have a row of featured XBOX games (with headings above each row)?
Thanks,
Paul
Thanks David, managed to get that working.
Hi David,
regarding the above, I have created the new featuredproducts.php and comment out the code in index, however i couldn't get the products to show up. I did managed to get the sub headings up as shown below...
Category 1
Category 2
Category 3
but there are no products displayed below each category. my guess is maybe the category calling i used is wrong? i used different variations to call it, like using all caps, only capitalizing first letter, using %20 between two words, but its still not showing anything.
any advice?
Henry
Hi Henry,
The values you use for $featuredproducts_category should exactly match
the value you enter in your Featured Products configuration page in
/admin/, for example, if you are using
$featuredproducts_category = "Widgets";
require("featuredproducts.php");...then this should show up all products configured as
Widgets/Featured Widget 1
Widgets/Featured Widget 2
etc.
If it's still not working as expected, add some debug code to your
featuredproducts.php file, such as printing the SQL:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY sequence";
print "[".$sql."]";This will print the SQL being generated between square brackets. Then
compare that to your configured Featured Products. If you're still not
sure, if you could post the SQL that is being generated by the above
debug code, and also a sample of your configured Featured Products that
should be being selected but are not being I'll check it out...
Cheers,
David.
--
PriceTapestry.com
Hi everyone,
Thanks David for the advice! I finally got mine to work!
I thought i will just post my thoughts here.
I read through this thread at least 5 times, but it did not occur to me that the solution is just
1) go to featured products
2) instead of adding just product names like
nike womens shirt1
nike womens shirt2
etc, we need to add category1/nike womens shirt1 and category1/nike womens shirt2
3) where category1 is the category name used in index.php mentioned above.
hope this helps!
Henry
I've managed to get mine working but for some reason, every other section starts all its products on different lines. If i have 3 products in one section, it puts 2 across and one underneath and if i change to 2, they're both underneath each other and this messes up the section which is two sections down.
Any ideas on what the problem could be? I've copied it exactly as above.
My url is {link saved}
Hi,
This sounds like the $count variable (I assume that you have implemented the
Featured Products in 2 or more rows mod) needs to be reset for each section.
Try adding the following line to the very top of your html/featured.php:
<?php $count = 0; ?>Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Yep, thanks David. That was the problem.
Hi,
I tried to get it working but get:
[SELECT * FROM `pt_featured` WHERE name LIKE 'Cadeau/%' ORDER BY sequence]
The product should be showing is on this url:
{link saved}
The above is for showing featured products in categories. And what if I would like to show all the producst of several categories? (the categories I want to show have a limited number of products).
Hi Marco,
The page seems to be working now so you may have fixed the problem -
let me know if it's still not working.
To show muiltiple featured sections in one go, repeat the code for
each section, for example
$featuredproducts_category = "Cadeau";
require("featuredproducts.php");
$featuredproducts_category = "Clothing";
require("featuredproducts.php");Cheers,
David.
--
PriceTapestry.com
Hi,
Sorry, I forgot to mention that I made a testpage.
It's on:
{link saved}
And it's not working yet.
Hi Marco,
Could you email me your featuredproducts.php file, and password for /admin/ and I'll check it out for you...
Cheers,
David.
--
PriceTapestry.com
Hi, I received the modified featuredproducts.php and it works.
I want also to have the option to list specific categories without specifying the products in the category. The products in the categories I want to show are frequently changed in the feeds and the number is limited.
How can this be done?
Hi Marco,
What you can do is add support for an alternative variable, e.g.
$featuredproducts_categoryRandom
...and then in your featuredproducts.php where you have:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY sequence";...REPLACE that with:
if ($featuredproducts_categoryRandom)
{
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category = '".$featuredproducts_categoryRandom."' ORDER BY RAND() LIMIT 3";
}
else
{
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY sequence";
}(change LIMIT 3 for more or less random products)
Also add at very end of featuredproducts.php (just before the closing PHP tag)
$featuredproducts_category = "";
$featuredproducts_categoryRandom = "";Then in your index.php (or wherever you are calling featuredproducts.php) just use
$featuredproducts_categoryRandom = "Category Name";
require("featuredproducts.php");Cheers,
David.
--
PriceTapestry.com
Is it possible to sort the featured products on Merchant Name?
Hi Marco,
Sure - in your file where the featured products code is (e.g. index.php or featuredproducts.php as described above), search for:
ORDER BY sequence...and REPLACE that with:
ORDER BY merchantCheers,
David.
--
PriceTapestry.com
Hi,
I changed a line in featuredproducts.php into:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY merchant";
But the merchant with the M still comes before the merchant with the I.
Example url:
{link saved}
Hi Marco,
The ORDER BY sequence occurs twice throughout the featured products code - make sure to change both instances (although it's actually only the second that matters...)
Cheers,
David.
--
PriceTapestry.com
Hi,
I found only one.
I tried altering the ORDER BY RAND() LIMIT 3 into ORDER BY merchant but that didn't work.
{code saved}
Hi Marco,
Your code was slightly different - from the above replace this line:
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";with:
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name ORDER BY merchant";Cheers,
David.
--
PriceTapestry.com
Hi,
The order is now there, but I got some strange things. If you click on the two top products (merchants)it doesn't find the product and I imported more merchants/articles for the top category but they don't show. Only two show.
My index.php code:
<?php
require("includes/common.php");
require("html/header.php");
require("html/searchform.php");
// print javascript_focus("search.q");
$featuredproducts_categoryRandom = "Dagaanbiedingen top";
require("featuredproducts.php");
$featuredproducts_categoryRandom = "Dagaanbiedingen";
require("featuredproducts.php");
$featuredproducts_categoryRandom = "Dagaanbiedingen vrije tijd";
require("featuredproducts.php");
require("html/footer.php");
?>Featuredproducts.php code:
<?php
unset($featured);
if ($featuredproducts_categoryRandom)
{
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category = '".$featuredproducts_categoryRandom."' ORDER BY merchant";
}
else
{
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY merchant";
}
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
foreach($rows as $featured)
{
$sqlNames[] = "'".database_safe(str_replace($featuredproducts_category."/","",$featured["name"]))."'";
}
$sqlIn = implode(",",$sqlNames);
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name ORDER BY merchant";
database_querySelect($sql,$rows);
$featured["products"] = $rows;
foreach($featured["products"] as $k => $product)
{
if ($config_useRewrite)
{
$featured["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
$featured["products"][$k]["reviewHREF"] = "review/".tapestry_hyphenate($product["name"]).".html";
}
else
{
$featured["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
$featured["products"][$k]["reviewHREF"] = "reviews.php?q=".urlencode($product["name"]);
}
}
}
if (isset($featured)) require("html/featured.php");
$featuredproducts_category = "";
$featuredproducts_categoryRandom = "";
?>Hi Marco,
Double check that the product names exactly match what is imported - when creating your category/Featured Product Name copy Featured Product Name directly from the Product Finder tool (open it in a new window is the easiest way).
Regarding links not working, within your featuredproducts.php, replace each instance of
tapestry_hyphenate($product["name"])...with:
tapestry_hyphenate($product["normalised_name"])Cheers,
David.
--
PriceTapestry.com
Hi,
I'm not listing featured product names, but specific categories without specifying the products in the category. I have several categories and added merchants to those categories (exclusively). For example category A has now four merchants. But only two get on the featured page. Why aren't the other two merchants shown?
PS: the links work now.
Hi Marco,
Can you email me your featuredproducts.php, a link to the installation and any password required for /admin/ and I'll take a good look for you...
Thanks!
Cheers,
David.
--
PriceTapestry.com
Hi, I found the problem. The feed I had, had also a category field in it. While registering it I defined a specific category for it but I didn't set the 'or use field' on 'nothing'. If I do that the products of that merchant feed show. So I guess PT chooses the 'or use field' before the field set for the category?
Hi Marco,
That is correct, however it would be a simple mod to make it act as an override if a field was selected but empty in some records.
Cheers,
David.
--
PriceTapestry.com
Hi,
I emailed you because the problem returned. Don't know if it is caused by the field. I made a new feed so that it only had the records required (to prevent price tapestry to select a category field) but this didn't work to.
Hi David,
Would you be able to create subcategories in a similar fashion with this method?
Thanks
matt
Hi Paul,
There is quite a neat and straight-forward mod to do this. What it involves is simply pre-fixing each of your Featured Products within the admin area with a "category" name followed by a "/", for example:
PS3/Guitar Hero
PS3/Burnout Paradise City
XBOX/Rock Band
XBOX/Vandal Hearts
etc.
Then, what I would do is extract the Featured Products code from index.php and place it into its own file, so that you then just need to set a category variable, generate any section title you want within the index, and call featuredproducts.php for each section.
To do this, create a new file as follows:
featuredproducts.php
<?phpunset($featured);
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY sequence";
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
$sqlCase = "CASE normalised_name";
foreach($rows as $featured)
{
$featured["name"] = str_replace($featuredproducts_category."/","",$featured["name"]);
$featured["name"] = tapestry_normalise($featured["name"]);
$sqlNames[] = "'".$featured["name"]."'";
$sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
}
$sqlCase .= " END AS sequence";
$sqlIn = implode(",",$sqlNames);
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
database_querySelect($sql,$rows);
$featured["products"] = $rows;
foreach($featured["products"] as $k => $product)
{
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
}
}
if (isset($featured)) require("html/featured.php");
?>
Then, simply remove the equivalent code from index.php - let me know if you're not sure what to remove - but it's basically everything from the $sql line to SELECT featured products, down to the line containing require("html/featured.php") - and REPLACE with the following:
print "<h2>PS3</h2>";$featuredproducts_category = "PS3";
require("featuredproducts.php");
print "<h2>XBOX</h2>";
$featuredproducts_category = "XBOX";
require("featuredproducts.php");
Hope this helps!
Cheers,
David.