diff --git a/ChangeLog b/ChangeLog
index aaad1ca826b..8377c3d35d3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -78,6 +78,7 @@ Fix: Enable extrafields for customer order, proposal and invoice lines. This fea
was developed for 3.5 but was disabled (hidden) because of a bug not possible to
fix enough quickly for 3.5.0 release.
Fix: user right on Holiday for month report nor working.
+Fix: [ bug #1250 ] "Supplier Ref. product" sidebar search box does not work
***** ChangeLog for 3.5 compared to 3.4.* *****
For users:
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 20299041dfe..7c1c755a7c6 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2895,16 +2895,21 @@ abstract class CommonObject
$text=$product_static->getNomUrl(1);
// Define output language (TODO Does this works ?)
- if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
+ if (! empty($conf->global->MAIN_MULTILANGS))
{
- $this->fetch_thirdparty();
+ if (! is_object($this->client))
+ {
+ // TODO Remove this
+ $this->fetch_thirdparty(); // The fetch_thirdparty should be done before calling $object->printObjectLines, not into function called for each line
+ }
+
$prod = new Product($this->db);
$prod->fetch($line->fk_product);
$outputlangs = $langs;
$newlang='';
if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
- if (empty($newlang)) $newlang=$this->client->default_lang;
+ if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->client->default_lang; // For language to language of customer
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 3f5b90df529..b9e25aa58f1 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -4523,26 +4523,23 @@ if (! function_exists('getmypid'))
* Natural search
*
* @param mixed $fields String or array of strings filled with the fields names in the SQL query
- * @param string $value The value to look for
+ * @param string $value The value to look for (example: "keyword1 keyword2")
* @return string $res The statement to append to the SQL query
*/
function natural_search($fields, $value)
{
global $db;
$crits = explode(' ', $value);
- $res = "";
- if (! is_array($fields)) {
- $fields = array($fields);
- }
+ $res = '';
+ if (! is_array($fields)) $fields = array($fields);
+
$end = count($fields);
$end2 = count($crits);
$j = 0;
foreach ($crits as $crit) {
$i = 0;
foreach ($fields as $field) {
- if ( $i > 0 && $i < $end){
- $res .= " OR ";
- }
+ if ( $i > 0 && $i < $end) $res .= " OR ";
$res .= $field . " LIKE '%" . $db->escape(trim($crit)) . "%'";
$i++;
}
diff --git a/htdocs/fourn/product/liste.php b/htdocs/fourn/product/liste.php
index 76c34be7034..e380f9dd7df 100644
--- a/htdocs/fourn/product/liste.php
+++ b/htdocs/fourn/product/liste.php
@@ -94,37 +94,26 @@ if ($catid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.f
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid";
$sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
-if (GETPOST('mode', 'alpha') == 'search')
-{
- $sql .= natural_search(array('p.ref', 'p.label'), GETPOST('mode', 'alpha'));
-}
-else
-{
- if (GETPOST('type'))
- {
- $sql .= " AND p.fk_product_type = " . GETPOST('type','int');
- }
- if ($sref)
- {
- $sql .= natural_search('p.ref', $sref);
- }
- if ($sRefSupplier)
- {
- $sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
- }
- if ($snom)
- {
- $sql .= natural_search('p.label', $snom);
- }
- if($catid)
- {
- $sql .= " AND cp.fk_categorie = ".$catid;
- }
-}
if ($sRefSupplier)
{
$sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
}
+if (GETPOST('type'))
+{
+ $sql .= " AND p.fk_product_type = " . GETPOST('type','int');
+}
+if ($sref)
+{
+ $sql .= natural_search('p.ref', $sref);
+}
+if ($snom)
+{
+ $sql .= natural_search('p.label', $snom);
+}
+if($catid)
+{
+ $sql .= " AND cp.fk_categorie = ".$catid;
+}
if ($fourn_id > 0)
{
$sql .= " AND ppf.fk_soc = ".$fourn_id;
@@ -132,9 +121,7 @@ if ($fourn_id > 0)
$sql .= " ORDER BY ".$sortfield." ".$sortorder;
$sql .= $db->plimit($limit + 1, $offset);
-
-dol_syslog("fourn/product/liste: sql=".$sql);
-
+dol_syslog("fourn/product/liste.php: sql=".$sql);
$resql = $db->query($sql);
if ($resql)
{
@@ -142,10 +129,10 @@ if ($resql)
$i = 0;
- if ($num == 1 && ( isset($_POST["sall"]) || $snom || $sref ) )
+ if ($num == 1 && (GETPOST("mode") == 'search'))
{
$objp = $db->fetch_object($resql);
- header("Location: fiche.php?id=".$objp->rowid);
+ header("Location: ".DOL_URL_ROOT."/product/fiche.php?id=".$objp->rowid);
exit;
}
@@ -155,8 +142,8 @@ if ($resql)
llxHeader("","",$texte);
- $param="&tobuy=$tobuy&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":"");
- print_barre_liste($texte, $page, "liste.php", $param, $sortfield, $sortorder,'',$num);
+ $param="&tobuy=".$tobuy."&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type)?"&type=".$type:"").(empty($sRefSupplier)?"":"&srefsupplier=".$sRefSupplier);
+ print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num);
if (isset($catid))
@@ -168,27 +155,27 @@ if ($resql)
print "
";
}
-
- print '