Hi David.
I use voucher codes functionality quite often.
I was wondering if this feature can be implemented.
I have some merchants that, depending on how much you spend, you get some discount or other. The voucher code is the same.
For instance.
If you spend 75€, you get 10€ discount. If you spend 150€, 15€. If you spend 300€, 20€. Is a bit messy because I have to copy and paste.
Usually, I have to repeat this procedure three times and only modify minimum spent and discount.
Is any way we can modify the functionality so we can handle this situation in the same voucher_codes_edit.php? Maybe with some separator in the fields?
Best regards
Hi David.
Another request that I would need...
Besides price, I have price_old.
I have a merchant which only allows to apply vouchers when price_old (no discount) is the same as price.
How can I achieve this little functionality?
Best regards
Hi,
Easiest thing to do is probably to hard code the condition into the tapestry_applyVoucherCodes() function - to do this, edit includes/tapestry.php and look for the following code at line 154;
$product["discount_price"] = $product["price"];
...and REPLACE with:
if (($product["merchant"]=="Merchant Name") && ($product["price"]!=$product["price_old"])) continue;
$product["discount_price"] = $product["price"];
Cheers,
David.
--
PriceTapestry.com
If it is possible, I would like for instance to have a checkbox. There are a couple of merchants so I would be touching source code every time. Also, it depends on the voucher code and merchant, not always.
What do you think this idea of checkbox?
Hi,
Sure - first here's the dbmod.php to add `not_discounted` field to the vouchers table...
<?php
require("includes/common.php");
$sql = "ALTER TABLE `".$config_databaseTablePrefix."vouchers` ADD `not_discounted` INT(11) NOT NULL DEFAULT '0'";
database_queryModify($sql,$result);
print "Done.";
?>
And then edit admin/voucher_codes_edit.php and look for the following code at line 165:
valid_to = '%s'
...and REPLACE with:
valid_to = '%s',
not_discounted = '%s'
And then the following code at line 179:
database_safe($_POST["valid_to"]),
...and REPLACE with:
database_safe($_POST["valid_to"]),
(isset($_POST["not_discounted"])?1:0)
And then the following code at line 421:
widget_textBox("Maximum Spend","max_price",FALSE,(isset($_POST["max_price"]) ? $_POST["max_price"] : ""),$config_currencyHTML,6);
...and REPLACE with:
widget_textBox("Maximum Spend","max_price",FALSE,(isset($_POST["max_price"]) ? $_POST["max_price"] : ""),$config_currencyHTML,6);
widget_checkBox("Not Discounted","not_discounted",FALSE,(isset($_POST["not_discounted"])&&$_POST["not_discounted"]) );
And then in includes/tapestry.php look for the following code at line 158:
$isValid = TRUE;
...and REPLACE with:
$isValid = TRUE;
if ($isValid)
{
if (
($voucher["not_discounted"])
&&
($product["price"] != $product["price_old"])
)
{
$isValid = FALSE;
}
}
Cheers,
David.
--
PriceTapestry.com
Awesome, I am going to test it ASAP (this night)!
Just to confirm, which change would be necessary in search.php?
By the way, I have been using voucher functionality for a while. Sometimes I get wrong when I create new voucher code because the first merchant is selected. Is it possible to don't have one selected by default?
Also, min_price default to 0 when creating a new one.
Thank you David.
Hi,
To add both default changes to new codes, edit admin/voucher_codes_edit.php and look for the following code at line 348:
$merchants = array();
...and REPLACE with:
$merchants = array();
$merchants[""] = "Select...";
...and then the following code at line 421:
widget_textBox("Minimum Spend","min_price",FALSE,(isset($_POST["min_price"]) ? $_POST["min_price"] : ""),$config_currencyHTML,6);
...and REPLACE with:
widget_textBox("Minimum Spend","min_price",FALSE,(isset($_POST["min_price"]) ? $_POST["min_price"] : "0.00"),$config_currencyHTML,6);
Cheers,
David.
--
PriceTapestry.com
Excellent David, thank you very much.
It works as expected without any additional work.
With your code, I spotted that I only have to add these lines in search.php
if ($voucher["not_discounted"])
{
$where .= " AND price = price_old ";
}
Hi again David.
Regarding the "not_discounted" column we added last year.
I am wondering if we can improve this.
Currently, I have a merchant which have the following promotion.
They have a voucher code which discount 30% when the product is with same price (price = price_old), and 15% when price is lower than price_old.
How do you think we can integrate this functionality?
Maybe add another column? not_discounted be multiple values? For instance:
- 0: do nothing
- 1: discounted products
- 2: same price.
What do you think?
Thank you!
Hi,
Sure - for the form (admin/voucher_codes_edit.php) replace the call to widget_checkBox() with a call to widget_selectArray as follows:
widget_selectArray("Not Discounted","not_discounted",FALSE,(isset($_POST["not_discounted"]) ? $_POST["not_discounted"] : ""),array("0"=>"N/A","1"=>"Discounted","2"=>"Same Price"));
And then in the application code (includes/tapestry.php) replace with:
$isValid = TRUE;
if ($isValid)
{
if (
($voucher["not_discounted"]==1)
&&
($product["price"] < $product["price_old"])
)
{
$isValid = FALSE;
}
}
if ($isValid)
{
if (
($voucher["not_discounted"]==2)
&&
($product["price"] != $product["price_old"])
)
{
$isValid = FALSE;
}
}
And the code you added to search.php REPLACE with:
if ($voucher["not_discounted"]==1)
{
$where .= " AND price < price_old ";
}
elseif ($voucher["not_discounted"]==2)
{
$where .= " AND price = price_old ";
}
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Thank you!
Probable you mean ($product["price"] == $product["price_old"]) when not_discounted = 1? Am I correct?
$isValid = TRUE;
if ($isValid)
{
if (
($voucher["not_discounted"]==1)
&&
($product["price"] == $product["price_old"])
)
{
$isValid = FALSE;
}
}
if ($isValid)
{
if (
($voucher["not_discounted"]==2)
&&
($product["price"] != $product["price_old"])
)
{
$isValid = FALSE;
}
}
Hi,
Using "==" would be fine but would mean the code would also apply if the new price is higher, that's all. If the code would still apply in this case then as well as that change the WHERE clause added in search.php for when discounted is 1 would need to be correspondingly;
$where .= " AND price <> price_old ";
Cheers,
David.
--
PriceTapestry.com
Hi David.
I need another tweak.
How can I add a new field in "Discount Type" so the % discount is applied to my field "price_old" rather than normal price?
Thank you!
Hi,
You could add an option "%O" for "percent old"; to give this a go edit admin/voucher_codes_edit.php and look for the following code at line 425:
$discount_types = array("#"=>html_entity_decode($config_currencyHTML,ENT_QUOTES,$config_charset),"%"=>"%","S"=>"Other");
...and REPLACE with:
$discount_types = array("#"=>html_entity_decode($config_currencyHTML,ENT_QUOTES,$config_charset),"%"=>"%","%O"=>"%O","S"=>"Other");
Then edit includes/tapestry.php and look for the following code at line 227:
elseif ($voucher["discount_type"]=="%")
...and REPLACE with:
elseif (($voucher["discount_type"]=="%") || ($voucher["discount_type"]=="%O"))
And finally look for the following code at line 256:
$products[$k]["price"] = $product["discount_price"];
...and REPLACE with:
if ($voucher["discount_type"] == "%O")
{
$products[$k]["price_old"] = $product["discount_price"];
}
else
{
$products[$k]["price"] = $product["discount_price"];
}
Cheers,
David.
--
PriceTapestry.com
Hi,
It's straight forward to make a Duplicate function which will save having to copy and paste - to do this, create a new file admin/voucher_codes_duplicate.php containing:
<?php
require("../includes/common.php");
$admin_checkPassword = TRUE;
require("../includes/admin.php");
$sql = "DESC `".$config_databaseTablePrefix."vouchers`";
database_querySelect($sql,$rows);
array_shift($rows);
$fields = array();
foreach($rows as $row)
{
$fields[] = $row["Field"];
}
$fieldList = implode(",",$fields);
$id = $_GET["id"];
$sql = "INSERT INTO `".$config_databaseTablePrefix."vouchers` (".$fieldList.") SELECT ".$fieldList." FROM `".$config_databaseTablePrefix."vouchers` WHERE id='".database_safe($id)."'";
database_queryModify($sql,$insertId);
header("Location: voucher_codes_edit.php?id=".$insertId);
exit();
?>
Then edit admin/voucher_codes.php and look for the following code at line 234:
admin_tool("Delete","voucher_codes_delete.php?id=".$voucher["id"],TRUE,FALSE);
...and REPLACE with:
admin_tool("Delete","voucher_codes_delete.php?id=".$voucher["id"],TRUE,FALSE);
admin_tool("Duplicate","voucher_codes_duplicate.php?id=".$voucher["id"],TRUE,FALSE);
Hope this helps!
Cheers,
David.
--
PriceTapestry.com