Found a bug? Please fill out the sections below.
Oscar 2.0 (sorry if already fixed..)
If the customer is on page 2 of the Shop product list, and some products are deleted such that there is now only one page, then the customer clicks 'add to cart', they are greeted with a 404 on
/catalogue/?page=2
I've retitled the issue because it's not related to adding to cart - the issue is more simply that if you pass an invalid page number to the catalogue view it will always return a 404. We're supposed to be catching the InvalidPage exception here and redirecting to the first page, but the exception is being raised too late, in get_context_data().
That is: https://latest.oscarcommerce.com/en-gb/catalogue/?page=50 should redirect to https://latest.oscarcommerce.com/en-gb/catalogue/ instead of throwing a 404.
Basically, SimpleProductSearchHandler inherits MultipleObjectMixin, which catches InvalidPage and would not allow to propagate it further, but return 404 - https://github.com/django/django/blob/335c9c94acf263901fb023404408880245b0c4b4/django/views/generic/list.py#L71-L75.
Don't have better idea, other than rewrite this method ^.
Alright, got another idea to generalize pagination throughout all search handlers - https://github.com/django-oscar/django-oscar/pull/3505.
Most helpful comment
I've retitled the issue because it's not related to adding to cart - the issue is more simply that if you pass an invalid page number to the catalogue view it will always return a 404. We're supposed to be catching the
InvalidPageexception here and redirecting to the first page, but the exception is being raised too late, inget_context_data().That is: https://latest.oscarcommerce.com/en-gb/catalogue/?page=50 should redirect to https://latest.oscarcommerce.com/en-gb/catalogue/ instead of throwing a 404.