[Skip to main content](#vessel-content)

#   Out of stock at the end

##

- **[khashiz](/forum/user/61259-khashiz "View khashiz's Profile")**
- [![khashiz's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/61259-khashiz "View khashiz's Profile") Topic Author
- [ Offline](/forum/user/61259-khashiz)

Less More

- Posts: 240
- Thank you received: 13
-
-

5 months 2 weeks ago [\#372036](#372036) by [khashiz](/forum/user/61259-khashiz "View khashiz's Profile")  *[Out of stock at the end](/forum/26-product-category-display/910544-out-of-stock-at-the-end#372036 "-- HikaShop version -- : 6.4.1 -- Joomla version -- : 6.1.0 -- PHP version -- : 8.3  Hi. how can i display my products by their creation date, but out of the stock products to be at the end of the list ?")* was created by *[khashiz](/forum/user/61259-khashiz "View khashiz's Profile")*

-- HikaShop version -- : 6.4.1
-- Joomla version -- : 6.1.0
-- PHP version -- : 8.3

Hi. how can i display my products by their creation date, but out of the stock products to be at the end of the list ?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MTA1NDQtb3V0LW9mLXN0b2NrLWF0LXRoZS1lbmQ/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

5 months 2 weeks ago [\#372037](#372037) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Out of stock at the end](/forum/26-product-category-display/910544-out-of-stock-at-the-end#372037 "-- HikaShop version -- : 6.4.1 -- Joomla version -- : 6.1.0 -- PHP version -- : 8.3  Hi. how can i display my products by their creation date, but out of the stock products to be at the end of the list ?")*

Hello,

There is no built-in option to keep the date sorting while sending out-of-stock products to the end, the "Display out of stock products" setting is only a yes/no toggle. It can be done with a small HikaShop plugin, though.

First, set your listing or menu "Sort by" to the creation date the way you want it. Then create a HikaShop plugin (in the "hikashop" group) with this method, which adds an out-of-stock criterion in front of your existing sort:
Code:

public function onBeforeProductListingLoad(&amp;$filters, &amp;$order, &amp;$obj, &amp;$select, &amp;$select2, &amp;$a, &amp;$b, &amp;$on) { // Push products with a quantity of 0 to the end, keeping your date sort within each group $stock = '(' . $b . '.product_quantity = 0)'; if (stripos($order, 'ORDER BY') !== false) { $order = preg_replace('#ORDER BY\s+#i', 'ORDER BY ' . $stock . ', ', $order, 1); } else { $order = ' ORDER BY ' . $stock; } }

The result is "in stock first, then your creation-date order" within each group. Two notes: only products whose quantity is exactly 0 are moved, so products that do not manage stock stay where the date sort puts them; and a product that is out of stock only through its variants (while its own quantity is not 0) will not be moved, since this looks at the product's own quantity.

If you are not comfortable creating a plugin, your developer can set this up quickly.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MTA1NDQtb3V0LW9mLXN0b2NrLWF0LXRoZS1lbmQ/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.052 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
