This commit is contained in:
Mamalizz
2025-02-06 22:58:23 +03:30
6 changed files with 271 additions and 84 deletions
@@ -0,0 +1,20 @@
# Generated by Django 5.1.2 on 2025-02-06 17:55
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('order', '0002_alter_discountcode_expiration_date_and_more'),
('product', '0015_attributetype_productdetailcategory_attributevalue_and_more'),
]
operations = [
migrations.AlterField(
model_name='orderitemmodel',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='product.productmodel', verbose_name='محصول'),
),
]
+73 -12
View File
@@ -11,6 +11,20 @@ from unfold.widgets import (
)
from unfold.decorators import action, display
@admin.register(ProductDetailCategory)
class ProductDetailCategoryAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
search_fields = ['title']
compressed_fields = True
warn_unsaved_form = True
formfield_overrides = {
ArrayField: {
"widget": ArrayWidget,
}
}
@admin.register(InPackItems)
class InPackItemsAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
@@ -24,15 +38,61 @@ class InPackItemsAdmin(ModelAdmin, ImportExportModelAdmin):
"widget": ArrayWidget,
}
}
class InStuckColorsInLine(TabularInline):
model = InStuckColors
extra = 0
tab = True
@admin.register(AttributeType)
class AttributeTypeAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
search_fields = ['name']
compressed_fields = True
warn_unsaved_form = True
formfield_overrides = {
models.CharField: {"widget": UnfoldAdminColorInputWidget()},
ArrayField: {
"widget": ArrayWidget,
}
}
verbose_name = 'رنگ موجود'
verbose_name_plural = 'رنگ‌های موجود'
@admin.register(AttributeValue)
class AttributeValueAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
search_fields = ['value']
compressed_fields = True
warn_unsaved_form = True
formfield_overrides = {
ArrayField: {
"widget": ArrayWidget,
}
}
def get_form(self, request, obj=None, change=False, **kwargs):
form = super().get_form(request, obj, change, **kwargs)
form.base_fields["color"].widget = UnfoldAdminColorInputWidget()
return form
class ProductVariantInLine(StackedInline):
model = ProductVariant
extra = 0
show_change_link = True
tab = True
autocomplete_fields = ['attributes']
# search_fields = ['']
def get_form(self, request, obj=None, change=False, **kwargs):
form = super().get_form(request, obj, change, **kwargs)
form.base_fields["color"].widget = UnfoldAdminColorInputWidget()
return form
@admin.register(DetailModel)
@@ -55,20 +115,21 @@ class DetailModelAdmin(ModelAdmin, ImportExportModelAdmin):
class DetailModelInLine(StackedInline):
model = ProductDetailModel
extra = 0
show_change_link = True
tab = True
autocomplete_fields = ['detail']
verbose_name = 'جزئیات محصول'
verbose_name_plural = 'جزئیات محصول'
autocomplete_fields = ['detail', 'detail_category']
@admin.register(ProductModel)
class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
inlines = [InStuckColorsInLine, DetailModelInLine]
inlines = [ProductVariantInLine, DetailModelInLine]
readonly_fields = ('slug', )
search_fields = ['name', 'description', ]
list_filter = ['currency', 'show', 'category']
autocomplete_fields = ['related_products', 'in_pack_items']
autocomplete_fields = ['related_products', 'in_pack_items',]
# compressed_fields = True
warn_unsaved_form = True
list_display = ['display_image', 'display_price', 'view', 'show', 'rating', 'category', 'discount', 'sell']
@@ -0,0 +1,70 @@
# Generated by Django 5.1.2 on 2025-02-06 17:55
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('product', '0014_inpackitems_alter_productdetailmodel_product_and_more'),
]
operations = [
migrations.CreateModel(
name='AttributeType',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, verbose_name='نام نوع اتربیوت')),
],
),
migrations.CreateModel(
name='ProductDetailCategory',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=40, verbose_name='عنوان')),
],
options={
'verbose_name': 'دسته بندی جزيات',
'verbose_name_plural': 'دسته بندی های جزيیات',
},
),
migrations.CreateModel(
name='AttributeValue',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.CharField(max_length=100, verbose_name='مقدار نوع اتربیوت')),
('color', models.CharField(blank=True, max_length=7, null=True, verbose_name='رنک')),
('attribute_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='product.attributetype')),
],
options={
'unique_together': {('attribute_type', 'value')},
},
),
migrations.AddField(
model_name='productdetailmodel',
name='detail_category',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='product.productdetailcategory', verbose_name='دسته بندی جزيات'),
),
migrations.AlterUniqueTogether(
name='productdetailmodel',
unique_together={('product', 'detail_category')},
),
migrations.CreateModel(
name='ProductVariant',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('in_stock', models.PositiveIntegerField(default=0, verbose_name='تعداد موجود')),
('price', models.PositiveIntegerField(blank=True, null=True, verbose_name='قیمت (اختیاری)')),
('attributes', models.ManyToManyField(to='product.attributevalue', verbose_name='ویژگی\u200cها')),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='variants', to='product.productmodel', verbose_name='محصول')),
],
options={
'verbose_name': 'تنوع محصول',
'verbose_name_plural': 'تنوع\u200cهای محصول',
},
),
migrations.DeleteModel(
name='InStuckColors',
),
]
+45 -10
View File
@@ -181,28 +181,31 @@ class DetailModel(models.Model):
verbose_name_plural = 'مدل های جزیات'
class ProductDetailCategory(models.Model):
title = models.CharField(max_length=40, verbose_name='عنوان')
def __str__(self):
return self.title
class Meta:
verbose_name = 'دسته بندی جزيات'
verbose_name_plural = 'دسته بندی های جزيیات'
class ProductDetailModel(models.Model):
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, verbose_name='محصول مرتبط', related_name='details')
detail_category = models.ForeignKey(ProductDetailCategory, on_delete=models.CASCADE, verbose_name='دسته بندی جزيات', blank=True, null=True)
detail = models.ManyToManyField(DetailModel, verbose_name='جزيات ها')
class Meta:
verbose_name = 'جزیات محصول'
verbose_name_plural = 'جزیات محصول ها'
unique_together = ('product', 'detail_category')
def __str__(self):
return f'جزيیات محصول {self.product}'
class InStuckColors(models.Model):
color = models.CharField(_("رنگ"), null=True, blank=True, max_length=255)
in_stuck = models.PositiveIntegerField(default=0, verbose_name="تعداد موجود")
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='colors', verbose_name='محصول')
class Meta:
verbose_name = 'تعداد موجود رنگ'
verbose_name_plural = 'تعداد موجود رنگ ها'
def __str__(self):
return f'{self.product} - {self.color}'
class CommentModel(models.Model):
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='comments', verbose_name='محصول')
@@ -215,3 +218,35 @@ class CommentModel(models.Model):
verbose_name_plural = 'نظرات'
def __str__(self):
return f"{self.user}-{self.content[:30]}"
class AttributeType(models.Model):
name = models.CharField(verbose_name='نام نوع اتربیوت', max_length=100)
def __str__(self):
return self.name
class AttributeValue(models.Model):
attribute_type = models.ForeignKey(AttributeType, on_delete=models.CASCADE)
value = models.CharField(verbose_name='مقدار نوع اتربیوت', max_length=100)
color = models.CharField(verbose_name='رنک', max_length=7, blank=True, null=True)
class Meta:
unique_together = ('attribute_type', 'value')
def __str__(self):
return f"{self.attribute_type.name}: {self.value}"
class ProductVariant(models.Model):
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='variants', verbose_name='محصول')
attributes = models.ManyToManyField(AttributeValue, verbose_name='ویژگی‌ها')
in_stock = models.PositiveIntegerField(default=0, verbose_name='تعداد موجود')
price = models.PositiveIntegerField(null=True, blank=True, verbose_name='قیمت (اختیاری)')
class Meta:
verbose_name = 'تنوع محصول'
verbose_name_plural = 'تنوع‌های محصول'
def __str__(self):
return f"{self.product.name} - {', '.join(str(attr) for attr in self.attributes.all())}"
+5 -8
View File
@@ -4,10 +4,7 @@ from django.utils import timezone
from datetime import timedelta
class InStuckColorsSerializer(serializers.ModelSerializer):
class Meta:
model = InStuckColors
fields = ['color', 'in_stuck']
class DetailSerializer(serializers.ModelSerializer):
@@ -24,7 +21,7 @@ class ProductDetailSerializer(serializers.ModelSerializer):
class DynamicProductSerializer(serializers.ModelSerializer):
colors = InStuckColorsSerializer(many=True, read_only=True)
price = serializers.SerializerMethodField()
is_new = serializers.SerializerMethodField()
related_products = serializers.SerializerMethodField()
@@ -45,9 +42,9 @@ class DynamicProductSerializer(serializers.ModelSerializer):
model = ProductModel
fields = "__all__"
view_type = {
'list': ['name', 'price', 'image1', 'video', 'rating', 'discount', 'slug', 'category', 'colors'],
'instance': ['name', 'description', 'price', 'image1', 'image2', 'image3', 'video', 'rating', 'discount', 'slug', 'meta_description', 'meta_keywords', 'meta_rating', 'category', 'colors', 'related_products', 'details', 'in_pack_items'],
'chat': ['name', 'description', 'price', 'in_stock', 'discount', 'colors']
'list': ['name', 'price', 'image1', 'video', 'rating', 'discount', 'slug', 'category', ],
'instance': ['name', 'description', 'price', 'image1', 'image2', 'image3', 'video', 'rating', 'discount', 'slug', 'meta_description', 'meta_keywords', 'meta_rating', 'category', 'related_products', 'details', 'in_pack_items'],
'chat': ['name', 'description', 'price', 'in_stock', 'discount', ]
}
def get_price(self, obj):
+57 -53
View File
@@ -10,9 +10,19 @@ import useHomeData from "~/composables/api/home/useHomeData";
const { data: homeData } = useHomeData();
const { $gsap: gsap, $ScrollTrigger: ScrollTrigger } = useNuxtApp();
const route = useRoute();
const swiper_instance = ref<SwiperClass | null>(null);
const observerTarget = ref(null);
const shouldPauseVideos = ref(false);
useIntersectionObserver(
observerTarget,
([entry], observerElement) => {
console.log(entry.rootBounds ? !entry.isIntersecting : false, "asdad");
shouldPauseVideos.value = entry.rootBounds ? !entry.isIntersecting : false;
}
);
const isMuted = ref(true);
const slidesPerView = ref(1);
@@ -24,14 +34,30 @@ const onSwiper = (swiper: SwiperClass) => {
swiper_instance.value = swiper;
};
const onChange = (swiper: SwiperClass) => {
console.log(swiper.activeIndex, swiper.realIndex, swiper.snapIndex);
const updateVideoStates = () => {
const activeIndex = swiper_instance.value?.realIndex || 0;
const videosElements = document.querySelectorAll(`.slide-video`) as NodeListOf<HTMLVideoElement>;
videosElements.forEach(videoElement => {
if (videoElement.id === `slide-video-${activeIndex}` && !shouldPauseVideos.value) {
videoElement.play();
} else {
videoElement.pause();
}
});
};
// watch
watch(() => [shouldPauseVideos.value, swiper_instance.value?.realIndex], () => {
updateVideoStates();
});
// lifecycle
onMounted(() => {
gsapTimeline = gsap.timeline({});
updateVideoStates();
gsapTimeline = gsap.timeline();
gsapTimeline
.fromTo(".header-slider-item", {
@@ -89,16 +115,9 @@ onMounted(() => {
});
watch(() => route.path, (nv) => {
if (gsapTimeline) {
if (nv === "/") {
gsapTimeline.play();
} else {
gsapTimeline.pause().progress(0);
}
}
}, {
immediate: true
onUnmounted(() => {
gsapTimeline.progress(1).pause();
gsapTimeline.kill();
});
</script>
@@ -108,12 +127,12 @@ watch(() => route.path, (nv) => {
<div id="header-slider-wrapper" class="relative">
<Swiper
ref="observerTarget"
:slides-per-view="slidesPerView"
:loop="true"
:space-between="40"
:centered-slides="true"
@swiper="onSwiper"
@slide-change="onChange"
>
<SwiperSlide
v-for="(slide, index) in homeData!.sliders"
@@ -123,43 +142,11 @@ watch(() => route.path, (nv) => {
class="header-slider-item relative w-full overflow-hidden"
>
<template v-if="!!slide.video">
<div class="flex items-center justify-between w-full absolute z-20 top-10 px-20">
<button
@click="isMuted = !isMuted"
class="transition-all cursor-pointer flex-center hover:scale-110 size-[50px] rounded-full bg-white"
>
<Icon
:name="isMuted ? 'bi:volume-mute-fill' : 'bi:volume-up-fill'"
class="text-black"
size="24px"
/>
</button>
<!-- <div class="header-slider-logo">-->
<!-- <svg-->
<!-- xmlns="http://www.w3.org/2000/svg"-->
<!-- height="23"-->
<!-- fill="none"-->
<!-- viewBox="0 0 220 40"-->
<!-- >-->
<!-- <path-->
<!-- fill="white"-->
<!-- d="M20 40c11.046 0 20-8.954 20-20V6a6 6 0 0 0-6-6H21v8.774c0 2.002.122 4.076 1.172 5.78a9.999 9.999 0 0 0 6.904 4.627l.383.062a.8.8 0 0 1 0 1.514l-.383.062a10 10 0 0 0-8.257 8.257l-.062.383a.8.8 0 0 1-1.514 0l-.062-.383a10 10 0 0 0-4.627-6.904C12.85 21.122 10.776 21 8.774 21H.024C.547 31.581 9.29 40 20 40Z"-->
<!-- ></path>-->
<!-- <path-->
<!-- fill="white"-->
<!-- d="M0 19h8.774c2.002 0 4.076-.122 5.78-1.172a10.018 10.018 0 0 0 3.274-3.274C18.878 12.85 19 10.776 19 8.774V0H6a6 6 0 0 0-6 6v13ZM46.455 2a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM211.711 12.104c5.591 0 8.289 3.905 8.289 8.428v8.495h-5.851V21.54c0-2.05-.748-3.742-2.893-3.742-2.145 0-2.86 1.692-2.86 3.742v7.486h-5.851V21.54c0-2.05-.715-3.742-2.861-3.742-2.145 0-2.893 1.692-2.893 3.742v7.486h-5.85v-8.495c0-4.523 2.697-8.428 8.288-8.428 3.056 0 5.266 1.204 6.274 3.189 1.072-1.985 3.413-3.19 6.208-3.19ZM180.427 23.82c1.885 0 2.698-1.725 2.698-3.776v-7.29h5.85v8.006c0 4.784-2.795 8.755-8.548 8.755-5.754 0-8.549-3.97-8.549-8.755v-8.006h5.851v7.29c0 2.05.812 3.776 2.698 3.776ZM163.275 29.547c-3.673 0-6.046-1.269-7.444-3.742l4.226-2.376c.585 1.041 1.462 1.562 2.925 1.562 1.203 0 1.755-.423 1.755-.944 0-1.985-8.581.033-8.581-6.28 0-3.06 2.6-5.533 7.021-5.533 3.868 0 5.981 1.887 6.924 3.71l-4.226 2.408c-.357-.976-1.463-1.562-2.568-1.562-.845 0-1.3.358-1.3.846 0 2.018 8.581.163 8.581 6.281 0 3.417-3.348 5.63-7.313 5.63ZM142.833 36.512h-5.851V20.858c0-4.98 3.738-8.592 8.939-8.592 5.071 0 8.939 3.873 8.939 8.592 0 5.207-3.446 8.657-8.614 8.657-1.203 0-2.405-.358-3.413-.912v7.909Zm3.088-12.497c1.853 0 3.088-1.432 3.088-3.125 0-1.724-1.235-3.124-3.088-3.124s-3.088 1.4-3.088 3.125c0 1.692 1.235 3.124 3.088 3.124ZM131.121 11.03c-1.918 0-3.51-1.595-3.51-3.515 0-1.92 1.592-3.515 3.51-3.515 1.918 0 3.511 1.595 3.511 3.515 0 1.92-1.593 3.515-3.511 3.515Zm-2.925 1.724h5.851v16.273h-5.851V12.754ZM116.97 29.515c-5.071 0-8.939-3.905-8.939-8.657 0-4.719 3.868-8.624 8.939-8.624s8.939 3.905 8.939 8.624c0 4.752-3.868 8.657-8.939 8.657Zm0-5.5c1.853 0 3.088-1.432 3.088-3.125 0-1.724-1.235-3.156-3.088-3.156s-3.088 1.432-3.088 3.156c0 1.693 1.235 3.125 3.088 3.125ZM96.983 37c-4.03 0-6.956-1.79-8.451-4.98l4.843-2.603c.52 1.107 1.495 2.246 3.51 2.246 2.114 0 3.511-1.335 3.674-3.678-.78.684-2.016 1.204-3.868 1.204-4.519 0-8.16-3.482-8.16-8.364 0-4.718 3.869-8.559 8.94-8.559 5.201 0 8.939 3.613 8.939 8.592v6.444c0 5.858-4.064 9.698-9.427 9.698Zm.39-13.31c1.755 0 3.088-1.205 3.088-2.995 0-1.757-1.332-2.929-3.088-2.929-1.723 0-3.088 1.172-3.088 2.93 0 1.79 1.365 2.993 3.088 2.993ZM78.607 29.515c-5.071 0-8.94-3.905-8.94-8.657 0-4.719 3.869-8.624 8.94-8.624 5.07 0 8.939 3.905 8.939 8.624 0 4.752-3.869 8.657-8.94 8.657Zm0-5.5c1.853 0 3.088-1.432 3.088-3.125 0-1.724-1.235-3.156-3.088-3.156s-3.088 1.432-3.088 3.156c0 1.693 1.235 3.125 3.088 3.125ZM59.013 7.06v16.434H68.7v5.533H58.2c-3.705 0-5.2-1.953-5.2-5.045V7.06h6.013Z"-->
<!-- ></path>-->
<!-- </svg>-->
<!-- </div>-->
</div>
<video
:id="`slide-video-${index}`"
:muted="swiper_instance?.realIndex !== index ? true : isMuted"
autoplay
loop
class="absolute inset-0 size-full object-cover brightness-90"
class="slide-video absolute inset-0 size-full object-cover brightness-90"
:src="slide.video"
/>
</template>
@@ -173,9 +160,26 @@ watch(() => route.path, (nv) => {
<div class="header-slider-item-child absolute z-10 w-full bottom-36">
<div class="w-full container">
<div class="border-b border-white/10 pb-6 flex flex-col gap-4">
<h3 class="typo-h-1 tracking-[-2px] text-white">
{{ slide.title }}
</h3>
<div class="flex items-center gap-8">
<div
class="hover:scale-110 size-[50px] relative flex items-center justify-center">
<div
class="size-full scale-75 bg-white absolute rounded-full animate-ping" />
<button
@click="isMuted = !isMuted"
class="transition-all cursor-pointer flex-center bg-white z-10 size-full rounded-full"
>
<Icon
:name="isMuted ? 'bi:volume-mute-fill' : 'bi:volume-up-fill'"
class="text-black"
size="24px"
/>
</button>
</div>
<h3 class="typo-h-1 tracking-[-2px] text-white">
{{ slide.title }}
</h3>
</div>
<div class="flex justify-between items-end">
<span class="typo-p-lg text-white">
{{ slide.description }}