How to pass the value from website to sales order custom field when the SCA version is below Suite Commerce 2021.1

For version suite commerce 2021.1 there is a standard method we can fallow that method.

For both method we need to add the custom field id in the configuration record.

Standard method for version 2021.1

var cart = container.getComponent('Cart');
var data = {
	fieldId: "custbody_customerref",
	type: "string",
	value: "C123456"
}


cart.setTransactionBodyField(data).then(function() {
	console.log(data.fieldId + ' was set to ' + data.value);
}).fail(function(error) {
	console.log('setTransactionBodyField failed.');
});

below version we need to set the value throw live order model that code will be added below

for my scenario i have used the saved search but change according to the need.

define('JJ.SearchContact.SearchContact'
,   [
    'LiveOrder.Model',
    'SC.Model',
    'Application',
    'Profile.Model',
    'StoreItem.Model',
    'SC.Models.Init',
    'SiteSettings.Model',
    'Utils',
    'ExternalPayment.Model',
    'underscore',
    'CustomFields.Utils',
    'Configuration'
    ]
,   function (
    LiveOrderModel,
    SCModel,
    Application,
    Profile,
    StoreItem,
    ModelsInit,
    SiteSettings,
    Utils,
    ExternalPayment,
    _,
    CustomFieldsUtils,
    Configuration
   
    )
{
    'use strict';
    _.extend(LiveOrderModel, {
        get: function get(threedsecure) {
            try {
            var order_fields = this.getFieldValues();
            var result = {};


            // @class LiveOrder.Model.Data object containing high level shopping order object information. Serializeble to JSON and this is the object that the .ss service will serve and so it will poblate front end Model objects
            try {
                // @property {Array<LiveOrder.Model.Line>} lines
                result.lines = this.getLines(order_fields);
            } catch (e) {
                if (e.code === 'ERR_CHK_ITEM_NOT_FOUND') {
                    return this.get();
                }
                throw e;
            }


            order_fields = this.hidePaymentPageWhenNoBalance(order_fields);


            // @property {Array<String>} lines_sort sorted lines ids
            result.lines_sort = this.getLinesSort();


            // @property {String} latest_addition
            result.latest_addition = ModelsInit.context.getSessionObject('latest_addition');


            // @property {Array<LiveOrder.Model.PromoCode>} promocodes
            result.promocodes = this.getPromoCodes(order_fields);


            if (this.automaticallyRemovedPromocodes) {
                result.automaticallyremovedpromocodes = this.automaticallyRemovedPromocodes;
            }


            // @property {Boolean} ismultishipto
            result.ismultishipto = this.getIsMultiShipTo(order_fields);


            // Ship Methods
            if (result.ismultishipto) {
                // @property {Array<OrderShipMethod>} multishipmethods
                result.multishipmethods = this.getMultiShipMethods(result.lines);


                // These are set so it is compatible with non multiple shipping.
                result.shipmethods = [];
                result.shipmethod = null;
            } else {
                // @property {Array<OrderShipMethod>} shipmethods
                result.shipmethods = this.getShipMethods(order_fields);
                // @property {OrderShipMethod} shipmethod
                result.shipmethod = order_fields.shipmethod
                    ? order_fields.shipmethod.shipmethod
                    : null;
            }


            // Addresses
            result.addresses = this.getAddresses(order_fields);
            result.billaddress = order_fields.billaddress
                ? order_fields.billaddress.internalid
                : null;
            result.shipaddress = !result.ismultishipto ? order_fields.shipaddress.internalid : null;


            // @property {Array<ShoppingSession.PaymentMethod>} paymentmethods Payments
            result.paymentmethods = this.getPaymentMethods(order_fields);


            // @property {Boolean} isPaypalComplete Paypal complete
            result.isPaypalComplete =
                ModelsInit.context.getSessionObject('paypal_complete') === 'T';


            // @property {Array<String>} touchpoints Some actions in the live order may change the URL of the checkout so to be sure we re send all the touchpoints
            result.touchpoints = SiteSettings.getTouchPoints();


            // @property {Boolean} agreetermcondition Terms And Conditions
            result.agreetermcondition = order_fields.agreetermcondition === 'T';


            // @property {OrderSummary} Summary
            result.summary = order_fields.summary;
            if (result.summary) {
                result.summary.discountrate = Utils.toCurrency(result.summary.discountrate);
                result.summary.discounttotal_formatted = Utils.formatCurrency(
                    result.summary.discounttotal
                );
                result.summary.taxonshipping_formatted = Utils.formatCurrency(
                    result.summary.taxonshipping
                );
                result.summary.taxondiscount_formatted = Utils.formatCurrency(
                    result.summary.taxondiscount
                );
                result.summary.taxonhandling_formatted = Utils.formatCurrency(
                    result.summary.taxonhandling
                );
                result.summary.discountedsubtotal_formatted = Utils.formatCurrency(
                    result.summary.discountedsubtotal
                );
                result.summary.handlingcost_formatted = Utils.formatCurrency(
                    result.summary.handlingcost
                );
                result.summary.taxtotal_formatted = Utils.formatCurrency(result.summary.taxtotal);
                result.summary.giftcertapplied_formatted = Utils.formatCurrency(
                    result.summary.giftcertapplied
                );
                result.summary.shippingcost_formatted = Utils.formatCurrency(
                    result.summary.shippingcost
                );
                result.summary.tax2total_formatted = Utils.formatCurrency(result.summary.tax2total);
                result.summary.discountrate_formatted = Utils.formatCurrency(
                    result.summary.discountrate
                );
                result.summary.estimatedshipping_formatted = Utils.formatCurrency(
                    result.summary.estimatedshipping
                );
                result.summary.total_formatted = Utils.formatCurrency(result.summary.total);
                result.summary.subtotal_formatted = Utils.formatCurrency(result.summary.subtotal);
            }


            if (this.isSuiteTaxEnabled) {
                // @property {Array<suitetax>} suitetaxes
                result.suitetaxes = this.getSuiteTaxes();
            }
            // @property {Object} options Transaction Body Field
adding custon value to the live order model
//start here
            result.options = this.getTransactionBodyField();
            var user = Profile.get()
            var contactSearch = this.contact(user.email)
            result.options.custbody_ordered_by = contactSearch !== null && contactSearch.response && contactSearch.response[0] ? contactSearch.response[0].id : "";
//ends here
           result.purchasenumber = order_fields.purchasenumber;


            if (
                !threedsecure &&
                this.isThreedSecureEnabled &&
                result &&
                result.summary &&
                result.paymentmethods &&
                result.paymentmethods.length &&
                result.paymentmethods[0].creditcard
            ) {
                var paymentMethod = result.paymentmethods[0].creditcard.paymentmethod;
                var notificationURL = ModelsInit.session.getAbsoluteUrl2(
                    'checkout',
                    '../threedsecure.ssp'
                );
                var site_id = ModelsInit.session.getSiteSettings(['siteid']).siteid;


                this.authenticationOptions = {
                    amount: result.summary.total,
                    paymentOption: result.paymentmethods[0].creditcard.internalid,
                    paymentProcessingProfile: paymentMethod.key.split(',')[1],
                    notificationURL:""+notificationURL + "?n="+ site_id
                };
            }


            // @class LiveOrder.Model
            return result;
        } catch (e) {
            nlapiLogExecution('ERROR', 'error@LIVEORDER_MODEL', JSON.stringify(e));
                throw e;
        }
        },

Thank you

Leave a comment

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