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

@rsc-labs/medusa-products-bought-together

v0.1.6

Published

Monitor and get products which are bought together

Downloads

313

Readme

Medusa "Products Bought Together" is a plugin which monitors and provides API for getting products which are frequently bought together.

Why?

When customer wants to buy product A, he can get information about other products which are frequently bought together with product A.

It is a common scenario for ecommerce, which leds to increasing sales by recommending such products to customers.

Getting Started

  1. Install the package with yarn add @rsc-labs/medusa-products-bought-together or npm i @rsc-labs/medusa-products-bought-together.
  2. In medusa-config.js, add the plugin to the plugins array.
const plugins = [
  // ... other plugins
  {
    resolve: `@rsc-labs/medusa-products-bought-together`,
    options: {
      
    }
  }
]
  1. Run migrations, e.g. npx medusa migrations run (see: https://docs.medusajs.com/development/entities/migrations/overview) as plugin uses new tables.

How it works?

When customer places new order, plugin takes information about all products in order and creates entries in database. If there is already existing pair of products (because they were bought together before), then it increases its ranking. In a result, there is a stored information about relations between products and how frequently they are bought together.

How can I use it?

When you install a plugin, monitoring is being done automatically.

To use it, you can use API described below:

openapi: 3.0.0
info:
  title:  API
  description: API for plugin
  version: 0.0.1
paths:
  /store/boughtTogether/{productId}:
    get:
      summary: List of products
      description: Returns a list of products which are bought together with {productId}
      parameters:
        - name: productId
          in: path
          description: ID of product for which you are looking for other products
          required: true
          schema:
            type: string
      responses:
        '200':
          description: productId passed in URL. Returns empty array if cannot be found in database.
          content:
            application/json:
              schema: 
                type: array
                items:
                  type: object
                  properties:
                    productId:
                      type: string
                    boughtTogetherProductId:
                      type: string
                    frequency:
                      type: number
        '404':
          description: productId not passed in URL

For example:

Request: https://localhost:9000/store/boughtTogether/prod_1123123123

Response:

[
    {
        "productId": "prod_1123123123",
        "boughtTogetherProductId": "prod_2223432432423",
        "frequency": 10
    },
    {
        "productId": "prod_1123123123",
        "boughtTogetherProductId": "prod_334343434343",
        "frequency": 4
    }
]

Configuration

There is a limit set for GET requests equal to: 5

You can change this limit by providing getLimit option to plugin:

const plugins = [
  // ... other plugins
  {
    resolve: ``,
    options: {
        getLimit: 10
    }
  }
]

TODO

[ ] Tests

[ ] Make limit per request, as we can't use "query" params in API routes (req.body in GET REST API sounds weak).

Contribution

Contributions are welcome and they are greatly appreciated!

License

MIT


© 2023 RSC https://rsoftcon.com/