You are here:  » Maximum Price - Voucher Code


Maximum Price - Voucher Code

Submitted by philstone on Mon, 2017-11-06 09:59 in

Hi David

Hope all is well

I'm finding more and more voucher codes are using a minimum to maximum price brackets, would it be hard to add on a maximum price field to voucher codes if required?

Regards

Phil

Submitted by support on Mon, 2017-11-06 11:46

Hello Phil,

Sure - first create and run the following dbmod.php script from the top level folder of your Price Tapestry installation;

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."vouchers` ADD max_price DECIMAL(10,2) NOT NULL DEFAULT '0.00'";
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Next edit admin/voucher_codes.php and look for the following code at line 210:

    print "<th>".translate("Minimum Spend")."</th>";

...and REPLACE with:

    print "<th>".translate("Minimum Spend")."</th>";
    print "<th>".translate("Maximum Spend")."</th>";

And then the following code at line 254:

      print "<td class='pta_num'>".($voucher["min_price"]=="0.00"?"-":$config_currencyHTML.$voucher["min_price"])."</td>";

...and REPLACE with:

      print "<td class='pta_num'>".($voucher["min_price"]=="0.00"?"-":$config_currencyHTML.$voucher["min_price"])."</td>";
      print "<td class='pta_num'>".($voucher["max_price"]=="0.00"?"-":$config_currencyHTML.$voucher["max_price"])."</td>";

Edit admin/voucher_codes_edit.php and look for the following code at line 77:

    widget_validate("min_price",FALSE,"numeric");

...and REPLACE with:

    widget_validate("min_price",FALSE,"numeric");
    widget_validate("max_price",FALSE,"numeric");

And then the following code at line 85:

    if(($_POST["min_price"] == "") && ($_POST["match_value"] == ""))

...and REPLACE with:

    if(($_POST["min_price"] == "") && ($_POST["max_price"] == "") && ($_POST["match_value"] == ""))

And then the following code at line 133:

      if ($_POST["min_price"] <> "")
      {
        $_POST["min_price"] = tapestry_decimalise($_POST["min_price"]);
      }

...and REPLACE with:

      if ($_POST["min_price"] <> "")
      {
        $_POST["min_price"] = tapestry_decimalise($_POST["min_price"]);
      }
      if ($_POST["max_price"] <> "")
      {
        $_POST["max_price"] = tapestry_decimalise($_POST["max_price"]);
      }

And then the following code at line 160:

                      min_price = '%s',

...and REPLACE with:

                      min_price = '%s',
                      max_price = '%s',

And then the following code at line 173:

                      database_safe($_POST["min_price"]),

...and REPLACE with:

                      database_safe($_POST["min_price"]),
                      database_safe($_POST["max_price"]),

And then the following code at line 415:

      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"] : ""),$config_currencyHTML,6);
      widget_textBox("Maximum Spend","max_price",FALSE,(isset($_POST["max_price"]) ? $_POST["max_price"] : ""),$config_currencyHTML,6);

Edit includes/tapestry.php and look for the following code at line 158:

          $isValid = TRUE;

...and REPLACE with:

          $isValid = TRUE;
          if ($isValid)
          {
            if (
               ($voucher["max_price"] > 0)
               &&
               ($voucher["max_price"] < $product["price"])
               )
            {
              $isValid = FALSE;
            }
          }

Edit search.php and look for the following code at line 211:

            if ($voucher["min_price"])
            {
              $where .= " AND price >= '".database_safe($voucher["min_price"])."' ";
            }

...and REPLACE with:

            if ($voucher["min_price"])
            {
              $where .= " AND price >= '".database_safe($voucher["min_price"])."' ";
            }
            if ($voucher["max_price"])
            {
              $where .= " AND price <= '".database_safe($voucher["max_price"])."' ";
            }

Edit vouchers.php and look for the following code at line 46:

      if ($voucher["min_price"] > 0)
      {
        $vouchers[$k]["text"] .= " ".translate("when you spend")." ".tapestry_price($voucher["min_price"]);
      }

...and REPLACE with:

      if (($voucher["min_price"] > 0) && ($voucher["max_price"] > 0))
      {
        $vouchers[$k]["text"] .= " ".translate("when you spend between")." ".tapestry_price($voucher["min_price"])." ".translate("and")." ".tapestry_price($voucher["max_price"]);
      }
      elseif($voucher["min_price"] > 0)
      {
        $vouchers[$k]["text"] .= " ".translate("when you spend")." ".tapestry_price($voucher["min_price"]);
      }
      elseif($voucher["max_price"] > 0)
      {
        $vouchers[$k]["text"] .= " ".translate("when you spend up to")." ".tapestry_price($voucher["max_price"]);
      }

(will include in the next distribution)

Cheers,
David.
--
PriceTapestry.com

Submitted by philstone on Mon, 2017-11-06 18:23

Thanks David

as always an exhaustive reply and great guidance!

Thanks so much

Phil

Submitted by philstone on Tue, 2017-11-07 19:43

Hi David

This works great but now all the vouchers that don't have max price aren't loading? but if i add a min/max price then re-import they work great?

any ideas?

Thanks

Phil

Submitted by support on Wed, 2017-11-08 10:57

Hello Phil,

There was a logic error in the replacement to includes/tapestry.php, sorry about that - corrected above...

Cheers,
David.
--
PriceTapestry.com