You're kind of mimicking the _order_totals function which gets used in
template tags:

https://github.com/stephenmcd/cartridge/blob/master/cartridge/shop/templatetags/shop_tags.py#L34

You could probably do something like:

from cartridge.shop.templatetags.shop_tags import _order_totals
order_vars = _order_totals({"request": request})
print order_vars["order_total"]

On Wed, May 27, 2015 at 6:01 PM, Wesley <nisp...@gmail.com> wrote:

> Hi,
>   I am trying to get this guy jus in a regular view.
> My scenario is:
>  Within checkout confirmation page, when click on 'next' to complete the
> order, raises a ajax request to a regular view to do something,and in this
> view function(only request available) I need ordr total.
> But, currently in the confirmation page, order is not setup or saved, so
> no order object available now.
>
> BTW, you mentioned, combine request.session["shipping_total"] and
> request.cart.total_price(), then, what about tax and discount, these two
> guys cover the latter two valuation?
>
> Currently, I use the following snippet to get the total price(changed the
> source code, so it's not a good idea...), don't know if it's exactly
> correct but haven't hit any issue yet:
> Model Order:
> def get_tmp_total(self, request):
>         """
>         added by wni.
>         for weixin pay, on confirm page, need to get total for weixin
> order creation.
>         """
>         #self.key = request.session.session_key
>         #self.user_id = request.user.id
>         for field in self.session_fields:
>             if field in request.session:
>                 setattr(self, field, request.session[field])
>         total = request.cart.total_price()
>         if self.shipping_total is not None:
>             total += Decimal(str(self.shipping_total))
>         if self.discount_total is not None:
>             total -= Decimal(self.discount_total)
>         if self.tax_total is not None:
>             total += Decimal(self.tax_total)
>         return total
>
> In view function:
> tmp_order = form.save(commit=False)
> request.session['wni_wxpay_total'] = tmp_order.get_tmp_total(request)
>
> Wesey
>
> Hi,
>>
>> Where are you trying to get this value? Is it a step handler like
>> SHOP_HANDLER_PAYMENT or SHOP_HANDLER_ORDER? Or a regular view?
>>
>> If you have an order object then it should be available in order.total,
>> given that you are “far enought” in the checkout process so it has been
>> computed. If you just have a request, try request.session["shipping_total"]
>> combined with request.cart.total_price().
>>
>>
>>
>> Le mercredi 27 mai 2015 13:49:51 UTC+2, Wesley a écrit :
>>>
>>> Sorry missing one that:
>>> I am trying to get the price from checkout confirmation page, I mean,
>>> when click "Next" on the page.
>>>
>>>
>>> Hi guys,
>>>>    In one of my views function, I wanna get final total price of the
>>>> order.
>>>>
>>>> I tried to get from request.session['order']['total'] or
>>>> request.session['cart']['something'] but all failed.
>>>>
>>>> I print order and cart getting this sample:
>>>> order is:
>>>> {'card_name': u'', u'delivery_type': u'', 'remember': True, 'pay_type':
>>>> u'\u5fae\u4fe1\u652f\u4ed8', 'billing_detail_street': u'\u6d4b\u8bd5',
>>>> 'shipping_detail_first_name': u'\u502a\u6770', 'shipping_detail_street':
>>>> u'\u6d4b\u8bd5', u'additional_instructions': u'', 'card_type': u'', 'step':
>>>> 2, 'same_billing_shipping': True, u'prefer_time':
>>>> u'\u7acb\u5373\u9001\u9910', 'shipping_detail_phone': u'11211',
>>>> 'billing_detail_email': u'whatever here', 'billing_detail_phone': u'11211',
>>>> 'billing_detail_first_name': u'\u502a\u6770'}
>>>>
>>>> cart is:544
>>>>
>>>> So, no something like 'total' in order object, and cart is id.
>>>>
>>>> Maybe I can get price to query database according to the cart's id, but
>>>> is there any easy way to get the total price?
>>>>
>>>> Thanks.
>>>> Wesley
>>>>
>>>  --
> You received this message because you are subscribed to the Google Groups
> "Mezzanine Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mezzanine-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Stephen McDonald
http://jupo.org

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to