Browse Source

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 years ago
parent
commit
b4dfe06ba6
1 changed files with 8 additions and 0 deletions
  1. 8
    0
      oscar/apps/basket/abstract_models.py

+ 8
- 0
oscar/apps/basket/abstract_models.py View File

165
         The 'options' list should contains dicts with keys 'option' and 'value'
165
         The 'options' list should contains dicts with keys 'option' and 'value'
166
         which link the relevant product.Option model and string value
166
         which link the relevant product.Option model and string value
167
         respectively.
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
         if options is None:
174
         if options is None:
170
             options = []
175
             options = []
213
             line.quantity += quantity
218
             line.quantity += quantity
214
             line.save()
219
             line.save()
215
         self.reset_offer_applications()
220
         self.reset_offer_applications()
221
+
222
+        # Returning the line is useful when overriding this method.
223
+        return line, created
216
     add_product.alters_data = True
224
     add_product.alters_data = True
217
     add = add_product
225
     add = add_product
218
 
226
 

Loading…
Cancel
Save