Skip to content

Commit 95ca27a

Browse files
author
Volodymyr Zaets
committed
Merge remote-tracking branch 'origin/MAGETWO-44289' into PR
2 parents b1d760f + e2d72db commit 95ca27a

File tree

10 files changed

+238
-119
lines changed

10 files changed

+238
-119
lines changed

app/code/Magento/Braintree/view/frontend/web/js/button/braintree-paypal.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,29 @@ define([
77
'Magento_Braintree/js/button/builder',
88
'Magento_Braintree/js/button/action/get-data',
99
'Magento_Customer/js/customer-data',
10-
'Magento_Ui/js/lib/view/utils/dom-observer'
11-
], function ($, builder, actionGetData, customerData, domObserver) {
10+
'Magento_Ui/js/lib/view/utils/dom-observer',
11+
'mageUtils'
12+
], function ($, builder, actionGetData, customerData, domObserver, utils) {
1213
'use strict';
1314

14-
return function (config) {
15+
/**
16+
* Ensure that several widget initializations that share common template
17+
* will provide uniqueIds
18+
*
19+
* @param {Object} config
20+
* @param {HTMLElement} element
21+
*/
22+
var ensureUniqueIds = function (config, element) {
23+
var id = utils.uniqueid();
24+
25+
config.containerId += id;
26+
config.options.container += id;
27+
element.id += id;
28+
config.detailsId += id;
29+
config.paymentId += id;
30+
};
1531

32+
return function (config, element) {
1633
var button = {
1734
isClick: false,
1835

@@ -96,8 +113,11 @@ define([
96113
}
97114
};
98115

99-
$(config.containerId).on('mousedown', button.mousedown.bind(button));
100-
$(config.containerId).on('click', button.click.bind(button));
116+
ensureUniqueIds(config, element);
117+
118+
$(element)
119+
.on('mousedown', button.mousedown.bind(button))
120+
.on('click', button.click.bind(button));
101121

102122
customerData.get('cart')
103123
.subscribe(function () {

app/code/Magento/Catalog/view/base/templates/product/price/tier_prices.phtml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ $product = $block->getSaleableItem();
2222
<?php foreach ($tierPrices as $index => $price) : ?>
2323
<li class="item">
2424
<?php
25-
$popupId = 'msrp-popup-' . $product->getId() . $block->getRandomString(20);
25+
$productId = $product->getId();
26+
$popupId = 'msrp-popup-' . $productId . $block->getRandomString(20);
2627
if ($msrpShowOnGesture && $price['price']->getValue() < $product->getMsrp()):
2728
$addToCartUrl = '';
2829
if ($product->isSaleable()) {
@@ -87,9 +88,13 @@ $product = $block->getSaleableItem();
8788
{
8889
".product-info-main": {
8990
"addToCart": {
91+
"origin": "tier",
92+
"addToCartButton": "#product_addtocart_form [type=submit]",
9093
"inputQty": "#qty",
9194
"attr": "[data-tier-price]",
92-
"productForm": "#product_addtocart_form"
95+
"productForm": "#product_addtocart_form",
96+
"productId": "<?php /* @escapeNotVerified */ echo $productId; ?>",
97+
"productIdInput": "input[type=hidden][name=product]"
9398
}
9499
}
95100
}

app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,23 @@ if ($product->isSaleable()) {
5454
$priceElementId = $priceElementIdPrefix . $productId . $block->getIdSuffix();
5555
$popupId = 'msrp-popup-' . $productId . $block->getRandomString(20);
5656
$data = ['addToCart' => [
57+
'origin'=> 'msrp',
5758
'popupId' => '#' . $popupId,
5859
'productName' => $product->getName(),
60+
'productId' => $productId,
61+
'productIdInput' => 'input[type="hidden"][name="product"]',
5962
'realPrice' => $block->getRealPriceHtml(),
6063
'msrpPrice' => $msrpPrice,
6164
'priceElementId' => $priceElementId,
6265
'closeButtonId' => '#map-popup-close',
63-
'popupCartButtonId' => '#map-popup-button',
6466
'addToCartUrl' => $addToCartUrl,
67+
'paymentButtons' => '[data-label=or]'
6568
]];
6669
if ($block->getRequest()->getFullActionName() === 'catalog_product_view') {
6770
$data['addToCart']['addToCartButton'] = '#product_addtocart_form [type=submit]';
6871
} else {
69-
$data['addToCart']['cartForm'] = sprintf(
70-
'form:has(input[type="hidden"][name="product"][value="%s"])',
72+
$data['addToCart']['addToCartButton'] = sprintf(
73+
'form:has(input[type="hidden"][name="product"][value="%s"]) button[type="submit"]',
7174
(int) $productId
7275
);
7376
}
@@ -76,7 +79,7 @@ if ($product->isSaleable()) {
7679
<a href="#"
7780
id="<?php /* @escapeNotVerified */ echo($popupId);?>"
7881
class="action map-show-info"
79-
data-mage-init="<?=$block->escapeHtml($this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($data))?>"><?php /* @escapeNotVerified */ echo __('Click for price'); ?>
82+
data-mage-init='<?=$this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($data)?>'><?php /* @escapeNotVerified */ echo __('Click for price'); ?>
8083
</a>
8184
<?php else: ?>
8285
<span class="msrp-message">
@@ -89,7 +92,8 @@ if ($product->isSaleable()) {
8992
<a href="#"
9093
id="<?php /* @escapeNotVerified */ echo $helpLinkId;?>"
9194
class="action map-show-info"
92-
data-mage-init='{"addToCart":{"helpLinkId": "#<?php /* @escapeNotVerified */ echo $helpLinkId;?>",
95+
data-mage-init='{"addToCart":{"origin": "info",
96+
"helpLinkId": "#<?php /* @escapeNotVerified */ echo $helpLinkId;?>",
9397
"productName": "<?php /* @escapeNotVerified */ echo $product->getName() ?>",
9498
"closeButtonId": "#map-popup-close"}}'><span><?php /* @escapeNotVerified */ echo __("What's this?"); ?></span>
9599
</a>

app/code/Magento/Msrp/view/base/web/js/msrp.js

Lines changed: 142 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define([
88
'jquery/ui',
99
'mage/dropdown',
1010
'mage/template'
11-
], function ($, _) {
11+
], function ($) {
1212
'use strict';
1313

1414
$.widget('mage.addToCart', {
@@ -18,23 +18,24 @@ define([
1818
singleOpenDropDown: true,
1919
dialog: {}, // Options for mage/dropdown
2020
dialogDelay: 500, // Delay in ms after resize dropdown shown again
21+
origin: '', //Required, type of popup: 'msrp', 'tier' or 'info' popup
2122

2223
// Selectors
2324
cartForm: '.form.map.checkout',
2425
msrpLabelId: '#map-popup-msrp',
2526
priceLabelId: '#map-popup-price',
2627
popUpAttr: '[data-role=msrp-popup-template]',
27-
cartButtonId: '', // better to be cartButton
28-
popupId: '', // better to be popup
28+
popupCartButtonId: '#map-popup-button',
29+
paypalCheckoutButons: '[data-action=checkout-form-submit]',
30+
popupId: '',
2931
realPrice: '',
3032
msrpPrice: '',
31-
helpLinkId: '', // better to be helpLink
33+
helpLinkId: '',
3234
addToCartButton: '',
3335

3436
// Text options
3537
productName: '',
3638
addToCartUrl: ''
37-
3839
},
3940

4041
openDropDown: null,
@@ -62,61 +63,149 @@ define([
6263
* @private
6364
*/
6465
_create: function () {
65-
var tierOptions;
66-
67-
this.popupDOM = $(this.options.popUpAttr)[0];
68-
this.infoPopupDOM = $('[data-role=msrp-info-template]')[0];
69-
70-
if (this.options.popupId) {
71-
$('body').append($(this.popupDOM).html());
72-
this.$popup = $($(this.popupDOM).html());
73-
74-
$(this.options.popupId).on('click', function (e) {
75-
this.popUpOptions.position.of = $(e.target);
76-
this.$popup.find(this.options.msrpLabelId).html(this.options.msrpPrice);
77-
this.$popup.find(this.options.priceLabelId).html(this.options.realPrice);
78-
this.$popup.dropdownDialog(this.popUpOptions).dropdownDialog('open');
79-
80-
this.$popup.find('button').on('click', function () {
81-
if (this.options.addToCartButton) {
82-
$(this.options.addToCartButton).click();
83-
}
84-
}.bind(this));
85-
this._toggle(this.$popup);
86-
}.bind(this));
66+
if (this.options.origin === 'msrp') {
67+
this.initMsrpPopup();
68+
} else if (this.options.origin === 'info') {
69+
this.initInfoPopup();
70+
} else if (this.options.origin === 'tier') {
71+
this.initTierPopup();
8772
}
73+
},
74+
75+
/**
76+
* Init msrp popup
77+
* @private
78+
*/
79+
initMsrpPopup: function () {
80+
var popupDOM = $(this.options.popUpAttr)[0],
81+
$msrpPopup = $($(popupDOM).html()).clone();
8882

89-
if (this.options.helpLinkId) {
90-
this.$infoPopup = $(this.infoPopupDOM.innerText).appendTo('body');
91-
$(this.options.helpLinkId).on('click', function (e) {
92-
this.popUpOptions.position.of = $(e.target);
93-
this.$infoPopup.dropdownDialog(this.popUpOptions).dropdownDialog('open');
94-
this._toggle(this.$infoPopup);
95-
}.bind(this));
83+
$msrpPopup.find(this.options.productIdInput).val(this.options.productId);
84+
$('body').append($msrpPopup);
85+
$msrpPopup.trigger('contentUpdated');
86+
87+
$msrpPopup.find('button').on('click', function (ev) {
88+
ev.preventDefault();
89+
this.handleMsrpAddToCart();
90+
}.bind(this));
91+
92+
$msrpPopup.find(this.options.paypalCheckoutButons).on('click',
93+
this.handleMsrpPaypalCheckout.bind(this));
94+
95+
$(this.options.popupId).on('click', function (e) {
96+
this.popUpOptions.position.of = $(e.target);
97+
$msrpPopup.find(this.options.msrpLabelId).html(this.options.msrpPrice);
98+
$msrpPopup.find(this.options.priceLabelId).html(this.options.realPrice);
99+
$msrpPopup.dropdownDialog(this.popUpOptions).dropdownDialog('open');
100+
this._toggle($msrpPopup);
101+
}.bind(this));
102+
103+
this.$popup = $msrpPopup;
104+
},
105+
106+
/**
107+
* Init info popup
108+
* @private
109+
*/
110+
initInfoPopup: function () {
111+
var infoPopupDOM = $('[data-role=msrp-info-template]')[0],
112+
$infoPopup = $(infoPopupDOM.innerText).appendTo('body');
113+
114+
$(this.options.helpLinkId).on('click', function (e) {
115+
this.popUpOptions.position.of = $(e.target);
116+
$infoPopup.dropdownDialog(this.popUpOptions).dropdownDialog('open');
117+
this._toggle($infoPopup);
118+
}.bind(this));
119+
120+
this.$popup = $infoPopup;
121+
},
122+
123+
/**
124+
* Init tier price popup
125+
* @private
126+
*/
127+
initTierPopup: function () {
128+
var tierOptions = JSON.parse($(this.options.attr).attr('data-tier-price')),
129+
popupDOM = $(this.options.popUpAttr)[0],
130+
$tierPopup = $(popupDOM.innerText).appendTo('body');
131+
132+
$tierPopup.find(this.options.productIdInput).val(this.options.productId);
133+
this.popUpOptions.position.of = $(this.options.helpLinkId);
134+
135+
$tierPopup.find('button').on('click', function (ev) {
136+
ev.preventDefault();
137+
this.handleTierAddToCart(tierOptions);
138+
}.bind(this));
139+
140+
$tierPopup.find(this.options.paypalCheckoutButons).on('click', function () {
141+
this.handleTierPaypalCheckout(tierOptions);
142+
}.bind(this));
143+
144+
$(this.options.attr).on('click', function (e) {
145+
this.popUpOptions.position.of = $(e.target);
146+
$tierPopup.find(this.options.msrpLabelId).html(tierOptions.msrp);
147+
$tierPopup.find(this.options.priceLabelId).html(tierOptions.price);
148+
$tierPopup.dropdownDialog(this.popUpOptions).dropdownDialog('open');
149+
this._toggle($tierPopup);
150+
}.bind(this));
151+
152+
this.$popup = $tierPopup;
153+
},
154+
155+
/**
156+
* handle 'AddToCart' click on Msrp popup
157+
*
158+
* @private
159+
*/
160+
handleMsrpAddToCart: function () {
161+
if (this.options.addToCartButton) {
162+
$(this.options.addToCartButton).click();
163+
this.closePopup(this.$popup);
164+
}
165+
},
166+
167+
/**
168+
* handle 'paypal checkout buttons' click on Msrp popup
169+
*
170+
* @private
171+
*/
172+
handleMsrpPaypalCheckout: function () {
173+
this.closePopup(this.$popup);
174+
},
175+
176+
/**
177+
* handle 'AddToCart' click on Tier popup
178+
*
179+
* @param {Object} tierOptions
180+
* @private
181+
*/
182+
handleTierAddToCart: function (tierOptions) {
183+
if (this.options.addToCartButton &&
184+
this.options.inputQty && !isNaN(tierOptions.qty)
185+
) {
186+
$(this.options.inputQty).val(tierOptions.qty);
187+
$(this.options.addToCartButton).click();
188+
this.closePopup(this.$popup);
96189
}
190+
},
97191

98-
if (this.options.attr) {
99-
this.popupDOM = $(this.options.popUpAttr)[0];
100-
this.$popup = $(this.popupDOM.innerText).appendTo('body');
101-
this.popUpOptions.position.of = $(this.options.helpLinkId);
102-
$(this.options.attr).on('click', function (e) {
103-
this.popUpOptions.position.of = $(e.target);
104-
tierOptions = JSON.parse($(e.target).attr('data-tier-price'));
105-
this.$popup.find(this.options.msrpLabelId).html(tierOptions.msrp);
106-
this.$popup.find(this.options.priceLabelId).html(tierOptions.price);
107-
this.$popup.find('button').on('click', function (e) {
108-
e.preventDefault();
109-
this.$popup.find('form').attr('action', tierOptions.addToCartUrl).submit();
110-
}.bind(this));
111-
this.$popup.dropdownDialog(this.popUpOptions).dropdownDialog('open');
112-
this._toggle(this.$popup);
113-
}.bind(this));
192+
/**
193+
* handle 'paypal checkout buttons' click on Tier popup
194+
*
195+
* @param {Object} tierOptions
196+
* @private
197+
*/
198+
handleTierPaypalCheckout: function (tierOptions) {
199+
if (this.options.inputQty && !isNaN(tierOptions.qty)
200+
) {
201+
$(this.options.inputQty).val(tierOptions.qty);
202+
this.closePopup(this.$popup);
114203
}
115204
},
116205

117206
/**
118207
*
119-
* @param $elem
208+
* @param {HTMLElement} $elem
120209
* @private
121210
*/
122211
_toggle: function ($elem) {
@@ -127,12 +216,12 @@ define([
127216
}.bind(this));
128217
$(window).on('resize', function () {
129218
this.closePopup($elem);
130-
}.bind(this))
219+
}.bind(this));
131220
},
132221

133222
/**
134223
*
135-
* @param $elem
224+
* @param {HTMLElement} $elem
136225
*/
137226
closePopup: function ($elem) {
138227
$elem.dropdownDialog('close');

app/code/Magento/Paypal/Observer/AddPaypalShortcutsObserver.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ public function execute(EventObserver $observer)
4949
/** @var \Magento\Catalog\Block\ShortcutButtons $shortcutButtons */
5050
$shortcutButtons = $observer->getEvent()->getContainer();
5151
$blocks = [
52-
'Magento\Paypal\Block\Express\ShortcutContainer' => PaypalConfig::METHOD_WPP_EXPRESS,
53-
'Magento\Paypal\Block\WpsExpress\ShortcutContainer' => PaypalConfig::METHOD_WPS_EXPRESS,
5452
'Magento\Paypal\Block\Express\Shortcut' => PaypalConfig::METHOD_WPP_EXPRESS,
5553
'Magento\Paypal\Block\WpsExpress\Shortcut' => PaypalConfig::METHOD_WPS_EXPRESS,
5654
'Magento\Paypal\Block\PayflowExpress\Shortcut' => PaypalConfig::METHOD_WPP_PE_EXPRESS,
57-
'Magento\Paypal\Block\PayflowExpress\ShortcutContainer' => PaypalConfig::METHOD_WPP_PE_EXPRESS,
5855
'Magento\Paypal\Block\Bml\Shortcut' => PaypalConfig::METHOD_WPP_EXPRESS,
5956
'Magento\Paypal\Block\WpsBml\Shortcut' => PaypalConfig::METHOD_WPS_EXPRESS,
6057
'Magento\Paypal\Block\Payflow\Bml\Shortcut' => PaypalConfig::METHOD_WPP_PE_EXPRESS

app/code/Magento/Paypal/Test/Unit/Observer/AddPaypalShortcutsObserverTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,10 @@ public function testAddPaypalShortcuts($paymentMethodsAvailability, $blocks)
108108
public function addAvailabilityOfMethodsDataProvider()
109109
{
110110
$blocks = [
111-
'Magento\Paypal\Block\Express\ShortcutContainer' =>
112-
['Magento\Paypal\Block\Express\Shortcut', \Magento\Paypal\Model\Config::METHOD_WPP_EXPRESS],
113111
'Magento\Paypal\Block\Express\Shortcut' =>
114112
['Magento\Paypal\Block\Express\Shortcut', \Magento\Paypal\Model\Config::METHOD_WPP_EXPRESS],
115113
'Magento\Paypal\Block\PayflowExpress\Shortcut' =>
116114
['Magento\Paypal\Block\Express\Shortcut', \Magento\Paypal\Model\Config::METHOD_WPP_PE_EXPRESS],
117-
'Magento\Paypal\Block\PayflowExpress\ShortcutContainer' =>
118-
['Magento\Paypal\Block\Express\Shortcut', \Magento\Paypal\Model\Config::METHOD_WPP_PE_EXPRESS],
119115
'Magento\Paypal\Block\Bml\Shortcut' =>
120116
['Magento\Paypal\Block\Bml\Shortcut', \Magento\Paypal\Model\Config::METHOD_WPP_EXPRESS],
121117
'Magento\Paypal\Block\Payflow\Bml\Shortcut' =>

0 commit comments

Comments
 (0)