Debug module variant

This commit is contained in:
Laurent Destailleur 2017-11-26 10:13:32 +01:00
parent 8352aee9f7
commit 1ec6c13ece
6 changed files with 112 additions and 44 deletions

View File

@ -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

View File

@ -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') { ?>
</div>
</div>
<?php if ($action == 'edit_value'): ?>
<form method="post">
<?php endif ?>
<?php
print_fiche_titre($langs->trans("PossibleValues"));
if ($action == 'edit_value') {
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<input type="hidden" name="valueid" value="'.$valueid.'">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
} ?>
<table class="liste">
<tr class="liste_titre">
<th class="liste_titre"><?php echo $langs->trans('Ref') ?></th>
<th class="liste_titre titlefield"><?php echo $langs->trans('Ref') ?></th>
<th class="liste_titre"><?php echo $langs->trans('Value') ?></th>
<th class="liste_titre"></th>
</tr>
<?php foreach ($objectval->fetchAllByProductAttribute($object->id) as $attrval): ?>
<tr <?php echo $bc[!$var] ?>>
<?php
foreach ($objectval->fetchAllByProductAttribute($object->id) as $attrval) {
?>
<tr class="oddeven">
<?php if ($action == 'edit_value' && ($valueid == $attrval->id)): ?>
<td><input type="text" name="ref" value="<?php echo $attrval->ref ?>"></td>
<td><input type="text" name="value" value="<?php echo $attrval->value ?>"></td>
<td style="text-align: right">
<input type="submit" value="<?php echo $langs->trans('Save') ?>" class="button">
&nbsp; &nbsp;
&nbsp; &nbsp;
<input type="submit" name="cancel" value="<?php echo $langs->trans('Cancel') ?>" class="button">
</td>
<?php else: ?>
@ -256,8 +268,7 @@ if ($action == 'edit') { ?>
<?php endif; ?>
</tr>
<?php
$var = !$var;
endforeach
}
?>
</table>

View File

@ -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()

View File

@ -421,12 +421,27 @@ if (! empty($id) || ! empty($ref))
<!-- Variant -->
<tr>
<td class="titlefieldcreate fieldrequired"><label for="attribute"><?php echo $langs->trans('ProductAttribute') ?></label></td>
<td><select class="flat minwidth100" id="attribute" name="attribute">
<option value="-1">&nbsp;</option>
<?php foreach ($prodattr_all as $attr): ?>
<option value="<?php echo $attr->id ?>"><?php echo $attr->label ?></option>
<?php endforeach ?>
</select></td>
<td>
<?php
if (is_array($prodattr_all))
{
print '<select class="flat minwidth100" id="attribute" name="attribute">';
print '<option value="-1">&nbsp;</option>';
foreach ($prodattr_all as $attr)
{
print '<option value="'.$attr->id.'">'.$attr->label.'</option>';
}
print '</select>';
}
$htmltext=$langs->trans("GoOnMenuToCreateVairants", $langs->transnoentities("Product"), $langs->transnoentities("VariantAttributes"));
print $form->textwithpicto('', $htmltext);
/*print ' &nbsp; &nbsp; <a href="'.DOL_URL_ROOT.'/variants/create.php?action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=add&id='.$object->id).'">';
print $langs->trans("Create");
print '</a>';*/
?>
</td>
</tr>
<!-- Value -->
<tr>
@ -435,12 +450,20 @@ if (! empty($id) || ! empty($ref))
<select class="flat minwidth100" id="value" name="value">
<option value="-1">&nbsp;</option>
</select>
<?php
$htmltext=$langs->trans("GoOnMenuToCreateVairants", $langs->transnoentities("Product"), $langs->transnoentities("VariantAttributes"));
print $form->textwithpicto('', $htmltext);
/*
print ' &nbsp; &nbsp; <a href="'.DOL_URL_ROOT.'/variants/create.php?action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=add&id='.$object->id).'">';
print $langs->trans("Create");
print '</a>';
*/
?>
</td>
</tr>
<tr>
<td></td><td>
<input type="submit" class="button" name="selectvariant" id="selectvariant" value="<?php echo dol_escape_htmltag($langs->trans("SelectCombination")); ?>">
<!-- <a href="#" class="button" id="addfeature"><?php echo $langs->trans("SelectCombination"); ?></a> -->
</td>
</tr>
</table>
@ -573,7 +596,7 @@ if (! empty($id) || ! empty($ref))
print '<a href="combinations.php?id='.$object->id.'&action=copy" class="butAction">'.$langs->trans('PropagateVariant').'</a>';
}
print '<a href="combinations.php?id='.$object->id.'&action=add#parttoaddvariant" class="butAction">'.$langs->trans('NewProductCombination').'</a>'; // NewVariant
print '<a href="combinations.php?id='.$object->id.'&action=add" class="butAction">'.$langs->trans('NewProductCombination').'</a>'; // NewVariant
// Too much bugged page.
/*
@ -590,7 +613,7 @@ if (! empty($id) || ! empty($ref))
// List of variants
print '<form method="POST" action="#parttoaddvariant">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
// List of mass actions available

View File

@ -1,5 +1,4 @@
<?php
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
*
* 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 '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
?>
<form method="post">
<table class="border" style="width: 100%">
<tr>
<td class="fieldrequired"><label for="ref"><?php echo $langs->trans('Ref') ?></label></td>
<td class="titlefield fieldrequired"><label for="ref"><?php echo $langs->trans('Ref') ?></label></td>
<td><input type="text" id="ref" name="ref" value="<?php echo $ref ?>"></td>
<td><?php echo $langs->trans("VariantRefExample"); ?>
</tr>
<tr>
<td class="fieldrequired"><label for="label"><?php echo $langs->trans('Label') ?></label></td>
<td><input type="text" id="label" name="label" value="<?php echo $label ?>"></td>
<td><?php echo $langs->trans("VariantLabelExample"); ?>
</tr>
</table>
@ -68,6 +93,9 @@ dol_fiche_head();
<?php
dol_fiche_end();
print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></div></form>';
print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></div>';
llxFooter();
print '</form>';
llxFooter();
$db->close();

View File

@ -128,7 +128,7 @@ dol_fiche_head();
<td><input id="ref" type="text" name="ref" value="<?php echo $ref ?>"></td>
</tr>
<tr>
<td class="fieldrequired"><label for="value"><?php echo $langs->trans('Value') ?></label></td>
<td class="fieldrequired"><label for="value"><?php echo $langs->trans('Label') ?></label></td>
<td><input id="value" type="text" name="value" value="<?php echo $value ?>"></td>
</tr>
</table>