| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?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;
- }
- $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");
|