Skip to content

[Issue] Use static const in Magento\Customer\Model\Address\Config #39135

Open
@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #39123: Use static const in Magento\Customer\Model\Address\Config


Description (*)

This PR adds the possibility to create a new configuration from a custom path and create a class that extends from Magento\Customer\Model\Address\Config without having to duplicate the function Magento\Customer\Model\Address\Config::getFormats()

use Magento\Customer\Model\Address\Config;

class ClickAndCollectConfig extends Config
{
    public const XML_PATH_ADDRESS_TEMPLATE = 'click_and_collect/address_templates/';
}

Capture d’écran du 2024-08-29 10-16-48

Workaround

Today, the only solution to come to do is to duplicate the getFormats function ...

use Magento\Customer\Model\Address\Config;

class ClickAndCollectConfig extends Config
{
    public const XML_PATH_ADDRESS_TEMPLATE = 'click_and_collect/address_templates/';

    /**
     * @inheritDoc
     */
    public function getFormats(): ?array
    {
        $store = $this->getStore();
        $storeId = $store->getId();

        if (!isset($this->_types[$storeId])) {
            $this->_types[$storeId] = [];
            foreach ($this->get() as $typeCode => $typeConfig) {
                $path = sprintf('%s%s', self::XML_PATH_ADDRESS_TEMPLATE, $typeCode);
                $type = new DataObject();
                if (isset($typeConfig['escapeHtml'])) {
                    $escapeHtml = $typeConfig['escapeHtml'] == 'true' || $typeConfig['escapeHtml'] == '1';
                } else {
                    $escapeHtml = false;
                }

                $format = $this->_scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
                $type->setData('code', $typeCode)
                    ->setData('title', (string)$typeConfig['title'])
                    ->setData('default_format', $format)
                    ->setData('escape_html', $escapeHtml);

                $renderer = isset($typeConfig['renderer']) ? (string)$typeConfig['renderer'] : null;
                if (!$renderer) {
                    $renderer = self::DEFAULT_ADDRESS_RENDERER;
                }

                // @phpstan-ignore-next-line
                $type->setRenderer($this->_addressHelper->getRenderer($renderer)->setType($type));
                $this->_types[$storeId][] = $type;
            }
        }

        return $this->_types[$storeId];
    }
}

Related Pull Requests

None

Fixed Issues (if relevant)

None

Manual testing scenarios (*)

  • Create new class extend Magento\Customer\Model\Address\Config
  • Setup XML_PATH_ADDRESS_TEMPLATE with custom value

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)

Activity

added
Priority: P2A defect with this priority could have functionality issues which are not to expectations.
on Sep 3, 2024
added
Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it
Reported on 2.4.xIndicates original Magento version for the Issue report.
on Sep 3, 2024
m2-assistant

m2-assistant commented on Sep 4, 2024

@m2-assistant
Author

Hi @engcom-November. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
    5. Add label Issue: Confirmed once verification is complete.
    6. Make sure that automatic system confirms that report has been added to the backlog.
engcom-November

engcom-November commented on Sep 4, 2024

@engcom-November
Contributor

Hello @dimitriBouteille,

Thank you for the report and collaboration!

Going through the issue this can be considered as a bug, hence confirming this.

github-jira-sync-bot

github-jira-sync-bot commented on Sep 4, 2024

@github-jira-sync-bot

✅ Jira issue https://jira.corp.adobe.com/browse/AC-12906 is successfully created for this GitHub issue.

m2-assistant

m2-assistant commented on Sep 4, 2024

@m2-assistant
Author

✅ Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: BackendIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: PR in progressReported 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 branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @engcom-Bravo@engcom-November@github-jira-sync-bot

      Issue actions

        [Issue] Use static const in Magento\Customer\Model\Address\Config · Issue #39135 · magento/magento2