Hi
Just added the script today which is great!
Is it possible to show all the products? Possibly a button which opens up a page which shows all the item names and links.
also a dropdown box shoing the items would also be useful
Thanks
Hi,
The code segments above are both standalone files - create them (with the filenames i've suggested if you wish) in your Price Tapestry installation folder and then browse to them as normal. You can then add a link to these pages in your index.php if you wish, for example:
print "<a href='allproducts.php'>All Products</a>
Hope this helps!
Cheers,
David.
Thanks David
Could you show what code is needed to show both the item name and price for the above 2 examples
cheers
Hi,
In both examples, change the SQL to something like:
$sql = "SELECT name,price FROM ".$config_databaseTablePrefix."products ORDER BY name";
..and then in the first script change:
print "<p><a href='".$href."'>".$product["name"]."</a></p>";
print "<p><a href='".$href."'>".$product["name"]." ".$config_currencyHTML.$product["price"]."</a></p>";
and in the second script change:
print "<option value='".$product["name"]."'>".$product["name"]."</option>";
print "<option value='".$product["name"]."'>".$product["name"]." ".$config_currencyHTML.$product["price"]."</option>";
Cheers,
David.
Hi David
I've added $sql = "SELECT DISTINCT(name) FROM ".$config_databaseTablePrefix."products ORDER BY name";
to get unique results listed in the second option of a drop down menu however this only works with the list of products and not when the price is shown.
Also is it possible to add the code to the searchform.php ? I've tried and it failed.
Finally, is it possible to have search engine friendly links for it?
thanks
Mally
Hi Mal,
To get the min price when using DISTINCT you would need to use GROUP BY instead; try this:
$sql = "SELECT name,MIN(price) as price FROM ".$config_databaseTablePrefix."products GROUP BY name ORDER BY name";
You should be able to use the code anywhere as long as the Price Tapestry standard includes have been included (which is all the standard PT pages). What error or failure mode are you seeing when trying to add this to the search form?
Cheers,
David.
Hello David
That works and shows the price.
When I add the code to the search form the list appears normally, however when I choose an item and select go I get the following message
Warning: Invalid argument supplied for foreach() in /home/magsub/public_html/html/product.php on line 4
Warning: require(descriptions/) [function.require]: failed to open stream: No such file or directory in /home/magsub/public_html/html/product.php on line 20
Warning: require(descriptions/) [function.require]: failed to open stream: No such file or directory in /home/magsub/public_html/html/product.php on line 20
Fatal error: require() [function.require]: Failed opening required 'descriptions/' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/magsub/public_html/html/product.php on line 20
Hi Mal,
That looks like it's something to do with another modification trying to load something in from a descriptions/ directory that you have created. Can you post the code from line 4 of html/product.php that is generating the error (and perhaps a few lines either side) and i'll take a look for you...
Cheers,
David.
thanks David
Heres the begining of my product.php file
<?php $mainProduct = $product["products"][0]; ?>
<div id='producttext'>
<?php $i=0; foreach($product["products"] as $priceProduct): ?>
<?php if (($priceProduct["price"] == $mainProduct["price"]) && ($i==0)): ?>
<p class='best'> The best price found is <?php print $config_currencyHTML.$mainProduct["price"]; ?> <?php print translate("from"); ?> <a target="_blank" href='<?php print tapestry_buyURL($priceProduct); ?>' title='<?php print $priceProduct["merchant"]; ?>' <?php print javascript_statusBar(translate("Go to")." ".$priceProduct["merchant"]); ?>><?php print $priceProduct["merchant"]; ?></a> » <a target="_blank" href='<?php print tapestry_buyURL($priceProduct); ?>' title='Buy <?php print $mainProduct["name"]; ?>' <?php print javascript_statusBar(translate("Go to")." ".$priceProduct["merchant"]); ?>><?php print translate("Buy Now"); ?></a></p>
<?php else: ?>
<?php break; ?>
<?php endif; ?>
<?php $i++; endforeach; ?>
<h3>
<?php if ($mainProduct["image_url"]): ?>
<img class='leftimage' width='100' src='<?php print $mainProduct["image_url"]; ?>' alt='<?php print $mainProduct["name"]; ?>' title='<?php print $mainProduct["name"]; ?>' />
<?php endif; ?>
<a href='<?php print tapestry_buyURL($mainProduct); ?>' title='<?php print $mainProduct["name"]; ?>' <?php print javascript_statusBar(translate("Go to")." ".$mainProduct["merchant"]); ?>><?php print $mainProduct["name"]; ?></a>
</h3>
Hi,
It looks like it's happening at a higher level than the HTML page then. Basically, the products page has not found a product to display.
You said that you added the code to the search form, and then you select a product from the drop down and select "Go" - can you let me know what happens after that in order to get to products.php?
Presumably, the search form is still submitting to search.php; so do you have some code at the top of search.php that is supposed to pick this up and then redirect to products.php?
It might be easier if you want to email me the modified html/searchform.php, search.php and products.php and i'll check it all over for you...
Cheers,
David.
Hello David
I'm currently showing all items on my homepage blurb using the following code
<?php
print "<form method='get' action='products.php'>";
print "<select name='q'>";
if(count($config_overseas))
{
foreach($config_overseas as $k => $v)
{
$config_overseas[$k] = "'".$v."'";
}
$in = implode(",",$config_overseas);
$sql = "SELECT name,MIN(price) as price FROM ".$config_databaseTablePrefix."products WHERE merchant NOT IN (".$in.") GROUP BY name ORDER BY name";
}
else
{
$sql = "SELECT name,MIN(price) as price FROM ".$config_databaseTablePrefix."products GROUP BY name ORDER BY name";
}
if (database_querySelect($sql,$rows))
{
foreach($rows as $product)
{
print "<option value='".$product["name"]."'>".$product["name"]." from ".$config_currencyHTML.$product["price"]."</option>";
}
}
print "</select> ";
print "<input type='submit' value='Go' />";
print "</form>";
?>
This shows the name of the product along with the lowest price.
I currently have a set of products set at price 9999 and have used various mods to remove them from search results.
Is it possible to change the code above, so if the minium value is 9999 it shows the product name and then "Not yet added"?
Many thanks
Mally
Hi Mally,
I would just change this section...
foreach($rows as $product)
{
print "<option value='".$product["name"]."'>".$product["name"]." from ".$config_currencyHTML.$product["price"]."</option>";
}
...to:
foreach($rows as $product)
{
if ($product["price"]==9999) $product["price"]="Not yet added";
print "<option value='".$product["name"]."'>".$product["name"]." from ".$config_currencyHTML.$product["price"]."</option>";
}
Cheers,
David.
ref the drop down code in my blurb (the post above), is there any way of restricting the length of the product name, so if it goes over so many characters, it continues on the next line? Some of my product titles are long and they are stretching the templates.
Thanks
Mally
Hi Mally,
Line breaking is tricking within HTML, however you might want to investigate adding a CSS max-width attribute to the container in which you are displaying the list.
Alternatively, you could always crop the product name to so many characters. On the line after the following line:
if ($product["price"]==9999) $product["price"]="Not yet added";
...try:
$manlen = 40; // set to whatever maximum length you want
if (strlen($product["name"])>$maxlen)
{
$product["name"] = substr($product["name"],0,$maxlen)."...";
}
Hope this helps!
Cheers,
David.
Hello Mally
I am french web designer who finds your code very extroardinary.
French developpers are not as creative as you. So thank you for your work.
Is it possible to make appear all the products like a search result page?
Thank you.
Hi David
For another site I'm putting together is it possible to modify this code to make the dropdown ordered by category, then by product?
<?php
print "<form method='get' action='products.php'>";
print "<select name='q'>";
if(count($config_overseas))
{
foreach($config_overseas as $k => $v)
{
$config_overseas[$k] = "'".$v."'";
}
$in = implode(",",$config_overseas);
$sql = "SELECT name,MIN(price) as price FROM ".$config_databaseTablePrefix."products WHERE merchant NOT IN (".$in.") GROUP BY name ORDER BY name";
}
else
{
$sql = "SELECT name,MIN(price) as price FROM ".$config_databaseTablePrefix."products GROUP BY name ORDER BY name";
}
if (database_querySelect($sql,$rows))
{
foreach($rows as $product)
{
print "<option value='".$product["name"]."'>".$product["name"]." from ".$config_currencyHTML.$product["price"]."</option>";
}
}
print "</select> ";
print "<input type='submit' value='Go' />";
print "</form>";
?>
cheers
Mally
Hi Mally,
This can be tricky when using summary queries; but try this for starters:
<?php
print "<form method='get' action='products.php'>";
print "<select name='q'>";
if(count($config_overseas))
{
foreach($config_overseas as $k => $v)
{
$config_overseas[$k] = "'".$v."'";
}
$in = implode(",",$config_overseas);
$sql = "SELECT category,name,MIN(price) as price FROM ".$config_databaseTablePrefix."products WHERE merchant NOT IN (".$in.") GROUP BY name ORDER BY category,name";
}
else
{
$sql = "SELECT category,name,MIN(price) as price FROM ".$config_databaseTablePrefix."products GROUP BY name ORDER BY category,name";
}
if (database_querySelect($sql,$rows))
{
foreach($rows as $product)
{
print "<option value='".$product["name"]."'>".$product["name"]." from ".$config_currencyHTML.$product["price"]."</option>";
}
}
print "</select> ";
print "<input type='submit' value='Go' />";
print "</form>";
?>
You can then display the category if you wish within the HTML-making part of the code using $product["category"]
Cheers,
David.
great stuff, works for me! Is there any way of change the price from for example 4.43 to just the first digit as in 4
basically getting ride of the decimal point and following numbers?
Hi Mal,
Sure - simply replace:
$product["price"]
...with:
sprintf("%d",$product["price"]);
However, this method will round according to normal mathematical rules. If you just want to strip the decimal part; use:
sprintf("%d",floor($product["price"]));
Cheers,
David.
Hi,
I'm trying to integrate url rewriting in the productselector.php but I can't seem to succeed..
Is it possible to do?
Thanks
Hello Gael,
productselector.php submits to your products.php directly so what you would need to do is add some code at the top to redirect to the rewritten version. It's straight forward to do; near the top of the file look for:
$rewrite = isset($_GET["rewrite"]);
...and REPLACE with:
$rewrite = isset($_GET["rewrite"]);
if (!$rewrite)
{
header("Location: ".$config_baseHREF."product/".tapestry_hyphenate($q).".html");
exit();
}
...and that will redirect to the rewritten version if submitted from your productselector.php...
Cheers,
David.
--
PriceTapestry.com
Hi,
Here's a slightly modified script from another thread that will display all products:
allproducts.php:
<?php
require("includes/common.php");
require("html/header.php");
require("html/menu.php");
require("html/searchform.php");
$banner["h2"] = "<strong>".translate("All Products")."</strong>";
require("html/banner.php");
$sql = "SELECT name FROM ".$config_databaseTablePrefix."products ORDER BY name";
if (database_querySelect($sql,$rows))
{
foreach($rows as $product)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
}
else
{
$href = $config_baseHREF."products.php?q=".urlencode($product["name"]);
}
print "<p><a href='".$href."'>".$product["name"]."</a></p>";
}
}
else
{
print "<p>There are no products to display.</p>";
}
require("html/footer.php");
?>
Here's a version with a drop down list - but I wouldn't recommend this for a site with too many products....!
productselector.php
<?php
require("includes/common.php");
require("html/header.php");
require("html/menu.php");
require("html/searchform.php");
$banner["h2"] = "<strong>".translate("Product Selector")."</strong>";
require("html/banner.php");
print "<form method='get' action='products.php'>";
print "<select name='q'>";
$sql = "SELECT name FROM ".$config_databaseTablePrefix."products ORDER BY name";
if (database_querySelect($sql,$rows))
{
foreach($rows as $product)
{
print "<option value='".$product["name"]."'>".$product["name"]."</option>";
}
}
print "</select> ";
print "<input type='submit' value='Go' />";
print "</form>";
require("html/footer.php");
?>
Hope this helps!
Cheers,
David.