# Sort products by stock and name

**URL:** <https://forum.modmore.com/t/sort-products-by-stock-and-name/2136>\
**Category:** Commerce\
**Created:** [October 7, 2020, 8:45pm UTC](https://forum.modmore.com/t/sort-products-by-stock-and-name/2136 "2020-10-07T20:45:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vibe\_Design](https://forum.modmore.com/user_avatar/forum.modmore.com/vibe_design/32/571_2.png) [@Vibe\_Design](https://forum.modmore.com/u/Vibe_Design)\
**Post date:** [October 7, 2020, 8:45pm UTC](https://forum.modmore.com/t/sort-products-by-stock-and-name/2136/1 "2020-10-07T20:45:44Z")

</div>

I would like to list products which are in stock before the ones which are currently sold out. Is there a way to get the `stock` value in the retrieval call? Currently I get my products with `pdoPage` and `TaggerGetResourcesWhere`:

```auto
  &element=`pdoResources`
  &where=`[[!TaggerGetResourcesWhere]]`
  &cache=`1`
  &limit=`9`
  &parents=`[[*id]]`
  &hideContainers=`1`
  &showHidden=`1`
  &depth=`1`
  &tpl=`product_item`
  &sortby=`pagetitle`
  &sortdir=`ASC`
  &limit=`9`
  &maxLimit=`9`
  &includeTVs=`products`
]]

```

The `stock` value is within the `products TV` if I’m not mistaken, but how am I able to sort by that?

---

<div class="post-metadata">

**Author:** ![Vibe\_Design](https://forum.modmore.com/user_avatar/forum.modmore.com/vibe_design/32/571_2.png) [@Vibe\_Design](https://forum.modmore.com/u/Vibe_Design)\
**Post date:** [October 14, 2020, 9:38am UTC](https://forum.modmore.com/t/sort-products-by-stock-and-name/2136/2 "2020-10-14T09:38:28Z")

</div>

Any ideas on this?

---

<div class="post-metadata">

**Author:** ![mhamstra](https://forum.modmore.com/user_avatar/forum.modmore.com/mhamstra/32/459_2.png) [@mhamstra](https://forum.modmore.com/u/mhamstra)\
**Post date:** [October 14, 2020, 2:36pm UTC](https://forum.modmore.com/t/sort-products-by-stock-and-name/2136/3 "2020-10-14T14:36:07Z")

</div>

What type of TV do you use, product list or matrix?

With the product list tv, that holds a comma separated list of products, which you can’t immediately sort in on a query for resources.

With the matrix tv, that holds the matrix ID which in theory could be used to join the matrix instance \> product instance to query the `stock` field or the price index table to sort on current price.

With a resource product implementation you should have a simple stock tv to look at.

---

<div class="post-metadata">

**Author:** ![Vibe\_Design](https://forum.modmore.com/user_avatar/forum.modmore.com/vibe_design/32/571_2.png) [@Vibe\_Design](https://forum.modmore.com/u/Vibe_Design)\
**Post date:** [October 14, 2020, 6:42pm UTC](https://forum.modmore.com/t/sort-products-by-stock-and-name/2136/4 "2020-10-14T18:42:47Z")

</div>

Yes, I’m using the `Products List TV`. Too bad, but was expecting that already. Thanks for clarifying, though!
