Announcement

Collapse
No announcement yet.

Enable Sorting

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

    Enable Sorting

    When I enable sorting for the products in a category after setting my view for assigned and active, the sort function shows both active and inactive. Seeing I have more the 100 inactive products it makes it time consuming to sort the products. I have tried all possible combinations but when I enable sorting i see all active and inactive products that are enabled in that category. Has anyone else run into this problem?

    Thank you
    Tom Dean
    WebMaintain

    #2
    Heyo,

    We were actually having the same sort of issue as you mention. We would have customers complain that we were "ALWAYS" out of stock on everything. When in reality we were just selling out of a few things that kept showing up on the top few pages and making it seem like we had less than we actually had.

    The solution we ended up settling on was having a Toolbox scheduled task iterate over each of our categories each night and re order them.
    The criteria was this
    • It had to sort by whats new (Newest items up front)
    • And it had to move any out of stock products to the back of the list

    This is the code we have in place on a page called CTGY_SORT
    Code:
    <mvt:if expr="g.run NE 'now'">
        <mvt:exit />
    </mvt:if>
    <mvt:comment> Triggered by toolbelt command at bottom of FSSP page template. </mvt:comment>
    
    <mvt:item name="ry_toolbelt" param="benchmark|Custom_Sort|START" />
    <mvt:item name="ry_toolbelt" param="benchmark|Category_Load|START" />
    
    <mvt:item name="ry_toolbelt" param="query|'SELECT id,code FROM s01_Categories WHERE active = 1'|categories|" />
    
    <mvt:if expr="ISNULL l.settings:categories">
        No categories found.<hr>
        <mvt:exit />
    
    <mvt:elseif expr="g.notfound">
        These categories were not found: <br>&mvt:global:notfound;<br>
    </mvt:if>
    
    <mvt:item name="ry_toolbelt" param="benchmark|Category_Load|END" />
    <mvt:item name="ry_toolbelt" param="benchmark|Category_Load|SHOW" />
    <hr>
    
    <mvt:comment> category count = <mvt:eval expr="miva_array_max(l.settings:categories)" /><br> </mvt:comment>
    
    
    <mvt:comment> Set Defaults </mvt:comment>
    <mvt:assign name="g.Maxitems" value="999999" />
    <mvt:assign name="Sortby" value="'newest'" />
    <mvt:assign name="g.PageNum" value="''" />
    
    <mvt:foreach iterator="catagory" array="categories">
       <mvt:comment> This is our exclusion check, basically we add the code we dont want this to do the sort on </mvt:comment>
        <mvt:if expr="(l.settings:catagory:code EQ 'Featured-Products') OR (l.settings:catagory:code EQ 'july_4_sales') OR (l.settings:catagory:code EQ 'peter_wright') OR (l.settings:catagory:code EQ 'special_sales') OR (l.settings:catagory:code EQ 'holiday') OR (l.settings:catagory:code EQ 'closeout') OR (l.settings:catagory:code EQ 'unicorn_closeout')  ">
            Category: id = &mvt:catagory:id;, code = &mvt:catagory:code;, Skipped!!<br>
            <hr>
        <mvt:else>
        <mvt:item name="ry_toolbelt" param="benchmark|This_Category|START" />
    
        Category: id = &mvt:catagory:id;, code = &mvt:catagory:code;, Order By: &mvt:global:Sortby;<br>
    
        <mvt:comment> Load l.settings:category_listing:products to get inventory</mvt:comment>
        <mvt:assign name="l.offset" value="0" />
        <mvt:assign name="l.nextoffset" value="0" />
        <mvt:assign name="l.settings:category_listing:products" value="''" />
    
        <mvt:do file = "g.Module_Library_DB"
            name = "g.product_count"
            value = "Runtime_ProductList_Load_Offset_Category_Sort(l.settings:catagory:id, l.offset, g.maxitems, g.sort, l.nextoffset, l.settings:category_listing:products)" />
    
        <mvt:if expr="g.product_count LT 1">
            No Products Found.
        <mvt:else>
            (&mvt:global:product_count;) Active Products,
            <mvt:comment> Filter a ref to out of stock items into l.settings:Nostock </mvt:comment>
            <mvt:assign name="g.nostock_count" value="miva_array_filter_ref( l.settings:category_listing:products, 1, l.prod, 'l.prod:inv_instock LT 1', l.settings:Nostock  )" />
            Out of Stock Items: (&mvt:global:nostock_count;),
    
    
            <mvt:comment> Sort by CXP Newest first and update the display orders in the array l.settings:CategoryXProduct </mvt:comment>
            <mvt:assign name="g.sql" value="'SELECT * FROM s01_CategoryXProduct WHERE cat_id = ? ORDER BY product_id DESC '" />
            <mvt:item name="ry_toolbelt" param="query|g.sql|CategoryXProduct|l.all_settings:catagory:id" /> <mvt:comment> sorted by newest </mvt:comment>
            <mvt:assign name="g.cxpcount" value="0" />
            <mvt:foreach iterator="item" array="CategoryXProduct">
                <mvt:assign name="g.cxpcount" value="g.cxpcount + 1" />
    <mvt:comment> <mvt:assign name="l.settings:item:old_disp_order" value="l.settings:item:disp_order" />  </mvt:comment>
                <mvt:assign name="l.settings:item:disp_order" value="g.cxpcount" />
            </mvt:foreach>
            <b>Updating</b> (&mvt:global:cxpcount;) records in CategoryXProduct<br>
    
    
            <mvt:assign name="l.next_disp_order" value="g.cxpcount + 1" />
            <mvt:comment>
                For each Nostock item in CategoryXProduct and get the index to that record
                Delete it from CategoryXProduct
                Recreate the record
                Add it to the bottom of the list
            </mvt:comment>
            <mvt:foreach iterator="product" array="Nostock">
                <mvt:assign name="l.cxp_index" value="miva_array_search( l.settings:CategoryXProduct, 1, l.cxp, 'l.cxp:product_id EQ l.settings:product:id')" />
                <mvt:if expr="l.cxp_index">
    <mvt:comment> <mvt:assign name="l.item:old_disp_order" value="l.settings:CategoryXProduct[l.cxp_index]:old_disp_order" /> </mvt:comment>
                    <mvt:assign name="l.new_count" value="miva_array_delete( l.settings:CategoryXProduct, l.cxp_index, 1 )" />
                    <mvt:assign name="l.item:cat_id" value="l.settings:catagory:id" />
                    <mvt:assign name="l.item:product_id" value="l.settings:product:id" />
                    <mvt:assign name="l.item:disp_order" value="l.next_disp_order" />
    <mvt:comment> <mvt:assign name="l.item:moved" value="'moved'" /> </mvt:comment>
                    <mvt:assign name="l.new_count" value="miva_array_insert( l.settings:CategoryXProduct, l.item, -1 )" />
                    <mvt:assign name="l.next_disp_order" value="l.next_disp_order + 1" />
                </mvt:if>
            </mvt:foreach>
    
    
            <mvt:foreach iterator="item" array="CategoryXProduct">
    <mvt:comment> <br><mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:item), ',', ' | '))" /> </mvt:comment>
    
                <mvt:do file = "g.Module_Library_DB"
                    name = "g.ok"
                    value = "CategoryXProduct_Update_DisplayOrder( l.settings:item )" />
    
            </mvt:foreach>
    
    
            <mvt:item name="ry_toolbelt" param="benchmark|This_Category|END" />
            <mvt:item name="ry_toolbelt" param="benchmark|This_Category|SHOW" />
    
        </mvt:if>
        <hr>
        </mvt:if>
    </mvt:foreach>
    
    <mvt:item name="ry_toolbelt" param="benchmark|Custom_Sort|END" />
    <mvt:item name="ry_toolbelt" param="benchmark|Custom_Sort|SHOW" />

    Then lastly all you need is a page that can be used to trip the scheduled task. We used the FSSP (Free standard Shipping Policy) page
    Code:
    <mvt:assign name="l.void" value="miva_output_flush()" />
    <mvt:assign name="g.url" value="'https://YOUR_SITE/SORT_CODE.html?run=now'" />
    <mvt:item name="ry_toolbelt" param="event_timer|ctgy_custom_sort|g.return|'daily 01:15:00'|3600 * 6|g.url|" />

    Comment


      #3
      Ideally, I would like to have a Hide "Out of Stock" items option on category pages.
      Thank you, Bill Davis

      Comment


        #4
        Originally posted by William Davis View Post
        Ideally, I would like to have a Hide "Out of Stock" items option on category pages.
        You could do that with facets and a custom field and have that custom field updated say every 15/30 minutes. Of course, this would take a bit of time to code in.

        You could also use the same custom field to resort the array before display so that Out of Stock are always last. This takes one line of SMT code.

        OR, you could just use a conditional to not display them inside the product display loop.

        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

        Working...
        X