Skip to content

Commit 2f08bcd

Browse files
author
Denys Rul
committed
MAGETWO-33936: Checkout scripts to eliminate (6 script)
- Move initialization of mage.accordion to dependant component
1 parent db05015 commit 2f08bcd

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

app/code/Magento/Checkout/view/frontend/templates/onepage.phtml

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ $_paymentBlock = $block->getLayout()->getBlock('checkout.onepage.payment');
1111
?>
1212

1313
<div class="opc-wrapper">
14-
<ol class="opc" id="checkoutSteps">
14+
<ol class="opc"
15+
id="checkoutSteps"
16+
data-accordion='{
17+
"collapsibleElement": " > li",
18+
"openedState": "active"
19+
}'
20+
data-mage-init='{
21+
"opcOrderReview": {
22+
"checkoutAgreements": "#checkout-agreements",
23+
"checkoutProgressContainer": "#checkout-progress-wrapper",
24+
"methodDescription": ".items"
25+
}
26+
}'>
1527
<?php $i = 0; foreach ($block->getSteps() as $_stepId => $_stepInfo): ?>
1628
<?php if (!$block->getChildBlock($_stepId) || !$block->getChildBlock($_stepId)->isShow()): continue; endif; $i++ ?>
1729
<li id="opc-<?php echo $_stepId ?>" class="section<?php echo !empty($_stepInfo['allow']) ? ' allow' : '' ?><?php echo !empty($_stepInfo['complete']) ? ' saved' : '' ?>">
@@ -25,36 +37,11 @@ $_paymentBlock = $block->getLayout()->getBlock('checkout.onepage.payment');
2537
</li>
2638
<?php endforeach ?>
2739
</ol>
28-
<script>
29-
require([
30-
"underscore",
31-
"accordion",
32-
"opcOrderReview",
33-
], function(_, accordion, opcOrderReview){
34-
'use strict';
35-
36-
/**
37-
* @todo refactor opcCheckoutMethod
38-
*
39-
* Initializiation of this components can't be moved to a data-mage-init attribute
40-
* due to dependencies between instances of opcCheckoutMethod and mage.accordion.
41-
* Thus initializiation has to be synchronyous.
42-
*/
43-
var elem = document.getElementById('checkoutSteps'),
44-
opcConfig;
45-
46-
opcConfig = _.extend({
47-
'checkoutAgreements': '#checkout-agreements',
48-
'checkoutProgressContainer': '#checkout-progress-wrapper',
49-
'methodDescription': '.items'
50-
},<?php echo $this->helper('Magento\Core\Helper\Data')->jsonEncode($_paymentBlock->getOptions()); ?>);
51-
52-
accordion({
53-
'collapsibleElement': ' > li',
54-
'openedState': 'active'
55-
}, elem);
56-
57-
opcOrderReview(opcConfig, elem);
58-
});
59-
</script>
40+
<script type="text/x-magento-init">
41+
{
42+
"#checkoutSteps": {
43+
"opcOrderReview": <?php echo $this->helper('Magento\Core\Helper\Data')->jsonEncode($_paymentBlock->getOptions()); ?>
44+
}
45+
}
46+
</script>
6047
</div>

app/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
/*global alert*/
99
define([
1010
"jquery",
11+
"accordion",
1112
"jquery/ui",
1213
"mage/validation/validation",
1314
"mage/translate"
14-
], function($){
15+
], function($, accordion){
1516
'use strict';
1617

1718
// Base widget, handle ajax events and first section(Checkout Method) in one page checkout accordion
@@ -43,9 +44,13 @@ define([
4344

4445
_create: function() {
4546
var self = this;
47+
48+
this._initAccordion();
49+
4650
this.sectionActiveClass = this.element.accordion("option","openedState");
4751
this.contentSelector = this.element.accordion("option","content");
4852
this.checkoutPrice = this.options.quoteBaseGrandTotal;
53+
4954
if (this.options.checkout.suggestRegistration) {
5055
$(this.options.checkout.loginGuestSelector).prop('checked', false);
5156
$(this.options.checkout.loginRegisterSelector).prop('checked', true);
@@ -96,6 +101,12 @@ define([
96101
});
97102
},
98103

104+
_initAccordion: function(){
105+
var config = this.element.data('accordion');
106+
107+
accordion(config, this.element[0]);
108+
},
109+
99110
/**
100111
* Get the checkout steps, disable steps but first, adding callback on before opening section to
101112
* disable all next steps

0 commit comments

Comments
 (0)