67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
|
<?php
|
||
|
namespace Retailcrm\Retailcrm\Helper;
|
||
|
|
||
|
use Magento\Framework\App\Helper\AbstractHelper;
|
||
|
use Magento\Store\Model\StoreManagerInterface;
|
||
|
use Magento\Framework\ObjectManagerInterface;
|
||
|
use Magento\Framework\App\Helper\Context;
|
||
|
use Magento\Store\Model\ScopeInterface;
|
||
|
|
||
|
class Data extends AbstractHelper
|
||
|
{
|
||
|
protected $storeManager;
|
||
|
protected $objectManager;
|
||
|
|
||
|
const XML_PATH_RETAILCRM = 'retailcrm/';
|
||
|
|
||
|
public function __construct(Context $context,
|
||
|
ObjectManagerInterface $objectManager,
|
||
|
StoreManagerInterface $storeManager
|
||
|
) {
|
||
|
$this->objectManager = $objectManager;
|
||
|
$this->storeManager = $storeManager;
|
||
|
parent::__construct($context);
|
||
|
}
|
||
|
|
||
|
public function getConfigValue($field, $storeId = null)
|
||
|
{
|
||
|
return $this->scopeConfig->getValue(
|
||
|
$field, ScopeInterface::SCOPE_STORE, $storeId
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public function getGeneralConfig($code, $storeId = null)
|
||
|
{
|
||
|
return $this->getConfigValue(self::XML_PATH_RETAILCRM . $code, $storeId);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Recursive array filter
|
||
|
*
|
||
|
* @param array $haystack input array
|
||
|
*
|
||
|
* @SuppressWarnings(PHPMD.StaticAccess)
|
||
|
* @SuppressWarnings(PHPMD.ElseExpression)
|
||
|
*
|
||
|
* @return array
|
||
|
*/
|
||
|
public function filterRecursive($haystack)
|
||
|
{
|
||
|
foreach ($haystack as $key => $value) {
|
||
|
if (is_array($value)) {
|
||
|
$haystack[$key] = self::filterRecursive($haystack[$key]);
|
||
|
}
|
||
|
|
||
|
if (is_null($haystack[$key])
|
||
|
|| $haystack[$key] === ''
|
||
|
|| count($haystack[$key]) == 0
|
||
|
) {
|
||
|
unset($haystack[$key]);
|
||
|
} elseif (!is_array($value)) {
|
||
|
$haystack[$key] = trim($value);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $haystack;
|
||
|
}
|
||
|
}
|