2021-08-31 15:46:14 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
2024-03-07 16:20:32 +01:00
use Models\Module ;
2021-08-31 15:46:14 +02:00
$numero_varianti = $combinazione -> articoli () -> count ();
echo '
< form action = " " method = " post " id = " edit-form " enctype = " multipart/form-data " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " update " >
< div class = " panel panel-primary " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Dati ').' </ h3 >
</ div >
< div class = " panel-body " >
< div class = " row " >
< div class = " col-md-6 " >
{[ " type " : " text " , " label " : " '.tr('Codice').' " , " name " : " codice " , " value " : " '. $combinazione->codice .' " , " required " : 1 , " help " : " '.tr('Codice di base per la combinazione: alla generazione variante vengono aggiunti i valore degli Attributi relativi').' " ]}
</ div >
< div class = " col-md-6 " >
2024-03-26 18:05:18 +01:00
{[ " type " : " text " , " label " : " '.tr('Nome').' " , " name " : " nome " , " value " : " '. $combinazione->getTranslation ('name').' " , " required " : 1 , " help " : " '.tr('Nome univoco della combinazione').' " ]}
2021-08-31 15:46:14 +02:00
</ div >
</ div >
< div class = " row " >
2022-09-09 12:11:28 +02:00
< div class = " col-md-6 " > ' ;
2024-03-07 16:20:32 +01:00
if ( ! empty ( $combinazione -> id_categoria )) {
2024-01-15 15:30:45 +01:00
echo '
2024-03-07 16:20:32 +01:00
'.Modules::link(' Categorie articoli ', $combinazione->id_categoria, null, null, ' class = " pull-right " ' );
2024-01-15 15:30:45 +01:00
}
echo '
2024-03-27 16:59:46 +01:00
{[ " type " : " select " , " label " : " '.tr('Categoria').' " , " name " : " id_categoria " , " required " : 0 , " value " : " $id_categoria $ " , " ajax-source " : " categorie " , " icon-after " : " add|'.(new Module())->getByField('name', 'Categorie articoli', Models \ Locale::getPredefined()->id).' " ]}
2021-08-31 15:46:14 +02:00
</ div >
< div class = " col-md-6 " >
2024-03-07 16:20:32 +01:00
{[ " type " : " select " , " label " : " '.tr('Sottocategoria').' " , " name " : " id_sottocategoria " , " value " : " $id_sottocategoria $ " , " ajax-source " : " sottocategorie " , " select-options " : '.json_encode([' id_categoria ' => $combinazione->id_categoria]).' ]}
2021-08-31 15:46:14 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
2024-03-22 15:52:24 +01:00
{[ " type " : " select " , " label " : " '.tr('Attributi').' " , " name " : " attributi[] " , " value " : " '.implode(',', $combinazione->attributi ->pluck('id')->all()).' " , " values " : " query=SELECT `mg_attributi`.`id`, `mg_attributi_lang`.`name` AS descrizione FROM `mg_attributi` LEFT JOIN `mg_attributi_lang` ON (`mg_attributi_lang`.`id_record` = `mg_attributi`.`id` AND `mg_attributi_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') WHERE `deleted_at` IS NULL " , " required " : 1 , " multiple " : 1 , " help " : " '.tr('Attributi abilitati per la combinazione corrente').' " ]}
2021-08-31 15:46:14 +02:00
</ div >
</ div >
</ div >
</ div >
</ form >
< div class = " box box-primary " >
< div class = " box-header " >
< h3 class = " box-title " > '.tr(' Varianti disponibili ( Articoli ) ').' </ h3 >
</ div >
< div class = " box-body " >
< button type = " button " class = " btn btn-primary " onclick = " aggiungiVariante(this) " >
< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi variante ').'
</ button >
< div class = " tip pull-right " data - toggle = " tooltip " title = " '.tr('Genera tutte le varianti sulla base degli Attributi associati alla Combinazione corrente').'. '.tr('Disponibile solo se non sono giò presenti delle varianti').'. " >
< button type = " button " class = " btn btn-warning '.( $numero_varianti === 0 ? '' : 'disabled').' " onclick = " generaVarianti(this) " >
< i class = " fa fa-refresh " ></ i > '.tr(' Genera tutte le varianti ').'
</ button >
</ div >
< table class = " table table-hover table-striped " >
< thead >
< tr >
< th width = " 10% " > '.tr(' Foto ').' </ th >
< th > '.tr(' Variante ').' </ th >
< th > '.tr(' Articolo ').' </ th >
2021-12-17 10:52:21 +01:00
< th class = " text-center " width = " 13% " ></ th >
2021-08-31 15:46:14 +02:00
</ tr >
</ thead >
< tbody > ' ;
$articoli = $combinazione -> articoli ;
foreach ( $articoli as $articolo ) {
echo '
< tr data - id = " '. $articolo->id .' " >
< td >< img class = " img-thumbnail img-responsive " src = " '. $articolo->image .' " ></ td >
< td > '.$articolo->nome_variante.' </ td >
2024-03-19 18:18:11 +01:00
< td > '.Modules::link(' Articoli ', $articolo->id, $articolo->codice.' - '.$articolo->getTranslation(' name ')).' </ td >
2021-12-13 09:35:13 +01:00
< td class = " text-center " >
< button type = " button " class = " btn btn-warning btn-xs " onclick = " modificaVariante('. $articolo->id .') " >
2021-12-17 10:52:21 +01:00
< i class = " fa fa-edit " ></ i > '.tr(' Modifica ').'
</ button >
< button type = " button " class = " btn btn-danger btn-xs " onclick = " rimuoviVariante('. $articolo->id .') " >
< i class = " fa fa-remove " ></ i > '.tr(' Rimuovi ').'
2021-12-13 09:35:13 +01:00
</ button >
</ td >
2021-08-31 15:46:14 +02:00
</ tr > ' ;
}
echo '
</ tbody >
</ table >
</ div >
</ div >
< a class = " btn btn-danger ask " data - backto = " record-list " >
< i class = " fa fa-trash " ></ i > '.tr(' Elimina ').'
</ a >
< script >
function aggiungiVariante ( button ) {
// Apertura modal
2021-12-13 09:35:13 +01:00
openModal ( " '.tr('Aggiungi variante').' " , " '. $module->fileurl ('add-variante.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record );
}
function modificaVariante ( id ) {
// Modifica modal
openModal ( " '.tr('Modifica variante').' " , " '. $module->fileurl ('edit-variante.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record + " &id_articolo= " + id );
2021-08-31 15:46:14 +02:00
}
2021-12-17 10:52:21 +01:00
function rimuoviVariante ( id ) {
if ( confirm ( \ ' Rimuovere la variante dalla combinazione ? \ ' ) ){
$ . post ( \ '' . base_path () . '/modules/combinazioni_articoli/actions.php\', { op: \'remove-variante\', id_articolo: + id }, function(data){ location.href=\'' . base_path () . '/editor.php?id_module=' . $id_module . '&id_record=' . $id_record . ' \ ' ; } );
}
}
2021-08-31 15:46:14 +02:00
function generaVarianti ( button ) {
// Redirect
redirect ( globals . rootdir + " /editor.php " , {
id_module : globals . id_module ,
id_record : globals . id_record ,
op : " genera-varianti " ,
backto : " record-edit " ,
});
}
2022-09-09 12:11:28 +02:00
$ ( " #id_categoria " ) . change ( function () {
updateSelectOption ( " id_categoria " , $ ( this ) . val ());
$ ( " #id_sottocategoria " ) . val ( null ) . trigger ( " change " );
});
2021-08-31 15:46:14 +02:00
</ script > ' ;