def view_cart_esi(cls): """Returns a view of the shopping cart Similar to :meth:view_cart but for ESI """ cart = cls.open_cart() return current_app.response_class( render_template("shopping-cart-esi.jinja", cart=cart), headers=[("Cache-Control", "max-age=0")] )
def view_cart(cls): """Returns a view of the shopping cart This method only handles GET. Unlike previous versions the checkout method has been moved to nereid.checkout.x For XHTTP/Ajax Requests a JSON object with order and lines information which should be sufficient to show order information is returned. """ cart = cls.open_cart() if request.is_xhr: if not cart.sale: # Dont try to build further if the cart is empty return jsonify({"empty": True}) # Build locale formatters currency_format = partial( numbers.format_currency, currency=cart.sale.currency.code, locale=request.nereid_language.code ) number_format = partial(numbers.format_number, locale=request.nereid_language.code) return jsonify( cart={ "lines": [ { "product": l.product.name, "quantity": number_format(l.quantity), "unit": l.unit.symbol, "unit_price": currency_format(l.unit_price), "amount": currency_format(l.amount), } for l in cart.sale.lines ], "empty": len(cart.sale.lines) > 0, "total_amount": currency_format(cart.sale.total_amount), "tax_amount": currency_format(cart.sale.tax_amount), "untaxed_amount": currency_format(cart.sale.untaxed_amount), } ) return current_app.response_class( render_template("shopping-cart.jinja", cart=cart), headers=[("Cache-Control", "max-age=0")] )