|
7 | 7 | */ |
8 | 8 | /*global define*/ |
9 | 9 | define( |
10 | | - [ |
11 | | - 'Magento_Checkout/js/view/shipping', |
12 | | - 'jquery', |
13 | | - 'Magento_Checkout/js/model/quote', |
14 | | - 'Magento_Checkout/js/model/full-screen-loader', |
15 | | - 'buttonConfig', |
16 | | - ], |
17 | | - function (Shipping, $, quote, fullScreenLoader, button) { |
18 | | - 'use strict'; |
19 | | - return Shipping.extend( |
20 | | - { |
21 | | - setShippingInformation: function () { |
22 | | - /** |
23 | | - * Call parent method |
24 | | - */ |
25 | | - Shipping.prototype.setShippingInformation.call(this); |
| 10 | + [ |
| 11 | + 'Magento_Checkout/js/view/shipping', |
| 12 | + 'jquery', |
| 13 | + 'Magento_Checkout/js/model/quote', |
| 14 | + 'Magento_Checkout/js/model/full-screen-loader', |
| 15 | + 'buttonConfig' |
| 16 | + ], |
| 17 | + function (Shipping, $, quote, fullScreenLoader, button) { |
| 18 | + 'use strict'; |
| 19 | + return Shipping.extend( |
| 20 | + { |
| 21 | + setShippingInformation: function () { |
| 22 | + /** |
| 23 | + * Call parent method |
| 24 | + */ |
| 25 | + Shipping.prototype.setShippingInformation.call(this); |
26 | 26 |
|
27 | | - this.updateConfigData(); |
28 | | - this.invalidateToken(); |
29 | | - this.refreshBreadPaymentMethod(); |
30 | | - }, |
| 27 | + this.updateConfigData(); |
| 28 | + this.invalidateToken(); |
| 29 | + this.refreshBreadPaymentMethod(); |
| 30 | + }, |
31 | 31 |
|
32 | | - /** |
33 | | - * Add updated shipping option data to window.checkoutConfig global variable |
34 | | - * |
35 | | - * @see Bread\BreadCheckout\Model\Ui\ConfigProvider |
36 | | - */ |
37 | | - updateConfigData: function () { |
38 | | - window.checkoutConfig.payment.breadcheckout.breadConfig.shippingOptions = { |
39 | | - type: quote.shippingMethod().carrier_title + ' - ' + quote.shippingMethod().method_title, |
40 | | - typeId: quote.shippingMethod().carrier_code + '_' + quote.shippingMethod().method_code, |
41 | | - cost: this.round(quote.shippingMethod().base_amount) |
42 | | - }; |
43 | | - }, |
| 32 | + /** |
| 33 | + * Add updated shipping option data to window.checkoutConfig global variable |
| 34 | + * |
| 35 | + * @see Bread\BreadCheckout\Model\Ui\ConfigProvider |
| 36 | + */ |
| 37 | + updateConfigData: function () { |
| 38 | + window.checkoutConfig.payment.breadcheckout.breadConfig.shippingOptions = { |
| 39 | + type: quote.shippingMethod().carrier_title + ' - ' + quote.shippingMethod().method_title, |
| 40 | + typeId: quote.shippingMethod().carrier_code + '_' + quote.shippingMethod().method_code, |
| 41 | + cost: this.round(quote.shippingMethod().base_amount) |
| 42 | + }; |
| 43 | + }, |
44 | 44 |
|
45 | | - /** |
46 | | - * Invalidate existing transaction ID (in case user filled out payment |
47 | | - * form and then went back a step) |
48 | | - */ |
49 | | - invalidateToken: function () { |
50 | | - if (window.checkoutConfig.payment.breadcheckout.transactionId !== null) { |
51 | | - window.checkoutConfig.payment.breadcheckout.transactionId = null; |
52 | | - } |
53 | | - }, |
54 | | - |
55 | | - /** |
56 | | - * |
57 | | - * Refresh the payment method section if transactionId is not set |
58 | | - */ |
59 | | - refreshBreadPaymentMethod: function () { |
60 | | - var paymentMethod = quote.paymentMethod(); |
61 | | - if (typeof paymentMethod !== 'undefined') { |
62 | | - if (typeof paymentMethod.method !== 'undefined') { |
63 | | - if (quote.paymentMethod().method === 'breadcheckout' |
64 | | - && window.checkoutConfig.payment.breadcheckout.transactionId === null) { |
65 | | - button.embeddedCheckout(); |
66 | | - } |
67 | | - } |
68 | | - |
69 | | - } |
70 | | - |
71 | | - }, |
72 | | - |
73 | | - /** |
74 | | - * Round float to 2 decimal plates and convert to integer |
75 | | - * |
76 | | - * @param value |
77 | | - * @returns {Number} |
78 | | - */ |
79 | | - round: function (value) { |
80 | | - if (isNaN(value)) { |
81 | | - return 0; |
| 45 | + /** |
| 46 | + * Invalidate existing transaction ID (in case user filled out payment |
| 47 | + * form and then went back a step) |
| 48 | + */ |
| 49 | + invalidateToken: function () { |
| 50 | + if (window.checkoutConfig.payment.breadcheckout.transactionId !== null) { |
| 51 | + window.checkoutConfig.payment.breadcheckout.transactionId = null; |
| 52 | + } |
| 53 | + }, |
| 54 | + |
| 55 | + /** |
| 56 | + * |
| 57 | + * Refresh the payment method section if transactionId is not set |
| 58 | + */ |
| 59 | + refreshBreadPaymentMethod: function () { |
| 60 | + var paymentMethod = quote.paymentMethod(); |
| 61 | + if ( paymentMethod !== null && typeof paymentMethod.method !== 'undefined') { |
| 62 | + if (quote.paymentMethod().method === 'breadcheckout' |
| 63 | + && window.checkoutConfig.payment.breadcheckout.transactionId === null) { |
| 64 | + //Check if embeddedCheckout is enabled |
| 65 | + if(window.checkoutConfig.payment.breadcheckout.breadConfig.embeddedCheckout) { |
| 66 | + button.embeddedCheckout(); |
| 67 | + } else { |
| 68 | + button.init(); |
82 | 69 | } |
83 | | - return parseInt( |
84 | | - Number(Math.round(parseFloat(value) + 'e' + 2) + 'e-' + 2) |
85 | | - * 100 |
86 | | - ); |
87 | 70 | } |
| 71 | + } |
| 72 | + }, |
| 73 | + |
| 74 | + /** |
| 75 | + * Round float to 2 decimal plates and convert to integer |
| 76 | + * |
| 77 | + * @param value |
| 78 | + * @returns {Number} |
| 79 | + */ |
| 80 | + round: function (value) { |
| 81 | + if (isNaN(value)) { |
| 82 | + return 0; |
88 | 83 | } |
89 | | - ); |
90 | | - } |
| 84 | + return parseInt( |
| 85 | + Number(Math.round(parseFloat(value)+'e'+2)+'e-'+2) |
| 86 | + * 100 |
| 87 | + ); |
| 88 | + } |
| 89 | + } |
| 90 | + ); |
| 91 | + } |
91 | 92 | ); |
0 commit comments