2016-07-23 16:37:21 +02:00
< ? php
2017-04-07 12:22:59 +02:00
/* Copyright ( C ) 2016 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2016-07-23 16:37:21 +02:00
*
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2017-02-08 12:37:38 +01:00
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductAttribute.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductAttributeValue.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductCombination.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductCombination2ValuePair.class.php' ;
2016-07-23 16:37:21 +02:00
$langs -> load ( " products " );
$langs -> load ( " other " );
$var = false ;
$id = GETPOST ( 'id' , 'int' );
$valueid = GETPOST ( 'valueid' , 'int' );
$ref = GETPOST ( 'ref' );
$weight_impact = ( float ) GETPOST ( 'weight_impact' );
$price_impact = ( float ) GETPOST ( 'price_impact' );
$price_impact_percent = ( bool ) GETPOST ( 'price_impact_percent' );
$form = new Form ( $db );
2017-04-07 12:22:59 +02:00
$action = GETPOST ( 'action' , 'alpha' );
$massaction = GETPOST ( 'massaction' , 'alpha' );
$show_files = GETPOST ( 'show_files' , 'int' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
$toselect = GETPOST ( 'toselect' , 'array' );
2017-09-15 10:50:50 +02:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2016-07-23 16:37:21 +02:00
// Security check
$fieldvalue = ( ! empty ( $id ) ? $id : $ref );
$fieldtype = ( ! empty ( $ref ) ? 'ref' : 'rowid' );
$result = restrictedArea ( $user , 'produit|service' , $fieldvalue , 'product&product' , '' , '' , $fieldtype );
$prodstatic = new Product ( $db );
$prodattr = new ProductAttribute ( $db );
$prodattr_val = new ProductAttributeValue ( $db );
2017-02-08 12:52:31 +01:00
$object = new Product ( $db );
if ( $id > 0 || $ref )
{
$object -> fetch ( $id , $ref );
}
2016-07-23 16:37:21 +02:00
2017-04-07 12:22:59 +02:00
$selectedvariant = $_SESSION [ 'addvariant_' . $object -> id ];
2017-02-08 14:07:54 +01:00
2017-02-08 12:52:31 +01:00
/*
* Actions
*/
2016-07-23 16:37:21 +02:00
2017-04-07 11:01:12 +02:00
if ( $cancel ) {
$action = '' ;
2017-04-07 12:22:59 +02:00
$massactions = '' ;
unset ( $_SESSION [ 'addvariant_' . $object -> id ]);
2017-04-07 11:01:12 +02:00
}
2017-04-07 12:22:59 +02:00
2018-04-24 11:01:17 +02:00
if ( ! $object -> isProduct () && ! $object -> isService ()) {
2017-02-08 12:52:31 +01:00
header ( 'Location: ' . dol_buildpath ( '/product/card.php?id=' . $object -> id , 2 ));
exit ();
2016-07-23 16:37:21 +02:00
}
2017-11-26 18:43:43 +01:00
if ( $action == 'add' )
{
unset ( $selectedvariant );
unset ( $_SESSION [ 'addvariant_' . $object -> id ]);
}
if ( $action == 'create' && GETPOST ( 'selectvariant' , 'alpha' )) // We click on select combination
2017-04-07 12:22:59 +02:00
{
$action = 'add' ;
if ( GETPOST ( 'attribute' ) != '-1' && GETPOST ( 'value' ) != '-1' )
{
$selectedvariant [ GETPOST ( 'attribute' ) . ':' . GETPOST ( 'value' )] = GETPOST ( 'attribute' ) . ':' . GETPOST ( 'value' );
$_SESSION [ 'addvariant_' . $object -> id ] = $selectedvariant ;
}
}
2017-02-08 12:52:31 +01:00
2016-07-23 16:37:21 +02:00
$prodcomb = new ProductCombination ( $db );
$prodcomb2val = new ProductCombination2ValuePair ( $db );
$productCombination2ValuePairs1 = array ();
if ( $_POST ) {
2017-11-26 18:43:43 +01:00
if (( $action == 'add' || $action == 'create' ) && empty ( $massaction ) && ! GETPOST ( 'selectvariant' , 'alpha' )) // We click on Create all defined combinations
{
2017-04-07 12:22:59 +02:00
//$features = GETPOST('features', 'array');
$features = $_SESSION [ 'addvariant_' . $object -> id ];
2016-07-23 16:37:21 +02:00
if ( ! $features ) {
setEventMessage ( $langs -> trans ( 'ErrorFieldsRequired' ), 'errors' );
2017-07-28 09:45:23 +02:00
}
else
2017-04-07 12:22:59 +02:00
{
2016-07-23 16:37:21 +02:00
$weight_impact = price2num ( $weight_impact );
$price_impact = price2num ( $price_impact );
$sanit_features = array ();
//First, sanitize
foreach ( $features as $feature ) {
$explode = explode ( ':' , $feature );
if ( $prodattr -> fetch ( $explode [ 0 ]) < 0 ) {
continue ;
}
if ( $prodattr_val -> fetch ( $explode [ 1 ]) < 0 ) {
continue ;
}
2017-11-26 18:43:43 +01:00
// Valuepair
2016-07-23 16:37:21 +02:00
$sanit_features [ $explode [ 0 ]] = $explode [ 1 ];
$tmp = new ProductCombination2ValuePair ( $db );
$tmp -> fk_prod_attr = $explode [ 0 ];
$tmp -> fk_prod_attr_val = $explode [ 1 ];
$productCombination2ValuePairs1 [] = $tmp ;
}
$db -> begin ();
2017-11-26 18:43:43 +01:00
// sanit_feature is an array with 1 (and only 1) value per attribute.
// For example: Color->blue, Size->Small, Option->2
//var_dump($sanit_features);
//var_dump($productCombination2ValuePairs1); exit;
if ( ! $prodcomb -> fetchByProductCombination2ValuePairs ( $id , $sanit_features ))
{
$result = $prodcomb -> createProductCombination ( $object , $sanit_features , array (), $price_impact_percent , $price_impact , $weight_impact );
if ( $result > 0 )
{
2016-07-23 16:37:21 +02:00
setEventMessage ( $langs -> trans ( 'RecordSaved' ));
2017-04-07 12:22:59 +02:00
unset ( $_SESSION [ 'addvariant_' . $object -> id ]);
2017-11-26 18:43:43 +01:00
$db -> commit ();
2017-02-08 12:37:38 +01:00
header ( 'Location: ' . dol_buildpath ( '/variants/combinations.php?id=' . $id , 2 ));
2017-02-08 12:52:31 +01:00
exit ();
2016-07-23 16:37:21 +02:00
} else {
2017-11-26 18:43:43 +01:00
$langs -> load ( " errors " );
setEventMessages ( '' , $prodcomb -> errors , 'errors' );
2016-07-23 16:37:21 +02:00
}
} else {
2017-11-26 18:43:43 +01:00
setEventMessages ( $langs -> trans ( 'ErrorRecordAlreadyExists' ), null , 'errors' );
2016-07-23 16:37:21 +02:00
}
$db -> rollback ();
}
2017-07-28 09:45:23 +02:00
}
elseif ( ! empty ( $massaction ))
2017-04-07 12:22:59 +02:00
{
$bulkaction = $massaction ;
2016-07-23 16:37:21 +02:00
$error = 0 ;
$prodstatic = new Product ( $db );
$db -> begin ();
2017-04-07 12:22:59 +02:00
foreach ( $toselect as $prodid ) {
2016-07-23 16:37:21 +02:00
if ( $prodstatic -> fetch ( $prodid ) < 0 ) {
continue ;
}
if ( $bulkaction == 'on_sell' ) {
$prodstatic -> status = 1 ;
$res = $prodstatic -> update ( $prodstatic -> id , $user );
} elseif ( $bulkaction == 'on_buy' ) {
$prodstatic -> status_buy = 1 ;
$res = $prodstatic -> update ( $prodstatic -> id , $user );
} elseif ( $bulkaction == 'not_sell' ) {
$prodstatic -> status = 0 ;
$res = $prodstatic -> update ( $prodstatic -> id , $user );
} elseif ( $bulkaction == 'not_buy' ) {
$prodstatic -> status_buy = 0 ;
$res = $prodstatic -> update ( $prodstatic -> id , $user );
} elseif ( $bulkaction == 'delete' ) {
2017-11-26 18:43:43 +01:00
$res = $prodstatic -> delete ( $user , $prodstatic -> id );
2016-07-23 16:37:21 +02:00
} else {
break ;
}
if ( $res <= 0 ) {
$error ++ ;
break ;
}
}
if ( $error ) {
$db -> rollback ();
if ( $prodstatic -> error ) {
2017-11-26 18:43:43 +01:00
setEventMessages ( $prodstatic -> error , $prodstatic -> errors , 'errors' );
2016-07-23 16:37:21 +02:00
} else {
2017-11-26 18:43:43 +01:00
setEventMessages ( $langs -> trans ( 'CoreErrorMessage' ), null , 'errors' );
2016-07-23 16:37:21 +02:00
}
} else {
$db -> commit ();
setEventMessage ( $langs -> trans ( 'RecordSaved' ));
}
2017-07-28 09:45:23 +02:00
}
2017-04-07 12:22:59 +02:00
elseif ( $valueid > 0 ) {
2016-07-23 16:37:21 +02:00
if ( $prodcomb -> fetch ( $valueid ) < 0 ) {
dol_print_error ( $db , $langs -> trans ( 'ErrorRecordNotFound' ));
2017-02-08 12:52:31 +01:00
exit ();
2016-07-23 16:37:21 +02:00
}
$prodcomb -> variation_price_percentage = $price_impact_percent ;
$prodcomb -> variation_price = $price_impact ;
$prodcomb -> variation_weight = $weight_impact ;
2017-11-26 18:43:43 +01:00
if ( $prodcomb -> update ( $user ) > 0 ) {
2016-07-23 16:37:21 +02:00
setEventMessage ( $langs -> trans ( 'RecordSaved' ));
2017-02-08 12:37:38 +01:00
header ( 'Location: ' . dol_buildpath ( '/variants/combinations.php?id=' . $id , 2 ));
2017-02-08 12:52:31 +01:00
exit ();
2016-07-23 16:37:21 +02:00
} else {
2017-11-26 18:43:43 +01:00
setEventMessages ( $prodcomb -> error , $prodcomb -> errors , 'errors' );
2016-07-23 16:37:21 +02:00
}
}
}
2017-04-07 12:22:59 +02:00
// Reload variants
2017-02-08 12:52:31 +01:00
$productCombinations = $prodcomb -> fetchAllByFkProductParent ( $object -> id );
2016-07-23 16:37:21 +02:00
if ( $action === 'confirm_deletecombination' ) {
if ( $prodcomb -> fetch ( $valueid ) > 0 ) {
$db -> begin ();
2017-07-28 09:45:23 +02:00
if ( $prodcomb -> delete ( $user ) > 0 && $prodstatic -> fetch ( $prodcomb -> fk_product_child ) > 0 && $prodstatic -> delete ( $user ) > 0 ) {
2016-07-23 16:37:21 +02:00
$db -> commit ();
setEventMessage ( $langs -> trans ( 'RecordSaved' ));
2017-02-08 12:52:31 +01:00
header ( 'Location: ' . dol_buildpath ( '/variants/combinations.php?id=' . $object -> id , 2 ));
exit ();
2016-07-23 16:37:21 +02:00
}
$db -> rollback ();
setEventMessage ( $langs -> trans ( 'ProductCombinationAlreadyUsed' ), 'errors' );
$action = '' ;
}
} elseif ( $action === 'edit' ) {
if ( $prodcomb -> fetch ( $valueid ) < 0 ) {
dol_print_error ( $db , $langs -> trans ( 'ErrorRecordNotFound' ));
2017-02-08 12:52:31 +01:00
exit ();
2016-07-23 16:37:21 +02:00
}
$weight_impact = $prodcomb -> variation_weight ;
$price_impact = $prodcomb -> variation_price ;
$price_impact_percent = $prodcomb -> variation_price_percentage ;
$productCombination2ValuePairs1 = $prodcomb2val -> fetchByFkCombination ( $valueid );
} elseif ( $action === 'confirm_copycombination' ) {
//Check destination product
$dest_product = GETPOST ( 'dest_product' );
if ( $prodstatic -> fetch ( '' , $dest_product ) > 0 ) {
//To prevent from copying to the same product
2017-02-08 12:52:31 +01:00
if ( $prodstatic -> ref != $object -> ref ) {
if ( $prodcomb -> copyAll ( $object -> id , $prodstatic ) > 0 ) {
2017-02-08 12:37:38 +01:00
header ( 'Location: ' . dol_buildpath ( '/variants/combinations.php?id=' . $prodstatic -> id , 2 ));
2017-02-08 12:52:31 +01:00
exit ();
2016-07-23 16:37:21 +02:00
} else {
setEventMessage ( $langs -> trans ( 'ErrorCopyProductCombinations' ), 'errors' );
}
}
} else {
setEventMessage ( $langs -> trans ( 'ErrorDestinationProductNotFound' ), 'errors' );
}
}
2017-02-08 12:52:31 +01:00
2016-07-23 16:37:21 +02:00
/*
* View
*/
2017-04-07 11:01:12 +02:00
$form = new Form ( $db );
2017-07-28 09:45:23 +02:00
if ( ! empty ( $id ) || ! empty ( $ref ))
2017-04-07 12:22:59 +02:00
{
2016-07-23 16:37:21 +02:00
llxHeader ( " " , " " , $langs -> trans ( " CardProduct " . $object -> type ));
2017-04-07 12:22:59 +02:00
$showbarcode = empty ( $conf -> barcode -> enabled ) ? 0 : 1 ;
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> barcode -> lire_advance )) $showbarcode = 0 ;
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
$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 );
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/product/list.php?type=' . $object -> type . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
$object -> next_prev_filter = " fk_product_type = " . $object -> type ;
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , ( $user -> societe_id ? 0 : 1 ), 'ref' , '' , '' , '' , 0 , '' , '' , 1 );
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
dol_fiche_end ();
2016-07-23 16:37:21 +02:00
2017-07-28 09:45:23 +02:00
2017-03-11 12:04:28 +01:00
// Create or edit a varian
2016-07-23 16:37:21 +02:00
if ( $action == 'add' || ( $action == 'edit' )) {
if ( $action == 'add' ) {
$title = $langs -> trans ( 'NewProductCombination' );
2018-04-24 12:08:17 +02:00
print dol_fiche_head ();
$features = $_SESSION [ 'addvariant_' . $object -> id ];
//First, sanitize
print '<div id="parttoaddvariant">' ;
if ( ! empty ( $features )) {
foreach ( $features as $feature ) {
$explode = explode ( ':' , $feature );
if ( $prodattr -> fetch ( $explode [ 0 ]) < 0 ) {
continue ;
}
if ( $prodattr_val -> fetch ( $explode [ 1 ]) < 0 ) {
continue ;
}
print '<i>' . $prodattr -> label . '</i>:' . $prodattr_val -> value . ' ' ;
}
}
print '</div>' ;
print dol_fiche_end ();
2016-07-23 16:37:21 +02:00
} else {
$title = $langs -> trans ( 'EditProductCombination' );
}
print_fiche_titre ( $title );
if ( $action == 'add' ) {
$prodattr_all = $prodattr -> fetchAll ();
if ( ! $selected ) {
$selected = $prodattr_all [ key ( $prodattr_all )] -> id ;
}
$prodattr_alljson = array ();
foreach ( $prodattr_all as $each ) {
$prodattr_alljson [ $each -> id ] = $each ;
}
2018-04-24 12:08:17 +02:00
?>
2016-07-23 16:37:21 +02:00
2017-04-07 12:22:59 +02:00
< script type = " text/javascript " >
2016-07-23 16:37:21 +02:00
2018-03-10 14:51:24 +01:00
variants_available = < ? php echo json_encode ( $prodattr_alljson ); ?> ;
2017-02-08 12:37:38 +01:00
variants_selected = {
2016-07-23 16:37:21 +02:00
index : [],
info : []
};
2017-07-28 09:45:23 +02:00
< ? php
2017-03-11 12:04:28 +01:00
foreach ( $productCombination2ValuePairs1 as $pc2v ) {
$prodattr_val -> fetch ( $pc2v -> fk_prod_attr_val );
2016-07-23 16:37:21 +02:00
?>
2017-03-11 12:04:28 +01:00
variants_selected . index . push ( < ? php echo $pc2v -> fk_prod_attr ?> );
variants_selected . info [ < ? php echo $pc2v -> fk_prod_attr ?> ] = {
attribute : variants_available [ < ? php echo $pc2v -> fk_prod_attr ?> ],
value : {
id : < ? php echo $pc2v -> fk_prod_attr_val ?> ,
label : '<?php echo $prodattr_val->value ?>'
}
};
2017-07-28 09:45:23 +02:00
< ? php
}
2017-03-11 12:04:28 +01:00
?>
2016-07-23 16:37:21 +02:00
restoreAttributes = function () {
2017-03-11 12:04:28 +01:00
jQuery ( " select[name=attribute] " ) . empty () . append ( '<option value="-1"> </option>' );
2016-07-23 16:37:21 +02:00
2017-02-08 12:37:38 +01:00
jQuery . each ( variants_available , function ( key , val ) {
if ( jQuery . inArray ( val . id , variants_selected . index ) == - 1 ) {
2016-07-23 16:37:21 +02:00
jQuery ( " select[name=attribute] " ) . append ( '<option value="' + val . id + '">' + val . label + '</option>' );
}
});
};
2017-07-28 09:45:23 +02:00
2016-07-23 16:37:21 +02:00
jQuery ( document ) . ready ( function () {
jQuery ( " select#attribute " ) . change ( function () {
2017-04-07 11:01:12 +02:00
console . log ( " Change of field variant attribute " );
2016-07-23 16:37:21 +02:00
var select = jQuery ( " select#value " );
2017-03-11 12:04:28 +01:00
if ( ! jQuery ( this ) . val () . length || jQuery ( this ) . val () == '-1' ) {
2016-07-23 16:37:21 +02:00
select . empty ();
2017-04-07 11:01:12 +02:00
select . append ( '<option value="-1"> </option>' );
2016-07-23 16:37:21 +02:00
return ;
}
select . empty () . append ( '<option value="">Loading...</option>' );
2018-04-11 11:44:22 +02:00
jQuery . getJSON ( " ajax/get_attribute_values.php " , {
2016-07-23 16:37:21 +02:00
id : jQuery ( this ) . val ()
}, function ( data ) {
if ( data . error ) {
2017-04-07 11:01:12 +02:00
select . empty ();
select . append ( '<option value="-1"> </option>' );
2016-07-23 16:37:21 +02:00
return alert ( data . error );
}
select . empty ();
2017-04-07 11:01:12 +02:00
select . append ( '<option value="-1"> </option>' );
2016-07-23 16:37:21 +02:00
jQuery ( data ) . each ( function ( key , val ) {
2017-03-11 12:04:28 +01:00
keyforoption = val . id
valforoption = val . value
2017-04-07 11:01:12 +02:00
select . append ( '<option value="' + keyforoption + '">' + valforoption + '</option>' );
2016-07-23 16:37:21 +02:00
});
});
});
});
</ script >
2017-07-28 09:45:23 +02:00
< ? php
2017-03-11 12:04:28 +01:00
}
2017-07-28 09:45:23 +02:00
2017-11-26 18:43:43 +01:00
print '<form method="post" id="combinationform" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2017-04-07 12:22:59 +02:00
print '<input type="hidden" name="id" value="' . dol_escape_htmltag ( $id ) . '">' . " \n " ;
2018-03-10 14:51:24 +01:00
print '<input type="hidden" name="action" value="' . (( $valueid > 0 ) ? " update " : " create " ) . '">' . " \n " ;
if ( $valueid > 0 ) {
print '<input type="hidden" name="valueid" value="' . $valueid . '">' . " \n " ;
}
2017-03-11 12:04:28 +01:00
print dol_fiche_head ();
2017-07-28 09:45:23 +02:00
2017-03-11 12:04:28 +01:00
?>
2017-07-28 09:45:23 +02:00
2016-07-23 16:37:21 +02:00
< table class = " border " style = " width: 100% " >
2017-03-11 12:04:28 +01:00
< ? php if ( $action == 'add' ) { ?>
2017-04-07 11:01:12 +02:00
<!-- Variant -->
2016-07-23 16:37:21 +02:00
< tr >
2017-03-11 12:04:28 +01:00
< td class = " titlefieldcreate fieldrequired " >< label for = " attribute " >< ? php echo $langs -> trans ( 'ProductAttribute' ) ?> </label></td>
2017-11-26 10:13:32 +01:00
< td >
< ? php
if ( is_array ( $prodattr_all ))
{
print '<select class="flat minwidth100" id="attribute" name="attribute">' ;
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 >
2016-07-23 16:37:21 +02:00
</ tr >
2017-04-07 11:01:12 +02:00
<!-- Value -->
2016-07-23 16:37:21 +02:00
< tr >
2017-03-11 12:04:28 +01:00
< td class = " fieldrequired " >< label for = " value " >< ? php echo $langs -> trans ( 'Value' ) ?> </label></td>
2017-04-07 11:01:12 +02:00
< td >
2017-03-11 12:04:28 +01:00
< select class = " flat minwidth100 " id = " value " name = " value " >
< option value = " -1 " >& nbsp ; </ option >
2016-07-23 16:37:21 +02:00
</ select >
2017-11-26 10:13:32 +01:00
< ? 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>' ;
*/
?>
2016-07-23 16:37:21 +02:00
</ td >
</ tr >
< tr >
2017-04-07 11:01:12 +02:00
< td ></ td >< td >
2017-04-07 12:22:59 +02:00
< input type = " submit " class = " button " name = " selectvariant " id = " selectvariant " value = " <?php echo dol_escape_htmltag( $langs->trans ( " SelectCombination " )); ?> " >
2017-04-07 11:01:12 +02:00
</ td >
</ tr >
</ table >
2017-11-26 18:43:43 +01:00
< ? php
}
2018-03-10 14:51:24 +01:00
if ( is_array ( $productCombination2ValuePairs1 )) {
2017-11-26 18:43:43 +01:00
?>
2017-04-07 11:01:12 +02:00
< hr >
< table class = " border " style = " width: 100% " >
< tr >
2017-11-26 18:43:43 +01:00
< td class = " titlefieldcreate fieldrequired tdtop " >< label for = " features " >< ? php echo $langs -> trans ( 'Combination' ) ?> </label></td>
2017-04-07 12:22:59 +02:00
< td class = " tdtop " >
2017-04-07 11:01:12 +02:00
< div class = " inline-block valignmiddle quatrevingtpercent " >
2017-04-07 12:22:59 +02:00
< ? php
2018-03-10 14:51:24 +01:00
if ( is_array ( $productCombination2ValuePairs1 ))
2017-04-07 12:22:59 +02:00
{
2018-03-10 14:51:24 +01:00
foreach ( $productCombination2ValuePairs1 as $key => $val ) {
$result1 = $prodattr -> fetch ( $val -> fk_prod_attr );
$result2 = $prodattr_val -> fetch ( $val -> fk_prod_attr_val );
if ( $result1 > 0 && $result2 > 0 )
{
print $prodattr -> label . ' - ' . $prodattr_val -> value . '<br>' ;
// TODO Add delete link
}
}
2017-04-07 12:22:59 +02:00
}
?>
2017-04-07 11:01:12 +02:00
</ div >
2017-04-07 12:22:59 +02:00
<!-- < div class = " inline-block valignmiddle " >
< a href = " # " class = " inline-block valignmiddle button " id = " delfeature " >< ? php echo img_edit_remove () ?> </a>
</ div >-->
2017-04-07 11:01:12 +02:00
</ td >
2016-07-23 16:37:21 +02:00
< td >
</ td >
</ tr >
< tr >
2017-03-11 12:04:28 +01:00
< td >< label for = " price_impact " >< ? php echo $langs -> trans ( 'PriceImpact' ) ?> </label></td>
2017-04-07 11:01:12 +02:00
< td >< input type = " text " id = " price_impact " name = " price_impact " value = " <?php echo price( $price_impact ) ?> " >
2016-07-23 16:37:21 +02:00
< input type = " checkbox " id = " price_impact_percent " name = " price_impact_percent " < ? php echo $price_impact_percent ? ' checked' : '' ?> > <label for="price_impact_percent"><?php echo $langs->trans('PercentageVariation') ?></label></td>
</ tr >
2018-04-24 11:01:17 +02:00
< ? php if ( $object -> isProduct ()) {
print '<tr>' ;
print '<td><label for="weight_impact">' . $langs -> trans ( 'WeightImpact' ) . '</label></td>' ;
print '<td><input type="text" id="weight_impact" name="weight_impact" value="' . price ( $weight_impact ) . '"></td>' ;
print '</tr>' ;
}
print '</table>' ;
2017-11-26 18:43:43 +01:00
}
print dol_fiche_end ();
2017-03-11 12:04:28 +01:00
?>
< div style = " text-align: center " >
2018-03-10 14:51:24 +01:00
< input type = " submit " name = " create " < ? php if ( ! is_array ( $productCombination2ValuePairs1 )) print ' disabled="disabled"' ; ?> value="<?php echo $action == 'add' ? $langs->trans('Create') : $langs->trans('Save') ?>" class="button">
2017-04-07 11:01:12 +02:00
& nbsp ;
< input type = " submit " name = " cancel " value = " <?php echo $langs->trans ('Cancel'); ?> " class = " button " >
</ div >
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
< ? php
2016-07-23 16:37:21 +02:00
2017-03-11 12:04:28 +01:00
print '</form>' ;
}
2017-07-28 09:45:23 +02:00
else
2017-03-11 12:04:28 +01:00
{
2016-07-23 16:37:21 +02:00
if ( $action === 'delete' ) {
if ( $prodcomb -> fetch ( $valueid ) > 0 ) {
$prodstatic -> fetch ( $prodcomb -> fk_product_child );
print $form -> formconfirm (
" combinations.php?id= " . $id . " &valueid= " . $valueid ,
$langs -> trans ( 'Delete' ),
2017-02-08 12:37:38 +01:00
$langs -> trans ( 'ProductCombinationDeleteDialog' , $prodstatic -> ref ),
2016-07-23 16:37:21 +02:00
" confirm_deletecombination " ,
'' ,
0 ,
1
);
}
} elseif ( $action === 'copy' ) {
print $form -> formconfirm (
'combinations.php?id=' . $id ,
$langs -> trans ( 'CloneCombinationsProduct' ),
$langs -> trans ( 'ConfirmCloneProductCombinations' ),
'confirm_copycombination' ,
array (
array (
'type' => 'text' ,
'label' => $langs -> trans ( 'CloneDestinationReference' ),
'name' => 'dest_product'
)
),
0 ,
1
);
}
$comb2val = new ProductCombination2ValuePair ( $db );
2017-07-28 09:45:23 +02:00
if ( $productCombinations )
2017-02-08 12:52:31 +01:00
{
?>
2016-07-23 16:37:21 +02:00
< script type = " text/javascript " >
jQuery ( document ) . ready ( function () {
jQuery ( 'input[name="select_all"]' ) . click ( function () {
if ( jQuery ( this ) . prop ( 'checked' )) {
var checked = true ;
} else {
var checked = false ;
}
jQuery ( 'table.liste input[type="checkbox"]' ) . prop ( 'checked' , checked );
});
jQuery ( 'input[name^="select["]' ) . click ( function () {
jQuery ( 'input[name="select_all"]' ) . prop ( 'checked' , false );
});
});
</ script >
2017-07-28 09:45:23 +02:00
< ? php }
2017-04-07 11:01:12 +02:00
// Buttons
2017-03-11 12:04:28 +01:00
print '<div class="tabsAction">' ;
2017-07-28 09:45:23 +02:00
2017-03-11 12:04:28 +01:00
print ' <div class="inline-block divButAction">' ;
if ( $productCombinations ) {
2017-04-07 12:22:59 +02:00
print '<a href="combinations.php?id=' . $object -> id . '&action=copy" class="butAction">' . $langs -> trans ( 'PropagateVariant' ) . '</a>' ;
2017-03-11 12:04:28 +01:00
}
2017-07-28 09:45:23 +02:00
2017-11-26 10:13:32 +01:00
print '<a href="combinations.php?id=' . $object -> id . '&action=add" class="butAction">' . $langs -> trans ( 'NewProductCombination' ) . '</a>' ; // NewVariant
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
// Too much bugged page.
/*
print '<a href="generator.php?id=' . $object -> id . '" class="butAction">' . $langs -> trans ( 'ProductCombinationGenerator' ) . '</a>' ;
*/
2017-07-28 09:45:23 +02:00
2017-03-11 12:04:28 +01:00
print ' </div>' ;
2017-07-28 09:45:23 +02:00
2017-03-11 12:04:28 +01:00
print '</div>' ;
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
// List of variants
2017-11-26 10:13:32 +01:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2017-11-26 18:43:43 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="massaction">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">' ;
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
// List of mass actions available
/*
$arrayofmassactions = array (
'presend' => $langs -> trans ( " SendByMail " ),
'builddoc' => $langs -> trans ( " PDFMerge " ),
);
2017-11-15 11:39:11 +01:00
if ( $user -> rights -> product -> supprimer ) $arrayofmassactions [ 'predelete' ] = $langs -> trans ( " Delete " );
2017-11-11 16:03:22 +01:00
if ( in_array ( $massaction , array ( 'presend' , 'predelete' ))) $arrayofmassactions = array ();
2017-04-07 12:22:59 +02:00
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
*/
2017-07-28 09:45:23 +02:00
2017-04-07 11:01:12 +02:00
$aaa = '' ;
if ( count ( $productCombinations ))
{
2017-04-07 12:22:59 +02:00
$aaa = '<label for="massaction">' . $langs -> trans ( 'BulkActions' ) . '</label>' ;
$aaa .= '<select id="bulk_action" name="massaction" class="flat">' ;
$aaa .= ' <option value="nothing"> </option>' ;
2017-04-07 11:01:12 +02:00
$aaa .= ' <option value="not_buy">' . $langs -> trans ( 'ProductStatusNotOnBuy' ) . '</option>' ;
$aaa .= ' <option value="not_sell">' . $langs -> trans ( 'ProductStatusNotOnSell' ) . '</option>' ;
$aaa .= ' <option value="on_buy">' . $langs -> trans ( 'ProductStatusOnBuy' ) . '</option>' ;
$aaa .= ' <option value="on_sell">' . $langs -> trans ( 'ProductStatusOnSell' ) . '</option>' ;
$aaa .= ' <option value="delete">' . $langs -> trans ( 'Delete' ) . '</option>' ;
$aaa .= '</select>' ;
$aaa .= '<input type="submit" value="' . dol_escape_htmltag ( $langs -> trans ( " Apply " )) . '" class="button">' ;
}
2017-04-07 12:22:59 +02:00
$massactionbutton = $aaa ;
2017-07-28 09:45:23 +02:00
2017-04-07 11:01:12 +02:00
$title = $langs -> trans ( " ProductCombinations " );
2017-07-28 09:45:23 +02:00
2017-04-07 11:01:12 +02:00
print_barre_liste ( $title , 0 , $_SERVER [ " PHP_SELF " ], '' , $sortfield , $sortorder , $aaa , 0 );
2017-07-28 09:45:23 +02:00
2017-04-07 11:01:12 +02:00
print '<div class="div-table-responsive">' ;
2017-03-11 12:04:28 +01:00
?>
2016-07-23 16:37:21 +02:00
< table class = " liste " >
< tr class = " liste_titre " >
2017-04-07 12:22:59 +02:00
< td class = " liste_titre " >< ? php echo $langs -> trans ( 'Product' ) ?> </td>
< td class = " liste_titre " >< ? php echo $langs -> trans ( 'Combination' ) ?> </td>
< td class = " liste_titre right " >< ? php echo $langs -> trans ( 'PriceImpact' ) ?> </td>
2018-04-24 11:01:17 +02:00
< ? php if ( $object -> isProduct ()) print '<td class="liste_titre right">' . $langs -> trans ( 'WeightImpact' ) . '</td>' ; ?>
2017-04-07 12:22:59 +02:00
< td class = " liste_titre center " >< ? php echo $langs -> trans ( 'OnSell' ) ?> </td>
< td class = " liste_titre center " >< ? php echo $langs -> trans ( 'OnBuy' ) ?> </td>
< td class = " liste_titre " ></ td >
2017-07-28 09:45:23 +02:00
< ? php
2017-04-07 12:22:59 +02:00
print '<td class="liste_titre" align="middle">' ;
2017-05-14 21:20:35 +02:00
$searchpicto = $form -> showCheckAddButtons ( 'checkforselect' , 1 );
print $searchpicto ;
2017-04-07 12:22:59 +02:00
print '</td>' ;
?>
2016-07-23 16:37:21 +02:00
</ tr >
2017-03-12 17:10:32 +01:00
< ? php
2017-07-28 09:45:23 +02:00
2017-03-12 17:10:32 +01:00
if ( count ( $productCombinations ))
{
2017-11-26 18:43:43 +01:00
foreach ( $productCombinations as $currcomb )
{
2017-07-28 09:45:23 +02:00
$prodstatic -> fetch ( $currcomb -> fk_product_child );
2017-03-12 17:10:32 +01:00
?>
2017-04-07 11:01:12 +02:00
< tr class = " oddeven " >
2017-03-12 17:10:32 +01:00
< td >< ? php echo $prodstatic -> getNomUrl ( 1 ) ?> </td>
< td >
< ? php
2017-07-28 09:45:23 +02:00
2017-03-12 17:10:32 +01:00
$productCombination2ValuePairs = $comb2val -> fetchByFkCombination ( $currcomb -> id );
$iMax = count ( $productCombination2ValuePairs );
2017-07-28 09:45:23 +02:00
2017-03-12 17:10:32 +01:00
for ( $i = 0 ; $i < $iMax ; $i ++ ) {
echo dol_htmlentities ( $productCombination2ValuePairs [ $i ]);
2017-07-28 09:45:23 +02:00
2017-03-12 17:10:32 +01:00
if ( $i !== ( $iMax - 1 )) {
echo ', ' ;
}
} ?>
</ td >
2017-04-07 11:01:12 +02:00
< td class = " right " >< ? php echo ( $currcomb -> variation_price >= 0 ? '+' : '' ) . price ( $currcomb -> variation_price ) . ( $currcomb -> variation_price_percentage ? ' %' : '' ) ?> </td>
2018-04-24 11:01:17 +02:00
< ? php if ( $object -> isProduct ()) print '<td class="right">' . ( $currcomb -> variation_weight >= 0 ? '+' : '' ) . price ( $currcomb -> variation_weight ) . ' ' . measuring_units_string ( $prodstatic -> weight_units , 'weight' ) . '</td>' ; ?>
2017-03-12 17:10:32 +01:00
< td style = " text-align: center; " >< ? php echo $prodstatic -> getLibStatut ( 2 , 0 ) ?> </td>
< td style = " text-align: center; " >< ? php echo $prodstatic -> getLibStatut ( 2 , 1 ) ?> </td>
2017-04-07 11:01:12 +02:00
< td class = " right " >
< a class = " paddingleft paddingright " href = " <?php echo dol_buildpath('/variants/combinations.php?id='. $id .'&action=edit&valueid='. $currcomb->id , 2) ?> " >< ? php echo img_edit () ?> </a>
< a class = " paddingleft paddingright " href = " <?php echo dol_buildpath('/variants/combinations.php?id='. $id .'&action=delete&valueid='. $currcomb->id , 2) ?> " >< ? php echo img_delete () ?> </a>
2017-03-12 17:10:32 +01:00
</ td >
2017-07-28 09:45:23 +02:00
< ? php
2017-04-07 12:22:59 +02:00
print '<td class="nowrap" align="center">' ;
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 '<input id="cb' . $prodstatic -> id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $prodstatic -> id . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
}
print '</td>' ;
?>
2017-03-12 17:10:32 +01:00
</ tr >
< ? php
}
}
else
{
2017-07-28 09:45:23 +02:00
print '<tr><td colspan="8"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
2017-03-12 17:10:32 +01:00
}
?>
2016-07-23 16:37:21 +02:00
</ table >
< ? php
2017-04-07 11:01:12 +02:00
print '</div>' ;
2017-11-26 18:43:43 +01:00
2017-04-07 11:01:12 +02:00
print '</form>' ;
2016-07-23 16:37:21 +02:00
}
2018-04-11 12:10:58 +02:00
} else {
llxHeader ();
// not found
2016-07-23 16:37:21 +02:00
}
2018-04-11 12:10:58 +02:00
2016-07-23 16:37:21 +02:00
llxFooter ();
2017-04-07 11:01:12 +02:00
$db -> close ();