From: Benoît Pin Date: Thu, 4 Sep 2014 20:51:23 +0000 (+0200) Subject: Introduction d'un système de remise scriptable. X-Git-Url: https://scm.cri.mines-paristech.fr/git/Portfolio.git/commitdiff_plain/42f8aecd3f2b63a3929bb3a0baf420c6bd47b05f?hp=-c Introduction d'un système de remise scriptable. --- 42f8aecd3f2b63a3929bb3a0baf420c6bd47b05f diff --git a/skins/my_cart.py b/skins/my_cart.py index f305a1e..e12acec 100755 --- a/skins/my_cart.py +++ b/skins/my_cart.py @@ -22,127 +22,133 @@ form = context.REQUEST.form nextStep = None if cart.locked : - pendingOrder = context.restrictedTraverse(cart.pendingOrderPath) - return context.setRedirect(pendingOrder, 'object/view', ajax=form.get('ajax')) + pendingOrder = context.restrictedTraverse(cart.pendingOrderPath) + return context.setRedirect(pendingOrder, 'object/view', ajax=form.get('ajax')) if order : - if isAnon : - atool = portal.portal_actions - came_from = '%s/my_cart' % portal_url - return context.setRedirect(atool, 'customer/login', came_from=came_from, ajax=form.get('ajax')) + if isAnon : + atool = portal.portal_actions + came_from = '%s/my_cart' % portal_url + return context.setRedirect(atool, 'customer/login', came_from=came_from, ajax=form.get('ajax')) if shipping : - member = mtool.getAuthenticatedMember() - options['shipping_fullname'] = member.getMemberFullName(nameBefore=0) - options['shipping_address'] = member.getProperty('billing_address') - options['shipping_city'] = member.getProperty('billing_city') - options['shipping_zipcode'] = member.getProperty('billing_zipcode') - options['shipping_country'] = member.getProperty('country') - return context.shipping_template(**options) + member = mtool.getAuthenticatedMember() + options['shipping_fullname'] = member.getMemberFullName(nameBefore=0) + options['shipping_address'] = member.getProperty('billing_address') + options['shipping_city'] = member.getProperty('billing_city') + options['shipping_zipcode'] = member.getProperty('billing_zipcode') + options['shipping_country'] = member.getProperty('country') + return context.shipping_template(**options) if set_shipping : - fg = lambda name : form.get(name,'').strip() - if context.shipping_set_control(**form) : - order = pptool.addPrintOrder(cart) - return context.setRedirect(order, 'object/view', ajax=fg('ajax')) - else : - for name in [ 'shipping_fullname' - , 'shipping_address' - , 'shipping_city' - , 'shipping_zipcode' - , 'shipping_country'] : - options[name] = fg(name) - return context.shipping_template(**options) + fg = lambda name : form.get(name,'').strip() + if context.shipping_set_control(**form) : + order = pptool.addPrintOrder(cart) + return context.setRedirect(order, 'object/view', ajax=fg('ajax')) + else : + for name in [ 'shipping_fullname' + , 'shipping_address' + , 'shipping_city' + , 'shipping_zipcode' + , 'shipping_country'] : + options[name] = fg(name) + return context.shipping_template(**options) if isAnon : - nextStep = {'name':'order', 'value' : _('Order >>')} + nextStep = {'name':'order', 'value' : _('Order >>')} else : - nextStep = {'name':'shipping', 'value' : _('Shipping >>')} - + nextStep = {'name':'shipping', 'value' : _('Shipping >>')} + msg = '' for k, v in form.items() : - if hasattr(v, 'items') : - uid, templateId = k.split('_',1) - if v.has_key('refresh') : - quantity = v['quantity'] - try : - quantity = int(quantity) - except ValueError: - msg = _('You must enter an integer for quantity (found: %s)') % quantity - if quantity <= 0 : - msg = _('You must enter a positive value for quantity (found: %s)') % quantity - if not msg : - item = {'cmf_uid' : uid - ,'printing_template' : templateId - ,'quantity' : quantity} - try : - cart.update(context, item) - except SoldOutError, e : - n = e.n - if n > 1 : - msg = _("Only %d available copies of this photo in this size.") % n - elif n == 1 : - msg = _("Only one last available copy of this photo in this size.") - else : - msg = _("No more available copy of this photo and in this size.") - - - if v.has_key('delete'): - cart.remove(context, uid, templateId) + if hasattr(v, 'items') : + uid, templateId = k.split('_',1) + if v.has_key('refresh') : + quantity = v['quantity'] + try : + quantity = int(quantity) + except ValueError: + msg = _('You must enter an integer for quantity (found: %s)') % quantity + if quantity <= 0 : + msg = _('You must enter a positive value for quantity (found: %s)') % quantity + if not msg : + item = {'cmf_uid' : uid + ,'printing_template' : templateId + ,'quantity' : quantity} + try : + cart.update(context, item) + except SoldOutError, e : + n = e.n + if n > 1 : + msg = _("Only %d available copies of this photo in this size.") % n + elif n == 1 : + msg = _("Only one last available copy of this photo in this size.") + else : + msg = _("No more available copy of this photo and in this size.") + + + if v.has_key('delete'): + cart.remove(context, uid, templateId) options['empty'] = not cart infos = [] prices = [] quantityTotal = 0 for item in cart : - b = uidh.getBrain(item['cmf_uid']) - poptions = pptool.getPrintingOptionsContainerFor(b.getObject()) - pt = getattr(poptions, item['printing_template']) - size = b.getThumbnailSize - d = {'thumbUrl' : '%s/getThumbnail' % b.getURL() - ,'thumbHeight' : size['height'] / 2 - ,'thumbWidth' : size['width'] / 2 - ,'alt' : ('%s - %s' % (b.Title, b.Description)).strip(' -') - ,'cmf_uid':b.cmf_uid - ,'title': pt.title - ,'description': pt.description - ,'quantity':item['quantity'] - ,'amount': '%s €' % (pt.price * item['quantity']).taxed - ,'templateId': pt.getId() - } - quantityTotal += item['quantity'] - prices.append(pt.price * item['quantity']) - infos.append(d) + b = uidh.getBrain(item['cmf_uid']) + poptions = pptool.getPrintingOptionsContainerFor(b.getObject()) + pt = getattr(poptions, item['printing_template']) + size = b.getThumbnailSize + d = {'thumbUrl' : '%s/getThumbnail' % b.getURL() + ,'thumbHeight' : size['height'] / 2 + ,'thumbWidth' : size['width'] / 2 + ,'alt' : ('%s - %s' % (b.Title, b.Description)).strip(' -') + ,'cmf_uid':b.cmf_uid + ,'title': pt.title + ,'description': pt.description + ,'quantity':item['quantity'] + ,'amount': '%s €' % (pt.price * item['quantity']).taxed + ,'templateId': pt.getId() + } + quantityTotal += item['quantity'] + prices.append(pt.price * item['quantity']) + infos.append(d) options['infos'] = infos if len(prices) == 1: - pricesTotal = prices[0] + pricesTotal = prices[0] elif len(prices) > 1 : - pricesTotal = reduce(lambda a, b : a + b, prices) + pricesTotal = reduce(lambda a, b : a + b, prices) + if prices : - options['pricesTotal'] = pricesTotal - options['quantityTotal'] = quantityTotal - shippingFees = pptool.getShippingFeesFor(price=pricesTotal) - options['shippingFees'] = shippingFees - options['totalAmount'] = pricesTotal + shippingFees + options['pricesTotal'] = pricesTotal + options['quantityTotal'] = quantityTotal + discount = 0 + if context.get('photoprint_discount') : + discount = context.photoprint_discount(pricesTotal, quantityTotal) + options['discount'] = discount + shippingFees = pptool.getShippingFeesFor(price=pricesTotal) + options['shippingFees'] = shippingFees + coeff = (100 - discount) / 100. + options['totalAmount'] = pricesTotal * coeff + shippingFees breadcrumbs = [ - { 'id' : 'root' - , 'title' : portal.title - , 'url' : portal_url}, + { 'id' : 'root' + , 'title' : portal.title + , 'url' : portal_url}, - {'id' : 'my_cart' - ,'title' : _('My cart') - , 'url' : '%s/my_cart' % portal_url} - ] + {'id' : 'my_cart' + ,'title' : _('My cart') + , 'url' : '%s/my_cart' % portal_url} + ] options['breadcrumbs'] = breadcrumbs if msg : - context.REQUEST.other['portal_status_message'] = msg + context.REQUEST.other['portal_status_message'] = msg options['cartIsOrder'] = False options['nextStep'] = nextStep return context.my_cart_template(**options) diff --git a/skins/my_cart_template.pt b/skins/my_cart_template.pt index b05a499..bdafd8c 100644 --- a/skins/my_cart_template.pt +++ b/skins/my_cart_template.pt @@ -76,6 +76,11 @@ prices total
+ + Discount + % +
+ Shipping 2