joseic Posted May 27, 2013 Share Posted May 27, 2013 Buenas Estoy intentando añadir un nuevo campo "web" a Fabricante, he hecho: 1. crear el campo en base de datos ALTER TABLE `manufacturer` ADD `web` VARCHAR(100) AFTER `active`; 2. sobreescribir la clase override/classes/Manufacturer.php class Manufacturer extends ManufacturerCore { /** @var string web */ public $web; /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'manufacturer', 'primary' => 'id_manufacturer', 'multilang' => true, 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64), 'active' => array('type' => self::TYPE_BOOL), 'web' => array('type' => self::TYPE_STRING), 'date_add' => array('type' => self::TYPE_DATE), 'date_upd' => array('type' => self::TYPE_DATE), // Lang fields 'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'), 'short_description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 254), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128), 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName'), ), ); } 3. sobreescribir el controlador de admin: override/controllers/admin/AdminManufacturersController.php class AdminManufacturersController extends AdminManufacturersControllerCore { public function __construct() { $this->table = 'manufacturer'; $this->className = 'Manufacturer'; $this->lang = false; $this->deleted = false; $this->allow_export = true; $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->context = Context::getContext(); $this->fieldImageSettings = array( 'name' => 'logo', 'dir' => 'm' ); $this->fields_list = array( 'id_manufacturer' => array( 'title' => $this->l('ID'), 'width' => 25 ), 'logo' => array( 'title' => $this->l('Logo'), 'image' => 'm', 'orderby' => false, 'search' => false, 'width' => 150, 'align' => 'center', ), 'name' => array( 'title' => $this->l('Name'), 'width' => 'auto' ), 'addresses' => array( 'title' => $this->l('Addresses'), 'width' => 20, 'align' => 'center', 'havingFilter' => true ), 'products' => array( 'title' => $this->l('Products:'), 'havingFilter' => true, 'width' => 20, 'align' => 'center', ), 'active' => array( 'title' => $this->l('Enabled'), 'width' => 70, 'active' => 'status', 'type' => 'bool', 'align' => 'center', 'orderby' => false ), 'web' => array( 'title' => $this->l('Web'), 'width' => 'auto', 'align' => 'center' ) ); parent::__construct(); } public function renderForm() { $this->fields_form_override = array( 'type' => 'text', 'label' => $this->l('Web:'), 'name' => 'web', 'hint' => $this->l('Include http://:') ); return parent::renderForm(); } } Como veis, lo añado en el fields_list del constructor y en fields_form_override de renderForm, parece que funciona, pero el problema viene cuando quiero añadir otro campo, puesto que en la clase AdminController.php, la función renderForm() está añadiendo una única posición en el array: // For add a fields via an override of $fields_form, use $fields_form_override if (is_array($this->fields_form_override) && !empty($this->fields_form_override)) $this->fields_form[0]['form']['input'][] = $this->fields_form_override; Por lo que en $this->fields_form_override debería cargar un array de arrays, pero al cargarlo en AdminController.php no funciona. La solución que veo es modificar AdminController.php de la siguiente manera: // For add a fields via an override of $fields_form, use $fields_form_override if (is_array($this->fields_form_override) && !empty($this->fields_form_override)) $this->fields_form[0]['form']['input'] += $this->fields_form_override; Pero no me gusta puesto que modifica el core... ¿Hay alguna otra forma de hacerlo sin tocar el core? Gracias! Link to comment Share on other sites More sharing options...
fbaquero Posted September 18, 2014 Share Posted September 18, 2014 Hola joseic. ¿Encontraste la solución? Estoy con el mismo problema Link to comment Share on other sites More sharing options...
Recommended Posts