Skip to content

[Issue] Fix "area code is not set" in all commands that depend on Payment/Helper/Data #33908

Closed
@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #33726: Fix "area code is not set" in all commands that depend on Payment/Helper/Data


Description (*)

The Helper Magento\Payment\Helper\Data creates a new layout in the constructor. This is unneccessary and creates issues when the helper is used without specifying the area code previously (eg in commands).

Edit: Also there is no real workaround to fix this. You would need to set the area in the constructor, which in turn is called every time the command list is generated, triggering "area code is already set".

Fixed Issues (if relevant)

  1. Fixes magento/magento2#<issue_number>

Manual testing scenarios (*)

  1. Create a custom Command, inject Magento\Sales\Model\Service\InvoiceService or the mentioned helper directly, or some class that depends on it
  2. Dont specify an area, because its not always needed, or you dont actually intend to use the layout
  3. Scratch your head why it fails with error "area code is not set"

Questions or comments

I dont think a test case is neccessary for this change, because the only place $this->_layout is used, is in one single method as a fallback when no layout has been passed to getInfoBlock().

Maybe using the layoutfactory inside a constructor method should be prohibited at all, or at least trigger/log a warning message. It is troublesome to detect where the root issue comes from.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Metadata

Metadata

Assignees

Labels

Area: FrameworkComponent: PaymentFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P1Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing.Progress: doneReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S1Affects critical data or functionality and forces users to employ a workaround.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions