1
0
mirror of synced 2025-02-16 20:23:16 +03:00
Akolzin Dmitry 3b6430cf7d Refactoring
2018-04-28 11:59:43 +03:00

72 lines
1.8 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
{
private $storeManager;
private $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 static function filterRecursive($haystack)
{
foreach ($haystack as $key => $value) {
if (is_array($value)) {
$haystack[$key] = self::filterRecursive($haystack[$key]);
}
if ($haystack[$key] === null
|| $haystack[$key] === ''
|| (is_array($haystack[$key]) && empty($haystack[$key]))
) {
unset($haystack[$key]);
} elseif (!is_array($value)) {
$haystack[$key] = trim($value);
}
}
return $haystack;
}
}