Forum CMS Made Simple FR

Version complète : [resolu]Module Products => template search
Vous consultez actuellement la version basse qualité d’un document. Voir la version complète avec le bon formatage.
Citation :#~~~~~ DEBUT BLOC A NE PAS SUPPRIMER ~~~~~
#~ Version du CMS: 1.11.13
#~ Url du site :
#~ Hébergeur / Soft :
#~ Informations Système :
#~ ----------------------------------------------
#~ Cms Version: 1.11.13
#~ Installed Modules:
#~ CMSMailer: 5.2.2
#~ CMSPrinting: 1.0.5
#~ FileManager: 1.4.5
#~ MenuManager: 1.8.6
#~ Gallery: 2.0.1
#~ ModuleManager: 1.5.8
#~ News: 2.15
#~ Search: 1.7.12
#~ ThemeManager: 1.1.8
#~ TinyMCE: 2.9.12
#~ CGExtensions: 1.45
#~ CGContentUtils: 1.5
#~ JQueryTools: 1.3.4
#~ CGSimpleSmarty: 1.7.4
#~ Products: 2.22.1
#~ MleCMS: 1.11.4
#~ FormBuilder: 0.8.1.1
#~ CGGoogleMaps: 2.4.7
#~ MicroTiny: 1.2.9
#~ Config Information:
#~ php_memory_limit:
#~ process_whole_template:
#~ max_upload_size: 15000000
#~ url_rewriting: none
#~ page_extension:
#~ query_var: page
#~ image_manipulation_prog: GD
#~ auto_alias_content: true
#~ locale:
#~ default_encoding: utf-8
#~ admin_encoding: utf-8
#~ set_names: true
#~ Php Information:
#~ phpversion: 5.4.4-14+deb7u10
#~ md5_function: On (Vrai)
#~ gd_version: 2
#~ tempnam_function: On (Vrai)
#~ magic_quotes_runtime: Off (Faux)
#~ E_STRICT: 0
#~ E_DEPRECATED: 0
#~ memory_limit: 128M
#~ max_execution_time: 30
#~ output_buffering: 4096
#~ safe_mode: Off (Faux)
#~ file_uploads: On (Vrai)
#~ post_max_size: 15M
#~ upload_max_filesize: 15M
#~ session_save_path: Aucune vérification à cause de la restriction spécifiée par PHP open_basedir
#~ session_use_cookies: On (Vrai)
#~ xml_function: On (Vrai)
#~ xmlreader_class: On (Vrai)
#~ Server Information:
#~ Server Api: cgi-fcgi
#~ Server Db Type: MySQL (mysqli)
#~ Server Db Version: 5.5.37
#~ Server Db Grants: Trouvé un privilège "GRANT ALL" qui semble être adapté
#~ Server Time Diff: Aucune différence de date du système de fichiers trouvées
#~ ----------------------------------------------
#~~~~~ FIN BLOC A NE PAS SUPPRIMER ~~~~~



Bonjour

j'arrive au bout de l'installation du module products -> fonction et design.

Il ne me reste plus qu'a valider les recherches.

Je m'explique.
J'ai modifié le template de recherche du module pour afficher que les champs de recherche qui m'intéressent. Tout fonctionne sauf les cases à cocher.
J'ai ajouté les champs correspondant dans "définition des champs" voltage5, voltage12 Etc

Je les récupère bien dans mon formulaire (ils sont affichés) par contre je n'ai plus aucun retour de résultats, alors que quand je ne les mets pas tout fonctionne.

Voici le code du formulaire pour cette partie
Code :
[== HTML ==]
{foreach from=$searchprops key='fldname' item='obj'}
    {if $obj->type == 'checkbox' AND ($obj->name != Voltage12 OR $obj->name != Voltage33  OR $obj->name != Voltage5 OR $obj->name != Voltage25 OR $obj->name != Voltage28 OR $obj->name != Voltage15 OR $obj->name != Voltage18)}
      <input type='checkbox' name="{$actionid}cd_prodvalue[{$fldname}]" id="{$actionid}cd_prodvalue[{$fldname}]" /> {* style="display:none;"  *}
{/if}


et le contenu de la variable liée à la case à cocher
optenu avec
<pre>
{$obj|@print_r}
</pre>

Code :
[== HTML ==]

stdClass Object
(
    [id] => 23
    [name] => voltage12
    [prompt] => 12V
    [type] => checkbox
    [options] => Array
        (
        )

    [max_length] => 255
)
1
Salut,
Essaye avec les apostrophes ($obj->name != "Voltage12"...
pas de changement
Bizarre que tu obtiennes le print_r de voltage12 alors qu'il est refusé dans ton foreach. Tu n'as pas un lien que je puisse regarder avec la web developper bar de Chrispederick ?
je vous ai envoyé par mail un lien,
il y a un produit avec la tension qui correspond à 2.5 => voltage25
Je ne vois rien d'incorrect dans ton code. En fait, je ne connais pas le module products.
Par contre, je viens de faire un petit tour sur la forge et ai découvert que c'est déjà recensé dans les bugs : http://dev.cmsmadesimple.org/bug/view/6796.
Quelqu'un a donné une solution, mais je crains que tu ne doives l'adapter pour ta version.
je viens de regarder.
Et ne vois rien qui ressemble au code donné dans la forge.
Il y a deux fichier pour gérer les recherches

action.search.php

Code :
[== PHP ==]
<?php  /* -*- Mode: PHP; c-set-style: linux; tab-width: 4; c-basic-offset: 4 -*- */
#BEGIN_LICENSE
#-------------------------------------------------------------------------
# Module: Products (c) 2008-2014 by Robert Campbell
#         (calguy1000@cmsmadesimple.org)
#  An addon module for CMS Made Simple to allow users to create, manage
#  and display products in a variety of ways.
#
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org)
# Visit the CMSMS Homepage at: http://www.cmsmadesimple.org
#
#-------------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# However, as a special exception to the GPL, this software is distributed
# as an addon module to CMS Made Simple.  You may not use this software
# in any Non GPL version of CMS Made simple, or in any version of CMS
# Made simple that does not indicate clearly and obviously in its admin
# section that the site was built with CMS Made simple.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#
#-------------------------------------------------------------------------
#END_LICENSE
if( !isset($gCms) ) exit;

//
// initialization
//
$inline = 0;
$resultpage = $returnid;
$thetemplate = $this->GetPreference(PRODUCTS_PREF_DFLTSEARCH_TEMPLATE);
$searchfield = '';
$sortorder = $this->GetPreference('sortorder','asc');
$sortby = $this->GetPreference('sortby','product_name');
$fields = array();
{
    // get all of the field definitions
    // filter for those that can be used in search
    // and prepare the objects so that there is enough info to build a form.
    $tmp = product_utils::get_fielddefs();
    if( count($tmp) ) {
        for( $i = 0; $i < count($tmp); $i++ ) {
            $obj = $tmp[$i];
            if( in_array($obj->type,array('textbox','checkbox','textarea','dropdown')) ) {
                if( $obj->type == 'text' || $obj->type == 'textarea' || $obj->type == 'textbox' ) $obj->type = 'text';
                if( $obj->type == 'dropdown' ) $obj->options = cge_array::hash_prepend($obj->options,-1,$this->Lang('any'));
                $fields[$obj->name] = $obj;
            }
        }
    }
}

//
// Get parameters
//
if( isset($params['inline']) && $params['inline'] != 0 ) {
    $inline = 1;
    unset($params['inline']);
}
if( isset($params['resultpage']) ) {
    $tmp = $this->resolve_alias_or_id($params['resultpage']);
    if( $tmp ) {
        $resultpage = $tmp;
        $inline = 0;
    }
    unset($params['resultpage']);
}
if( isset($params['searchformtemplate']) ) {
    $thetemplate = trim($params['searchformtemplate']);
    unset($params['searchformtemplate']);
}
if( isset($params['searchfield']) ) $searchfield = trim($params['searchfield']); // this param is deprecated


//
// Get the field definitions.
//
if( !empty($searchfield) ) {
    $searchfields = array();
    $tfield = explode(',',$searchfield);
    foreach( $tfield as $onefield ) {
        $onefield = trim($onefield);
        if( !$onefield ) continue;
        if( !isset($fields[$onefield]) ) continue;

        $searchfields[$onefield] = $fields[$onefield];
    }
    if( count($searchfields) ) $smarty->assign('searchprops',$searchfields);
}
else {
    if( count($fields) ) $smarty->assign('searchprops',$fields);
}

$smarty->assign('cd_origpage',$returnid);
$smarty->assign('formstart',$this->CGCreateFormStart($id,'do_search',$resultpage,$params,$inline));
$smarty->assign('formend',$this->CreateFormEnd());

#
# Process the template
#
echo $this->ProcessTemplateFromDatabase('search_'.$thetemplate);

#
# EOF
#
?>

et action.do_search.php

Code :
[== PHP ==]
<?php  /* -*- Mode: PHP; c-set-style: linux; tab-width: 4; c-basic-offset: 4 -*- */
#BEGIN_LICENSE
#-------------------------------------------------------------------------
# Module: Products (c) 2008-2014 by Robert Campbell
#         (calguy1000@cmsmadesimple.org)
#  An addon module for CMS Made Simple to allow users to create, manage
#  and display products in a variety of ways.
#
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org)
# Visit the CMSMS Homepage at: http://www.cmsmadesimple.org
#
#-------------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# However, as a special exception to the GPL, this software is distributed
# as an addon module to CMS Made Simple.  You may not use this software
# in any Non GPL version of CMS Made simple, or in any version of CMS
# Made simple that does not indicate clearly and obviously in its admin
# section that the site was built with CMS Made simple.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#
#-------------------------------------------------------------------------
#END_LICENSE
if( !isset($gCms) ) exit;

//
// initialization
//
$fields = array();
{
    // get all of the field definitions
    // and filter them for the ones that we can search on.
    $tmp = product_utils::get_fielddefs();
    if( count($tmp) ) {
        for( $i = 0; $i < count($tmp); $i++ ) {
            $obj = $tmp[$i];
            if( in_array($obj->type,array('textbox','checkbox','textarea','dropdown')) ) {
                $fields[$obj->name] = $obj;
            }
        }
    }
}

$detailpage = $this->GetPreference('detailpage',$returnid);
$thetemplate = 'summary_'.$this->GetPreference(PRODUCTS_PREF_DFLTSUMMARY_TEMPLATE);
$destpage = $returnid;
$entryarray = '';
$npages = 0;
$inline = 0;


//
// handle params
//
if( isset($params['cd_cancel']) ) $this->RedirectContent($destpage);
if( isset($params['cd_ser']) && isset($params['cd_serck']) ) {
    $salt = __DIR__;
    if( md5($salt.$params['cd_ser']) == $params['cd_serck'] ) {
        $tmp = unserialize(base64_decode($params['cd_ser']));
        if( is_array($tmp) && count($tmp) ) {
            unset($params['cd_ser'],$params['cd_serck']);
            $params = array_merge($tmp,$params);
        }
    }
}

if( isset($params['summarytemplate']) ) $thetemplate = 'summary_'.$params['summarytemplate'];
if( isset($params['cd_notpretty']) ) {
    $params['notpretty'] = $params['cd_notpretty'];
    unset($params['cd_notpretty']);
}
if( isset($params['cd_detailpage']) ) {
    $params['detailpage'] = $params['cd_detailpage'];
    unset($params['cd_detailpage']);
}
if( isset($params['cd_pagelimit']) ) {
    $params['pagelimit'] = $params['cd_pagelimit'];
    unset($params['cd_pagelimit']);
}
if( isset($params['cd_origpage']) ) $destpage = (int)$params['cd_origpage'];
if( isset($params['pagelimit']) ) {
    $pagelimit = (int)$params['pagelimit'];
    $pagelimit = max($pagelimit,1);
    $pagelimit = min(500,$pagelimit);
}
if( isset($params['cd_sortby']) ) {
    $params['sortby'] = $params['cd_sortby'];
    unset($params['cd_sortby']);
}
if( isset($params['cd_sortorder']) ) {
    $params['sortorder'] = $params['cd_sortorder'];
    unset($params['cd_sortorder']);
}
if( isset($params['detailpage']) ) {
    $str = trim($params['detailpage']);
    if( $str ) $str = $this->resolve_alias_or_id($str);
    if( $str ) $detailpage = $str;
}

//
// handle form submission
//

try {
    // take the params passed from the tag, and/or form, or from a pagination link and build a query object
    $products_query = new products_query;
    foreach( $params as $key => $value ) {
        try {
            $products_query[$key] = $value;
        }
        catch( Exception $e ) {
            // ignore this error.
        }
    }

    if( isset($params['cd_prodname']) && $params['cd_prodname']) $products_query['productnamelike'] = trim($params['cd_prodname']);
    if( isset($params['cd_proddesc']) && $params['cd_proddesc']) $products_query['desclike'] = trim($params['cd_proddesc']);
    if( isset($params['cd_allany']) ) $products_query['useor'] = $params['cd_allany'];

    if( isset($params['cd_prodprice_min']) || isset($params['cd_prodprice_max']) ) {
        if( isset($params['cd_prodprice_min']) ) $price_min = (float)trim($params['cd_prodprice_min']);
        if( isset($params['cd_prodprice_max']) ) $price_max = (float)trim($params['cd_prodprice_max']);
        $products_query['pricerange'] = "{$price_min}:{$price_max}";
    }
    else if( isset($params['cd_prodprice']) && $params['cd_prodprice'] != -1 ) {
        if( strpos($params['cd_prodprice'],':') !== FALSE ) {
            list($min,$max) = explode(':',trim($params['cd_prodprice']),2);
            $min = trim($min);
            $max = trim($max);
            if( $min != '' && $max != '' ) {
                $min = floatval($min);
                $max = floatval($max);
                $products_query['pricerange'] = "{$min}:{$max}";
            }
            else if( $min != '' ) {
                $min = floatval($min);
                $products_query['pricerange'] = "{$min}:";
            }
            else if( $max  != '' ) {
                $max = floatval($max);
                $products_query['pricerange'] = ":{$max}";
            }
        }
    }

    if( isset($params['cd_prodvalue']) && !is_array($params['cd_prodvalue']) ) $params['cd_prodvalue'] = unserialize($params['cd_prodvalue']);
    $tfields = array_keys($fields);
    foreach( $tfields as $one ) {
        $fieldid = $fields[$one]->id;
        if( isset($params['cd_prodvalue'][$one]) && $params['cd_prodvalue'][$one] != '-1' && !empty($params['cd_prodvalue'][$one]) ) {
            $products_query->add_field_expr($fieldid,trim($params['cd_prodvalue'][$one]));
            continue;
        }

        $key1 = 'cd_prodvalue_'.$one.'_min';
        $key2 = 'cd_prodvalue_'.$one.'_max';
        if( isset($params[$key1]) || isset($params[$key2]) ) {
            $tdata = array('min'=>'','max'=>'');
            if( isset($params[$key1]) ) $tdata['min'] = (float)trim($params[$key1]);
            if( isset($params[$key2]) ) $tdata['max'] = (float)trim($params[$key2]);
            if( $tdata['min'] && $tdata['max'] ) {
                if( $tdata['min'] > $tdata['max'] ) {
                    $tmp = $tdata['max'];
                    $tdata['max'] = $tdata['min'];
                    $tdata['min'] = $tmp;
                }
                $products_query->add_field_expr($fieldid,"{$tdata['min']}:{$tdata['max']}");
            }
            else if( $tdata['min'] ) {
                $products_query->add_field_expr($fieldid,"{$tdata['min']}:");
            }
            else if( $tdata['max'] ) {
                $products_query->add_field_expr($ieldid,":{$tdata['min']}");
            }
        }
    }

    $results = $products_query->execute();
    $results->curpage = $returnid;
    if( isset($params['notpretty']) ) $results->notpretty = $params['notpretty'];
    if( isset($params['detailpage']) ) $results->detailpage = $params['detailpage'];
    if( isset($params['detailtemplate']) ) $results->detailtemplate = $params['detailtemplate'];
    $entryarray = array();
    while( !$results->EOF ) {
        $entryarray[] = $results->get_product_for_display();
        $results->MoveNext();
    }

    $smarty->assign('items', $entryarray);
    $smarty->assign('itemcount', count($entryarray));
    $smarty->assign('totalcount',$results->totalrows);
    $smarty->assign('pagecount',$results->numpages);
    $smarty->assign('curpage',$products_query['page']);

    $ser = base64_encode(serialize($params));
    $serck = md5(__DIR__.$ser);
    $parms = array('cd_ser'=>$ser,'cd_serck'=>$serck);

    $page = $products_query['page'];
    if( $page == 1 ) {
        $smarty->assign('firstlink',$this->Lang('firstpage'));
        $smarty->assign('prevlink',$this->Lang('prevpage'));
    } else {
        $parms['page'] = 1;
        $smarty->assign('firstlink',$this->CreateLink($id,'do_search',$returnid,$this->Lang('firstpage'),$parms));
        $smarty->assign('firstpage_url',$this->create_url($id,'do_search',$returnid,$parms));

        $parms['page'] = $page - 1;
        $smarty->assign('prevlink',$this->CreateLink($id,'do_search',$returnid,$this->Lang('prevpage'),$parms));
        $smarty->assign('prevpage_url',$this->create_url($id,'do_search',$returnid,$parms));
    }

    if( $page == $results->numpages ) {
        $smarty->assign('lastlink',$this->Lang('lastpage'));
        $smarty->assign('nextlink',$this->Lang('nextpage'));
    } else {
        $parms['page'] = $results->numpages;
        $smarty->assign('lastlink',$this->CreateLink($id,'do_search',$returnid,$this->Lang('lastpage'),$parms));
        $smarty->assign('lastpage_url',$this->create_url($id,'do_search',$returnid,$parms));
        $parms['page'] = $page + 1;
        $smarty->assign('nextlink',$this->CreateLink($id,'do_search',$returnid,$this->Lang('nextpage'),$parms));
        $smarty->assign('nextpage_url',$this->create_url($id,'do_search',$returnid,$parms));
    }

    $smarty->assign('pagetext',$this->Lang('page'));
    $smarty->assign('oftext',$this->Lang('of'));
    $smarty->assign('currency_symbol',product_ops::get_currency_symbol());
    $smarty->assign('weight_units',product_ops::get_weight_units());
}
catch( Exception $e ) {
    die('got exception: '.$e->GetMessage());
}

//
// Process the template
//
echo $this->ProcessTemplateFromDatabase($thetemplate);

#
# EOF
#
?>

je n'en vois pas d'autres et pas ou le pb se situe
J'ai donc téléchargé ce module et avec un peu de recherche : /lib/class.products_resultset.php
je viens de chercher directement dans les fichiers précité et j'ai trouvé une petite astuce qui fonctionne

il y a un problème avec les cases à cocher, dans la base de données si elle est cliqué (partie admin dans une fiche produit - champs de définitions) elle est affiché comme "true".
dans le fichier action.do.searche.php en testant $params['cd_prodvalue'][$one] dans la boucle
foreach( $tfields as $one ) { (ligne 168 pour moi)
On vois que pour les case cochées, c'est "on" qui est pris comme valeur.

j'ai ajouté ce code au début de la boucle :

Code :
[== PHP ==]
        if ( $params['cd_prodvalue'][$one] == 'on') { $params['cd_prodvalue'][$one] = 'true'; }

certe pas la meille des solutions, mais ça fonctionne

Merci bcp d'avoir pris le temps (surtout à cette heure) de regarder