Skip to content

Commit

Permalink
Shipping method customer on change fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KiprotichMaritim committed May 26, 2022
1 parent 9db902e commit 4573d42
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 87 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ Installation

## Usage instructions:

See documentation at https://docs.getbread.com
Contact your Bread representative for login credentials.
See documentation at https://docs.breadpayments.com/bread-classic/docs/magento-2
Contact your Bread representative for your merchant credentials.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Offers the Bread financing and checkout tools for your Magento store",
"license": "MIT",
"minimum-stability": "stable",
"version": "1.1.18",
"version": "1.1.19",
"require": {
"php": "~7.0.13||~7.1.0||~7.1.3||~7.2.0||~7.3.0||~7.4.0"
},
Expand Down
155 changes: 71 additions & 84 deletions view/frontend/web/js/view/shipping.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,98 +7,85 @@
*/
/*global define*/
define(
[
'Magento_Checkout/js/view/shipping',
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/full-screen-loader',
'buttonConfig',
],
function (Shipping, $, quote, fullScreenLoader, button) {
'use strict';
return Shipping.extend(
{
setShippingInformation: function () {
/**
* Call parent method
*/
Shipping.prototype.setShippingInformation.call(this);
[
'Magento_Checkout/js/view/shipping',
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/full-screen-loader',
'buttonConfig',
],
function (Shipping, $, quote, fullScreenLoader, button) {
'use strict';
return Shipping.extend(
{
setShippingInformation: function () {
/**
* Call parent method
*/
Shipping.prototype.setShippingInformation.call(this);

this.updateConfigData();
this.invalidateToken();
this.refreshBreadPaymentMethod();
},
this.updateConfigData();
this.invalidateToken();
this.refreshBreadPaymentMethod();
},

/**
* Add updated shipping option data to window.checkoutConfig global variable
*
* @see Bread\BreadCheckout\Model\Ui\ConfigProvider
*/
updateConfigData: function () {
window.checkoutConfig.payment.breadcheckout.breadConfig.shippingOptions = {
type: quote.shippingMethod().carrier_title + ' - ' + quote.shippingMethod().method_title,
typeId: quote.shippingMethod().carrier_code + '_' + quote.shippingMethod().method_code,
cost: this.round(quote.shippingMethod().base_amount)
};
},
/**
* Add updated shipping option data to window.checkoutConfig global variable
*
* @see Bread\BreadCheckout\Model\Ui\ConfigProvider
*/
updateConfigData: function () {
window.checkoutConfig.payment.breadcheckout.breadConfig.shippingOptions = {
type: quote.shippingMethod().carrier_title + ' - ' + quote.shippingMethod().method_title,
typeId: quote.shippingMethod().carrier_code + '_' + quote.shippingMethod().method_code,
cost: this.round(quote.shippingMethod().base_amount)
};
},

/**
* Invalidate existing transaction ID (in case user filled out payment
* form and then went back a step)
*/
invalidateToken: function () {
if (window.checkoutConfig.payment.breadcheckout.transactionId !== null) {
window.checkoutConfig.payment.breadcheckout.transactionId = null;
}
},
/**
*
* Refresh the payment method section if transactionId is not set
*/
refreshBreadPaymentMethod: function () {
/**
* Invalidate existing transaction ID (in case user filled out payment
* form and then went back a step)
*/
invalidateToken: function () {
if (window.checkoutConfig.payment.breadcheckout.transactionId !== null) {
window.checkoutConfig.payment.breadcheckout.transactionId = null;
}
},

/**
*
* Refresh the payment method section if transactionId is not set
*/
refreshBreadPaymentMethod: function () {
var paymentMethod = quote.paymentMethod();
if (typeof paymentMethod.method !== 'undefined' && paymentMethod !== null) {
if (quote.paymentMethod().method === 'breadcheckout'
&& window.checkoutConfig.payment.breadcheckout.transactionId === null) {
button.embeddedCheckout();
if (typeof paymentMethod !== 'undefined') {
if (typeof paymentMethod.method !== 'undefined') {
if (quote.paymentMethod().method === 'breadcheckout'
&& window.checkoutConfig.payment.breadcheckout.transactionId === null) {
button.embeddedCheckout();
}
}

}

},

},

/**
*
* Refresh the payment method section if transactionId is not set
*/
refreshBreadPaymentMethod: function () {
var paymentMethod = quote.paymentMethod();
if ( paymentMethod !== null && typeof paymentMethod.method !== 'undefined') {
if (quote.paymentMethod().method === 'breadcheckout'
&& window.checkoutConfig.payment.breadcheckout.transactionId === null) {
button.embeddedCheckout();
/**
* Round float to 2 decimal plates and convert to integer
*
* @param value
* @returns {Number}
*/
round: function (value) {
if (isNaN(value)) {
return 0;
}
return parseInt(
Number(Math.round(parseFloat(value) + 'e' + 2) + 'e-' + 2)
* 100
);
}
}
},


/**
* Round float to 2 decimal plates and convert to integer
*
* @param value
* @returns {Number}
*/
round: function (value) {
if (isNaN(value)) {
return 0;
}
return parseInt(
Number(Math.round(parseFloat(value)+'e'+2)+'e-'+2)
* 100
);
}
}
);
}
);
}
);

0 comments on commit 4573d42

Please sign in to comment.