Fix pagination when add-to-cart is in the URL

Fixes #5857