Hi David,
Can we modify the voucher code functionality to allow for coupon links instead of voucher codes? Many stores in US provides coupon links instead of voucher codes. When a visitor visits a merchant site through one of these special links they qualify for an additional discount during checkout. It would be of great help if you can let me know how to accommodate such a functionality in the current voucher code implementation. I think if we can change voucher code interface to include two different types one for the code version and another one for the link version that would be a good starting point.
Thanks,
Matt
Thanks. Can we also modify the functionality to add "SKU" and "UPC" level matching? Which parts of the code should I change for this? Also if I want the coupon to attach to multiple SKUs can I just include these as sku1,sku2,sku3,sku4 in the Against field.
Hi Matt,
Sure, any custom fields that you have added can easily be added to the Match Fields array at line 212 of admin/voucher_codes_edit.php, for example:
$match_fields = array("name"=>"Product Name","category"=>"Category","brand"=>"Brand","sku"=>"SKU");
(assuming the custom field name is sku in the products table)
To match a list of values rather will require a new match type, so in the same file, add a List match type to the $match_types array at line 204:
$match_types = array("exact"=>"Exact Match","keyword"=>"Keyword Match","list"=>"List Match");
Finally, in include/tapestry.php, look for the following code beginning at line 185:
case "keyword":
if (strpos($product[$voucher["match_field"]],$voucher["match_value"]) === FALSE)
{
$isValid = FALSE;
}
break;
...and REPLACE that with:
case "keyword":
if (strpos($product[$voucher["match_field"]],$voucher["match_value"]) === FALSE)
{
$isValid = FALSE;
}
break;
case "list":
if (strpos($voucher["match_value"],$product[$voucher["match_field"]]) === FALSE)
{
$isValid = FALSE;
}
break;
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
I was integrating the changes you suggested but in addition to vouchers.php should not I also modify product.php and prices.php so that vouchers with links become a hpyerlink in these pages?
Hi karakartal,
It would only require a single change in includes/tapestry.php to also link the Discount Text field where displayed alongside a product. To do this, look for the following code at line 225:
if ($voucher["discount_text"])
{
$product["voucher_code"] .= " (".$voucher["discount_text"].")";
}
...and REPLACE with:
if (substr($voucher["discount_text"],0,4)=="http")
{
$product["voucher_code"] = "<a href='".$voucher["discount_text"]."'>".$product["voucher_code"]."</a>";
}
elseif ($voucher["discount_text"])
{
$product["voucher_code"] .= " (".$voucher["discount_text"].")";
}
Cheers,
David.
--
PriceTapestry.com
Thanks David. This is such a great support! I really appreciate it.
The list match didn't work the way you suggested. Not sure what was wrong but when I did this trick it worked. So I thought I should post it here in case somebody uses the code in the future.
case "list":
$matchValues = explode(",",$voucher["match_value"]);
foreach($matchValues as $matchValue){
$tmp=strpos($attributes[$voucher["match_field"]],$matchValue);
if ($tmp === FALSE)
{
$isValid=FALSE;
}
else {
$isValid=TRUE;
break;
}
}
break;
Hi Matt,
There is a straight forward mod to make the "Discount Text" field become the link if it begins "http://". To do this, in vouchers.php, look for the following code at line 50:
$vouchers[$k]["text"] .= " ".translate("using voucher code")." <strong>".$voucher["code"]."</strong>";
...and REPLACE that with:
$vouchers[$k]["text"] .= " ".translate("using voucher code")." <strong>".$voucher["code"]."</strong>";
if (substr($voucher["discount_text"],0,4)=="http")
{
$vouchers[$k]["href"] = $voucher["discount_text"];
}
Hope this helps!
Cheers,
David.
--
PriceTapestry.com