Add product categories and full information display

This commit is contained in:
masoodafar-web
2025-11-28 10:13:46 +03:30
parent 82ddafda33
commit fe5f7bd9b9
4 changed files with 116 additions and 16 deletions

View File

@@ -52,6 +52,26 @@ else
<MudStack Spacing="2">
<MudText Typo="Typo.h4">@_product.Title</MudText>
<MudText Typo="Typo.body1" Class="mud-text-secondary">@_product.Description</MudText>
@if (!string.IsNullOrWhiteSpace(_product.FullInformation))
{
<MudText Typo="Typo.body2" Class="mud-text-secondary" GutterBottom="true">
@((MarkupString)_product.FullInformation)
</MudText>
}
@if (_categoryPaths.Count > 0)
{
<MudStack Spacing="1">
<MudText Typo="Typo.caption" Class="mud-text-secondary">دسته‌بندی‌ها</MudText>
<MudStack Row="true" Spacing="1" Wrap="Wrap.Wrap">
@foreach (var categoryPath in _categoryPaths)
{
<MudChip T="string" Variant="Variant.Outlined" Color="Color.Primary" OnClick="() => NavigateToCategory(categoryPath)">
@GetCategoryLabel(categoryPath)
</MudChip>
}
</MudStack>
</MudStack>
}
<MudDivider Class="my-2"/>
<MudText Typo="Typo.h5" Color="Color.Primary">@FormatPrice(_product.Price)</MudText>

View File

@@ -19,6 +19,7 @@ public partial class ProductDetail : ComponentBase, IDisposable
private const int MinQty = 1;
private const int MaxQty = 20;
private IReadOnlyList<ProductGalleryImage> _galleryItems = Array.Empty<ProductGalleryImage>();
private IReadOnlyList<ProductCategoryPathInfo> _categoryPaths = Array.Empty<ProductCategoryPathInfo>();
private ProductGalleryImage? _selectedGalleryImage;
private long TotalPrice => (_product?.Price ?? 0) * _qty;
private bool HasDiscount => _product is { Discount: > 0 and < 100 };
@@ -36,6 +37,13 @@ public partial class ProductDetail : ComponentBase, IDisposable
protected override async Task OnParametersSetAsync()
{
}
protected override async Task OnInitializedAsync()
{
Cart.OnChange += HandleCartChanged;
_loading = true;
_product = await ProductService.GetByIdAsync(id);
_loading = false;
@@ -43,20 +51,20 @@ public partial class ProductDetail : ComponentBase, IDisposable
{
_galleryItems = BuildGalleryItems(_product);
_selectedGalleryImage = _galleryItems.FirstOrDefault();
_categoryPaths = _product.Categories;
_qty = Math.Clamp(CurrentCartItem?.Quantity ?? _qty, MinQty, MaxQty);
}
else
{
_galleryItems = Array.Empty<ProductGalleryImage>();
_categoryPaths = Array.Empty<ProductCategoryPathInfo>();
}
StateHasChanged();
await base.OnInitializedAsync();
}
protected override void OnInitialized()
{
Cart.OnChange += HandleCartChanged;
}
private async Task AddToCart()
{
@@ -163,4 +171,13 @@ public partial class ProductDetail : ComponentBase, IDisposable
if (_selectedGalleryImage == item) return;
_selectedGalleryImage = item;
}
private void NavigateToCategory(ProductCategoryPathInfo path)
{
var target = $"{RouteConstants.Store.Products}?category={path.CategoryId}";
Navigation.NavigateTo(target);
}
private string GetCategoryLabel(ProductCategoryPathInfo path)
=> path.DisplayLabel;
}