Announcement

Collapse
No announcement yet.

Load product page if category only has one product

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

    Load product page if category only has one product

    Hello,

    When a category is visited, if it only has one product in the category, then I would like to load that product page instead of the category display. I suppose I could easily do this with javascript

    Code:
    <mvt:if expr="l.settings:category_product_count EQ 1">
        <script type="text/javascript">
            window.location.href = "www.storeurl.com/&mvt:category_listing:products[1]:code;.html"
        </script>
    <mvt:else>
         Display category 
    </mvt:if>
    But this doesn't seem very efficient. I suppose it's probably not that slow, but I just don't feel like this is the correct way to do this. I would much rather have the redirect loaded server side. I figured I could use the render toolkit command, but I'm not getting far with it. How can I render the product page with a specific product code using the render command?

    Any other suggestions that don't involve render from the toolkit or does this seem like the correct choice?

    #2
    Re: Load product page if category only has one product

    This works using multiple toolkit functions:

    Code:
    <mvt:item name="toolkit" param="cxpc|pcount|g.Category_Code" />
    <mvt:if expr="pcount EQ 1">
    <mvt:foreach iterator="sub_product" array="sub_products">
    <mvt:item name="toolkit" param="sassign|newurl|http://your.store.com/mm5/merchant.mvc?Screen=PROD&Product_Code=%replace%" />
    <mvt:item name="toolkit" param="vglosub|newurl,%replace%,l.all_settings:SUB_PRODUCT:CODE" />
    <mvt:item name="toolkit" param="headeroutput|Status|302 Found" />
    <mvt:item name="toolkit" param="vheaderoutput|Location|g.newurl" />
    </mvt:foreach>
    <mvt:else>
    do the regular category stuff
    </mvt:if>
    Tested in my store with 0,1 and 2 products and reacted as expected.
    Last edited by nottheusual1; 02-26-14, 03:49 PM.

    Comment


      #3
      Re: Load product page if category only has one product

      Nice. That works perfectly, thanks.

      Comment

      Working...
      X