menu
Menu
Mobify DevCenter
search_icon_focus

Extending the Salesforce and SAP Hybris Connectors

Most ecommerce backends are customized, which means that existing Connectors will require some customization to match.

You can extend the existing Connectors any way you like, provided that you continue to implement the CommerceConnector interface.

Note: As a general rule, it’s safe to add properties to a return value, but do not remove them or change their types.

In this section, we will walk through two examples that show you how to customize your connector: overriding a parser, and adding a new method.

Overriding a parser

It’s common for ecommerce backends to rename the properties of their response attributes. This breaks the connector’s pre-built parsers.

For example, OCAPI’s Product Search Result endpoint commonly moves, where images are defined.

To adjust, we will need to override the parser, as shown here:

import {SalesforceConnector} from '@mobify/commerce-integrations/dist/connectors/sfcc'
class CustomSalesforceConnector extends SalesforceConnector {
parseSearchProducts(ocapiProductSearchResult, searchParams) {
const productSearch = super.parseSearchProducts(ocapiProductSearchResult, searchParams)
productSearch.results.forEach((product, index) => {
product.defaultImage = {
src: ocapiProductSearchResult.hits[index].c_default_image
}
})
return productSearch
}
}

Alternatively, you can also override the entire method.

Adding your own method to a connector

You can extend the Connector by adding your own methods. Let’s walk through an example of extending a SalesforceConnector:

import {SalesforceConnector} from '@mobify/commerce-integrations/dist/connectors/sfcc'
/**
* A custom Connector for a project.
*/
class CustomSalesforceConnector extends SalesforceConnector {
/**
* Override the default behavior to return only uppercase product names.
*/
searchProducts(searchParams, opts = {}) {
return super.searchProducts(searchParams, opts).then((data) => {
data.results = data.results.map((result) => {
result.productName = result.productName.toUpperCase()
return result
})
return data
})
}
}