feat: added product variants

This commit is contained in:
2026-07-23 11:37:37 +02:00
parent 5786c07077
commit 87405f31fa
22 changed files with 818 additions and 315 deletions
+35 -1
View File
@@ -4,7 +4,7 @@ from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import reverse
from shop.models import Cart, CartItem, CustomerAddress, Order, ShippingMethod, ShopSettings
from shop.models import Cart, CartItem, CustomerAddress, Order, OrderLine, ShippingMethod, ShopSettings
from shop.tests.mixins import CreateProductsMixin
@@ -111,3 +111,37 @@ class TestOrders(TestCase, CreateProductsMixin):
assert response.status_code == 200
assert not Order.objects.filter(user=self.user).exists()
def test_order_from_cart_with_variant_uses_variant_price(self):
size_m = self.create_attribute_value('Talla', 'M')
variant = self.create_product_variant(self.product, sku='V1', price=Decimal('25.00'), attribute_values=[size_m])
CartItem.objects.create(cart=self.cart_for_user, product=self.product, variant=variant, quantity=1)
self.client.force_login(self.user)
data = {
'email': self.user.email,
'shipping_address_full_name': self.address.full_name,
'shipping_address': self.address.address,
'shipping_address_town': self.address.address_town,
'shipping_address_zip': self.address.address_zip,
'shipping_address_state': self.address.address_state,
'shipping_address_country': self.address.address_country,
'shipping_address_phone': self.address.address_phone,
'same_as_shipping': True,
'billing_address_full_name': self.address.full_name,
'billing_address': self.address.address,
'billing_address_town': self.address.address_town,
'billing_address_zip': self.address.address_zip,
'billing_address_state': self.address.address_state,
'billing_address_country': self.address.address_country,
'billing_address_phone': self.address.address_phone,
'shipping_method': self.shipping_method.pk,
}
response = self.client.post(reverse('web:cart_detail'), data)
assert response.status_code == 302
order = Order.objects.get(user=self.user)
variant_line = OrderLine.objects.get(order=order, variant=variant)
assert variant_line.price == Decimal('25.00')