↑↓ selectEnter openEsc close

    1. Elbuz

    How to connect the cart, wishlist and comparison to the smart search window

    3 min readUpdated

    The “Buy”, “Add to wishlist” and “Add to comparison” buttons in the Elbuz search window call your site's JavaScript: the product goes into the site cart from search. For common CMSs the app fills it in.

    When you need this:

    • Cards in search lack a “Buy” button — it appears with add-to-cart code.
    • Your site is on OpenCart, WooCommerce, Magento, Horoshop or Elbuz CMS — choosing the CMS fills all six fields.
    • The Elbuz catalog has no product ID from your CMS — the widget reads it from the product page.

    Where to start: the “Setup” tab → choose “CMS ID” → check the code on the “Events” tab.

    What action buttons in the search window can do

    Which buttons appear on the product card at all is set on the “View” tab — action buttons.

    How to get ready-made code for your CMS

    On the “Setup” tab, in the “Site and search box” card, choose “CMS ID”, and for OpenCart also “CMS theme”. The app fills in the button code on the “Events” tab, the selectors, the styles the CMS needs and page addresses, and for Horoshop also “Product ID extraction”. Empty fields are filled right away; before replacing what you've already entered, the app lists the fields and asks: “Replace”, “Fill empty only” or “Cancel”. Details: what choosing a CMS fills in.

    CMS IDWhat code is filled in
    OpenCartall six actions; with the OCT ShowCase, OCT Deals or OCT Promo theme, the code also updates the cart, wishlist and comparison counters in the theme header
    Elbuz CMS, WooCommerce (WordPress), Magento (Adobe Commerce), Horoshopall six actions
    Shopifyonly adding to and removing from the cart
    PrestaShop, BigCommerce, Squarespace Commerceno code — the fields stay as they are, you write the code yourself

    For WooCommerce, wishlist and comparison work only with separate plugins for these lists on the site.

    What each button's code does

    The “JS code for buttons and events” card has six fields: “Add to cart”, “Remove from cart”, “Add to wishlist”, “Remove from wishlist”, “Add to comparison”, “Remove from comparison”. The code runs in the shopper's browser when they click the matching button in the search window.

    • The “Buy” button appears on the card only when all of these hold: it's turned on in the “View” tab, the product is in stock, the “Add to cart” field is filled in, and the product has an ID from the CMS or ID extraction is filled in. Without code there's no button.
    • Wishlist and comparison appear even without code: the product goes into the list inside the search window, but nothing reaches your site's lists.
    • Code with an error — the action on the site doesn't happen, and the shopper sees a widget window with an error.
    The “JS code for buttons and events” card with the code inserted by choosing the OpenCart CMS and the OCT Deals theme
    1Add to cart
    2Remove from cart
    3Wishlist
    4Comparison
    1. The code runs in the shopper's browser; the product ID in the CMS is productData.id_ext.
    2. Without add-to-cart code there is no “Buy” button on the card.
    3. Adding and removing are separate fields.
    4. The code was inserted by choosing “CMS ID” and “CMS theme”.

    What product data the code receives

    The code has the productData variable — the product whose button was clicked. The code that removes from lists receives the same CMS ID as the add code, including one taken from the product page.

    FieldWhat it contains
    productData.idproduct ID in Elbuz
    productData.id_extproduct ID in your CMS — this is what the site cart expects
    productData.name, sku, mpnname, store SKU, manufacturer part number
    productData.pricethe price as shown on the card, with the currency sign
    productData.url, image_urlproduct page address and photo
    productData.category_id, category, brandcategory and brand

    Besides the product, the code has showCartSuccessModal and showErrorModal — the widget's “Product added” and “Error” windows — and fetch for a request to the site.

    An example for an OpenCart cart that expects the product ID in the CMS:

    fetch('index.php?route=checkout/cart/add', {
      method: 'POST',
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      body: new URLSearchParams({product_id: productData.id_ext, quantity: 1})
    });

    How to take the product ID from a site page

    The site cart accepts a product by its ID in the CMS. When the Elbuz catalog has no such ID — the catalog was built not by exporting to the site but from another source — fill in the “Product ID extraction” card on the “Events” tab.

    • “CSS selector or Regex to extract product ID from page” — what to look for on the product page.
    • “Extraction type” — CSS (default) or Regex.
    • “Always extract ID from product page, even if id_ext is filled” — when the catalog has an ID, but not the one the cart needs.

    What happens when the shopper clicks a button:

    1. If the product has an ID from the CMS and the “Always…” checkbox is cleared, that ID is used and the page isn't loaded.
    2. Otherwise the shopper's browser loads the product page using its link from search.
    3. For CSS, the first element found is used: its field value, the data-id or data-product-id attribute, the content attribute or the text — whichever is found first.
    4. For Regex, the first group in parentheses is used: "product_id":\s*(\d+) gives a number.
    5. The ID found goes into productData.id_ext, and the button code runs. Repeated clicks on the same site page don't load the product page again.

    If the page didn't open or nothing was found, the button code runs with the ID it had. That's why product links must lead to your site — see the product URL template.

    The “Product ID extraction” card: a CSS selector of the element with the ID on the product page
    1What to look for
    2CSS or Regex
    3Always from the page
    1. The product page element holding its ID in the CMS.
    2. Regex takes the first group in parentheses.
    3. Even when the catalog has the CMS ID.

    Scenarios

    An OpenCart site with the OCT Deals theme

    What to do. Enter the “Site address”, choose OpenCart in “CMS ID” and OCT Deals in “CMS theme”.

    What you get. Buttons in the search window put the product into the site cart and update the counters in the theme header; below the cart list in the search window there are buttons to go to the cart and to checkout.

    The catalog is built from suppliers and has no site product IDs

    What to do. Find an element with the ID on your site's product page — for example, the hidden field input[name="product_id"] — and enter it in “CSS selector or Regex to extract product ID from page”.

    What you get. On the first click, the widget opens the product page in the background, takes the ID and passes it to the site cart.

    You need your own action after adding

    What to do. At the end of the “Add to cart” code, add your own call, for example opening your theme's side cart.

    What you get. After adding, the shopper sees the site cart right away.

    What to do when a button doesn't work

    What you seeWhyWhat to do
    The card has no “Buy” buttonthe “Add to cart” code is empty, the product is out of stock, or there's no product ID from the CMSchoose the CMS or enter the code; fill in “Product ID extraction”
    The product is in the wishlist in the search window but not on the sitethe code field for this action is emptychoose the CMS or enter the code
    The wrong product is addedthe code uses productData.id instead of id_extpass productData.id_ext to the cart
    The site cart responds with a “product not found” errorthe CMS product ID in the catalog differs from the one on the sitefill in “Product ID extraction” and turn on “Always extract…”

    FAQ

    Why do product cards in search have no “Buy” button?

    It appears only with “Add to cart” code, for in-stock products and with a product ID from the CMS. Choose the CMS or enter the code, and fill in “Product ID extraction” if needed.

    What should I choose for an Elbuz CMS store?

    Elbuz CMS in “CMS ID”. For a store created in Elbuz, search is set up automatically when the store is created.

    How do I open the theme's side cart after adding?

    Add a call that opens your theme's cart at the end of the “Add to cart” code. For OpenCart with OCT themes, the code already does this.

    Which is better — CSS or Regex?

    CSS, if the ID is in an attribute or a page field. Regex, if the ID is only in the text of a page script.

    Does ID extraction slow down the button?

    Only the first click on a product: the browser loads its page. Repeated clicks on the same page use the ID already found.

    Where it is and who has access

    Menu
    Directories → Categories → the “Widget settings - Smart search” tile → the “Events” tab
    Other entry points
    ready-made code — the “Setup” tab, the “CMS ID” and “CMS theme” fields
    Access right
    the “Smart product search widget” window in “Group permissions”
    Prepare
    know how your site's cart adds a product

    Related topics

    Was this article helpful?

    Missing a feature? Tell us.

    We will add it for free if other users need it too.

    If only you need it, we will agree on it separately.

    Article contents

    Suggest an improvement

    Try Elbuz free