Skip to content

. - #3

Closed
atakanserifoglu wants to merge 2 commits into
developfrom
test-pr-6304
Closed

.#3
atakanserifoglu wants to merge 2 commits into
developfrom
test-pr-6304

Conversation

@atakanserifoglu

@atakanserifoglu atakanserifoglu commented Oct 8, 2025 •

Copy link
Copy Markdown
Collaborator

👍 Conditional Approval Checklist

@deeployed-peer-dev

Copy link
Copy Markdown

❌ Sorry @atakanserifoglu, your organization has never subscribed to Deeployed Peer. Please register through the dashboard first.

@atakanserifoglu

Copy link
Copy Markdown
Collaborator Author

@deeployedpeer review

@deeployed-peer-dev

Copy link
Copy Markdown

❌ Sorry @atakanserifoglu, your organization has never subscribed to Deeployed Peer. Please register through the dashboard first.

deeployed-peer-dev[bot]

This comment was marked as spam.

@Deeployed-Peer Deeployed-Peer deleted a comment from deeployed-peer-dev Bot Oct 9, 2025
@Deeployed-Peer Deeployed-Peer deleted a comment from deeployed-peer-dev Bot Oct 9, 2025
@ali-tunahan

Copy link
Copy Markdown

@deeployed-peer-alpha review

@deeployed-peer-alpha

deeployed-peer-alpha Bot commented Oct 9, 2025 •

Copy link
Copy Markdown
Walkthrough

This update introduces a new EuVatEnabledForGuests setting, allowing store owners to control whether guest customers can enter a VAT number during checkout. The change includes the necessary backend logic, admin configuration UI, and updates to the public checkout flow and styling.

Changes
File(s) Summary
src/Libraries/Nop.Core/.../TaxSettings.cs
src/Libraries/Nop.Services/.../InstallationService.cs
src/Presentation/Nop.Web.Framework/Migrations/...
src/Presentation/Nop.Web/Areas/Admin/...
src/Presentation/Nop.Web/Controllers/CheckoutController.cs
src/Presentation/Nop.Web/Factories/CheckoutModelFactory.cs
src/Presentation/Nop.Web/Models/Common/AddressModel.cs
src/Presentation/Nop.Web/Views/Shared/_CreateOrUpdateAddress.cshtml
Introduces the EuVatEnabledForGuests setting to control VAT number input for guests. This includes database migration, admin UI configuration, localization, and updates to the public checkout logic to conditionally show the VAT field and save the data.
src/Presentation/Nop.Web/Themes/DefaultClean/Content/css/styles.css
src/Presentation/Nop.Web/Themes/DefaultClean/Content/css/styles.rtl.css
Adds CSS styles for the .vat-number-warning class, used to display a message to guest users when the VAT number input is disabled.
Sequence Diagram
sequenceDiagram
    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

Loading

Uplevel your code reviews with Deeployed Peer!

@Deeployed-Peer Deeployed-Peer deleted a comment from deeployed-peer-alpha Bot Oct 9, 2025

@deeployed-peer-alpha deeployed-peer-alpha Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commits Files that changed from the base of the PR and between Base and 4bced88 commits: 16
Files 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-alpha in 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: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +110 to +113
/// <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; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
/// <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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _taxSettings field is assigned again on line 131. This assignment is a duplicate and can be removed to avoid redundancy.

Suggested change
_taxSettings = taxSettings;

Comment on lines +584 to +585
if (await _customerService.IsGuestAsync(customer) && _taxSettings.EuVatEnabled && _taxSettings.EuVatEnabledForGuests)
await SaveCustomerVatNumberAsync(model.BillingNewAddress.VatNumber, customer);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1437 to +1438
if (await _customerService.IsGuestAsync(customer) && _taxSettings.EuVatEnabled && _taxSettings.EuVatEnabledForGuests)
await SaveCustomerVatNumberAsync(model.BillingNewAddress.VatNumber, customer);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +4801 to +4810
.vat-number-warning {
text-align: center;
font-size: 13px;
color: #e4434b;
margin-top: 5px;
}

.vat-number-warning a {
text-decoration: underline;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines +157 to +163
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>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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>

@Deeployed-Peer Deeployed-Peer deleted a comment from deeployed-peer-dev Bot Oct 9, 2025
Comment on lines +146 to +163
@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>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 customerService

Here is the suggested change to the logic:

Suggested change
@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>
}

Comment on lines +294 to +301
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();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments

Suggested change
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();
}

Comment on lines +107 to +110
[NopResourceDisplayName("Admin.Configuration.Settings.Tax.EuVatEnabledForGuests")]
public bool EuVatEnabledForGuests { get; set; }
public bool EuVatEnabledForGuests_OverrideForStore { get; set; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments

Suggested change
[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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove underscore from name

Suggested change
ITaxService taxService,
ITaxService taxService,

@ahmetkaansever ahmetkaansever left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Conditional approval has been given. If the suggestions are applied as-is, the PR will be automatically approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants