Skip to content

Instantly share code, notes, and snippets.

@rgraff
Created April 23, 2009 18:49
Show Gist options
  • Save rgraff/100683 to your computer and use it in GitHub Desktop.
Save rgraff/100683 to your computer and use it in GitHub Desktop.
Price Range Requirements/Algorithm:
===================================
The price ranges for an offergroup are determined by:
if offergroup has offersets with status 'open' or 'expired' and 1 offer with quantity > 0:
Using only those offersets, find offers that have quantity available:
if any offers have quantity available:
Using those offers, calculate price ranges
replace '$0.00' with 'FREE' in ourprice range
else:
Using all offers with quantity > 0 (from the offersets that are 'open' or 'expired')
calculate price ranges
override ourprice to 'SOLD OUT'
else if offergroup has offersets with status 'closed' and 1 offer with quantity > 0:
Using only those offersets:
calculate price ranges from offers with quantity > 0
replace '$0.00' with 'FREE' in ourprice range
else:
ourprice and fullprice are 'n/a'
Subroutines:
============
Quantity Available is:
offer.quantity minus the sum of claims.quantity WHERE status = 'completed'
Calculate price ranges:
Give a set of offers:
For ourprice and fullprice:
Find the lowest and highest value.
If lowest == highest:
price range is either in currency format (e.g. "$9.00")
else:
price range is lowest - highest in currency format (e.g. "$7.00 - $9.00")
Notes:
======
The string 'SOLD OUT' is used by the mailer daemon as a flag to skip that offergroup.
The string 'n/a' is used instead of an empty string to prevent constant cache rebuilds. An empty string would mean that the range needs to be calculated.
Offers with quantity == 0 should not be considered for any price range unless they are the child offer (i.e. shared inventory).
Updates:
========
on edit to any offerset or offer of offergroup
on claims becoming completed or cancelled for any offer of offergroup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment