Просмотр исходного кода

Return matching line in Basket.add_product()

add_product mostly handles updating or creating a basket line. Having
that line available is both useful when overriding the method, or when
calling the method from elsewhere.

Another lovely suggestion by @metamatik.
master
Maik Hoepfel 11 лет назад
Родитель
Сommit
b4dfe06ba6
1 измененных файлов: 8 добавлений и 0 удалений
  1. 8
    0
      oscar/apps/basket/abstract_models.py

+ 8
- 0
oscar/apps/basket/abstract_models.py Просмотреть файл

@@ -165,6 +165,11 @@ class AbstractBasket(models.Model):
165 165
         The 'options' list should contains dicts with keys 'option' and 'value'
166 166
         which link the relevant product.Option model and string value
167 167
         respectively.
168
+
169
+        Returns (line, created).
170
+          line: the matching basket line
171
+          created: whether the line was created or updated
172
+
168 173
         """
169 174
         if options is None:
170 175
             options = []
@@ -213,6 +218,9 @@ class AbstractBasket(models.Model):
213 218
             line.quantity += quantity
214 219
             line.save()
215 220
         self.reset_offer_applications()
221
+
222
+        # Returning the line is useful when overriding this method.
223
+        return line, created
216 224
     add_product.alters_data = True
217 225
     add = add_product
218 226
 

Загрузка…
Отмена
Сохранить