2009-01-12 21:13:18 -08:00
|
|
|
<?php
|
|
|
|
|
class ProductsController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Products';
|
2009-02-22 18:22:19 -08:00
|
|
|
var $components = array('RequestHandler');
|
2009-09-09 20:23:39 -07:00
|
|
|
var $helpers = array('Html', 'Form', 'Ajax', 'Number');
|
2009-01-12 21:13:18 -08:00
|
|
|
|
|
|
|
|
function index() {
|
|
|
|
|
$this->Product->recursive = 0;
|
|
|
|
|
$this->set('products', $this->paginate());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function view($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Product.', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
$this->set('product', $this->Product->read(null, $id));
|
2009-09-09 20:23:39 -07:00
|
|
|
|
|
|
|
|
//$this->set('product', $this->Product->find('first', array('conditions' => array('Product.id'=>$id), 'recursive' => 1)));
|
|
|
|
|
|
|
|
|
|
$this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$id), 'order'=>'ProductOptionsCategory.location ASC')));
|
|
|
|
|
|
2009-02-22 18:22:19 -08:00
|
|
|
$this->set('files', $this->Product->ProductAttachment->findAllByProductId($id));
|
|
|
|
|
$this->set('number_of_files', $this->Product->ProductAttachment->find('count', array('conditions' => array('ProductAttachment.product_id'=>$id))));
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add() {
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
$this->Product->create();
|
|
|
|
|
|
|
|
|
|
if ($this->Product->save($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('The Product has been saved', true));
|
2009-03-26 18:26:36 -07:00
|
|
|
$id = $this->Product->id;
|
|
|
|
|
$this->redirect(array('action'=>'view/'.$id));
|
2009-01-12 21:13:18 -08:00
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$principles = $this->Product->Principle->find('list');
|
2009-11-19 20:27:07 -08:00
|
|
|
|
2009-03-26 18:26:36 -07:00
|
|
|
$this->set(compact('principles', 'product_categories'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add_costing() {
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function edit($id = null) {
|
|
|
|
|
if (!$id && empty($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Product', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
if ($this->Product->save($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('The Product has been saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->data)) {
|
|
|
|
|
$this->data = $this->Product->read(null, $id);
|
2009-09-09 20:23:39 -07:00
|
|
|
$this->set('description', $this->data['Product']['description']);
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
$principles = $this->Product->Principle->find('list');
|
|
|
|
|
$this->set(compact('principles'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid id for Product', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if ($this->Product->del($id)) {
|
|
|
|
|
$this->Session->setFlash(__('Product deleted', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
?>
|