From 1ec6c13ecec19abd414c2a140a90f3824c726f0f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 26 Nov 2017 10:13:32 +0100 Subject: [PATCH] Debug module variant --- htdocs/langs/en_US/products.lang | 4 ++ htdocs/variants/card.php | 33 ++++++++---- .../variants/class/ProductAttribute.class.php | 26 +++++----- htdocs/variants/combinations.php | 41 +++++++++++---- htdocs/variants/create.php | 50 +++++++++++++++---- htdocs/variants/create_val.php | 2 +- 6 files changed, 112 insertions(+), 44 deletions(-) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 67c7fa81da0..a1d81183c41 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -202,6 +202,8 @@ UseMultipriceRules=Use price segment rules (defined into product module setup) t PercentVariationOver=%% variation over %s PercentDiscountOver=%% discount over %s KeepEmptyForAutoCalculation=Keep empty to have this calculated automatically from weight or volume of products +VariantRefExample=Example: COL +VariantLabelExample=Example: Color ### composition fabrication Build=Produce ProductsMultiPrice=Products and prices for each price segment @@ -285,6 +287,8 @@ ConfirmDeleteProductBuyPrice=Are you sure you want to delete this buying price? SubProduct=Sub product ProductSheet=Product sheet ServiceSheet=Service sheet +PossibleValues=Possible values +GoOnMenuToCreateVairants=Go on menu %s - %s to prepare attribute variants (like colors, size, ...) #Attributes VariantAttributes=Variant attributes diff --git a/htdocs/variants/card.php b/htdocs/variants/card.php index f5d35019971..c191c1fd4c3 100644 --- a/htdocs/variants/card.php +++ b/htdocs/variants/card.php @@ -56,7 +56,7 @@ if ($_POST) { header('Location: '.dol_buildpath('/variants/card.php?id='.$id, 2)); exit(); } - } elseif ($action == 'edit_value') { + } elseif ($action == 'update') { if ($objectval->fetch($valueid) > 0) { @@ -94,7 +94,7 @@ if ($confirm == 'yes') { } exit(); } - elseif ($action == 'confirm_deletevalue') + elseif ($action == 'confirm_deletevalue') { if ($objectval->fetch($valueid) > 0) { @@ -225,25 +225,37 @@ if ($action == 'edit') { ?> - -
- + + trans("PossibleValues")); + + if ($action == 'edit_value') { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } ?> - + - fetchAllByProductAttribute($object->id) as $attrval): ?> - > + fetchAllByProductAttribute($object->id) as $attrval) { + ?> + id)): ?> @@ -256,8 +268,7 @@ if ($action == 'edit') { ?>
trans('Ref') ?>trans('Ref') ?> trans('Value') ?>
-     +    
diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php index 792a0f67e93..7995dc89919 100644 --- a/htdocs/variants/class/ProductAttribute.class.php +++ b/htdocs/variants/class/ProductAttribute.class.php @@ -106,39 +106,41 @@ class ProductAttribute if ($query) { while ($result = $this->db->fetch_object($query)) { - + $tmp = new ProductAttribute($this->db); $tmp->id = $result->rowid; $tmp->ref = $result->ref; $tmp->label = $result->label; $tmp->rang = $result->rang; - + $return[] = $tmp; } } else dol_print_error($this->db); - + return $return; } /** * Creates a product attribute * - * @return int <0 KO, >0 OK + * @param User $user Object user that create + * @return int <0 KO, Id of new variant if OK */ - public function create() + public function create(User $user) { //Ref must be uppercase $this->ref = strtoupper($this->ref); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_attribute (ref, label, entity, rang) + $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_attribute (ref, label, entity, rang) VALUES ('".$this->db->escape($this->ref)."', '".$this->db->escape($this->label)."', ".(int) $this->entity.", ".(int) $this->rang.")"; - $query = $this->db->query($sql); - if ($query) { + $query = $this->db->query($sql); + if ($query) + { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'product_attribute'); - return 1; + return $this->id; } return -1; @@ -193,7 +195,7 @@ class ProductAttribute return $result->count; } - + /** * Returns the number of products that are using this attribute * @@ -211,7 +213,7 @@ class ProductAttribute return $result->count; } - + /** * Reorders the order of the variants. * This is an internal function used by moveLine function @@ -298,7 +300,7 @@ class ProductAttribute /** * Shows this attribute after others - * + * * @return int <0 KO >0 OK */ public function moveDown() diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index 7be3c4e60f1..a15d4781500 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -421,12 +421,27 @@ if (! empty($id) || ! empty($ref)) - + + '; + print ''; + foreach ($prodattr_all as $attr) + { + print ''; + } + print ''; + } + + $htmltext=$langs->trans("GoOnMenuToCreateVairants", $langs->transnoentities("Product"), $langs->transnoentities("VariantAttributes")); + print $form->textwithpicto('', $htmltext); + /*print '     id).'">'; + print $langs->trans("Create"); + print '';*/ + + ?> + @@ -435,12 +450,20 @@ if (! empty($id) || ! empty($ref)) + trans("GoOnMenuToCreateVairants", $langs->transnoentities("Product"), $langs->transnoentities("VariantAttributes")); + print $form->textwithpicto('', $htmltext); + /* + print '     id).'">'; + print $langs->trans("Create"); + print ''; + */ + ?> "> - @@ -573,7 +596,7 @@ if (! empty($id) || ! empty($ref)) print ''.$langs->trans('PropagateVariant').''; } - print ''.$langs->trans('NewProductCombination').''; // NewVariant + print ''.$langs->trans('NewProductCombination').''; // NewVariant // Too much bugged page. /* @@ -590,7 +613,7 @@ if (! empty($id) || ! empty($ref)) // List of variants - print ''; + print ''; // List of mass actions available diff --git a/htdocs/variants/create.php b/htdocs/variants/create.php index 0cd68cb4d02..f1a34a835b6 100644 --- a/htdocs/variants/create.php +++ b/htdocs/variants/create.php @@ -1,5 +1,4 @@ * * This program is free software; you can redistribute it and/or modify @@ -17,13 +16,18 @@ */ require '../main.inc.php'; -require 'class/ProductAttribute.class.php'; +require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php'; -$ref = GETPOST('ref'); -$label = GETPOST('label'); +$ref = GETPOST('ref', 'alpha'); +$label = GETPOST('label', 'alpha'); +$backtopage = GETPOST('backtopage', 'alpha'); + + +/* + * Actions + */ if ($_POST) { - if (empty($ref) || empty($label)) { setEventMessage($langs->trans('ErrorFieldsRequired'), 'errors'); } else { @@ -32,9 +36,18 @@ if ($_POST) { $prodattr->label = $label; $prodattr->ref = $ref; - if ($prodattr->create()) { + $resid = $prodattr->create($user); + if ($resid > 0) { setEventMessage($langs->trans('RecordSaved')); - header('Location: '.dol_buildpath('/variants/list.php', 2)); + if ($backtopage) + { + header('Location: '.$backtopage); + } + else + { + header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$resid.'&backtopage='.urlencode($backtopage)); + } + exit; } else { setEventMessage($langs->trans('ErrorRecordAlreadyExists'), 'errors'); } @@ -43,6 +56,11 @@ if ($_POST) { $langs->load('products'); + +/* + * View + */ + $title = $langs->trans('NewProductAttribute'); llxHeader('', $title); @@ -51,16 +69,23 @@ print_fiche_titre($title); dol_fiche_head(); +print ''; +print ''; +print ''; +print ''; + ?> - + - + + +
trans("VariantRefExample"); ?>
trans("VariantLabelExample"); ?>
@@ -68,6 +93,9 @@ dol_fiche_head();
'; +print '
'; -llxFooter(); \ No newline at end of file +print ''; + +llxFooter(); +$db->close(); diff --git a/htdocs/variants/create_val.php b/htdocs/variants/create_val.php index 2f463286787..7c624765e32 100644 --- a/htdocs/variants/create_val.php +++ b/htdocs/variants/create_val.php @@ -128,7 +128,7 @@ dol_fiche_head(); - +