npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bigcommerce-product-options

v0.1.1

Published

Easily render product data with a custom Handlebars template externally from the product page

Downloads

6

Readme

BigCommerce Product Options

Easily render product data with a custom Handlebars template externally from the product page. Most commonly used to render the available product options on category page.

Getting Started

Prerequisites

Nodejs v8+ (we assume you have installed something like nvm for changing Node versions).

API

new ProductOptions(productId)

productId

Type: number

BigCommerce product identifier to use.

ProductOptions.render(config)

Renders the template using product data and inserts the HTML directly into the DOM using the config Object supplied to indicate both the template and the element to insert content at. An optional position

config

Type: Object

A set of key/value pairs that configure that provides configuration for both insertion point (where on the DOM the HTML will be added) and for path to the template file.

  • template (required): Type: string

Path to the handlebars template to render.

  • element (required): Type: Object

Selected HTML element that is the insertion point of the rendered template.

  • position (optional): Type: string, either beforebegin, afterbegin, beforeend, afterend)

If not specified, the rendered template will be placed as the inner HTML of the element.

Where to insert the rendered template specifically, with respect to element.

Example

import PageManager from './page-manager';
import ProductOptions from 'bigcommerce-product-options';

export default class Category extends PageManager {
  before(next) {
      this.showSwatches();
      next();
  }

  showSwatches() {
      const products = Array.from(document.querySelectorAll('[data-has-options]'));

      if (products.length !== 0) {
          products.forEach(product => {
              let productId = product.getAttribute('data-has-options');
              new ProductOptions(productId).render({
                  template: 'custom/options/color-swatches',
                  element: product, // insertion point
                  position: 'beforeend' // where to insert in the insertion point (optional).
              });
          });
      }
  }
}

Notes

  • Since BigCommerce doesn't transpile external package code (for oldies like IE11), we provide transpiled files inside dist/ folder. You can access these files adding an alias on your webpack.conf.js file like 'brandlabs-bigcommerce-product-options': path.resolve(__dirname, 'node_modules/brandlabs-bigcommerce-product-options/dist/product-options.min.js')

Authors

  • Carson Reinke
  • Osama Aldemeery
  • Hector Fernando Hurtado

License

This project is licensed under the MIT License - see the LICENSE file for details

alt text