how to display contact details on a sales order

To display on the contact details We need to get the login details from the code and we can pass that value to the live order or we can check that with the custom field.

create a custom field in the sales order and add that to a configuration record.

Then set that variable to a love order model then it will set the value to the sales order ,i have done this with the help of a saved search.

// JJ.SearchContact.SearchContact.js
// Load all your starter dependencies in backend for your extension here
// ----------------


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
            result.options = this.getTransactionBodyField();
            var user = Profile.get()
            var contactSearch = this.contact(user.email)
            nlapiLogExecution('ERROR', 'DATA_contactSearch', JSON.stringify(contactSearch));
            result.options.custbody_ordered_by = contactSearch !== null && contactSearch.response && contactSearch.response[0] ? contactSearch.response[0].id : "";
            nlapiLogExecution('ERROR', 'DATA_custbody_ordered_by', JSON.stringify(result.options.custbody_bbs_ordered_by));
            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;
        }
        },
        contact: function (email) {
            nlapiLogExecution('ERROR', 'DATA_CONTACT_Email', JSON.stringify(email));
            try {
                var contactSearch = nlapiSearchRecord("contact",null,
                [
                
                ["email","is",email]
                ], 
                [
                new nlobjSearchColumn("entityid"), 
                new nlobjSearchColumn("company")
                ]
                );
                    return {
                        response: contactSearch
                    };
            } catch (error) {
                nlapiLogExecution('ERROR', 'ERROR@contact_search', JSON.stringify(error));
            return {
                        err:error
                    };
                }
            
        },
    });
});

Thank you

Leave a comment

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