cakephp 2.4: Add quantity with old quantity field

103 views Asked by At

In my database table I have a quantity field.I am trying to add new quantities which will add with previous.

I have tried by this code in controller

$this->request->data['StoreProduct']['quantity']=100+$this->request->data['StoreProduct']['quantity'];

Here this code working fine.But in 100 here I want to place my old data.So at first here I have to sent data which already in database.How can I send this data for add with new data ?

I have sent old data by using find methods, here is the code.

$options = array('conditions' => array('StoreProduct.' . $this->StoreProduct->primaryKey => $id));
        $request= $this->StoreProduct->find('all', $options);

I have succeed to see the quantity in edit.ctp. Now I can I send this edit.ctp to edit method in controller ?

1

There are 1 answers

3
user3698702 On

First, get the data using

$data = $this->StoreProduct->find('first',array('conditions'=>array('StoreProduct.id'=>$id)));

then add the data

$this->request->data['StoreProduct']['quantity']=$data['StoreProduct']['quantity']+$this->request->data['StoreProduct']['quantity'];