magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.5k stars 9.3k forks source link

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

Open m2-assistant[bot] opened 1 month ago

m2-assistant[bot] commented 1 month ago

This issue is automatically created based on existing pull request: magento/magento2#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 (*)

Contribution checklist (*)

m2-assistant[bot] commented 1 month ago

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: :point_down:

engcom-November commented 1 month ago

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 commented 1 month ago

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

m2-assistant[bot] commented 1 month ago

:white_check_mark: 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.