0.0.2 • Published 5 months ago

@builder.io/plugin-commercelayer v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Builder.io CommerceLayer plugin

Easily connect your CommerceLayer APIs to your Builder.io content!

Installation

Go to builder.io/account/organization and type @builder.io/plugin-commercelayer , then hit save, a prompt will ask you for your Client ID / Client Secret.

Installation screenshot

You will now see three new field types (for model fields, symbol inputs, custom components fields), and custom targeting attributes that can be used in three different contexts:

Custom targeting

Custom targeting in Builder.io allow users to target content by a multitude of attributes, and in this plugin you'll be able to add specific content to CommerceLayer products, for this you'll need first to set the target attributes on the host site, either by setting the userAttributes if you're rendering client side:

builder.setUserAttributes({
  product: currentProduct.id,
});

Or by passing it as a query param to the content API call, or in graqhql query for e.g in Gatsby or nextjs.

  • CommerceLayer Product when used as a custom targeting type, it'll target contexts where the field is set to the product ID, you'll need to set the product ID on the host environment, using one of the methods above. Alternatively, if you want to target by product handle (slug) use the CommerceLayer Product Handle type in your custom targeting attributes.

Symbol Inputs

Using the field types CommerceLayer Product as inputs, the UIs will prompt to search for products. When consumed by APIs, SDKs, or in the Builder.io UIs, the value will be resolved automatically the in the form of a Builder.io Request object

{
  "yourFieldName": {
    "@type": "@builder.io/core:Request",
    "request": {
      "url": "..."
    },
    "data": {
      // Response data from the API request, e.g.:
      "product": {
        /* ... */
      }
    }
  }
}

How to develop?

Install

git clone https://github.com/BuilderIO/builder.git
cd plugins/commercelayer
npm install

Run

npm start

Add the plugin in Builder.io

Go to builder.io/account/organization and add the localhost URL to the plugin from the plugin settings (http://localhost:1268/plugin.system.js?pluginId=@builder.io/plugin-commercelayer)

NOTE: Loading http:// content on an https:// website will give you a warning. Be sure to click the shield in the top right of your browser and choose "load unsafe scripts" to allow the HTTP content on Builder's HTTPS site when developing locally

Now as you develop you can restart Builder to see the latest version of your plugin.

To uninstall your plugin,remove it in the plugins UI

Seeing the plugin in action

Try creating a custom model, component, or symbol using an CommerceLayer field, and edit away!

Frameworks

Builder.io uses React and Material UI for the UI, and Emotion for styling.

Using these frameworks in Builder plugins ensures a better experience and performance.