#NEWLINE# def productvariation_details( product , include_tax , user , create = False ) : #NEWLINE# #INDENT# 'Build the product variation details, for conversion to javascript.\n\n    Returns variation detail dictionary built like so:\n    details = {\n        "OPTION_KEY" : {\n            "SLUG": "Variation Slug",\n            "PRICE" : {"qty" : "$price", [...]},\n            "SALE" : {"qty" : "$price", [...]},\n            "TAXED" : "$taxed price",   # omitted if no taxed price requested\n            "QTY" : 1\n        },\n        [...]\n    }\n    ' #NEWLINE# ignore_stock = config_value ( 'PRODUCT' , 'NO_STOCK_CHECKOUT' ) #NEWLINE# discount = find_best_auto_discount ( product ) #NEWLINE# use_discount = ( discount and ( discount . percentage > 0 ) ) #NEWLINE# if include_tax : #NEWLINE# #INDENT# from tax.utils import get_tax_processor #NEWLINE# taxer = get_tax_processor ( user = user ) #NEWLINE# tax_class = product . taxClass #NEWLINE# #UNINDENT# details = { #NEWLINE# #INDENT# 'SALE' : use_discount , #NEWLINE# #UNINDENT# } #NEWLINE# variations = ProductPriceLookup . objects . filter ( parentid = product . id ) . order_by ( '-price' ) #NEWLINE# if ( variations . count ( ) == 0 ) : #NEWLINE# #INDENT# if create : #NEWLINE# #INDENT# log . debug ( 'Creating price lookup for %s' , product ) #NEWLINE# ProductPriceLookup . objects . smart_create_for_product ( product ) #NEWLINE# variations = ProductPriceLookup . objects . filter ( parentid = product . id ) . order_by ( '-price' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# log . warning ( 'You must run satchmo_rebuild_pricing and add it to a cron-job to run every day, or else the product details will not work for product detail pages.' ) #NEWLINE# #UNINDENT# #UNINDENT# for detl in variations : #NEWLINE# #INDENT# key = detl . key #NEWLINE# if details . has_key ( key ) : #NEWLINE# #INDENT# detail = details [ key ] #NEWLINE# qty = detl . quantity #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# detail = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# detail [ 'SLUG' ] = detl . productslug #NEWLINE# if ( not detl . active ) : #NEWLINE# #INDENT# qty = round_decimal ( '-1.0' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ignore_stock : #NEWLINE# #INDENT# qty = round_decimal ( '10000.0' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# qty = round_decimal ( detl . items_in_stock ) #NEWLINE# #UNINDENT# #UNINDENT# detail [ 'QTY' ] = round_decimal ( qty ) #NEWLINE# detail [ 'PRICE' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if use_discount : #NEWLINE# #INDENT# detail [ 'SALE' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if include_tax : #NEWLINE# #INDENT# detail [ 'TAXED' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if use_discount : #NEWLINE# #INDENT# detail [ 'TAXED_SALE' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# details [ key ] = detail #NEWLINE# #UNINDENT# qtykey = ( '%d' % detl . quantity ) #NEWLINE# price = detl . dynamic_price #NEWLINE# detail [ 'PRICE' ] [ qtykey ] = moneyfmt ( price ) #NEWLINE# if use_discount : #NEWLINE# #INDENT# detail [ 'SALE' ] [ qtykey ] = moneyfmt ( calc_discounted_by_percentage ( price , discount . percentage ) ) #NEWLINE# #UNINDENT# if include_tax : #NEWLINE# #INDENT# tax_price = ( taxer . by_price ( tax_class , price ) + price ) #NEWLINE# detail [ 'TAXED' ] [ qtykey ] = moneyfmt ( tax_price ) #NEWLINE# if use_discount : #NEWLINE# #INDENT# detail [ 'TAXED_SALE' ] [ qtykey ] = moneyfmt ( calc_discounted_by_percentage ( tax_price , detail . percentage ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return details