From 957d45e651e97a5e0dd9f796e858251298764ff8 Mon Sep 17 00:00:00 2001 From: Ross McHugh Date: Fri, 8 Jul 2022 15:33:07 +0200 Subject: [PATCH] Improvements for setting locale The locale is currently set by the value from the HTML tag's `lang` attribute. https://github.com/Itonomy/module-flowbox/blob/075ee836544f485e28e8743d3282c976202f4958/Block/Widget/Flow.php#L53 This includes the language, e.g. `en`, but not the region which makes it invalid for Flowbox. https://help.getflowbox.com/en/articles/4485750-changing-the-language-region-of-your-flow#our-supported-locales. The changes here fixes this to get the locale from the widget options, or if a locale is not set in the widget options, it will be gotten from the Magento store locale. https://docs.magento.com/user-guide/configuration/general/general.html#locale-options The reason for having an option in the widget, is that some Magento stores do not have their locale configured correctly. --- Block/Widget/Flow.php | 7 ++++++- etc/widget.xml | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Block/Widget/Flow.php b/Block/Widget/Flow.php index 7bbdbf9..bd9a1b5 100644 --- a/Block/Widget/Flow.php +++ b/Block/Widget/Flow.php @@ -15,6 +15,8 @@ class Flow extends \Itonomy\Flowbox\Block\Base implements \Magento\Widget\Block\ private \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder; + private \Magento\Framework\Locale\Resolver $store; + /** * Flow constructor. * @param \Magento\Framework\View\Element\Template\Context $context @@ -22,6 +24,7 @@ class Flow extends \Itonomy\Flowbox\Block\Base implements \Magento\Widget\Block\ * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder * @param \Magento\Cookie\Helper\Cookie $cookie * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor + * @param \Magento\Framework\Encryption\EncryptorInterface $store * @param array $data */ public function __construct( @@ -30,11 +33,13 @@ public function __construct( \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Cookie\Helper\Cookie $cookie, \Magento\Framework\Encryption\EncryptorInterface $encryptor, + \Magento\Framework\Locale\Resolver $store, array $data = [] ) { parent::__construct($context, $cookie, $encryptor, $data); $this->productRepository = $productRepository; $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->_store = $store; } /** @@ -50,7 +55,7 @@ protected function prepareConfig(): void 'flow' => $flow, 'key' => $this->escapeHtml((string) $this->getData('key')), 'lazyload' => (bool) $this->getData('lazyload'), - 'locale' => (string) $this->pageConfig->getElementAttribute('html', 'lang') + 'locale' => (string) $this->getData('locale') ?: $this->_store->getLocale() ]; if ($flow === static::FLOW_TYPE_DYNAMIC_PRODUCT) { diff --git a/etc/widget.xml b/etc/widget.xml index 63754fb..bf2ba7e 100644 --- a/etc/widget.xml +++ b/etc/widget.xml @@ -32,6 +32,14 @@ Visit flowbox]]> to access your flows. + + + Magento store locale will be used.
+ Visit here to see a list of supported locales. + ]]>
+
+