Announcement

Collapse
No announcement yet.

Is this a good way to show related products on BASK?

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

    Is this a good way to show related products on BASK?

    Using Shadows, I tried adding the related_products item to the BASK page, but that didn't seem to do much. So I threw together some manual code to pull the related items and print out a basic list, but since I'm new to these frameworks / themes I'm wondering if this is the 'right' way to do it, or if there's a built-in thing that I should use instead?


    HTML Code:
       <div class="relatedProducts">
          <mvt:foreach array="basket:groups" iterator="group">
             <mvt:do file="g.Module_Feature_RPD_DB" name="l.success" value="RelatedProductList_Customer_Load_Product(g. basket:cust_id, l.settings:group:product:id, l.settings:relatedProducts)" />
             <mvt:foreach array="relatedProducts" iterator="relatedProduct">
                <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:relatedProduct: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:if expr="l.have_uri">
                   <a href="&mvt:canonical_uri:uri;" class="relatedProduct">
                      <div>
                         <mvt:do name="l.success" file="g.Module_Library_DB" value="ProductImage_Load_Type(l.settings:relatedProduct:id, 1, l.settings:main)" />
                         <mvt:do file="g.Module_Library_DB" name="l.success" value="GeneratedImage_Load_ID(l.settings:main:image_id, l.settings:thumb)" />
                         <img src="&mvt:thumb:image;" alt="&mvte:relatedProduct:name;">
                         <br><b>&mvte:relatedProduct:name;</b>
                         <br>&mvte:relatedProduct:price;
                      </div>
                   </a>
                </mvt:if>
             </mvt:foreach>
          </mvt:foreach>
       </div>
    Looking for work as of March 2024! I've been a web developer for going on 20 years, with most of that time spent on Miva sites.

    #2
    Nothing really built into shadows or even miva for that matter. Your approach sounds great if you don't need a difference between Related Products and Basket Upsell.

    The other general approach if you don't use the related products array is to just use a custom field with a character dilminated list of product codes and just step through those and call the product_load_code() function. (or use those codes to create a complete array structure so you can then just use mvt:foreach on l.settings:myUpsellItems)
    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


      #3
      If there are more than one item in the basket:group you may be displaying the same related product several times or displaying a related product that is already in the basket which could be confusing to the user.

      You may need to add logic to display only unique items and to test if the related item is already in the basket.

      I'm not sure if miva has a unique sort function like _underscore but this comparison snippet may help:

      Code:
      <mvt:foreach iterator="sort_rel_product" array="sort_rel_products">
      <mvt:assign name="g.compare" value="l.settings:sort_rel_product" />
      <mvt:assign name="g.uniquendx" value="g.uniquendx + 1" />
      <mvt:assign name="g.contrastndx" value="g.uniquendx + 1" />
      <mvt:item name="ry_toolbelt" param="assign|g.contrast|l.all_settings:sort_rel_products[g.contrastndx]" />
      <mvt:if expr="g.compare NE g.contrast">
      <mvt:item name="ry_toolbelt" param="assign|l.all_settings:unique_rel_products[g.uniquendx]|g.compare" />
      </mvt:if>
      </mvt:foreach>
      <mvt:item name="ry_toolbelt" param="assign|g.array_elements|miva_array_collapse ( l.all_settings:unique_rel_products )" />
      http://www.alphabetsigns.com/

      Comment


        #4
        Thanks Bruce - PhosphorMedia and alphabet, those are good points. Another consideration is that you may end up with a really long list of related items if there are multiple items in the cart. So for now I'm doing max of 3 per item, and no more than 12 total.

        I might end up with some sort of hybrid the custom field list + dedupe though.

        Also realized after posting yesterday's code snippet, for some reason I'm getting the wrong product images, while the titles / prices / links are correct. Seems like I'm using `
        ProductImage_Load_Type` incorrectly, however I checked the id's etc and everything looked good. Didn't have much time to look into it further so I deactivated it for now
        Looking for work as of March 2024! I've been a web developer for going on 20 years, with most of that time spent on Miva sites.

        Comment


          #5
          yes, alphabet made a good point about duplicates.

          and yes, image handling in miva via imagemachine is an absolute bear.

          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
            Mike521w Did you get the related products in the basket to work to your liking?
            Trying to implement something similar. Thanks!

            Comment


              #7
              Hi pmlvalerie - actually I hadn't gotten it to work, I got sidetracked and never returned to it. But you reminded me and it started bugging me, so I figured it out today. I had to make a few changes, the original code I posted wasn't correct. Also I added de-duping. This is brand new code so might have some bugs I'm not catching!

              One remaining thing I don't like is how I'm using the `GeneratedImage_Load_Dimensions` function - I'm hardcoding the dimensions (208 x 208). I don't remember exactly where those dimensions came from, I just know that this is what the store is using for its thumbnails. I dug around in admin and could find no setting that specified these dimensions. Could be it's part of the store theme. But I don't like having it coded this way, I'd rather have it set to just pull whatever the store's preferred thumbnail is

              In any case, here's the code:

              Code:
              <mvt:if expr="1">
                    <div class="relatedProducts">
                       <h3>Related Products</h3>
                       <mvt:assign name="l.max_totalRelated" value="12" />
                       <mvt:assign name="l.max_itemRelated" value="3" />
                       <mvt:assign name="l.count_totalRelated" value="0" />
                       <mvt:assign name="l.debugRelated" value="0" />
                       <mvt:foreach array="basket:groups" iterator="group">
                          <mvt:if expr="l.count_totalRelated GE l.max_totalRelated">
                             <mvt:if expr="l.debugRelated">l.max_totalRelated hit</mvt:if>
                          <mvt:else>
                             <mvt:assign name="l.count_itemRelated" value="0" />
                             <mvt:do file="g.Module_Feature_RPD_DB" name="l.success_loadRelated" value="RelatedProductList_Customer_Load_Product(g.basket:cust_id, l.settings:group:product:id, l.settings:pulledRelatedProducts)" />
                             <mvt:if expr="NOT l.success_loadRelated">
                                <mvt:if expr="l.debugRelated">booo 1</mvt:if>
                             <mvt:else>
                                <mvt:foreach array="pulledRelatedProducts" iterator="relatedProduct">
                                   <mvt:if expr="l.count_itemRelated GE l.max_itemRelated">
                                      <mvt:if expr="l.debugRelated">l.count_itemRelated hit</mvt:if>
                                   <mvt:else>
                                      <mvt:comment>is it already in the basket? or already on our list?</mvt:comment>
                                      <mvt:assign name="l.alreadyListed" value="0" />
                                      <mvt:foreach array="basket:groups" iterator="groupAgain">
                                         <mvt:if expr="l.settings:relatedProduct:id EQ l.settings:groupAgain:product:id">
                                            <mvt:assign name="l.alreadyListed" value="1" />
                                            <mvt:foreachstop />
                                         </mvt:if>
                                      </mvt:foreach>
                                      <mvt:if expr="NOT l.alreadyListed AND miva_array_max( l.allRelatedItems )">
                                         <mvt:assign name="l.settings:allRelatedItems" value="l.allRelatedItems" />
                                         <mvt:foreach array="allRelatedItems" iterator="related">
                                            <mvt:if expr="l.settings:relatedProduct:id EQ l.settings:related:id">
                                               <mvt:assign name="l.alreadyListed" value="1" />
                                               <mvt:foreachstop />
                                            </mvt:if>
                                         </mvt:foreach>
                                      </mvt:if>
                                      <mvt:if expr="NOT l.alreadyListed">
                                         <mvt:comment>1. get the URI for this related item</mvt:comment>
                                         <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:relatedProduct: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:if expr="NOT l.have_uri">
                                            <mvt:if expr="l.debugRelated">booo 2</mvt:if>
                                         <mvt:else>
                                            <mvt:do file="g.Module_Library_DB" name="l.success_imageLoadType" value="ProductImage_Load_Type(l.settings:relatedProduct:id, 1, l.settings:main)" />
                                            <mvt:if expr="NOT l.success_imageLoadType">
                                               <mvt:if expr="l.debugRelated">booo 3</mvt:if>
                                            <mvt:else>
                                               <mvt:do file="g.Module_Library_DB" name="l.success_genImageLoadResult" value="GeneratedImage_Load_Dimensions( l.settings:main:image_id, '208', '208', l.settings:genImage )" />
                                               <mvt:if expr="NOT l.success_genImageLoadResult">
                                                  <mvt:if expr="l.debugRelated">booo 4</mvt:if>
                                               <mvt:else>
                                                  <mvt:comment>yay</mvt:comment>
                                                  <mvt:assign name="l.count_totalRelated" value="l.count_totalRelated + 1" />
                                                  <mvt:assign name="l.count_itemRelated" value="l.count_itemRelated + 1" />
                                                  <mvt:assign name="l.record:thumb" value="l.settings:genImage:image" />
                                                  <mvt:assign name="l.record:uri" value="l.settings:canonical_uri:uri" />
                                                  <mvt:assign name="l.record:name" value="l.settings:relatedProduct:name" />
                                                  <mvt:assign name="l.record:price" value="l.settings:relatedProduct:price" />
                                                  <mvt:assign name="l.record:id" value="l.settings:relatedProduct:id" />
                                                  <mvt:assign name="l.record:code" value="l.settings:relatedProduct:code" />
                                                  <mvt:assign name="l.success_arrayInsert" value="miva_array_insert( l.allRelatedItems, l.record, -1 )" />
                                               </mvt:if>
              
                                            </mvt:if>
              
                                         </mvt:if>
                                      </mvt:if>
                                   </mvt:if>
                                </mvt:foreach>
                                <mvt:comment>
                                   * you have to erase the array before the next pass. Let's say the current item
                                   * had 6 related items, and the next item has 4. You'll find that the array still
                                   * contains 6 entries, the first 4 will be for the next item, but the 2 from the
                                   * current item will still be on the end. So let's just blank it out.
                                </mvt:comment>
                                <mvt:assign name="l.settings:pulledRelatedProducts" value="''" />
                             </mvt:if>
                          </mvt:if>
                       </mvt:foreach>
                       <mvt:if expr="NOT miva_array_max( l.allRelatedItems )">
                          <mvt:if expr="l.debugRelated">no related items</mvt:if>
                       <mvt:else>
                          <mvt:assign name="l.settings:allRelatedItems" value="l.allRelatedItems" />
                          <mvt:foreach array="allRelatedItems" iterator="related">
                             <a href="&mvt:related:uri;" class="relatedProduct">
                                <div>
                                   <img src="&mvte:related:thumb;" alt="&mvte:related:name;">
                                   <br><b>&mvt:related:name;</b>
                                   <br>&mvte:related:price;
                                   <br>&mvte:related:code;
                                   <br>&mvte:related:id;
                                </div>
                             </a>
                          </mvt:foreach>
                       </mvt:if>
                    </div>
                 </mvt:if>
              Last edited by Mike521w; 03-18-24, 07:59 AM.
              Looking for work as of March 2024! I've been a web developer for going on 20 years, with most of that time spent on Miva sites.

              Comment


                #8
                pmlvalerie it wouldn't let me tag you in the post above, trying now
                Looking for work as of March 2024! I've been a web developer for going on 20 years, with most of that time spent on Miva sites.

                Comment


                  #9
                  minor change to format the price nicely:

                  Code:
                  .....
                  <mvt:assign name="l.count_totalRelated" value="l.count_totalRelated + 1" />
                  <mvt:assign name="l.count_itemRelated" value="l.count_itemRelated + 1" />
                  <mvt:do name="l.formattedPrice" file="g.Module_Root $ g.Store:currncy_mod:module" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, l.settings:relatedProduct:price )" />
                  <mvt:assign name="l.record:price" value="l.settings:relatedProduct:price" />
                  <mvt:assign name="l.record:thumb" value="l.settings:genImage:image" />
                  .....
                  .....
                  <br><b>&mvt:related:name;</b>
                  <br>&mvte:related:formattedPrice;
                  .....
                  Looking for work as of March 2024! I've been a web developer for going on 20 years, with most of that time spent on Miva sites.

                  Comment


                    #10
                    Originally posted by Mike521w View Post
                    pmlvalerie it wouldn't let me tag you in the post above, trying now
                    FYI: there isn't really a 'preferred' image for thumbnails. you use the generated function, and Miva First checks to see if it existed, and if not, creates it. so I think your usage here is correct.
                    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


                      #11
                      Bruce - PhosphorMedia oh ok that makes sense! In practice I might find some way to store certain thumbnail sizes in custom fields and pull from there, so I'd have a central spot where anyone could modify them, rather than hardcoding into template code. Nice to know that the system will just generate whatever size is requested though
                      Looking for work as of March 2024! I've been a web developer for going on 20 years, with most of that time spent on Miva sites.

                      Comment


                        #12
                        Mike521w Wow, thanks, that great! I'll try it out.

                        Comment

                        Working...
                        X