Commit 15e432df authored by Vincent Mrose's avatar Vincent Mrose 💬
Browse files

Fixed a bug where the auto capture categories were not saved correctly


Signed-off-by: Vincent Mrose's avatarVincent Mrose <v.mrose@crefopay.de>
parent 49bc2f63
......@@ -4,26 +4,25 @@ namespace Trilix\CrefoPay\Controller\Adminhtml\Autocapture;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface as ConfigWriter;
use Trilix\CrefoPay\Gateway\Config\Config;
class Save extends \Magento\Backend\App\Action
{
/**
* @var ConfigWriter
* @var Config
*/
private $configWriter;
private $config;
/**
* Save constructor.
*
* @param ConfigWriter $configWriter
* @param Context $context
* @param Config $config
* @param Context $context
*/
public function __construct(ConfigWriter $configWriter, Context $context)
public function __construct(Config $config, Context $context)
{
parent::__construct($context);
$this->configWriter = $configWriter;
$this->config = $config;
}
/**
......@@ -50,12 +49,7 @@ class Save extends \Magento\Backend\App\Action
$configScopeId = $scope['website'];
}
$this->configWriter->save(
Config::KEY_AUTO_CAPTURE_CATEGORIES,
implode(',', $categories),
$configScope,
$configScopeId
);
$this->config->setAutoCaptureCategoryIds($categories, $configScope, $configScopeId);
return $result;
}
......
......@@ -4,6 +4,7 @@ namespace Trilix\CrefoPay\Gateway\Config;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface as ConfigWriter;
use Magento\Payment\Model\CcConfig;
use Trilix\CrefoPay\Model\Adminhtml\Source\Environment;
......@@ -19,6 +20,16 @@ class Config extends \Magento\Payment\Gateway\Config\Config
const KEY_RISK_CLASS = 'risk_class';
const KEY_AUTO_CAPTURE_CATEGORIES = 'auto_capture_categories';
/**
* @var string|null
*/
private $methodCode;
/**
* @var string|null
*/
private $pathPattern;
/**
* @var CcConfig
*/
......@@ -38,6 +49,10 @@ class Config extends \Magento\Payment\Gateway\Config\Config
* @var CategoryCollectionFactory
*/
private $categoryCollectionFactory;
/**
* @var ConfigWriter
*/
private $configWriter;
/**
* Config constructor.
......@@ -45,6 +60,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config
* @param ScopeConfigInterface $scopeConfig
* @param CcConfig $ccConfig
* @param CategoryCollectionFactory $categoryCollectionFactory
* @param ConfigWriter $configWriter
* @param null $methodCode
* @param string $pathPattern
*/
......@@ -52,12 +68,16 @@ class Config extends \Magento\Payment\Gateway\Config\Config
ScopeConfigInterface $scopeConfig,
CcConfig $ccConfig,
CategoryCollectionFactory $categoryCollectionFactory,
ConfigWriter $configWriter,
$methodCode = null,
$pathPattern = self::DEFAULT_PATH_PATTERN
) {
parent::__construct($scopeConfig, $methodCode, $pathPattern);
$this->ccConfig = $ccConfig;
$this->categoryCollectionFactory = $categoryCollectionFactory;
$this->configWriter = $configWriter;
$this->methodCode = $methodCode;
$this->pathPattern = $pathPattern;
}
/**
......@@ -166,6 +186,23 @@ class Config extends \Magento\Payment\Gateway\Config\Config
return $this->baseUrl;
}
/**
* Save auto capture category IDs.
*
* @param array $categoryIds
* @param string $scope
* @param int $scopeId
*
* @return void
*/
public function setAutoCaptureCategoryIds(
array $categoryIds,
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
$scopeId = 0
) {
$this->setValue(self::KEY_AUTO_CAPTURE_CATEGORIES, join(',', $categoryIds), $scope, $scopeId);
}
/**
* Return auto capture category IDs as plain array.
*
......@@ -188,4 +225,25 @@ class Config extends \Magento\Payment\Gateway\Config\Config
return $categories;
}
/**
* Save config value.
*
* @param string $field
* @param $value
* @param string $scope
* @param int $scopeId
*
* @return void
*/
protected function setValue(
string $field,
$value,
string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
int $scopeId = 0
) {
$this->configWriter->save(
sprintf($this->pathPattern, $this->methodCode, $field), $value, $scope, $scopeId
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment