Problem with "How to enforce stock rules" recipe

37 views
Skip to first unread message

Adam Fast

unread,
Dec 2, 2014, 9:55:14 AM12/2/14
to django...@googlegroups.com
Hi,

I'm experimenting with Oscar and have this example (http://django-oscar.readthedocs.org/en/latest/howto/enforcing_stock_rules.html) set up in a project, but I'm not sure how to continue. By raising the InvalidBasketLineError inside the signal (I currently have it set to fail every time so I could experiment), it causes the site to 500. When adding a product to the cart that gets me a 500 page ("InvalidBasketLineError at /basket/add/4/"), when updating a quantity in an existing basket, since the update is done with Javascript I get a page that hangs.

How do I move forward with getting a user-friendly error here that displays to the user the reason they're not allowed to purchase? Since the documentation used an explicit exception with a message I expected that the basket would be trapping that exception by default and making the provided error message visible to the user (much as check_basket_is_valid does). Is this an "old" method of doing this? Overriding oscar.apps.checkout.session.CheckoutSessionMixin.check_basket_is_valid works great for displaying errors about something the user has in their basket, but it isn't used as early as possible (right upon add) to let the user know there's an issue selling them what they've added so the line signal example is still useful, I would imagine.

Adam

Frantchesco Cecchin

unread,
Jun 12, 2019, 3:40:21 PM6/12/19
to django-oscar
Same problem, five years later.

Someone knows how to deal with?

Samir Shah

unread,
Jun 12, 2019, 10:12:52 PM6/12/19
to django-oscar
It seems like the flow mentioned in that documentation was never actually implemented - I've made a ticket to update it.

The approach that you should take instead is to use availability policies for this - see https://django-oscar.readthedocs.io/en/latest/topics/prices_and_availability.html#availability-policies . This means defining a strategy class for your products that will return an availability policy that enforces whatever stock rules you want.
Reply all
Reply to author
Forward
0 new messages