@php
$defaultVariation = \App\Models\Variation::query()
->where(['product_id' => $product->id, 'is_default' => 1])
->first();
if (!$defaultVariation) {
$defaultVariationImage = $product->getFirstMediaUrl(Helper::PRODUCT_MAIN_IMAGE_COLLECTION, 'preview');
} else {
$defaultVariationImage = $defaultVariation->getFirstMediaUrl(Helper::VARIATIONS_COLLECTION, 'preview');
$defaultVariationColor = $defaultVariation->color;
}
$colors = \App\Models\Variation::query()
->where(['product_id' => $product->id, 'is_default' => false, 'is_show' => true])
->select('color_id')
->distinct()
->with(['color'])
->get()
->map(function ($item) {
return $item->color;
});
if (isset($defaultVariationColor)) {
$visibleColors = $colors->where('id', '!=', $defaultVariationColor->id)->take(4);
} else {
$visibleColors = $colors->take(4);
}
$remainingColorsCount = max(0, $colors->count() - $visibleColors->count()); // حساب عدد الألوان المتبقية
@endphp
@if (isset($defaultVariationColor))
@endif
@foreach ($visibleColors as $color)
@endforeach
@if ($remainingColorsCount > 1)
+{{ $remainingColorsCount }}
@endif
@if (auth('web')->check())
@if ($product->isFavoritedByUser(auth('web')->id()))
@else
@endif
@else
@endif