Repository navigation
. - #3
.#3atakanserifoglu wants to merge 2 commits into
Conversation
|
❌ Sorry @atakanserifoglu, your organization has never subscribed to Deeployed Peer. Please register through the dashboard first. |
|
@deeployedpeer review |
|
❌ Sorry @atakanserifoglu, your organization has never subscribed to Deeployed Peer. Please register through the dashboard first. |
|
@deeployed-peer-alpha review |
WalkthroughThis update introduces a new Changes
Sequence DiagramsequenceDiagram
participant GuestUser as Guest User
participant Frontend as Checkout Page
participant Backend as Server (Factories/Controllers)
participant DB as Database (Settings)
GuestUser->>Frontend: Initiates checkout
Frontend->>Backend: Request checkout address page
Backend->>DB: Read TaxSettings
DB-->>Backend: Return EuVatEnabledForGuests setting
alt Guest user & EuVatEnabledForGuests is true
Backend-->>Frontend: Prepare model with VAT input visible
Frontend-->>GuestUser: Display address form with VAT input
GuestUser->>Frontend: Enters address and VAT number, submits form
Frontend->>Backend: POST address data (with VAT number)
Backend->>Backend: Save guest VAT number
else Guest user & EuVatEnabledForGuests is false
Backend-->>Frontend: Prepare model with VAT warning
Frontend-->>GuestUser: Display address form with VAT warning
GuestUser->>Frontend: Enters address, submits form
Frontend->>Backend: POST address data (no VAT number)
Backend->>Backend: Process address without VAT number
end
|
There was a problem hiding this comment.
Commits
Files that changed from the base of the PR and between Base and 4bced88 commits: 16Files Selected For Review: 15
- src/Libraries/Nop.Core/Domain/Tax/TaxSettings.cs with diff length 468.
- src/Libraries/Nop.Services/Installation/InstallationService.cs with diff length 470.
- src/Presentation/Nop.Web.Framework/Migrations/UpgradeTo460/LocalizationMigration.cs with diff length 904.
- src/Presentation/Nop.Web.Framework/Migrations/UpgradeTo460/SettingMigration.cs with diff length 970.
- src/Presentation/Nop.Web/Areas/Admin/Controllers/SettingController.cs with diff length 1410.
- src/Presentation/Nop.Web/Areas/Admin/Factories/SettingModelFactory.cs with diff length 1242.
- src/Presentation/Nop.Web/Areas/Admin/Infrastructure/Mapper/AdminMapperConfiguration.cs with diff length 817.
- src/Presentation/Nop.Web/Areas/Admin/Models/Settings/TaxSettingsModel.cs with diff length 597.
- src/Presentation/Nop.Web/Areas/Admin/Views/Setting/_Tax.VAT.cshtml with diff length 904.
- src/Presentation/Nop.Web/Controllers/CheckoutController.cs with diff length 4975.
- src/Presentation/Nop.Web/Factories/CheckoutModelFactory.cs with diff length 2486.
- src/Presentation/Nop.Web/Models/Common/AddressModel.cs with diff length 578.
- src/Presentation/Nop.Web/Themes/DefaultClean/Content/css/styles.css with diff length 300.
- src/Presentation/Nop.Web/Themes/DefaultClean/Content/css/styles.rtl.css with diff length 300.
- src/Presentation/Nop.Web/Views/Shared/_CreateOrUpdateAddress.cshtml with diff length 1251.
Files excluded from review due to unsupported file extensions: 1
- src/Presentation/Nop.Web/App_Data/Localization/defaultResources.nopres.xml
Review comments generated: (32)
- Review: 6
- LGTM: 26
- Identified issue already discussed: 0
Tips
Chat with Deeployed Bot (@@deeployed-peer-alpha)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@@deeployed-peer-alphain a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@deeployed-peer-alpha: ignoreanywhere in the PR description to pause further reviews from the bot.
| /// <summary> | ||
| /// Gets or sets a value indicating whether EU VAT (Europe Union Value Added Tax) for guest customers is enabled | ||
| /// </summary> | ||
| public int EuVatEnabledForGuests { get; set; } |
There was a problem hiding this comment.
This property seems to represent a boolean state (enabled/disabled). For better type safety and consistency with the existing EuVatEnabled property, it should be of type bool instead of int.
Additionally, the comment could be more specific about what this setting controls, which appears to be the visibility of the VAT number input for guests.
| /// <summary> | |
| /// Gets or sets a value indicating whether EU VAT (Europe Union Value Added Tax) for guest customers is enabled | |
| /// </summary> | |
| public int EuVatEnabledForGuests { get; set; } | |
| /// <summary> | |
| /// Gets or sets a value indicating whether guest customers can enter a VAT number | |
| /// </summary> | |
| public bool EuVatEnabledForGuests { get; set; } |
| _shoppingCartService = shoppingCartService; | ||
| _storeContext = storeContext; | ||
| _taxService = taxService; | ||
| _taxSettings = taxSettings; |
There was a problem hiding this comment.
The _taxSettings field is assigned again on line 131. This assignment is a duplicate and can be removed to avoid redundancy.
| _taxSettings = taxSettings; |
| if (await _customerService.IsGuestAsync(customer) && _taxSettings.EuVatEnabled && _taxSettings.EuVatEnabledForGuests) | ||
| await SaveCustomerVatNumberAsync(model.BillingNewAddress.VatNumber, customer); |
There was a problem hiding this comment.
The await _customerService.IsGuestAsync(customer) call is also made on line 581. To improve performance and adhere to the DRY principle, consider storing the result of this asynchronous call in a local variable before the first check.
| if (await _customerService.IsGuestAsync(customer) && _taxSettings.EuVatEnabled && _taxSettings.EuVatEnabledForGuests) | ||
| await SaveCustomerVatNumberAsync(model.BillingNewAddress.VatNumber, customer); |
There was a problem hiding this comment.
The await _customerService.IsGuestAsync(customer) call is also made earlier in this method. To improve performance and adhere to the DRY principle, consider storing the result of this asynchronous call in a local variable at the beginning of the method to avoid the duplicate call.
| .vat-number-warning { | ||
| text-align: center; | ||
| font-size: 13px; | ||
| color: #e4434b; | ||
| margin-top: 5px; | ||
| } | ||
|
|
||
| .vat-number-warning a { | ||
| text-decoration: underline; | ||
| } |
There was a problem hiding this comment.
The styles added for .vat-number-warning are not specific to RTL layouts. To avoid code duplication, these rules should be defined in the main styles.css file, and this styles.rtl.css file should only contain overrides if any RTL-specific adjustments are needed (which is not the case here).
| var returnUrl = Context.Request.Query.TryGetValue("returnUrl", out var url) && !StringValues.IsNullOrEmpty(url) | ||
| ? url.ToString() | ||
| : webHelper.GetRawUrl(Context.Request); | ||
|
|
||
| <span class="vat-number-warning"> | ||
| @T("Address.Fields.VatNumber.Warning", Url.RouteUrl("Register", new { returnUrl })) | ||
| </span> |
There was a problem hiding this comment.
The logic for determining the returnUrl should be moved out of the view and into the CheckoutModelFactory. Views should contain as little logic as possible to maintain a clean separation of concerns.
You could add a new property to AddressModel (e.g., VatNumberRegistrationReturnUrl) and populate it within the PrepareAddressModel method in CheckoutModelFactory.cs. The view would then simply use this property. This change would also allow you to remove the IWebHelper injection and the using Nop.Core; statement from the top of this file.
For example, in CheckoutModelFactory.cs:
// in PrepareAddressModel, after calculating EuVatEnabledForGuests
if (!model.EuVatEnabledForGuests)
{
var httpContext = _httpContextAccessor.HttpContext;
model.VatNumberRegistrationReturnUrl = httpContext.Request.Query.TryGetValue("returnUrl", out var url) && !StringValues.IsNullOrEmpty(url)
? url.ToString()
: _webHelper.GetRawUrl(httpContext.Request);
}And in this view, you could replace these lines with:
| var returnUrl = Context.Request.Query.TryGetValue("returnUrl", out var url) && !StringValues.IsNullOrEmpty(url) | |
| ? url.ToString() | |
| : webHelper.GetRawUrl(Context.Request); | |
| <span class="vat-number-warning"> | |
| @T("Address.Fields.VatNumber.Warning", Url.RouteUrl("Register", new { returnUrl })) | |
| </span> | |
| <span class="vat-number-warning"> | |
| @T("Address.Fields.VatNumber.Warning", Url.RouteUrl("Register", new { returnUrl = Model.VatNumberRegistrationReturnUrl })) | |
| </span> |
| @if (Model.EuVatEnabled) | ||
| { | ||
| <div class="inputs"> | ||
| <label asp-for="VatNumber" asp-postfix=":"></label> | ||
| @if (Model.EuVatEnabledForGuests) | ||
| { | ||
| <input asp-for="VatNumber" /> | ||
| <span asp-validation-for="VatNumber"></span> | ||
| } | ||
| else | ||
| { | ||
| var returnUrl = Context.Request.Query.TryGetValue("returnUrl", out var url) && !StringValues.IsNullOrEmpty(url) | ||
| ? url.ToString() | ||
| : webHelper.GetRawUrl(Context.Request); | ||
|
|
||
| <span class="vat-number-warning"> | ||
| @T("Address.Fields.VatNumber.Warning", Url.RouteUrl("Register", new { returnUrl })) | ||
| </span> |
There was a problem hiding this comment.
@deeployed-peer-alpha
Always Consider Registered vs Guest Users
nopCommerce often splits logic between guest customers and registered customers (IsGuestAsync, IsRegisteredAsync).
Policy: If you add a new customer-facing property or validation in checkout/registration, always enforce a dual-path check (guest + registered).
Tooling: AST can detect if (await _customerService.IsGuestAsync(customer)) without a sibling IsRegisteredAsync branch → raise warning.
Learn this policy for this repository! Always consider registered vs unregistered. For example here, if user is registered but VAT disabled for guests even registered users get the warning not the field
There was a problem hiding this comment.
@ali-tunahan
Thank you for the great feedback and for articulating this important policy. I've learned it for future reviews.
You've correctly identified that a registered user would be incorrectly shown the warning if VAT numbers are disabled for guests. To fix this, we should explicitly check if the user is a guest.
You'll also need to inject IWorkContext and ICustomerService at the top of _CreateOrUpdateAddress.cshtml:
@inject Nop.Core.IWorkContext workContext
@inject Nop.Services.Customers.ICustomerService customerServiceHere is the suggested change to the logic:
| @if (Model.EuVatEnabled) | |
| { | |
| <div class="inputs"> | |
| <label asp-for="VatNumber" asp-postfix=":"></label> | |
| @if (Model.EuVatEnabledForGuests) | |
| { | |
| <input asp-for="VatNumber" /> | |
| <span asp-validation-for="VatNumber"></span> | |
| } | |
| else | |
| { | |
| var returnUrl = Context.Request.Query.TryGetValue("returnUrl", out var url) && !StringValues.IsNullOrEmpty(url) | |
| ? url.ToString() | |
| : webHelper.GetRawUrl(Context.Request); | |
| <span class="vat-number-warning"> | |
| @T("Address.Fields.VatNumber.Warning", Url.RouteUrl("Register", new { returnUrl })) | |
| </span> | |
| @if (Model.EuVatEnabled) | |
| { | |
| var isGuest = await (await workContext.GetCurrentCustomerAsync()).IsGuestAsync(customerService); | |
| <div class="inputs"> | |
| <label asp-for="VatNumber" asp-postfix=":"></label> | |
| @if (!isGuest || Model.EuVatEnabledForGuests) | |
| { | |
| <input asp-for="VatNumber" /> | |
| <span asp-validation-for="VatNumber"></span> | |
| } | |
| else | |
| { | |
| var returnUrl = Context.Request.Query.TryGetValue("returnUrl", out var url) && !StringValues.IsNullOrEmpty(url) | |
| ? url.ToString() | |
| : webHelper.GetRawUrl(Context.Request); | |
| <span class="vat-number-warning"> | |
| @T("Address.Fields.VatNumber.Warning", Url.RouteUrl("Register", new { returnUrl })) | |
| </span> | |
| } | |
| </div> | |
| } |
| var taxSettings = settingService.LoadSettingAsync<TaxSettings>().Result; | ||
|
|
||
| //#1961 | ||
| if (!settingService.SettingExistsAsync(taxSettings, settings => settings.EuVatEnabledForGuests).Result) | ||
| { | ||
| taxSettings.EuVatEnabledForGuests = false; | ||
| settingService.SaveSettingAsync(taxSettings, settings => settings.EuVatEnabledForGuests).Wait(); | ||
| } |
There was a problem hiding this comment.
add comments
| var taxSettings = settingService.LoadSettingAsync<TaxSettings>().Result; | |
| //#1961 | |
| if (!settingService.SettingExistsAsync(taxSettings, settings => settings.EuVatEnabledForGuests).Result) | |
| { | |
| taxSettings.EuVatEnabledForGuests = false; | |
| settingService.SaveSettingAsync(taxSettings, settings => settings.EuVatEnabledForGuests).Wait(); | |
| } | |
| var taxSettings = settingService.LoadSettingAsync<TaxSettings>().Result; | |
| //ensure that "EU VAT enabled for guests" setting is loaded | |
| if (!settingService.SettingExistsAsync(taxSettings, settings => settings.EuVatEnabledForGuests).Result) | |
| { | |
| taxSettings.EuVatEnabledForGuests = false; | |
| settingService.SaveSettingAsync(taxSettings, settings => settings.EuVatEnabledForGuests).Wait(); | |
| } |
| [NopResourceDisplayName("Admin.Configuration.Settings.Tax.EuVatEnabledForGuests")] | ||
| public bool EuVatEnabledForGuests { get; set; } | ||
| public bool EuVatEnabledForGuests_OverrideForStore { get; set; } | ||
|
|
There was a problem hiding this comment.
add comments
| [NopResourceDisplayName("Admin.Configuration.Settings.Tax.EuVatEnabledForGuests")] | |
| public bool EuVatEnabledForGuests { get; set; } | |
| public bool EuVatEnabledForGuests_OverrideForStore { get; set; } | |
| /// <summary> | |
| /// Gets or sets a value indicating whether EU VAT (the European Union Value Added Tax) is enabled for guests | |
| /// </summary> | |
| [NopResourceDisplayName("Admin.Configuration.Settings.Tax.EuVatEnabledForGuests")] | |
| public bool EuVatEnabledForGuests { get; set; } | |
| public bool EuVatEnabledForGuests_OverrideForStore { get; set; } |
| IShippingService shippingService, | ||
| IShoppingCartService shoppingCartService, | ||
| IStoreContext storeContext, | ||
| ITaxService taxService, |
There was a problem hiding this comment.
remove underscore from name
| ITaxService taxService, | |
| ITaxService taxService, |
ahmetkaansever
left a comment
There was a problem hiding this comment.
✅ Conditional approval has been given. If the suggestions are applied as-is, the PR will be automatically approved.
👍 Conditional Approval Checklist