Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use Product.get_name() in create_from_cart.

It is there for extensibility so use it.
  • Loading branch information...
commit a3533a6bf734290f171e610cb1cf0ae0af43e115 1 parent 05ea03a
Bojan Mihelac bmihelac authored
2  shop/models/defaults/bases.py
@@ -422,5 +422,5 @@ class Meta(object):
422 422
423 423 def save(self, *args, **kwargs):
424 424 if self.product:
425   - self.product_name = self.product.name
  425 + self.product_name = self.product.get_name()
426 426 super(BaseOrderItem, self).save(*args, **kwargs)
2  shop/models/defaults/managers.py
@@ -106,7 +106,7 @@ def create_from_cart(self, cart):
106 106 i = OrderItem()
107 107 i.order = o
108 108 i.product_reference = item.product.id
109   - i.product_name = item.product.name
  109 + i.product_name = item.product.get_name()
110 110 i.product = item.product
111 111 i.unit_price = item.product.get_price()
112 112 i.quantity = item.quantity
17 shop/tests/order.py
@@ -201,6 +201,23 @@ def test_create_order_from_simple_cart(self):
201 201 self.assertEqual(o.order_subtotal, self.cart.subtotal_price)
202 202 self.assertEqual(o.order_total, self.cart.total_price)
203 203
  204 + def test_create_order_order_items_proper_product_name(self):
  205 + baseproduct = BaseProduct.objects.create(
  206 + name="Table",
  207 + unit_price=self.PRODUCT_PRICE
  208 + )
  209 + variation = ProductVariation.objects.create(
  210 + baseproduct=baseproduct,
  211 + name="white"
  212 + )
  213 + self.cart.add_product(variation)
  214 + self.cart.update()
  215 + self.cart.save()
  216 +
  217 + o = Order.objects.create_from_cart(self.cart)
  218 + ois = OrderItem.objects.filter(order=o)
  219 + self.assertEqual(ois[0].product_name, "Table - white")
  220 +
204 221 def test_create_order_from_taxed_cart(self):
205 222 """
206 223 This time assert that everything is consistent with a tax cart modifier
5 tests/testapp/project/models.py
@@ -14,6 +14,7 @@ class CompactDiscProduct(Product):
14 14
15 15
16 16 class BaseProduct(models.Model):
  17 + name = models.CharField(max_length=255)
17 18 unit_price = CurrencyField()
18 19
19 20
@@ -23,4 +24,8 @@ class ProductVariation(Product):
23 24 def get_price(self):
24 25 return self.baseproduct.unit_price
25 26
  27 + def get_name(self):
  28 + return "%s - %s" % (self.baseproduct.name, self.name,)
  29 +
  30 +
26 31

0 comments on commit a3533a6

Please sign in to comment.
Something went wrong with that request. Please try again.