Skip to content

Commit 43b1bd8

Browse files
committed
MAGETWO-43992: Can't select payment method for virtual product if payment is available for specific countries
1 parent 01e50e8 commit 43b1bd8

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

app/code/Magento/Checkout/view/frontend/web/js/action/set-billing-address.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@
44
*/
55
define(
66
[
7+
'jquery',
78
'Magento_Checkout/js/model/quote',
89
'Magento_Checkout/js/model/url-builder',
910
'mage/storage',
1011
'Magento_Checkout/js/model/error-processor',
1112
'Magento_Customer/js/model/customer',
1213
'Magento_Checkout/js/action/get-totals',
13-
'Magento_Checkout/js/model/full-screen-loader'
14+
'Magento_Checkout/js/model/full-screen-loader',
15+
'Magento_Checkout/js/action/get-payment-information'
1416
],
15-
function (quote, urlBuilder, storage, errorProcessor, customer, getTotalsAction, fullScreenLoader) {
17+
function ($,
18+
quote,
19+
urlBuilder,
20+
storage,
21+
errorProcessor,
22+
customer,
23+
getTotalsAction,
24+
fullScreenLoader,
25+
getPaymentInformationAction
26+
) {
1627
'use strict';
1728

1829
return function (messageContainer) {
@@ -44,14 +55,19 @@ define(
4455
serviceUrl, JSON.stringify(payload)
4556
).done(
4657
function () {
47-
getTotalsAction([]);
58+
if (!quote.isVirtual()) {
59+
getTotalsAction([]);
60+
} else {
61+
var deferred = $.Deferred();
62+
getPaymentInformationAction(deferred);
63+
$.when(deferred).done(function () {
64+
fullScreenLoader.stopLoader();
65+
});
66+
}
4867
}
4968
).fail(
5069
function (response) {
5170
errorProcessor.process(response, messageContainer);
52-
}
53-
).always(
54-
function () {
5571
fullScreenLoader.stopLoader();
5672
}
5773
);

app/code/Magento/Checkout/view/frontend/web/js/view/payment/list.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ define([
3030
paymentMethods.subscribe(
3131
function (changes) {
3232
checkoutDataResolver.resolvePaymentMethod();
33+
//remove renderer for "deleted" payment methods
34+
_.each(changes, function (change) {
35+
if (change.status === 'deleted') {
36+
this.removeRenderer(change.value.method);
37+
}
38+
}, this);
39+
//add renderer for "added" payment methods
3340
_.each(changes, function (change) {
3441
if (change.status === 'added') {
3542
this.createRenderer(change.value);
36-
} else if (change.status === 'deleted') {
37-
this.removeRenderer(change.value.method);
3843
}
3944
}, this);
4045
}, this, 'arrayChange');

app/code/Magento/Payment/Model/Checks/CanUseForCountry/CountryProvider.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public function __construct(DirectoryHelper $directoryHelper)
3131
*/
3232
public function getCountry(Quote $quote)
3333
{
34-
return $quote->isVirtual()
35-
? $this->directoryHelper->getDefaultCountry()
36-
: $quote->getShippingAddress()->getCountry();
34+
$address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
35+
return $address
36+
? $address->getCountry()
37+
: $this->directoryHelper->getDefaultCountry();
3738
}
3839
}

app/code/Magento/Payment/Test/Unit/Model/Checks/CanUseForCountry/CountryProviderTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,27 @@ public function testGetCountryForNonVirtualQuote()
3333
$this->assertEquals(1, $this->model->getCountry($quoteMock));
3434
}
3535

36-
public function testGetCountryForVirtualQuote()
36+
public function testGetCountryForVirtualQuoteWhenBillingAddressNotExist()
3737
{
3838
$quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false, false);
3939
$quoteMock->expects($this->once())->method('isVirtual')->willReturn(true);
4040
$addressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false, false);
4141
$addressMock->expects($this->never())->method('getCountry');
4242
$quoteMock->expects($this->never())->method('getShippingAddress');
43+
$quoteMock->expects($this->once())->method('getBillingAddress')->willReturn(null);
4344
$this->directoryMock->expects($this->once())->method('getDefaultCountry')->willReturn(10);
4445
$this->assertEquals(10, $this->model->getCountry($quoteMock));
4546
}
47+
48+
public function testGetCountryForVirtualQuoteWhenBillingAddressExist()
49+
{
50+
$quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false, false);
51+
$quoteMock->expects($this->once())->method('isVirtual')->willReturn(true);
52+
$addressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false, false);
53+
$addressMock->expects($this->once())->method('getCountry')->willReturn(10);
54+
$quoteMock->expects($this->never())->method('getShippingAddress');
55+
$quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($addressMock);
56+
$this->directoryMock->expects($this->never())->method('getDefaultCountry');
57+
$this->assertEquals(10, $this->model->getCountry($quoteMock));
58+
}
4659
}

0 commit comments

Comments
 (0)