Announcement

Collapse
No announcement yet.

Hide Products from Search Results and Fasten Header

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Hide Products from Search Results and Fasten Header

    We have some add-on products that we hide from the search results page using the below code:
    Code:
            <mvt:if expr="NOT('PROD-CODE' CIN l.settings:product:code OR 'PROD-CODE2' CIN l.settings:product:code" >
    But the items are still appearing in the fasten header preview. I tried wrapping my conditional around this code:
    Code:
            <span class="x-search-preview t-search-preview" data-hook="search-preview" data-mm_searchfield_menu="Yes" data-mm_searchfield_id="x-search-preview"></span>
    But that didn't work. I can't quite tell what code I need to wrap the conditional around. Or maybe there is a better way to hide active products from Search?

    #2
    You might try using that conditional to wrap the Menu Item Template code under User Interface -> Search Settings -> Search Preview Settings.
    Matt Zimmermann

    Miva Web Developer
    Alchemy Web Development
    https://www.alchemywebdev.com
    Site Development - Maintenance - Consultation

    Miva Certified Developer
    Miva Professional Developer

    https://www.dev4web.net | Twitter

    Comment


      #3
      minor point...if you're going to have more than one or two products, use something like

      <mvt:if expr="NOT('|'$l.settings:product:code$'|' IN '|product_code1|product_code2|etc|'">

      this should be easier to maintain and a lot faster. Also always use IN instead of CIN if you know the value isn't going to change case (i.e., product codes wont ever change case.

      CIN takes up a lot more processing time than IN.
      Bruce Golub
      Phosphor Media - "Your Success is our Business"

      Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
      phosphormedia.com

      Comment


        #4
        Regarding hiding more than 1 products from search; I have quite a few that I've hidden so I made a custom field checkbox to mark a product if I don't want it showing in search results. Makes it easier to maintain.

        Comment


          #5
          ^^^^
          that's true as well.
          Bruce Golub
          Phosphor Media - "Your Success is our Business"

          Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
          phosphormedia.com

          Comment


            #6
            And regarding hiding search results, I use the power search module so I may be wrong here, but I believe your code would need to be entered within

            <mvt:foreach iterator="product" array="search_results:products"> on the srch page in the search results section.

            Comment


              #7
              Thanks for the tips. I was able to get Bruce's code to work, however, now there are just blank spaces where those products would have shown.

              I already have a custom field for out of stock so adding it in was simple enough but the below isn't working in the same spot that Bruce's code was working under User Interface -> Search Settings -> Search Preview Settings. The items still appear.

              Code:
              <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'stock', g.stock)" />
              <mvt:if expr="ISNULL g.stock">
              <div class="u-color-black t-search-preview__link">
                  <figure class="t-search-preview__figure">
                      <picture class="t-search-preview__picture">
                          <img class="t-search-preview__image" src="&mvte:product:imagetypes:main;" alt="&mvte:product:name;">
                      </picture>
                      <figcaption class="t-search-preview__figure-caption">
                          <span class="t-search-preview__name">&mvte:product:name;</span>
                      </figcaption>
                  </figure>
              </div>
              </mvt:if>
              Attached Files

              Comment


                #8
                It looks like, without overriding some of the search functionality, you may have to check the URI of the product page against the set of items returned for the preview. Try adding this to the User Interface -> Search Settings -> Search Preview Settings -> JavaScript Template and replace PRODUCT_URI with a valid, full product URI.
                Code:
                MMSearchField.prototype.Menu_Append_Item = function (data) {
                    let self = this;
                    let item;
                
                    if (item = this.onMenuAppendItem(data.menuitem)) {
                        item.mm_data = data;
                        item.action = data.product_link;
                        item.onclick = function (event) {
                            self.Menu_Item_OnClick(event ? event : window.event, this.action);
                        };
                        item.onmousemove = function (event) {
                            self.Event_MenuItem_MouseMove(event ? event : window.event, item);
                        };
                
                        if (item.action !== 'https://PRODUCT_URI') {
                            this.element_menu.appendChild(item);
                            this.menu_items.push(item);
                        }
                    }
                };
                Matt Zimmermann

                Miva Web Developer
                Alchemy Web Development
                https://www.alchemywebdev.com
                Site Development - Maintenance - Consultation

                Miva Certified Developer
                Miva Professional Developer

                https://www.dev4web.net | Twitter

                Comment


                  #9
                  This dev site is currently setup using Legacy SEO Settings - so I will need to change to "URI Management" for this fix correct? We plan on using URI Management anyway as we want to move away from using the product codes in the URLs. Since all of the product codes are changing anyway - it seemedd the best time to make this change.

                  We have at least 20 items we have to do this for. Can we have multiple URL's here?

                  Comment


                    #10
                    URI Management would be advised for this and, unless you change the evaluation, you would have to include each as an OR.
                    Matt Zimmermann

                    Miva Web Developer
                    Alchemy Web Development
                    https://www.alchemywebdev.com
                    Site Development - Maintenance - Consultation

                    Miva Certified Developer
                    Miva Professional Developer

                    https://www.dev4web.net | Twitter

                    Comment

                    Working...
                    X