picinfo Posted September 6, 2011 Share Posted September 6, 2011 Bonjour , en fait j'ai un souci avec mon méthode Code : function recurseCategoryForInclude($indexedCategories, $categories, $current, $id_category = 1, $id_category_default = NULL){ global $done; static $irow; $id_obj = intval(Tools::getValue($this->identifier)); if (!isset($done[$current['infos']['id_parent']])){ $done[$current['infos']['id_parent']] = 0; } $done[$current['infos']['id_parent']] += 1; $todo = sizeof($categories[$current['infos']['id_parent']]); $doneC = $done[$current['infos']['id_parent']]; $level = $current['infos']['level_depth'] + 1; $img = $level == 1 ? 'lv1.gif' : 'lv'.$level.'_'.($todo == $doneC ? 'f' : 'b').'.gif'; $this->_html .= '<tr class="'.($irow++ % 2 ? 'alt_row' : '').'"> <td> <input type="checkbox" name="categoryBox[]" class="categoryBox'.($id_category_default != NULL ? ' id_category_default' : '').'" id="categoryBox_'.$id_category.'" value="'.$id_category.'"'.(((in_array($id_category, $indexedCategories) OR (intval(Tools::getValue('id_category')) == $id_category AND !intval($id_obj))) OR Tools::getIsset('adddiscount')) ? ' checked="checked"' : '').' /> </td> <td> '.$id_category.' </td> <td> <img src="../img/admin/'.$img.'" alt="" /> <label for="categoryBox_'.$id_category.'" class="t">'.stripslashes(Category::hideCategoryPosition($current['infos']['name'])).'</label> </td> </tr>'; var_dump($this->_html); if (isset($categories[$id_category])){ foreach ($categories[$id_category] AS $key => $row){ if ($key != 'infos'){ $this->recurseCategoryForInclude($indexedCategories, $categories, $categories[$id_category][$key], $key); } } } } qui existe dans un fichier php quand j’appelle Code : $this->_html .= '<table cellspacing="0" cellpadding="0" class="table" style="width: 29.5em;"> <tr> <th>'.$this->l('Choose').'</th> <th>'.$this->l('ID').'</th> <th>'.$this->l('Categories').'</th> </tr>'; $done = array(); $index = array(); $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : ($obj->id ? Discount::getCategories($obj->id) : array()); $categories = Category::getCategories(intval($cookie->id_lang), false); print_r($indexedCategories); //print_r($categories); foreach ($indexedCategories AS $k => $row){ $index[] = $row['id_category']; } recurseCategoryForInclude($index, $categories, $categories[0][1], 1, $obj->id); ici sa marche pas voir ci-joint mon fichier php merci en avance default.php Link to comment Share on other sites More sharing options...
Broceliande Posted September 6, 2011 Share Posted September 6, 2011 Pour commencer , ici : $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : ($obj->id ? Discount::getCategories($obj->id) : array()); Je ne trouve aucun endroit plus haut dans le code ou soit instancier $obj ? du coup erreur à coup sur non ? Link to comment Share on other sites More sharing options...
picinfo Posted September 7, 2011 Author Share Posted September 7, 2011 Bonjour, en fait moi je suivie ce site http://www.webbax.ch/2011/03/25/tutorial-creation-dun-module-prestashop-avec-devpro/ et si vous pouvez me corriger mon erreur je suis debutant avec prestashop codepromoauto.php <?php $id = Tools::getValue('id'); // Charge les donneés en session $data = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_ .'discount WHERE id_discount="'.$id.'"'); $data['position'] = array('hookLeftColumn'=>$this->l('Colonne gauche'),'hookRightColumn'=>$this->l('Colonne droite'),'hookHome'=>$this->l('Bloc central Home')); $positions = $data['position']; Session::loadData(array_merge($data,$positions)); // Retour $this->_html.= Html::linkBo($this->l('Retour à la liste des blocs'),array('module'=>'codepromoauto','form'=>'default'),array('img'=>'list.png')).'<br/><br/>'; // Formulaire $Form = new Form(); $this->_html.= $Form->init('codepromoauto',null,'post',array('fields_multilang'=>array('title','content')),$this->l('codepromoauto')). $Form->select('position',$this->l('Emplacement'),$positions,'position'). $Form->text('title',$this->l('Titre du bloc'),array('validation'=>array('notEmpty'))). $Form->textarea('content',$this->l('Contenu du bloc')). $Form->submit('formDiscount'); // Si le formulaire est validé if($Form->isSubmit('formDiscount')){ $languages = Language::getLanguages(); // Création if(empty($id)){ $id_discount = Tool::nextID('discount'); foreach($languages as $l){ Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_ .'discount (id_discount,id_discount_type,behavior_not_exhausted,id_customer,id_group,id_currency,name,value,quantity,quantity_per_user,cumulable,cumulable_reduction,date_from,date_to,minimal,active,cart_display,date_add,date_upd) VALUES ("'.$l['id_discount_type'].'", "'.$l['behavior_not_exhausted'].'", "'.$l['id_customer'].'", "'.$l['id_group'].'", "'.$l['id_currency'].'", "'.Tools::getValue($l['name']).'", "'.$l['value'].'", "'.$l['quantity'].'", "'.$l['quantity_per_user'].'", "'.$l['cumulable'].'", "'.$l['cumulable_reduction'].'", "'.$l['date_from'].'", "'.$l['date_to'].'", "'.$l['minimal'].'", "'.$l['active'].'", "'.$l['cart_display'].'", "'.$l['date_add'].'", "'.$l['date_upd'].'" )' ); } Form::msgConfirm($this->l('Le block été ajouté'),array('module'=>'codepromoauto','form'=>'default')); // Modification }else{ foreach($languages as $l){ Db::getInstance()->Execute('UPDATE '._DB_PREFIX_ .'discount d SET d.`id_discount`="'.Tools::getValue($l['id_discount']).'", d.`id_discount_type`="'.Tools::getValue($l['id_discount_type']).'", d.`id_customer`="'.Tools::getValue('behavior_not_exhausted').'", d.`id_group`="'.Tools::getValue('id_group').'", d.`id_currency`="'.Tools::getValue('id_currency').'", d.`name`="'.Tools::getValue('name').'", d.`value`="'.Tools::getValue('value').'", d.`quantity`="'.Tools::getValue('quantity').'", d.`quantity_per_user`="'.Tools::getValue('quantity_per_user').'", d.`cumulable`="'.Tools::getValue('cumulable').'", d.`cumulable_reduction`="'.Tools::getValue('cumulable_reduction').'", d.`date_from`="'.Tools::getValue('date_from').'", d.`date_to`="'.Tools::getValue('date_to').'", d.`minimal`="'.Tools::getValue('minimal').'", d.`active`="'.Tools::getValue('active').'", d.`cart_display`="'.Tools::getValue('cart_display').'", d.`date_add`="'.Tools::getValue('date_add').'", d.`date_upd`="'.Tools::getValue('date_upd').'", WHERE d.`id_discount`="'.$id_discount.'"'); } Form::msgConfirm($this->l('Le block a été modifiée'),array('module'=>'codepromoauto','form'=>'default')); } } ?> Merci en avance Link to comment Share on other sites More sharing options...
coeos.pro Posted September 7, 2011 Share Posted September 7, 2011 Je vois que tu utilises execute (Db::getInstance()->Execute...) pour update et insert, perso je préfère utiliser autoExecute pour des questions de lisibilités (c'est dans la classe Db) Link to comment Share on other sites More sharing options...
picinfo Posted September 7, 2011 Author Share Posted September 7, 2011 Bonjour, si possible tu montrer un bout de code que je dois changer avec AutOEXECUTE Merci Link to comment Share on other sites More sharing options...
coeos.pro Posted September 7, 2011 Share Posted September 7, 2011 Par exemple le dernier (2ème) foreach deviens: foreach($languages as $l)[indent=1]{ $table = '._DB_PREFIX_ .'discount';[/indent][indent=1] $values['id_discount'] = Tools::getValue($l['id_discount']); $values['id_discount_type'] = Tools::getValue($l['id_discount_type']); $values['id_customer'] = Tools::getValue('behavior_not_exhausted'); $values['id_group'] = Tools::getValue('id_group'); $values['id_currency'] = Tools::getValue('id_currency'); $values['name'] = Tools::getValue('name'); $values['value'] = Tools::getValue('value'); $values['quantity'] = Tools::getValue('quantity'); $values['quantity_per_user'] = Tools::getValue('quantity_per_user'); $values['cumulable'] = Tools::getValue('cumulable'); $values['cumulable_reduction'] = Tools::getValue('cumulable_reduction'); $values['date_from'] = Tools::getValue('date_from'); $values['date_to'] = Tools::getValue('date_to'); $values['minimal'] = Tools::getValue('minimal'); $values['active'] = Tools::getValue('active'); $values['cart_display'] = Tools::getValue('cart_display'); $values['date_add'] = Tools::getValue('date_add'); $values['date_upd'] = Tools::getValue('date_upd');[/indent] [indent=1]$type = 'UPDATE';[/indent] [indent=1]$where = '`id_discount` = '.$id_discount.';[/indent] [indent=1]Db::getInstance()->autoExecute($table, $values, $type, $where);[/indent][indent=1]}[/indent] Link to comment Share on other sites More sharing options...
coeos.pro Posted September 7, 2011 Share Posted September 7, 2011 Je n'arrive pas à modifier mon message pour enlever les indent qui apparaissent en trop alors je remet le code : foreach($languages as $l) { $table = '._DB_PREFIX_ .'discount'; $values['id_discount'] = Tools::getValue($l['id_discount']); $values['id_discount_type'] = Tools::getValue($l['id_discount_type']); $values['id_customer'] = Tools::getValue('behavior_not_exhausted'); $values['id_group'] = Tools::getValue('id_group'); $values['id_currency'] = Tools::getValue('id_currency'); $values['name'] = Tools::getValue('name'); $values['value'] = Tools::getValue('value'); $values['quantity'] = Tools::getValue('quantity'); $values['quantity_per_user'] = Tools::getValue('quantity_per_user'); $values['cumulable'] = Tools::getValue('cumulable'); $values['cumulable_reduction'] = Tools::getValue('cumulable_reduction'); $values['date_from'] = Tools::getValue('date_from'); $values['date_to'] = Tools::getValue('date_to'); $values['minimal'] = Tools::getValue('minimal'); $values['active'] = Tools::getValue('active'); $values['cart_display'] = Tools::getValue('cart_display'); $values['date_add'] = Tools::getValue('date_add'); $values['date_upd'] = Tools::getValue('date_upd'); $type = 'UPDATE'; $where = '`id_discount` = '.$id_discount.'; Db::getInstance()->autoExecute($table, $values, $type, $where); } Link to comment Share on other sites More sharing options...
coeos.pro Posted September 7, 2011 Share Posted September 7, 2011 Zut (décidément), c'est $where = '`id_discount` = '.$id_discount; à l'avant dernière ligne, j'ai laissé .' en trop Link to comment Share on other sites More sharing options...
picinfo Posted September 7, 2011 Author Share Posted September 7, 2011 je pense c'est faut $where = '`id_discount` = '.$id_discount.'; merci Link to comment Share on other sites More sharing options...
picinfo Posted September 7, 2011 Author Share Posted September 7, 2011 Bonjour, mon problème pas encore résolut si quelqu'un peut m'aider merci en avance Link to comment Share on other sites More sharing options...
coeos.pro Posted September 7, 2011 Share Posted September 7, 2011 je pense c'est faut $where = '`id_discount` = '.$id_discount.'; merci C'est pour cela que je l'ai corrigé dans le message suivant par $where = '`id_discount` = '.$id_discount; Link to comment Share on other sites More sharing options...
picinfo Posted September 7, 2011 Author Share Posted September 7, 2011 deux egals je pense si faut en plus mon editeur signe d'erreur Merci de réécrire le code complet Merci Link to comment Share on other sites More sharing options...
coeos.pro Posted September 7, 2011 Share Posted September 7, 2011 deux egals je pense si faut == ??? c'est pas une condition Link to comment Share on other sites More sharing options...
picinfo Posted September 7, 2011 Author Share Posted September 7, 2011 celui qui est faut $where = '`id_discount` = '.$id_discount.'; je pense ca est pas faut non $where '`id_discount` = '.$id_discount.'; Link to comment Share on other sites More sharing options...
coeos.pro Posted September 7, 2011 Share Posted September 7, 2011 celui qui est faut $where = '`id_discount` = '.$id_discount.'; je pense ca est pas faut non $where '`id_discount` = '.$id_discount.'; Non, c'est : $where = '`id_discount` = '.$id_discount; j'ai l'habitude de faire des modules Link to comment Share on other sites More sharing options...
picinfo Posted September 8, 2011 Author Share Posted September 8, 2011 Bonjour, merci pour votre réponse mais l'essentiel pour moi de résoudre mon problème en tout cas j'ai pas encore trouver une réponse qui permet de résoudre mon souci Merci en avance 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