All things Shopify and commerce
Hello community,
Since some days i try to implement this functionality without success:
I have a product with custom metafield which contains values can be grouped to obtain set of products. For example: custom_field - "model" value AA11. I have different products with the same values (but different colors) and i need show this products in product page (as grid) - similar than featured products.
I've installed app "Search & discovery" and i've made my custom filter and works well on collections but i don't know if is possible to use on product page. I've tryed also to group in the collections (best solution) but my catalog has more then 5.000 groups (max limit of collections) so i can't use this solution. Another solutions i've tryed is make a smaller collection of product (for example by manufacturer) and loop over products to find with the same metafield but loop is limited to firs 50 products, so also this solution not working.
NB: I have over 50k products on my catalog, and 1200 collections (manufacturers and navigation)
Can someone help me to find working solution for this problem?
Any suggestion will be very appreciated.
Alberto
Hello Alberto,
Custom solutions will work here.
You need to use Javascript and fetch all the products . Once you have all the products then you have to make it conditional so you will get the products which match the defined condition.
And lastly you need to add the html in it.
Sample code but keep note it need lot of modification a/to your need:
let storeProducts = [];
let fetchCalls = [];
// For 50k products I use ( i <= 20; ) change it a/to your need.
for (let i = 1; i <= 20; i++) {
fetchCalls.push(fetch('/products.json/?limit=250&page=' + i));
}
Promise.all(fetchCalls)
.then(responses => Promise.all(responses.map(response => response.json())))
.then(productsArray => {
// Flatten the array of arrays into a single array
storeProducts = productsArray.flat();
storeProducts.forEach(productsObj => {
if (productsObj.products) {
productsObj.products.forEach(product => {
// Check if the product title matches any element in the array
// You need to replace it with the metafield
if (lineBreakCount.includes(product.title)) {
// Log the match
console.log('Match found for product with title:', product);
}
});
} else {
console.log('Invalid products structure in storeProducts');
}
});
})
.catch(error => console.error('Error:', error));
Thanks
This is not the way to do this.
DO NOT force a customers browser to preload 50k items worth of information.
That type of behavior kills performance and conversion, read: lose money.
Use the section rendering api and just get a paginated collection with products
https://shopify.dev/api/section-rendering
See the dawn theme for examples of client-side section rendering.
@disual wrote:
I've tryed also to group in the collections (best solution) but my catalog has more then 5.000 groups (max limit of collections) so i can't use this solution
This often indicates something went very wrong with the businesses information architecture.
You can use tag filtering with collections to represent groups as a tradeoff in not redlining resource limits.
https://shopify.dev/docs/themes/navigation-search/filtering/tag-filtering
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
I don't think I force anyone to use it. It's an idea and helpful for those who know how Javascript works.
btw can you please let us know how much time Javascript takes for 50k products?
And can you let us know how we can do comparison using section rendering api ?
This solution work with this code: (using tag not metafield)
Consider utilizing a custom filter through the "Search & discovery" app, as it works effectively on collections. Unfortunately, the product page grid display might have limitations. If possible, explore grouping products in smaller collections or consider optimizing the loop approach for better efficiency. Keep in mind the constraints posed by the 50-product limit in the loop. Your detailed catalog structure and requirements may benefit from tailored solutions or adjustments based on specific needs.
Hi,
Yesterday I've found solution using graphql inside javascript:
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025