# Class: SalesforceConnector

## connectors/sfcc.SalesforceConnector(client)

A connector for the Salesforce Commerce Cloud API.

## Constructor

#### new SalesforceConnector(client)

##### Parameters:

Name | Type | Description
--- | --- | ---
`client` | ShopApi.ApiClient |

Implements:
  - module:connectors/interfaces.CommerceConnector
  - module:connectors/interfaces.ParserHooks
Source:
  - connectors/sfcc.js, line 334

### Methods

#### (static) fromConfig(config) → {module:sfcc.SalesforceConnector}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`config` | Object | https://github.com/mobify/commercecloud-ocapi-client/blob/develop/src/ApiClient.js#L44

Source:
  - connectors/sfcc.js, line 349

##### Returns:

The new SalesforceConnector instance.

Type
  module:sfcc.SalesforceConnector

#### addCartItem(cart, cartItem, opts) → {Promise.<module:types.Cart>}

Adds a cart item to cart.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The cart to add the cart item to.
`cartItem` | module:types.CartItem | The cart item to add.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#addCartItem
Source:
  - connectors/interfaces.js, line 214

##### Returns:

Type
  Promise.<module:types.Cart>

#### addCouponEntry(cart, couponEntry, opts) → {Promise.<module:types.Cart>}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The customer's cart.
`couponEntry` | Object | The coupon.
`opts` | Object | Options object.

Implements:
  - module:connectors/interfaces.CommerceConnector#addCouponEntry
Source:
  - connectors/interfaces.js, line 362

##### Returns:

Type
  Promise.<module:types.Cart>

#### createCart(oldCcart, optsopt) → {Promise.<module:types.Cart>}

Creates a new cart with an optional cart object.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`oldCcart` | module:types.Cart |  | The cart you'd like to migrate to the new cart
`opts` | Object | <optional> | object

Implements:
  - module:connectors/interfaces.CommerceConnector#createCart
Source:
  - connectors/interfaces.js, line 180

##### Throws:

Could not create cart.

##### Returns:

Type
  Promise.<module:types.Cart>

#### createOrder(cart, opts) → {Promise.<module:types.Order>}

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.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The customer's cart.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#createOrder
Source:
  - connectors/sfcc.js, line 1208

##### Returns:

.

Type
  Promise.<module:types.Order>

#### deleteCart(cartId, optsopt)

Deletes the given cart

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`cartId` | String |  | The id of the cart you want to delete.
`opts` | Object | <optional> | object

Implements:
  - module:connectors/interfaces.CommerceConnector#deleteCart
Source:
  - connectors/interfaces.js, line 203

##### Throws:

Could not delete cart.

#### getCart(cartId, optsopt) → {Promise.<module:types.Cart>}

Retrieve cart by id.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`cartId` | String |  | The id of the cart you want to retrieve
`opts` | Object | <optional> | object

Implements:
  - module:connectors/interfaces.CommerceConnector#getCart
Source:
  - connectors/interfaces.js, line 191

##### Returns:

Type
  Promise.<module:types.Cart>

#### getCategories(ids, optsopt) → {Promise.<module:types.CategoryList>}

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.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`ids` | Array.<String> |  |
`opts` | Object | <optional> | object

Implements:
  - module:connectors/interfaces.CommerceConnector#getCategories
Source:
  - connectors/interfaces.js, line 156

##### Returns:

Type
  Promise.<module:types.CategoryList>

#### getCategory(id, optsopt) → {Promise.<module:types.Category>}

Get a product Category by id.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`id` | String |  |
`opts` | Object | <optional> | object

Implements:
  - module:connectors/interfaces.CommerceConnector#getCategory
Source:
  - connectors/interfaces.js, line 139

##### Returns:

Type
  Promise.<module:types.Category>

#### getCustomer(id, optsopt) → {Promise.<module:types.Customer>}

Return a customer's details by id.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`id` | String |  | Customer Id
`opts` | Object | <optional> | Options object

Implements:
  - module:connectors/interfaces.CommerceConnector#getCustomer
Source:
  - connectors/interfaces.js, line 76

##### Throws:

Throw generic error if server has error.

Type
  module:errors.ServerError

##### Returns:

Type
  Promise.<module:types.Customer>

#### getDefaultHeaders() → {Object.<String, String>}

Get the default headers that are sent with every request.

Implements:
  - module:connectors/interfaces.CommerceConnector#getDefaultHeaders
Source:
  - connectors/interfaces.js, line 15

##### Returns:

Type
  Object.<String, String>

#### getOrder(id, optsopt) → {Promise.<module:types.Order>}

Get a single order by id.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`id` | String |  | The order id.
`opts` | Object | <optional> | Options object

Implements:
  - module:connectors/interfaces.CommerceConnector#getOrder
Source:
  - connectors/interfaces.js, line 332

##### Returns:

.

Type
  Promise.<module:types.Order>

#### getOrders(ids, optsopt) → {Promise.<module:types.OrderList>}

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.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`ids` | Array.<String> |  | The order ids.
`opts` | Object | <optional> | Options object

Implements:
  - module:connectors/interfaces.CommerceConnector#getOrders
Source:
  - connectors/interfaces.js, line 349

##### Returns:

.

Type
  Promise.<module:types.OrderList>

#### getPaymentMethods(cart, opts) → {Promise.<Array.<module:types.PaymentMethod>>}

Get the available payment methods for the cart.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The customer's cart.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#getPaymentMethods
Source:
  - connectors/interfaces.js, line 311

##### Returns:

Type
  Promise.<Array.<module:types.PaymentMethod>>

#### getProduct(id, optsopt) → {Promise.<module:types.Product>}

Get a single product by id.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`id` | String |  | The product id.
`opts` | Object | <optional> | Options object

Implements:
  - module:connectors/interfaces.CommerceConnector#getProduct
Source:
  - connectors/interfaces.js, line 98

##### Returns:

.

Type
  Promise.<module:types.Product>

#### getProducts(ids, optsopt) → {Promise.<module:types.ProductList>}

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.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`ids` | Array.<String> |  | The product ids.
`opts` | Object | <optional> | Options object

Implements:
  - module:connectors/interfaces.CommerceConnector#getProducts
Source:
  - connectors/interfaces.js, line 115

##### Returns:

.

Type
  Promise.<module:types.ProductList>

#### getShippingMethods(cart, opts) → {Promise.<Array.<module:types.ShippingMethod>>}

Get all the available shipping methods given the cart details.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The cart to determinen avaialble shipping methods for.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#getShippingMethods
Source:
  - connectors/interfaces.js, line 279

##### Returns:

Type
  Promise.<Array.<module:types.ShippingMethod>>

#### getStore(id, optsopt) → {Promise.<module:types.Store>}

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

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`id` | String |  | The id of the store
`opts` | Object | <optional> | Options object

Implements:
  - module:connectors/interfaces.CommerceConnector#getStore
Source:
  - connectors/interfaces.js, line 128

##### Returns:

.

Type
  Promise.<module:types.Store>

#### login(username, password) → {Promise.<module:types.Customer>}

Log a customer in and return their details.

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`username` | String |
`password` | String |

Implements:
  - module:connectors/interfaces.CommerceConnector#login
Source:
  - connectors/interfaces.js, line 41

##### Throws:

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

  Type
    module:errors.InvalidArgumentError

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

  Type
    module:errors.ForbiddenError

##### Returns:

.

Type
  Promise.<module:types.Customer>

#### logout() → {Promise.<undefined>}

Log a customer out.

Implements:
  - module:connectors/interfaces.CommerceConnector#logout
Source:
  - connectors/interfaces.js, line 52

##### Throws:

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

Type
  module:errors.ServerError

##### Returns:

Type
  Promise.<undefined>

#### parseCart()

Parse a cart

Implements:
  - module:connectors/interfaces.ParserHooks#parseCart
Source:
  - connectors/sfcc.js, line 828

#### parseCartItem()

Parse a cart item

Implements:
  - module:connectors/interfaces.ParserHooks#parseCartItem
Source:
  - connectors/sfcc.js, line 725

#### parseCategories(categories) → {Array.<module:types.Category>}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`categories` | Array.<Object> | an array of OCAPI Category document

Implements:
  - module:connectors/interfaces.ParserHooks#parseCategories
Source:
  - connectors/sfcc.js, line 1128

##### Returns:

Type
  Array.<module:types.Category>

#### parseCategory()

Parse a category.

Implements:
  - module:connectors/interfaces.ParserHooks#parseCategory
Source:
  - connectors/interfaces.js, line 401

#### parseCouponEntry()

Parse a coupon item

Implements:
  - module:connectors/interfaces.ParserHooks#parseCouponEntry
Source:
  - connectors/sfcc.js, line 741

#### parseCustomer(data) → {Promise.<module:types.Customer>}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | a OCAPI Customer document

Implements:
  - module:connectors/interfaces.ParserHooks#parseCustomer
Source:
  - connectors/sfcc.js, line 927

##### Returns:

Type
  Promise.<module:types.Customer>

#### parseCustomerInformation()

Parse customer information

Implements:
  - module:connectors/interfaces.ParserHooks#parseCustomerInformation
Source:
  - connectors/sfcc.js, line 768

#### parseGetStore(data) → {Promise.<module:types.Store>}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | a OCAPI Store document

Source:
  - connectors/sfcc.js, line 1040

##### Returns:

Type
  Promise.<module:types.Store>

#### parseImage(imageUrl, attributes) → {Promise.<module:types.Image>}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`imageUrl` | string |
`attributes` | Object | additional attributes of an image

Source:
  - connectors/sfcc.js, line 1177

##### Returns:

Type
  Promise.<module:types.Image>

#### parseOrder()

Parse an order.

Implements:
  - module:connectors/interfaces.ParserHooks#parseOrder
Source:
  - connectors/interfaces.js, line 499

#### parseOrderAddress()

Parse an order address

Implements:
  - module:connectors/interfaces.ParserHooks#parseOrderAddress
Source:
  - connectors/sfcc.js, line 751

#### parsePayment()

Parse a payment.

Implements:
  - module:connectors/interfaces.ParserHooks#parsePayment
Source:
  - connectors/sfcc.js, line 809

#### parsePaymentMethod()

Parse a payment method

Implements:
  - module:connectors/interfaces.ParserHooks#parsePaymentMethod
Source:
  - connectors/sfcc.js, line 789

#### parseProduct(data) → {Promise.<module:types.Product>}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | a OCAPI Product document

Implements:
  - module:connectors/interfaces.ParserHooks#parseProduct
Source:
  - connectors/sfcc.js, line 984

##### Returns:

Type
  Promise.<module:types.Product>

#### parseSearchProducts(data) → {Promise.<module:types.ProductSearch>}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | a OCAPI ProductSearchResult document

Implements:
  - module:connectors/interfaces.ParserHooks#parseSearchProducts
Source:
  - connectors/sfcc.js, line 1021

##### Returns:

Type
  Promise.<module:types.ProductSearch>

#### parseSearchStores()

Parse a StoreSearchResult

Implements:
  - module:connectors/interfaces.ParserHooks#parseSearchStores
Source:
  - connectors/interfaces.js, line 443

#### parseShippingMethod()

Parse a shipping method

Implements:
  - module:connectors/interfaces.ParserHooks#parseShippingMethod
Source:
  - connectors/sfcc.js, line 778

#### refreshSession() → {Promise.<module:types.Customer>}

Refresh a session token, on backends that support refresh.

Implements:
  - module:connectors/interfaces.CommerceConnector#refreshSession
Source:
  - connectors/interfaces.js, line 63

##### Throws:

Will throw an error if authorization credentials are incorrect

Type
  module:errors.ForbiddenError

##### Returns:

Type
  Promise.<module:types.Customer>

#### registerCustomer(data) → {Promise.<module:types/Customer>}

Register a new customer account and login.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | module:types/CustomerRegistration |

Source:
  - connectors/sfcc.js, line 564

##### Returns:

Type
  Promise.<module:types/Customer>

#### removeCartItem(cart, cartItemId, opts) → {Promise.<module:types.Cart>}

Remove a cart item from the cart.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The cart to remove the cart item from.
`cartItemId` | String | The id of the cart item to remove.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#removeCartItem
Source:
  - connectors/interfaces.js, line 225

##### Returns:

Type
  Promise.<module:types.Cart>

#### removeCouponEntry(cart, couponEntryId, opts) → {Promise.<module:types.Cart>}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The customer's cart.
`couponEntryId` | Object | The coupon entry id.
`opts` | Object | Options object.

Implements:
  - module:connectors/interfaces.CommerceConnector#removeCouponEntry
Source:
  - connectors/interfaces.js, line 375

##### Returns:

Type
  Promise.<module:types.Cart>

#### searchProducts(productSearchRequest, optsopt) → {Promise.<module:types.ProductSearch>}

Search for products, given a productSearchRequest object.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`productSearchRequest` | module:types.ProductSearchRequest |  | Search query
`opts` | Object | <optional> | Options object

Implements:
  - module:connectors/interfaces.CommerceConnector#searchProducts
Source:
  - connectors/interfaces.js, line 87

##### Returns:

Type
  Promise.<module:types.ProductSearch>

#### searchStores(storeSearchRequest, optsopt) → {Promise.<module:types.StoreSearchResult>}

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

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`storeSearchRequest` | module:types.StoreSearchRequest |  |
`opts` | Object | <optional> | Options object

Implements:
  - module:connectors/interfaces.CommerceConnector#searchStores
Source:
  - connectors/interfaces.js, line 167

##### Returns:

Type
  Promise.<module:types.StoreSearchResult>

#### setBillingAddress(cart, billingAddress, opts) → {Promise.<module:types.Cart>}

Set the billing address on the cart.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The cart to update the billing address for.
`billingAddress` | module:types.OrderAddress | The new or modified address.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#setBillingAddress
Source:
  - connectors/interfaces.js, line 258

##### Returns:

Type
  Promise.<module:types.Cart>

#### setCustomerInformation(cart, customerInformation, opts) → {Promise.<module:types.Cart>}

Set the customer information.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The customer's cart.
`customerInformation` | module:types.CustomerInformation | The new or modified customer information.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#setCustomerInformation
Source:
  - connectors/interfaces.js, line 301

##### Returns:

Type
  Promise.<module:types.Cart>

#### setDefaultHeaders(headers)

Set the default headers that are sent with every request.

##### Parameters:

Name | Type | Description
--- | --- | ---
`headers` | Object.<String, String> |

Implements:
  - module:connectors/interfaces.CommerceConnector#setDefaultHeaders
Source:
  - connectors/interfaces.js, line 24

#### setPayment(cart, payment, opts) → {Promise.<module:types.Cart>}

Add a supported payment type to the cart

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The cart to remove the payment from.
`payment` | module:types.Payment | The payment to add.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#setPayment
Source:
  - connectors/interfaces.js, line 269

##### Returns:

Type
  Promise.<module:types.Cart>

#### setShippingAddress(cart, shippingAddress, opts) → {Promise.<module:types.Cart>}

Set the shipping address on the cart.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The cart to update the shipping address for.
`shippingAddress` | module:types.OrderAddress | The new or modified address.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#setShippingAddress
Source:
  - connectors/interfaces.js, line 247

##### Returns:

Type
  Promise.<module:types.Cart>

#### setShippingMethod(cart, shippingMethod, opts) → {Promise.<module:types.Cart>}

Set the shipping method for the cart.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The cart to set the shipping method for.
`shippingMethod` | module:types.ShippingMethod | The shipping method to set.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#setShippingMethod
Source:
  - connectors/interfaces.js, line 290

##### Returns:

Type
  Promise.<module:types.Cart>

#### 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).

Source:
  - connectors/sfcc.js, line 1063

#### updateCartItem(cart, cartItem, opts) → {Promise.<module:types.Cart>}

Update an existing cart item in the cart.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cart` | module:types.Cart | The cart to containing the cart item to update.
`cartItem` | module:types.CartItem | The cart item to update.
`opts` | Object |

Implements:
  - module:connectors/interfaces.CommerceConnector#updateCartItem
Source:
  - connectors/interfaces.js, line 236

##### Returns:

Type
  Promise.<module:types.Cart>