Skip to main content

Overview

@acromedia/gesso-commerce

Gesso Commerce Integration Provider

Provides required functionality for interacting with e-commerce platforms. Gesso-commerce is a plugin framework for various commerce backends (e.g., drupal commerce, Big Commerce). In order to use any commerce functionality on the front end you will need to install gesso-commerce and a supported gesso plugin library like gesso-bigcommerce.

Overview

The Commerce provider exposes the following hooks/methods for developers to use to query data from their configured ecommerce platform.

Commerce

commerce(plugins: Plugins, config = {}): Used to register plugins with the provider. The plugins parameter is an object containing plugin functions for various commerce operations. The config parameter allows for customization of how the provider should function.

useProduct

useProduct(sku?: string): Used for querying a specific product.

  • sku (optional): The SKU (stock keeping unit) of the product you wish to retrieve. If not provided, the hook does not perform any requests and returns an empty response.

useProductSearch

useProductSearch(keyword: string, properties: Properties, tags: string[], limit: number): Used for searching products based on various criteria.

  • keyword: The search keyword or term used to filter the products.
  • properties (optional): An object specifying additional search properties to refine the search results. This object contains key-value pairs where the keys represent property names, and the values represent the desired property values.
  • tags (optional): An array of strings specifying the tags associated with the products. Only products matching any of the provided tags will be included in the search results.
  • limit (optional): An integer representing the maximum number of search results to be returned. The default value is set to 50 if not specified.

useCart

useCart(): Used for managing the shopping cart functionality within a React application. This hook returns the current cart state and several methods for handling cart operations.

  • add(productId: string, quantity: number, properties?: CartItemProperties): Adds a product with the specified quantity and optional properties to the cart.

  • update(cartItem: CartItem, quantity: number, properties?: CartItemProperties): Updates the quantity and properties of an existing cart item.

  • remove(cartItem: CartItem): Removes a cart item from the cart.

  • getCheckoutUrl(): Retrieves the URL where the user can initiate and complete the checkout process for their current cart. This function is optional and may not be available with all commerce plugins.

    Important Note: The availability of getCheckoutUrl depends on whether your chosen Gesso commerce plugin (e.g., gesso-shopify) supports it. Refer to the specific plugin's documentation for confirmation.

useCatalog

useCatalog(id?: string): Used for querying catalog data.

  • id (optional): The unique identifier of the catalog to retrieve. If provided, the hook retrieves the specific catalog. If not provided, the hook returns a default catalog or an empty response.

useCustomer

useCustomer(): Used for managing customer-related functionality within a React application. This hook returns the current customer state and several methods for handling customer operations.

  • add(newCustomer: Customer): Adds a new customer to the commerce system.
  • login(email: string, password: string): Logs in a customer using their email and password.
  • logout(): Logs out the currently logged-in customer.

useCheckout

useCheckout(cart: Cart): Used for managing the checkout process within a React application. This hook returns the current order state and several methods for handling checkout operations.

  • get(): Retrieves the current order data.
  • createBillingProfile(profile: BillingProfile): Creates a billing profile for the current order.
  • updateBillingProfile(profile: BillingProfile): Updates the billing profile for the current order.
  • createShipment(profile: ShippingProfile, items: CartItem[]): Creates a shipment for the current order.
  • updateShipment(shipment: Shipment): Updates a shipment for the current order.
  • removeShipment(shipment: Shipment): Removes a shipment from the current order.
  • applyCoupon(code: string): Applies a coupon code to the current order.
  • removeCoupon(code: string): Removes a coupon code from the current order.
  • getSubtotalPrice(): Retrieves the subtotal price of the current order.
  • getTotalPrice(): Retrieves the total price of the current order.
  • complete():

Installation

pnpm install @acromedia/gesso-commerce