You are here:  » View products when more than one Voucher Code is available


View products when more than one Voucher Code is available

Submitted by richard on Tue, 2016-07-19 13:27 in

Hi David,

I have just discovered yet again how PT is so clever! I see that PT calculates, if there is more than one voucher, the best saving and offers the appropriate voucher code.

Currys has a number of voucher codes available at the moment e.g offering either £40 off if over £499 or a 10% off if over £299. In this scenario, the 10% off will always be superior to the £40 off offer.

if I look at vouchers.php I see a list of all vouchers available but when I click on the £40 off offer there are no products as the 10% offer is taking precedent.

I don't know how often this scenario could prevail but have you already developed a work around?

Best regards

Richard

Submitted by support on Tue, 2016-07-19 13:54

Hi Richard,

Thank you for your comments!

Sure - if using voucher code integration level 2, so that discounts are calculated at import time and the `voucher_code` field on the products table populated, then vouchers.php can be modified to only show active voucher codes in this scenario. Look for the following code at line 6:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."vouchers` WHERE ( (valid_from < '".$now."' AND valid_to = '0') OR (valid_from <= '".$now."' AND valid_to > '".$now."') ) ORDER BY merchant";

...and REPLACE with:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."vouchers` WHERE ( (valid_from < '".$now."' AND valid_to = '0') OR (valid_from <= '".$now."' AND valid_to > '".$now."') ) AND code IN (SELECT DISTINCT(voucher_code) FROM `".$config_databaseTablePrefix."products`) ORDER BY merchant";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by philstone on Fri, 2016-07-22 06:59

Hi David

Trust all is well

I have found that sometimes vouchers given by merchants don't work for users, is there a way to show all voucher codes that may be used against a product (in the description column) but keeping the best one to be used in the price column?

or even on the vouchers.php page making it possible to view all relevant products under all codes and not the just the best code?

regards

Phil Stone

Submitted by support on Fri, 2016-07-22 10:07

Hi Phil,

I'm currently reviewing the voucher code functionality for the next distribution so I will keep this in mind. Because of the current architecture being specifically designed around deriving the best code to use this would become quite complicated I'm afraid, with a different implementation depending on voucher code integration level.

However if using voucher codes integration level 1 it is straight forward to get a list of all codes that could apply to a product, and display this below the catalogue product name in the price comparison table, so if you'd like to give this a go, first edit includes/tapestry.php and look for the following code at line 115:

  function tapestry_applyVoucherCodes($products)

...and REPLACE with:

  function tapestry_applyVoucherCodes($products,$all=FALSE)

Then look for the following code at line 237:

  if (
     ($discountPrice <= $product["discount_price"])
     )

...and REPLACE with:

  if ($all)
  {
    $all_voucher_code = $voucher["code"];
    if ($voucher["discount_text"])
    {
      $all_voucher_code .= " (".$voucher["discount_text"].")";
    }
    $products[$k]["all_voucher_codes"][] = $all_voucher_code;
  }
  if (
     ($discountPrice <= $product["discount_price"])
     )

And then in html/prices.php look for the following code at line 57:

  <td class='hide-for-small-only'><?php print $product["original_name"]; ?></td>

...and REPLACE with:

  <td class='hide-for-small-only'>
  <?php print $product["original_name"]; ?>
  <?php
    $p = tapestry_applyVoucherCodes(array($product),TRUE);
    if (count($p[0]["all_voucher_codes"]))
    {
      print "<br /><strong>Voucher codes that may be used with this product:</strong><br />";
      print implode(",",$p[0]["all_voucher_codes"]);
    }
  ?>
  </td>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by philstone on Fri, 2016-07-22 15:04

Thanks for this David

I will give this a go!

regards

Phil Stone