|
|
@@ -36,17 +36,46 @@ 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" => "id",
|
|
|
+ "sort" => $sort_column,
|
|
|
+ "order" => $sort_order,
|
|
|
"offset" => $pagination->getOffset(),
|
|
|
"limit" => $pagination->getPageSize()
|
|
|
]);
|
|
|
|
|
|
View::include("header");
|
|
|
-View::include("products", compact("products", "pagination", "product_id", "supplier_id", "name", "sku", "type"));
|
|
|
+View::include("products", compact("products", "pagination", "sort_options", "product_id", "supplier_id", "name", "sku", "type", "sort"));
|
|
|
View::include("footer");
|