Skip to content

Commit 526199f

Browse files
author
Jan Polak
committed
oto display order info in confirmation
1 parent 44b12c6 commit 526199f

File tree

3 files changed

+69
-24
lines changed

3 files changed

+69
-24
lines changed

app/code/Magento/OneTouchOrdering/Controller/Button/Available.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ public function execute()
6565
}
6666
$customer = $this->customerSession->getCustomer();
6767
$available = $this->oneTouchOrdering->isAvailableForCustomer($customer);
68-
$resultData['available'] = $available;
69-
$resultData['cards'] = $this->customerCardsFormatter->getFormattedCards($customer);
70-
if ($this->oneTouchOrderingConfig->isSelectAddressEnabled()) {
71-
$resultData += [
72-
'addresses' => $this->customerAddressesFormatter->getFormattedAddresses($customer),
73-
'defaultAddress' => $customer->getDefaultShippingAddress()->getId()
74-
];
75-
}
68+
$resultData = [
69+
'available' => $available,
70+
'cards' => $this->customerCardsFormatter->getFormattedCards($customer),
71+
'addresses' => $this->customerAddressesFormatter->getFormattedAddresses($customer),
72+
'defaultShipping' => $customer->getDefaultShippingAddress()->getId(),
73+
'defaultBilling' => $customer->getDefaultBillingAddress()->getId(),
74+
'selectAddressAvailable' => $this->oneTouchOrderingConfig->isSelectAddressEnabled()
75+
];
76+
7677
$result->setData($resultData);
7778

7879
return $result;

app/code/Magento/OneTouchOrdering/view/frontend/web/js/view/one-touch-order.js

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ define(
88
'jquery',
99
'Magento_Customer/js/customer-data',
1010
'mage/url',
11+
'mage/template',
12+
'underscore',
1113
'jquery/ui',
1214
'mage/translate'
1315
], function (
@@ -16,12 +18,16 @@ define(
1618
confirm,
1719
$,
1820
customerData,
19-
urlBuilder
21+
urlBuilder,
22+
mageTemplate,
23+
_
2024
) {
2125
'use strict';
2226

2327
return Component.extend({
2428
showButton: ko.observable(false),
29+
currentCard: ko.observable(null),
30+
currentShipping: ko.observable(null),
2531
defaults: {
2632
template: 'Magento_OneTouchOrdering/one-touch-order',
2733
buttonText: $.mage.__('One Touch Ordering')
@@ -31,7 +37,16 @@ define(
3137
formSelector: '#product_addtocart_form',
3238
addresses: ko.observable([]),
3339
cards: ko.observable([]),
34-
defaultAddress: ko.observable(0)
40+
selectAddressAvailable: ko.observable(false),
41+
defaultBilling: ko.observable(0),
42+
defaultShipping: ko.observable(0),
43+
confirmTemplate: '<p class="message"><%- data.message %></p>' +
44+
'<strong>' + $.mage.__('Shipping Address') + ':</strong>' +
45+
'<p><%- data.shippingAddress %></p>' +
46+
'<strong>' + $.mage.__('Billing Address') + ':</strong>' +
47+
'<p><%- data.billingAddress %></p>' +
48+
'<strong>' + $.mage.__('Credit Card') + ':</strong>\n' +
49+
'<p><%- data.creditCard %></p>'
3550
},
3651

3752
/** @inheritdoc */
@@ -42,32 +57,61 @@ define(
4257
$.get(urlBuilder.build('onetouchorder/button/available')).done(function (data) {
4358
if (typeof data.available !== 'undefined') {
4459
self.showButton(data.available);
45-
}
46-
47-
if (typeof data.addresses !== 'undefined' && typeof data.defaultAddress !== 'undefined') {
48-
self.options.addresses(data.addresses);
49-
self.options.defaultAddress(data.defaultAddress);
50-
}
51-
52-
if (typeof data.cards !== 'undefined') {
5360
self.options.cards(data.cards);
61+
self.currentCard(_.first(data.cards)['card']);
62+
self.options.addresses(data.addresses);
63+
self.options.defaultShipping(data.defaultShipping);
64+
self.options.selectAddressAvailable(data.selectAddressAvailable);
65+
self.options.defaultBilling(
66+
_.find(data.addresses, function(obj) { return obj.id === data.defaultBilling})['address']
67+
);
68+
self.currentShipping(
69+
_.find(data.addresses, function(obj) { return obj.id === data.defaultShipping})['address']
70+
);
5471
}
5572
});
5673
},
5774

75+
/**
76+
* Change shipping method
77+
*/
78+
changeShipping: function (object, event) {
79+
this.currentShipping(
80+
_.find(this.options.addresses(), function(obj) { return obj.id === event.target.value})['address']
81+
);
82+
},
83+
84+
/**
85+
* Change credit card method
86+
*/
87+
changeCc: function (object, event) {
88+
this.currentCard(
89+
_.find(this.options.cards(), function(obj) { return obj.id === event.target.value})['card']
90+
);
91+
},
92+
5893
/**
5994
* Confirmation method
6095
*/
6196
oneTouchOrder: function () {
6297
var self = this,
63-
form = $(self.options.formSelector);
98+
form = $(self.options.formSelector),
99+
confirmTemplate = mageTemplate(this.options.confirmTemplate);
64100

65101
if (!(form.validation() && form.validation('isValid'))) {
66102
return;
67103
}
68-
69104
confirm({
70-
content: self.options.message,
105+
content: confirmTemplate(
106+
{
107+
data: {
108+
message: self.options.message,
109+
shippingAddress: self.currentShipping(),
110+
billingAddress: self.options.defaultBilling(),
111+
creditCard: self.currentCard()
112+
}
113+
}
114+
),
71115
actions: {
72116
/** @inheritdoc */
73117
confirm: function () {

app/code/Magento/OneTouchOrdering/view/frontend/web/template/one-touch-order.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
<div class="field">
1111
<label for="address-selector"><!-- ko i18n: 'Select shipping address' --><!-- /ko -->:</label>
1212
<select name="customer_address" id="address-selector"
13-
data-bind="options: options.addresses, optionsText: 'address', optionsValue: 'id', value: options.defaultAddress">
13+
data-bind="options: options.addresses, optionsText: 'address', optionsValue: 'id', value: options.defaultShipping, event: {change: changeShipping}">
1414
</select>
1515
</div>
1616
<!-- /ko -->
1717

18-
<!-- ko if: options.cards().length > 0 -->
18+
<!-- ko if: options.selectAddressAvailable() -->
1919
<div class="field">
2020
<label for="address-selector"><!-- ko i18n: 'Select credit card' --><!-- /ko -->:</label>
2121
<select name="customer_cc" id="cc-selector"
22-
data-bind="options: options.cards, optionsText: 'card', optionsValue: 'id'">
22+
data-bind="options: options.cards, optionsText: 'card', optionsValue: 'id', event: {change: changeCc}">
2323
</select>
2424
</div>
2525
<!-- /ko -->

0 commit comments

Comments
 (0)