|
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\Quote\Model\Quote; |
|
|
|
|
|
|
30
|
|
|
use Magento\Checkout\Model\Type\Onepage; |
|
|
|
|
|
|
31
|
|
|
use Magento\Quote\Api\Data\AddressInterface; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Helper class for everything that has to do with the checkout |
|
35
|
|
|
*/ |
|
36
|
|
|
class Checkout extends \Payone\Core\Helper\Base |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* Checkout session |
|
40
|
|
|
* |
|
41
|
|
|
* @var \Magento\Customer\Model\Session |
|
|
|
|
|
|
42
|
|
|
*/ |
|
43
|
|
|
protected $customerSession; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var \Magento\Checkout\Helper\Data |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
|
|
protected $checkoutData; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* All parameters used for the address hash |
|
52
|
|
|
* |
|
53
|
|
|
* @var array |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $aHashParams = [ |
|
56
|
|
|
'firstname', |
|
57
|
|
|
'lastname', |
|
58
|
|
|
'company', |
|
59
|
|
|
'street', |
|
60
|
|
|
'zip', |
|
61
|
|
|
'city', |
|
62
|
|
|
'country', |
|
63
|
|
|
'state', |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Constructor |
|
68
|
|
|
* |
|
69
|
|
|
* @param \Magento\Framework\App\Helper\Context $context |
|
70
|
|
|
* @param \Magento\Store\Model\StoreManagerInterface $storeManager |
|
71
|
|
|
* @param \Payone\Core\Helper\Shop $shopHelper |
|
72
|
|
|
* @param \Magento\Framework\App\State $state |
|
73
|
|
|
* @param \Magento\Customer\Model\Session $customerSession |
|
74
|
|
|
* @param \Magento\Checkout\Helper\Data $checkoutData |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __construct( |
|
77
|
|
|
\Magento\Framework\App\Helper\Context $context, |
|
|
|
|
|
|
78
|
|
|
\Magento\Store\Model\StoreManagerInterface $storeManager, |
|
|
|
|
|
|
79
|
|
|
\Payone\Core\Helper\Shop $shopHelper, |
|
80
|
|
|
\Magento\Framework\App\State $state, |
|
|
|
|
|
|
81
|
|
|
\Magento\Customer\Model\Session $customerSession, |
|
82
|
|
|
\Magento\Checkout\Helper\Data $checkoutData |
|
83
|
|
|
) { |
|
84
|
|
|
parent::__construct($context, $storeManager, $shopHelper, $state); |
|
85
|
|
|
$this->customerSession = $customerSession; |
|
86
|
|
|
$this->checkoutData = $checkoutData; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get checkout method |
|
91
|
|
|
* |
|
92
|
|
|
* @param Quote $oQuote |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getCurrentCheckoutMethod(Quote $oQuote) |
|
96
|
|
|
{ |
|
97
|
|
|
if ($this->customerSession->isLoggedIn()) { |
|
98
|
|
|
return Onepage::METHOD_CUSTOMER; |
|
99
|
|
|
} |
|
100
|
|
|
if (!$oQuote->getCheckoutMethod()) { |
|
101
|
|
|
if ($this->checkoutData->isAllowedGuestCheckout($oQuote)) { |
|
102
|
|
|
$oQuote->setCheckoutMethod(Onepage::METHOD_GUEST); |
|
103
|
|
|
} else { |
|
104
|
|
|
$oQuote->setCheckoutMethod(Onepage::METHOD_REGISTER); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
return $oQuote->getCheckoutMethod(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Generate a string that represents the basket, used to compare it at different times during checkout |
|
112
|
|
|
* |
|
113
|
|
|
* @param Quote $oQuote |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getQuoteComparisonString(Quote $oQuote) |
|
117
|
|
|
{ |
|
118
|
|
|
$sComparisonString = ""; |
|
119
|
|
|
foreach ($oQuote->getAllItems() as $oItem) { // add invoice items for all order items |
|
120
|
|
|
$sComparisonString .= $oItem->getProductId().$oItem->getSku().$oItem->getQty()."|"; |
|
121
|
|
|
} |
|
122
|
|
|
return $sComparisonString; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get address array for hash creation |
|
127
|
|
|
* |
|
128
|
|
|
* @param AddressInterface $oAddress |
|
129
|
|
|
* @return array |
|
130
|
|
|
*/ |
|
131
|
|
|
protected function getAddressArray(AddressInterface $oAddress) |
|
132
|
|
|
{ |
|
133
|
|
|
return [ |
|
134
|
|
|
'firstname' => $oAddress->getFirstname(), |
|
135
|
|
|
'lastname' => $oAddress->getLastname(), |
|
136
|
|
|
'company' => $oAddress->getCompany(), |
|
137
|
|
|
'street' => $oAddress->getStreet()[0], |
|
138
|
|
|
'zip' => $oAddress->getPostcode(), |
|
139
|
|
|
'city' => $oAddress->getCity(), |
|
140
|
|
|
'country' => $oAddress->getCountryId(), |
|
141
|
|
|
'state' => $oAddress->getRegionCode(), |
|
142
|
|
|
]; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Generate a unique hash of an address |
|
147
|
|
|
* |
|
148
|
|
|
* @param AddressInterface $oAddress |
|
149
|
|
|
* @param array $aResponse |
|
150
|
|
|
* @return string |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getHashFromAddress(AddressInterface $oAddress, $aResponse = false) |
|
153
|
|
|
{ |
|
154
|
|
|
$aAddressArray = $this->getAddressArray($oAddress); // collect data from the address object |
|
155
|
|
|
|
|
156
|
|
|
$sAddress = ''; |
|
157
|
|
|
foreach ($this->aHashParams as $sParamKey) { |
|
158
|
|
|
$sParamValue = isset($aAddressArray[$sParamKey]) ? $aAddressArray[$sParamKey] : false; |
|
159
|
|
|
if ($sParamValue) { |
|
160
|
|
|
if ($aResponse !== false && array_key_exists($sParamKey, $aResponse) !== false && $aResponse[$sParamKey] != $sParamValue) { |
|
161
|
|
|
//take the corrected value from the address-check |
|
162
|
|
|
$sParamValue = $aResponse[$sParamKey]; |
|
163
|
|
|
} |
|
164
|
|
|
$sAddress .= $sParamValue; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
$sHash = md5($sAddress); // generate hash from address for identification |
|
168
|
|
|
|
|
169
|
|
|
return $sHash; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Generate hash for the addresses used in the quote at the current moment |
|
174
|
|
|
* |
|
175
|
|
|
* @param Quote $oQuote |
|
176
|
|
|
* @return string |
|
177
|
|
|
*/ |
|
178
|
|
|
public function getQuoteAddressHash(Quote $oQuote) |
|
179
|
|
|
{ |
|
180
|
|
|
$sHash = $this->getHashFromAddress($oQuote->getBillingAddress()); |
|
181
|
|
|
if ($oQuote->getIsVirtual() === false && !empty($oQuote->getShippingAddress())) { |
|
182
|
|
|
$sHash .= $this->getHashFromAddress($oQuote->getShippingAddress()); |
|
183
|
|
|
} |
|
184
|
|
|
return $sHash; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
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