Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting filter_backends option for ProductRetrieveView #853

Open
execut opened this issue Apr 14, 2021 · 0 comments
Open

Supporting filter_backends option for ProductRetrieveView #853

execut opened this issue Apr 14, 2021 · 0 comments

Comments

@execut
Copy link
Contributor

execut commented Apr 14, 2021

Hello! I think there is a flaw in ProductRetrieveView when looking for a product. The product search does not include the current CMS page. As a result, the product can be opened by a link that contains someone else's category. For example, we have an apple product and it is in the fruits category and is located under the /fruits/apple link. But because of this flaw, it can be opened for another existing category of vegetables: /vegetables/apple. This is because there is no filtering on the current CMS page in the product queryset here:

def get_object(self):
if not hasattr(self, '_product'):
assert self.lookup_url_kwarg in self.kwargs
filter_kwargs = {
'active': True,
self.lookup_field: self.kwargs[self.lookup_url_kwarg],
}
if hasattr(self.product_model, 'translations'):
filter_kwargs.update(translations__language_code=get_language_from_request(self.request))
queryset = self.product_model.objects.filter(self.limit_choices_to, **filter_kwargs)
self._product = get_object_or_404(queryset)
return self._product

How about add to ProductRetrieveView ability support of backend filters like CMSPagesFilterBackend?:

filter_backends = [CMSPagesFilterBackend]
filter_backends.extend(api_settings.DEFAULT_FILTER_BACKENDS)
return [
    ...
    url(r'^(?P<slug>[\w-]+)', ProductRetrieveView.as_view(
        filter_backends=filter_backends,
    )),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant