Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@bva/recommendations
Advanced tools
JS wrapper around Shopify's Recommendation API that provides an easy to use interface to get HTML on the page.
If you're using Node you can install this package in the following ways:
Yarn
yarn add @bva/recommendations
NPM
npm install @bva/recommendations
If you're not using Yarn or NPM, see below in Usage for more info on adding the minified file directly to your projects.
Recommendations is a simple widget using Shopify's native recommendations API that can be included on any Shopify website. Check out how easy it is to implement using ES6 modules:
import Recommendations from '@bva/recommendations';
const config = {
productId: 10590155084,
limit: 5,
};
const recs = new Recommendations(config);
recs.initialize();
If you're not using NPM and ES6 import/export syntax, you can also grab the minified dist/recommendations.min.js and include it in your HTML before your custom JS. Its equally simple:
<body>
<div data-recommendations-insertion></div>
<script src="recommendations.min.js"></script>
<script>
var config = {
productId: 10590155084,
limit: 6
};
var recs = new Shopify.Recommendations(config);
recs.initialize();
</script>
Perfect for your new slate projects
A configuration is required when initializing your Recommendations instance and uses the following properties:
"recommendations::hide"
) Tag that hides specific products"[data-recommendations-insertion]"
) HTML element that the reviews will be inserted into4
)The amount of products that will be displayed (max 10)The Product ID is what will be used in the request to Shopify to figure out which products to display. It must be passed to your instance upon instantiation via 1 of the following methods.
Add the data attribute data-recommendations-main-product-id
to your insertion element and add the product id as a value to that. This is the recommended method because you'll usually have access to the Product ID via liquid. It is much easier for a future developer to read this and understand what's happening.
<div data-recommendations-insertion data-recommendations-main-product-id="1234567890"></div>
In Liquid
<div data-recommendations-insertion data-recommendations-main-product-id="{{ product.id }}"></div>
Pass the productId
value along with your configuration object.
const config = {
productId: 1234567890,
limit: 5,
};
const recs = Shopify.Recommendations(config);
recs.initialize();
In Liquid
<script>
Shopify.customVariables = {
productId: {{ product.id }}
};
</script>
const config = {
productId: window.Shopify.customVariables.productId,
limit: 5,
};
...
A template is the HTML that is displayed for each product in the recommendations widget. The template config option is a function that takes 1 argument product
, which is the product object returned from Shopify. The return vaue should be a string of HTML. The product
argument has access to all imformation that would usually be accessible when pulling product data from Shopify.
The default template looks like:
function(product) {
return(`
<div class="recommendation__product" data-recommendations-product-id="${product.id}">
<a href="${product.url}" class="recommendation__wrapper">
<div class="recommendation__product-image-wrapper">
<img class="recommendation__product-image" src="${product.featured_image}" alt="${product_title} image" />
</div>
<div class="recommendation__product-details">
<h3 class="recommendation__product-title">${product_title}</h3>
<span class="recommendation__product-price">${product_price}</span>
</div>
</a>
</div>
`);
}
Initializes a Recommendations instance and adds it to the page.
const recs = Shopify.Recommendations({ variantId: 1234567890 });
recs.initialize();
Needs documentation
Needs documentation
Needs documentation
recommendations.initialized
: Fires when a recommendation instance is initialized. The callback you will find the product data in event.detail.data
and the current instance in event.detail.context
.To see any recent changes view the CHANGELOG.
FAQs
JS recommendations widget using Shopify native recommendations API
The npm package @bva/recommendations receives a total of 0 weekly downloads. As such, @bva/recommendations popularity was classified as not popular.
We found that @bva/recommendations demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.