public function updateTotalOrder($orderProductID = 0) { try { if (0 !== $orderProductID) { $OrderModel = new Order(); $OrderProductModel = new OrderProduct(); $orderProduct = $OrderProductModel->read(null, $orderProductID); if (!empty($orderProduct)) { $order = $OrderModel->read(null, $orderProduct["OrderProduct"]["order_id"]); $allProducts = $orderProducts = $OrderProductModel->find('all', array('conditions' => array('OrderProduct.id >=' => 1, 'OrderProduct.order_id' => $orderProduct["OrderProduct"]["order_id"], 'OrderProduct.status' => 'active'))); $pSum = 0; $pUnit = 0; $tTax = 0; $tDisc = 0; $tSub = 0; foreach ($allProducts as $value) { $orderProduct = $value["OrderProduct"]; $pUnit = $orderProduct["product_price"] * $orderProduct["product_qty"]; $pUnit = $pUnit - $pUnit * $orderProduct["product_disc"] / 100; $pUnit = $pUnit + $pUnit * $orderProduct["product_tax"] / 100; $pSum += $pUnit; } $order["Order"]["price"] = $pSum; $order["Order"]["tax"] = 0; $order["Order"]["tax_amt"] = 0; $order["Order"]["subtotal_amt"] = $pSum; $order["Order"]["total_amt"] = $pSum; if (0 < $pSum) { $order["Order"]["status"] = 'pending'; } $order["Order"]["disc"] = 0; $order["Order"]["disc_amt"] = 0; $OrderModel->recursive = -1; if (!$OrderModel->save($order["Order"])) { $this->log('No se pudo actualizar el total de la orden'); $this->log($OrderModel->validationErrors); } } } } catch (Exception $ex) { $this->log('Error al guardar el total de productos a la orden'); $this->log($ex->getMessage()); } }