diff --git a/include/Inventory.php b/include/Inventory.php index 09fb001..eb6a33b 100644 --- a/include/Inventory.php +++ b/include/Inventory.php @@ -105,6 +105,7 @@ class Inventory { foreach($this->seen_products as $prodid) { $out[] = new Product($prodid); } + usort($out, ['Product', 'compare']); return $out; } @@ -146,6 +147,7 @@ class Inventory { $out[] = $product; } } + usort($out, ['Product', 'compare']); return $out; } } diff --git a/include/Page.php b/include/Page.php index 66b0d71..c4227ec 100644 --- a/include/Page.php +++ b/include/Page.php @@ -133,6 +133,8 @@ abstract class Page extends Responder { } final protected function build_product_table($products) { + usort($products, ['Product', 'compare']); + $rows = ''; foreach($products as $product) { $rows .= $this->build_product_row($product); @@ -305,6 +307,7 @@ abstract class Page extends Responder { $unseen[] = $product; } } + usort($unseen, ['Product', 'compare']); } else { $unseen = $inventory->get_unseen_products(); $total_count = count($unseen) + count($seen); diff --git a/include/Product.php b/include/Product.php index 461a73c..9d0d4ac 100644 --- a/include/Product.php +++ b/include/Product.php @@ -42,6 +42,11 @@ class Product extends Entity { } } + public static function sort($prod1, $prod2) { + return strcmp(strtolower($prod1->get_name()), + strtolower($prod2->get_name())); + } + public function __construct($clue, $type = 'id') { parent::__construct(); $search = null;