Hi David
Thanks for the help at http://www.pricetapestry.com/node/3355.
Is it possible to show voucher codes per product on the featured.php page. I've had a look round but not found anything.
Chris
Unfortunatly we are using level 1, does that mean it's a non starter?
Chris
Hi Chris,
You can switch to level 2 as simply as updating config.advanced.php and re-importing - and then of course as long as you re-import at least as frequently as voucher codes may expire. Is that the only sticking point; in that it's not practical for you to update / re-import daily (or as required)?
Cheers,
David.
--
PriceTapestry.com
The trouble is we have nearly 80 databases on our server and we find that its not practical to import during the day as other database applications slow down, the 60 PT databases are scheduled to import once a fortnight overnight. I think in our case daily is not practical and I will have to look at first how long voucher codes typically last before they expire otherwise incorrect prices will be shown.
Thanks
Chris
Hi Chris,
Ah I understand - OK let me work out the code to apply voucher codes to Featured Products based on a level 1 integration which anticipates a mix of compared / non-compared Featured Products - I'll look into this for you first thing tomorrow for you...
Cheers,
David.
--
PriceTapestry.com
Hi Chris,
This should do it; which involves replacing the standard Featured Products select code with a version that guarantees field consistency, to which level 1 voucher code integration can be applied.
In index.php, look for the following code beginning at line 55:
$sqlNames = array();
$sqlCase = "CASE normalised_name";
foreach($rows as $featured)
{
$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); database_querySelect($sql,$rows);
$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);
}
...and REPLACE with:
$featured["products"] = array();
foreach($rows as $row)
{
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($row["name"])."' ORDER BY price";
database_querySelect($sql,$rows2);
$product = $rows2[0];
$product["minPrice"] = $product["price"];
$product["numMerchants"] = count($rows2);
$featured["products"][] = $product;
}
$featured["products"] = tapestry_applyVoucherCodes($featured["products"]);
And then to display the codes, the same modification as described above to html/featured.php - look for the following code at line 28:
<strong><?php print $config_currencyHTML.$product["price"]; ?></strong><br />
...and REPLACE with:
<strong><?php print $config_currencyHTML.$product["price"]; ?></strong><br />
<?php if ($product["voucher_code"]): ?>
<small>using voucher code:</small><br />
<strong><?php print $product["voucher_code"]; ?></strong><br />
<?php endif; ?>
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hi David
I've sent you an email with files to look at.
Chris
Hi David
Thanks very much for sorting the featured file for us, I've got it all functioning as planned. Did you manage to have a look at the search.php file? Also can (if voucher) be added to the merchants AtoZ?
I've been looking for a forum article I seen back along about adding a merchant details/information page could you post the link as I can't seem to find it.
Many thanks
Chris
Hi Chris,
Here's the code to apply voucher codes to search result pages when not sorted by price. Simply insert the following code at the very top of html/searchresults.php:
<?php
function cmp($a, $b)
{
if ($a["price"] == $b["price"])
{
return 0;
}
return ($a["price"] < $b["price"]) ? -1 : 1;
}
if (($sort <> "priceAsc") && ($sort <> "priceDesc"))
{
foreach($searchresults["products"] as $k => $product)
{
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."'";
database_querySelect($sql,$products);
$products = tapestry_applyVoucherCodes($products);
usort($products,"cmp");
$searchresults["products"][$k]["merchant"] = $products[0]["merchant"];
$searchresults["products"][$k]["voucher_code"] = $products[0]["voucher_code"];
$searchresults["products"][$k]["minPrice"] = $products[0]["price"];
$searchresults["products"][$k]["price"] = $products[0]["price"];
}
}
?>
One way to incorporate voucher codes with the Merchant A-Z would be, for each merchant that has vouchers available, to add a link to vouchers.php filtered by that merchant. To do this, open merchants.php and look for the following code at line 4:
$atoz["items"] = array();
...and REPLACE with;
$hasVouchers = array();
$sql = "SELECT DISTINCT(merchant) FROM `".$config_databaseTablePrefix."vouchers`";
database_querySelect($sql,$rows);
foreach($rows as $row)
{
$hasVouchers[] = $row["merchant"];
}
$atoz["items"] = array();
Next look for the following code at line 30:
$atoz["items"][] = $item;
...and REPLACE with
if (in_array($item["name"],$hasVouchers))
{
$item["extra"] = " <a href='".$config_baseHREF."vouchers.php?merchant=".urlencode($item["name"])."'>Special Offers Available!</a>";
}
$atoz["items"][] = $item;
Next, in html/atoz.php look for the following code at line 58:
print "</p>";
...and REPLACE with:
if (isset($item["extra"])) print $item["extra"];
print "</p>";
Finally, in vouchers.php look for the following code at line 8:
if (database_querySelect($sql,$vouchers))
...and REPLACE with:
if (isset($_GET["merchant"]))
{
$sql = str_replace("WHERE","WHERE merchant='".database_safe($_GET["merchant"])."' AND ",$sql);
}
if (database_querySelect($sql,$vouchers))
I think the merchant info / description thread you're after may be this one...
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hi David
That's a brilliant help! Thanks.
I'm working my way through to changes starting with vouchers on merchants.php
The above works fine but I noticed that out of date vouchers were also showing so I changed it slightly using the query in vouchers.php to:
$hasVouchers = array();
$now = time();
$sql = "SELECT DISTINCT(merchant) FROM `".$config_databaseTablePrefix."vouchers` WHERE ( (valid_from < '".$now."' AND valid_to = '0') OR (valid_from <= '".$now."' AND valid_to > '".$now."') ) ORDER BY merchant";
//$sql = "SELECT DISTINCT(merchant) FROM `".$config_databaseTablePrefix."vouchers`";
database_querySelect($sql,$rows);
foreach($rows as $row)
{
$hasVouchers[] = $row["merchant"];
}
It works fine, am I OK to use?
Chris
Hi Chris,
If using Voucher Codes level 2 integration ($config_useVoucherCodes = 2; at line 41 of config.advanced.php) - so that voucher codes are imported and discounts calculated at import time then the prices shown by Featured Products will take into account the cheapest after discount.
Displaying the voucher code is not so straight forward however as Featured Products, like search results, derive from a summary query which uses SQL statments such as MIN(price) - which leaves the value of other fields undefined.
What it would be possible to do however, once level 2 integration is enabled, is that if a Featured Product is only available from 1 merchant then the voucher code can be displayed.
To do this, in html/featured.php look for the following code at line 28:
<strong><?php print $config_currencyHTML.$product["price"]; ?></strong><br />
(note that this is within the single merchant section, e.g. "More Information" rather than "Compare Prices" link) and REPLACE with:
<strong><?php print $config_currencyHTML.$product["price"]; ?></strong><br />
<?php if ($product["voucher_code"]): ?>
<small>using voucher code:</small><br />
<strong><?php print $product["voucher_code"]; ?></strong><br />
<?php endif; ?>
(adjust HTML as required of course)
Note the caveat that is required when using level 2 voucher code integration which is that you must ensure that your feed update / import process takes place sufficiently frequently that expired codes are purged - so ideally daily!
Cheers,
David.
--
PriceTapestry.com