Skip to content

Commit 01f0702

Browse files
committed
Merge branch 'MAGETWO-67106' into MPI-Bugfixes
2 parents 89f8baf + ee3e6f8 commit 01f0702

File tree

8 files changed

+133
-13
lines changed

8 files changed

+133
-13
lines changed

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/etc/frontend/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<item name="template" xsi:type="string">Magento_Paypal::express/in-context/shortcut/button.phtml</item>
9393
<item name="alias" xsi:type="string">paypal.express-in-context.mini-cart</item>
9494
<item name="button_id" xsi:type="string">paypal-express-in-context-mini-cart</item>
95+
<item name="link_data_action" xsi:type="string">paypal-in-context-checkout</item>
9596
</argument>
9697
<argument name="payment" xsi:type="object">Magento\Paypal\Model\Express</argument>
9798
</arguments>

app/code/Magento/Paypal/view/frontend/templates/express/in-context/shortcut/button.phtml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ use Magento\Paypal\Block\Express\InContext\Minicart\Button;
1111
*/
1212
$config = [
1313
'Magento_Paypal/js/in-context/button' => [
14-
'id' => $block->getContainerId(),
15-
'paypalButton' => Button::PAYPAL_BUTTON_ID,
16-
'addToCartSelector' => $block->getAddToCartSelector()
14+
'id' => $block->escapeHtml($block->getContainerId()),
15+
'linkDataAction' => $block->escapeHtml($block->getLinkAction()),
16+
'paypalButton' => $block->escapeHtml(Button::PAYPAL_BUTTON_ID),
17+
'addToCartSelector' => $block->escapeHtml($block->getAddToCartSelector())
1718
]
1819
];
1920

2021
?>
2122
<div data-mage-init='<?php /* @noEscape */ echo json_encode($config); ?>'
22-
class="paypal checkout paypal-logo <?php /* @noEscape */ echo $block->getContainerId(); ?>-container">
23-
<a id="<?php /* @noEscape */ echo $block->getContainerId(); ?>" href="#">
23+
class="paypal checkout paypal-logo <?php echo $block->escapeHtml($block->getContainerId()); ?>-container">
24+
<a data-action="<?php echo $block->escapeHtml($block->getLinkAction()); ?>" href="#">
2425
<img class="paypal-button-hidden"
25-
src="<?php /* @noEscape */ echo $block->getImageUrl() ?>"
26+
src="<?php echo $block->escapeHtml($block->getImageUrl()); ?>"
2627
alt="Check out with PayPal" />
2728
</a>
2829
</div>

app/code/Magento/Paypal/view/frontend/web/js/in-context/button.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ define(
1212
Component,
1313
$
1414
) {
15-
'use strict';
16-
1715
return Component.extend({
1816

1917
defaults: {},
@@ -31,7 +29,7 @@ define(
3129
* @returns {Object}
3230
*/
3331
initEvents: function () {
34-
$('#' + this.id).off('click.' + this.id)
32+
$('a[data-action="' + this.linkDataAction + '"]').off('click.' + this.id)
3533
.on('click.' + this.id, this.click.bind(this));
3634

3735
return this;

app/code/Magento/Paypal/view/frontend/web/js/in-context/express-checkout.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ define(
2525
defaults: {
2626
clientConfig: {
2727

28+
checkoutInited: false,
29+
2830
/**
2931
* @param {Object} event
3032
*/
@@ -33,7 +35,12 @@ define(
3335

3436
event.preventDefault();
3537

36-
paypalExpressCheckout.checkout.initXO();
38+
if (!this.clientConfig.checkoutInited) {
39+
paypalExpressCheckout.checkout.initXO();
40+
this.clientConfig.checkoutInited = true;
41+
} else {
42+
paypalExpressCheckout.checkout.closeFlow();
43+
}
3744

3845
$.get(
3946
this.path,
@@ -52,11 +59,11 @@ define(
5259
}
5360
).fail(
5461
function () {
55-
$('body').trigger('processStop');
5662
paypalExpressCheckout.checkout.closeFlow();
5763
}
5864
).always(
5965
function () {
66+
$('body').trigger('processStop');
6067
customerData.invalidate(['cart']);
6168
}
6269
);

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class View extends AbstractConfigureBlock
6868
*
6969
* @var string
7070
*/
71-
protected $inContextPaypalCheckout = '#paypal-express-in-context-mini-cart';
71+
protected $inContextPaypalCheckout = 'ul.checkout-methods-items a[data-action="paypal-in-context-checkout"]';
7272

7373
/**
7474
* Product name element.

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Cart extends Block
6262
*
6363
* @var string
6464
*/
65-
protected $inContextPaypalCheckoutButton = '#paypal-express-in-context-mini-cart';
65+
protected $inContextPaypalCheckoutButton = 'ul.checkout-methods-items a[data-action="paypal-in-context-checkout"]';
6666

6767
/**
6868
* Locator value for "Check out with Braintree PayPal" button.
@@ -184,6 +184,7 @@ public function paypalCheckout()
184184
*/
185185
public function inContextPaypalCheckout()
186186
{
187+
$this->waitForCheckoutButton();
187188
$this->_rootElement->find($this->inContextPaypalCheckoutButton)->click();
188189
$this->browser->selectWindow();
189190
$this->waitForFormLoaded();
@@ -262,4 +263,14 @@ public function waitCartContainerLoading()
262263
{
263264
$this->waitForElementVisible($this->cartContainer);
264265
}
266+
267+
/**
268+
* Wait until in-context checkout button is visible.
269+
*
270+
* @return void
271+
*/
272+
public function waitForCheckoutButton()
273+
{
274+
$this->waitForElementVisible($this->inContextPaypalCheckoutButton);
275+
}
265276
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/* eslint-disable max-nested-callbacks */
7+
define([
8+
'squire',
9+
'jquery'
10+
], function (Squire, $) {
11+
'use strict';
12+
13+
describe('Magento_Paypal/js/in-context/express-checkout', function () {
14+
15+
var model,
16+
event,
17+
paypalExpressCheckout,
18+
injector = new Squire(),
19+
mocks = {
20+
'paypalInContextExpressCheckout': {
21+
checkout: jasmine.createSpyObj('checkout',
22+
['setup', 'initXO', 'startFlow', 'closeFlow']
23+
)
24+
}
25+
};
26+
27+
/**
28+
* Run before each test method
29+
*
30+
* @return void
31+
*/
32+
beforeEach(function (done) {
33+
event = {
34+
/** Stub */
35+
preventDefault: jasmine.createSpy('preventDefault')
36+
};
37+
38+
injector.mock(mocks);
39+
40+
injector.require([
41+
'paypalInContextExpressCheckout',
42+
'Magento_Paypal/js/in-context/express-checkout'], function (PayPal, Constr) {
43+
paypalExpressCheckout = PayPal;
44+
model = new Constr();
45+
46+
done();
47+
});
48+
});
49+
50+
describe('clientConfig.click method', function () {
51+
52+
it('Check for properties defined ', function () {
53+
expect(model.hasOwnProperty('clientConfig')).toBeDefined();
54+
expect(model.clientConfig.hasOwnProperty('click')).toBeDefined();
55+
expect(model.clientConfig.hasOwnProperty('checkoutInited')).toBeDefined();
56+
});
57+
58+
it('Check properties type', function () {
59+
expect(typeof model.clientConfig.checkoutInited).toEqual('boolean');
60+
expect(typeof model.clientConfig.click).toEqual('function');
61+
});
62+
63+
it('Check properties value', function () {
64+
expect(model.clientConfig.checkoutInited).toEqual(false);
65+
});
66+
67+
it('Check call "click" method', function () {
68+
69+
spyOn(jQuery.fn, 'trigger');
70+
spyOn(jQuery, 'get').and.callFake(function () {
71+
var d = $.Deferred();
72+
73+
d.resolve({
74+
'url': true
75+
});
76+
77+
return d.promise();
78+
});
79+
80+
model.clientConfig.click(event);
81+
82+
expect(event.preventDefault).toHaveBeenCalled();
83+
expect(paypalExpressCheckout.checkout.initXO).toHaveBeenCalled();
84+
expect(model.clientConfig.checkoutInited).toEqual(true);
85+
expect(jQuery.get).toHaveBeenCalled();
86+
expect(jQuery('body').trigger).toHaveBeenCalledWith(
87+
jasmine.arrayContaining(['processStart'], ['processStop'])
88+
);
89+
});
90+
});
91+
});
92+
});

0 commit comments

Comments
 (0)