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
@@ -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;
}