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; } $archived = $request->int("archived"); if($archived === 0) { $nvp["archived"] = $archived; } $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; } $archived_options = [ "0" => __("Hide"), "1" => __("Show"), ]; $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", "archived_options", "sort_options", "product_id", "supplier_id", "name", "sku", "type", "archived", "sort")); View::include("footer");