2017-05-31 15:24:46 +03:00
|
|
|
<?php
|
2018-03-12 16:34:48 +03:00
|
|
|
|
2017-05-31 15:24:46 +03:00
|
|
|
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)
|
|
|
|
{
|
2018-03-12 16:34:48 +03:00
|
|
|
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;
|
2017-05-31 15:24:46 +03:00
|
|
|
}
|
|
|
|
}
|