Shop: orderable

  • Hi,


    I like how Perch Shop allows us to set both a stock status and the stock level. It would be nice if there was a variable that indicates whether a product can be ordered.


    To evaluate whether a product can be ordered, one would have to check the stock status and the stock level. And if the stock status is unlimited, then the stock level shouldn't be taken into account. And if a product has variants, this check needs to be performed for all variants to determine whether this product can be ordered.


    Attempting to perform these checks with conditional tags inside the template would be messy. The alternative would be to perform the check in the each option when using perch_shop_products() or perch_shop_product().


    So I think it makes sense for Perch Shop to evaluate this and return a variable like orderable. This would make things much easier:


    HTML
    1. <perch:if exists="orderable">
    2. <!--* Add to cart form *-->
    3. <perch:else>
    4. <!--* No stock message *-->
    5. <perch:if id="stock_status" value="5">
    6. This product has been discontinued.
    7. <perch:else>
    8. This product is out of stock.
    9. </perch:if>
    10. </perch:if>


    It would also be nice to be able to filter by this:


    PHP
    1. perch_shop_products([
    2. 'filter' => 'orderable',
    3. 'match' => 'eq',
    4. 'value' => 1
    5. ]);
  • That sounds like a sensible approach. A more powerful perch:if tag would be appreciated regardless.


    I understand not wanting to add this to the app even though I see this as a common use case (any shop that has products with finite stock?).


    It's achievable as is anyway. I wrote a small helper app with a function I can use where necessary: