You are here:  » Calculating Discounted Prices


Calculating Discounted Prices

Submitted by ChrisNBC on Thu, 2013-11-07 16:31 in

Hi David,

Hope all is going well.

On my mobile contracts site, I have some merchants who offer cashback/contract discounts. The discounts are included in the merchant feeds usually as a total discount figure. To provide a real comparison, I would ideally like to use a discounted monthly contract price as the price used for comparison purposes.

I wondered if you could suggest if there is any way I can apply a mathematical calculation in a feed filter to arrive at an 'actual cost for comparison' figure which I can then use to replace the value held in the price field in the products table. I will probably also retain the price before discount in a new field so that I can quote both.

Thanks in advance.

Regards

Chris

Submitted by support on Thu, 2013-11-07 16:49

Hello Chris,

This would be reasonably straight forward to plumb in. If you have a custom field `discount` containing a percentage value, and the normal `price` field on the products table is the one you want to discount, then in includes/admin.php look for the following code around line 327:

  $importRecord["price"] = tapestry_decimalise($importRecord["price"]);

...and REPLACE with:

  $importRecord["price"] = tapestry_decimalise($importRecord["price"]);
  // decimalise discount field to remove non-numeric characters e.g. "%" itself
  $importRecord["discount"] = tapestry_decimalise($importRecord["discount"]);
  // apply discount to price if not 0.00
  if ($importRecord["discount"] != "0.00")
  {
    $importRecord["price"] = ($importRecord["price"] * (1-($importRecord["discount"]/100)));
    $importRecord["price"] = tapestry_decimalise($importRecord["price"]);
  }

If you wanted to capture the price ex discount in another new field, say `price_ex` then immediately after the first line of the above mod, add:

  $importRecord["price_ex"] = $importRecord["price"];

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Mon, 2013-12-16 11:23

Hi David,

Hope you had a good weekend.

It's taken me a much longer than I anticipated to get to the point of implementing the above but during all my work on the feed files, I've encountered a problem with the above way of working...In summary, I have found that different merchants present discounts in a number of ways, sometimes the discount is presented as a total GBP discount across the life of the contract, sometimes it's shown as the number of discounted months together with the monthly GBP discount and in some instances the feed shows the pre discount monthly price, the number of discounted months and the total GBP discount across the life of the contract. With so many variations the above won't work. I wondered if you could suggest a way I could maybe implement something along the lines of my original post above?.. basically a filter which would allow calculations?
Would be grateful if you could let me know what you think.

Thanks in advance.
Regards
Chris

Submitted by support on Mon, 2013-12-16 16:29

Hi Chris,

The Voucher Code logic currently applies something similar (looking for %, "off", "minimum spend") so this sort of thing can be done when there are clearly defined rules to look for - and if not then you can always default to "Check Website" under the discount or something along those lines.

What would be handy is if you could compile a list of example `discount` field values and then pop them into an email and I'll check out the similarities and see what could be done...

Cheers,
David.
--
PriceTapestry.com