def action_pay(self, resource, context, form): from orders import Order cart = ProductCart(context) root = context.root # Check if cart is valid if not cart.is_valid(): return context.come_back(CART_ERROR, goto='/') # Calcul total price total_price_with_tax = decimal(0) total_price_without_tax = decimal(0) total_weight = decimal(0) for cart_elt in cart.products: product = context.root.get_resource(cart_elt['name']) quantity = cart_elt['quantity'] declination = cart_elt['declination'] unit_price_with_tax = product.get_price_with_tax(declination) unit_price_without_tax = product.get_price_without_tax(declination) total_price_with_tax += unit_price_with_tax * quantity total_price_without_tax += unit_price_without_tax * quantity total_weight += product.get_weight(declination) * quantity # Get Shipping price shipping_price = cart.get_shipping_ns(resource, context)['price'] total_price_with_tax += shipping_price total_price_without_tax += shipping_price # Arrondi total_price_with_tax = get_arrondi(total_price_with_tax) total_price_without_tax = get_arrondi(total_price_without_tax) # Guess ref number # We take last order name + 1 search = root.search(format='order') orders = search.get_documents(sort_by='creation_datetime', reverse=True) if orders: ref = str(int(orders[0].name) + 1) else: ref = '1' # We create a new order kw = {'user': context.user, 'payment_mode': form['payment'], 'shipping_price': shipping_price, 'total_price': total_price_with_tax, 'total_weight': total_weight, 'cart': cart, 'shop': resource, 'shop_uri': context.uri.resolve('/')} orders = resource.get_resource('orders') order = Order.make_resource(Order, orders, ref, title={'en': u'#%s' % ref}, **kw) # We clear the cart cart.clear() # We show the payment form kw = {'ref': ref, 'amount': total_price_with_tax, 'amount_without_tax': total_price_without_tax, 'resource_validator': str(order.get_abspath()), 'mode': form['payment']} payments = resource.get_resource('payments') return payments.show_payment_form(context, kw)
def action_pay(self, resource, context, form): from orders import Order cart = ProductCart(context) root = context.root # Check if cart is valid if not cart.is_valid(): return context.come_back(CART_ERROR, goto='/') # Calcul total price total_price_with_tax = decimal(0) total_price_without_tax = decimal(0) total_weight = decimal(0) for cart_elt in cart.products: product = context.root.get_resource(cart_elt['name']) quantity = cart_elt['quantity'] declination = cart_elt['declination'] unit_price_with_tax = product.get_price_with_tax(declination) unit_price_without_tax = product.get_price_without_tax(declination) total_price_with_tax += unit_price_with_tax * quantity total_price_without_tax += unit_price_without_tax * quantity total_weight += product.get_weight(declination) * quantity # Get Shipping price shipping_price = cart.get_shipping_ns(resource, context)['price'] total_price_with_tax += shipping_price total_price_without_tax += shipping_price # Arrondi total_price_with_tax = get_arrondi(total_price_with_tax) total_price_without_tax = get_arrondi(total_price_without_tax) # Guess ref number # We take last order name + 1 search = root.search(format='order') orders = search.get_documents(sort_by='creation_datetime', reverse=True) if orders: ref = str(int(orders[0].name) + 1) else: ref = '1' # We create a new order kw = { 'user': context.user, 'payment_mode': form['payment'], 'shipping_price': shipping_price, 'total_price': total_price_with_tax, 'total_weight': total_weight, 'cart': cart, 'shop': resource, 'shop_uri': context.uri.resolve('/') } orders = resource.get_resource('orders') order = Order.make_resource(Order, orders, ref, title={'en': u'#%s' % ref}, **kw) # We clear the cart cart.clear() # We show the payment form kw = { 'ref': ref, 'amount': total_price_with_tax, 'amount_without_tax': total_price_without_tax, 'resource_validator': str(order.get_abspath()), 'mode': form['payment'] } payments = resource.get_resource('payments') return payments.show_payment_form(context, kw)
def action_clear(self, resource, context, form): cart = ProductCart(context) cart.clear()
def action_clear(self, resource, context, form): cart = ProductCart(context) cart.clear()