Parcourir la source

Exclude non-public Products from Offers detail and Range detail view (#4053)

* Non-public Products are shown in Offers
master
Gunther Waidacher il y a 2 ans
Parent
révision
75ed8827bd
Aucun compte lié à l'adresse e-mail de l'auteur

+ 3
- 5
src/oscar/apps/offer/abstract_models.py Voir le fichier

@@ -451,8 +451,7 @@ class AbstractConditionalOffer(models.Model):
451 451
             return Product.objects.none()
452 452
 
453 453
         queryset = self.condition.range.all_products()
454
-        return queryset.filter(is_discountable=True).exclude(
455
-            structure=Product.CHILD)
454
+        return queryset.filter(is_discountable=True).browsable()
456 455
 
457 456
     @cached_property
458 457
     def combined_offers(self):
@@ -970,8 +969,8 @@ class AbstractRange(models.Model):
970 969
         Product = self.included_products.model
971 970
 
972 971
         if self.includes_all_products:
973
-            # Filter out blacklisted products
974
-            return Product.objects.all().exclude(
972
+            # Filter out blacklisted
973
+            return Product.objects.exclude(
975 974
                 id__in=self.excluded_products.values("id")
976 975
             )
977 976
 
@@ -998,7 +997,6 @@ class AbstractRange(models.Model):
998 997
                 ~Q(excludes=self),
999 998
                 ~Q(parent__excludes=self)
1000 999
             )
1001
-
1002 1000
         return selected_products.distinct()
1003 1001
 
1004 1002
     @property

+ 1
- 1
src/oscar/apps/offer/views.py Voir le fichier

@@ -68,7 +68,7 @@ class RangeDetailView(ListView):
68 68
         Return a queryset of all :py:class:`Product <oscar.apps.catalogue.abstract_models.AbstractProduct>`
69 69
         instances related to the :py:class:`Range <oscar.apps.offer.abstract_models.AbstractRange>`.
70 70
         """  # noqa
71
-        products = self.range.all_products()
71
+        products = self.range.all_products().browsable()
72 72
         return products.order_by('rangeproduct__display_order')
73 73
 
74 74
     def get_context_data(self, **kwargs):

+ 21
- 0
tests/integration/offer/test_offer.py Voir le fichier

@@ -0,0 +1,21 @@
1
+from django.test import TestCase
2
+
3
+from oscar.apps.offer.views import RangeDetailView
4
+from oscar.test.factories import create_product
5
+from oscar.test.factories.offer import ConditionalOfferFactory
6
+
7
+
8
+class TestOffer(TestCase):
9
+
10
+    def setUp(self):
11
+        self.offer = ConditionalOfferFactory()
12
+        self.non_public_product = create_product(is_public=False)
13
+        self.offer.condition.range.add_product(self.non_public_product)
14
+
15
+    def test_non_public_product_not_in_offer(self):
16
+        self.assertFalse(self.non_public_product in self.offer.products())
17
+
18
+    def test_non_public_product_not_in_range_detail_view(self):
19
+        view = RangeDetailView()
20
+        view.range = self.offer.condition.range
21
+        self.assertFalse(self.non_public_product in view.get_queryset())

Chargement…
Annuler
Enregistrer