231da2cbaa
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 3m10s
- Add two sections to landing page (Index.razor) below the hero: - Top 6 best-selling regular products (3-per-row grid) - Top 6 best-selling discount store products (3-per-row grid) - Each section has a 'More' button linking to /products and /discount-store - Add GuestActionGate utility service: wraps auth-required actions; shows login modal for guests and resumes the original action after successful login - Register GuestActionGate as scoped service in ConfigureServices - Add GetTopSellingAsync(count) to ProductService and DiscountProductService - Add optional sortBy parameter to DiscountProductService.GetProductsAsync - Hybridize all product pages for guest browsing: - Store/Products, Store/ProductDetail: wrap AddToCart with GuestActionGate - DiscountStore/Products, DiscountStore/ProductDetail: wrap AddToCart with GuestActionGate - Store/Cart, DiscountStore/Cart, Store/CheckoutSummary: soft auth gate on page init - Fix MembershipPage membership benefit text to be package-agnostic Co-authored-by: Cursor <cursoragent@cursor.com>
123 lines
4.3 KiB
C#
123 lines
4.3 KiB
C#
using CMSMicroservice.Protobuf.Protos.UserAddress;
|
|
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
|
using FrontOffice.Main.Utilities;
|
|
using Microsoft.AspNetCore.Components;
|
|
using MudBlazor;
|
|
using Messages = CMSMicroservice.Protobuf.Protos;
|
|
|
|
namespace FrontOffice.Main.Pages.Store;
|
|
|
|
public partial class CheckoutSummary : ComponentBase
|
|
{
|
|
[Inject] private CartService Cart { get; set; } = default!;
|
|
[Inject] private OrderService OrderService { get; set; } = default!;
|
|
[Inject] private VATService VAT { get; set; } = default!;
|
|
[Inject] private UserAddressContract.UserAddressContractClient UserAddressContract { get; set; } = default!;
|
|
[Inject] private UserOrderContract.UserOrderContractClient UserOrderContract { get; set; } = default!;
|
|
[Inject] private AuthDialogService AuthDialogService { get; set; } = default!;
|
|
[Inject] private AuthService AuthService { get; set; } = default!;
|
|
// Snackbar and Navigation are injected via _Imports.razor
|
|
|
|
private List<CustomerAddressModel> _addresses = new();
|
|
private CustomerAddressModel? _selectedAddress;
|
|
private bool _loadingAddresses;
|
|
private long walletBalance;
|
|
|
|
private Messages.PaymentMethod _payment = Messages.PaymentMethod.Wallet;
|
|
|
|
private bool CanPlaceOrder => Cart.Items.Count > 0 && _selectedAddress != null;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (!await AuthService.IsAuthenticatedAsync())
|
|
{
|
|
await AuthDialogService.ShowAuthDialogAsync();
|
|
}
|
|
// لود سبد خرید (فقط اگر کاربر لاگین کرده باشد)
|
|
await Cart.EnsureInitializedAsync();
|
|
await LoadAddresses();
|
|
await LoadWalletBalance();
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
// بارگذاری نرخ VAT
|
|
await VAT.LoadAsync();
|
|
}
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
}
|
|
|
|
private async Task LoadWalletBalance()
|
|
{
|
|
var walletResult = await WalletService.GetBalancesAsync();
|
|
walletBalance = walletResult.CreditBalance
|
|
// + walletResult.NetworkBalance
|
|
;
|
|
}
|
|
|
|
private async Task LoadAddresses()
|
|
{
|
|
_loadingAddresses = true;
|
|
try
|
|
{
|
|
var response = await UserAddressContract.GetCustomerAddressesAsync(new());
|
|
if (response?.Models?.Any() == true)
|
|
{
|
|
_addresses = response.Models.ToList();
|
|
_selectedAddress = _addresses.FirstOrDefault(a => a.IsDefault) ?? _addresses.First();
|
|
}
|
|
else
|
|
{
|
|
_addresses = new();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"خطا در بارگذاری آدرسها: {ex.Message}", Severity.Error);
|
|
_addresses = new();
|
|
}
|
|
finally
|
|
{
|
|
_loadingAddresses = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
private async Task PlaceOrder()
|
|
{
|
|
if (!CanPlaceOrder || _selectedAddress is null)
|
|
{
|
|
Snackbar.Add("لطفاً آدرس را انتخاب کنید و سبد خرید را بررسی کنید.", Severity.Warning);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var request = new SubmitShopBuyOrderRequest
|
|
{
|
|
TotalAmount = VAT.AddVAT(Cart.Total)
|
|
};
|
|
|
|
var response = await UserOrderContract.SubmitShopBuyOrderAsync(request);
|
|
await Cart.Clear();
|
|
Snackbar.Add("سفارش با موفقیت ثبت شد.", Severity.Success);
|
|
Navigation.NavigateTo($"{RouteConstants.Store.OrderDetail}{response.Id}");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"خطا در ثبت سفارش: {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
|
|
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);
|
|
|
|
/// <summary>
|
|
/// محاسبه مالیات بر ارزش افزوده
|
|
/// </summary>
|
|
private long CalculateVAT() => VAT.CalculateVAT(Cart.Total);
|
|
|
|
private static string GetProductImageUrl(string? imageUrl)
|
|
=> string.IsNullOrWhiteSpace(imageUrl) ? "/images/product-placeholder.svg" : imageUrl.TrimStart('/');
|
|
} |