NEW Can include product variants in list of products

This commit is contained in:
Laurent Destailleur 2023-08-26 22:18:49 +02:00
parent 8946320154
commit ae89f278ef
2 changed files with 20 additions and 19 deletions

View file

@ -387,6 +387,7 @@ ErrorDeletingGeneratedProducts=There was an error while trying to delete existin
NbOfDifferentValues=No. of different values
NbProducts=Number of products
ParentProduct=Parent product
ParentProductOfVariant=Parent product of variant
HideChildProducts=Hide variant products
ShowChildProducts=Show variant products
NoEditVariants=Go to Parent product card and edit variants price impact in the variants tab

View file

@ -105,12 +105,9 @@ $optioncss = GETPOST('optioncss', 'alpha');
$type = GETPOST("type", "int");
$mode = GETPOST('mode', 'alpha');
//Show/hide child products
if (isModEnabled('variants') && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { // PRODUIT_ATTRIBUTES_HIDECHILD means: show the checkbox to show/hide child
// Show/hide child product variants
if (isModEnabled('variants')) {
$show_childproducts = GETPOST('search_show_childproducts');
} else {
$show_childproducts = '';
}
$diroutputmassaction = $conf->product->dir_output.'/temp/massgeneration/'.$user->id;
@ -226,7 +223,7 @@ $arrayfields = array(
'p.fk_product_type'=>array('label'=>"Type", 'checked'=>0, 'enabled'=>(isModEnabled("product") && isModEnabled("service")), 'position'=>11),
'p.barcode'=>array('label'=>"Gencod", 'checked'=>1, 'enabled'=>(isModEnabled('barcode')), 'position'=>12),
'p.duration'=>array('label'=>"Duration", 'checked'=>($contextpage != 'productlist'), 'enabled'=>(isModEnabled("service") && (string) $type == '1'), 'position'=>13),
'pac.fk_product_parent' => array('label'=>"ParentProduct", 'checked'=> -1, 'enabled'=>(isModEnabled('variants')), 'position'=>14),
'pac.fk_product_parent' => array('label'=>"ParentProductOfVariant", 'checked'=>-1, 'enabled'=>(isModEnabled('variants')), 'position'=>14),
'p.finished'=>array('label'=>"Nature", 'checked'=>0, 'enabled'=>(isModEnabled("product") && $type != '1'), 'position'=>19),
'p.weight'=>array('label'=>'Weight', 'checked'=>0, 'enabled'=>(isModEnabled("product") && $type != '1'), 'position'=>20),
'p.weight_units'=>array('label'=>'WeightUnits', 'checked'=>0, 'enabled'=>(isModEnabled("product") && $type != '1'), 'position'=>21),
@ -441,7 +438,7 @@ if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
}
$sql .= ' p.datec as date_creation, p.tms as date_update, p.pmp, p.stock, p.cost_price,';
$sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, fk_country, fk_state,';
if (!empty($conf->global->PRODUCT_USE_UNITS)) {
if (getDolGlobalString('PRODUCT_USE_UNITS')) {
$sql .= ' p.fk_unit, cu.label as cu_label,';
}
$sql .= ' MIN(pfp.unitprice) as bestpurchaseprice';
@ -479,11 +476,10 @@ $sql .= $linktopfp;
if (getDolGlobalInt('MAIN_MULTILANGS')) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$db->escape($langs->getDefaultLang())."'";
}
if (isModEnabled('variants')) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid";
}
if (!empty($conf->global->PRODUCT_USE_UNITS)) {
if (getDolGlobalString('PRODUCT_USE_UNITS')) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units cu ON cu.rowid = p.fk_unit";
}
@ -509,7 +505,7 @@ if (dol_strlen($search_type) && $search_type != '-1') {
}
}
if (isModEnabled('variants') && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) {
if (isModEnabled('variants') && !$show_childproducts) {
$sql .= " AND pac.rowid IS NULL";
}
@ -619,13 +615,12 @@ if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
$sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export, ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
}
$sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.fk_country, p.fk_state';
if (!empty($conf->global->PRODUCT_USE_UNITS)) {
if (getDolGlobalString('PRODUCT_USE_UNITS')) {
$sql .= ', p.fk_unit, cu.label';
}
if (isModEnabled('workstation')) {
$sql .= ', p.fk_default_workstation, ws.status, ws.ref ';
$sql .= ', p.fk_default_workstation, ws.status, ws.ref';
}
if (isModEnabled('variants')) {
$sql .= ', pac.rowid';
$sql .= ', pac.fk_product_parent';
@ -912,8 +907,8 @@ if (isModEnabled('categorie') && $user->hasRight('categorie', 'read')) {
$moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PRODUCT, $searchCategoryProductList, 'minwidth300', $searchCategoryProductOperator ? $searchCategoryProductOperator : 0);
}
//Show/hide child products. Hidden by default
if (isModEnabled('variants') && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
// Show/hide child variant products
if (isModEnabled('variants')) {
$moreforfilter .= '<div class="divsearchfield">';
$moreforfilter .= '<input type="checkbox" id="search_show_childproducts" name="search_show_childproducts"'.($show_childproducts ? 'checked="checked"' : '').'>';
$moreforfilter .= ' <label for="search_show_childproducts">'.$langs->trans('ShowChildProducts').'</label>';
@ -1272,7 +1267,7 @@ if (!empty($arrayfields['p.duration']['checked'])) {
$totalarray['nbfield']++;
}
if (!empty($arrayfields['pac.fk_product_parent']['checked'])) {
print_liste_field_titre($arrayfields['pac.fk_product_parent']['label'], $_SERVER["PHP_SELF"], "pac.fk_product_parent", "", $param, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre($arrayfields['pac.fk_product_parent']['label'], $_SERVER["PHP_SELF"], "pac.fk_product_parent", "", $param, '', $sortfield, $sortorder, '', $arrayfields['pac.fk_product_parent']['help']);
}
if (!empty($arrayfields['p.finished']['checked'])) {
print_liste_field_titre($arrayfields['p.finished']['label'], $_SERVER["PHP_SELF"], "p.finished", "", $param, '', $sortfield, $sortorder, 'center ');
@ -1685,10 +1680,15 @@ while ($i < $imaxinloop) {
}
if (!empty($arrayfields['pac.fk_product_parent']['checked'])) {
print '<td class="center nowraponall">';
print '<td class="nowraponall">';
if ($obj->fk_product_parent > 0) {
$product_parent_static= new Product($db);
$product_parent_static->fetch($obj->fk_product_parent);
if (!empty($conf->cache['product'][$obj->fk_product_parent])) {
$product_parent_static = $conf->cache['product'][$obj->fk_product_parent];
} else {
$product_parent_static= new Product($db);
$product_parent_static->fetch($obj->fk_product_parent);
$conf->cache['product'][$obj->fk_product_parent] = $product_parent_static;
}
print $product_parent_static->getNomUrl(1);
}
print '</td>';