Added clone product functionality
This commit is contained in:
parent
ef825ebdc7
commit
334806cc5c
|
|
@ -6,53 +6,85 @@ class ProductsController extends AppController {
|
||||||
var $helpers = array('Html', 'Form', 'Ajax', 'Number');
|
var $helpers = array('Html', 'Form', 'Ajax', 'Number');
|
||||||
|
|
||||||
function index() {
|
function index() {
|
||||||
/*$this->Product->recursive = 0;
|
/*$this->Product->recursive = 0;
|
||||||
$this->set('products', $this->paginate());
|
$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) {
|
function view_principle($id = null) {
|
||||||
if(!$id) {
|
if(!$id) {
|
||||||
$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));
|
||||||
}
|
}
|
||||||
|
|
||||||
function view($id = null) {
|
function view($id = null) {
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
$this->Session->setFlash(__('Invalid Product.', true));
|
$this->Session->setFlash(__('Invalid Product.', true));
|
||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
$this->set('product', $this->Product->read(null, $id));
|
$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('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('number_of_files', $this->Product->ProductAttachment->find('count', array('conditions' => array('ProductAttachment.product_id'=>$id))));
|
||||||
}
|
}
|
||||||
|
|
||||||
function add() {
|
function add() {
|
||||||
if (!empty($this->data)) {
|
if (!empty($this->data)) {
|
||||||
$this->Product->create();
|
$this->Product->create();
|
||||||
|
|
||||||
if ($this->Product->save($this->data)) {
|
if ($this->Product->save($this->data)) {
|
||||||
$this->Session->setFlash(__('The Product has been saved', true));
|
$this->Session->setFlash(__('The Product has been saved', true));
|
||||||
$id = $this->Product->id;
|
$id = $this->Product->id;
|
||||||
$this->redirect(array('action'=>'view/'.$id));
|
$this->redirect(array('action'=>'view/'.$id));
|
||||||
} else {
|
} else {
|
||||||
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
|
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$principles = $this->Product->Principle->find('list');
|
$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() {
|
function add_costing() {
|
||||||
|
|
@ -60,35 +92,35 @@ class ProductsController extends AppController {
|
||||||
}
|
}
|
||||||
|
|
||||||
function edit($id = null) {
|
function edit($id = null) {
|
||||||
if (!$id && empty($this->data)) {
|
if (!$id && empty($this->data)) {
|
||||||
$this->Session->setFlash(__('Invalid Product', true));
|
$this->Session->setFlash(__('Invalid Product', true));
|
||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
if (!empty($this->data)) {
|
if (!empty($this->data)) {
|
||||||
if ($this->Product->save($this->data)) {
|
if ($this->Product->save($this->data)) {
|
||||||
$this->Session->setFlash(__('The Product has been saved', true));
|
$this->Session->setFlash(__('The Product has been saved', true));
|
||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
} else {
|
} else {
|
||||||
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
|
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($this->data)) {
|
if (empty($this->data)) {
|
||||||
$this->data = $this->Product->read(null, $id);
|
$this->data = $this->Product->read(null, $id);
|
||||||
$this->set('description', $this->data['Product']['description']);
|
$this->set('description', $this->data['Product']['description']);
|
||||||
}
|
}
|
||||||
$principles = $this->Product->Principle->find('list');
|
$principles = $this->Product->Principle->find('list');
|
||||||
$this->set(compact('principles'));
|
$this->set(compact('principles'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($id = null) {
|
function delete($id = null) {
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
$this->Session->setFlash(__('Invalid id for Product', true));
|
$this->Session->setFlash(__('Invalid id for Product', true));
|
||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
if ($this->Product->del($id)) {
|
if ($this->Product->del($id)) {
|
||||||
$this->Session->setFlash(__('Product deleted', true));
|
$this->Session->setFlash(__('Product deleted', true));
|
||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -98,30 +130,30 @@ class ProductsController extends AppController {
|
||||||
*/
|
*/
|
||||||
function getPrincipleProducts() {
|
function getPrincipleProducts() {
|
||||||
|
|
||||||
|
|
||||||
if(empty($this->data)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
if(empty($this->data)) {
|
||||||
$this->set('products', $this->Product->find('list', array('conditions' =>
|
return;
|
||||||
array('Product.principle_id'=> $this->data['LineItem']['principle_id']))));
|
}
|
||||||
|
|
||||||
}
|
else {
|
||||||
|
$this->set('products', $this->Product->find('list', array('conditions' =>
|
||||||
|
array('Product.principle_id'=> $this->data['LineItem']['principle_id']))));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getProductOptions() {
|
function getProductOptions() {
|
||||||
if(empty($this->data)) {
|
if(empty($this->data)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
||||||
$this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), 'order'=>'ProductOptionsCategory.location ASC')));
|
$this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), 'order'=>'ProductOptionsCategory.location ASC')));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
43
views/products/clone_product.ctp
Executable file
43
views/products/clone_product.ctp
Executable 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>
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue