foz1234 Posted July 15, 2019 Share Posted July 15, 2019 Is there anyway to display latest products on home screen in order of value starting form most expensive to the cheapest ? they just seem to display any how, i thought i had sorted this once upon a time ago but cant seem to find any posts about it and i assume upgrading CC has over written what changes i must have made thanks in advance Link to comment Share on other sites More sharing options...
bsmither Posted July 15, 2019 Share Posted July 15, 2019 Currently, the database query to get the Latest Products is hard-coded to sort by when the product was added to the inventory (then by product_id). Fortunately, there is a hook we can use to resort the aquired recordset (by the 'price' on those recently added products), or issue a completely new query. Link to comment Share on other sites More sharing options...
foz1234 Posted July 16, 2019 Author Share Posted July 16, 2019 Hi Brian Thanks again for your time in replying, the only hook i see in code snippets is the order of gallery images, how do i resort the acquired record set by the price again mate? Thanks again Link to comment Share on other sites More sharing options...
bsmither Posted July 16, 2019 Share Posted July 16, 2019 We will create a Code Snippet that fetches a fresh recordset that is sorted by price. In admin, Manage Hooks, Code Snippets tab, click Add Snippet. The next page load will have a form below the list of existing snippets. Enabled: Checked Unique ID: sortLPbyPrice@CC62+ Execution Order: 1 Description: Makes new query to get Latest Products ordered by Price Trigger: class.cubecart.latest_products Version: 1.0 Author: https://forums.cubecart.com/topic/55063-latest-products/ PHP Code: <?php $query = sprintf("SELECT I.* FROM `%1\$sCubeCart_inventory` AS I JOIN `%1\$sCubeCart_category` AS C ON C.cat_id=I.cat_id AND C.`status`=1 AND $where ORDER BY I.price DESC, I.product_id DESC", $GLOBALS['config']->get('config', 'dbprefix')); $latestProducts = $GLOBALS['db']->query($query, (int)$GLOBALS['config']->get('config', 'catalogue_latest_products_count')); Save and clear the cache. Link to comment Share on other sites More sharing options...
foz1234 Posted July 17, 2019 Author Share Posted July 17, 2019 Hi Brian,Thanks for your help with this again, i have tried the above snippet code as suggested and it has not worked, but i must add not sure if it makes a difference, i have renamed my latest products in Languages>catalogue - display.... latest_products from memory, should i put it back then run re-enable the snippet? (because it did not work after save and clear data i disabled the snippet for now) Will renaming it have stopped it working? i can try again tomorrow Link to comment Share on other sites More sharing options...
bsmither Posted July 17, 2019 Share Posted July 17, 2019 The only naming that would make a difference would be if the name of the database table CubeCart_inventory, the column 'latest' isn't named 'latest'. The language chosen to use for the storefront and/or what phrase you have chosen to actually display for the concept of "Latest Products" does not matter. Your message tag indicates you are using "SFWS Homepage Featured Products". This plugin (presumably) does the same thing we are trying to do: it overrules what was originally queried (a list of products where the 'latest' flag is true) with a new query with relevant conditions. Link to comment Share on other sites More sharing options...
foz1234 Posted July 17, 2019 Author Share Posted July 17, 2019 Hi Brian Yes i used the Homepage Featured Products for New products located at the top of the home page, in there you can manually state the listing order and i have latest products renamed to Refurbished products, until recently I've never had a problem before they were always in order of monetary value, then i added 2 more items that now sit at the front. Question thinking out-loud what if i remove them from display in Latest items and cleaned cache and then re added them in correct order would that work? thanks again Link to comment Share on other sites More sharing options...
bsmither Posted July 17, 2019 Share Posted July 17, 2019 I think you may have added to much info to the explanation of your problem. Are you saying the Homepage Featured Products module is now acting differently than what it was until recently? Link to comment Share on other sites More sharing options...
foz1234 Posted July 18, 2019 Author Share Posted July 18, 2019 Sorry for confusion Brian, short story Homepage Featured Products is used for displaying new products (works fine), then I've renamed Latest Products, so i use latest products for my displaying refurbished items on home page. Until recently everything was fine, then i added more refurbished items in to stock (displayed in renamed Latest Products on home page), they had previously displayed in monetary value, i was trying to get them back into monetary value. Link to comment Share on other sites More sharing options...
bsmither Posted July 18, 2019 Share Posted July 18, 2019 So you are saying you have both a set of Featured Products (listing newly added 'latest' products or are these in "New" condition?) and a set of Refurbished Products (renamed from 'Latest Products'). Normally, the Featured Product side panel is any one item from a collection of items where the product details have the "Include in featured products" checkbox is checked. I assume the plugin still respects this setting in showing those items you have targeted as being "New". Still, the Code Snippet above should work assuming no other plugin hook is not interfering. Link to comment Share on other sites More sharing options...
foz1234 Posted July 18, 2019 Author Share Posted July 18, 2019 i will delete the snippet and try again, just one thing "PHP Code:" i assume that is not copied in the PHP Code box with the rest of the script? i copied from <?php on in to the box and filled out the above as you had it saved, cleaned cache and reloaded the home page but order did not change. There is a separate tab added in products>General info called featured products (when using Homepage Featured Products module) in there are 2 options with status and order fields, status displays the item the order you set eg.1-20. I used this to list my new items. i then use the renamed Latest products to Refurbished header for displaying my used items, i use include in latest products radio button to list these. Link to comment Share on other sites More sharing options...
bsmither Posted July 18, 2019 Share Posted July 18, 2019 The PHP Code box has the contents that start with <?php on the first line. Link to comment Share on other sites More sharing options...
foz1234 Posted July 18, 2019 Author Share Posted July 18, 2019 Brian it's worked this time, so sorry to have wasted your time, looks like an error on my behalf no idea what mistake i made but it's working now thank you so much Regards Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.