1 | <?php |
||
2 | |||
3 | /** |
||
4 | * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
||
5 | * it under the terms of the GNU Lesser General Public License as published by |
||
6 | * the Free Software Foundation, either version 3 of the License, or |
||
7 | * (at your option) any later version. |
||
8 | * |
||
9 | * PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | * GNU Lesser General Public License for more details. |
||
13 | * |
||
14 | * You should have received a copy of the GNU Lesser General Public License |
||
15 | * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
||
16 | * |
||
17 | * PHP version 5 |
||
18 | * |
||
19 | * @category Payone |
||
20 | * @package Payone_Magento2_Plugin |
||
21 | * @author FATCHIP GmbH <[email protected]> |
||
22 | * @copyright 2003 - 2016 Payone GmbH |
||
23 | * @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
||
24 | * @link http://www.payone.de |
||
25 | */ |
||
26 | |||
27 | namespace Payone\Core\Helper; |
||
28 | |||
29 | use Magento\Store\Model\ScopeInterface; |
||
0 ignored issues
–
show
|
|||
30 | |||
31 | /** |
||
32 | * Helper base class |
||
33 | */ |
||
34 | class Base extends \Magento\Framework\App\Helper\AbstractHelper |
||
0 ignored issues
–
show
The type
Magento\Framework\App\Helper\AbstractHelper was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
35 | { |
||
36 | /** |
||
37 | * Store manager object |
||
38 | * |
||
39 | * @var \Magento\Store\Model\StoreManagerInterface |
||
0 ignored issues
–
show
The type
Magento\Store\Model\StoreManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
40 | */ |
||
41 | protected $storeManager; |
||
42 | |||
43 | /** |
||
44 | * PAYONE shop helper |
||
45 | * |
||
46 | * @var \Payone\Core\Helper\Shop |
||
47 | */ |
||
48 | protected $shopHelper; |
||
49 | |||
50 | /** |
||
51 | * @var \Magento\Framework\App\State |
||
0 ignored issues
–
show
The type
Magento\Framework\App\State was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
52 | */ |
||
53 | protected $state; |
||
54 | |||
55 | /** |
||
56 | * Constructor |
||
57 | * |
||
58 | * @param \Magento\Framework\App\Helper\Context $context |
||
59 | * @param \Magento\Store\Model\StoreManagerInterface $storeManager |
||
60 | * @param \Payone\Core\Helper\Shop $shopHelper |
||
61 | * @param \Magento\Framework\App\State $state |
||
62 | */ |
||
63 | public function __construct( |
||
64 | \Magento\Framework\App\Helper\Context $context, |
||
0 ignored issues
–
show
The type
Magento\Framework\App\Helper\Context was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
65 | \Magento\Store\Model\StoreManagerInterface $storeManager, |
||
66 | \Payone\Core\Helper\Shop $shopHelper, |
||
67 | \Magento\Framework\App\State $state |
||
68 | ) { |
||
69 | parent::__construct($context); |
||
70 | $this->storeManager = $storeManager; |
||
71 | $this->shopHelper = $shopHelper; |
||
72 | $this->state = $state; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Helper method to get parameter from the config |
||
77 | * divided by the config path elements |
||
78 | * |
||
79 | * @param string $sKey |
||
80 | * @param string $sGroup |
||
81 | * @param string $sSection |
||
82 | * @param string $sStoreCode |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getConfigParam($sKey, $sGroup = 'global', $sSection = 'payone_general', $sStoreCode = null) |
||
86 | { |
||
87 | $sPath = $sSection."/".$sGroup."/".$sKey; |
||
88 | return $this->getConfigParamByPath($sPath, $sStoreCode); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Helper method to get parameter from the config by path |
||
93 | * |
||
94 | * @param string $sPath |
||
95 | * @param string $sStoreCode |
||
96 | * @return string |
||
97 | */ |
||
98 | public function getConfigParamByPath($sPath, $sStoreCode = null) |
||
99 | { |
||
100 | $sScopeCode = ScopeInterface::SCOPE_STORES; |
||
101 | if (!$sStoreCode) { |
||
102 | list($sStoreCode, $sScopeCode) = $this->fetchCurrentStoreCode(); |
||
103 | } |
||
104 | return $this->scopeConfig->getValue($sPath, $sScopeCode, $sStoreCode); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Trying to fetch the current storeCode |
||
109 | * Fetching the correct storeCode in the Magento2 backend is very inaccurate |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | protected function fetchCurrentStoreCode() |
||
114 | { |
||
115 | $sScopeCode = \Magento\Store\Model\ScopeInterface::SCOPE_STORES; |
||
116 | $sStoreCode = $this->storeManager->getStore()->getCode(); |
||
117 | if ($this->state->getAreaCode() == \Magento\Framework\App\Area::AREA_ADMINHTML) { |
||
0 ignored issues
–
show
The type
Magento\Framework\App\Area was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
118 | $sStoreCode = 0; // 0 = default config, which should be used when neither website nor store parameter are present, storeManager returns default STORE though, which would be wrong |
||
119 | if (!empty($this->getRequestParameter('website'))) { |
||
120 | $sStoreCode = $this->getRequestParameter('website'); |
||
121 | $sScopeCode = \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES; |
||
122 | } |
||
123 | if (!empty($this->getRequestParameter('store'))) { |
||
124 | $sStoreCode = $this->getRequestParameter('store'); |
||
125 | } |
||
126 | } |
||
127 | |||
128 | return [$sStoreCode, $sScopeCode]; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Get a certain config param for all available stores |
||
133 | * |
||
134 | * @param string $sKey |
||
135 | * @param string $sGroup |
||
136 | * @param string $sSection |
||
137 | * @return array |
||
138 | */ |
||
139 | public function getConfigParamAllStores($sKey, $sGroup = 'global', $sSection = 'payone_general') |
||
140 | { |
||
141 | $aValues = []; |
||
142 | $aShopIds = $this->storeManager->getStores(false, true); |
||
143 | foreach ($aShopIds as $sStoreCode => $oStore) { |
||
144 | $sValue = $this->getConfigParam($sKey, $sGroup, $sSection, $sStoreCode); |
||
145 | if (array_search($sValue, $aValues) === false) { |
||
146 | $aValues[] = $sValue; |
||
147 | } |
||
148 | } |
||
149 | return $aValues; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Get parameter from the request |
||
154 | * |
||
155 | * @param string $sParameter |
||
156 | * @return mixed |
||
157 | */ |
||
158 | public function getRequestParameter($sParameter) |
||
159 | { |
||
160 | return $this->_getRequest()->getParam($sParameter); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Checks if the given value is json encoded |
||
165 | * |
||
166 | * @param $sValue |
||
167 | * @return bool |
||
168 | */ |
||
169 | protected function isJson($sValue) |
||
170 | { |
||
171 | if (is_string($sValue) && is_array(json_decode($sValue, true)) && (json_last_error() == JSON_ERROR_NONE)) { |
||
172 | return true; |
||
173 | } |
||
174 | return false; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * Handle the serialization of strings depending on the Magento version |
||
179 | * |
||
180 | * @param mixed $mValue |
||
181 | * @return string |
||
182 | */ |
||
183 | public function serialize($mValue) |
||
184 | { |
||
185 | if (version_compare($this->shopHelper->getMagentoVersion(), '2.2.0', '>=')) { // Magento 2.2.0 and above |
||
186 | return json_encode($mValue); |
||
187 | } |
||
188 | return serialize($mValue); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param string $sValue |
||
193 | * @return mixed |
||
194 | */ |
||
195 | public function unserialize($sValue) |
||
196 | { |
||
197 | if ($this->isJson($sValue)) { |
||
198 | return json_decode($sValue, true); |
||
199 | } |
||
200 | return unserialize($sValue ?? ''); |
||
201 | } |
||
202 | } |
||
203 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths