Skip to content

Commit 1fc8368

Browse files
author
Denys Rul
committed
MAGETWO-33936: Checkout scripts to eliminate (6 script)
1 parent f191737 commit 1fc8368

File tree

6 files changed

+71
-86
lines changed

6 files changed

+71
-86
lines changed

app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,15 @@
3232
</div>
3333
</fieldset>
3434
</div>
35-
36-
<script>
37-
require([
38-
"jquery",
39-
"mage/mage"
40-
], function($){
41-
42-
var addtocartForm = $('#product_addtocart_form');
43-
addtocartForm.mage('validation');
44-
addtocartForm.mage('addToCart', {
45-
cartButtonId: "#product-updatecart-button",
46-
cartForm: "#product_addtocart_form"
47-
});
48-
49-
});
50-
</script>
35+
<script type="text/x-magento-init">
36+
{
37+
"#product_addtocart_form": {
38+
"validation": {},
39+
"addToCart": {
40+
"cartButtonId": "#product-updatecart-button",
41+
"cartForm": "#product_addtocart_form"
42+
}
43+
}
44+
}
45+
</script>
5146
<?php endif; ?>

app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,17 @@
9292
</div>
9393
<?php endif ?>
9494
<?php endif; ?>
95-
<script>
96-
require([
97-
"jquery",
98-
"mage/mage"
99-
], function($){
100-
"use strict";
101-
$('[data-block="minicart"]').mage('sidebar', {
102-
checkoutUrl: '<?php echo $block->getCheckoutUrl();?>',
103-
checkoutButton: '#top-cart-btn-checkout',
104-
removeButton: '#mini-cart a.action.delete',
105-
confirmMessage: '<?php echo __('Are you sure you would like to remove this item from the shopping cart?') ?>'
106-
});
107-
});
95+
<script type="text/x-magento-init">
96+
{
97+
"[data-block='minicart']": {
98+
"sidebar": {
99+
"checkoutUrl": "<?php echo $block->getCheckoutUrl();?>",
100+
"checkoutButton": "#top-cart-btn-checkout",
101+
"removeButton": "#mini-cart a.action.delete",
102+
"confirmMessage": "<?php echo __('Are you sure you would like to remove this item from the shopping cart?') ?>"
103+
}
104+
}
105+
}
108106
</script>
109107
<?php if ($block->getInList()): ?>
110108
</li>

app/code/Magento/Checkout/view/frontend/templates/cart/shipping.phtml

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,25 @@
5757
</div>
5858
</fieldset>
5959
</form>
60-
<script>
61-
require([
62-
"jquery",
63-
"mage/mage"
64-
], function($){
65-
66-
var $form = $('#shipping-zip-form');
67-
68-
$form.mage('validation');
69-
70-
$('#country').mage('regionUpdater', {
71-
optionalRegionAllowed: <?php echo ($block->getConfig('general/region/display_all')? 'true' : 'false'); ?>,
72-
regionListId: '#region_id',
73-
regionInputId: '#region',
74-
postcodeId: '#postcode',
75-
form: $form,
76-
regionJson: <?php echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
77-
defaultRegion: "<?php echo $block->getEstimateRegionId() ?>",
78-
countriesWithOptionalZip: <?php echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
79-
});
80-
81-
});
82-
</script>
60+
<script type="text/x-magento-init">
61+
{
62+
"#shipping-zip-form": {
63+
"validation": {}
64+
},
65+
"#country": {
66+
"regionUpdater": {
67+
"optionalRegionAllowed": <?php echo ($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
68+
"regionListId": "#region_id",
69+
"regionInputId": "#region",
70+
"postcodeId": "#postcode",
71+
"form": "#shipping-zip-form",
72+
"regionJson": <?php echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
73+
"defaultRegion": "<?php echo $block->getEstimateRegionId() ?>",
74+
"countriesWithOptionalZip": <?php echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
75+
}
76+
}
77+
}
78+
</script>
8379
<?php if (($_shippingRateGroups = $block->getEstimateRates())): ?>
8480
<form id="co-shipping-method-form" action="<?php echo $block->getUrl('checkout/cart/estimateUpdatePost') ?>">
8581
<fieldset class="fieldset rates">

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,18 @@
194194
<div class="primary"><button data-role="opc-continue" type="button" class="button action continue primary"><span><?php echo __('Continue') ?></span></button></div>
195195
</div>
196196
</form>
197-
<script>
198-
require([
199-
"jquery",
200-
"mage/mage"
201-
], function($){
202-
203-
$('#billing\\:country_id').mage('regionUpdater', {
204-
optionalRegionAllowed: <?php echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
205-
regionListId: '#billing\\\:region_id',
206-
regionInputId: '#billing\\\:region',
207-
postcodeId: '#billing\\\:postcode',
208-
regionJson: <?php echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
209-
defaultRegion: "<?php echo $block->getAddress()->getRegionId() ?>",
210-
countriesWithOptionalZip: <?php echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
211-
});
212-
213-
});
197+
<script type="text/x-magento-init">
198+
{
199+
"#billing\\:country_id": {
200+
"regionUpdater": {
201+
"optionalRegionAllowed": <?php echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
202+
"regionListId": "#billing\\:region_id",
203+
"regionInputId": "#billing\\:region",
204+
"postcodeId": "#billing\\:postcode",
205+
"regionJson": <?php echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
206+
"defaultRegion": "<?php echo $block->getAddress()->getRegionId() ?>",
207+
"countriesWithOptionalZip": <?php echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
208+
}
209+
}
210+
}
214211
</script>

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,18 @@
113113
<div class="secondary"><a href="#" class="action back"><span><?php echo __('Back') ?></span></a></div>
114114
</div>
115115
</form>
116-
<script>
117-
require([
118-
"jquery",
119-
"mage/mage"
120-
], function($){
121-
122-
$('#shipping\\:country_id').mage('regionUpdater', {
123-
optionalRegionAllowed: <?php echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
124-
regionListId: '#shipping\\\:region_id',
125-
regionInputId: '#shipping\\\:region',
126-
postcodeId: '#shipping\\\:postcode',
127-
regionJson: <?php echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
128-
defaultRegion: "<?php echo $block->getAddress()->getRegionId() ?>",
129-
countriesWithOptionalZip: <?php echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
130-
});
131-
132-
});
116+
<script type="text/x-magento-init">
117+
{
118+
"#shipping\\:country_id": {
119+
"regionUpdater": {
120+
"optionalRegionAllowed": <?php echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
121+
"regionListId": "#shipping\\:region_id",
122+
"regionInputId": "#shipping\\:region",
123+
"postcodeId": "#shipping\\:postcode",
124+
"regionJson": <?php echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
125+
"defaultRegion": "<?php echo $block->getAddress()->getRegionId() ?>",
126+
"countriesWithOptionalZip": <?php echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
127+
}
128+
}
129+
}
133130
</script>

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ define([
111111
this.options.form = this.element.closest('form').length ? $(this.element.closest('form')[0]) : null;
112112
}
113113

114+
this.options.form = $(this.options.form);
115+
114116
this.options.form && this.options.form.data('validation') && this.options.form.validation('clearError',
115117
this.options.regionListId, this.options.regionInputId, this.options.postcodeId);
116118
}

0 commit comments

Comments
 (0)