Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…gento2ce into MAGETWO-52321
  • Loading branch information
shiftedreality committed Apr 27, 2016
2 parents 4c5e54f + f01f524 commit 2d5f447
Show file tree
Hide file tree
Showing 37 changed files with 838 additions and 260 deletions.
11 changes: 9 additions & 2 deletions app/code/Magento/Braintree/Observer/DataAssignObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;

/**
* Class DataAssignObserver
Expand All @@ -31,13 +32,19 @@ class DataAssignObserver extends AbstractDataAssignObserver
public function execute(Observer $observer)
{
$data = $this->readDataArgument($observer);

$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_array($additionalData)) {
return;
}

$paymentInfo = $this->readPaymentModelArgument($observer);

foreach ($this->additionalInformationList as $additionalInformationKey) {
if ($data->getDataByKey($additionalInformationKey) !== null) {
if (isset($additionalData[$additionalInformationKey])) {
$paymentInfo->setAdditionalInformation(
$additionalInformationKey,
$data->getDataByKey($additionalInformationKey)
$additionalData[$additionalInformationKey]
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Payment\Model\InfoInterface;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Braintree\Observer\DataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;

/**
* Class DataAssignObserverTest
Expand All @@ -30,8 +31,10 @@ public function testExecute()
$paymentInfoModel = $this->getMock(InfoInterface::class);
$dataObject = new DataObject(
[
'payment_method_nonce' => self::PAYMENT_METHOD_NONCE,
'device_data' => self::DEVICE_DATA,
PaymentInterface::KEY_ADDITIONAL_DATA => [
'payment_method_nonce' => self::PAYMENT_METHOD_NONCE,
'device_data' => self::DEVICE_DATA
]
]
);
$observerContainer->expects(static::atLeastOnce())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ protected function getTierPriceStructure($tierPricePath)
'dndConfig' => [
'enabled' => false,
],
'disabled' => false,
'sortOrder' =>
$this->arrayManager->get($tierPricePath . '/arguments/data/config/sortOrder', $this->meta),
],
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/Checkout/Model/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ public function addOrderItem($orderItem, $qtyFlag = null)
if ($orderItem->getParentItem() === null) {
$storeId = $this->_storeManager->getStore()->getId();
try {
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId);
/**
* We need to reload product in this place, because products
* with the same id may have different sets of order attributes.
*/
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId, true);
} catch (NoSuchEntityException $e) {
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
/**
* jshint browser:true
*/
/*eslint no-unused-vars: 0*/
define([
'jquery',
'Magento_Customer/js/zxcvbn',
'mage/translate',
'Magento_Customer/js/zxcvbn'
], function ($, $t, zxcvbn) {
'mage/validation'
], function ($, zxcvbn, $t, validation) {
'use strict';

$.widget('mage.passwordStrengthIndicator', {
Expand Down Expand Up @@ -50,6 +52,8 @@ define([
className = this._getClassName(score);

this._displayStrength(className, score);
//update error messages
$.validator.validateSingleElement(this.element.find('input[type="password"]'));
},

/**
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/ImportExport/Model/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ public static function getStaticAttributeFilterType(\Magento\Eav\Model\Entity\At
return self::FILTER_TYPE_INPUT;
}
$columns = $attribute->getFlatColumns();
if (empty($columns)) {
return self::FILTER_TYPE_INPUT;
}
switch ($columns[$attribute->getAttributeCode()]['type']) {
case \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER:
case \Magento\Framework\DB\Ddl\Table::TYPE_BIGINT:
Expand Down
4 changes: 0 additions & 4 deletions app/code/Magento/OfflinePayments/Model/Purchaseorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ class Purchaseorder extends \Magento\Payment\Model\Method\AbstractMethod
*/
public function assignData(\Magento\Framework\DataObject $data)
{
if (!$data instanceof \Magento\Framework\DataObject) {
$data = new \Magento\Framework\DataObject($data);
}

$this->getInfoInstance()->setPoNumber($data->getPoNumber());
return $this;
}
Expand Down
3 changes: 0 additions & 3 deletions app/code/Magento/Payment/Model/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ protected function _initAdditionalInformation()
{
$additionalInfo = $this->_getData('additional_information');
if (empty($this->_additionalInformation) && $additionalInfo) {
if (!is_array($additionalInfo)) {
$additionalInfo = unserialize($additionalInfo);
}
$this->_additionalInformation = $additionalInfo;
}
}
Expand Down
7 changes: 1 addition & 6 deletions app/code/Magento/Payment/Model/Method/AbstractMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @deprecated
*/
abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibleModel implements
MethodInterface,
Expand Down Expand Up @@ -769,12 +770,6 @@ public function getConfigData($field, $storeId = null)
*/
public function assignData(\Magento\Framework\DataObject $data)
{
if (is_array($data)) {
$this->getInfoInstance()->addData($data);
} elseif ($data instanceof \Magento\Framework\DataObject) {
$this->getInfoInstance()->addData($data->getData());
}

$this->_eventManager->dispatch(
'payment_method_assign_data_' . $this->getCode(),
[
Expand Down
10 changes: 3 additions & 7 deletions app/code/Magento/Payment/Test/Unit/Model/InfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function ccKeysDataProvider()
];
}


public function testGetMethodInstanceWithRealMethod()
{
$method = 'real_method';
Expand All @@ -108,7 +107,6 @@ public function testGetMethodInstanceWithRealMethod()
$this->info->getMethodInstance();
}


public function testGetMethodInstanceWithUnrealMethod()
{
$method = 'unreal_method';
Expand All @@ -131,7 +129,6 @@ public function testGetMethodInstanceWithUnrealMethod()
$this->info->getMethodInstance();
}


/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage The payment method you requested is not available.
Expand All @@ -141,8 +138,7 @@ public function testGetMethodInstanceWithNoMethod()
$this->info->setData('method', false);
$this->info->getMethodInstance();
}



public function testGetMethodInstanceRequestedMethod()
{
$code = 'real_method';
Expand Down Expand Up @@ -251,9 +247,9 @@ public function testHasAdditionalInformation()

public function testInitAdditionalInformationWithUnserialize()
{
$data = serialize(['key1' => 'data1', 'key2' => 'data2']);
$data = ['key1' => 'data1', 'key2' => 'data2'];
$this->info->setData('additional_information', $data);

$this->assertEquals(unserialize($data), $this->info->getAdditionalInformation());
$this->assertEquals($data, $this->info->getAdditionalInformation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\Payment\Test\Unit\Model\Method;

use Magento\Framework\DataObject;
use Magento\Payment\Model\InfoInterface;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Store\Model\ScopeInterface;
use Magento\Payment\Test\Unit\Model\Method\AbstractMethod\Stub;

Expand Down Expand Up @@ -65,7 +68,7 @@ protected function setUp()

$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->payment = $helper->getObject(
'Magento\Payment\Test\Unit\Model\Method\AbstractMethod\Stub',
Stub::class,
[
'scopeConfig' => $this->scopeConfigMock,
'context' => $contextMock,
Expand Down Expand Up @@ -114,6 +117,37 @@ public function testIsAvailable($result)
$this->assertEquals($result, $this->payment->isAvailable($this->quoteMock));
}

public function testAssignData()
{
$data = new DataObject();
$paymentInfo = $this->getMock(InfoInterface::class);

$this->payment->setInfoInstance($paymentInfo);

$eventData = [
AbstractDataAssignObserver::METHOD_CODE => $this,
AbstractDataAssignObserver::MODEL_CODE => $paymentInfo,
AbstractDataAssignObserver::DATA_CODE => $data
];

$this->eventManagerMock->expects(static::exactly(2))
->method('dispatch')
->willReturnMap(
[
[
'payment_method_assign_data_' . Stub::STUB_CODE,
$eventData
],
[
'payment_method_assign_data',
$eventData
]
]
);

$this->payment->assignData($data);
}

/**
* @return array
*/
Expand Down
25 changes: 18 additions & 7 deletions app/code/Magento/Paypal/Model/Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Paypal\Model\Api\Nvp;
use Magento\Paypal\Model\Api\ProcessableException as ApiProcessableException;
use Magento\Paypal\Model\Express\Checkout as ExpressCheckout;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Model\Order\Payment;
use Magento\Sales\Model\Order\Payment\Transaction;
Expand Down Expand Up @@ -667,14 +668,24 @@ public function getApi()
*/
public function assignData(\Magento\Framework\DataObject $data)
{
$result = parent::assignData($data);
$key = ExpressCheckout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT;
if (is_array($data)) {
$this->getInfoInstance()->setAdditionalInformation($key, isset($data[$key]) ? $data[$key] : null);
} elseif ($data instanceof \Magento\Framework\DataObject) {
$this->getInfoInstance()->setAdditionalInformation($key, $data->getData($key));
parent::assignData($data);

$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);

if (
!is_array($additionalData)
|| !isset($additionalData[ExpressCheckout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT])
) {
return $this;
}
return $result;

$this->getInfoInstance()
->setAdditionalInformation(
ExpressCheckout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT,
$additionalData[ExpressCheckout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT]
);

return $this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\Paypal\Model\Payment\Method\Billing;

use Magento\Paypal\Model\Billing\Agreement;
use Magento\Quote\Api\Data\PaymentInterface;

/**
* Billing Agreement Payment Method Abstract model
*
Expand Down Expand Up @@ -110,34 +113,35 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
*/
public function assignData(\Magento\Framework\DataObject $data)
{
$result = parent::assignData($data);

$key = self::TRANSPORT_BILLING_AGREEMENT_ID;
$id = false;
if (is_array($data) && isset($data[$key])) {
$id = $data[$key];
} elseif ($data instanceof \Magento\Framework\DataObject && $data->getData($key)) {
$id = $data->getData($key);
parent::assignData($data);

$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);

if (!is_array($additionalData) || !isset($additionalData[self::TRANSPORT_BILLING_AGREEMENT_ID])) {
return $this;
}
if ($id) {
$info = $this->getInfoInstance();
$ba = $this->_agreementFactory->create()->load($id);
if ($ba->getId() && $ba->getCustomerId() == $info->getQuote()->getCustomerId()) {
$info->setAdditionalInformation(
$key,
$id
)->setAdditionalInformation(
self::PAYMENT_INFO_REFERENCE_ID,
$ba->getReferenceId()
);
}

$id = $additionalData[self::TRANSPORT_BILLING_AGREEMENT_ID];
if (!$id || !is_numeric($id)) {
return $this;
}
return $result;

$info = $this->getInfoInstance();
/** @var Agreement $ba */
$ba = $this->_agreementFactory->create();
$ba->load($id);

if ($ba->getId() && $ba->getCustomerId() == $info->getQuote()->getCustomerId()) {
$info->setAdditionalInformation(self::TRANSPORT_BILLING_AGREEMENT_ID, $id);
$info->setAdditionalInformation(self::PAYMENT_INFO_REFERENCE_ID, $ba->getReferenceId());
}

return $this;
}

/**
* @param object $quote
* @return void
* @return bool
*/
abstract protected function _isAvailable($quote);
}
14 changes: 13 additions & 1 deletion app/code/Magento/Paypal/Observer/PayflowProAddCcData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Paypal\Model\Payflow\Transparent;
use Magento\Quote\Api\Data\PaymentInterface;

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

$ccData = array_intersect_key($dataObject->getData(), array_flip($this->ccKeys));
$additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA);

if (!is_array($additionalData)) {
return;
}

$ccData = array_intersect_key($additionalData, array_flip($this->ccKeys));
if (count($ccData) !== count($this->ccKeys)) {
return;
}
Expand All @@ -39,6 +46,11 @@ public function execute(\Magento\Framework\Event\Observer $observer)
Transparent::CC_DETAILS,
$this->sortCcData($ccData)
);

// CC data should be stored explicitly
foreach ($ccData as $ccKey => $ccValue) {
$paymentModel->setData($ccKey, $ccValue);
}
}

/**
Expand Down
Loading

0 comments on commit 2d5f447

Please sign in to comment.