/** * method onEdit() * Executed whenever the user clicks at the edit button da datagrid */ function onEdit($param) { try { TTransaction::open('samples'); if (isset($param['key'])) { $key = $param['key']; $object = new Sale($key); $sale_items = $object->getSaleItems(); $session_items = array(); foreach ($sale_items as $item) { $session_items[$item->product_id] = $item->toArray(); $session_items[$item->product_id]['product_id'] = $item->product_id; $session_items[$item->product_id]['product_name'] = $item->product->description; $session_items[$item->product_id]['product_amount'] = $item->amount; $session_items[$item->product_id]['product_price'] = $item->sale_price; $session_items[$item->product_id]['product_discount'] = $item->discount; } TSession::setValue('sale_items', $session_items); $this->form->setData($object); // fill the form with the active record data $this->onReload($param); // reload sale items list TTransaction::close(); // close transaction } else { $this->form->clear(); TSession::setValue('sale_items', null); $this->onReload($param); } } catch (Exception $e) { new TMessage('error', '<b>Error</b> ' . $e->getMessage()); TTransaction::rollback(); } }