Skip to content

Hide widget in selected language. #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/Block/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
}
23 changes: 23 additions & 0 deletions src/Block/Product/View/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
*/
Expand Down
17 changes: 17 additions & 0 deletions src/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
<comment>Use widget legacy instead new widget</comment>
</field>

<field id="hide_in_languages" translate="label" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Hide Widget in Languages</label>
<source_model>Magento\Config\Model\Config\Source\Locale</source_model>
<comment>Select the languages in which the widget should be hidden.</comment>
<can_be_empty>1</can_be_empty>
</field>

<group id="aplazame_product_widget" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Product Widget</label>

Expand Down Expand Up @@ -194,6 +201,16 @@
<comment>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</comment>
</field>
</group>

<group id="aplazame_dev" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Developer Settings (WARNING: DO NOT TOUCH IF NOT NECESSARY)</label>

<field id="checkout_v4" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Checkout v4</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Use v4 checkout API</comment>
</field>
</group>
</group>
</section>
</system>
Expand Down
4 changes: 4 additions & 0 deletions src/view/frontend/templates/product/view/widget.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand Down