Bonjour je travail avec virtuemart j'ai ajouter un module qui filter les catégories sauf que a chaque ajout d'une nouvelle catégories un select est ajouté , je veux limiter l'affichage des select a 3 seulement , voici le code :
public static function getCategoriesTree($params){
et la fonction du code js est :
Quelqu'un pourrait m'aider s'il vous plait ? Merci beaucoup
public static function getCategoriesTree($params){
Code:
$db = JFactory::getDBO(); $query = $db->getQuery(true); $query->from('#__virtuemart_categories_'.VMLANG.' AS l'); $query->join('INNER', '#__virtuemart_categories AS c using (virtuemart_category_id)'); $query->join('LEFT', '#__virtuemart_category_categories AS cx ON l.virtuemart_category_id = cx.category_child_id '); $query->select('c.virtuemart_category_id as id, l.category_name as title, cx.category_child_id as child_id, cx.category_parent_id as parent_id'); $query->where('c.published = 1'); if ($params->get('ordering', 'ordering') == 'title') { $query->order('l.category_name'); } else { $query->order('cx.ordering'); } //echo $query->dump(); $db->setQuery($query); $results = $db->loadObjectList('id'); if (empty($results)) { return array(); } $categories = array(); $categories[0] = (object) array( 'id' => 0, 'parent_id' => null, 'title' => 'Top Level Category' ); $categories += $results; $i = 1; foreach ($categories as $cat) { //Ordre $categories[$cat->id]->ordering = $i; if (empty($categories[$cat->id]->children)) { $categories[$cat->id]->children = array(); } //L'element fils if (isset($categories[$cat->parent_id])) { if (empty($categories[$cat->parent_id]->children)) { $categories[$cat->parent_id]->children = array(); } $p= $categories[$cat->parent_id] ; $categories[$cat->parent_id]->children[] = $cat; } $i++; } return $categories;
Code:
updateTree: function (changed){ //var id;//id of selected children //change event this.fireEvent('changed', [changed]); if(changed){ //clear all after changed changed.getAllNext('label').destroy().empty(); changed.getAllNext('select').destroy().empty(); //add children select var id = changed.get('value'); //get children JSON if link is given and tree empty if (this.options.request_url && id != this.options.empty_value && !this.tree[id]){ this.requestChildren(changed); } else {//add select } this.addSelect(id) ; } else { //cleare and build new this.element.getChildren('label').destroy().empty(); this.element.getChildren('select').destroy().empty(); //build new this.addSelect(); } },