Understanding the purchase_info_for_product template tag

39 views
Skip to first unread message

dbjax

unread,
Aug 5, 2022, 2:14:15 PM8/5/22
to django-oscar
Hello again

I am trying to understand some code in the detail.html template related to the purchase_info_for_product template tag, and have some basic questions:

What does 'session' represent in this line? Does it represent the request argument or the product argument of the purchase_info_for_product(request, product) function? Or does it represent the PurchaseInfo object returned by the Default strategy?

Further, in this line, I understand that we can write price.excl_tax because excl_tax is an attribute of the Price class in this file. But how can 'session' have a price attribute/ property? Also, what other properties does 'session' have, apart from price and where is this referred to in the source code?

Thanks


Joey Jurjens

unread,
Aug 15, 2022, 4:38:35 PM8/15/22
to django-oscar
Hello dbajax,

Excuse the somewhat late reply, just got back from my vacation!
The session variable represents what your startegy "fetch_for_product" method returns.


The session can have a price attribute because it is the PurchaseInfo linked above. The PurchaseInfo is actually a namedtuple: https://github.com/django-oscar/django-oscar/blob/003e66154c59ce5370644efcb75b0f8eded8a6ad/src/oscar/apps/partner/strategy.py#L14

The named tuple has three "attributes" by default; price, availability, stockrecord. All those attributes are set when returning the PurchaseInfo in the strategy by seperate methods. For price for example, it calls self.pricing_policy: https://github.com/django-oscar/django-oscar/blob/003e66154c59ce5370644efcb75b0f8eded8a6ad/src/oscar/apps/partner/strategy.py#L127

Let me know if you have any other questions!

Joey

Op vrijdag 5 augustus 2022 om 20:14:15 UTC+2 schreef dbjax:

dbjax

unread,
Aug 20, 2022, 10:34:52 AM8/20/22
to django-oscar
No worries Joey. I appreciate you replying anyway

Hope your vacation was chill :)

Reply all
Reply to author
Forward
0 new messages