diff --git a/src/Block/Js.php b/src/Block/Js.php index 77edb71..39f2476 100644 --- a/src/Block/Js.php +++ b/src/Block/Js.php @@ -3,8 +3,10 @@ namespace Aplazame\Payment\Block; use Aplazame\Payment\Gateway\Config\Config; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; +use Magento\Store\Model\ScopeInterface; class Js extends Template { @@ -13,14 +15,20 @@ class Js extends Template */ private $config; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + public function __construct( Context $context, Config $config, + ScopeConfigInterface $scopeConfig, array $data = [] ) { parent::__construct($context, $data); - $this->config = $config; + $this->scopeConfig = $scopeConfig; } /** @@ -33,10 +41,22 @@ public function getConfig() protected function _toHtml() { - if (!$this->config->isActive()) { + if (!$this->config->isActive() || $this->isHiddenInCurrentLanguage()) { return ''; } return parent::_toHtml(); } + + public function isHiddenInCurrentLanguage() + { + $currentLocale = $this->scopeConfig->getValue('general/locale/code', ScopeInterface::SCOPE_STORE); + $hiddenLanguages = $this->scopeConfig->getValue('payment/aplazame_payment/aplazame_widget/hide_in_languages', ScopeInterface::SCOPE_STORE); + + if (in_array($currentLocale, explode(',', $hiddenLanguages))) { + return true; + } + + return false; + } } diff --git a/src/Block/Product/View/Widget.php b/src/Block/Product/View/Widget.php index f88aca1..b71433d 100644 --- a/src/Block/Product/View/Widget.php +++ b/src/Block/Product/View/Widget.php @@ -6,6 +6,8 @@ use Magento\Catalog\Block\Product\AbstractProduct; use Magento\Directory\Model\Currency; use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Store\Model\ScopeInterface; class Widget extends AbstractProduct { @@ -19,18 +21,39 @@ class Widget extends AbstractProduct */ private $config; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + public function __construct( PriceCurrencyInterface $priceCurrency, \Magento\Catalog\Block\Product\Context $context, Config $config, + ScopeConfigInterface $scopeConfig, array $data = [] ) { parent::__construct($context, $data); $this->priceCurrency = $priceCurrency; $this->config = $config; + $this->scopeConfig = $scopeConfig; } + public function isHiddenInCurrentLanguage() +{ + // Obtiene el código de localización actual + $currentLocale = $this->scopeConfig->getValue('general/locale/code', ScopeInterface::SCOPE_STORE); + // Obtiene la configuración de los idiomas seleccionados para ocultar el widget + $hiddenLanguages = $this->scopeConfig->getValue('payment/aplazame_payment/aplazame_widget/hide_in_languages', ScopeInterface::SCOPE_STORE) ?? ''; + + if (in_array($currentLocale, explode(',', $hiddenLanguages))) { + return true; + } + + return false; +} + /** * @return float */ diff --git a/src/etc/adminhtml/system.xml b/src/etc/adminhtml/system.xml index bdcadfe..898f91d 100644 --- a/src/etc/adminhtml/system.xml +++ b/src/etc/adminhtml/system.xml @@ -60,6 +60,13 @@ Use widget legacy instead new widget + + + Magento\Config\Model\Config\Source\Locale + Select the languages in which the widget should be hidden. + 1 + + @@ -194,6 +201,16 @@ Change Aplazame's internal ID from 'quote' to 'order' when an order is confirmed, the 'order_' prefix will be used to avoid DB problems with duplicate numeric IDs + + + + + + + Magento\Config\Model\Config\Source\Yesno + Use v4 checkout API + + diff --git a/src/view/frontend/templates/product/view/widget.phtml b/src/view/frontend/templates/product/view/widget.phtml index 4721452..60c9995 100644 --- a/src/view/frontend/templates/product/view/widget.phtml +++ b/src/view/frontend/templates/product/view/widget.phtml @@ -4,6 +4,10 @@ use Aplazame\Payment\Block\Product\View\Widget; use Aplazame\Serializer\Decimal; +if ($block->isHiddenInCurrentLanguage()) { + return ''; // No renderizar el widget si el idioma actual está en la lista de idiomas ocultos. +} + if (!$block->isAplazameActive()) { return ''; }