Skip to content

Commit

Permalink
MAG1-202: built in conflict messages
Browse files Browse the repository at this point in the history
- Changes behavior of warning and prevent savings from "enable" configuration
  • Loading branch information
ebanolopes committed Mar 7, 2018
1 parent c0fc570 commit 066d5ea
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions Model/System/Config/Backend/Enabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,39 @@
namespace Signifyd\Connect\Model\System\Config\Backend;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Message\ManagerInterface;

class Enabled extends \Magento\Framework\App\Config\Value
{
protected $messageManager;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param ScopeConfigInterface $config
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
ManagerInterface $messageManager,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
$this->messageManager = $messageManager;

parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
}

/**
* @return $this
*/
public function beforeSave()
{
if ($this->getValue() == 0) {
Expand All @@ -32,8 +60,12 @@ public function beforeSave()
$isAnotherEnabled = $this->_config->getValue($path == $signifydPath ? $builtinPath : $signifydPath, 'store');

if ($isAnotherEnabled) {
$this->setValue(0);
throw new LocalizedException(__('WARNING: Another instance of Signifyd is currently enabled. Please disable the other running instance to avoid conflicts.'));
$currentConfig = $this->_config->getValue($builtinPath);
if ($currentConfig == 0) {
$this->setValue(0);
}

$this->messageManager->addError(__('WARNING: Another instance of Signifyd is currently enabled. Please disable the other running instance to avoid conflicts.'));
}
return $this;
}
Expand Down

0 comments on commit 066d5ea

Please sign in to comment.