From ab55ff2e2c71218ba84ca6683e64169615620acd Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Thu, 11 Oct 2018 15:44:23 +0200 Subject: [PATCH] New: works with variants: - Make the checkbox working correctly --- htdocs/langs/en_US/products.lang | 1 + htdocs/product/class/product.class.php | 2 +- htdocs/product/list.php | 37 ++++++++++--------- htdocs/product/stock/product.php | 2 +- .../class/ProductCombination.class.php | 1 + 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 0dde8ad538a..33be55ec336 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -330,6 +330,7 @@ NbOfDifferentValues=No. of different values NbProducts=No. of products ParentProduct=Parent product HideChildProducts=Hide variant products +ShowChildProducts=Show variant products ConfirmCloneProductCombinations=Would you like to copy all the product variants to the other parent product with the given reference? CloneDestinationReference=Destination product reference ErrorCopyProductCombinations=There was an error while copying the product variants diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 3257f9bbde5..adb17e67235 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -4,7 +4,7 @@ * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2007-2011 Jean Heimburger - * Copyright (C) 2010-2013 Juanjo Menent + * Copyright (C) 2010-2018 Juanjo Menent * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013-2014 Cedric GROSS * Copyright (C) 2013-2016 Marcos García diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 720ef957c01..9028ceb15c2 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2018 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012-2016 Marcos García - * Copyright (C) 2013-2016 Juanjo Menent + * Copyright (C) 2013-2018 Juanjo Menent * Copyright (C) 2013-2015 Raphaël Doursenaud * Copyright (C) 2013 Jean Heimburger * Copyright (C) 2013 Cédric Salvador @@ -53,7 +53,7 @@ $sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alp $search_ref=GETPOST("search_ref"); $search_barcode=GETPOST("search_barcode"); $search_label=GETPOST("search_label"); -$search_type = GETPOST("search_type",'int'); +$search_type = GETPOST("search_type", 'int'); $search_sale = GETPOST("search_sale"); $search_categ = GETPOST("search_categ",'int'); $search_tosell = GETPOST("search_tosell", 'int'); @@ -66,11 +66,11 @@ $search_accountancy_code_buy = GETPOST("search_accountancy_code_buy",'alpha'); $optioncss = GETPOST('optioncss','alpha'); $type=GETPOST("type","int"); -//Show/hide child products. Hidden by default -if (!$_POST) { - $search_hidechildproducts = 'on'; +//Show/hide child products +if (!empty($conf->variants->enabled) && ! empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { + $show_childproducts = GETPOST('show_childproducts'); } else { - $search_hidechildproducts = GETPOST('search_hidechildproducts'); + $show_childproducts = ''; } $diroutputmassaction=$conf->product->dir_output . '/temp/massgeneration/'.$user->id; @@ -219,6 +219,8 @@ if (empty($reshook)) $search_tobuy=""; $search_tobatch=''; //$search_type=''; // There is 2 types of list: a list of product and a list of services. No list with both. So when we clear search criteria, we must keep the filter on type. + + $show_childproducts = ''; $search_accountancy_code_sell=''; $search_accountancy_code_buy=''; $search_array_options=array(); @@ -265,7 +267,7 @@ $sql.= ' p.fk_product_type, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, $sql.= ' p.tobatch, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy,'; $sql.= ' p.datec as date_creation, p.tms as date_update, p.pmp,'; $sql.= ' MIN(pfp.unitprice) as minsellprice'; -if (!empty($conf->variants->enabled) && $search_hidechildproducts && ($search_type === 0)) { +if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && ! $show_childproducts )) { $sql .= ', pac.rowid prod_comb_id'; } // Add fields from extrafields @@ -282,11 +284,8 @@ if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREF $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; // multilang if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$langs->getDefaultLang() ."'"; -if (!empty($conf->variants->enabled) && $search_hidechildproducts && ($search_type === 0)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid"; -} -if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { +if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && ! $show_childproducts )) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid"; } @@ -300,7 +299,7 @@ if (dol_strlen($search_type) && $search_type != '-1') else $sql.= " AND p.fk_product_type <> 1"; } -if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { +if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && ! $show_childproducts )) { $sql .= " AND pac.rowid IS NULL"; } @@ -318,7 +317,7 @@ if ($fourn_id > 0) $sql.= " AND pfp.fk_soc = ".$fourn_id; if ($search_tobatch != '' && $search_tobatch >= 0) $sql.= " AND p.tobatch = ".$db->escape($search_tobatch); if ($search_accountancy_code_sell) $sql.= natural_search('p.accountancy_code_sell', $search_accountancy_code_sell); if ($search_accountancy_code_buy) $sql.= natural_search('p.accountancy_code_buy', $search_accountancy_code_buy); -if (!empty($conf->variants->enabled) && $search_hidechildproducts && ($search_type === 0)) $sql .= " AND pac.rowid IS NULL"; + // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -328,7 +327,10 @@ $sql.=$hookmanager->resPrint; $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,"; $sql.= " p.fk_product_type, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,"; $sql.= ' p.datec, p.tms, p.entity, p.tobatch, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.pmp'; -if (!empty($conf->variants->enabled) && $search_hidechildproducts && ($search_type === 0)) $sql .= ', pac.rowid'; + +if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && ! $show_childproducts )) { + $sql .= ', pac.rowid'; +} // Add fields from extrafields if (! empty($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : ''); @@ -402,6 +404,7 @@ if ($resql) if ($search_tobuy != '') $param.="&search_tobuy=".urlencode($search_tobuy); if ($fourn_id > 0) $param.=($fourn_id?"&fourn_id=".$fourn_id:""); if ($seach_categ) $param.=($search_categ?"&search_categ=".urlencode($search_categ):""); + if ($show_childproducts) $param.=($show_childproducts?"&show_childproducts=".urlencode($show_childproducts):""); if ($type != '') $param.='&type='.urlencode($type); if ($search_type != '') $param.='&search_type='.urlencode($search_type); if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); @@ -477,10 +480,10 @@ if ($resql) } //Show/hide child products. Hidden by default - if (!empty($conf->variants->enabled) && $search_type === 0) { + if (!empty($conf->variants->enabled) && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD )) { $moreforfilter.='
'; - $moreforfilter.= ''; - $moreforfilter.= ' '; + $moreforfilter.= ''; + $moreforfilter.= ' '; $moreforfilter.='
'; } diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 51871736a3d..dc291eb0fdc 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -5,7 +5,7 @@ * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Cédric Salvador - * Copyright (C) 2013-2015 Juanjo Menent + * Copyright (C) 2013-2018 Juanjo Menent * Copyright (C) 2014-2015 Cédric Gross * Copyright (C) 2015 Marcos García * Copyright (C) 2018 Frédéric France diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 3c94e775ee0..8908bfa4d2d 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -1,6 +1,7 @@ + * Copyright (C) 2018 Juanjo Menent * * 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