Announcement

Collapse
No announcement yet.

Display of sub-sub-categories displaying duplicates

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

    Display of sub-sub-categories displaying duplicates

    I went back and read through my previous post regarding my sub-sub-categories template challenges and I don't think the "extra" categories being displayed issue was ever resolved. Post # 28 here

    https://www.miva.com/forums/forum/de...tegories/page2

    It's referring to the issue with categories duplicating themselves in the layout. It seems to only happen when the second column of categories (Base Cabinets) has more categories than the third column (Accessories)

    UyCqha.png


    To see what I am referring to you need to click the Rush Fee. There should be nothing following Rush Fee but instead, the two categories from the Base Cabinets are listed after the Rush Fee at the bottom of the entire list. FYI - this category doesn't have the issue. I don't think it might be the way I "sectioned" the code out (but I could be wrong).


    Code:
     <mvt:foreach array="cattree_categories" iterator="category_children">
    <mvt:if expr="l.settings:category_children:parent_id EQ l.settings:category:id">
    <mvt:assign name="l.null" value="miva_array_insert(l.settings:subcategories, l.settings:category_children, -1)" />
    </mvt:if>
    </mvt:foreach>
    <mvt:assign name="l.settings:subcategory_count" value="miva_array_elements(l.settings:subcategories)" />
    
    <section class="o-layout u-grids-1 u-grids-3--l x-product-list" style="margin-top:16px;">
    <mvt:foreach iterator="subcategory" array="subcategories">
    <div class="o-layout__item u-text-center x-product-list__item">
    
    <figure class="x-product-list__figure">
    <mvt:if expr="l.settings:subcategory:image">
    <img class="x-product-list__image" src="&mvt:subcategory:image;" alt="&mvt:subcategory:name;">
    </mvt:if>
    
    <h2 style="text-align:left; font-size:1.2rem; font-weight:bold;"><a href="&mvt:category:link;#&mvt:subcategory:code;"> <span class="u-icon-chevron-right u-color-oxide"></span> &mvte:subcategory:name;</a></h2>
    
    
    <mvt:do name="l.result" file="g.Module_Library_DB" value="Category_Load_Code( l.settings:subcategory:code, l.settings:sub_subcategory )" />
    <mvt:do name="l.result" file="g.Module_Library_DB" value="CategoryList_Load_Parent( l.settings:sub_subcategory:id, l.settings:sub_subcategories )" />
    
    <mvt:if expr="l.settings:sub_subcategories">
    <mvt:foreach iterator="sub_subcategory" array="sub_subcategories">
    <figure class="x-product-list__figure" style="text-align:left;">
    <figcaption><a href="&mvt:category:link;#&mvt:sub_subcategory:cod e;"><span class="u-icon-chevron-right u-color-oxide"></span> &mvte:sub_subcategory:name;</a>
    </figcaption>
    </figure>
    
    
    </mvt:foreach>
    <mvt:assign name="l.settings:sub_subcategory" value="''"/>
    <mvt:assign name="l.settings:sub_subcategories" value="''"/>
    </mvt:if>
    </figure>
    
    </div>
    </mvt:foreach>
    </section>
    <! -- EOF Main links -->
    <section class="o-layout">
    <div class="o-layout__item">
    <mvt:item name="subcategory_listing" />
    </div>
    </section>
    The sub-category links at the top of the page are correct. It's the content within the Item subcategory_listing that are the issue:

    Code:
    <mvt:assign name="l.settings:subcat:id" value=" " />
    <mvt:do name="l.result" file="g.Module_Library_DB" value="Category_Load_Code( g.Category_Code, l.settings:current_category )" />
    <mvt:do name="l.result" file="g.Module_Library_DB" value="Runtime_CategoryList_Load_Parent( l.settings:current_category:id, l.settings:sub_categories )" />
    <mvt:assign name="l.subcat_count" value="miva_array_elements( l.settings:sub_categories )" />
    <mvt:if expr="l.subcat_count GT 0">
    <mvt:foreach iterator="subcat" array="sub_categories">
    <h2 style="font-size:1.4rem; font-weight:bold;"><a name="&mvt:subcat:code;"></a>&mvte:subcat:name;</h2>
    <mvt:assign name="l.settings:sub_categories2" value=" " />
    <mvt:do name="l.result" file="g.Module_Library_DB" value="Runtime_CategoryList_Load_Parent( l.settings:subcat:id, l.settings:sub_categories2 )" />
    <mvt:assign name="l.subcat2_count" value="miva_array_elements( l.settings:sub_categories2 )" />
    <mvt:if expr="l.subcat2_count GT 0">
    <mvt:foreach iterator="subcat2" array="sub_categories2">
    <section>
    <p></p>
    <ul class="c-form-list o-layout o-layout--narrow">
    <li class="c-form-list__item o-layout__item u-width-10--m">
    <a name="&mvte:subcat2:code;"></a>
    <h3 style="margin-top:30px;"><strong>&mvte:subcat2:name;</strong></h3></li>
    <li class="c-form-list__item o-layout__item u-width-2--m">
    <h3> <a href="&mvt:category:link;#top"><span class="u-font-small u-icon-chevron-up"></span>
    <strong class="u-color-oxide">Back to top</strong></a></h3></li>
    </ul>
    </section>
    <mvt:comment>tweaked with Ted's code</mvt:comment>
    <mvt:assign name="l.settings:myProducts" value="0" />
    <mvt:do name="l.doit" file="g.Module_Library_DB" value="Runtime_ProductList_Load_Offset_Category( l.settings:subcat2:id, g.Offset, l.settings:null, g.NextOffset, l.settings:myProducts )" />
    <section class="o-layout o-layout--row--l o-layout--narrow">
    
    
    <div class="o-layout__item u-width-12--l">
    
    <!-- placed outside product loop -->
    <mvt:assign name="l.settings:img:width" value="160"/>
    <mvt:assign name="l.settings:img:height" value="160"/>
    
    <mvt:foreach iterator="product" array="myProducts">
    <mvt:assign name="l.uri:store_id" value="g.Store:id" />
    <mvt:assign name="l.uri:screen" value="''" />
    <mvt:assign name="l.uri:page_id" value="0" />
    <mvt:assign name="l.uri:cat_id" value="0" />
    <mvt:assign name="l.uri:product_id" value="l.settings:product:id" />
    <mvt:do file="g.Module_Feature_URI_DB" name="l.have_uri" value="URI_Load_Item_Canonical( l.uri, l.settings:canonical_uri )" />
    
    <section>
    <form class="o-layout__item u-width-12 inline-labeling ctgy-add-form" data-hook="purchase" action="&mvte:urls:BASK:auto;" method="post" name="add">
    <input type="hidden" name="Action" value="ADPR" />
    <input type="hidden" name="Product_Code" value="&mvte:product:code;" />
    <ul class="c-form-list o-layout o-layout--narrow">
    <li class="c-form-list__item o-layout__item u-width-2--m center">
    
    <!-- placed within the product loop -->
    <mvt:do file="g.Module_Library_DB" name="l.settings:sub_category:product:image_count" value="ProductImageDataList_Load_Product(l.setting s:product:id, l.settings:product:images)" />
    <mvt:foreach iterator="image" array="product:images">
    <mvt:if expr="l.settings:image:imagetype:code EQ 'main'">
    <mvt:assign name="l.settings:product:main_image" value="l.settings:image" />
    <mvt:foreachstop/>
    </mvt:if>
    </mvt:foreach>
    
    <mvt:do file="g.Module_Library_DB" name="l.result" value="GeneratedImage_FindOrInsert_Image_Dimension s( l.settings:product:main_image:image, l.settings:img:width, l.settings:img:height, l.settings:product:main_image:generated )" />
    <mvt:assign name="l.settings:image:mainthumb" value="l.settings:product:main_image:generated:ima ge" />
    <mvt:item name="customfields" param="Read_Product_ID(l.settings:product:id, 'index', l.settings:product:index)" />
    <mvt:if expr="NOT ISNULL l.settings:product:index">
    <a data-mm-linktype="product-list-link" href="&mvt:canonical_uri:uri;">
    <mvt:if expr="l.settings:image:mainthumb">
    <img src="&mvte:image:mainthumb;" alt="&mvte:product:name;" />
    <mvt:else>
    <img src="graphics/00000001/image-coming-soon_160x160.png" alt="&mvte:product:name;" />
    </mvt:if>
    </a>
    <mvt:else>
    <mvt:if expr="l.settings:image:mainthumb">
    <img src="&mvte:image:mainthumb;" alt="&mvte:product:name;" />
    <mvt:else>
    <img src="graphics/00000001/image-coming-soon_160x160.png" alt="&mvte:product:name;" />
    </mvt:if>
    </mvt:if>
    </li>
    <li class="c-form-list__item o-layout__item u-width-4--m">
    <mvt:item name="customfields" param="Read_Product_ID(l.settings:product:id, 'index', l.settings:product:index)" />
    <mvt:item name="customfields" param="Read_Product_ID(l.settings:product:id, 'prod_name_postfix', l.settings:product:prod_name_postfix)" />
    
    
    <mvt:if expr="NOT ISNULL l.settings:product:index">
    <a href="&mvt:canonical_uri:uri;"><span>&mvt:product: name; &mvt:product:prod_name_postfix;</span></a>
    <mvt:else>
    <span>&mvt:product:name; &mvt:product:prod_name_postfix;</span>
    </mvt:if>
    
    
    <mvt:item name="customfields" param="Read_Product_ID(l.settings:product:id, 'notes', l.settings:product:notes)" />
    <mvt:if expr="NOT ISNULL l.settings:product:notes">
    <br><div class="custom-field" id="customfields-notes"><span class="bold">Notes:</span> &mvt:product:notes;</div>
    </mvt:if>
    </li>
    <li class="c-form-list__item o-layout__item u-width-2--m">
    <mvt:if expr="l.settings:product:base_price GT l.settings:product:price">Was <s>&mvt:product:formatted_base_price;</s> Now
    </mvt:if> <span>$<mvt:eval expr="l.settings:product:price ROUND 2" /></span></li>
    <li class="c-form-list__item o-layout__item u-width-1--m"><span>
    <input class="form-control form-control-sm col-sm-4 text-center float-right cart-quantity ctgyQuantity" autocomplete="off" style="margin:0 auto" type="tel" min="0" name="Quantity" value="1">
    </span></li>
    <li class="c-form-list__item o-layout__item u-width-3--m">
    <input type="submit" value="Add to Cart" class="ctgyCart c-button c-button--full c-button--large c-control-group__button u-bg-primary u-color-yellow u-text-bold u-font-small u-text-uppercase">
    </li>
    </ul>
    </form>
    <hr class="c-keyline">
    </section>
    </mvt:foreach>
    
    </div>
    </section>
    </mvt:foreach>
    
    <mvt:assign name="l.settings:sub_categories2" value=" " />
    </mvt:if>
    </mvt:foreach>
    </mvt:if>

    Also still have a problem with not being able to use any of the price tokens.

    But the more important issue is needing to stop the duplication of categories below what should be the last category.
    Leslie Kirk
    Miva Certified Developer
    Miva Merchant Specialist since 1997
    Previously of Webs Your Way
    (aka Leslie Nord leslienord)

    Email me: [email protected]
    www.lesliekirk.com

    Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

    #2
    Assigning the value 0 to l.settings:myProducts doesn't seem to be actually clearing the array, so when there are fewer products in the subsequent sub-sub-cat, the ones from the previous iteration are still there. You might want to look at using https://docs.miva.com/mivascript/miva_array_delete instead.

    Comment


      #3
      Originally posted by Leanne View Post
      Assigning the value 0 to l.settings:myProducts doesn't seem to be actually clearing the array, so when there are fewer products in the subsequent sub-sub-cat, the ones from the previous iteration are still there. You might want to look at using https://docs.miva.com/mivascript/miva_array_delete instead.
      Thanks Leanne. I wish the link had actual examples. I learn by examples...
      Leslie Kirk
      Miva Certified Developer
      Miva Merchant Specialist since 1997
      Previously of Webs Your Way
      (aka Leslie Nord leslienord)

      Email me: [email protected]
      www.lesliekirk.com

      Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

      Comment


        #4
        So, something like...

        Replace this:

        Code:
        <mvt:comment>tweaked with Ted's code</mvt:comment>
        <mvt:assign name="l.settings:myProducts" value="0" />
        <mvt:do name="l.doit" file="g.Module_Library_DB" value="Runtime_ProductList_Load_Offset_Category( l.settings:subcat2:id, g.Offset, l.settings:null, g.NextOffset, l.settings:myProducts )" />

        With this:

        Code:
        <mvt:comment>tweaked with Ted's code</mvt:comment>
        <mvt:assign name="g.count" value="miva_array_elements(l.settings:myProducts)" />
        <mvt:if expr="g.count GT 0">
             <mvt:assign name="g.return_value" value="miva_array_delete( l.settings:myProducts, 1, g.count )" />
        </mvt:if>
        <mvt:do name="l.doit" file="g.Module_Library_DB" value="Runtime_ProductList_Load_Offset_Category( l.settings:subcat2:id, g.Offset, l.settings:null, g.NextOffset, l.settings:myProducts )" />
        Not tested, so it may need some tweaking.

        Comment


          #5
          Originally posted by Leanne View Post
          So, something like...

          Replace this:

          Code:
          <mvt:comment>tweaked with Ted's code</mvt:comment>
          <mvt:assign name="l.settings:myProducts" value="0" />
          <mvt:do name="l.doit" file="g.Module_Library_DB" value="Runtime_ProductList_Load_Offset_Category( l.settings:subcat2:id, g.Offset, l.settings:null, g.NextOffset, l.settings:myProducts )" />

          With this:

          Code:
          <mvt:comment>tweaked with Ted's code</mvt:comment>
          <mvt:assign name="g.count" value="miva_array_elements(l.settings:myProducts)" />
          <mvt:if expr="g.count GT 0">
          <mvt:assign name="g.return_value" value="miva_array_delete( l.settings:myProducts, 1, g.count )" />
          </mvt:if>
          <mvt:do name="l.doit" file="g.Module_Library_DB" value="Runtime_ProductList_Load_Offset_Category( l.settings:subcat2:id, g.Offset, l.settings:null, g.NextOffset, l.settings:myProducts )" />
          Not tested, so it may need some tweaking.
          Thanks, Leanne. As is, it made no difference.

          Leslie Kirk
          Miva Certified Developer
          Miva Merchant Specialist since 1997
          Previously of Webs Your Way
          (aka Leslie Nord leslienord)

          Email me: [email protected]
          www.lesliekirk.com

          Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

          Comment


            #6
            Oops, I was targeting the wrong array. Try this?

            Replace:

            Code:
            <h2 style="font-size:1.4rem; font-weight:bold;"><a name="&mvt:subcat:code;"></a>&mvte:subcat:name;</h2>
            
            <mvt:assign name="l.settings:sub_categories2" value=" " />
            
            <mvt:do name="l.result" file="g.Module_Library_DB" value="Runtime_CategoryList_Load_Parent( l.settings:subcat:id, l.settings:sub_categories2 )" />
            <mvt:assign name="l.subcat2_count" value="miva_array_elements( l.settings:sub_categories2 )" />

            With:

            Code:
            <h2 style="font-size:1.4rem; font-weight:bold;"><a name="&mvt:subcat:code;"></a>&mvte:subcat:name;</h2>
            
            <mvt:comment>Clear subcat2 array if exists</mvt:comment>
            
            <mvt:if expr="l.subcat2_count GT 0">
            <mvt:assign name="g.return_value" value="miva_array_delete( l.settings:sub_categories2, 1, l.subcat2_count )" />
            </mvt:if>
            
            <mvt:do name="l.result" file="g.Module_Library_DB" value="Runtime_CategoryList_Load_Parent( l.settings:subcat:id, l.settings:sub_categories2 )" />
            <mvt:assign name="l.subcat2_count" value="miva_array_elements( l.settings:sub_categories2 )" />

            Comment


              #7
              Thank you Leanne - that was just what it needed! Much appreciated.
              Leslie Kirk
              Miva Certified Developer
              Miva Merchant Specialist since 1997
              Previously of Webs Your Way
              (aka Leslie Nord leslienord)

              Email me: [email protected]
              www.lesliekirk.com

              Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

              Comment

              Working...
              X