Announcement

Collapse
No announcement yet.

Category List and Breadrcump Trail in Miva Feed

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

    Category List and Breadrcump Trail in Miva Feed

    I built comma separated category list, and breadrumb trails in one of my Miva Feeds. I went based off the following code snippets:
    https://docs.miva.com/code-samples/assigned-categories (for the category list)
    https://gist.github.com/jtmurch42/c2...d4077d93f3f9c4 (for breadcrumbs)

    The Category List works fine. The issue is if a product does not have a category assigned, the breadcrumb will populate with the previous products breadcrumb. How can I get it to leave the breadcrumbs blank if the product is not assigned to any category? I tried various conditionals with no success.

    PLEASE HELP!!!!

    #2
    If you post the code snippet that does not work, it might be easier to answer the question.
    Ray Yates
    "If I have seen further, it is by standing on the shoulders of giants."
    --- Sir Isaac Newton

    Comment


      #3
      Yes, that would help, wouldn't it? (I meant to then forgot).

      Here is the entire code (in case something else is causing the issue:

      Code:
      <mvt:assign name="g.tab" value="asciichar(9)"/>
      <mvt:comment>
      | This code finds and renders the correct full image url for the product
      </mvt:comment>
      <mvt:if expr="NOT ISNULL l.settings:record:customfield:main">
          <mvt:assign name="g.full_image_path" value="g.domain:base_url $ l.settings:record:customfield:main" />
      <mvt:elseif expr="NOT ISNULL l.settings:record:customfield:image_url_med">
          <mvt:assign name="g.full_image_path" value="g.domain:base_url $ l.settings:record:customfield:image_url_med" />
      <mvt:elseif expr="NOT ISNULL l.settings:record:image">
          <mvt:assign name="g.full_image_path" value="g.domain:base_url $ l.settings:record:image" />
      <mvt:else>
          <mvt:assign name="g.full_image_path" value="''" />
      </mvt:if>
      <mvt:comment>
      | Lookup Categories each product is assigned to and output them as a single
      | pipe (|) seperated list
      </mvt:comment>
      <mvt:assign name="g.assigned_categories" value="''" />
      <mvt:assign name="g.category_list" value="''" />
      <mvt:do name="l.result" file="g.Module_Library_DB" value="CategoryList_Load_Offset_Product_Assigned(l.settings:record:id,0,'','',0,l.null, g.assigned_categories )" />
      <mvt:if expr="NOT ISNULL g.assigned_categories">
        <mvt:assign name="g.category_list" value="''" />
        <mvt:foreach iterator="category" array="global:assigned_categories">
          <mvt:assign name="g.category_list" value="g.category_list $ l.settings:category:code $ ','" />
        </mvt:foreach>
        <mvt:assign name="g.category_list" value="substring( g.category_list, 1, len( g.category_list )-1 )" />
      <mvt:comment>
        <mvt:assign name="g.category_list" value="miva_csv_encode( g.category_list, ',' )" />
      </mvt:comment>
      <mvt:comment>
      | This code finds and renders all possible category paths to the product
      </mvt:comment>
      <mvt:do file="g.Module_Library_DB" name="l.success" value="CategoryList_Load_Offset_Product_Assigned( l.settings:record:id, 0, 1, 'active', 999, l.next, l.settings:product:categories )" />
      <mvt:assign name="l.settings:product:category_path_length" value="1" />
      <mvt:assign name="l.settings:product:full_category_path" value="''" />
      <mvt:foreach iterator="cat" array="product:categories">
          <mvt:assign name="l.temp_category_string" value="''" />
          <mvt:assign name="l.parent_id" value="l.settings:cat:parent_id" />
          <mvt:while expr="l.parent_id NE 0">
              <mvt:do file="g.Module_Library_DB" name="l.success" value="Category_Load_ID( l.parent_id, l.loaded_category )" />
              <mvt:assign name="l.parent_id" value="l.loaded_category:parent_id" />
              <mvt:assign name="l.temp_category_string" value="l.loaded_category:name $ ' >> ' $ l.temp_category_string" />
          </mvt:while>
          <mvt:if expr="l.temp_category_string">
              <mvt:assign name="l.temp_category_string" value="l.temp_category_string $ l.settings:cat:name " />
          <mvt:else>
              <mvt:assign name="l.temp_category_string" value="l.settings:cat:name" />
          </mvt:if>
          <mvt:if expr="len(l.temp_category_string) GE l.settings:product:category_path_length">
              <mvt:assign name="l.settings:product:category_path_length" value="len(l.temp_category_string)" />
              <mvt:assign name="l.settings:product:full_category_path" value="l.temp_category_string" />
          </mvt:if>
      </mvt:foreach>
      
      </mvt:if>
      
      <mvt:comment>This code finds and renders all possible Descriptions for the product</mvt:comment>
      <mvt:if expr="NOT ISNULL l.settings:record:customfield:features_intro">
          <mvt:assign name="l.settings:full_description" value="l.settings:record:customfield:features_intro $ l.settings:record:customfield:features_intro2 $ l.settings:record:customfield:features1 $ l.settings:record:customfield:features2" />
      <mvt:else>
          <mvt:assign name="l.settings:full_description" value="l.settings:record:descrip" />
      </mvt:if>
      <mvt:comment>Strip HTML from Description</mvt:comment>
      <mvt:assign name="l.stripped_descrip" value="l.settings:full_description" />
      <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip,'</li>','. ')" />
      <mvt:if expr="('<' IN l.stripped_descrip) AND ('>' IN l.stripped_descrip)">
        <mvt:assign name="l.tag_out" value="''" />
        <mvt:assign name="l.pos" value="1" />
        <mvt:while expr="l.pos LE len(l.stripped_descrip)">
          <mvt:if expr="substring(l.stripped_descrip,l.pos,1) EQ '<'">
            <mvt:while expr="l.pos LE len(l.stripped_descrip)">
              <mvt:if expr="substring(l.stripped_descrip,l.pos,1) EQ '>'">
                <mvt:whilestop />
              </mvt:if>
              <mvt:assign name="l.pos" value="l.pos + 1" />
            </mvt:while>
          <mvt:else>
            <mvt:assign name="l.tag_out" value="l.tag_out $ substring(l.stripped_descrip,l.pos,1)" />
          </mvt:if>
          <mvt:assign name="l.pos" value="l.pos + 1" />
        </mvt:while>
        <mvt:assign name="l.stripped_descrip" value="l.tag_out"/>
        <mvt:if expr="('<' IN l.stripped_descrip) OR ('>' IN l.stripped_descrip)">
          <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip,'<','')" />
          <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip,'>','')" />
        </mvt:if>
      <mvt:else>
        <mvt:if expr="('<' IN l.stripped_descrip) OR ('>' IN l.stripped_descrip)">
          <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip,'<','')" />
          <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip,'>','')" />
        </mvt:if>
      </mvt:if>
      <mvt:assign name="l.stripped_descrip" value="ltrim(l.stripped_descrip )" />
      <mvt:assign name="l.stripped_descrip" value="rtrim( l.stripped_descrip )" />
      <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip, asciichar(10), '')" />
      <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip, asciichar(13), '')" />
      <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip, asciichar(09), '')" />
      <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip, asciichar(44), '')" />
      <mvt:assign name="l.stripped_descrip" value="glosub(l.stripped_descrip, asciichar(32) $ asciichar(32) $ asciichar(32), ' ')" />
      <mvt:assign name="l.settings:stripped_descrip" value="glosub(l.stripped_descrip, asciichar(32) $ asciichar(32), ' ')" />
      <mvt:comment>
      <mvt:assign name="l.settings:stripped_descrip" value="substring_var(l.stripped_descrip, 1, 160)" />
      </mvt:comment>
      &mvt:record:code;&mvt:global:tab;&mvt:global:category_list;&mvt:global:tab;&mvt:product:full_category_path;&mvt:global:tab;&mvt:record:customfield:producttype-google;&mvt:global:tab;&mvt:record:name;&mvt:global:tab;&mvt:record:customfield:extname;&mvt:global:tab;&mvt:record:url;&mvt:global:tab;&mvt:record:price;&mvt:global:tab;&mvt:record:customfield:hazmatind;&mvt:global:tab;&mvt:record:customfield:truckind;&mvt:global:tab;&mvt:record:code;&mvt:global:tab;&mvt:record:customfield:googleproductcategory;&mvt:global:tab;&mvt:record:url;&mvt:global:tab;&mvt:record:code;&mvt:global:tab;&mvt:record:cost;&mvt:global:tab;&mvt:record:customfield:brand;&mvt:global:tab;&mvt:global:full_image_path;&mvt:global:tab;&mvt:stripped_descrip;&mvt:global:tab;&mvt:record:customfield:noStock;&mvt:global:tab;&mvt:record:customfield:country_of_origin;&mvt:global:tab;&mvt:record:customfield:mfrpartnumber;&mvt:global:tab;&mvt:record:customfield:badge1;&mvt:global:tab;&mvt:record:customfield:popcodes;&mvt:global:tab;&mvt:record:customfield:searchboost;&mvt:eol:crlf;

      Comment


        #4
        breadcrubs-screenshot.png


        Here is a sample of output. You will see that the 2 GWT products are pulling the breadcrumbs from the previous product that was actually assigned to a category. I need the breadcrumbs to be blank if the category_code is blank.

        Comment


          #5
          It appeared from your description that a variable is not getting cleared.

          After line 38 try clearing l.loaded_category as shown below and testing the return value from Category_Load_ID()

          Code:
          <mvt:foreach iterator="cat" array="product:categories">
              <mvt:assign name="l.temp_category_string" value="''" />
          <mvt:assign name="l.loaded_category" value="''" />
              <mvt:assign name="l.parent_id" value="l.settings:cat:parent_id" />
              <mvt:while expr="l.parent_id NE 0">
                  <mvt:do file="g.Module_Library_DB" name="l.success" value="Category_Load_ID( l.parent_id, l.loaded_category )" />
          <mvt:if expr="l.loaded_category:parent_id">
                      <mvt:assign name="l.parent_id" value="l.loaded_category:parent_id" />
                      <mvt:assign name="l.temp_category_string" value="l.loaded_category:name $ ' >> ' $ l.temp_category_string" />        
          </mvt:if>
              </mvt:while>
          Ray Yates
          "If I have seen further, it is by standing on the shoulders of giants."
          --- Sir Isaac Newton

          Comment


            #6
            Ray,

            I tried your solution, but it came up a little short. I ended up changing my code from

            Code:
            <mvt:assign name="l.settings:product:full_category_path" value="''" />
            
            to
            
            <mvt:assign name="l.settings:product:categories" value="''" />
            That worked to clear it out.

            Thank you for your response and insight.

            Comment

            Working...
            X