Skip to main content
All CollectionsSmart Search
Rebuy Smart Search support for B2B & Markets
Rebuy Smart Search support for B2B & Markets

A guide for allowing Smart Search to display correct B2B and Market pricing.

Jason Khan avatar
Written by Jason Khan
Updated over a week ago

Rebuy's Smart Search feature is an excellent tool for empowering your customers to find the products they're looking for faster and to showcase products you want them to explore.

To learn more about Smart Search and enable it on your store today, please refer to our Smart Search guide here.

Many merchants have blended stores that support wholesale customers along with customers from a variety of market locations. It's important that these customers be able to utilize Rebuy's Smart Search to it's full potential.

The steps shown below will allow you to modify Smart Search to display the correct prices for these customers while our team works to make this a natively supported feature.

The steps below involve adding code to your theme files. The code is prebuilt for you, we're simply showing you how to utilize it.

We recommend testing in a duplicate theme first before modifying your live theme.

Step 1: Create a new snippet file in your theme files

  1. Open your theme files and select the theme you want to modify.

  2. Search for "snippets", then click to add a new snippet.

  3. Name the snippet rebuy-extensions (we recommend copy and pasting this name to avoid typos).

Step 2: Adding code to your snippet file

  1. Open the newly created rebuy-extensions snippet file.

  2. Copy and paste the prebuilt code into the file. The code is below where you see "click here to view the code."

    1. No edits to the code are needed.

  3. Click Save to complete this step.

<-- Click here to view the code.

<script>
/* Modify Rebuy Search prices to support B2B and Market prices */

function updateSearchPrices(products, type) {
setTimeout(() => {
products.forEach(product => {
// console.log(type, product);

fetch(Shopify.routes.root + "products/" + product.handle + ".js")
.then((res) => res.json())
.then((data) => {
var updatedProductData = data;

// console.log(type, updatedProductData);

if (Number(product.id) === updatedProductData.id || product.productId === updatedProductData.id) {

product.price = updatedProductData.price;
product.compareAtPrice = updatedProductData.compare_at_price;

// if the product object has variants, loop over each variant and set the correct prices
if (product.variants) {
for (var j = 0, updatedProductVariant; j < updatedProductData.variants?.length; j++) {
updatedProductVariant = updatedProductData.variants[j];

for (var x = 0, productVariant; x < product.variants?.length; x++) {
productVariant = product.variants[x];

if (updatedProductVariant.id === Number(productVariant.id)) {
productVariant.price = updatedProductVariant.price;
productVariant.compareAtPrice = updatedProductVariant.compare_at_price;
break;
}
}
}
} else {
product.selected_variant.price = updatedProductData.price;
product.selected_variant.compareAtPrice = updatedProductData.compare_at_price;
}
}
});
})
}, 500)
}


/* quick view loads, update suggested products*/
document.addEventListener('rebuy:smartsearch.quickview.ready', (event) => {
setTimeout(() => {
updateSearchPrices(event.detail.smartSearchQuickView.setting.suggestedProducts, "QUICKVIEW ready");
// console.log("Quickview Ready");
}, 500)
});

/* quickview search products returned */
document.addEventListener('rebuy:smartsearch.quickview.productsChange', (event) => {
updateSearchPrices(event.detail.products, "QUICKVIEW change");
// console.log("Quickview productsChange");
});

/* results page search products returned */
document.addEventListener('rebuy:smartsearch.resultsPage.productsChange', (event) => {
setTimeout(() => {
updateSearchPrices(event.detail.products, "RESULTSPAGE");
// console.log("Results Page productsChange");
}, 500)
});



</script>

Step 3: Render the rebuy-extensions file

  1. Open your theme.liquid file.

  2. Scroll down to the closing </body> tag (use keyword search if needed).

  3. Just above the </body> tag, paste the following line:

    1. {% render "rebuy-extensions" %}

  4. Click Save.

That's it. You've now modified Rebuy's Smart Search to reflect B2B and Market prices. To ensure everything is working correctly, preview Smart Search on the same theme where you added the code.

FAQ

Q: What does this code do?

A: This code uses your product handles (different from product titles) to pull updated pricing data from Shopify and display the updated prices in Smart Search.

Q: Will this work for all merchants and themes?

A: Yes, the code will work for all themes. The limitation is on the product handles. Product handles are set on each individual product in Shopify Admin. If you modify your product handles as markets change then the code will not work.

Example:

In Shopify admin the product title and product handle are both "Silver Bracelet".

In the French market the product title (shown on the PDP) translates to "Bracelet en Argent" but the product handle (shown in the URL) remains the same "/products/silver-bracelet". The code will work here.

However if the handle also translates in French and the URL becomes "/products/bracelet-en-argent", the code will not work because in Shopify Admin no product exists with that handle, so we cannot pull updated prices.

Q: Why isn't the code working?

A: If the code isn’t functioning as expected, check the following:

  1. Correct Implementation – Ensure you've copied and pasted the code exactly as instructed and saved after each step.

  2. Cache Issues – Preview the theme in an incognito browser to make sure you're not seeing a cached version.

  3. Product Handle Consistency – Confirm that your product handles haven’t been modified in the market you're testing (see the previous question for details).

  4. If these steps all check out, please contact our Support Team.

Did this answer your question?