Skip to content

Commit

Permalink
Merge branch 2.2-develop into ENGCOM-4754-magento-magento2-22295
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-engcom-team committed Apr 18, 2019
2 parents 11768b2 + 77de966 commit 60a223e
Show file tree
Hide file tree
Showing 81 changed files with 2,313 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,23 @@ public function getGridIdsJson()
if (!$this->getUseSelectAll()) {
return '';
}
/** @var \Magento\Framework\Data\Collection $allIdsCollection */
$allIdsCollection = clone $this->getParentBlock()->getCollection();

if ($this->getMassactionIdField()) {
$massActionIdField = $this->getMassactionIdField();
/** @var \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection */
$collection = clone $this->getParentBlock()->getCollection();

if ($collection instanceof AbstractDb) {
$idsSelect = clone $collection->getSelect();
$idsSelect->reset(\Magento\Framework\DB\Select::ORDER);
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
$idsSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
$idsSelect->columns($this->getMassactionIdField(), 'main_table');
$idList = $collection->getConnection()->fetchCol($idsSelect);
} else {
$massActionIdField = $this->getParentBlock()->getMassactionIdField();
$idList = $collection->setPageSize(0)->getColumnValues($this->getMassactionIdField());
}
if ($allIdsCollection instanceof AbstractDb) {
$allIdsCollection->getSelect()->limit();
$allIdsCollection->clear();
}

$gridIds = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField);
if (!empty($gridIds)) {
return join(",", $gridIds);
}
return '';

return implode(',', $idList);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<section name="AdminPopupModalSection">
<element name="message" type="text" selector="aside.modal-popup .modal-content .popup-window-content"/>
<element name="ok" type="button" selector="//span[contains(text(),'Ok')]/ancestor::button"/>
<element name="confirm" type="button" selector="//aside[contains(@class, 'modal-popup')]//footer/button[normalize-space(.)='Confirm']" timeout="30"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -269,62 +269,6 @@ public function testGetGridIdsJsonWithoutUseSelectAll()
$this->assertEmpty($this->_block->getGridIdsJson());
}

/**
* @param array $items
* @param string $result
*
* @dataProvider dataProviderGetGridIdsJsonWithUseSelectAll
*/
public function testGetGridIdsJsonWithUseSelectAll(array $items, $result)
{
$this->_block->setUseSelectAll(true);

if ($this->_block->getMassactionIdField()) {
$massActionIdField = $this->_block->getMassactionIdField();
} else {
$massActionIdField = $this->_block->getParentBlock()->getMassactionIdField();
}

$collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
->disableOriginalConstructor()
->getMock();

$this->_gridMock->expects($this->once())
->method('getCollection')
->willReturn($collectionMock);
$collectionMock->expects($this->once())
->method('setPageSize')
->with(0)
->willReturnSelf();
$collectionMock->expects($this->once())
->method('getColumnValues')
->with($massActionIdField)
->willReturn($items);

$this->assertEquals($result, $this->_block->getGridIdsJson());
}

/**
* @return array
*/
public function dataProviderGetGridIdsJsonWithUseSelectAll()
{
return [
[
[],
'',
],
[
[1],
'1',
],
[
[1, 2, 3],
'1,2,3',
],
];
}

/**
* @param string $itemId
* @param array|\Magento\Framework\DataObject $item
Expand Down
177 changes: 177 additions & 0 deletions app/code/Magento/Braintree/Model/Multishipping/PlaceOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Model\Multishipping;

use Magento\Braintree\Gateway\Command\GetPaymentNonceCommand;
use Magento\Braintree\Model\Ui\ConfigProvider;
use Magento\Braintree\Observer\DataAssignObserver;
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PaypalConfigProvider;
use Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;

/**
* Order payments processing for multishipping checkout flow.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PlaceOrder implements PlaceOrderInterface
{
/**
* @var OrderManagementInterface
*/
private $orderManagement;

/**
* @var OrderPaymentExtensionInterfaceFactory
*/
private $paymentExtensionFactory;

/**
* @var GetPaymentNonceCommand
*/
private $getPaymentNonceCommand;

/**
* @param OrderManagementInterface $orderManagement
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
* @param GetPaymentNonceCommand $getPaymentNonceCommand
*/
public function __construct(
OrderManagementInterface $orderManagement,
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
GetPaymentNonceCommand $getPaymentNonceCommand
) {
$this->orderManagement = $orderManagement;
$this->paymentExtensionFactory = $paymentExtensionFactory;
$this->getPaymentNonceCommand = $getPaymentNonceCommand;
}

/**
* @inheritdoc
*/
public function place(array $orderList): array
{
if (empty($orderList)) {
return [];
}

$errorList = [];
$firstOrder = $this->orderManagement->place(array_shift($orderList));
// get payment token from first placed order
$paymentToken = $this->getPaymentToken($firstOrder);

foreach ($orderList as $order) {
try {
/** @var OrderInterface $order */
$orderPayment = $order->getPayment();
$this->setVaultPayment($orderPayment, $paymentToken);
$this->orderManagement->place($order);
} catch (\Exception $e) {
$incrementId = $order->getIncrementId();
$errorList[$incrementId] = $e;
}
}

return $errorList;
}

/**
* Sets vault payment method.
*
* @param OrderPaymentInterface $orderPayment
* @param PaymentTokenInterface $paymentToken
* @return void
*/
private function setVaultPayment(OrderPaymentInterface $orderPayment, PaymentTokenInterface $paymentToken)
{
$vaultMethod = $this->getVaultPaymentMethod(
$orderPayment->getMethod()
);
$orderPayment->setMethod($vaultMethod);

$publicHash = $paymentToken->getPublicHash();
$customerId = $paymentToken->getCustomerId();
$result = $this->getPaymentNonceCommand->execute(
['public_hash' => $publicHash, 'customer_id' => $customerId]
)
->get();

$orderPayment->setAdditionalInformation(
DataAssignObserver::PAYMENT_METHOD_NONCE,
$result['paymentMethodNonce']
);
$orderPayment->setAdditionalInformation(
PaymentTokenInterface::PUBLIC_HASH,
$publicHash
);
$orderPayment->setAdditionalInformation(
PaymentTokenInterface::CUSTOMER_ID,
$customerId
);
}

/**
* Returns vault payment method.
*
* For placing sequence of orders, we need to replace the original method on the vault method.
*
* @param string $method
* @return string
*/
private function getVaultPaymentMethod(string $method): string
{
$vaultPaymentMap = [
ConfigProvider::CODE => ConfigProvider::CC_VAULT_CODE,
PaypalConfigProvider::PAYPAL_CODE => PaypalConfigProvider::PAYPAL_VAULT_CODE
];

return $vaultPaymentMap[$method] ?? $method;
}

/**
* Returns payment token.
*
* @param OrderInterface $order
* @return PaymentTokenInterface
* @throws \BadMethodCallException
*/
private function getPaymentToken(OrderInterface $order): PaymentTokenInterface
{
$orderPayment = $order->getPayment();
$extensionAttributes = $this->getExtensionAttributes($orderPayment);
$paymentToken = $extensionAttributes->getVaultPaymentToken();

if ($paymentToken === null) {
throw new \BadMethodCallException('Vault Payment Token should be defined for placed order payment.');
}

return $paymentToken;
}

/**
* Gets payment extension attributes.
*
* @param OrderPaymentInterface $payment
* @return OrderPaymentExtensionInterface
*/
private function getExtensionAttributes(OrderPaymentInterface $payment): OrderPaymentExtensionInterface
{
$extensionAttributes = $payment->getExtensionAttributes();
if (null === $extensionAttributes) {
$extensionAttributes = $this->paymentExtensionFactory->create();
$payment->setExtensionAttributes($extensionAttributes);
}

return $extensionAttributes;
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Braintree/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"magento/module-quote": "101.0.*",
"magento/module-paypal": "100.2.*",
"magento/module-ui": "101.0.*",
"magento/module-multishipping": "100.2.*",
"braintree/braintree_php": "3.28.0"
},
"suggest": {
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Braintree/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<paymentInfoKeys>cc_type,cc_number,avsPostalCodeResponseCode,avsStreetAddressResponseCode,cvvResponseCode,processorAuthorizationCode,processorResponseCode,processorResponseText,liabilityShifted,liabilityShiftPossible,riskDataId,riskDataDecision</paymentInfoKeys>
<avs_ems_adapter>Magento\Braintree\Model\AvsEmsCodeMapper</avs_ems_adapter>
<cvv_ems_adapter>Magento\Braintree\Model\CvvEmsCodeMapper</cvv_ems_adapter>
<group>braintree_group</group>
</braintree>
<braintree_paypal>
<model>BraintreePayPalFacade</model>
Expand All @@ -67,6 +68,7 @@
<privateInfoKeys>processorResponseCode,processorResponseText,paymentId</privateInfoKeys>
<paymentInfoKeys>processorResponseCode,processorResponseText,paymentId,payerEmail</paymentInfoKeys>
<supported_locales>en_US,en_GB,en_AU,da_DK,fr_FR,fr_CA,de_DE,zh_HK,it_IT,nl_NL,no_NO,pl_PL,es_ES,sv_SE,tr_TR,pt_BR,ja_JP,id_ID,ko_KR,pt_PT,ru_RU,th_TH,zh_CN,zh_TW</supported_locales>
<group>braintree_group</group>
</braintree_paypal>
<braintree_cc_vault>
<model>BraintreeCreditCardVaultFacade</model>
Expand All @@ -76,6 +78,7 @@
<tokenFormat>Magento\Braintree\Model\InstantPurchase\CreditCard\TokenFormatter</tokenFormat>
<additionalInformation>Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider</additionalInformation>
</instant_purchase>
<group>braintree_group</group>
</braintree_cc_vault>
<braintree_paypal_vault>
<model>BraintreePayPalVaultFacade</model>
Expand All @@ -85,6 +88,7 @@
<tokenFormat>Magento\Braintree\Model\InstantPurchase\PayPal\TokenFormatter</tokenFormat>
<additionalInformation>Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider</additionalInformation>
</instant_purchase>
<group>braintree_group</group>
</braintree_paypal_vault>
</payment>
</default>
Expand Down
8 changes: 8 additions & 0 deletions app/code/Magento/Braintree/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@
<argument name="resolver" xsi:type="object">Magento\Braintree\Model\LocaleResolver</argument>
</arguments>
</type>
<type name="Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderPool">
<arguments>
<argument name="services" xsi:type="array">
<item name="braintree" xsi:type="string">Magento\Braintree\Model\Multishipping\PlaceOrder</item>
<item name="braintree_paypal" xsi:type="string">Magento\Braintree\Model\Multishipping\PlaceOrder</item>
</argument>
</arguments>
</type>
</config>
23 changes: 23 additions & 0 deletions app/code/Magento/Braintree/etc/payment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<payment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
<groups>
<group id="braintree_group">
<label>Braintree</label>
</group>
</groups>
<methods>
<method name="braintree">
<allow_multiple_address>1</allow_multiple_address>
</method>
<method name="braintree_paypal">
<allow_multiple_address>1</allow_multiple_address>
</method>
</methods>
</payment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout_billing">
<arguments>
<argument name="form_templates" xsi:type="array">
<item name="braintree" xsi:type="string">Magento_Braintree::multishipping/form.phtml</item>
<item name="braintree_paypal" xsi:type="string">Magento_Braintree::multishipping/form_paypal.phtml</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Loading

0 comments on commit 60a223e

Please sign in to comment.