瀏覽代碼

Fixed #3171 Applied offer on min num of basket and benefit items

master
Nasir Hussain 6 年之前
父節點
當前提交
fda27a183d
共有 2 個檔案被更改,包括 21 行新增1 行删除
  1. 1
    1
      src/oscar/apps/basket/utils.py
  2. 20
    0
      tests/integration/basket/test_utils.py

+ 1
- 1
src/oscar/apps/basket/utils.py 查看文件

@@ -162,6 +162,6 @@ class LineOfferConsumer(object):
162 162
 
163 163
             # respect max_affected_items
164 164
             if offer.benefit.max_affected_items:
165
-                max_affected_items = offer.benefit.max_affected_items
165
+                max_affected_items = min(offer.benefit.max_affected_items, max_affected_items)
166 166
 
167 167
         return max_affected_items - self.consumed(offer)

+ 20
- 0
tests/integration/basket/test_utils.py 查看文件

@@ -1,6 +1,7 @@
1 1
 
2 2
 import pytest
3 3
 
4
+from oscar.apps.offer import models
4 5
 from oscar.apps.offer.applicator import Applicator
5 6
 from oscar.test.factories import (
6 7
     BasketFactory, ConditionalOfferFactory, ProductFactory)
@@ -58,6 +59,25 @@ class TestLineOfferConsumer:
58 59
         for line in filled_basket.all_lines():
59 60
             assert line.consumer.consumed() == 0
60 61
 
62
+    def test_available_with_offer(self):
63
+        basket = BasketFactory()
64
+        product1 = ProductFactory()
65
+        product2 = ProductFactory()
66
+        basket.add_product(product1, quantity=1)
67
+        basket.add_product(product2, quantity=10)
68
+
69
+        benefit = models.Benefit(
70
+            type=models.Benefit.PERCENTAGE,
71
+            value=10,
72
+            max_affected_items=5,
73
+        )
74
+        benefit.save()
75
+
76
+        offer1 = ConditionalOfferFactory(name='offer1', benefit=benefit)
77
+        lines = basket.all_lines()
78
+        assert lines[0].consumer.available(offer1) == 1
79
+        assert lines[1].consumer.available(offer1) == 5
80
+
61 81
     def test_consumed_with_offer(self, filled_basket):
62 82
         offer1 = ConditionalOfferFactory(name='offer1')
63 83
         offer2 = ConditionalOfferFactory(name='offer2')

Loading…
取消
儲存