menu
Menu
Mobify DevCenter
search_icon_focus

Sfcc

@mobify/commerce-integrations/dist/connectors/sfcc

The sfcc module contains the SalesforceConnector class, an implementation of the CommerceConnector interface using the Open Commerce API (OCAPI) for connecting to Salesforce B2C Commerce.

class

SalesforceConnector

A Commerce Integrations connector for Salesforce B2C Commerce backends.

Import
import { SalesforceConnector } from '@mobify/commerce-integrations/dist/connectors/sfcc

Implements:

CommerceConnector, ParserHooks

Constructor

Usage
new SalesforceConnector(client)
ParameterType
clientShopApi.ApiClient

Methods

registerCustomer(data)

Register a new customer account and login.

Returns:

Promise.<Customer>

ParameterType
dataCustomerRegistration

parseCartItem()

Parse a cart item


parseCouponEntry()

Parse a coupon item


parseOrderAddress()

Parse an order address


parseCustomerInformation()

Parse customer information


parseShippingMethod()

Parse a shipping method


parsePaymentMethod()

Parse a payment method


parsePayment()

Parse a payment.


parseCart()

Parse a cart


parseCustomer(data)

Takes a OCAPI Customer object and parses it into a commerce-integrations Customer type.

Returns:

Promise.<Customer>

ParameterTypeDescription
dataObjecta OCAPI Customer document

parseProduct(data)

Takes a OCAPI Product object and parses it into a commerce-integrations Product type.

Returns:

Promise.<Product>

ParameterTypeDescription
dataObjecta OCAPI Product document

parseSearchProducts(data)

Takes a OCAPI ProductSearchResult object and parses it into a commerce-integrations ProductSearch type.

Returns:

Promise.<ProductSearch>

ParameterTypeDescription
dataObjecta OCAPI ProductSearchResult document

parseGetStore(data)

Takes a OCAPI Store object and parses it into a commerce-integrations Store type.

Returns:

Promise.<Store>

ParameterTypeDescription
dataObjecta OCAPI Store document

transformSearchStoreParams()

This function will take product search request as we use them in the commerce-integrations and output them into a format usable by the specific connector (ocapi).


parseCategories(categories)

Takes an array of OCAPI Category objects and parses it into an commerce-integrations Category type.

Returns:

Array.<Category>

ParameterTypeDescription
categoriesArray.<Object>an array of OCAPI Category document

parseImage(imageUrl, attributes)

Takes an image url and its attributes and return an commerce-integrations Image type.

Returns:

Promise.<Image>

ParameterTypeDescription
imageUrlstring
attributesObjectadditional attributes of an image

createOrder(cart, opts)

Create a new order using a given cart. This command will trigger the appropriate OCAPI order authorization hooks. If orders placed through this command aren’t progressing from the created status, it’s possible that your API hooks haven’t been set up. Please consult your Saleforce professional.

Returns:

Promise.<Order>

ParameterTypeDescription
cartCartThe customer’s cart.
optsObject

parseCategory()

Parse a category.


parseSearchStores()

Parse a StoreSearchResult


getDefaultHeaders()

Get the default headers that are sent with every request.

Returns:

Object.<String, String>


setDefaultHeaders(headers)

Set the default headers that are sent with every request.

ParameterType
headersObject.<String, String>

login(username, password)

Log a customer in and return their details.

On backends which support “guest login”, credentials can be omitted to give you a guest session.

Returns:

Promise.<Customer>

Throws:

InvalidArgumentError Will throw an error if the username or password aren’t provided for type registered.

ForbiddenError Will throw an error if the customer credentials are incorrect.

ParameterType
usernameString
passwordString

logout()

Log a customer out.

Returns:

Promise.<undefined>

Throws:

ServerError Will throw an error if there was a server-side error.


refreshSession()

Refresh a session token, on backends that support refresh.

Returns:

Promise.<Customer>

Throws:

ForbiddenError Will throw an error if authorization credentials are incorrect


getCustomer(id, [opts])

Return a customer’s details by id.

Returns:

Promise.<Customer>

Throws:

ServerError Throw generic error if server has error.

ParameterTypeDescription
idStringCustomer Id
[opts]ObjectOptions object

searchProducts(productSearchRequest, [opts])

Search for products, given a productSearchRequest object.

Returns:

Promise.<ProductSearch>

ParameterTypeDescription
productSearchRequestProductSearchRequestSearch query
[opts]ObjectOptions object

getProduct(id, [opts])

Get a single product by id.

Returns:

Promise.<Product>

ParameterTypeDescription
idStringThe product id.
[opts]ObjectOptions object

getProducts(ids, [opts])

Get multiple products by their ids.

On supported backends this method will retrieve products in a single network call. Others may make a call per id to emulate the same behaviour.

Invalid ids are ignored and results are not guaranteed to be returned in the order requested.

Returns:

Promise.<ProductList>

ParameterTypeDescription
idsArray.<String>The product ids.
[opts]ObjectOptions object

getStore(id, [opts])

Get a Store (ie. a physical retail-outlet) by id. Includes addresses, opening hours, etc.

Returns:

Promise.<Store>

ParameterTypeDescription
idStringThe id of the store
[opts]ObjectOptions object

getCategory(id, [opts])

Get a product Category by id.

Returns:

Promise.<Category>

ParameterTypeDescription
idString
[opts]Objectobject

getCategories(ids, [opts])

Returns multiple product Categories by their ids.

On supported backends this method will retrieve Categories in a single network call. Others may make a call per id to emulate the same behaviour.

Invalid ids are ignored and results are not guaranteed to be returned in the order requested.

Returns:

Promise.<CategoryList>

ParameterTypeDescription
idsArray.<string>
[opts]Objectobject

searchStores(storeSearchRequest, [opts])

Searches for Stores (ie. physical retail-outlets).

Returns:

Promise.<StoreSearchResult>

ParameterTypeDescription
storeSearchRequestStoreSearchRequest
[opts]ObjectOptions object

createCart(oldCcart, [opts])

Creates a new cart with an optional cart object.

Returns:

Promise.<Cart>

Throws:

Could not create cart.

ParameterTypeDescription
oldCcartCartThe cart you’d like to migrate to the new cart
[opts]Objectobject

getCart(cartId, [opts])

Retrieve cart by id.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartIdStringThe id of the cart you want to retrieve
[opts]Objectobject

deleteCart(cartId, [opts])

Deletes the given cart

Throws:

Could not delete cart.

ParameterTypeDescription
cartIdStringThe id of the cart you want to delete.
[opts]Objectobject

addCartItem(cart, cartItem, opts)

Adds a cart item to cart.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe cart to add the cart item to.
cartItemCartItemThe cart item to add.
optsObject

removeCartItem(cart, cartItemId, opts)

Remove a cart item from the cart.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe cart to remove the cart item from.
cartItemIdStringThe id of the cart item to remove.
optsObject

updateCartItem(cart, cartItem, opts)

Update an existing cart item in the cart.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe cart to containing the cart item to update.
cartItemCartItemThe cart item to update.
optsObject

setShippingAddress(cart, shippingAddress, opts)

Set the shipping address on the cart.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe cart to update the shipping address for.
shippingAddressOrderAddressThe new or modified address.
optsObject

setBillingAddress(cart, billingAddress, opts)

Set the billing address on the cart.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe cart to update the billing address for.
billingAddressOrderAddressThe new or modified address.
optsObject

setPayment(cart, payment, opts)

Add a supported payment type to the cart

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe cart to remove the payment from.
paymentPaymentThe payment to add.
optsObject

getShippingMethods(cart, opts)

Get all the available shipping methods given the cart details.

Returns:

Promise.<Array.<ShippingMethod>>

ParameterTypeDescription
cartCartThe cart to determinen avaialble shipping methods for.
optsObject

setShippingMethod(cart, shippingMethod, opts)

Set the shipping method for the cart.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe cart to set the shipping method for.
shippingMethodShippingMethodThe shipping method to set.
optsObject

setCustomerInformation(cart, customerInformation, opts)

Set the customer information.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe customer’s cart.
customerInformationCustomerInformationThe new or modified customer information.
optsObject

getPaymentMethods(cart, opts)

Get the available payment methods for the cart.

Returns:

Promise.<Array.<PaymentMethod>>

ParameterTypeDescription
cartCartThe customer’s cart.
optsObject

getOrder(id, [opts])

Get a single order by id.

Returns:

Promise.<Order>

ParameterTypeDescription
idStringThe order id.
[opts]ObjectOptions object

getOrders(ids, [opts])

Get multiple orders by their ids.

On supported backends this method will retrieve orders in a single network call. Others may make a call per id to emulate the same behaviour.

Invalid ids are ignored and results are not guaranteed to be returned in the order requested.

Returns:

Promise.<OrderList>

ParameterTypeDescription
idsArray.<String>The order ids.
[opts]ObjectOptions object

addCouponEntry(cart, couponEntry, opts)

Add a coupon to the cart by it’s code.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe customer’s cart.
couponEntryObjectThe coupon.
optsObjectOptions object.

removeCouponEntry(cart, couponEntryId, opts)

Removes a coupon from the cart by its coupon entry id.

Returns:

Promise.<Cart>

ParameterTypeDescription
cartCartThe customer’s cart.
couponEntryIdObjectThe coupon entry id.
optsObjectOptions object.

parseOrder()

Parse an order.


fromConfig(config)

Given a configuration in the form of a plain object, this method returns a new SalesforceConnector instance.

Returns:

SalesforceConnector - The new SalesforceConnector instance.