Hi David.
I have a mercahtn which have two vouchers code actived, however, the are the same with the only different of the min_price (match_value and match_type is the same)
So, when I search for that /search.php?q=voucher:{merchant}:{code}, only the first one is picked as we are taking $voucher = $vouchers[0]; in search.php
Is any way I can "merge" both vouchers? Maybe when code is the same, order by min_price?
Thanks in advance!
Thank you, I love it, just a minor change and it works as expected.
Hi David.
Now, my problem is that I have three vouchers, same code for same merchant. Each code is applyed with different conditions. How can I modify the code so the SQL query include all the conditions with an OR?
Thank you.
Hi,
As long as you're using Voucher Codes Integration level 2 (code determined and discount applied at import time) then you can have multiple entries of the same code for the same merchant with different conditions and should work as required...
Cheers,
David.
--
PriceTapestry.com
Sorry, I must use voucher code "on real time"
$config_useVoucherCodes = 1;
Hi,
Ah OK - for level 1 integration then edit search.php and look for the following code beginning at line 179:
$voucher = $vouchers[0];
$where = " merchant = '".database_safe($voucher["merchant"])."' ";
if ($config_useVoucherCodes == 2)
{
$where .= " AND voucher_code = '".database_safe($voucher["code"]).($voucher["discount_text"]?" (".$voucher["discount_text"].")":"")."' ";
}
else
{
if ($voucher["match_value"])
{
$match_values = explode(",",$voucher["match_value"]);
$match_wheres = array();
foreach($match_values as $match_value)
{
if ($voucher["match_type"]=="exact")
{
$match_wheres[] = " ".$voucher["match_field"]." = '".database_safe($match_value)."' ";
}
else
{
$match_wheres[] = " ".$voucher["match_field"]." LIKE '%".database_safe($match_value)."%' ";
}
}
$where .= " AND (".implode(" OR ",$match_wheres).") ";
}
if ($voucher["min_price"])
{
$where .= " AND price >= '".database_safe($voucher["min_price"])."' ";
}
if ($voucher["max_price"])
{
$where .= " AND price <= '".database_safe($voucher["max_price"])."' ";
}
}
...and REPLACE with:
$merchant_where = " merchant = '".database_safe($parts[1])."' ";
$vouchers_wheres = array();
foreach($vouchers as $voucher)
{
$wheres = array();
if ($voucher["match_value"])
{
$match_values = explode(",",$voucher["match_value"]);
$match_wheres = array();
foreach($match_values as $match_value)
{
if ($voucher["match_type"]=="exact")
{
$match_wheres[] = " ".$voucher["match_field"]." = '".database_safe($match_value)."' ";
}
else
{
$match_wheres[] = " ".$voucher["match_field"]." LIKE '%".database_safe($match_value)."%' ";
}
}
$wheres[] = " (".implode(" OR ",$match_wheres).") ";
}
if ($voucher["min_price"] > 0)
{
$wheres[] = " price >= '".database_safe($voucher["min_price"])."' ";
}
if ($voucher["max_price"] > 0)
{
$wheres[] = " price <= '".database_safe($voucher["max_price"])."' ";
}
$vouchers_wheres[] = "(".implode(" AND ",$wheres).")";
}
$where = "(".$merchant_where." AND (".implode(" OR ",$vouchers_wheres)."))";
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Thank you David. As usual, it is working as expected.
Hi,
To merge by min_price at search time - edit search.php and look for the following code at line 179:
$voucher = $vouchers[0];
...and REPLACE with:
$voucher = $vouchers[0];
if (count($vouchers > 1))
{
foreach($vouchers as $v)
{
if ($v["min_price"] < $voucher["min_price"])
{
$voucher["min_price"] = $v["min_price"];
}
}
}
Hope this helps!
Cheers,
David.
--
PriceTapestry.com