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.
SalesforceConnector
A Commerce Integrations connector for Salesforce B2C Commerce backends.
Importimport { SalesforceConnector } from '@mobify/commerce-integrations/dist/connectors/sfcc
Implements:
Constructor
Usagenew SalesforceConnector(client)
Parameter | Type |
---|---|
client | ShopApi.ApiClient |
Methods
registerCustomer(data)
Register a new customer account and login.
Returns:
Promise.<Customer>
Parameter | Type |
---|---|
data | CustomerRegistration |
parseCartItem()
Parse a cart item
Implements:
parseCouponEntry()
Parse a coupon item
Implements:
parseOrderAddress()
Parse an order address
Implements:
parseCustomerInformation()
Parse customer information
Implements:
parseShippingMethod()
Parse a shipping method
Implements:
parsePaymentMethod()
Parse a payment method
Implements:
parsePayment()
Parse a payment.
Implements:
parseCart()
Parse a cart
Implements:
parseCustomer(data)
Takes a OCAPI Customer object and parses it into a commerce-integrations Customer type.
Implements:
Returns:
Promise.<Customer>
Parameter | Type | Description |
---|---|---|
data | Object | a OCAPI Customer document |
parseProduct(data)
Takes a OCAPI Product object and parses it into a commerce-integrations Product type.
Implements:
Returns:
Promise.<Product>
Parameter | Type | Description |
---|---|---|
data | Object | a OCAPI Product document |
parseSearchProducts(data)
Takes a OCAPI ProductSearchResult object and parses it into a commerce-integrations ProductSearch type.
Implements:
Returns:
Promise.<ProductSearch>
Parameter | Type | Description |
---|---|---|
data | Object | a OCAPI ProductSearchResult document |
parseGetStore(data)
Takes a OCAPI Store object and parses it into a commerce-integrations Store type.
Returns:
Promise.<Store>
Parameter | Type | Description |
---|---|---|
data | Object | a 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.
Implements:
Returns:
Array.<Category>
Parameter | Type | Description |
---|---|---|
categories | Array.<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>
Parameter | Type | Description |
---|---|---|
imageUrl | string | |
attributes | Object | additional 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.
Implements:
Returns:
Promise.<Order>
Parameter | Type | Description |
---|---|---|
cart | Cart | The customer’s cart. |
opts | Object |
parseCategory()
Parse a category.
Implements:
parseSearchStores()
Parse a StoreSearchResult
Implements:
getDefaultHeaders()
Get the default headers that are sent with every request.
Implements:
Returns:
Object.<String, String>
setDefaultHeaders(headers)
Set the default headers that are sent with every request.
Implements:
Parameter | Type |
---|---|
headers | Object.<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.
Implements:
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.
Parameter | Type |
---|---|
username | String |
password | String |
logout()
Log a customer out.
Implements:
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.
Implements:
Returns:
Promise.<Customer>
Throws:
ForbiddenError Will throw an error if authorization credentials are incorrect
getCustomer(id, [opts])
Return a customer’s details by id.
Implements:
Returns:
Promise.<Customer>
Throws:
ServerError Throw generic error if server has error.
Parameter | Type | Description |
---|---|---|
id | String | Customer Id |
[opts] | Object | Options object |
searchProducts(productSearchRequest, [opts])
Search for products, given a productSearchRequest object.
Implements:
Returns:
Promise.<ProductSearch>
Parameter | Type | Description |
---|---|---|
productSearchRequest | ProductSearchRequest | Search query |
[opts] | Object | Options object |
getProduct(id, [opts])
Get a single product by id.
Implements:
Returns:
Promise.<Product>
Parameter | Type | Description |
---|---|---|
id | String | The product id. |
[opts] | Object | Options 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.
Implements:
Returns:
Promise.<ProductList>
Parameter | Type | Description |
---|---|---|
ids | Array.<String> | The product ids. |
[opts] | Object | Options object |
getStore(id, [opts])
Get a Store (ie. a physical retail-outlet) by id. Includes addresses, opening hours, etc.
Implements:
Returns:
Promise.<Store>
Parameter | Type | Description |
---|---|---|
id | String | The id of the store |
[opts] | Object | Options object |
getCategory(id, [opts])
Get a product Category by id.
Implements:
Returns:
Promise.<Category>
Parameter | Type | Description |
---|---|---|
id | String | |
[opts] | Object | object |
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.
Implements:
Returns:
Promise.<CategoryList>
Parameter | Type | Description |
---|---|---|
ids | Array.<string> | |
[opts] | Object | object |
searchStores(storeSearchRequest, [opts])
Searches for Stores (ie. physical retail-outlets).
Implements:
Returns:
Promise.<StoreSearchResult>
Parameter | Type | Description |
---|---|---|
storeSearchRequest | StoreSearchRequest | |
[opts] | Object | Options object |
createCart(oldCcart, [opts])
Creates a new cart with an optional cart object.
Implements:
Returns:
Promise.<Cart>
Throws:
Could not create cart.
Parameter | Type | Description |
---|---|---|
oldCcart | Cart | The cart you’d like to migrate to the new cart |
[opts] | Object | object |
getCart(cartId, [opts])
Retrieve cart by id.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cartId | String | The id of the cart you want to retrieve |
[opts] | Object | object |
deleteCart(cartId, [opts])
Deletes the given cart
Implements:
Throws:
Could not delete cart.
Parameter | Type | Description |
---|---|---|
cartId | String | The id of the cart you want to delete. |
[opts] | Object | object |
addCartItem(cart, cartItem, opts)
Adds a cart item to cart.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to add the cart item to. |
cartItem | CartItem | The cart item to add. |
opts | Object |
removeCartItem(cart, cartItemId, opts)
Remove a cart item from the cart.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to remove the cart item from. |
cartItemId | String | The id of the cart item to remove. |
opts | Object |
updateCartItem(cart, cartItem, opts)
Update an existing cart item in the cart.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to containing the cart item to update. |
cartItem | CartItem | The cart item to update. |
opts | Object |
setShippingAddress(cart, shippingAddress, opts)
Set the shipping address on the cart.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to update the shipping address for. |
shippingAddress | OrderAddress | The new or modified address. |
opts | Object |
setBillingAddress(cart, billingAddress, opts)
Set the billing address on the cart.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to update the billing address for. |
billingAddress | OrderAddress | The new or modified address. |
opts | Object |
setPayment(cart, payment, opts)
Add a supported payment type to the cart
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to remove the payment from. |
payment | Payment | The payment to add. |
opts | Object |
getShippingMethods(cart, opts)
Get all the available shipping methods given the cart details.
Implements:
Returns:
Promise.<Array.<ShippingMethod>>
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to determinen avaialble shipping methods for. |
opts | Object |
setShippingMethod(cart, shippingMethod, opts)
Set the shipping method for the cart.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to set the shipping method for. |
shippingMethod | ShippingMethod | The shipping method to set. |
opts | Object |
setCustomerInformation(cart, customerInformation, opts)
Set the customer information.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The customer’s cart. |
customerInformation | CustomerInformation | The new or modified customer information. |
opts | Object |
getPaymentMethods(cart, opts)
Get the available payment methods for the cart.
Implements:
Returns:
Promise.<Array.<PaymentMethod>>
Parameter | Type | Description |
---|---|---|
cart | Cart | The customer’s cart. |
opts | Object |
getOrder(id, [opts])
Get a single order by id.
Implements:
Returns:
Promise.<Order>
Parameter | Type | Description |
---|---|---|
id | String | The order id. |
[opts] | Object | Options 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.
Implements:
Returns:
Promise.<OrderList>
Parameter | Type | Description |
---|---|---|
ids | Array.<String> | The order ids. |
[opts] | Object | Options object |
addCouponEntry(cart, couponEntry, opts)
Add a coupon to the cart by it’s code.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The customer’s cart. |
couponEntry | Object | The coupon. |
opts | Object | Options object. |
removeCouponEntry(cart, couponEntryId, opts)
Removes a coupon from the cart by its coupon entry id.
Implements:
Returns:
Promise.<Cart>
Parameter | Type | Description |
---|---|---|
cart | Cart | The customer’s cart. |
couponEntryId | Object | The coupon entry id. |
opts | Object | Options object. |
parseOrder()
Parse an order.
Implements:
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.
Parameter | Type | Description |
---|---|---|
config | Object | https://github.com/mobify/commercecloud-ocapi-client/blob/develop/src/ApiClient.js#L44 |