Skip to content

Commit 2087543

Browse files
author
Voskoboinikov, Dmytro(dvoskoboinikov)
committed
Merge pull request #564 from magento-mpi/MAGETWO-52116
[MPI] Bugfix
2 parents 7a04197 + e1fe677 commit 2087543

File tree

28 files changed

+609
-113
lines changed

28 files changed

+609
-113
lines changed

app/code/Magento/Braintree/Observer/DataAssignObserver.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\Event\Observer;
99
use Magento\Payment\Observer\AbstractDataAssignObserver;
10+
use Magento\Quote\Api\Data\PaymentInterface;
1011

1112
/**
1213
* Class DataAssignObserver
@@ -31,13 +32,19 @@ class DataAssignObserver extends AbstractDataAssignObserver
3132
public function execute(Observer $observer)
3233
{
3334
$data = $this->readDataArgument($observer);
35+
36+
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
37+
if (!is_array($additionalData)) {
38+
return;
39+
}
40+
3441
$paymentInfo = $this->readPaymentModelArgument($observer);
3542

3643
foreach ($this->additionalInformationList as $additionalInformationKey) {
37-
if ($data->getDataByKey($additionalInformationKey) !== null) {
44+
if (isset($additionalData[$additionalInformationKey])) {
3845
$paymentInfo->setAdditionalInformation(
3946
$additionalInformationKey,
40-
$data->getDataByKey($additionalInformationKey)
47+
$additionalData[$additionalInformationKey]
4148
);
4249
}
4350
}

app/code/Magento/Braintree/Test/Unit/Observer/DataAssignObserverTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Payment\Model\InfoInterface;
1111
use Magento\Payment\Observer\AbstractDataAssignObserver;
1212
use Magento\Braintree\Observer\DataAssignObserver;
13+
use Magento\Quote\Api\Data\PaymentInterface;
1314

1415
/**
1516
* Class DataAssignObserverTest
@@ -30,8 +31,10 @@ public function testExecute()
3031
$paymentInfoModel = $this->getMock(InfoInterface::class);
3132
$dataObject = new DataObject(
3233
[
33-
'payment_method_nonce' => self::PAYMENT_METHOD_NONCE,
34-
'device_data' => self::DEVICE_DATA,
34+
PaymentInterface::KEY_ADDITIONAL_DATA => [
35+
'payment_method_nonce' => self::PAYMENT_METHOD_NONCE,
36+
'device_data' => self::DEVICE_DATA
37+
]
3538
]
3639
);
3740
$observerContainer->expects(static::atLeastOnce())

app/code/Magento/Checkout/Model/Cart.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ public function addOrderItem($orderItem, $qtyFlag = null)
257257
if ($orderItem->getParentItem() === null) {
258258
$storeId = $this->_storeManager->getStore()->getId();
259259
try {
260-
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId);
260+
/**
261+
* We need to reload product in this place, because products
262+
* with the same id may have different sets of order attributes.
263+
*/
264+
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId, true);
261265
} catch (NoSuchEntityException $e) {
262266
return $this;
263267
}

app/code/Magento/OfflinePayments/Model/Purchaseorder.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ class Purchaseorder extends \Magento\Payment\Model\Method\AbstractMethod
4747
*/
4848
public function assignData(\Magento\Framework\DataObject $data)
4949
{
50-
if (!$data instanceof \Magento\Framework\DataObject) {
51-
$data = new \Magento\Framework\DataObject($data);
52-
}
53-
5450
$this->getInfoInstance()->setPoNumber($data->getPoNumber());
5551
return $this;
5652
}

app/code/Magento/Payment/Model/Info.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ protected function _initAdditionalInformation()
220220
{
221221
$additionalInfo = $this->_getData('additional_information');
222222
if (empty($this->_additionalInformation) && $additionalInfo) {
223-
if (!is_array($additionalInfo)) {
224-
$additionalInfo = unserialize($additionalInfo);
225-
}
226223
$this->_additionalInformation = $additionalInfo;
227224
}
228225
}

app/code/Magento/Payment/Model/Method/AbstractMethod.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
2222
* @SuppressWarnings(PHPMD.TooManyFields)
2323
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24+
* @deprecated
2425
*/
2526
abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibleModel implements
2627
MethodInterface,
@@ -769,12 +770,6 @@ public function getConfigData($field, $storeId = null)
769770
*/
770771
public function assignData(\Magento\Framework\DataObject $data)
771772
{
772-
if (is_array($data)) {
773-
$this->getInfoInstance()->addData($data);
774-
} elseif ($data instanceof \Magento\Framework\DataObject) {
775-
$this->getInfoInstance()->addData($data->getData());
776-
}
777-
778773
$this->_eventManager->dispatch(
779774
'payment_method_assign_data_' . $this->getCode(),
780775
[

app/code/Magento/Payment/Test/Unit/Model/InfoTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public function ccKeysDataProvider()
9090
];
9191
}
9292

93-
9493
public function testGetMethodInstanceWithRealMethod()
9594
{
9695
$method = 'real_method';
@@ -108,7 +107,6 @@ public function testGetMethodInstanceWithRealMethod()
108107
$this->info->getMethodInstance();
109108
}
110109

111-
112110
public function testGetMethodInstanceWithUnrealMethod()
113111
{
114112
$method = 'unreal_method';
@@ -131,7 +129,6 @@ public function testGetMethodInstanceWithUnrealMethod()
131129
$this->info->getMethodInstance();
132130
}
133131

134-
135132
/**
136133
* @expectedException \Magento\Framework\Exception\LocalizedException
137134
* @expectedExceptionMessage The payment method you requested is not available.
@@ -141,8 +138,7 @@ public function testGetMethodInstanceWithNoMethod()
141138
$this->info->setData('method', false);
142139
$this->info->getMethodInstance();
143140
}
144-
145-
141+
146142
public function testGetMethodInstanceRequestedMethod()
147143
{
148144
$code = 'real_method';
@@ -251,9 +247,9 @@ public function testHasAdditionalInformation()
251247

252248
public function testInitAdditionalInformationWithUnserialize()
253249
{
254-
$data = serialize(['key1' => 'data1', 'key2' => 'data2']);
250+
$data = ['key1' => 'data1', 'key2' => 'data2'];
255251
$this->info->setData('additional_information', $data);
256252

257-
$this->assertEquals(unserialize($data), $this->info->getAdditionalInformation());
253+
$this->assertEquals($data, $this->info->getAdditionalInformation());
258254
}
259255
}

app/code/Magento/Payment/Test/Unit/Model/Method/AbstractMethodTest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Payment\Test\Unit\Model\Method;
77

8+
use Magento\Framework\DataObject;
9+
use Magento\Payment\Model\InfoInterface;
10+
use Magento\Payment\Observer\AbstractDataAssignObserver;
811
use Magento\Store\Model\ScopeInterface;
912
use Magento\Payment\Test\Unit\Model\Method\AbstractMethod\Stub;
1013

@@ -65,7 +68,7 @@ protected function setUp()
6568

6669
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
6770
$this->payment = $helper->getObject(
68-
'Magento\Payment\Test\Unit\Model\Method\AbstractMethod\Stub',
71+
Stub::class,
6972
[
7073
'scopeConfig' => $this->scopeConfigMock,
7174
'context' => $contextMock,
@@ -114,6 +117,37 @@ public function testIsAvailable($result)
114117
$this->assertEquals($result, $this->payment->isAvailable($this->quoteMock));
115118
}
116119

120+
public function testAssignData()
121+
{
122+
$data = new DataObject();
123+
$paymentInfo = $this->getMock(InfoInterface::class);
124+
125+
$this->payment->setInfoInstance($paymentInfo);
126+
127+
$eventData = [
128+
AbstractDataAssignObserver::METHOD_CODE => $this,
129+
AbstractDataAssignObserver::MODEL_CODE => $paymentInfo,
130+
AbstractDataAssignObserver::DATA_CODE => $data
131+
];
132+
133+
$this->eventManagerMock->expects(static::exactly(2))
134+
->method('dispatch')
135+
->willReturnMap(
136+
[
137+
[
138+
'payment_method_assign_data_' . Stub::STUB_CODE,
139+
$eventData
140+
],
141+
[
142+
'payment_method_assign_data',
143+
$eventData
144+
]
145+
]
146+
);
147+
148+
$this->payment->assignData($data);
149+
}
150+
117151
/**
118152
* @return array
119153
*/

app/code/Magento/Paypal/Model/Express.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Paypal\Model\Api\Nvp;
99
use Magento\Paypal\Model\Api\ProcessableException as ApiProcessableException;
1010
use Magento\Paypal\Model\Express\Checkout as ExpressCheckout;
11+
use Magento\Quote\Api\Data\PaymentInterface;
1112
use Magento\Sales\Api\Data\OrderPaymentInterface;
1213
use Magento\Sales\Model\Order\Payment;
1314
use Magento\Sales\Model\Order\Payment\Transaction;
@@ -667,14 +668,24 @@ public function getApi()
667668
*/
668669
public function assignData(\Magento\Framework\DataObject $data)
669670
{
670-
$result = parent::assignData($data);
671-
$key = ExpressCheckout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT;
672-
if (is_array($data)) {
673-
$this->getInfoInstance()->setAdditionalInformation($key, isset($data[$key]) ? $data[$key] : null);
674-
} elseif ($data instanceof \Magento\Framework\DataObject) {
675-
$this->getInfoInstance()->setAdditionalInformation($key, $data->getData($key));
671+
parent::assignData($data);
672+
673+
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
674+
675+
if (
676+
!is_array($additionalData)
677+
|| !isset($additionalData[ExpressCheckout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT])
678+
) {
679+
return $this;
676680
}
677-
return $result;
681+
682+
$this->getInfoInstance()
683+
->setAdditionalInformation(
684+
ExpressCheckout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT,
685+
$additionalData[ExpressCheckout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT]
686+
);
687+
688+
return $this;
678689
}
679690

680691
/**

app/code/Magento/Paypal/Model/Payment/Method/Billing/AbstractAgreement.php

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Paypal\Model\Payment\Method\Billing;
77

8+
use Magento\Paypal\Model\Billing\Agreement;
9+
use Magento\Quote\Api\Data\PaymentInterface;
10+
811
/**
912
* Billing Agreement Payment Method Abstract model
1013
*
@@ -110,34 +113,35 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
110113
*/
111114
public function assignData(\Magento\Framework\DataObject $data)
112115
{
113-
$result = parent::assignData($data);
114-
115-
$key = self::TRANSPORT_BILLING_AGREEMENT_ID;
116-
$id = false;
117-
if (is_array($data) && isset($data[$key])) {
118-
$id = $data[$key];
119-
} elseif ($data instanceof \Magento\Framework\DataObject && $data->getData($key)) {
120-
$id = $data->getData($key);
116+
parent::assignData($data);
117+
118+
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
119+
120+
if (!is_array($additionalData) || !isset($additionalData[self::TRANSPORT_BILLING_AGREEMENT_ID])) {
121+
return $this;
121122
}
122-
if ($id) {
123-
$info = $this->getInfoInstance();
124-
$ba = $this->_agreementFactory->create()->load($id);
125-
if ($ba->getId() && $ba->getCustomerId() == $info->getQuote()->getCustomerId()) {
126-
$info->setAdditionalInformation(
127-
$key,
128-
$id
129-
)->setAdditionalInformation(
130-
self::PAYMENT_INFO_REFERENCE_ID,
131-
$ba->getReferenceId()
132-
);
133-
}
123+
124+
$id = $additionalData[self::TRANSPORT_BILLING_AGREEMENT_ID];
125+
if (!$id || !is_numeric($id)) {
126+
return $this;
134127
}
135-
return $result;
128+
129+
$info = $this->getInfoInstance();
130+
/** @var Agreement $ba */
131+
$ba = $this->_agreementFactory->create();
132+
$ba->load($id);
133+
134+
if ($ba->getId() && $ba->getCustomerId() == $info->getQuote()->getCustomerId()) {
135+
$info->setAdditionalInformation(self::TRANSPORT_BILLING_AGREEMENT_ID, $id);
136+
$info->setAdditionalInformation(self::PAYMENT_INFO_REFERENCE_ID, $ba->getReferenceId());
137+
}
138+
139+
return $this;
136140
}
137141

138142
/**
139143
* @param object $quote
140-
* @return void
144+
* @return bool
141145
*/
142146
abstract protected function _isAvailable($quote);
143147
}

app/code/Magento/Paypal/Observer/PayflowProAddCcData.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\Event\Observer;
99
use Magento\Payment\Observer\AbstractDataAssignObserver;
1010
use Magento\Paypal\Model\Payflow\Transparent;
11+
use Magento\Quote\Api\Data\PaymentInterface;
1112

1213
class PayflowProAddCcData extends AbstractDataAssignObserver
1314
{
@@ -29,7 +30,13 @@ public function execute(\Magento\Framework\Event\Observer $observer)
2930
{
3031
$dataObject = $this->readDataArgument($observer);
3132

32-
$ccData = array_intersect_key($dataObject->getData(), array_flip($this->ccKeys));
33+
$additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
34+
35+
if (!is_array($additionalData)) {
36+
return;
37+
}
38+
39+
$ccData = array_intersect_key($additionalData, array_flip($this->ccKeys));
3340
if (count($ccData) !== count($this->ccKeys)) {
3441
return;
3542
}
@@ -39,6 +46,11 @@ public function execute(\Magento\Framework\Event\Observer $observer)
3946
Transparent::CC_DETAILS,
4047
$this->sortCcData($ccData)
4148
);
49+
50+
// CC data should be stored explicitly
51+
foreach ($ccData as $ccKey => $ccValue) {
52+
$paymentModel->setData($ccKey, $ccValue);
53+
}
4254
}
4355

4456
/**

0 commit comments

Comments
 (0)