API search help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fastees
    Mivite

    • Dec 2007
    • 194

    #1

    API search help

    We are trying to suppress products from displaying in the auto complete in the main search field in the global header. These products all have one thing in common. They have a sales reps name in a custom field called SalesRep. This code is located on the api page in the main template. Here is the code that I am attempting and it does not work:

    <mvt:foreach iterator="product" array="ac:products">
    <mvt:if expr="NOT ISNULL l.settings:product:customfield_values:customfields :SalesRep">
    <mvt:foreachcontinue/>
    </mvt:if>
    <li><a href="&mvt:product:link;"><b>&mvt:product:code;</b> - &mvt:product:name;</a></li>
    </mvt:foreach>

    As a work around, since the client does not use the cost field, I populated the cost fields for these products with .01 and this does work:


    <mvt:foreach iterator="product" array="ac:products">
    <mvt:if expr=" '.01' CIN l.settings:product:cost ">
    <mvt:foreachcontinue/>
    </mvt:if>
    <li><a href="&mvt:product:link;"><b>&mvt:product:code;</b> - &mvt:product:name;</a></li>
    </mvt:foreach>

    It seems to work fine with regular product fields but I need the code that will query custom fields please.
  • Leanne
    Mega Mivite






    • Mar 2006
    • 2666

    #2
    Is the custom product field assigned to the page?

    Comment

    • fastees
      Mivite

      • Dec 2007
      • 194

      #3
      Make sure you understand that this is on the API page that generates the auto complete function for the search engine in the Global header of a Levels Readytheme. Yes I have the item custom fields assigned to the page. This page does not have a product display template so there is not a way to assign the custom field itself to a product list or product display field. I did assign the search product list item to the page and assigned that custom field to it and that did not work. I think the problem is either in my coding or it just will not work with custom fields.

      K

      Comment

      • Kent Multer
        Mega Mivite









        • Mar 2006
        • 3256

        #4
        You can read and write specific custom fields using the functions described here: http://docs.miva.com/template-langua...-documentation. They're pretty versatile; you should be able to get what you need with one of them.
        Kent Multer
        Magic Metal Productions
        http://TheMagicM.com
        * Web developer/designer
        * E-commerce and Miva
        * Author, The Official Miva Web Scripting Book -- available on-line:
        http://www.amazon.com/exec/obidos/IS...icmetalproducA

        Comment

        • fastees
          Mivite

          • Dec 2007
          • 194

          #5
          So whats wrong with this?

          <mvt:foreach iterator="product" array="ac:products">
          <mvt:if expr="NOT ISNULL l.settings:product:customfield_values:customfields :SalesRep">
          <mvt:foreachcontinue/>
          </mvt:if>
          <li><a href="&mvt:product:link;"><b>&mvt:product:code;</b> - &mvt:product:name;</a></li>
          </mvt:foreach>

          Comment

          • Brennan
            Super Moderator









            • Jun 2009
            • 3481

            #6
            The code you have should work assuming you have the SalesRep field assigned to the page. The way you're referencing the custom field is the "old" way to call in custom fields and requires the field be assigned to the page.

            Here would be some code that should work using the "new" custom field functions. These don't require the custom field to first be assigned to the page to use.

            Code:
            <mvt:foreach iterator="product" array="ac:products">
            
            <mvt:assign name="l.sales_rep" value="''" />
            <mvt:item name="customfields" param="load_product_code(l.settings:product:code, 'SalesRep', l.sales_rep)" />
            
                <mvt:if expr="ISNULL l.sales_rep">
                    <li><a href="&mvt:product:link;">&mvt:product:name;</a></li>
                </mvt:if>
            
            </mvt:foreach>
            Brennan Heyde
            VP Product
            Miva, Inc.
            [email protected]
            https://www.miva.com

            Comment

            • Kent Multer
              Mega Mivite









              • Mar 2006
              • 3256

              #7
              In the above example, the command name "load_product_code" should actually be "Read_Product_Code" (unless there's an undocumented feature that I didn't know about).
              Kent Multer
              Magic Metal Productions
              http://TheMagicM.com
              * Web developer/designer
              * E-commerce and Miva
              * Author, The Official Miva Web Scripting Book -- available on-line:
              http://www.amazon.com/exec/obidos/IS...icmetalproducA

              Comment

              • fastees
                Mivite

                • Dec 2007
                • 194

                #8
                I did try this as is and then tried a couple variations and it did not work. I am doing this on jantecneon.com and all products that start with code q- have something in the custom field with the code SalesRep. I do not have the code that you sent installed right now. I have the code using the cost field and it works but the client needs that field. I appreciate your feedback.

                K

                Comment

                • fastees
                  Mivite

                  • Dec 2007
                  • 194

                  #9
                  I just tried both Brennan and Kent's version and neither works.

                  K

                  Comment

                  • Dan - Glendale Designs
                    Mega Mivite


                    • Sep 2006
                    • 2904

                    #10
                    Try this:
                    Code:
                    <mvt:foreach iterator="product" array="ac:products">
                    <mvt:assign name="l.settings:sales_rep" value="''" />
                        <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'SalesRep', l.settings:sales_rep)" />
                        <mvt:if expr="ISNULL l.settings:sales_rep">
                            <li><a href="&mvt:product:link;">&mvt:product:name;</a></li>
                        </mvt:if>
                    </mvt:foreach>

                    Comment

                    • fastees
                      Mivite

                      • Dec 2007
                      • 194

                      #11
                      That works! Nice job Dan and thanx to all that pitched in. I did send you a client named Bruce to move some reviews and he bought your mod. I've sent several clients in the last few years.

                      Thanks Again.

                      Kevin

                      Comment

                      Working...
                      X