products.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use App\Constraint\HasTextConstraint;
  4. $core = Core::getInstance();
  5. $core->addBreadcrumb("/products", __("Products"));
  6. $nvp = [];
  7. $request = Request::fromRequest();
  8. $product_id = $request->int("product_id");
  9. if($product_id) {
  10. $nvp["id"] = $product_id;
  11. }
  12. $supplier_id = $request->int("supplier_id");
  13. if($supplier_id) {
  14. $nvp["supplier_id"] = $supplier_id;
  15. }
  16. $name = $request->string("name");
  17. if($name) {
  18. $nvp["name"] = new HasTextConstraint($name);
  19. }
  20. $sku = $request->string("sku");
  21. if($sku) {
  22. $nvp["sku"] = new HasTextConstraint($sku);
  23. }
  24. $type = $request->int("type");
  25. if($type) {
  26. $nvp["type"] = $type;
  27. }
  28. $count = Product::count($nvp);
  29. $pagination = new Pagination($count);
  30. $pagination->setTerms(__("%s product"), __("%s products"));
  31. $products = Product::query($nvp, [
  32. "sort" => "id",
  33. "offset" => $pagination->getOffset(),
  34. "limit" => $pagination->getPageSize()
  35. ]);
  36. View::include("header");
  37. View::include("products", compact("products", "pagination", "product_id", "supplier_id", "name", "sku", "type"));
  38. View::include("footer");