You are here:  » Same voucher code with different MOV & Discount


Same voucher code with different MOV & Discount

Submitted by sirmanu on Tue, 2019-09-24 13:57 in

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

Submitted by support on Wed, 2019-09-25 10:26

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

Submitted by sirmanu on Fri, 2019-09-27 09:40

This is awesome!!!
Thank you very much David

Submitted by sirmanu on Fri, 2019-11-29 10:56

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

Submitted by support on Fri, 2019-11-29 11:08

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

Submitted by sirmanu on Fri, 2019-11-29 12:12

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?

Submitted by support on Fri, 2019-11-29 14:55

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

Submitted by sirmanu on Fri, 2019-11-29 15:39

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.

Submitted by support on Fri, 2019-11-29 15:56

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

Submitted by sirmanu on Sat, 2019-11-30 17:17

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 ";
            }

Submitted by sirmanu on Mon, 2020-09-14 10:03

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!

Submitted by support on Mon, 2020-09-14 11:16

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

Submitted by sirmanu on Mon, 2020-09-14 16:39

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;
  }
}

Submitted by support on Tue, 2020-09-15 06:22

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