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

@ -19,7 +19,7 @@ class ProductsController extends AppController {
$this->Session->setFlash(__('Invalid Principle ID', true)); $this->Session->setFlash(__('Invalid Principle ID', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
} }
$this->set('products', $this->Product->find('all', array('conditions'=>array('Product.principle_id'=>$id)))); $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)); $this->set('principle', $this->Product->Principle->findById($id));
} }
@ -55,6 +55,38 @@ class ProductsController extends AppController {
$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() { function add_costing() {
} }

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"> <td class="actions">
<?php echo $html->link(__('View', true), array('action'=>'view', $product['Product']['id'])); ?> <?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(__('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> </td>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>