Advertisement
talalaite

Kaching test task1

Apr 3rd, 2025 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. <ul>
  2. <!--selecting the category of the products for testing purposes-->
  3. {%- assign selected_category = "electronics" %}
  4. <!--sorting products by price-->
  5. {%- assign sorted_products = products | sort: "price" %}
  6. {%- assign category_found = false %}
  7.  
  8. <h2>Products Category: {{ selected_category | capitalize }}</h2>
  9.  
  10. <!--showing products by selected category-->
  11. {%- for product in sorted_products %}
  12. {%- if selected_category == "" or product.category == selected_category %}
  13. {%- assign category_found = true %}
  14. <li>
  15. <!--showing product name and price like in the output example/missing price handling-->
  16. <a href="{{ product.name | prepend: "#" }}">
  17. {%- if product.price != null %}
  18. ${{ product.price | round: 2 }}
  19. {%- else %}
  20. Price unavailable
  21. {%- endif %}
  22. </a>
  23. </li>
  24. {%- endif %}
  25. {%- endfor %}
  26.  
  27. <!--edge case handling-->
  28. {%- if category_found == false %}
  29. <h2>No products were found in this category.
  30. All our available products: </h2>
  31. {%- for product in sorted_products %}
  32. <li>
  33. <a href="{{ product.name | prepend: "#" }}">
  34. {%- if product.price != null %}
  35. ${{ product.price | round: 2 }}
  36. {%- else %}
  37. Price unavailable
  38. {%- endif %}
  39. </a>
  40. </li>
  41. {%- endfor %}
  42. {%- endif %}
  43. </ul>
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement