Hybris
The hybris
module contains the HybrisConnector
class, an implementation of the
CommerceConnector
interface using the Omni Channel Connect API (OCC API) for
connecting to SAP Hybris Commerce.
HybrisConnector
A Commerce Integrations connector for SAP Hybris Commerce backends.
Importimport { HybrisConnector } from '@mobify/commerce-integrations/dist/connectors/hybris
Implements:
Methods
registerCustomer(data)
Register a new customer account and login.
Returns:
Promise.<Customer>
Parameter | Type |
---|---|
data | HybrisCustomerRegistration |
getAuthentications()
Get the current authentications object, which can be used to save and restore auth state.
Returns:
Object
setAuthentications(authentications)
Set the current authentications object, as returned from getAuthentications. Use to save and restore auth state.
Parameter | Type |
---|---|
authentications | Object |
parseCategory(categories)
Takes an OCC API Category objects and parses it into an commerce-integrations Category type.
Implements:
Returns:
Promise.<Category>
Parameter | Type | Description |
---|---|---|
categories | Array.<Object> | An OCC API Category document |
parseOpeningHours(hours)
Takes an OCC API WeekdayOpeningDay object and parses it into a commerce-integrations Store.hours type.
Returns:
Promise.<Store>
Parameter | Type | Description |
---|---|---|
hours | Object | An OCC API WeekdayOpneningDay document |
parseGetStore(data)
Takes an OCC API PointOfService object and parses it into a commerce-integrations Store type.
Returns:
Promise.<Store>
Parameter | Type | Description |
---|---|---|
data | Object | An OCC API PointOfService document |
parseCouponEntry()
Parse a coupon item
Implements:
transformOrderAddress()
Transform an orderAddress into hybris’ models: billingAddress or shippingAddress
transformShippingMethod()
Transform a shippingMethod into hybris’ model deliveryMethod.
transformCartItem()
Transform a cartItem into hybris’ model OrderEntryOCC.
transformPayment()
Transform a payment into hybris’ model paymentDetail.
setPayment(cart, payment, opts)
Add a supported payment type to the cart
Implements:
Returns:
Promise.<Cart> - Need to set a billing address before setting a payment. Must call setCustomerInformation() to add an email before setting payment for an anonymous cart.user. cart.paymentDetails.number will be returned as undefined and set as a masked number in cart.paymentDetails.maskedNumber.
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to add the payment to |
payment | Payment | The payment to add |
opts | Object |
setCustomerInformation(cart, customerInformation, opts)
Set the customer information.
Implements:
Returns:
Promise.<Cart> - Email can be set for a guest user but not a registered user.
Parameter | Type | Description |
---|---|---|
cart | Cart | The customer’s cart |
customerInformation | CustomerInformation | The new or modified customer information |
opts | Object |
setBillingAddress(cart, billingAddress, opts)
Set the billing address on the cart.
Billing Address model : this order address needs to have a titleCode defined. The default titleCodes are: [‘mr’, ‘ms’, ‘miss’, ‘mrs’, ‘dr’, ‘rev’] But these may change depending on your backend, please refer to your backend instance to confirm valid titleCodes.
If the billing address is set before adding a payment, the billing address will not yet be saved in the hybris instance. Instead, the billing address will be saved in the hybris instance upon setting a payment.
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 |
setShippingAddress(cart, shippingMethod, opts)
Set the shipping method for the cart.
Implements:
Returns:
Promise.<Cart> - Must call setCustomerInformation() to add an email before setting payment for a guest user.
Parameter | Type | Description |
---|---|---|
cart | Cart | The cart to set the shipping method for |
shippingMethod | ShippingMethod | The shipping method to setid |
opts | Object |
getPaymentMethods(cart, opts)
Get the available payment methods for the cart
Implements:
Returns:
Promise.<Array.PaymentMethod> - Hybris only supports payments by credit card attained from their cardtypes endpoint so this command will return only one payment method with the id ‘CREDIT_CARD’, name ‘Credit Card’ and all of it’s valid credit card types.
Parameter | Type | Description |
---|---|---|
cart | Cart | The customer’s cart |
opts | Object |
parseCategories()
Parse categories.
Implements:
parseSearchProducts()
Parse a product search result.
Implements:
parseProduct()
Parse a product.
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 |
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 |
createOrder(cart, opts)
Create a new order using a given cart.
Implements:
Returns:
Promise.<Order>
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. |
parseCustomer()
Parse a customer.
Implements:
parseCart()
Parse a cart
Implements:
parseCartItem()
Parse a cart item
Implements:
parseOrderAddress()
Parse an order address
Implements:
parseShippingMethod()
Parse a shipping method
Implements:
parsePayment()
Parse a payment.
Implements:
parsePaymentMethod()
Parse a payment method.
Implements:
parseOrder()
Parse an order.
Implements: