diff --git a/controllers/products_controller.php b/controllers/products_controller.php index 39285901..30480218 100755 --- a/controllers/products_controller.php +++ b/controllers/products_controller.php @@ -6,53 +6,85 @@ class ProductsController extends AppController { var $helpers = array('Html', 'Form', 'Ajax', 'Number'); function index() { - /*$this->Product->recursive = 0; + /*$this->Product->recursive = 0; $this->set('products', $this->paginate()); * - */ - $this->set('principles', $this->Product->Principle->find('all', array('order' => 'Principle.name ASC'))); + */ + $this->set('principles', $this->Product->Principle->find('all', array('order' => 'Principle.name ASC'))); } function view_principle($id = null) { - if(!$id) { - $this->Session->setFlash(__('Invalid Principle ID', true)); - $this->redirect(array('action'=>'index')); - } - $this->set('products', $this->Product->find('all', array('conditions'=>array('Product.principle_id'=>$id)))); - $this->set('principle', $this->Product->Principle->findById($id)); + if(!$id) { + $this->Session->setFlash(__('Invalid Principle ID', true)); + $this->redirect(array('action'=>'index')); + } + $this->set('products', $this->Product->find('all', array('conditions'=>array('Product.principle_id'=>$id),'order'=>'Product.title ASC'))); + $this->set('principle', $this->Product->Principle->findById($id)); } 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)); + if (!$id) { + $this->Session->setFlash(__('Invalid Product.', true)); + $this->redirect(array('action'=>'index')); + } + $this->set('product', $this->Product->read(null, $id)); - //$this->set('product', $this->Product->find('first', array('conditions' => array('Product.id'=>$id), 'recursive' => 1))); + //$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'))); + $this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$id), 'order'=>'ProductOptionsCategory.location ASC'))); - $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)))); + $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)))); } function add() { - if (!empty($this->data)) { - $this->Product->create(); + if (!empty($this->data)) { + $this->Product->create(); - if ($this->Product->save($this->data)) { - $this->Session->setFlash(__('The Product has been saved', true)); - $id = $this->Product->id; - $this->redirect(array('action'=>'view/'.$id)); - } else { - $this->Session->setFlash(__('The Product could not be saved. Please, try again.', true)); - } - } - $principles = $this->Product->Principle->find('list'); + if ($this->Product->save($this->data)) { + $this->Session->setFlash(__('The Product has been saved', true)); + $id = $this->Product->id; + $this->redirect(array('action'=>'view/'.$id)); + } else { + $this->Session->setFlash(__('The Product could not be saved. Please, try again.', true)); + } + } + $principles = $this->Product->Principle->find('list'); - $this->set(compact('principles', 'product_categories')); + $this->set(compact('principles', 'product_categories')); + } + + function cloneProduct($id) { + + if(!$id) { + $this->Session->setFlash('Invalid Product ID'); + $this->redirect(array('action'=>'index')); + } + else { + $product = $this->Product->find('first',array('conditions'=>array('Product.id'=>$id))); + } + + + + if (!empty($this->data)) { + $this->Product->create(); + + if ($this->Product->save($this->data)) { + $this->Session->setFlash(__('The Product has been saved', true)); + $id = $this->Product->id; + $this->redirect(array('action'=>'view/'.$id)); + } else { + $this->Session->setFlash(__('The Product could not be saved. Please, try again.', true)); + } + } + + $this->data['Product']['principle_id'] = $product['Product']['principle_id']; + $this->data['Product']['title'] = $product['Product']['title']; + $this->data['Product']['description'] = $product['Product']['description']; + + $principles = $this->Product->Principle->find('list'); + $this->set(compact('principles', 'product_categories')); } function add_costing() { @@ -60,35 +92,35 @@ class ProductsController extends AppController { } 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); - $this->set('description', $this->data['Product']['description']); - } - $principles = $this->Product->Principle->find('list'); - $this->set(compact('principles')); + 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); + $this->set('description', $this->data['Product']['description']); + } + $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')); - } + 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')); + } } @@ -98,30 +130,30 @@ class ProductsController extends AppController { */ function getPrincipleProducts() { - - if(empty($this->data)) { - return; - } - else { - $this->set('products', $this->Product->find('list', array('conditions' => - array('Product.principle_id'=> $this->data['LineItem']['principle_id'])))); - - } + if(empty($this->data)) { + return; + } + + else { + $this->set('products', $this->Product->find('list', array('conditions' => + array('Product.principle_id'=> $this->data['LineItem']['principle_id'])))); + + } } function getProductOptions() { - if(empty($this->data)) { - return; - } + if(empty($this->data)) { + return; + } - else { - - $this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), 'order'=>'ProductOptionsCategory.location ASC'))); + else { + + $this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), 'order'=>'ProductOptionsCategory.location ASC'))); - } + } diff --git a/views/products/clone_product.ctp b/views/products/clone_product.ctp new file mode 100755 index 00000000..24748d84 --- /dev/null +++ b/views/products/clone_product.ctp @@ -0,0 +1,43 @@ + echo $javascript->link('ckeditor/ckeditor'); + echo $javascript->link('ckeditor/adapters/jquery'); +?> + + + +