why does {{ product|discount_price:sale|currency }} return an error?

26 views
Skip to first unread message

easypie

unread,
Mar 27, 2012, 4:27:05 PM3/27/12
to satchm...@googlegroups.com
Why does {{ product|discount_price:sale|currency }} return an error in shop/index.html template? I wanted the product thumbnail to also include the price listed below it. But there is an error?

here's a link to the template: dpaste.com/722410

Olivier Lauret

unread,
Mar 27, 2012, 4:52:30 PM3/27/12
to satchm...@googlegroups.com

Can you share with us the error message?

This might give us a hint.

On Mar 27, 2012 9:27 PM, "easypie" <progr...@gmail.com> wrote:
Why does {{ product|discount_price:sale|currency }} return an error in shop/index.html template? I wanted the product thumbnail to also include the price listed below it. But there is an error?

here's a link to the template: dpaste.com/722410

--
You received this message because you are subscribed to the Google Groups "Satchmo users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/satchmo-users/-/E29WNHCJgxYJ.
To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.

easypie

unread,
Mar 27, 2012, 5:10:32 PM3/27/12
to satchm...@googlegroups.com
sure. here's the error: dpaste.com/722438/


On Tuesday, March 27, 2012 1:52:30 PM UTC-7, olauret wrote:

Can you share with us the error message?

This might give us a hint.

On Mar 27, 2012 9:27 PM, "easypie" <progr...@gmail.com> wrote:
Why does {{ product|discount_price:sale|currency }} return an error in shop/index.html template? I wanted the product thumbnail to also include the price listed below it. But there is an error?

here's a link to the template: dpaste.com/722410

--
You received this message because you are subscribed to the Google Groups "Satchmo users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/satchmo-users/-/E29WNHCJgxYJ.
To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-users+unsubscribe@googlegroups.com.

hynekcer

unread,
Mar 28, 2012, 4:23:26 AM3/28/12
to Satchmo users
do you mean a general sale?
{{ product|discount_price:storewide_sale|currency }}
or you should not use "sale" outside of block
{% if sale %}... something with sale
{% endif %}

-- Hy

On 27 bře, 23:10, easypie <program...@gmail.com> wrote:
> sure. here's the error: dpaste.com/722438/
>
>
>
>
>
>
>
> On Tuesday, March 27, 2012 1:52:30 PM UTC-7, olauret wrote:
>
> > Can you share with us the error message?
>
> > This might give us a hint.
> > On Mar 27, 2012 9:27 PM, "easypie" <program...@gmail.com> wrote:
>
> >> Why does {{ product|discount_price:sale|currency }} return an error in
> >> shop/index.html template? I wanted the product thumbnail to also include
> >> the price listed below it. But there is an error?
>
> >> here's a link to the template: dpaste.com/722410
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Satchmo users" group.
> >> To view this discussion on the web visit
> >>https://groups.google.com/d/msg/satchmo-users/-/E29WNHCJgxYJ.
> >> To post to this group, send email to satchm...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> satchmo-user...@googlegroups.com.

Olivier Lauret

unread,
Mar 28, 2012, 4:24:01 AM3/28/12
to satchm...@googlegroups.com
Hi,

I had this problem as well. It is related, as you probably realised, to the sale key which is not part of your Request Context. I found a solution but it is at the moment very inefficient. Maybe, someone else can help with something better.

Here is what I have done:

*******************************************************************
from product.utils import find_best_auto_discount

def shop(request, template="shop/shop_base.html"):
    [...]
    Prod = Product.objects.all()
    [...]
    best_discount = find_best_auto_discount(list(Prod))
   
    myDict = {
        'all_products_list' : page.object_list,       
        'is_paginated' : is_paged,
        'page_obj' : page,
        'paginator' : paginator,
        'sale' : best_discount,
    }
    ctx=RequestContext(request, myDict)
    return render_to_response(template, context_instance=ctx)
*******************************************************************

Hope this helps.
Regards,
Olivier

To view this discussion on the web visit https://groups.google.com/d/msg/satchmo-users/-/uVJa8t2TGtEJ.

To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.

hynekcer

unread,
Mar 28, 2012, 8:09:52 AM3/28/12
to Satchmo users
You probably want to use

{{ product|untaxed_sale_price|currency }}

where "untaxed_sale_price" internally calls "find_best_auto_discount"
for the product.

All three filters:
discount_price, taxed_discount_price, untaxed_discount_price
are useful _only_ if you want to give a discount for all products to
some users or on some day and you should combine them with signals
from checkout, to be consistent. Autodiscounts are cleaner.

It is related to discussion about the following problem and to
resolution that global context variable "sale" has been renamed to
"storewide_sale".
https://bitbucket.org/chris1610/satchmo/issue/1171/satchmo_storeshopcontext_processorssetting

Oliver, is your example really useful?
If "find_best_auto_discount" is applied to a set, it should be
carefully.
Example: You have two products A B with autodiscounts.
A, $1000, 10%
B, $10, 75%
Is really 75% the best you want for both??
find_best_auto_discount([A, B]) yes you see big fat printed 75%
today, but really?

The most interesting proposals to discounts are in "discounts
brainstorming"
issues #1351, #1352, #1381 (probably much more than is desirable)

--Hy

On 28 bře, 10:24, Olivier Lauret <olivier.lau...@googlemail.com>
wrote:
> Le 27 mars 2012 22:10, easypie <program...@gmail.com> a écrit :
>
>
>
>
>
>
>
> > sure. here's the error: dpaste.com/722438/
>
> > On Tuesday, March 27, 2012 1:52:30 PM UTC-7, olauret wrote:
>
> >> Can you share with us the error message?
>
> >> This might give us a hint.
> >> On Mar 27, 2012 9:27 PM, "easypie" <program...@gmail.com> wrote:
>
> >>> Why does {{ product|discount_price:sale|**currency }} return an error
> >>> in shop/index.html template? I wanted the product thumbnail to also include
> >>> the price listed below it. But there is an error?
>
> >>> here's a link to the template: dpaste.com/722410
>
> >>>  --
> >>> You received this message because you are subscribed to the Google
> >>> Groups "Satchmo users" group.
> >>> To view this discussion on the web visithttps://groups.google.com/d/**
> >>> msg/satchmo-users/-/**E29WNHCJgxYJ<https://groups.google.com/d/msg/satchmo-users/-/E29WNHCJgxYJ>
> >>> .
> >>> To post to this group, send email to satchm...@googlegroups.com**.
> >>> To unsubscribe from this group, send email to satchmo-users+unsubscribe@
> >>> **googlegroups.com <satchmo-users%2Bunsu...@googlegroups.com>.
> >>> For more options, visit this group athttp://groups.google.com/**
> >>> group/satchmo-users?hl=en<http://groups.google.com/group/satchmo-users?hl=en>
> >>> .

Olivier Lauret

unread,
Mar 29, 2012, 4:06:50 AM3/29/12
to satchm...@googlegroups.com
Hi Hy,

Thank you for clarifying it. Indeed, I didn't see it that way. I will change it accordingly and test it correctly this time.

Thank you.
Regards,
Olivier
Reply all
Reply to author
Forward
0 new messages