Medusa Products Bought Together
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
- Install the package with Copy to clipboard
yarn add @rsc-labs/medusa-products-bought-together
or Copy to clipboardnpm i @rsc-labs/medusa-products-bought-together
. - In Copy to clipboard
medusa-config.js
, add the plugin to the Copy to clipboardplugins
array.
123456789const plugins = [// ... other plugins{resolve: `@rsc-labs/medusa-products-bought-together`,options: {}}]
- Run migrations, e.g. Copy to clipboard
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:
1234567891011121314151617181920212223242526272829303132333435openapi: 3.0.0info:title: APIdescription: API for pluginversion: 0.0.1paths:/store/boughtTogether/{productId}:get:summary: List of productsdescription: Returns a list of products which are bought together with {productId}parameters:- name: productIdin: pathdescription: ID of product for which you are looking for other productsrequired: trueschema:type: stringresponses:'200':description: productId passed in URL. Returns empty array if cannot be found in database.content:application/json:schema:type: arrayitems:type: objectproperties:productId:type: stringboughtTogetherProductId:type: stringfrequency:type: number'404':description: productId not passed in URL
For example:
Request:
12Response:
[
{
"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: Copy to clipboard
5
You can change this limit by providing Copy to clipboard
getLimit
option to plugin:123456789const 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/