bootstrap = true; $this->className = 'CmsPack'; $this->table = 'cms_pack'; $this->identifier = 'id_pack'; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->fields_list = array( 'id_pack' => array( 'title' => $this->l('ID'), 'align' => 'center', ), 'title' => array( 'title' => $this->l('Nom du pack'), 'align' => 'center', ), 'product' => array( 'title' => $this->l('Produits'), 'align' => 'center', 'callback' => 'getProductDetails', 'filter' => false, 'search' => false ), ); $this->_select = ' "product" as product'; $this->_group = ' GROUP BY a.`id_pack`'; parent::__construct(); } public function getProductDetails($data, $obj) { $pack = new CmsPack($obj['id_pack']); $infos = $pack->getInfosWithValues(); $result = ''; foreach ($infos as $key => $info) { $result.= $info['id'] . ' - ' . $info['content'] . ' | ' ; } return $result; } public function renderForm() { if (!($obj = $this->loadObject(TRUE))) return; $this->fields_form = array( 'legend' => array( 'title' => $this->className, ), 'submit' => array( 'name' => 'submitCMSPack', 'title' => $this->l('Save'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Nom du pack'), 'name' => 'title', 'size' => 114, ), array( 'type' => 'relation_product', 'label' => $this->l('Sélectionner des produits'), 'name' => 'relation_product', 'class' => 'relation_product', 'id' => 'product-pack', 'query' => $this->object->getInfosWithValues('product'), ), ) ); return parent::renderForm(); } public function processSave() { parent::processSave(); $relations = Tools::getValue('input-product-pack', array()); if ($this->object->deleteRelations()) { foreach ($relations as $key => $relation) { $this->object->addRelation($relation); } } } public function processDelete() { if (Validate::isLoadedObject($object = $this->loadObject())) { $object->deleteRelations(); } parent::processDelete(); } }