diff --git a/shop/admin.py b/shop/admin.py index f4f6814..760fbad 100644 --- a/shop/admin.py +++ b/shop/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin from .models import Product, Color, Size, Order, OrderItem, GuestUser +from django.utils.html import format_html @admin.register(Product) class ProductAdmin(admin.ModelAdmin): @@ -7,7 +8,24 @@ class ProductAdmin(admin.ModelAdmin): @admin.register(Color) class ColorAdmin(admin.ModelAdmin): - list_display = ("name",) + list_display = ("color_preview", "name", "ordering", "colorHex", "secondary_hex_color") + list_editable = ("ordering",) + ordering = ["ordering"] + search_fields = ["name"] + list_per_page = 20 + + def color_preview(self, obj): + if obj.secondary_hex_color: + return format_html( + '
', + obj.colorHex, obj.secondary_hex_color + ) + return format_html( + '
', + obj.colorHex + ) @admin.register(Size) class SizeAdmin(admin.ModelAdmin): diff --git a/shop/management/commands/create_initial_shop_data.py b/shop/management/commands/create_initial_shop_data.py index a613712..1de6575 100644 --- a/shop/management/commands/create_initial_shop_data.py +++ b/shop/management/commands/create_initial_shop_data.py @@ -9,16 +9,18 @@ class Command(BaseCommand): # Create colors self.stdout.write('Creating colors...') colors = [ - {'name': 'Noir', 'hex': '#333333', 'secondary_hex': None}, - {'name': 'Noir / Gris Foncé Chiné', 'hex': '#000000', 'secondary_hex': '#4D4D4D'}, - {'name': 'Bleu Sport', 'hex': '#112B44', 'secondary_hex': None}, - {'name': 'Bleu Sport / Bleu Sport Chiné', 'hex': '#112B44', 'secondary_hex': '#16395A'}, - {'name': 'Bleu Sport / Blanc', 'hex': '#112B44', 'secondary_hex': '#FFFFFF'}, - {'name': 'Blanc / Gris Clair', 'hex': '#FFFFFF', 'secondary_hex': '#D3D3D3'}, - {'name': 'Fuchsia', 'hex': '#C1366B', 'secondary_hex': None}, - {'name': 'Corail / Noir', 'hex': '#FF7F50', 'secondary_hex': '#000000'}, - {'name': 'Blanc / Bleu Sport', 'hex': '#FFFFFF', 'secondary_hex': '#112B44'}, - {'name': 'Blanc', 'hex': '#FFFFFF', 'secondary_hex': None}, + {'name': 'Blanc', 'hex': '#FFFFFF', 'secondary_hex': None, 'ordering': 10}, + {'name': 'Blanc / Bleu Sport', 'hex': '#FFFFFF', 'secondary_hex': '#112B44', 'ordering': 11}, + {'name': 'Blanc / Gris Clair', 'hex': '#FFFFFF', 'secondary_hex': '#D3D3D3', 'ordering': 12}, + {'name': 'Bleu Sport', 'hex': '#112B44', 'secondary_hex': None, 'ordering': 20}, + {'name': 'Bleu Sport / Blanc', 'hex': '#112B44', 'secondary_hex': '#FFFFFF', 'ordering': 21}, + {'name': 'Bleu Sport / Bleu Sport Chiné', 'hex': '#112B44', 'secondary_hex': '#16395A', 'ordering': 22}, + {'name': 'Fuchsia', 'hex': '#C1366B', 'secondary_hex': None, 'ordering': 30}, + {'name': 'Corail / Noir', 'hex': '#FF7F50', 'secondary_hex': '#000000', 'ordering': 40}, + {'name': 'Gris Foncé Chiné / Noir', 'hex': '#4D4D4D', 'secondary_hex': '#000000', 'ordering': 50}, + {'name': 'Noir', 'hex': '#333333', 'secondary_hex': None, 'ordering': 60}, + {'name': 'Noir / Corail', 'hex': '#000000', 'secondary_hex': '#FF7F50', 'ordering': 61}, + {'name': 'Noir / Gris Foncé Chiné', 'hex': '#000000', 'secondary_hex': '#4D4D4D', 'ordering': 62}, ] color_objects = {} @@ -27,21 +29,19 @@ class Command(BaseCommand): name=color_data['name'], defaults={ 'colorHex': color_data['hex'], - 'secondary_hex_color': color_data['secondary_hex'] + 'secondary_hex_color': color_data['secondary_hex'], + 'ordering': color_data['ordering'] } ) color_objects[color_data['name']] = color if created: self.stdout.write(f'Created color: {color_data["name"]}') else: - # Update existing colors with secondary color if needed - if color.colorHex != color_data['hex'] or color.secondary_hex_color != color_data['secondary_hex']: - color.colorHex = color_data['hex'] - color.secondary_hex_color = color_data['secondary_hex'] - color.save() - self.stdout.write(f'Updated color: {color_data["name"]}') - else: - self.stdout.write(f'Color already exists: {color_data["name"]}') + color.colorHex = color_data['hex'] + color.secondary_hex_color = color_data['secondary_hex'] + color.ordering = color_data['ordering'] + color.save() + self.stdout.write(f'Updated color: {color_data["name"]}') # Create sizes self.stdout.write('Creating sizes...') @@ -99,7 +99,7 @@ class Command(BaseCommand): 'price': 25.00, 'ordering_value': 20, 'cut': 1, # Women - 'colors': ['Blanc / Bleu Sport', 'Noir', 'Noir / Gris Foncé Chiné'], + 'colors': ['Blanc / Bleu Sport', 'Noir / Corail', 'Noir / Gris Foncé Chiné'], 'sizes': ['XS', 'S', 'M', 'L', 'XL'], 'image_filename': 'PS_PA4031_WHITE-SPORTYNAVY.png.avif' }, @@ -121,7 +121,7 @@ class Command(BaseCommand): 'price': 25.00, 'ordering_value': 40, 'cut': 2, # Men - 'colors': ['Blanc / Bleu Sport', 'Noir', 'Noir / Gris Foncé Chiné'], + 'colors': ['Blanc / Gris Clair', 'Bleu Sport / Blanc', 'Bleu Sport / Bleu Sport Chine', 'Noir', 'Noir / Gris Foncé Chiné'], 'sizes': ['S', 'M', 'L', 'XL', 'XXL', '3XL'], 'image_filename': 'tshirt_h.png' }, @@ -132,7 +132,7 @@ class Command(BaseCommand): 'price': 30.00, 'ordering_value': 50, 'cut': 2, # Men - 'colors': ['Blanc / Bleu Sport', 'Noir', 'Noir / Gris Foncé Chiné'], + 'colors': ['Blanc / Bleu Sport', 'Blanc / Gris Clair', 'Noir', 'Gris Foncé Chiné / Noir'], 'sizes': ['S', 'M', 'L', 'XL', 'XXL', '3XL'], 'image_filename': 'PS_PA1030_WHITE-SPORTYNAVY.png.avif' }, diff --git a/shop/migrations/0023_alter_color_options_color_ordering.py b/shop/migrations/0023_alter_color_options_color_ordering.py new file mode 100644 index 0000000..2b81545 --- /dev/null +++ b/shop/migrations/0023_alter_color_options_color_ordering.py @@ -0,0 +1,22 @@ +# Generated by Django 5.1 on 2025-03-27 11:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('shop', '0022_alter_cartitem_options_alter_orderitem_options'), + ] + + operations = [ + migrations.AlterModelOptions( + name='color', + options={'ordering': ['ordering']}, + ), + migrations.AddField( + model_name='color', + name='ordering', + field=models.IntegerField(default=0), + ), + ] diff --git a/shop/models.py b/shop/models.py index 508483e..94f3f38 100644 --- a/shop/models.py +++ b/shop/models.py @@ -18,6 +18,10 @@ class Color(models.Model): colorHex = models.CharField(max_length=7, default="#FFFFFF", help_text="Color in hex format (e.g. #FF0000)") secondary_hex_color = models.CharField(max_length=7, null=True, blank=True, help_text="Secondary color in hex format for split color display") + ordering = models.IntegerField(default=0) + + class Meta: + ordering = ['ordering'] # This will make queries respect the ordering by default def __str__(self): return self.name diff --git a/shop/static/shop/css/shop.css b/shop/static/shop/css/shop.css index 9d7e92c..e71a1f6 100644 --- a/shop/static/shop/css/shop.css +++ b/shop/static/shop/css/shop.css @@ -12,6 +12,7 @@ object-fit: contain; /* This will maintain the aspect ratio of the image */ background-color: white; border-radius: 12px; + display: none; /* Hide all images by default */ } .no-image { @@ -480,3 +481,48 @@ v .cart-table { position: relative; overflow: hidden; } + +.slider-container { + position: relative; + width: 100%; + max-height: 240px; /* Match your original height */ +} + +.slides { + position: relative; + width: 100%; + height: 100%; +} + +.product-image.active { + display: block; +} + +.prev, +.next { + cursor: pointer; + position: absolute; + top: 50%; + transform: translateY(-50%); + background: none; + color: black; + border: none; + font-size: 24px; + padding: 8px; + opacity: 0.6; + transition: opacity 0.3s; + z-index: 2; +} + +.prev { + left: 5px; +} + +.next { + right: 5px; +} + +.prev:hover, +.next:hover { + opacity: 1; +} diff --git a/shop/static/shop/images/products/PC001/blanc/PS_KP912-B_WHITE.png.avif b/shop/static/shop/images/products/PC001/blanc/PS_KP912-B_WHITE.png.avif new file mode 100644 index 0000000..52ba473 Binary files /dev/null and b/shop/static/shop/images/products/PC001/blanc/PS_KP912-B_WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PC001/blanc/PS_KP912-S_WHITE.png.avif b/shop/static/shop/images/products/PC001/blanc/PS_KP912-S_WHITE.png.avif new file mode 100644 index 0000000..b713c00 Binary files /dev/null and b/shop/static/shop/images/products/PC001/blanc/PS_KP912-S_WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PC001/blanc/PS_KP912_WHITE.png.avif b/shop/static/shop/images/products/PC001/blanc/PS_KP912_WHITE.png.avif new file mode 100644 index 0000000..c6d5cab Binary files /dev/null and b/shop/static/shop/images/products/PC001/blanc/PS_KP912_WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PC001/bleu-sport/PS_KP912-B_NAVY.png.avif b/shop/static/shop/images/products/PC001/bleu-sport/PS_KP912-B_NAVY.png.avif new file mode 100644 index 0000000..773a218 Binary files /dev/null and b/shop/static/shop/images/products/PC001/bleu-sport/PS_KP912-B_NAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC001/bleu-sport/PS_KP912-S_NAVY.png.avif b/shop/static/shop/images/products/PC001/bleu-sport/PS_KP912-S_NAVY.png.avif new file mode 100644 index 0000000..857968a Binary files /dev/null and b/shop/static/shop/images/products/PC001/bleu-sport/PS_KP912-S_NAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC001/bleu-sport/PS_KP912_NAVY.png.avif b/shop/static/shop/images/products/PC001/bleu-sport/PS_KP912_NAVY.png.avif new file mode 100644 index 0000000..cbefe4d Binary files /dev/null and b/shop/static/shop/images/products/PC001/bleu-sport/PS_KP912_NAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC001/noir/PS_KP912-B_BLACK.png.avif b/shop/static/shop/images/products/PC001/noir/PS_KP912-B_BLACK.png.avif new file mode 100644 index 0000000..c467628 Binary files /dev/null and b/shop/static/shop/images/products/PC001/noir/PS_KP912-B_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC001/noir/PS_KP912-S_BLACK.png.avif b/shop/static/shop/images/products/PC001/noir/PS_KP912-S_BLACK.png.avif new file mode 100644 index 0000000..3956e54 Binary files /dev/null and b/shop/static/shop/images/products/PC001/noir/PS_KP912-S_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/noir_hat.png.avif b/shop/static/shop/images/products/PC001/noir/noir_hat.png.avif similarity index 100% rename from shop/static/shop/images/products/noir_hat.png.avif rename to shop/static/shop/images/products/PC001/noir/noir_hat.png.avif diff --git a/shop/static/shop/images/products/PC002/blanc/PS_K473-B_WHITE.png.avif b/shop/static/shop/images/products/PC002/blanc/PS_K473-B_WHITE.png.avif new file mode 100644 index 0000000..d89e3bc Binary files /dev/null and b/shop/static/shop/images/products/PC002/blanc/PS_K473-B_WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PC002/blanc/PS_K473-S_WHITE.png.avif b/shop/static/shop/images/products/PC002/blanc/PS_K473-S_WHITE.png.avif new file mode 100644 index 0000000..05a6a82 Binary files /dev/null and b/shop/static/shop/images/products/PC002/blanc/PS_K473-S_WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PS_K473_WHITE.png.avif b/shop/static/shop/images/products/PC002/blanc/PS_K473_WHITE.png.avif similarity index 100% rename from shop/static/shop/images/products/PS_K473_WHITE.png.avif rename to shop/static/shop/images/products/PC002/blanc/PS_K473_WHITE.png.avif diff --git a/shop/static/shop/images/products/PC002/bleu-sport/PS_K473-B_NAVY.png.avif b/shop/static/shop/images/products/PC002/bleu-sport/PS_K473-B_NAVY.png.avif new file mode 100644 index 0000000..a953fa6 Binary files /dev/null and b/shop/static/shop/images/products/PC002/bleu-sport/PS_K473-B_NAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC002/bleu-sport/PS_K473-S_NAVY.png.avif b/shop/static/shop/images/products/PC002/bleu-sport/PS_K473-S_NAVY.png.avif new file mode 100644 index 0000000..cf112ab Binary files /dev/null and b/shop/static/shop/images/products/PC002/bleu-sport/PS_K473-S_NAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC002/bleu-sport/PS_K473_NAVY.png.avif b/shop/static/shop/images/products/PC002/bleu-sport/PS_K473_NAVY.png.avif new file mode 100644 index 0000000..f935b0b Binary files /dev/null and b/shop/static/shop/images/products/PC002/bleu-sport/PS_K473_NAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC002/fuchsia/PS_K473-B_FUCHSIA.png.avif b/shop/static/shop/images/products/PC002/fuchsia/PS_K473-B_FUCHSIA.png.avif new file mode 100644 index 0000000..6c4d75b Binary files /dev/null and b/shop/static/shop/images/products/PC002/fuchsia/PS_K473-B_FUCHSIA.png.avif differ diff --git a/shop/static/shop/images/products/PC002/fuchsia/PS_K473-S_FUCHSIA.png.avif b/shop/static/shop/images/products/PC002/fuchsia/PS_K473-S_FUCHSIA.png.avif new file mode 100644 index 0000000..6cb0ce3 Binary files /dev/null and b/shop/static/shop/images/products/PC002/fuchsia/PS_K473-S_FUCHSIA.png.avif differ diff --git a/shop/static/shop/images/products/PC002/fuchsia/PS_K473_FUCHSIA.png.avif b/shop/static/shop/images/products/PC002/fuchsia/PS_K473_FUCHSIA.png.avif new file mode 100644 index 0000000..1b33def Binary files /dev/null and b/shop/static/shop/images/products/PC002/fuchsia/PS_K473_FUCHSIA.png.avif differ diff --git a/shop/static/shop/images/products/PC002/noir/PS_K473-B_BLACK.png.avif b/shop/static/shop/images/products/PC002/noir/PS_K473-B_BLACK.png.avif new file mode 100644 index 0000000..d90c138 Binary files /dev/null and b/shop/static/shop/images/products/PC002/noir/PS_K473-B_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC002/noir/PS_K473-S_BLACK.png.avif b/shop/static/shop/images/products/PC002/noir/PS_K473-S_BLACK.png.avif new file mode 100644 index 0000000..55166c0 Binary files /dev/null and b/shop/static/shop/images/products/PC002/noir/PS_K473-S_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC002/noir/PS_K473_BLACK.png.avif b/shop/static/shop/images/products/PC002/noir/PS_K473_BLACK.png.avif new file mode 100644 index 0000000..724c919 Binary files /dev/null and b/shop/static/shop/images/products/PC002/noir/PS_K473_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC003/blanc/PS_K476-B_WHITE.png.avif b/shop/static/shop/images/products/PC003/blanc/PS_K476-B_WHITE.png.avif new file mode 100644 index 0000000..649a86c Binary files /dev/null and b/shop/static/shop/images/products/PC003/blanc/PS_K476-B_WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PC003/blanc/PS_K476-S_WHITE.png.avif b/shop/static/shop/images/products/PC003/blanc/PS_K476-S_WHITE.png.avif new file mode 100644 index 0000000..0cbb2b0 Binary files /dev/null and b/shop/static/shop/images/products/PC003/blanc/PS_K476-S_WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PS_K476_WHITE.png.avif b/shop/static/shop/images/products/PC003/blanc/PS_K476_WHITE.png.avif similarity index 100% rename from shop/static/shop/images/products/PS_K476_WHITE.png.avif rename to shop/static/shop/images/products/PC003/blanc/PS_K476_WHITE.png.avif diff --git a/shop/static/shop/images/products/PC003/bleu-sport/PS_K476-B_NAVY.png.avif b/shop/static/shop/images/products/PC003/bleu-sport/PS_K476-B_NAVY.png.avif new file mode 100644 index 0000000..732c38d Binary files /dev/null and b/shop/static/shop/images/products/PC003/bleu-sport/PS_K476-B_NAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC003/bleu-sport/PS_K476-S_NAVY.png.avif b/shop/static/shop/images/products/PC003/bleu-sport/PS_K476-S_NAVY.png.avif new file mode 100644 index 0000000..e791db9 Binary files /dev/null and b/shop/static/shop/images/products/PC003/bleu-sport/PS_K476-S_NAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC003/bleu-sport/PS_K476_NAVY.png.avif b/shop/static/shop/images/products/PC003/bleu-sport/PS_K476_NAVY.png.avif new file mode 100644 index 0000000..d862ba6 Binary files /dev/null and b/shop/static/shop/images/products/PC003/bleu-sport/PS_K476_NAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC003/fuchsia/PS_K476-B_FUCHSIA.png.avif b/shop/static/shop/images/products/PC003/fuchsia/PS_K476-B_FUCHSIA.png.avif new file mode 100644 index 0000000..ea1747f Binary files /dev/null and b/shop/static/shop/images/products/PC003/fuchsia/PS_K476-B_FUCHSIA.png.avif differ diff --git a/shop/static/shop/images/products/PC003/fuchsia/PS_K476-S_FUCHSIA.png.avif b/shop/static/shop/images/products/PC003/fuchsia/PS_K476-S_FUCHSIA.png.avif new file mode 100644 index 0000000..9f84bff Binary files /dev/null and b/shop/static/shop/images/products/PC003/fuchsia/PS_K476-S_FUCHSIA.png.avif differ diff --git a/shop/static/shop/images/products/PC003/fuchsia/PS_K476_FUCHSIA.png.avif b/shop/static/shop/images/products/PC003/fuchsia/PS_K476_FUCHSIA.png.avif new file mode 100644 index 0000000..8fc5748 Binary files /dev/null and b/shop/static/shop/images/products/PC003/fuchsia/PS_K476_FUCHSIA.png.avif differ diff --git a/shop/static/shop/images/products/PC003/noir/PS_K476-B_BLACK.png.avif b/shop/static/shop/images/products/PC003/noir/PS_K476-B_BLACK.png.avif new file mode 100644 index 0000000..7af7b48 Binary files /dev/null and b/shop/static/shop/images/products/PC003/noir/PS_K476-B_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC003/noir/PS_K476-S_BLACK.png.avif b/shop/static/shop/images/products/PC003/noir/PS_K476-S_BLACK.png.avif new file mode 100644 index 0000000..f82bdfd Binary files /dev/null and b/shop/static/shop/images/products/PC003/noir/PS_K476-S_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC003/noir/PS_K476_BLACK.png.avif b/shop/static/shop/images/products/PC003/noir/PS_K476_BLACK.png.avif new file mode 100644 index 0000000..2da7d42 Binary files /dev/null and b/shop/static/shop/images/products/PC003/noir/PS_K476_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC004/blanc-bleu-sport/PS_PA4031-B_WHITE-SPORTYNAVY.png.avif b/shop/static/shop/images/products/PC004/blanc-bleu-sport/PS_PA4031-B_WHITE-SPORTYNAVY.png.avif new file mode 100644 index 0000000..bfd36aa Binary files /dev/null and b/shop/static/shop/images/products/PC004/blanc-bleu-sport/PS_PA4031-B_WHITE-SPORTYNAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC004/blanc-bleu-sport/PS_PA4031-S_WHITE-SPORTYNAVY.png.avif b/shop/static/shop/images/products/PC004/blanc-bleu-sport/PS_PA4031-S_WHITE-SPORTYNAVY.png.avif new file mode 100644 index 0000000..869293f Binary files /dev/null and b/shop/static/shop/images/products/PC004/blanc-bleu-sport/PS_PA4031-S_WHITE-SPORTYNAVY.png.avif differ diff --git a/shop/static/shop/images/products/PS_PA4031_WHITE-SPORTYNAVY.png.avif b/shop/static/shop/images/products/PC004/blanc-bleu-sport/PS_PA4031_WHITE-SPORTYNAVY.png.avif similarity index 100% rename from shop/static/shop/images/products/PS_PA4031_WHITE-SPORTYNAVY.png.avif rename to shop/static/shop/images/products/PC004/blanc-bleu-sport/PS_PA4031_WHITE-SPORTYNAVY.png.avif diff --git a/shop/static/shop/images/products/PC004/noir-corail/PS_PA4031-B_BLACK-CORAL.png.avif b/shop/static/shop/images/products/PC004/noir-corail/PS_PA4031-B_BLACK-CORAL.png.avif new file mode 100644 index 0000000..937ee31 Binary files /dev/null and b/shop/static/shop/images/products/PC004/noir-corail/PS_PA4031-B_BLACK-CORAL.png.avif differ diff --git a/shop/static/shop/images/products/PC004/noir-corail/PS_PA4031-S_BLACK-CORAL.png.avif b/shop/static/shop/images/products/PC004/noir-corail/PS_PA4031-S_BLACK-CORAL.png.avif new file mode 100644 index 0000000..91dea46 Binary files /dev/null and b/shop/static/shop/images/products/PC004/noir-corail/PS_PA4031-S_BLACK-CORAL.png.avif differ diff --git a/shop/static/shop/images/products/PC004/noir-corail/PS_PA4031_BLACK-CORAL.png.avif b/shop/static/shop/images/products/PC004/noir-corail/PS_PA4031_BLACK-CORAL.png.avif new file mode 100644 index 0000000..bfb8d3b Binary files /dev/null and b/shop/static/shop/images/products/PC004/noir-corail/PS_PA4031_BLACK-CORAL.png.avif differ diff --git a/shop/static/shop/images/products/PC004/noir-gris-fonce-chine/PS_PA4031-B_BLACK-MARLDARKGREY.png.avif b/shop/static/shop/images/products/PC004/noir-gris-fonce-chine/PS_PA4031-B_BLACK-MARLDARKGREY.png.avif new file mode 100644 index 0000000..7bf1c53 Binary files /dev/null and b/shop/static/shop/images/products/PC004/noir-gris-fonce-chine/PS_PA4031-B_BLACK-MARLDARKGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC004/noir-gris-fonce-chine/PS_PA4031-S_BLACK-MARLDARKGREY.png.avif b/shop/static/shop/images/products/PC004/noir-gris-fonce-chine/PS_PA4031-S_BLACK-MARLDARKGREY.png.avif new file mode 100644 index 0000000..69791e0 Binary files /dev/null and b/shop/static/shop/images/products/PC004/noir-gris-fonce-chine/PS_PA4031-S_BLACK-MARLDARKGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC004/noir-gris-fonce-chine/PS_PA4031_BLACK-MARLDARKGREY.png.avif b/shop/static/shop/images/products/PC004/noir-gris-fonce-chine/PS_PA4031_BLACK-MARLDARKGREY.png.avif new file mode 100644 index 0000000..d377936 Binary files /dev/null and b/shop/static/shop/images/products/PC004/noir-gris-fonce-chine/PS_PA4031_BLACK-MARLDARKGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC005/blanc-bleu-sport/PS_PA1031-B_WHITE-SPORTYNAVY.png.avif b/shop/static/shop/images/products/PC005/blanc-bleu-sport/PS_PA1031-B_WHITE-SPORTYNAVY.png.avif new file mode 100644 index 0000000..97d2d8d Binary files /dev/null and b/shop/static/shop/images/products/PC005/blanc-bleu-sport/PS_PA1031-B_WHITE-SPORTYNAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC005/blanc-bleu-sport/PS_PA1031-S_WHITE-SPORTYNAVY.png.avif b/shop/static/shop/images/products/PC005/blanc-bleu-sport/PS_PA1031-S_WHITE-SPORTYNAVY.png.avif new file mode 100644 index 0000000..c157a41 Binary files /dev/null and b/shop/static/shop/images/products/PC005/blanc-bleu-sport/PS_PA1031-S_WHITE-SPORTYNAVY.png.avif differ diff --git a/shop/static/shop/images/products/PS_PA1031_WHITE-SPORTYNAVY.png.avif b/shop/static/shop/images/products/PC005/blanc-bleu-sport/PS_PA1031_WHITE-SPORTYNAVY.png.avif similarity index 100% rename from shop/static/shop/images/products/PS_PA1031_WHITE-SPORTYNAVY.png.avif rename to shop/static/shop/images/products/PC005/blanc-bleu-sport/PS_PA1031_WHITE-SPORTYNAVY.png.avif diff --git a/shop/static/shop/images/products/PC005/bleu-sport-blanc/PS_PA1031-B_SPORTYNAVY-WHITE.png.avif b/shop/static/shop/images/products/PC005/bleu-sport-blanc/PS_PA1031-B_SPORTYNAVY-WHITE.png.avif new file mode 100644 index 0000000..27cbc4c Binary files /dev/null and b/shop/static/shop/images/products/PC005/bleu-sport-blanc/PS_PA1031-B_SPORTYNAVY-WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PC005/bleu-sport-blanc/PS_PA1031-S_SPORTYNAVY-WHITE.png.avif b/shop/static/shop/images/products/PC005/bleu-sport-blanc/PS_PA1031-S_SPORTYNAVY-WHITE.png.avif new file mode 100644 index 0000000..d021631 Binary files /dev/null and b/shop/static/shop/images/products/PC005/bleu-sport-blanc/PS_PA1031-S_SPORTYNAVY-WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PC005/bleu-sport-blanc/PS_PA1031_SPORTYNAVY-WHITE.png.avif b/shop/static/shop/images/products/PC005/bleu-sport-blanc/PS_PA1031_SPORTYNAVY-WHITE.png.avif new file mode 100644 index 0000000..bed342e Binary files /dev/null and b/shop/static/shop/images/products/PC005/bleu-sport-blanc/PS_PA1031_SPORTYNAVY-WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PC005/corail-noir/PS_PA1031-B_CORAL-BLACK.png.avif b/shop/static/shop/images/products/PC005/corail-noir/PS_PA1031-B_CORAL-BLACK.png.avif new file mode 100644 index 0000000..963cc34 Binary files /dev/null and b/shop/static/shop/images/products/PC005/corail-noir/PS_PA1031-B_CORAL-BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC005/corail-noir/PS_PA1031-S_CORAL-BLACK.png.avif b/shop/static/shop/images/products/PC005/corail-noir/PS_PA1031-S_CORAL-BLACK.png.avif new file mode 100644 index 0000000..dd4558e Binary files /dev/null and b/shop/static/shop/images/products/PC005/corail-noir/PS_PA1031-S_CORAL-BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC005/corail-noir/PS_PA1031_CORAL-BLACK.png.avif b/shop/static/shop/images/products/PC005/corail-noir/PS_PA1031_CORAL-BLACK.png.avif new file mode 100644 index 0000000..83ca6db Binary files /dev/null and b/shop/static/shop/images/products/PC005/corail-noir/PS_PA1031_CORAL-BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC005/noir-gris-fonce-chine/PS_PA1031-B_BLACK-MARLDARKGREY.png.avif b/shop/static/shop/images/products/PC005/noir-gris-fonce-chine/PS_PA1031-B_BLACK-MARLDARKGREY.png.avif new file mode 100644 index 0000000..86a39d6 Binary files /dev/null and b/shop/static/shop/images/products/PC005/noir-gris-fonce-chine/PS_PA1031-B_BLACK-MARLDARKGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC005/noir-gris-fonce-chine/PS_PA1031-S_BLACK-MARLDARKGREY.png.avif b/shop/static/shop/images/products/PC005/noir-gris-fonce-chine/PS_PA1031-S_BLACK-MARLDARKGREY.png.avif new file mode 100644 index 0000000..3f447b9 Binary files /dev/null and b/shop/static/shop/images/products/PC005/noir-gris-fonce-chine/PS_PA1031-S_BLACK-MARLDARKGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC005/noir-gris-fonce-chine/PS_PA1031_BLACK-MARLDARKGREY.png.avif b/shop/static/shop/images/products/PC005/noir-gris-fonce-chine/PS_PA1031_BLACK-MARLDARKGREY.png.avif new file mode 100644 index 0000000..ace9ebf Binary files /dev/null and b/shop/static/shop/images/products/PC005/noir-gris-fonce-chine/PS_PA1031_BLACK-MARLDARKGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/blanc-gris-clair/PS_PA4030-B_WHITE-FINEGREY.png.avif b/shop/static/shop/images/products/PC006/blanc-gris-clair/PS_PA4030-B_WHITE-FINEGREY.png.avif new file mode 100644 index 0000000..9358907 Binary files /dev/null and b/shop/static/shop/images/products/PC006/blanc-gris-clair/PS_PA4030-B_WHITE-FINEGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/blanc-gris-clair/PS_PA4030-S_WHITE-FINEGREY.png.avif b/shop/static/shop/images/products/PC006/blanc-gris-clair/PS_PA4030-S_WHITE-FINEGREY.png.avif new file mode 100644 index 0000000..deca711 Binary files /dev/null and b/shop/static/shop/images/products/PC006/blanc-gris-clair/PS_PA4030-S_WHITE-FINEGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/blanc-gris-clair/PS_PA4030_WHITE-FINEGREY.png.avif b/shop/static/shop/images/products/PC006/blanc-gris-clair/PS_PA4030_WHITE-FINEGREY.png.avif new file mode 100644 index 0000000..6ee4793 Binary files /dev/null and b/shop/static/shop/images/products/PC006/blanc-gris-clair/PS_PA4030_WHITE-FINEGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/bleu-sport-blanc/PS_PA4030-B_SPORTYNAVY-WHITE.png.avif b/shop/static/shop/images/products/PC006/bleu-sport-blanc/PS_PA4030-B_SPORTYNAVY-WHITE.png.avif new file mode 100644 index 0000000..86b6188 Binary files /dev/null and b/shop/static/shop/images/products/PC006/bleu-sport-blanc/PS_PA4030-B_SPORTYNAVY-WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PC006/bleu-sport-blanc/PS_PA4030-S_SPORTYNAVY-WHITE.png.avif b/shop/static/shop/images/products/PC006/bleu-sport-blanc/PS_PA4030-S_SPORTYNAVY-WHITE.png.avif new file mode 100644 index 0000000..3fcc498 Binary files /dev/null and b/shop/static/shop/images/products/PC006/bleu-sport-blanc/PS_PA4030-S_SPORTYNAVY-WHITE.png.avif differ diff --git a/shop/static/shop/images/products/PS_PA4030_SPORTYNAVY-WHITE.png.avif b/shop/static/shop/images/products/PC006/bleu-sport-blanc/PS_PA4030_SPORTYNAVY-WHITE.png.avif similarity index 100% rename from shop/static/shop/images/products/PS_PA4030_SPORTYNAVY-WHITE.png.avif rename to shop/static/shop/images/products/PC006/bleu-sport-blanc/PS_PA4030_SPORTYNAVY-WHITE.png.avif diff --git a/shop/static/shop/images/products/PC006/bleu-sport-bleu-sport-chine/PS_PA4030-B_SPORTYNAVY-MARLSPORTYNAVY.png.avif b/shop/static/shop/images/products/PC006/bleu-sport-bleu-sport-chine/PS_PA4030-B_SPORTYNAVY-MARLSPORTYNAVY.png.avif new file mode 100644 index 0000000..e679063 Binary files /dev/null and b/shop/static/shop/images/products/PC006/bleu-sport-bleu-sport-chine/PS_PA4030-B_SPORTYNAVY-MARLSPORTYNAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/bleu-sport-bleu-sport-chine/PS_PA4030-S_SPORTYNAVY-MARLSPORTYNAVY.png.avif b/shop/static/shop/images/products/PC006/bleu-sport-bleu-sport-chine/PS_PA4030-S_SPORTYNAVY-MARLSPORTYNAVY.png.avif new file mode 100644 index 0000000..fd0bd95 Binary files /dev/null and b/shop/static/shop/images/products/PC006/bleu-sport-bleu-sport-chine/PS_PA4030-S_SPORTYNAVY-MARLSPORTYNAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/bleu-sport-bleu-sport-chine/PS_PA4030_SPORTYNAVY-MARLSPORTYNAVY.png.avif b/shop/static/shop/images/products/PC006/bleu-sport-bleu-sport-chine/PS_PA4030_SPORTYNAVY-MARLSPORTYNAVY.png.avif new file mode 100644 index 0000000..a73890d Binary files /dev/null and b/shop/static/shop/images/products/PC006/bleu-sport-bleu-sport-chine/PS_PA4030_SPORTYNAVY-MARLSPORTYNAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/noir-gris-fonce-chine/PS_PA4030-B_BLACK-MARLDARKGREY.png.avif b/shop/static/shop/images/products/PC006/noir-gris-fonce-chine/PS_PA4030-B_BLACK-MARLDARKGREY.png.avif new file mode 100644 index 0000000..447a6f2 Binary files /dev/null and b/shop/static/shop/images/products/PC006/noir-gris-fonce-chine/PS_PA4030-B_BLACK-MARLDARKGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/noir-gris-fonce-chine/PS_PA4030-S_BLACK-MARLDARKGREY.png.avif b/shop/static/shop/images/products/PC006/noir-gris-fonce-chine/PS_PA4030-S_BLACK-MARLDARKGREY.png.avif new file mode 100644 index 0000000..2138b14 Binary files /dev/null and b/shop/static/shop/images/products/PC006/noir-gris-fonce-chine/PS_PA4030-S_BLACK-MARLDARKGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/noir-gris-fonce-chine/PS_PA4030_BLACK-MARLDARKGREY.png.avif b/shop/static/shop/images/products/PC006/noir-gris-fonce-chine/PS_PA4030_BLACK-MARLDARKGREY.png.avif new file mode 100644 index 0000000..036d0cb Binary files /dev/null and b/shop/static/shop/images/products/PC006/noir-gris-fonce-chine/PS_PA4030_BLACK-MARLDARKGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC006/noir/PS_PA4030-B_BLACK.png.avif b/shop/static/shop/images/products/PC006/noir/PS_PA4030-B_BLACK.png.avif new file mode 100644 index 0000000..79cf6f9 Binary files /dev/null and b/shop/static/shop/images/products/PC006/noir/PS_PA4030-B_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC006/noir/PS_PA4030-S_BLACK.png.avif b/shop/static/shop/images/products/PC006/noir/PS_PA4030-S_BLACK.png.avif new file mode 100644 index 0000000..635447d Binary files /dev/null and b/shop/static/shop/images/products/PC006/noir/PS_PA4030-S_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC006/noir/PS_PA4030_BLACK.png.avif b/shop/static/shop/images/products/PC006/noir/PS_PA4030_BLACK.png.avif new file mode 100644 index 0000000..625f435 Binary files /dev/null and b/shop/static/shop/images/products/PC006/noir/PS_PA4030_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC007/blanc-bleu-sport/PS_PA1030-B_WHITE-SPORTYNAVY.png.avif b/shop/static/shop/images/products/PC007/blanc-bleu-sport/PS_PA1030-B_WHITE-SPORTYNAVY.png.avif new file mode 100644 index 0000000..dc9d68a Binary files /dev/null and b/shop/static/shop/images/products/PC007/blanc-bleu-sport/PS_PA1030-B_WHITE-SPORTYNAVY.png.avif differ diff --git a/shop/static/shop/images/products/PC007/blanc-bleu-sport/PS_PA1030-S_WHITE-SPORTYNAVY.png.avif b/shop/static/shop/images/products/PC007/blanc-bleu-sport/PS_PA1030-S_WHITE-SPORTYNAVY.png.avif new file mode 100644 index 0000000..94cfa58 Binary files /dev/null and b/shop/static/shop/images/products/PC007/blanc-bleu-sport/PS_PA1030-S_WHITE-SPORTYNAVY.png.avif differ diff --git a/shop/static/shop/images/products/PS_PA1030_WHITE-SPORTYNAVY.png.avif b/shop/static/shop/images/products/PC007/blanc-bleu-sport/PS_PA1030_WHITE-SPORTYNAVY.png.avif similarity index 100% rename from shop/static/shop/images/products/PS_PA1030_WHITE-SPORTYNAVY.png.avif rename to shop/static/shop/images/products/PC007/blanc-bleu-sport/PS_PA1030_WHITE-SPORTYNAVY.png.avif diff --git a/shop/static/shop/images/products/PC007/blanc-gris-clair/PS_PA1030-B_WHITE-FINEGREY.png.avif b/shop/static/shop/images/products/PC007/blanc-gris-clair/PS_PA1030-B_WHITE-FINEGREY.png.avif new file mode 100644 index 0000000..8c7d292 Binary files /dev/null and b/shop/static/shop/images/products/PC007/blanc-gris-clair/PS_PA1030-B_WHITE-FINEGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC007/blanc-gris-clair/PS_PA1030-S_WHITE-FINEGREY.png.avif b/shop/static/shop/images/products/PC007/blanc-gris-clair/PS_PA1030-S_WHITE-FINEGREY.png.avif new file mode 100644 index 0000000..60a13d0 Binary files /dev/null and b/shop/static/shop/images/products/PC007/blanc-gris-clair/PS_PA1030-S_WHITE-FINEGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC007/blanc-gris-clair/PS_PA1030_WHITE-FINEGREY.png.avif b/shop/static/shop/images/products/PC007/blanc-gris-clair/PS_PA1030_WHITE-FINEGREY.png.avif new file mode 100644 index 0000000..4084a47 Binary files /dev/null and b/shop/static/shop/images/products/PC007/blanc-gris-clair/PS_PA1030_WHITE-FINEGREY.png.avif differ diff --git a/shop/static/shop/images/products/PC007/gris-fonce-chine-noir/PS_PA1030-B_MARLDARKGREY-BLACK.png.avif b/shop/static/shop/images/products/PC007/gris-fonce-chine-noir/PS_PA1030-B_MARLDARKGREY-BLACK.png.avif new file mode 100644 index 0000000..e549cc5 Binary files /dev/null and b/shop/static/shop/images/products/PC007/gris-fonce-chine-noir/PS_PA1030-B_MARLDARKGREY-BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC007/gris-fonce-chine-noir/PS_PA1030-S_MARLDARKGREY-BLACK.png.avif b/shop/static/shop/images/products/PC007/gris-fonce-chine-noir/PS_PA1030-S_MARLDARKGREY-BLACK.png.avif new file mode 100644 index 0000000..074fbb1 Binary files /dev/null and b/shop/static/shop/images/products/PC007/gris-fonce-chine-noir/PS_PA1030-S_MARLDARKGREY-BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC007/gris-fonce-chine-noir/PS_PA1030_MARLDARKGREY-BLACK.png.avif b/shop/static/shop/images/products/PC007/gris-fonce-chine-noir/PS_PA1030_MARLDARKGREY-BLACK.png.avif new file mode 100644 index 0000000..8588556 Binary files /dev/null and b/shop/static/shop/images/products/PC007/gris-fonce-chine-noir/PS_PA1030_MARLDARKGREY-BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC007/noir/PS_PA1030-B_BLACK.png.avif b/shop/static/shop/images/products/PC007/noir/PS_PA1030-B_BLACK.png.avif new file mode 100644 index 0000000..1c486cf Binary files /dev/null and b/shop/static/shop/images/products/PC007/noir/PS_PA1030-B_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC007/noir/PS_PA1030-S_BLACK.png.avif b/shop/static/shop/images/products/PC007/noir/PS_PA1030-S_BLACK.png.avif new file mode 100644 index 0000000..b35a48e Binary files /dev/null and b/shop/static/shop/images/products/PC007/noir/PS_PA1030-S_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/PC007/noir/PS_PA1030_BLACK.png.avif b/shop/static/shop/images/products/PC007/noir/PS_PA1030_BLACK.png.avif new file mode 100644 index 0000000..4d3574a Binary files /dev/null and b/shop/static/shop/images/products/PC007/noir/PS_PA1030_BLACK.png.avif differ diff --git a/shop/static/shop/images/products/hat.jpg b/shop/static/shop/images/products/hat.jpg deleted file mode 100644 index 3a67a20..0000000 Binary files a/shop/static/shop/images/products/hat.jpg and /dev/null differ diff --git a/shop/static/shop/images/products/tshirt_h.png b/shop/static/shop/images/products/tshirt_h.png deleted file mode 100644 index b82c8c3..0000000 Binary files a/shop/static/shop/images/products/tshirt_h.png and /dev/null differ diff --git a/shop/templates/shop/product_item.html b/shop/templates/shop/product_item.html index 047ec50..4cdb4bb 100644 --- a/shop/templates/shop/product_item.html +++ b/shop/templates/shop/product_item.html @@ -2,10 +2,21 @@
{% if product.image %} - {{ product.title }} +
+ {% color_images_url product.image product.colors.all.0.name product.sku as images %} +
+ {% for image_url in images %} + {{ product.title }} + {% endfor %} +
+ {% if images|length > 1 %} + + + {% endif %} +
{% else %}
No Image Available
{% endif %} @@ -28,17 +39,19 @@
{% for color in product.colors.all %} + {% color_images_url product.image color.name product.sku as color_images %}
+ data-color-images="{{ color_images|join:',' }}" + onclick="selectColor('{{ product.id }}', '{{ color.id }}', '{{ color.name }}', this)"> +
{% endfor %}
{% endif %} @@ -129,14 +142,30 @@ function selectColor(productId, colorId, colorName, element) { // Add selected class to clicked color element.classList.add('selected'); - // Update product image based on selected color - const productImage = document.getElementById(`product-image-${productId}`); + // Update product images based on selected color + const slider = document.getElementById(`slider-${productId}`); + if (slider) { + const colorImages = element.getAttribute('data-color-images').split(','); + const slidesContainer = slider.querySelector('.slides'); - if (productImage) { - const colorImage = element.getAttribute('data-color-image'); - if (colorImage) { - productImage.src = colorImage; - } + // Clear existing slides + slidesContainer.innerHTML = ''; + + // Add new slides + colorImages.forEach((imageUrl, index) => { + const img = document.createElement('img'); + img.src = imageUrl; + img.alt = colorName; + img.className = `product-image ${index === 0 ? 'active' : ''}`; + img.id = `product-image-${productId}-${index}`; + slidesContainer.appendChild(img); + }); + + // Update navigation buttons visibility + const navButtons = slider.querySelectorAll('.prev, .next'); + navButtons.forEach(button => { + button.style.display = colorImages.length > 1 ? 'block' : 'none'; + }); } } @@ -212,4 +241,21 @@ function addToCartAjax(productId) { }, 3000); }); } + +function changeSlide(productId, direction) { + const slides = document.querySelectorAll(`#slider-${productId} .product-image`); + let activeIndex = Array.from(slides).findIndex(slide => slide.classList.contains('active')); + + // Remove active class from current slide + slides[activeIndex].classList.remove('active'); + + // Calculate new index + activeIndex = activeIndex + direction; + if (activeIndex >= slides.length) activeIndex = 0; + if (activeIndex < 0) activeIndex = slides.length - 1; + + // Add active class to new slide + slides[activeIndex].classList.add('active'); +} + diff --git a/shop/templatetags/shop_extras.py b/shop/templatetags/shop_extras.py index c6f6406..704d9d1 100644 --- a/shop/templatetags/shop_extras.py +++ b/shop/templatetags/shop_extras.py @@ -2,69 +2,66 @@ from django import template import os register = template.Library() +from django.conf import settings -@register.filter -def color_image_url(product_image, color_name): +@register.simple_tag +def color_images_url(default_image, color_name, sku): """ - Returns color-specific image URL with any supported extension. - Falls back to the original image if no color variant exists. + Returns color-specific image URLs from the color-specific folder structure. + Structure expected: + static/shop/images/products/ + ├── {sku}/ + │ ├── default.jpg (or any supported extension) + │ └── {color_name}/ + │ └── image.jpg (or any supported extension) """ - if not product_image or not color_name: - return product_image - - # Generate color suffix - suffix = generate_color_suffix(color_name) - - # Split path - directory, filename = os.path.split(product_image) - base_name, original_ext = os.path.splitext(filename) - - # List of supported image extensions to check + # List of supported image extensions supported_extensions = ['.png.avif', '.jpg', '.jpeg', '.png', '.gif', '.webp', '.avif'] - # Check for the color image with original extension first - color_filename = f"{suffix}_{base_name}{original_ext}" - color_image = os.path.join(directory, color_filename) - - # Extract the path after /static/ - static_prefix = '/static/' - if color_image.startswith(static_prefix): - rel_path = color_image[len(static_prefix):] - else: - rel_path = color_image.lstrip('/') - - # Check if file with original extension exists - from django.conf import settings - app_static_path = os.path.join(settings.BASE_DIR, 'shop', 'static', rel_path) - - if os.path.exists(app_static_path): - return color_image - - # If not found with original extension, try other extensions - for ext in supported_extensions: - if ext == original_ext: - continue # Skip the original extension as we already checked it - - color_filename = f"{suffix}_{base_name}{ext}" - color_image = os.path.join(directory, color_filename) - - if color_image.startswith(static_prefix): - rel_path = color_image[len(static_prefix):] - else: - rel_path = color_image.lstrip('/') - - app_static_path = os.path.join(settings.BASE_DIR, 'shop', 'static', rel_path) - - if os.path.exists(app_static_path): - return color_image - - # If no color variant is found with any extension, return the original image - return product_image - -def generate_color_suffix(color_name): + # Base path for products + base_path = f'/static/shop/images/products/{sku}/' + physical_base_path = os.path.join(settings.BASE_DIR, 'shop', 'static', 'shop', 'images', 'products', sku) + + if color_name: + # Generate color folder name (sanitize the color name) + color_folder = generate_color_folder_name(color_name) + + # Check color-specific folder + color_path = os.path.join(physical_base_path, color_folder) + if os.path.exists(color_path): + # Get all images from color folder + files = [f for f in os.listdir(color_path) + if any(f.lower().endswith(ext) for ext in supported_extensions)] + + if files: + # Sort files by specific prefix rules + files.sort(key=lambda x: ( + 1 if '-B_' in x else + 2 if '-S_' in x else + 0 + )) + return [f'{base_path}{color_folder}/{file}' for file in files] + + # If no color-specific image found, look for default image in product folder + if os.path.exists(physical_base_path): + files = [f for f in os.listdir(physical_base_path) + if os.path.isfile(os.path.join(physical_base_path, f)) and + any(f.lower().endswith(ext) for ext in supported_extensions)] + if files: + files.sort(key=lambda x: ( + 1 if '-B_' in x else + 2 if '-S_' in x else + 0 + )) + return [f'{base_path}{file}' for file in files] + + # If nothing found, return list with default image + return [default_image] + +def generate_color_folder_name(color_name): """ - Generates a URL-friendly suffix from a color name - Example: "Noir / Gris Foncé Chiné" becomes "noir_gris_fonce_chine" + Generates a folder-friendly name from a color name + Example: "Noir / Gris Foncé Chiné" becomes "noir-gris-fonce-chine" """ import unicodedata import re @@ -73,10 +70,10 @@ def generate_color_suffix(color_name): value = color_name.lower() value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') - # Replace slashes and spaces with underscores - value = re.sub(r'[/\s]+', '_', value) + # Replace slashes and spaces with hyphens + value = re.sub(r'[/\s]+', '-', value) - # Remove any remaining non-alphanumeric characters - value = re.sub(r'[^\w_]', '', value) + # Remove any remaining non-alphanumeric characters except hyphens + value = re.sub(r'[^\w-]', '', value) return value