Skip to content

Instantly share code, notes, and snippets.

@shofetim
Created March 4, 2013 18:15
Show Gist options
  • Select an option

  • Save shofetim/5084226 to your computer and use it in GitHub Desktop.

Select an option

Save shofetim/5084226 to your computer and use it in GitHub Desktop.
def _price(product, level):
if product.is_priced_by_weight:
price_obj = product.sell_price_per_pound(level)
else:
price_obj = product.sell_price(level)
amount, off = price_obj
if off == False:
off = ""
try:
amount = float(amount)
if amount:
if product.is_priced_by_weight:
price = "$%s per lb." % intcomma(floatformat(amount,2))
else:
price = "$%s" % intcomma(floatformat(amount,2))
if amount > 0 and off != "":
return "<nobr>%s %s%% off</nobr>" % (price, off)
elif amount > 0:
return price
else:
return "<span class='negative_amount'>%s</span>" % price
except:
print "Couldn't get price for %s" % [product]
return "$0.00"
def current_users_price(product, customer=False):
price_level = customer.price_level if customer else RETAIL
if product.is_priced_by_weight:
price_obj = product.sell_price_per_pound(price_level)
else:
price_obj = product.sell_price(price_level)
amount, off = price_obj
if off == False:
off = ""
try:
amount = float(amount)
if amount:
if product.is_priced_by_weight:
price = "$%s per lb." % intcomma(floatformat(amount,2))
else:
price = "$%s" % intcomma(floatformat(amount,2))
if amount > 0 and off != "":
return mark_safe("<nobr>%s %s%% off</nobr>" % (price, off))
elif amount > 0:
return price
else:
return mark_safe("<span class='negative_amount'>%s</span>" % price)
except:
pass
return "$0.00"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment