Debug module variant
This commit is contained in:
parent
8352aee9f7
commit
1ec6c13ece
@ -202,6 +202,8 @@ UseMultipriceRules=Use price segment rules (defined into product module setup) t
|
|||||||
PercentVariationOver=%% variation over %s
|
PercentVariationOver=%% variation over %s
|
||||||
PercentDiscountOver=%% discount over %s
|
PercentDiscountOver=%% discount over %s
|
||||||
KeepEmptyForAutoCalculation=Keep empty to have this calculated automatically from weight or volume of products
|
KeepEmptyForAutoCalculation=Keep empty to have this calculated automatically from weight or volume of products
|
||||||
|
VariantRefExample=Example: COL
|
||||||
|
VariantLabelExample=Example: Color
|
||||||
### composition fabrication
|
### composition fabrication
|
||||||
Build=Produce
|
Build=Produce
|
||||||
ProductsMultiPrice=Products and prices for each price segment
|
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
|
SubProduct=Sub product
|
||||||
ProductSheet=Product sheet
|
ProductSheet=Product sheet
|
||||||
ServiceSheet=Service sheet
|
ServiceSheet=Service sheet
|
||||||
|
PossibleValues=Possible values
|
||||||
|
GoOnMenuToCreateVairants=Go on menu %s - %s to prepare attribute variants (like colors, size, ...)
|
||||||
|
|
||||||
#Attributes
|
#Attributes
|
||||||
VariantAttributes=Variant attributes
|
VariantAttributes=Variant attributes
|
||||||
|
|||||||
@ -56,7 +56,7 @@ if ($_POST) {
|
|||||||
header('Location: '.dol_buildpath('/variants/card.php?id='.$id, 2));
|
header('Location: '.dol_buildpath('/variants/card.php?id='.$id, 2));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
} elseif ($action == 'edit_value') {
|
} elseif ($action == 'update') {
|
||||||
|
|
||||||
if ($objectval->fetch($valueid) > 0) {
|
if ($objectval->fetch($valueid) > 0) {
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ if ($confirm == 'yes') {
|
|||||||
}
|
}
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
elseif ($action == 'confirm_deletevalue')
|
elseif ($action == 'confirm_deletevalue')
|
||||||
{
|
{
|
||||||
if ($objectval->fetch($valueid) > 0) {
|
if ($objectval->fetch($valueid) > 0) {
|
||||||
|
|
||||||
@ -225,25 +225,37 @@ if ($action == 'edit') { ?>
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if ($action == 'edit_value'): ?>
|
|
||||||
<form method="post">
|
<?php
|
||||||
<?php endif ?>
|
|
||||||
|
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">
|
<table class="liste">
|
||||||
<tr class="liste_titre">
|
<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"><?php echo $langs->trans('Value') ?></th>
|
||||||
<th class="liste_titre"></th>
|
<th class="liste_titre"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<?php foreach ($objectval->fetchAllByProductAttribute($object->id) as $attrval): ?>
|
<?php
|
||||||
<tr <?php echo $bc[!$var] ?>>
|
foreach ($objectval->fetchAllByProductAttribute($object->id) as $attrval) {
|
||||||
|
?>
|
||||||
|
<tr class="oddeven">
|
||||||
<?php if ($action == 'edit_value' && ($valueid == $attrval->id)): ?>
|
<?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="ref" value="<?php echo $attrval->ref ?>"></td>
|
||||||
<td><input type="text" name="value" value="<?php echo $attrval->value ?>"></td>
|
<td><input type="text" name="value" value="<?php echo $attrval->value ?>"></td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
<input type="submit" value="<?php echo $langs->trans('Save') ?>" class="button">
|
<input type="submit" value="<?php echo $langs->trans('Save') ?>" class="button">
|
||||||
|
|
||||||
<input type="submit" name="cancel" value="<?php echo $langs->trans('Cancel') ?>" class="button">
|
<input type="submit" name="cancel" value="<?php echo $langs->trans('Cancel') ?>" class="button">
|
||||||
</td>
|
</td>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
@ -256,8 +268,7 @@ if ($action == 'edit') { ?>
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
$var = !$var;
|
}
|
||||||
endforeach
|
|
||||||
?>
|
?>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@ -106,39 +106,41 @@ class ProductAttribute
|
|||||||
if ($query)
|
if ($query)
|
||||||
{
|
{
|
||||||
while ($result = $this->db->fetch_object($query)) {
|
while ($result = $this->db->fetch_object($query)) {
|
||||||
|
|
||||||
$tmp = new ProductAttribute($this->db);
|
$tmp = new ProductAttribute($this->db);
|
||||||
$tmp->id = $result->rowid;
|
$tmp->id = $result->rowid;
|
||||||
$tmp->ref = $result->ref;
|
$tmp->ref = $result->ref;
|
||||||
$tmp->label = $result->label;
|
$tmp->label = $result->label;
|
||||||
$tmp->rang = $result->rang;
|
$tmp->rang = $result->rang;
|
||||||
|
|
||||||
$return[] = $tmp;
|
$return[] = $tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else dol_print_error($this->db);
|
else dol_print_error($this->db);
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a product attribute
|
* 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
|
//Ref must be uppercase
|
||||||
$this->ref = strtoupper($this->ref);
|
$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.")";
|
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');
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'product_attribute');
|
||||||
|
|
||||||
return 1;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -193,7 +195,7 @@ class ProductAttribute
|
|||||||
|
|
||||||
return $result->count;
|
return $result->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of products that are using this attribute
|
* Returns the number of products that are using this attribute
|
||||||
*
|
*
|
||||||
@ -211,7 +213,7 @@ class ProductAttribute
|
|||||||
return $result->count;
|
return $result->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reorders the order of the variants.
|
* Reorders the order of the variants.
|
||||||
* This is an internal function used by moveLine function
|
* This is an internal function used by moveLine function
|
||||||
@ -298,7 +300,7 @@ class ProductAttribute
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows this attribute after others
|
* Shows this attribute after others
|
||||||
*
|
*
|
||||||
* @return int <0 KO >0 OK
|
* @return int <0 KO >0 OK
|
||||||
*/
|
*/
|
||||||
public function moveDown()
|
public function moveDown()
|
||||||
|
|||||||
@ -421,12 +421,27 @@ if (! empty($id) || ! empty($ref))
|
|||||||
<!-- Variant -->
|
<!-- Variant -->
|
||||||
<tr>
|
<tr>
|
||||||
<td class="titlefieldcreate fieldrequired"><label for="attribute"><?php echo $langs->trans('ProductAttribute') ?></label></td>
|
<td class="titlefieldcreate fieldrequired"><label for="attribute"><?php echo $langs->trans('ProductAttribute') ?></label></td>
|
||||||
<td><select class="flat minwidth100" id="attribute" name="attribute">
|
<td>
|
||||||
<option value="-1"> </option>
|
<?php
|
||||||
<?php foreach ($prodattr_all as $attr): ?>
|
if (is_array($prodattr_all))
|
||||||
<option value="<?php echo $attr->id ?>"><?php echo $attr->label ?></option>
|
{
|
||||||
<?php endforeach ?>
|
print '<select class="flat minwidth100" id="attribute" name="attribute">';
|
||||||
</select></td>
|
print '<option value="-1"> </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 ' <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>
|
||||||
<!-- Value -->
|
<!-- Value -->
|
||||||
<tr>
|
<tr>
|
||||||
@ -435,12 +450,20 @@ if (! empty($id) || ! empty($ref))
|
|||||||
<select class="flat minwidth100" id="value" name="value">
|
<select class="flat minwidth100" id="value" name="value">
|
||||||
<option value="-1"> </option>
|
<option value="-1"> </option>
|
||||||
</select>
|
</select>
|
||||||
|
<?php
|
||||||
|
$htmltext=$langs->trans("GoOnMenuToCreateVairants", $langs->transnoentities("Product"), $langs->transnoentities("VariantAttributes"));
|
||||||
|
print $form->textwithpicto('', $htmltext);
|
||||||
|
/*
|
||||||
|
print ' <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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td><td>
|
<td></td><td>
|
||||||
<input type="submit" class="button" name="selectvariant" id="selectvariant" value="<?php echo dol_escape_htmltag($langs->trans("SelectCombination")); ?>">
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</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=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.
|
// Too much bugged page.
|
||||||
/*
|
/*
|
||||||
@ -590,7 +613,7 @@ if (! empty($id) || ! empty($ref))
|
|||||||
|
|
||||||
|
|
||||||
// List of variants
|
// List of variants
|
||||||
print '<form method="POST" action="#parttoaddvariant">';
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||||
|
|
||||||
|
|
||||||
// List of mass actions available
|
// List of mass actions available
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
|
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -17,13 +16,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require '../main.inc.php';
|
require '../main.inc.php';
|
||||||
require 'class/ProductAttribute.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
|
||||||
|
|
||||||
$ref = GETPOST('ref');
|
$ref = GETPOST('ref', 'alpha');
|
||||||
$label = GETPOST('label');
|
$label = GETPOST('label', 'alpha');
|
||||||
|
$backtopage = GETPOST('backtopage', 'alpha');
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Actions
|
||||||
|
*/
|
||||||
|
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
|
|
||||||
if (empty($ref) || empty($label)) {
|
if (empty($ref) || empty($label)) {
|
||||||
setEventMessage($langs->trans('ErrorFieldsRequired'), 'errors');
|
setEventMessage($langs->trans('ErrorFieldsRequired'), 'errors');
|
||||||
} else {
|
} else {
|
||||||
@ -32,9 +36,18 @@ if ($_POST) {
|
|||||||
$prodattr->label = $label;
|
$prodattr->label = $label;
|
||||||
$prodattr->ref = $ref;
|
$prodattr->ref = $ref;
|
||||||
|
|
||||||
if ($prodattr->create()) {
|
$resid = $prodattr->create($user);
|
||||||
|
if ($resid > 0) {
|
||||||
setEventMessage($langs->trans('RecordSaved'));
|
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 {
|
} else {
|
||||||
setEventMessage($langs->trans('ErrorRecordAlreadyExists'), 'errors');
|
setEventMessage($langs->trans('ErrorRecordAlreadyExists'), 'errors');
|
||||||
}
|
}
|
||||||
@ -43,6 +56,11 @@ if ($_POST) {
|
|||||||
|
|
||||||
$langs->load('products');
|
$langs->load('products');
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
$title = $langs->trans('NewProductAttribute');
|
$title = $langs->trans('NewProductAttribute');
|
||||||
|
|
||||||
llxHeader('', $title);
|
llxHeader('', $title);
|
||||||
@ -51,16 +69,23 @@ print_fiche_titre($title);
|
|||||||
|
|
||||||
dol_fiche_head();
|
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%">
|
<table class="border" style="width: 100%">
|
||||||
<tr>
|
<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><input type="text" id="ref" name="ref" value="<?php echo $ref ?>"></td>
|
||||||
|
<td><?php echo $langs->trans("VariantRefExample"); ?>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="fieldrequired"><label for="label"><?php echo $langs->trans('Label') ?></label></td>
|
<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><input type="text" id="label" name="label" value="<?php echo $label ?>"></td>
|
||||||
|
<td><?php echo $langs->trans("VariantLabelExample"); ?>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
@ -68,6 +93,9 @@ dol_fiche_head();
|
|||||||
<?php
|
<?php
|
||||||
dol_fiche_end();
|
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();
|
||||||
|
|||||||
@ -128,7 +128,7 @@ dol_fiche_head();
|
|||||||
<td><input id="ref" type="text" name="ref" value="<?php echo $ref ?>"></td>
|
<td><input id="ref" type="text" name="ref" value="<?php echo $ref ?>"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<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>
|
<td><input id="value" type="text" name="value" value="<?php echo $value ?>"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user