pliciweb_stephane Posted June 20, 2014 Share Posted June 20, 2014 (edited) Hello, I Have worked hard but i think this can help. I ha ve to make a database table with : Code : Field different on any shop Subtitle : Field lang dependent Then, i have created this tables XXX, XXX_lang, XXX_shop : CREATE TABLE `ps_plici_menu` ( `id_plici_menu` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `code` VARCHAR(254) NOT NULL, PRIMARY KEY (`id_plici_menu`) ); CREATE TABLE `ps_plici_menu_lang` ( `id_plici_menu` INT(10) UNSIGNED NOT NULL, `id_shop` INT(11) UNSIGNED NULL DEFAULT NULL, `id_lang` INT(10) UNSIGNED NOT NULL, `subtitle` TEXT NULL, PRIMARY KEY (`id_plici_menu`, id_shop, id_lang) ); CREATE TABLE `ps_plici_menu_shop` ( `id_plici_menu` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `id_shop` INT(11) UNSIGNED NULL DEFAULT NULL, `code` VARCHAR(254) NOT NULL, PRIMARY KEY (`id_plici_menu`, id_shop), UNIQUE INDEX `code_unique` (`code`, `id_shop`) ); I Have Created this ObjectModel : class PliciMenu extends ObjectModel { public $id; public $code; public $id_shop; public $subtitle; public static $definition = array( 'table' => 'plici_menu', 'primary' => 'id_plici_menu', 'multilang' => true, // indique que l'on utilise du multilang 'multilang_shop' => true, // indique que l'on utilise du multilang et du multistore 'fields' => array( 'code' => array('type' => self::TYPE_STRING, 'shop' => true, /* definit que ce champ est multishop sur la table xxx_shop*/ /* tout champ multistore doit aussi être présent dans la table maitre*/ 'required' => true, 'size' => 254), 'subtitle' => array('type' => self::TYPE_STRING, 'lang'=>true /* definit que ce champ est multilangue sur la table xxx_lang*/), ), ); } And, i have created this controller to list, modify my table ( the important thing is 1/ to declare Shop::addTableAssociation('plici_menu', array('type' => 'shop')); to associate the shop table 2/ to set in the fields_form the id_shop to be setted ) : class AdminPliciMenuController extends AdminController { public function __construct() { $this->table = 'plici_menu'; $this->className = 'PliciMenu'; $this->bootstrap = true; $this->lang = true; $this->multishop_context = Shop::CONTEXT_SHOP; $this->action = ''; $this->addRowAction('edit'); Shop::addTableAssociation('plici_menu', array('type' => 'shop')); /* Ce champ indique la table XXX_shop pour plici_menu*/ /* si je le place dans la class PliciMenu.php, le controller n'en tient pas compte !! */ parent::__construct(); if (is_null(Shop::getContextShopID())) { $this->errors[] = $this->l('Vous devez selectionner une boutique pour utiliser cet onglet.'); return; } $this->fields_list = array(); $this->fields_list['code'] = array( 'title' => $this->l('Code'), 'width' => 'auto', ); $this->fields_list['justforprint'] = array( 'title' => $this->l('Titre'), 'type' => 'string', 'callback' => 'getMenuTitle', 'havingFilter' => false, 'width' => 'auto', ); $this->fields_list['subtitle'] = array( 'title' => $this->l('Sous titre'), 'width' => 'auto', 'lang' => true, ); } public function getMenuTitle($value, $all_values) { return "Hello"; } public function renderForm() { $this->fields_form = array( 'legend' => array( 'title' => $this->l('Sous titres du menu'), /*'image' => '../img/admin/nav-user.gif'*/ ), 'input' => array( array( 'type' => 'shop', 'label' => $this->l('Boutique'), 'name' => 'id_shop', 'size' => 255, ), array( 'type' => 'free', 'label' => $this->l('Titre'), 'name' => '', 'size' => 255, 'callback' => 'getMenuTitle', 'desc' => $this->getMenuTitle(NULL, get_object_vars($this->loadObject())) , ), array( 'type' => 'text', 'label' => $this->l('Texte du sous titre'), 'name' => 'subtitle', 'size' => 255, 'required' => true, 'lang' => true, ), ), 'submit' => array( 'title' => $this->l('Save'), //'class' => 'button' ), ); return parent::renderForm(); } } I Hope this code and tutocode can help another person than me Edited June 20, 2014 by pliciweb_stephane (see edit history) 1 Link to comment Share on other sites More sharing options...
jf Viguier Posted September 26, 2018 Share Posted September 26, 2018 Thanks a lot, your tuto helped me a lot. La remarque "tout champ multistore doit aussi être présent dans la table maitre" est tout à fait vrai mais cela me semble totalement surréaliste ;-) Link to comment Share on other sites More sharing options...
pliciweb_stephane Posted September 26, 2018 Author Share Posted September 26, 2018 Merci, ça fait plaisir (ça nous semble aussi étrange ) 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