Update order function finds all orderlines of current order.
Loops through subtracting quantity ordered from stock level and holding new stock level value in $newstock. All good.
But won't save.
Echoes "success" and the correct value but the database is not updated.
The Order status field does update, with the same code syntax.
It also has the same relationships with the Orderline. (Function called from Orderline Controller)
The table relationships are:
'Product'hasMany = array('Orderline');
'Order' hasMany = array('Orderline');
'Orderline' belongsTo = array('Order', 'Product');
function updateOrder(){
$this->data['Order']['id'] = $this->getOrderid();
$orderproducts = $this->Orderline->find('all',array('conditions' =>
array('Orderline.order_id' => $this->data['Order']['id'])));
foreach($orderproducts as $orderproduct){
$newstock = $orderproduct['Product']['stock']-$orderproduct['Orderline']['quantity'];
$this->data['Product']['stock']= $newstock;
if( $this->Product->saveAll($this->data)){
echo "success" ;
}else{
echo "not saved";
}
}
$this->data['Order']['status']= 1;
$this->Order->saveall($this->data);
}