How to change the shipping cost in the order summary section and store that value in the custom field of the sales order

We can set the value and store in the transaction body field in the sales order by using suitescript .

  try {
                var canadaShipCost = Configuration.get("shipcost.canada");
                var unitedStates = Configuration.get("shipcost.unitedstates");
                var canadaSubtotal = Configuration.get("shipcost.unitedstatesSubtotal");
                var unitedStateSubtotal = Configuration.get("shipcost.canadaSubtotal");
                result.options.custbody_jj_custom_shippingcost = result.addresses[0] && result.addresses[0].country ? 
                 ((result.addresses[0].country === "US" && result.summary.subtotal < canadaSubtotal) ? unitedStates : 
                (result.addresses[0].country === "CA" && result.summary.subtotal < unitedStateSubtotal) ? canadaShipCost : "0") : "0";
                result.summary.estimatedshipping = parseFloat((result.options.custbody_jj_custom_shippingcost));
                result.summary.shippingcost = parseFloat((result.options.custbody_jj_custom_shippingcost));
                result.summary.shippingcost_formatted = Utils.formatCurrency(
                    parseFloat((result.options.custbody_jj_custom_shippingcost))
                );
                result.summary.estimatedshipping_formatted = Utils.formatCurrency(
                    parseFloat((result.options.custbody_jj_custom_shippingcost))
                );
                result.summary.total = result.summary.discountedsubtotal + result.summary.taxtotal + parseFloat(result.options.custbody_jj_custom_shippingcost);
                result.summary.total_formatted = Utils.formatCurrency(result.summary.total);
                    
                if (result.addresses[0] && ((result.addresses[0].country === "US" && result.summary.subtotal < canadaSubtotal) ||
                (result.addresses[0].country === "CA" && result.summary.subtotal < unitedStateSubtotal))) {


                var selectedShippingMethodId = result.shipmethod;


                var selectedShippingMethod = _.find(result.shipmethods, function (data) {
                    return data.internalid === selectedShippingMethodId;
                });


                if (selectedShippingMethod) {
                    selectedShippingMethod.name = "Shipping Cost";
                    selectedShippingMethod.rate_formatted = result.options.custbody_jj_custom_shippingcost;
                }
            }
            } catch (error) {
                console.log('error in the shipping cost update function',JSON.stringify(error));
            }

Leave a comment

Your email address will not be published. Required fields are marked *