Skip to content

Commit e0e9ed0

Browse files
authored
Merge pull request #1130 from magento-mpi/MPI-Bugfixes
[MPI] Bugfixes
2 parents 07f4e70 + e4943e7 commit e0e9ed0

File tree

37 files changed

+911
-162
lines changed

37 files changed

+911
-162
lines changed

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/cc-form.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ define(
3636
braintreeDeviceData: null,
3737
paymentMethodNonce: null,
3838
lastBillingAddress: null,
39+
ccCode: null,
40+
ccMessageContainer: null,
3941
validatorManager: validatorManager,
4042
code: 'braintree',
4143

@@ -138,9 +140,39 @@ define(
138140
return;
139141
}
140142

143+
this.restoreMessageContainer();
144+
this.restoreCode();
145+
146+
/**
147+
* Define onReady callback
148+
*/
149+
braintree.onReady = function () {};
141150
this.initBraintree();
142151
},
143152

153+
/**
154+
* Restore original message container for cc-form component
155+
*/
156+
restoreMessageContainer: function () {
157+
this.messageContainer = this.ccMessageContainer;
158+
},
159+
160+
/**
161+
* Restore original code for cc-form component
162+
*/
163+
restoreCode: function () {
164+
this.code = this.ccCode;
165+
},
166+
167+
/** @inheritdoc */
168+
initChildren: function () {
169+
this._super();
170+
this.ccMessageContainer = this.messageContainer;
171+
this.ccCode = this.code;
172+
173+
return this;
174+
},
175+
144176
/**
145177
* Init config
146178
*/

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/vault.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ define([
5252
var self = this;
5353

5454
/**
55-
* Define already callback
55+
* Define onReady callback
5656
*/
5757
Braintree.onReady = function () {
5858
self.getPaymentMethodNonce();
@@ -78,6 +78,7 @@ define([
7878
formComponent.setPaymentMethodNonce(response.paymentMethodNonce);
7979
formComponent.additionalData['public_hash'] = self.publicHash;
8080
formComponent.code = self.code;
81+
formComponent.messageContainer = self.messageContainer;
8182
formComponent.placeOrder();
8283
});
8384
})

app/code/Magento/Braintree/view/frontend/web/template/payment/form.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,12 @@
139139
<button class="action primary checkout"
140140
type="submit"
141141
data-bind="
142-
click: placeOrderClick,
143-
attr: {title: $t('Place Order')}
144-
">
142+
click: placeOrderClick,
143+
attr: {title: $t('Place Order')},
144+
css: {disabled: !isPlaceOrderActionAllowed()},
145+
enable: isActive()
146+
"
147+
disabled>
145148
<span data-bind="i18n: 'Place Order'"></span>
146149
</button>
147150
</div>

app/code/Magento/Bundle/Model/Product/SaveHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public function execute($entity, $arguments = [])
6666
$options = $bundleProductOptions ?: [];
6767
foreach ($options as $option) {
6868
$this->optionRepository->save($entity, $option);
69-
$entity->setCopyFromView(false);
7069
}
70+
$entity->setCopyFromView(false);
7171
}
7272
return $entity;
7373
}

app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
1414
use Magento\Framework\Exception\LocalizedException;
1515
use Magento\Framework\App\ObjectManager;
16+
use Magento\Directory\Model\AllowedCountries;
1617

1718
/**
1819
* Multishipping checkout model
@@ -146,12 +147,19 @@ class Multishipping extends \Magento\Framework\DataObject
146147
*/
147148
private $cartExtensionFactory;
148149

150+
/**
151+
* @var AllowedCountries
152+
*/
153+
private $allowedCountryReader;
154+
149155
/**
150156
* @var \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor
151157
*/
152158
private $shippingAssignmentProcessor;
153159

154160
/**
161+
* Multishipping constructor.
162+
*
155163
* @param \Magento\Checkout\Model\Session $checkoutSession
156164
* @param \Magento\Customer\Model\Session $customerSession
157165
* @param \Magento\Sales\Model\OrderFactory $orderFactory
@@ -174,6 +182,7 @@ class Multishipping extends \Magento\Framework\DataObject
174182
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
175183
* @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector
176184
* @param array $data
185+
* @param AllowedCountries|null $allowedCountryReader
177186
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
178187
*/
179188
public function __construct(
@@ -198,7 +207,8 @@ public function __construct(
198207
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
199208
\Magento\Framework\Api\FilterBuilder $filterBuilder,
200209
\Magento\Quote\Model\Quote\TotalsCollector $totalsCollector,
201-
array $data = []
210+
array $data = [],
211+
AllowedCountries $allowedCountryReader = null
202212
) {
203213
$this->_eventManager = $eventManager;
204214
$this->_scopeConfig = $scopeConfig;
@@ -221,6 +231,8 @@ public function __construct(
221231
$this->quotePaymentToOrderPayment = $quotePaymentToOrderPayment;
222232
$this->quoteAddressToOrderAddress = $quoteAddressToOrderAddress;
223233
$this->totalsCollector = $totalsCollector;
234+
$this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance()
235+
->get(AllowedCountries::class);
224236
parent::__construct($data);
225237
$this->_init();
226238
}
@@ -696,6 +708,18 @@ protected function _validate()
696708
__('Please specify shipping methods for all addresses.')
697709
);
698710
}
711+
712+
// Checks if a country id present in the allowed countries list.
713+
if (
714+
!in_array(
715+
$address->getCountryId(),
716+
$this->allowedCountryReader->getAllowedCountries()
717+
)
718+
) {
719+
throw new \Magento\Framework\Exception\LocalizedException(
720+
__('Some addresses cannot be used due to country-specific configurations.')
721+
);
722+
}
699723
}
700724
$addressValidation = $quote->getBillingAddress()->validate();
701725
if ($addressValidation !== true) {

app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
use Magento\Store\Model\StoreManagerInterface;
4545
use PHPUnit_Framework_MockObject_MockObject;
4646
use PHPUnit_Framework_TestCase;
47+
use Magento\Quote\Model\Quote\Payment;
48+
use Magento\Payment\Model\Method\AbstractMethod;
49+
use Magento\Directory\Model\AllowedCountries;
4750

4851
/**
4952
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -146,6 +149,13 @@ protected function setUp()
146149
$this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomerDataObject')
147150
->willReturn($this->customerMock);
148151
$this->totalsCollectorMock = $this->createSimpleMock(TotalsCollector::class);
152+
$allowedCountryReaderMock = $this->getMockBuilder(AllowedCountries::class)
153+
->disableOriginalConstructor()
154+
->setMethods(['getAllowedCountries'])
155+
->getMock();
156+
$allowedCountryReaderMock->method('getAllowedCountries')
157+
->willReturn(['EN'=>'EN']);
158+
149159
$this->model = new Multishipping(
150160
$this->checkoutSessionMock,
151161
$this->customerSessionMock,
@@ -168,7 +178,8 @@ protected function setUp()
168178
$this->searchCriteriaBuilderMock,
169179
$this->filterBuilderMock,
170180
$this->totalsCollectorMock,
171-
$data
181+
$data,
182+
$allowedCountryReaderMock
172183
);
173184

174185
$this->cartExtensionFactoryMock = $this->getMockBuilder(CartExtensionFactory::class)
@@ -357,6 +368,49 @@ public function testSetShippingMethods()
357368
$this->model->setShippingMethods($methodsArray);
358369
}
359370

371+
/**
372+
* Tests exception for addresses with country id not in the allowed countries list.
373+
*
374+
* @expectedException \Magento\Framework\Exception\LocalizedException
375+
* @expectedExceptionMessage Some addresses cannot be used due to country-specific configurations.
376+
*/
377+
public function testCreateOrdersCountryNotPresentInAllowedListException()
378+
{
379+
$abstractMethod = $this->getMockBuilder(AbstractMethod::class)
380+
->disableOriginalConstructor()
381+
->setMethods(['isAvailable'])
382+
->getMockForAbstractClass();
383+
$abstractMethod->method('isAvailable')
384+
->willReturn(true);
385+
386+
$paymentMock = $this->getMockBuilder(Payment::class)
387+
->disableOriginalConstructor()
388+
->setMethods(['getMethodInstance'])
389+
->getMock();
390+
$paymentMock->method('getMethodInstance')
391+
->willReturn($abstractMethod);
392+
393+
$shippingAddressMock = $this->getMockBuilder(Address::class)
394+
->disableOriginalConstructor()
395+
->setMethods(['validate', 'getShippingMethod', 'getShippingRateByCode', 'getCountryId'])
396+
->getMock();
397+
$shippingAddressMock->method('validate')
398+
->willReturn(true);
399+
$shippingAddressMock->method('getShippingMethod')
400+
->willReturn('carrier');
401+
$shippingAddressMock->method('getShippingRateByCode')
402+
->willReturn('code');
403+
$shippingAddressMock->method('getCountryId')
404+
->willReturn('EU');
405+
406+
$this->quoteMock->method('getPayment')
407+
->willReturn($paymentMock);
408+
$this->quoteMock->method('getAllShippingAddresses')
409+
->willReturn([$shippingAddressMock]);
410+
411+
$this->model->createOrders();
412+
}
413+
360414
/**
361415
* @param ShippingAssignment $shippingAssignmentMock
362416
* @return CartExtension|PHPUnit_Framework_MockObject_MockObject

app/code/Magento/Multishipping/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"magento/module-customer": "100.2.*",
1212
"magento/module-theme": "100.2.*",
1313
"magento/module-quote": "100.2.*",
14-
"magento/framework": "100.2.*"
14+
"magento/framework": "100.2.*",
15+
"magento/module-directory": "100.2.*"
1516
},
1617
"type": "magento2-module",
1718
"version": "100.2.0-dev",

app/code/Magento/Multishipping/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,4 @@ Options,Options
8787
"Review Order","Review Order"
8888
"Select Shipping Method","Select Shipping Method"
8989
"We received your order!","We received your order!"
90+
"Some addresses cannot be used due to country-specific configurations.","Some addresses cannot be used due to country-specific configurations."

app/code/Magento/Paypal/Block/Express/InContext/Minicart/Button.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class Button extends Template implements ShortcutInterface
2626

2727
const BUTTON_ELEMENT_INDEX = 'button_id';
2828

29+
const LINK_DATA_ACTION = 'link_data_action';
30+
2931
const CART_BUTTON_ELEMENT_INDEX = 'add_to_cart_selector';
3032

3133
/**
@@ -132,6 +134,14 @@ public function getContainerId()
132134
return $this->getData(self::BUTTON_ELEMENT_INDEX);
133135
}
134136

137+
/**
138+
* @return string
139+
*/
140+
public function getLinkAction()
141+
{
142+
return $this->getData(self::LINK_DATA_ACTION);
143+
}
144+
135145
/**
136146
* @return string
137147
*/

app/code/Magento/Paypal/Model/Api/AbstractApi.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ abstract class AbstractApi extends \Magento\Framework\DataObject
5252
/**
5353
* @var array
5454
*/
55-
protected $_lineItemExportItemsFilters = [];
55+
protected $_lineItemExportItemsFilters = [
56+
'name' => 'strval'
57+
];
5658

5759
/**
5860
* @var array
@@ -440,14 +442,7 @@ protected function _exportLineItems(array &$request, $i = 0)
440442
foreach ($this->_lineItemExportItemsFormat as $publicKey => $privateFormat) {
441443
$result = true;
442444
$value = $item->getDataUsingMethod($publicKey);
443-
if (isset($this->_lineItemExportItemsFilters[$publicKey])) {
444-
$callback = $this->_lineItemExportItemsFilters[$publicKey];
445-
$value = call_user_func([$this, $callback], $value);
446-
}
447-
if (is_float($value)) {
448-
$value = $this->formatPrice($value);
449-
}
450-
$request[sprintf($privateFormat, $i)] = $value;
445+
$request[sprintf($privateFormat, $i)] = $this->formatValue($value, $publicKey);
451446
}
452447
$i++;
453448
}
@@ -635,4 +630,25 @@ public function getDebugReplacePrivateDataKeys()
635630
{
636631
return $this->_debugReplacePrivateDataKeys;
637632
}
633+
634+
/**
635+
* Formats value according to configured filters or converts to 0.00 format if value is float.
636+
*
637+
* @param string|int|float|\Magento\Framework\Phrase $value
638+
* @param string $publicKey
639+
* @return string
640+
*/
641+
private function formatValue($value, $publicKey)
642+
{
643+
if (!empty($this->_lineItemExportItemsFilters[$publicKey])) {
644+
$callback = $this->_lineItemExportItemsFilters[$publicKey];
645+
$value = method_exists($this, $callback) ? $this->{$callback}($value) : $callback($value);
646+
}
647+
648+
if (is_float($value)) {
649+
$value = $this->formatPrice($value);
650+
}
651+
652+
return $value;
653+
}
638654
}

0 commit comments

Comments
 (0)