Improved handling of unknown product IDs
This commit is contained in:
parent
f0bec4bedd
commit
3074136cf7
@ -165,24 +165,27 @@ class Product {
|
||||
}
|
||||
|
||||
public function __construct($clue, $type = 'id') {
|
||||
$search = null;
|
||||
switch($type) {
|
||||
case 'id':
|
||||
$this->id = $clue;
|
||||
$search = prepare('select `id` from `product`
|
||||
where `id`=?');
|
||||
bind($search, 'i', $clue);
|
||||
break;
|
||||
case 'serial':
|
||||
$search = prepare('select `id` from `product`
|
||||
where `serial`=?');
|
||||
bind($search, 's', $clue);
|
||||
execute($search);
|
||||
$result = result_single($search);
|
||||
if($result === null) {
|
||||
throw new Exception('Invalid serial.');
|
||||
}
|
||||
$this->id = $result['id'];
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Invalid type.');
|
||||
}
|
||||
execute($search);
|
||||
$result = result_single($search);
|
||||
if($result === null) {
|
||||
throw new Exception('Product does not exist..');
|
||||
}
|
||||
$this->id = $result['id'];
|
||||
$this->update_fields();
|
||||
$this->update_info();
|
||||
$this->update_tags();
|
||||
|
@ -468,12 +468,20 @@ class ProductPage extends Page {
|
||||
try {
|
||||
$this->template = new Template($template, 'name');
|
||||
} catch(Exception $e) {
|
||||
$template = null;
|
||||
$this->template = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($_GET['id'])) {
|
||||
$this->product = new Product($_GET['id']);
|
||||
$id = $_GET['id'];
|
||||
if($id) {
|
||||
try {
|
||||
$this->product = new Product($id);
|
||||
} catch(Exception $e) {
|
||||
$this->action = 'list';
|
||||
$this->product = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch($this->action) {
|
||||
case 'show':
|
||||
|
Loading…
x
Reference in New Issue
Block a user