Added clone product functionality

This commit is contained in:
Karl Cordes 2011-09-12 08:44:32 +10:00
parent ef825ebdc7
commit 334806cc5c
3 changed files with 148 additions and 73 deletions

View file

@ -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')));
}
}

View file

@ -0,0 +1,43 @@
<? echo $javascript->link('ckeditor/ckeditor');
echo $javascript->link('ckeditor/adapters/jquery');
?>
<script type="text/javascript">
$('.ckeditor').ckeditor(config);
</script>
<div class="addproduct">
<?php echo $form->create('Product', array('id'=>'productaddform', 'class'=>'addproduct'));?>
<fieldset>
<legend><?php __('Add Product');?></legend>
<?php
echo $form->input('principle_id', array('empty' => 'Choose a Principle'));
echo $form->input('title', array('class' => 'required', 'title'=>'Please Enter the Title for the Product'));
echo $form->input('description', array('id' => 'description', 'class'=>'ckeditor'));
echo $form->input('notes');
echo $html->image('calculator.png');
?>
</fieldset>
<?php echo $form->end(array('label' => 'Add Product'));
?>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('List Products', true), array('action'=>'index'));?></li>
<li><?php echo $html->link(__('List Principles', true), array('controller'=> 'principles', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Principle', true), array('controller'=> 'principles', 'action'=>'add')); ?> </li>
<li><?php echo $html->link(__('List Product Options', true), array('controller'=> 'product_options', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Product Option', true), array('controller'=> 'product_options', 'action'=>'add')); ?> </li>
</ul>
</div>

View file

@ -23,7 +23,7 @@ foreach ($products as $product):
<td class="actions">
<?php echo $html->link(__('View', true), array('action'=>'view', $product['Product']['id'])); ?>
<?php echo $html->link(__('Edit', true), array('action'=>'edit', $product['Product']['id'])); ?>
<?php echo $html->link(__('Create New Product based on this', true), array('action'=>'cloneProduct', $product['Product']['id'])); ?>
</td>
<?php endforeach; ?>
</table>