elham_K Posted September 9, 2014 Share Posted September 9, 2014 Hi everyone! I've created a Admin controller with an object model for table but when I use helper form for editing a row of table my changes doesnt save in database. and row that I've edit will be removed from list view !! this is my controller code: -------------------------------------------------------------------------------------------------------- <?php class AdminResellersreqControllerCore extends AdminController { public $description; public function initProcess() { $this->id_object = Tools::getValue('id_'.$this->table); if (Tools::isSubmit('changeStatus') && $this->id_object) $this->action = 'change_status'; parent::initProcess(); } public function __construct() { $this->bootstrap = true; $this->table = 'resellers_req'; $this->className = 'Resellersreq'; $this->lang = false; // Building the list of records stored within the "resellersreq" table $this->fields_list = array( 'firstname' => array( 'title' => $this->l('First Name'), 'align' => 'center', ), 'lastname' => array( 'title' => $this->l('Last Name'), 'width' => 'auto', ), 'req_date' => array( 'type' => 'date', 'title' => $this->l('Request Date'), 'width' => 'auto' ), // 'description' => array( // 'title' => $this->l('Description'), // 'width' => 'auto' // ), // 'status' => array( // 'title' => $this->l('Status'), // 'type' => 'bool', // 'callback' => 'ShowStatusIcon', // 'width' => 'auto' // ), 'id_customer' => array( 'title' => $this->l('Edit Group'), 'callback' =>'ShowCustomerGroupLink', 'width' => 'auto' ), ); $this->bulk_actions = array( 'delete' => array( 'text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?') ) ); parent::__construct(); $id_shop = $this->context->shop->id; $this->_select = ' a.*, cu.firstname, cu.lastname'; $this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer cu ON (cu.id_customer = a.id_customer)'; $this->_where = 'AND a.id_shop = '.(int)$id_shop; $this->processFilter(); } // This method generates the list of results public function renderList() { $this->addRowAction('edit'); return parent::renderList(); } public function renderForm() { $this->fields_form = array( 'legend' => array( 'title' => $this->l(''), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Customer Description'), 'name' => 'description', //'values' => $this->description, 'style' => '', 'readonly' => true, //'class' => 't', 'rows' => 5, 'cols' => 35, // 'required' => true, 'desc' => $this->l('Customer Description'), ), array( 'type' => 'switch', 'label' => $this->l('Accept'), 'desc' => $this->l('Accepting or Rejecting a Customer'), 'name' => 'status', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Accept') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Reject') ) ), ), array( 'type' => 'textarea', 'autoload_rte' => true, //'class' => 'input fixed-width-sm', 'label' => $this->l('Shop Description'), 'name' => 'shop_description', 'rows' => 5, 'cols' => 35, // 'required' => true, 'desc' => $this->l('Your description for customer'), ), ), 'submit' => array( 'title' => $this->l(' Save '), 'class' => 'button btn btn-default pull-right' ) ); return parent::renderForm(); } public function ShowStatusIcon($id_resellers_req, $tr) { $resellersreq = new Resellersreq($tr['id_resellers_req']); if (!Validate::isLoadedObject($resellersreq)) return; return '<a class="list-action-enable'.($resellersreq->status ? ' action-enabled' : ' action-disabled').'" href="index.php?tab=AdminResellersreq&id_resellers_req='.(int)$resellersreq->id.'&changeStatus&token='.Tools::getAdminTokenLite('AdminResellersreq').'"> '.($resellersreq->status ? '<i class="icon-check"></i>' : '<i class="icon-remove"></i>'). '</a>'; } public function ShowCustomerGroupLink($id_resellers_req, $tr) { $resellersreq = new Resellersreq($tr['id_resellers_req']); if (!Validate::isLoadedObject($resellersreq)) return; return '<a class="edit btn btn-default" href="index.php?tab=AdminCustomers&id_customer='.(int)$resellersreq->id_customer.'&updatecustomer&token='.Tools::getAdminTokenLite('AdminCustomers').'"> '.$this->l('Edit Group').' </a>'; } public function processChangeStatus() { $resellersreq = new Resellersreq($this->id_object); if (!Validate::isLoadedObject($resellersreq)) $this->errors[] = Tools::displayError('An error occurred while updating this Request.'); $update = Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'resellers_req` SET status = '.($resellersreq->status ? 0 : 1).' WHERE `id_resellers_req` = '.(int)$resellersreq->id); if (!$update) $this->errors[] = Tools::displayError('An error occurred while updating this Request.'); Tools::clearSmartyCache(); Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token); } } ----------------------------------------------------------------------------------- Code of Object Model : class ResellersreqCore extends ObjectModel { public $id; public $status; public $id_customer; public $firstname; public $lastname; /** @var string Name */ public $name; //public $editgroup; //public $shop_description; /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'resellers_req', //'multishop' => true, 'primary' => 'id_resellers_req', 'fields' => array( 'id_shop' => array( 'type' => self::TYPE_INT, 'validate' => 'isUnsignedId' ), 'id_customer' => array( 'type' => self::TYPE_INT, 'validate' => 'isUnsignedId' ), 'req_date' => array( 'type' => self::TYPE_DATE, 'validate' => 'isDateFormat', ), 'description' => array( 'type' => self::TYPE_STRING, ), 'status' => array( 'type' => self::TYPE_INT, 'validate' => 'isUnsignedId', ), 'shop_description' => array( 'type' => self::TYPE_STRING, ), ), ); public function __construct($id_shop = null) { parent::__construct($id_shop); } } ---------------------------------------------------------------------------------------------------------------- Could anyone Help me? Tanx. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now