| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App;
- use App\Constraint\HasTextConstraint;
- $core = Core::getInstance();
- $core->addBreadcrumb("/products", __("Products"));
- $nvp = [];
- $request = Request::fromRequest();
- $product_id = $request->int("product_id");
- if($product_id) {
- $nvp["id"] = $product_id;
- }
- $supplier_id = $request->int("supplier_id");
- if($supplier_id) {
- $nvp["supplier_id"] = $supplier_id;
- }
- $name = $request->string("name");
- if($name) {
- $nvp["name"] = new HasTextConstraint($name);
- }
- $sku = $request->string("sku");
- if($sku) {
- $nvp["sku"] = new HasTextConstraint($sku);
- }
- $type = $request->int("type");
- if($type) {
- $nvp["type"] = $type;
- }
- $sort_options = [
- "id" => __("ID"),
- "name" => __("Name"),
- "sku" => __("SKU"),
- "price_asc" => __("Price (Ascending)"),
- "price_desc" => __("Price (Descending)"),
- ];
- $sort = $request->string("sort");
- $sort_column = "id";
- $sort_order = "asc";
- switch($sort) {
- case "name":
- $sort_column = "name";
- break;
- case "sku":
- $sort_column = "sku";
- break;
- case "price_asc":
- $sort_column = "price";
- break;
- case "price_desc":
- $sort_column = "price";
- $sort_order = "desc";
- break;
- }
- $count = Product::count($nvp);
- $pagination = new Pagination($count);
- $pagination->setTerms(__("%s product"), __("%s products"));
- $products = Product::query($nvp, [
- "sort" => $sort_column,
- "order" => $sort_order,
- "offset" => $pagination->getOffset(),
- "limit" => $pagination->getPageSize()
- ]);
- View::include("header");
- View::include("products", compact("products", "pagination", "sort_options", "product_id", "supplier_id", "name", "sku", "type", "sort"));
- View::include("footer");
|