Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 5fcde49

Browse files
omiroshnichenkoVolodymyr Kublytskyi
authored and
Volodymyr Kublytskyi
committed
MAGETWO-84321: Instant Purchase button displays only for one store view
1 parent 268b0c9 commit 5fcde49

File tree

4 files changed

+257
-130
lines changed

4 files changed

+257
-130
lines changed
Lines changed: 106 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,115 @@
1-
/*jshint browser:true*/
2-
/*global define*/
3-
define(
4-
[
5-
'uiComponent',
6-
'ko',
7-
'Magento_Ui/js/modal/confirm',
8-
'jquery',
9-
'Magento_Customer/js/customer-data',
10-
'mage/url',
11-
'mage/template',
12-
'jquery/ui',
13-
'mage/translate'
14-
], function (
15-
Component,
16-
ko,
17-
confirm,
18-
$,
19-
customerData,
20-
urlBuilder,
21-
mageTemplate
22-
) {
23-
'use strict';
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'ko',
7+
'jquery',
8+
'underscore',
9+
'uiComponent',
10+
'Magento_Ui/js/modal/confirm',
11+
'Magento_Customer/js/customer-data',
12+
'mage/url',
13+
'mage/template',
14+
'mage/translate',
15+
'text!Magento_InstantPurchase/template/confirmation.html',
16+
'mage/validation'
17+
], function (ko, $, _, Component, confirm, customerData, urlBuilder, mageTemplate, $t, confirmationTemplate) {
18+
'use strict';
2419

25-
return Component.extend({
26-
showButton: ko.observable(false),
27-
paymentToken: ko.observable(null),
28-
shippingAddress: ko.observable(null),
29-
billingAddress: ko.observable(null),
30-
shippingMethod: ko.observable(null),
31-
defaults: {
32-
template: 'Magento_InstantPurchase/instant-purchase',
33-
buttonText: $.mage.__('Instant Purchase'),
34-
purchaseUrl: urlBuilder.build('instantpurchase/button/placeOrder')
35-
},
36-
options: {
37-
message: $.mage.__('Are you sure you want to place order and pay?'),
38-
formSelector: '#product_addtocart_form',
39-
confirmTemplate: '<p class="message"><%- data.message %></p>' +
40-
'<strong>' + $.mage.__('Shipping Address') + ':</strong>' +
41-
'<p><%- data.shippingAddress().summary %></p>' +
42-
'<strong>' + $.mage.__('Billing Address') + ':</strong>' +
43-
'<p><%- data.billingAddress().summary %></p>' +
44-
'<strong>' + $.mage.__('Payment Method') + ':</strong>\n' +
45-
'<p><%- data.paymentToken().summary %></p>' +
46-
'<strong>' + $.mage.__('Shipping Method') + ':</strong>\n' +
47-
'<p><%- data.shippingMethod().summary %></p>'
48-
},
20+
return Component.extend({
21+
defaults: {
22+
template: 'Magento_InstantPurchase/instant-purchase',
23+
buttonText: $t('Instant Purchase'),
24+
purchaseUrl: urlBuilder.build('instantpurchase/button/placeOrder'),
25+
showButton: false,
26+
paymentToken: null,
27+
shippingAddress: null,
28+
billingAddress: null,
29+
shippingMethod: null,
30+
productFormSelector: '#product_addtocart_form',
31+
confirmationTitle: $t('Instant Purchase Confirmation'),
32+
confirmationData: {
33+
message: $t('Are you sure you want to place order and pay?'),
34+
shippingAddressTitle: $t('Shipping Address'),
35+
billingAddressTitle: $t('Billing Address'),
36+
paymentMethodTitle: $t('Payment Method'),
37+
shippingMethodTitle: $t('Shipping Address')
38+
}
39+
},
4940

50-
/** @inheritdoc */
51-
initialize: function () {
52-
var self = this,
53-
data = customerData.get('instant-purchase')();
41+
/** @inheritdoc */
42+
initialize: function () {
43+
var instantPurchase = customerData.get('instant-purchase');
5444

55-
this._super();
56-
self.showButton(data.available);
57-
self.paymentToken(data.paymentToken);
58-
self.shippingAddress(data.shippingAddress);
59-
self.billingAddress(data.billingAddress);
60-
self.shippingMethod(data.shippingMethod);
61-
},
45+
this._super();
6246

63-
/**
64-
* Confirmation method
65-
*/
66-
instantPurchase: function () {
67-
var self = this,
68-
form = $(self.options.formSelector),
69-
confirmTemplate = mageTemplate(this.options.confirmTemplate);
47+
this.setPurchaseData(instantPurchase());
48+
instantPurchase.subscribe(this.setPurchaseData, this);
49+
},
7050

71-
if (!(form.validation() && form.validation('isValid'))) {
72-
return;
73-
}
51+
/** @inheritdoc */
52+
initObservable: function () {
53+
this._super()
54+
.observe('showButton paymentToken shippingAddress billingAddress shippingMethod');
7455

75-
confirm({
76-
title: $.mage.__('Instant Purchase Confirmation'),
77-
content: confirmTemplate(
78-
{
79-
data: {
80-
message: self.options.message,
81-
paymentToken: self.paymentToken,
82-
shippingAddress: self.shippingAddress,
83-
billingAddress: self.billingAddress,
84-
shippingMethod: self.shippingMethod
85-
}
86-
}
87-
),
88-
actions: {
89-
/** @inheritdoc */
90-
confirm: function () {
91-
$.ajax({
92-
url: self.purchaseUrl,
93-
data: form.serialize(),
94-
type: 'post',
95-
dataType: 'json',
56+
return this;
57+
},
9658

97-
/** Show loader before send */
98-
beforeSend: function () {
99-
$('body').trigger('processStart');
100-
}
101-
}).always(function () {
102-
$('body').trigger('processStop');
103-
});
104-
}
105-
}
59+
/**
60+
* Set data from customerData.
61+
*
62+
* @param {Object} data
63+
*/
64+
setPurchaseData: function (data) {
65+
this.showButton(data.available);
66+
this.paymentToken(data.paymentToken);
67+
this.shippingAddress(data.shippingAddress);
68+
this.billingAddress(data.billingAddress);
69+
this.shippingMethod(data.shippingMethod);
70+
},
71+
72+
/**
73+
* Confirmation method
74+
*/
75+
instantPurchase: function () {
76+
var form = $(this.productFormSelector),
77+
confirmTemplate = mageTemplate(confirmationTemplate),
78+
confirmData = _.extend({}, this.confirmationData, {
79+
paymentToken: this.paymentToken().summary,
80+
shippingAddress: this.shippingAddress().summary,
81+
billingAddress: this.billingAddress().summary,
82+
shippingMethod: this.shippingMethod().summary
10683
});
84+
85+
if (!(form.validation() && form.validation('isValid'))) {
86+
return;
10787
}
108-
});
109-
}
110-
);
88+
89+
confirm({
90+
title: this.confirmationTitle,
91+
content: confirmTemplate({
92+
data: confirmData
93+
}),
94+
actions: {
95+
/** @inheritdoc */
96+
confirm: function () {
97+
$.ajax({
98+
url: this.purchaseUrl,
99+
data: form.serialize(),
100+
type: 'post',
101+
dataType: 'json',
102+
103+
/** Show loader before send */
104+
beforeSend: function () {
105+
$('body').trigger('processStart');
106+
}
107+
}).always(function () {
108+
$('body').trigger('processStop');
109+
});
110+
}.bind(this)
111+
}
112+
});
113+
}
114+
});
115+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<p class="message"><%- data.message %></p>
8+
<strong><%- data.shippingAddressTitle %>:</strong>
9+
<p><%- data.shippingAddress %></p>
10+
<strong><%- data.billingAddressTitle %>:</strong>
11+
<p><%- data.billingAddress %></p>
12+
<strong><%- data.paymentMethodTitle %>:</strong>
13+
<p><%- data.paymentToken %></p>
14+
<strong><%- data.shippingMethodTitle %>:</strong>
15+
<p><%- data.shippingMethod %></p>
Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
<!-- ko if: showButton -->
2-
<button type="button"
3-
class="action primary instant-purchase"
4-
data-bind="click: instantPurchase, attr:{title: buttonText}">
5-
<span data-bind="text: buttonText"></span>
6-
</button>
7-
<!-- ko if: paymentToken -->
8-
<input type="hidden"
9-
name="instant_purchase_payment_token"
10-
data-bind="value: paymentToken().publicHash">
11-
<!-- /ko -->
12-
<!-- ko if: shippingAddress -->
13-
<input type="hidden"
14-
name="instant_purchase_shipping_address"
15-
data-bind="value: shippingAddress().id">
16-
<!-- /ko -->
17-
<!-- ko if: billingAddress -->
18-
<input type="hidden"
19-
name="instant_purchase_billing_address"
20-
data-bind="value: billingAddress().id">
21-
<!-- ko if: shippingMethod -->
22-
<input type="hidden"
23-
name="instant_purchase_carrier"
24-
data-bind="value: shippingMethod().carrier">
25-
<input type="hidden"
26-
name="instant_purchase_shipping"
27-
data-bind="value: shippingMethod().method">
28-
<!-- /ko -->
29-
<!-- /ko -->
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<if args="showButton()">
8+
<button type="button"
9+
class="action primary instant-purchase"
10+
click="instantPurchase"
11+
attr="title: $t(buttonText)">
12+
<span translate="buttonText" />
13+
</button>
14+
<input if="paymentToken()"
15+
type="hidden"
16+
name="instant_purchase_payment_token"
17+
ko-value="paymentToken().publicHash" />
18+
<input if="shippingAddress()"
19+
type="hidden"
20+
name="instant_purchase_shipping_address"
21+
ko-value="shippingAddress().id" />
22+
<input if="billingAddress()"
23+
type="hidden"
24+
name="instant_purchase_billing_address"
25+
ko-value="billingAddress().id" />
26+
<if args="shippingMethod()">
27+
<input type="hidden"
28+
name="instant_purchase_carrier"
29+
ko-value="shippingMethod().carrier" />
30+
<input type="hidden"
31+
name="instant_purchase_shipping"
32+
ko-value="shippingMethod().method" />
33+
</if>
34+
</if>

0 commit comments

Comments
 (0)