Announcement

Collapse
No announcement yet.

Miva9 Listing All products under multiple categories

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

  • lesliekirk
    replied
    Originally posted by aarcmedia View Post
    lesliekirk the FIX IS IN......

    Simply add this.....

    HTML Code:
    <mvt:assign name="l.settings:myProducts" value="0" />
    .....to the line just above Runtime_ProductList_Load_Offset_Category. And Boom, it works.
    Hey Ted aarcmedia - hope you are around. This fix seems to have stopped working. It's back to displaying duplicates as if to "fill space". I noticed it in this category. The Rush is supposed to be the last sub-sub-category with the Rush product. But right after it, it start back with 3 previously listed categories. It's like it tries to shift the last 3 sub-sub-categories of the previous sub-category over to "fill space".


    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--wide">
    <li class="c-form-list__item o-layout__item u-width-10--m">
    <a name="&mvte:subcat2:code;"></a>
    <h3><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:code;.html#top"><span class="u-font-small u-icon-chevron-up"></span>
    <strong class="u-color-red">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--wide">
    <div class="o-layout__item u-width-3--l">
    <mvt:do file="g.Module_Root $ '/modules/component/cmp-cssui-cattitle.mvc'" name="l.success" value="CSSUI_CatTitle_Load(l.settings:subcat2:id, l.settings:subcat2:title_image)" />
    <img src="&mvt:subcat2:title_image:image;" alt="&mvte:subcat2:name;">
    </div>
    <div class="o-layout__item u-width-9--l">
    <mvt:foreach iterator="product" array="myProducts">
    <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--wide">
    <li class="c-form-list__item o-layout__item u-width-6--m"><span>&mvt:product:name;</span>
    <mvt:if expr="NOT ISNULL l.settings:product:descrip">
    <br>&mvt:product:descrip;
    </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"> <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>
    Why would this stop working after working so nicely for a year and a half? Has something changed behind the scenes?




    Leave a comment:


  • RTHOMASDESIGN
    replied
    This is great! Thanks for the code guys :)

    Only problem I see is that the code aarcmedia provided pulls in the full-size product image. Even with lazyloading it's not going to work (for my needs)... Anyone know of a better method to produce/fetch thumbnails than the code I'm using below?

    HTML Code:
    <!-- placed outside product loop -->
    <mvt:assign name="l.settings:img:width" value="400"/>
    <mvt:assign name="l.settings:img:height" value="400"/>
    
    <!-- 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.settings: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_Dimensions( 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:image" />
    
    &mvte:image:mainthumb;


    Leave a comment:


  • aarcmedia
    replied
    OK, so thanks to developer support, I got the QTY stuff working now as well within this loop using by simply adding this little snippet just above the conditional for the qty in cart stuff, like so....

    HTML Code:
    <mvt:do file="g.Module_Library_DB" name="l.settings:product:quantity" value="Basket_Quantity(l.settings:item:basket_id, l.settings:product:id)" />
    <mvt:if expr="l.settings:product:quantity GT 0">
        <span class="x-product-layout-purchase__product-quantity u-font-tiny">
            QTY in Cart: <strong>&mvt:product:quantity;</strong>
        </span>
    </mvt:if>

    Leave a comment:


  • aarcmedia
    replied
    It works as part of the normal Category Product List loop, so it definitely goes beyond the PROD template (I have it working on the normal CTGY product page for each item now). I just can't figure out how I have to call it to work within this custom sub-category w/ products loop. I may reach out to partner support again haha. They helped get me square with the issue Leslie and I were having, so I may as well ping them and see if they'll allow me to abuse their kindness a bit more.

    Leave a comment:


  • Bruce - PhosphorMedia
    replied
    I think you'd have to come up with your own routine to loop through the basket and see if the product is in there. I believe that 'items in cart' variable is only created on Product Pages. That function could take up quite of bit of processing time BTW.

    Leave a comment:


  • aarcmedia
    replied
    For some reason, within this subcat w/ products loop, the "qty in cart" junk isn't working. What would have to be modified or called in to play in order to make this work on this custom loop the same way it works within the category product list loop?

    What's below doesn't pull anything...

    HTML Code:
    <mvt:if expr="l.settings:product:quantity GT 0">
        <span class="x-product-layout-purchase__product-quantity u-font-tiny">
            QTY in Cart: <strong>&mvt:product:quantity;</strong>
        </span>
    </mvt:if>

    Leave a comment:


  • aarcmedia
    replied
    I confirmed that worked and spit things out without getting funky and adding to rows below to make up where rows above had that dreaded "max" number of products.

    Was that what was still causing you issue? Or was it the add to cart forms? I removed the ordering mechanism from the above reply because we were doing some funky stuff there that would have convoluted this example. There is also probably a couple of items that I have planted on the page that aren't needed as well at the top of the foreach loop as I copy and pasted from the Miva examples and haven't stripped out the items not needed fully.

    I'm also a tab, not spaces kind of guy. Don't yell at me for that haha.

    Leave a comment:


  • aarcmedia
    replied
    I'd say it may be running into the normal "product" loop causing issues? Maybe try re-naming yours exactly as mine is? Here's my code exactly as I have it, stripped of the fluff......

    HTML 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:category_children" value="miva_array_elements(l.settings:subcategories)" />
                        <mvt:if expr="l.settings:subcategories GT 0">
    
                                <mvt:foreach iterator="subcategory" array="subcategories">
                                    <h2 class="u-text-uppercase"><a href="&mvte:subcategory:link;">
                                        <strong>&mvte:subcategory:name;</strong>
                                    </a></h2>
    
                                    <mvt:do name="l.doit" file="g.Module_Library_DB" value="Category_Load_Code( l.settings:subcategory:code, l.settings:thisCategory)" />
    
                                    <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:thisCategory:id, g.Offset, l.settings:null, g.NextOffset, l.settings:myProducts )" />                
                                    <table>
                                        <tr>
                                            <th>Image</th>
                                            <th>Name</th>
                                            <th>Size</th>
                                            <th>Order</th>
                                        </tr>
    
                                        <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 )" />
                                        <mvt:do name="l.success" file="g.Module_Library_DB" value="ProductImage_Load_Type(l.settings:product:id, 1, l.settings:imagetype)" />
                                        <mvt:do name="l.success" file="g.Module_Library_DB" value="Image_Load_ID(l.settings:imagetype:image_id, l.settings:imagedata)" />
                                        <mvt:assign name="g.subProductImage" value="g.baseurl $ l.settings:imagedata:image" />
                                        <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code,'product_size', g.product_size)" />        
    
    
                                        <tr>
                                            <td>
                                                <a href="&mvt:canonical_uri:uri;"><img src="&mvt:global:subProductImage;" alt="&mvt:product:name;" /></a>
                                            </td>
                                            <td><a href="&mvt:canonical_uri:uri;">&mvt:product:name;</a></td>
                                            <td nowrap>&mvt:global:product_size;</td>
                                            <td>
    
                                                <!-- add to cart form is here, I removed because we're doing funky stuff there also -->
    
                                            </td>
                                        </tr>
                                        </mvt:foreach>
                                        <!-- end .x-product-list -->
    
                                    </table>
    
                                </mvt:foreach>
    
                        <mvt:else>
                            <mvt:item name="category_listing" />
                        </mvt:if>

    Leave a comment:


  • lesliekirk
    replied
    Originally posted by aarcmedia View Post
    lesliekirk the FIX IS IN......

    Simply add this.....

    HTML Code:
    <mvt:assign name="l.settings:myProducts" value="0" />
    .....to the line just above Runtime_ProductList_Load_Offset_Category. And Boom, it works.
    Isn't that the same as this?

    Code:
    <mvt:assign name="l.settings:products" value="0" />
    If so, I'm still having issues....

    Leave a comment:


  • aarcmedia
    replied
    lesliekirk the FIX IS IN......

    Simply add this.....

    HTML Code:
    <mvt:assign name="l.settings:myProducts" value="0" />
    .....to the line just above Runtime_ProductList_Load_Offset_Category. And Boom, it works.

    Leave a comment:


  • lesliekirk
    replied
    Ted, I sent you a PM.

    Leave a comment:


  • aarcmedia
    replied
    That's exactly what I'm doing Leslie. I have what I've always used with Toolkit that I can use as a back up, but I'm trying to avoid that as this is way cooler.

    I have a ticket open. They are saying obviously that goes beyond what they can handle, but they'll ask around. We'll have much better luck here with Bruce and co chiming in as they are able or maybe someone in house will take pitty on us today and help us out with this one haha. I've tried setting the offset's to null, I've tried all variations of functions. I've tried isolating what is actually assigned from what isn't and just not showing any product within each of the loops that aren't actually assigned to that category haha. None of it worked. This wants very badly to spit out the same # of categories once the "category with the most items in it" shows, then all after it must include that many items, even if it has to pull from those above. It is very odd indeed, but I bet the solution involves tweaking less than 20 characters in our code above haha.

    May the fortune look fondly upon us Leslie :)

    Leave a comment:


  • lesliekirk
    replied
    I just realized you are having the EXACT same problem I am having while trying to replace the Toolkit code on the page I previously linked. It's like the code wants to make sure all the categories have the same number product in it. Something is squirrelly with the code that Miva Dev Support helped me with:

    <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="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.2rem; font-weight:bold;"><a name="&mvt:subcat:code;"></a><span style="color:#f00;">&mvte:subcat:name;</span></h2>
    <mvt:assign name="l.settings:sub_categories2" value=" " />
    <mvt:do name="l.result" file="g.Module_Library_DB" value="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">
    <p></p>
    <a name="&mvte:subcat2:code;"></a>
    <h3><strong style="color:#f00;">&mvte:subcat2:name;</strong>&nbsp; <a href="/&mvt:category:code;.html#top">
    <strong style="color:#f00;">Back to top</strong></a></h3>
    <mvt:comment>load first 100 products assigned to a specific category</mvt:comment>
    <mvt:assign name="l.settings:products" value="0" />
    <mvt:do name="l.result" file="g.Module_Library_DB" value="Runtime_ProductList_Load_Offset_Category( l.settings:subcat2:id, g.Offset, 100, g.NextOffset, l.settings:products )" />

    <section>
    <ul class="c-form-list o-layout o-layout--wide u-text-uppercase">
    <li class="c-form-list__item o-layout__item u-width-7--m"> <span>Name</span></li>
    <li class="c-form-list__item o-layout__item u-width-1--m"> <span>Price</span> </li>
    <li class="c-form-list__item o-layout__item u-width-4--m"> </li>
    </ul>
    </section>
    <mvt:foreach iterator="product" array="products">
    <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--wide u-text-uppercase">
    <li class="c-form-list__item o-layout__item u-width-7--m"> <span>&mvt:product:name;</span> </li>
    <li class="c-form-list__item o-layout__item u-width-1--m"> <span>&mvt:product:formatted_price; &mvt:product:price;</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" 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--huge c-control-group__button u-bg-primary u-color-black u-text-bold u-font-small u-text-uppercase">
    </li>
    </ul>
    </form>
    <hr class="c-keyline">
    </section>
    </mvt:foreach>
    </mvt:foreach>
    <mvt:assign name="l.settings:sub_categories2" value=" " />
    </mvt:if>
    </mvt:foreach>
    </mvt:if>
    My problem is with that "load first 100 products assigned to a specific category" - I don't want to load the first 100, I want to load exactly what is in the category. But it's what I was given to use to replace Toolkit code.

    Leave a comment:


  • lesliekirk
    replied
    Ted, are you trying to do something like this?

    ​​​​​​https://www.kitchencabinetdepot.com/...-cabinets.html


    Leave a comment:


  • aarcmedia
    replied
    Hey Bruce, tried that, same behavior. Any category that has fewer than the current max offset that I have set, it forces that loop to fill the difference with products from the previous. I had tried setting max to null, 0 and others and that didn't play.

    And thanks for trying to help me debug this while tiling your bathroom haha.

    Leave a comment:

Working...
X