diff --git a/view/frontend/web/js/actions/updatePaypalOrder.js b/view/frontend/web/js/actions/updatePaypalOrder.js index 6d59ac8..0311a19 100755 --- a/view/frontend/web/js/actions/updatePaypalOrder.js +++ b/view/frontend/web/js/actions/updatePaypalOrder.js @@ -29,38 +29,32 @@ define([ } let deliveryMethods = []; - if (selectedShippingMethod) { + + for (let i = 0; i < shippingMethods.length; i++) { + let isSelected = false; + + if (!selectedShippingMethod && i === 0) { + isSelected = true; + } else if (selectedShippingMethod && selectedShippingMethod.label === shippingMethods[i].detail) { + isSelected = true; + } + let method = { - reference: selectedShippingMethod.id, - description: selectedShippingMethod.label, + reference: (i + 1).toString(), + description: shippingMethods[i].detail, type: 'Shipping', amount: { currency: currency, - value: Math.round(selectedShippingMethod.amount.value * 100) + value: Math.round(shippingMethods[i].amount * 100) }, - selected: true + selected: isSelected }; + // Add method object to array. deliveryMethods.push(method); - updateOrderPayload.deliveryMethods = JSON.stringify(deliveryMethods); - } - else { - for (let i = 0; i < shippingMethods.length; i++) { - let method = { - reference: (i + 1).toString(), - description: shippingMethods[i].detail, - type: 'Shipping', - amount: { - currency: currency, - value: Math.round(shippingMethods[i].amount * 100) - }, - selected: i === 0 - }; - // Add method object to array. - deliveryMethods.push(method); - } - updateOrderPayload.deliveryMethods = JSON.stringify(deliveryMethods); } + updateOrderPayload.deliveryMethods = JSON.stringify(deliveryMethods); + return storage.post( updateOrderUrl, JSON.stringify(updateOrderPayload) diff --git a/view/frontend/web/js/paypal_express/button.js b/view/frontend/web/js/paypal_express/button.js index cbff53c..86b2e95 100755 --- a/view/frontend/web/js/paypal_express/button.js +++ b/view/frontend/web/js/paypal_express/button.js @@ -514,6 +514,9 @@ define([ let shippingMethods = []; + // Reset the selected shipping method after getting available shipping methods every time. + this.shippingMethod = null; + for (let method of result) { if (typeof method.method_code !== 'string') { continue;