From aa47575b13f64e2b062a796168be7feb2fd8252c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Apr 2017 12:22:59 +0200 Subject: [PATCH] Serious debug of variant module. No more fu.. js errors on smarpthone. --- htdocs/langs/en_US/products.lang | 3 +- htdocs/variants/combinations.php | 282 +++++++++++++++---------------- 2 files changed, 140 insertions(+), 145 deletions(-) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index ef4c13c89cc..72ec89c55d3 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -283,6 +283,7 @@ ProductAttributeValueDeleteDialog=Are you sure you want to delete the value "%s" ProductCombinationDeleteDialog=Are you sure want to delete the variant of the product "%s"? ProductCombinationAlreadyUsed=There was an error while deleting the variant. Please check it is not being used in any object ProductCombinations=Variants +PropagateVariant=Propagate variants HideProductCombinations=Hide products variant in the products selector ProductCombination=Variant NewProductCombination=New variant @@ -307,7 +308,7 @@ NbOfDifferentValues=Nb of different values NbProducts=Nb. of products ParentProduct=Parent product HideChildProducts=Hide variant products -ConfirmCloneProductCombinations=Would you like to copy all the product variant to the product with the given reference? +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 ErrorDestinationProductNotFound=Destination product not found diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index cfbec4a8016..4342b352478 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -1,6 +1,6 @@ +/* Copyright (C) 2016 Marcos García + * Copyright (C) 2017 Laurent Destailleur * * 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 @@ -35,7 +35,12 @@ $weight_impact = (float) GETPOST('weight_impact'); $price_impact = (float) GETPOST('price_impact'); $price_impact_percent = (bool) GETPOST('price_impact_percent'); $form = new Form($db); -$action = GETPOST('action'); + +$action=GETPOST('action','alpha'); +$massaction=GETPOST('massaction','alpha'); +$show_files=GETPOST('show_files','int'); +$confirm=GETPOST('confirm','alpha'); +$toselect = GETPOST('toselect', 'array'); $cancel = GETPOST('cancel'); // Security check @@ -53,6 +58,8 @@ if ($id > 0 || $ref) $object->fetch($id, $ref); } +$selectedvariant = $_SESSION['addvariant_'.$object->id]; + /* * Actions @@ -60,13 +67,25 @@ if ($id > 0 || $ref) if ($cancel) { $action=''; + $massactions=''; + unset($_SESSION['addvariant_'.$object->id]); } - + if (! $object->isProduct()) { header('Location: '.dol_buildpath('/product/card.php?id='.$object->id, 2)); exit(); } +if (GETPOST('selectvariant')) +{ + $action = 'add'; + if (GETPOST('attribute') != '-1' && GETPOST('value') != '-1') + { + $selectedvariant[GETPOST('attribute').':'.GETPOST('value')]=GETPOST('attribute').':'.GETPOST('value'); + $_SESSION['addvariant_'.$object->id]=$selectedvariant; + } +} + $prodcomb = new ProductCombination($db); $prodcomb2val = new ProductCombination2ValuePair($db); @@ -75,13 +94,16 @@ $productCombination2ValuePairs1 = array(); if ($_POST) { - if ($action == 'add') { + if (($action == 'add' || $action == 'create') && empty($massaction) && ! GETPOST('selectvariant')) { - $features = GETPOST('features', 'array'); + //$features = GETPOST('features', 'array'); + $features = $_SESSION['addvariant_'.$object->id]; if (!$features) { setEventMessage($langs->trans('ErrorFieldsRequired'), 'errors'); - } else { + } + else + { $weight_impact = price2num($weight_impact); $price_impact = price2num($price_impact); $sanit_features = array(); @@ -115,6 +137,7 @@ if ($_POST) { if (ProductCombination::createProductCombination($object, $sanit_features, array(), $price_impact_percent, $price_impact, $weight_impact)) { $db->commit(); setEventMessage($langs->trans('RecordSaved')); + unset($_SESSION['addvariant_'.$object->id]); header('Location: '.dol_buildpath('/variants/combinations.php?id='.$id, 2)); exit(); } else { @@ -126,17 +149,17 @@ if ($_POST) { $db->rollback(); } - } elseif ($action == 'bulk_actions') { - - $prodarray = array_keys(GETPOST('select', 'array')); - $bulkaction = GETPOST('bulk_action'); + } + elseif (! empty($massaction)) + { + $bulkaction = $massaction; $error = 0; $prodstatic = new Product($db); $db->begin(); - foreach ($prodarray as $prodid) { + foreach ($toselect as $prodid) { if ($prodstatic->fetch($prodid) < 0) { continue; @@ -180,7 +203,8 @@ if ($_POST) { setEventMessage($langs->trans('RecordSaved')); } - } elseif ($valueid > 0) { + } + elseif ($valueid > 0) { if ($prodcomb->fetch($valueid) < 0) { dol_print_error($db, $langs->trans('ErrorRecordNotFound')); @@ -201,6 +225,7 @@ if ($_POST) { } } +// Reload variants $productCombinations = $prodcomb->fetchAllByFkProductParent($object->id); if ($action === 'confirm_deletecombination') { @@ -263,29 +288,26 @@ if ($action === 'confirm_deletecombination') { $form = new Form($db); - -if (! empty($id) || ! empty($ref)) { - +if (! empty($id) || ! empty($ref)) +{ llxHeader("", "", $langs->trans("CardProduct".$object->type)); - if ($result) - { - $showbarcode=empty($conf->barcode->enabled)?0:1; - if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0; - - $head=product_prepare_head($object); - $titre=$langs->trans("CardProduct".$object->type); - $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); - dol_fiche_head($head, 'combinations', $titre, 0, $picto); - - $linkback = ''.$langs->trans("BackToList").''; - $object->next_prev_filter=" fk_product_type = ".$object->type; - - dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref', '', '', '', 0, '', '', 1); - - dol_fiche_end(); - } + $showbarcode=empty($conf->barcode->enabled)?0:1; + if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0; + + $head=product_prepare_head($object); + $titre=$langs->trans("CardProduct".$object->type); + $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); + dol_fiche_head($head, 'combinations', $titre, 0, $picto); + + $linkback = ''.$langs->trans("BackToList").''; + $object->next_prev_filter=" fk_product_type = ".$object->type; + + dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref', '', '', '', 0, '', '', 1); + + dol_fiche_end(); + // Create or edit a varian if ($action == 'add' || ($action == 'edit')) { @@ -295,6 +317,7 @@ if (! empty($id) || ! empty($ref)) { $title = $langs->trans('EditProductCombination'); } + print '
'; print_fiche_titre($title); if ($action == 'add') { @@ -312,7 +335,7 @@ if (! empty($id) || ! empty($ref)) { ?> - + '; - print ''; + print '
'."\n"; + print ''."\n"; + print ''."\n"; print dol_fiche_head(); @@ -483,7 +439,8 @@ if (! empty($id) || ! empty($ref)) { - trans("SelectCombination"); ?> + "> + @@ -493,17 +450,27 @@ if (! empty($id) || ! empty($ref)) { - @@ -524,15 +491,12 @@ if (! empty($id) || ! empty($ref)) { ?>
- + value="trans('Create') : $langs->trans('Save') ?>" class="button">  
- - - -'; } @@ -606,36 +570,56 @@ if (! empty($id) || ! empty($ref)) { print '
'; if ($productCombinations) { - print ''.$langs->trans('Copy').''; + print ''.$langs->trans('PropagateVariant').''; } - print ''.$langs->trans('NewProductCombination').''; + print ''.$langs->trans('NewProductCombination').''; // NewVariant - if (empty($conf->dol_optimize_smallscreen) && $conf->use_javascript_ajax) // Bugged page. Too much useless javascript. - { - print ''.$langs->trans('ProductCombinationGenerator').''; - } + // Too much bugged page. + /* + print ''.$langs->trans('ProductCombinationGenerator').''; + */ print '
'; print ''; - print ''; + + + $arrayofselected=is_array($toselect)?$toselect:array(); + + + // List of variants + print ''; + + + // List of mass actions available + /* + $arrayofmassactions = array( + 'presend'=>$langs->trans("SendByMail"), + 'builddoc'=>$langs->trans("PDFMerge"), + ); + if ($user->rights->product->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete"); + if ($massaction == 'presend' || $massaction == 'createbills') $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); + */ $aaa=''; if (count($productCombinations)) { - $aaa = ''; - $aaa .= ''; + $aaa .= ' '; $aaa .= ' '; $aaa .= ' '; $aaa .= ' '; $aaa .= ' '; $aaa .= ' '; $aaa .= ''; - $aaa .= ''; + $aaa .= ''; $aaa .= ''; } + $massactionbutton = $aaa; $title = $langs->trans("ProductCombinations"); @@ -645,18 +629,19 @@ if (! empty($id) || ! empty($ref)) { ?>
+
-
-
- + $val) { + $tmp = explode(':',$val); + $result1 = $prodattr->fetch($tmp[0]); + $result2 = $prodattr_val->fetch($tmp[1]); + if ($result1 > 0 && $result2 > 0) + { + print $prodattr->label . ' - '.$prodattr_val->value.'
'; + // TODO Add delete link + } + } + } + ?>
+
- - - - - - - - + + + + + + + + '; + $searchpitco=$form->showCheckAddButtons('checkforselect', 1); + print $searchpitco; + print ''; + ?> id, 2) ?>"> - + '; + if ($productCombinations || $massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + { + $selected=0; + if (in_array($prodstatic->id, $arrayofselected)) $selected=1; + print ''; + } + print ''; + ?>
trans('Product') ?>trans('Combination') ?>trans('PriceImpact') ?>trans('WeightImpact') ?>trans('OnSell') ?>trans('OnBuy') ?> - - - - trans('Product') ?>trans('Combination') ?>trans('PriceImpact') ?>trans('WeightImpact') ?>trans('OnSell') ?>trans('OnBuy') ?>