Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@commercelayer/algolia-importer
Advanced tools
> A Javascript library that lets you easily import your ecommerce catalog into Algolia.
A Javascript library that lets you easily import your ecommerce catalog into Algolia.
Commerce Layer is a headless platform that lets you easily build enterprise-grade ecommerce into any website, by using the language, CMS, and tools you already master and love.
Commerce Layer Algolia Importer is designed to make it quick and simple to import your products data, index them into Algolia, and eventually get their prices from Commerce Layer and add them to the search.
This importer is CMS-agnostic — you can import your content data from any CMS of your choice, according to any content model you defined.
To get started and import your data into Algolia you need to install the importer and retrieve your credentials from your Algolia account.
Commerce Layer Algolia Importer is available as an npm package:
// npm
npm install @commercelayer/algolia-importer
// yarn
yarn add @commercelayer/algolia-importer
You can use the ES6 default import as follows:
import importer from '@commercelayer/algolia-importer'
Commerce Layer Algolia importer
function returns as a promise an array of Algolia index
objects — one for each of your selling countries (associated with the specified translation). You need to pass to it as a parameter an object containing at least:
algoliaConfig
— your Algolia app ID and admin API keyitems
— the list of products you want to indeximporter({
algoliaConfig: {
appId: 'your-algolia-app-id',
adminApiKey: 'your-algolia-admin-api-key'
},
items: yourItems,
}).then((results) => {
console.log(results)
})
items
is an array of objects. It has to be properly built by specifying the language code, the country code, and a list of key/value parameters related to the single variants:
// Typescript types
{
[languageCode: string]: {
[countryCode: string]: {
customRanking: number
reference: string
objectID: string
category: string[] | string
description: string
name: string
code: string
image: string
}[],
marketId?: string
}[]
}[]
// Example
[
{
'en-US': [
{
us: [
{
customRanking: 0,
reference: 'your-reference',
objectID: 'your-objectID',
category: 'your-category',
description: 'your-description',
name: 'your-variant-name',
code: 'your-sku-code',
image: 'your-image-url'
}
]
}
]
}
]
For each item you can define a custom ranking by setting the
customRanking
parameter — the lower its value the higher the item will be ranked within the search results.
Commerce Layer Algolia importer comes with some default values for its main parameters:
showPrice: false,
clConfig: {
clientId: '',
endpoint: '',
},
algoliaIndexPrefix: 'store'
algoliaSettings: {
searchableAttributes: [
'category',
'code',
'description',
'name',
'reference',
],
customRanking: ['asc(customRanking)'],
attributesForFaceting: ['category'],
distinct: 1,
attributeForDistinct: 'reference',
replicas: [],
}
The
algoliaSettings
object can be overridden at your leisure — please refer to Algolia documentation for more info on how to set their API parameters.
Our Algolia importer lets you import from Commerce Layer the prices of each product you want to index and sort (ascending or descending) your search result by price. To do that, just set the showPrice
parameter to true
and add the clConfig
object with your Commerce Layer organization credentials, remembering to specify the market in scope at a country code level in the items
array:
const items = [
{
'en-US': [
{
us: [
{
customRanking: 0,
reference: 'your-reference',
objectID: 'your-objectID',
category: 'your-category',
description: 'your-description',
name: 'your-variant-name',
code: 'your-sku-code',
image: 'your-image-url'
}
],
marketId: 'your-market-id'
}
]
}
]
importer({
algoliaConfig: {
appId: 'your-algolia-app-id',
adminApiKey: 'your-algolia-admin-api-key'
},
items: items,
showPrice: true,
clConfig: {
clientId: 'your-client-id',
endpoint: 'https://yourdomain.commercelayer.io'
}
})
This way, all the prices are added to the related index and two Algolia replicas (
price_asc
andprice_desc
) are automatically created.
This repository is published under the MIT license.
FAQs
> A Javascript library that lets you easily import your ecommerce catalog into Algolia.
We found that @commercelayer/algolia-importer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.