update and fix braderie

This commit is contained in:
Marion Muszynski 2017-07-10 14:11:35 +02:00
parent ee1f66436c
commit deef10a0b2
3 changed files with 500 additions and 369 deletions

View File

@ -2,6 +2,7 @@
if(!defined('_PS_VERSION_')) { if(!defined('_PS_VERSION_')) {
exit; exit;
} }
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
class AdminBraderie extends AdminTab class AdminBraderie extends AdminTab
{ {
@ -12,19 +13,13 @@ class AdminBraderie extends AdminTab
{ {
global $cookie; global $cookie;
$this->_html .= '<style type="text/css"> $helperForm = new HelperFormBootstrap();
@import "'.__PS_BASE_URI__.'css/custom_admin.css"; $helperForm->_select2 = true;
</style>';
$id_category = Tools::getValue('id_category', 1); $id_category = Tools::getValue('id_category', 1);
$id_product = Tools::getValue('id_product', false); $id_product = Tools::getValue('id_product', false);
$db = Db::getInstance(); $db = Db::getInstance();
/*$sql_category = '
SELECT * FROM `'._DB_PREFIX_.'privatesale` ps
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ps.`id_category` = cl.`id_category`
WHERE ps.`braderie` = 1
AND cl.`id_lang` = '.(int) $cookie->id_lang;*/
$sql_category = ' $sql_category = '
SELECT c.`id_category`, cl.`name` FROM `'._DB_PREFIX_.'category` c SELECT c.`id_category`, cl.`name` FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category` LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`
@ -51,26 +46,21 @@ class AdminBraderie extends AdminTab
$small_titles[(int) $data['id_category']] = $data['value']; $small_titles[(int) $data['id_category']] = $data['value'];
} }
$this->_html .= $helperForm->renderStyle();
$this->_html .= $this->_buildHtmlCategoryBlock($categories, $small_titles); $this->_html .= $this->_buildHtmlCategoryBlock($categories, $small_titles);
$helperForm->_js .= '
$this->_html .= '<link type="text/css" rel="stylesheet" href="'._MODULE_DIR_.'bulkupdate/chosen.min.css" />'; <script type="text/javascript">
$this->_html .= '<script type="text/javascript" src="'._MODULE_DIR_.'bulkupdate/chosen.jquery.min.js"></script>'; function addCaption(img, title){
$this->_html .= '<script type="text/javascript"> return img+\'<div class="caption"><h5 class="text-center">\'+title+\'</h5><p class="text-center"><button type="button" class="btn btn-default" id="check_button">Vérifier</button></p></div>\';
$(function() {
$(".chosen-select").chosen(
{
allow_single_deselect:true,
placeholder_text_single : "Choisir une vente",
no_results_text : "Aucun résultat",
enable_split_word_search : true,
search_contains : true,
} }
); $(function() {
var $token = "'.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)).'"; var $token = "'.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)).'";
var $product_id = 0; var $product_id = 0;
$("#sale").select2({
allowClear: true
});
$(\'#sale\').change(function() { $(\'#sale\').change(function() {
$.ajax({ $.ajax({
type: \'POST\', type: \'POST\',
@ -86,28 +76,36 @@ class AdminBraderie extends AdminTab
$(".chosen-select").trigger("chosen:updated"); $(".chosen-select").trigger("chosen:updated");
$("#divider, #category_input_group, #ean_input_group, #storage_input_group, #button_input_group, #show_current_category_button, #quantity_input_group").show(); $("#divider, #category_input_group, #ean_input_group, #storage_input_group, #button_input_group, #show_current_category_button, #quantity_input_group").show();
$("#error").empty(); $("#error").empty();
$("#error").hide();
}, },
error: function(xhr) { error: function(xhr) {
$("#ean_from_product").empty(); $("#ean_from_product").empty();
$("#ean_from_product").hide();
$("#error").empty().append(JSON.parse(xhr.responseText)); $("#error").empty().append(JSON.parse(xhr.responseText));
$("#error").show();
} }
}); });
}); });
$("#category").change(function(event) { $("#category").change(function(event) {
$("#show_current_category_button").show(); $("#show_current_category_button").show();
$("#ean_input_group #input_ean").focus();
}); });
$("#input_ean").change(function(event) { $("#input_ean").change(function(event) {
$("#loader").show();
$.ajax({ $.ajax({
type: \'POST\', type: \'POST\',
url: \''._MODULE_DIR_.'braderie/ajax.php?action=getProductId'.'\', url: \''._MODULE_DIR_.'braderie/ajax.php?action=getProductId'.'\',
dataType: \'json\', dataType: \'json\',
data: { ean: $(this).val() }, data: { ean: $(this).val() },
success: function(response) { success: function(response) {
$("#loader").hide();
if (response.name == null) { if (response.name == null) {
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'"); $("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
$("#error").show();
$("#ean_from_product").empty(); $("#ean_from_product").empty();
$("#ean_from_product").hide();
return false; return false;
} }
@ -116,12 +114,16 @@ class AdminBraderie extends AdminTab
if (response.id_image == null) { if (response.id_image == null) {
image = \'\'; image = \'\';
} else { } else {
image = \'<img src="'._THEME_PROD_DIR_.'\'+response.img_path+\'-small.jpg" />\'; image = \'<img src="'._THEME_PROD_DIR_.'\'+response.img_path+\'-product_carre.jpg" width="200px"/>\';
} }
if (response.attribute_name) { if (response.attribute_name) {
$("#ean_from_product").empty().append(image+"<p>"+response.name+" - "+response.attribute_name+"</p>"); var caption = addCaption(image,response.name+" - "+response.attribute_name);
$("#ean_from_product").empty().append(caption);
$("#ean_from_product").show();
} else { } else {
$("#ean_from_product").empty().append(image+"<p>"+response.name+"</p>"); var caption = addCaption(image,response.name);
$("#ean_from_product").empty().append(caption);
$("#ean_from_product").show();
} }
if ($attibute_id) { if ($attibute_id) {
$("#hidden_attribute_id").val($attibute_id); $("#hidden_attribute_id").val($attibute_id);
@ -136,26 +138,32 @@ class AdminBraderie extends AdminTab
} }
$("#comment_input_group").show(); $("#comment_input_group").show();
$("#error").empty(); $("#error").empty();
$("#error").hide();
$("#input_storage").focus(); $("#input_storage").focus();
}, },
error: function(xhr) { error: function(xhr) {
$("#loader").hide();
$("#ean_from_product").empty(); $("#ean_from_product").empty();
$("#ean_from_product").hide();
$("#input_comment").val(""); $("#input_comment").val("");
$("#comment_input_group").hide(); $("#comment_input_group").hide();
$("#error").empty().append(JSON.parse(xhr.responseText)); $("#error").empty().append(JSON.parse(xhr.responseText));
$("#error").show();
} }
}); });
}); });
$("#check_button").click(function(event) { $(document).on("click", "#check_button", function(event) {
if ($product_id == undefined || $product_id == 0) { if ($product_id == undefined || $product_id == 0) {
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'"); $("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
$("#error").show();
return false; return false;
} }
if ($token.length == 0) { if ($token.length == 0) {
$("#error").empty().append("'.$this->l('Un problème de sécurité est survenu. Merci de réinitialisé la page').'"); $("#error").empty().append("'.$this->l('Un problème de sécurité est survenu. Merci de réinitialisé la page').'");
$("#error").show();
return false; return false;
} }
@ -167,6 +175,7 @@ class AdminBraderie extends AdminTab
event.preventDefault(); event.preventDefault();
if ($product_id == undefined || $product_id == 0) { if ($product_id == undefined || $product_id == 0) {
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'"); $("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
$("#error").show();
return false; return false;
} }
@ -174,15 +183,18 @@ class AdminBraderie extends AdminTab
if (emplacement.length == 0 || emplacement>505) { if (emplacement.length == 0 || emplacement>505) {
$("#error").empty().append("'.$this->l('L\'emplacement n\'est pas renseigné ou est mal renseigné').'"); $("#error").empty().append("'.$this->l('L\'emplacement n\'est pas renseigné ou est mal renseigné').'");
$("#error").show();
return false; return false;
} }
if ($("#input_quantity").val().length == 0) { if ($("#input_quantity").val().length == 0) {
$("#error").empty().append("'.$this->l('La quantité n\'est pas renseignée').'"); $("#error").empty().append("'.$this->l('La quantité n\'est pas renseignée').'");
$("#error").show();
return false; return false;
} }
$("#hidden_product_id").val($product_id); $("#hidden_product_id").val($product_id);
$("#loader").show();
$.ajax({ $.ajax({
type: \'POST\', type: \'POST\',
url: \''._MODULE_DIR_.'braderie/ajax.php?action=addToSellout'.'\', url: \''._MODULE_DIR_.'braderie/ajax.php?action=addToSellout'.'\',
@ -198,15 +210,20 @@ class AdminBraderie extends AdminTab
comment: tinymce.activeEditor.getContent() comment: tinymce.activeEditor.getContent()
}, },
success: function(response) { success: function(response) {
$("#loader").hide();
$("#error").empty().append(response); $("#error").empty().append(response);
$("#error").show();
$("#input_ean, #input_storage").val(""); $("#input_ean, #input_storage").val("");
$("#comment_input_group").hide(); $("#comment_input_group").hide();
$("#input_quantity").val(1); $("#input_quantity").val(1);
$("#ean_from_product").empty(); $("#ean_from_product").empty();
$("#ean_from_product").hide();
$("#input_ean").focus(); $("#input_ean").focus();
}, },
error: function(xhr) { error: function(xhr) {
$("#loader").hide();
$("#error").empty().append(JSON.parse(xhr.responseText)); $("#error").empty().append(JSON.parse(xhr.responseText));
$("#error").show();
} }
}); });
return false; return false;
@ -222,6 +239,7 @@ class AdminBraderie extends AdminTab
if ($product_id == undefined || $product_id == 0) { if ($product_id == undefined || $product_id == 0) {
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'"); $("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
$("#error").show();
return false; return false;
} }
@ -229,16 +247,18 @@ class AdminBraderie extends AdminTab
if (emplacement.length == 0 || emplacement>505) { if (emplacement.length == 0 || emplacement>505) {
$("#error").empty().append("'.$this->l('L\'emplacement n\'est pas renseigné ou est mal renseigné').'"); $("#error").empty().append("'.$this->l('L\'emplacement n\'est pas renseigné ou est mal renseigné').'");
$("#error").show();
return false; return false;
} }
if ($("#input_quantity").val().length == 0) { if ($("#input_quantity").val().length == 0) {
$("#error").empty().append("'.$this->l('La quantité n\'est pas renseignée').'"); $("#error").empty().append("'.$this->l('La quantité n\'est pas renseignée').'");
$("#error").show();
return false; return false;
} }
$("#hidden_product_id").val($product_id); $("#hidden_product_id").val($product_id);
$("#loader").show();
$.ajax({ $.ajax({
type: \'POST\', type: \'POST\',
url: \''._MODULE_DIR_.'braderie/ajax.php?action=addToSellout'.'\', url: \''._MODULE_DIR_.'braderie/ajax.php?action=addToSellout'.'\',
@ -253,12 +273,16 @@ class AdminBraderie extends AdminTab
attribute: $("#hidden_attribute_id").val() attribute: $("#hidden_attribute_id").val()
}, },
success: function(response) { success: function(response) {
$("#loader").hide();
$("#error").empty().append(response); $("#error").empty().append(response);
$("#error").show();
$("#input_ean, #input_storage").val(""); $("#input_ean, #input_storage").val("");
$("#ean_from_product").empty(); $("#ean_from_product").empty();
}, },
error: function(xhr) { error: function(xhr) {
$("#loader").hide();
$("#error").empty().append(JSON.parse(xhr.responseText)); $("#error").empty().append(JSON.parse(xhr.responseText));
$("#error").show();
} }
}); });
return false; return false;
@ -268,14 +292,15 @@ class AdminBraderie extends AdminTab
$category = $("#category").val(); $category = $("#category").val();
if ($category.length == 0) { if ($category.length == 0) {
$("#error").empty().append("'.$this->l('Catégorie invalide').'"); $("#error").empty().append("'.$this->l('Catégorie invalide').'");
$("#error").show();
return false; return false;
} }
window.open("?tab=AdminCatalog&viewcategory&id_category=" + $category + "&token=" + $token, "_blank"); window.open("?tab=AdminCatalog&viewcategory&id_category=" + $category + "&token=" + $token, "_blank");
return false; return false;
}); });
}); });
</script>'; </script>';
$this->_html .= $helperForm->renderScript();
$iso = Language::getIsoById((int)($cookie->id_lang)); $iso = Language::getIsoById((int)($cookie->id_lang));
$isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'); $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en');
$ad = dirname($_SERVER["PHP_SELF"]); $ad = dirname($_SERVER["PHP_SELF"]);
@ -308,7 +333,7 @@ class AdminBraderie extends AdminTab
theme_advanced_resizing : false, theme_advanced_resizing : false,
content_css : pathCSS+"global.css", content_css : pathCSS+"global.css",
document_base_url : ad, document_base_url : ad,
width: "200", width: "100",
height: "200", height: "200",
font_size_style_values : "8pt, 10pt, 12pt, 14pt, 18pt, 24pt, 36pt", font_size_style_values : "8pt, 10pt, 12pt, 14pt, 18pt, 24pt, 36pt",
elements : "nourlconvert,ajaxfilemanager", elements : "nourlconvert,ajaxfilemanager",
@ -320,6 +345,7 @@ class AdminBraderie extends AdminTab
}); });
}); });
</script>'; </script>';
echo $this->_html; echo $this->_html;
} }
@ -330,76 +356,149 @@ class AdminBraderie extends AdminTab
$token = Tools::getAdminToken('AdminBraderie'.(int)(Tab::getIdFromClassName('AdminBraderie')).(int)($cookie->id_employee)); $token = Tools::getAdminToken('AdminBraderie'.(int)(Tab::getIdFromClassName('AdminBraderie')).(int)($cookie->id_employee));
$html = ' $html = '
<style> <div class="col-md-6 col-md-offset-3 text-center" style="padding:5px;margin-bottom: 10px;background: #504d8b;color: #fff; display:none" id="error"></div>
.chosen-container { width: 315px !important; } <div class="panel">
.button-container input { margin: 10px 25px; } <div class="panel-title">
#ean_from_product { <h2><span class="anticon anticon-price-tags"></span> '.$this->l('Braderie').'</h2>
background-color: rgba(86,84,133,0.7); <div class="clearfix"></div>
color:#fff;
margin-top: 5px;
}
#ean_from_product p{width: 330px;text-align: center;}
#ean_from_product p,#ean_from_product img{
display:inline-block;
vertical-align:middle;
margin: 5px;
}
#error, #ean_from_product { margin-left: 205px; width: 445px;}
#error { font-weight: bold; margin-bottom: 20px; color: #CC0000; }
.margin-form {padding: 0 0 1em 10px;}
</style>
<fieldset>
<legend>'.$this->l('Braderie').'</legend>
<form id="formBraderie" action="?tab=AdminBraderie&token='.$token.'" method="POST">';
if ($this->error) {
$html .= '<p class="margin-form" id="error">'.$this->error.'</p>';
} else {
$html .= '<p class="margin-form" id="error">'.$this->error.'</p>';
}
$html .='<div class="margin-form" id="ean_input_group" style="display: none;">
<label>'.$this->l('Code EAN').' : </label>
<input type="text" name="ean" id="input_ean">
<div id="ean_from_product"></div>
</div> </div>
<hr id="divider" style="display: none;">'; <div class="panel-content">
$html .= '<div class="margin-form"> <div class="row">
<div class="col-md-5">
<form id="formBraderie" action="?tab=AdminBraderie&token='.$token.'" method="POST">
<div class="form-group" id="ean_input_group" style="display: none;">
<div class="input-group">
<span class="input-group-addon"><i class="anticon anticon-barcode"></i></span>
<input type="text" class="form-control" id="input_ean" name="ean" placeholder="Sélection par EAN..."/>
</div>
</div>
<div id="divider" class="ln_solid" style="display: none;"></div>
<div class="form-group">
<label>'.$this->l('Ventes').' : </label> <label>'.$this->l('Ventes').' : </label>
<select class="chosen-select" id="sale" name="sale"> <select class="form-control input-sm select2" id="sale" name="sale">
<option value=""></option>'; <option value="">Choisir une vente</option>';
foreach ($categories as $key => $value) { foreach ($categories as $key => $value) {
$html .= '<option value="'.$value['id_category'].'">'.$value['id_category'].' - '.$value['name'].(!empty($small_titles[(int)$value['id_category']])?' - '.$small_titles[(int)$value['id_category']]:'').'</option>'; $html .= '<option value="'.$value['id_category'].'">'.$value['id_category'].' - '.$value['name'].(!empty($small_titles[(int)$value['id_category']])?' - '.$small_titles[(int)$value['id_category']]:'').'</option>';
} }
$html .= ' </select> $html .= ' </select>
</div> </div>
<div class="margin-form" id="category_input_group" style="display: none;"> <div class="form-group" id="category_input_group" style="display: none;">
<label>'.$this->l('Catégories').' : </label> <label>'.$this->l('Catégorie').' : </label>
<select class="chosen-select" id="category" name="category"> <div class="input-group">
<option value=""></option> <select class="form-control input-sm select2" id="category" name="category">
<option value="">Choisir une vente</option>
</select> </select>
<a href="?tab=AdminCatalog" class="button" id="show_current_category_button" style="margin-left: 20px; display: none">'.$this->l('Voir cette catégorie').'</a> <span class="input-group-btn">
<a href="?tab=AdminCatalog" class="btn btn-default btn-sm" id="show_current_category_button" style="margin-left: 20px; display: none"><i class="glyphicon glyphicon-search"></i> '.$this->l('Voir').'</a>
</span>
</div> </div>
<div class="margin-form" id="quantity_input_group" style="display: none;">
<label>'.$this->l('Quantité').' : </label>
<input type="number" name="quantity" id="input_quantity" value="1">
</div> </div>
<div class="margin-form" id="storage_input_group" style="display: none;"> <div class="form-group" id="quantity_input_group" style="display: none;">
<label >'.$this->l('Quantité').' : </label>
<input class="form-control" type="number" name="quantity" id="input_quantity" value="1">
</div>
<div class="form-group" id="storage_input_group" style="display: none;">
<label>'.$this->l('Emplacement').' : </label> <label>'.$this->l('Emplacement').' : </label>
<input type="text" name="storage" id="input_storage"> <input class="form-control" type="text" name="storage" id="input_storage">
</div> </div>
<div class="margin-form" id="comment_input_group" style="display: none;"> <div class="form-group" id="comment_input_group" style="display: none;">
<label>'.$this->l('Commentaires').' : </label> <label>'.$this->l('Commentaires').' : </label>
<textarea class="other_textarea" cols="49" rows="3" id="input_comment" name="input_comment"></textarea> <textarea class="other_textarea form-control" cols="49" rows="3" id="input_comment" name="input_comment"></textarea>
</div> </div>
<div class="margin-form button-container" id="button_input_group" style="display: none;"> <div class="form-group text-left" id="button_input_group" style="display: none;">
<input type="submit" class="button" name="adminbraderie" value="'.$this->l('Ajouter').'" style="margin-left: 200px;" id="add_button"> <input type="submit" class="btn btn-primary" name="adminbraderie" value="'.$this->l('Ajouter').'" id="add_button">
<input type="submit" class="button" id="check_button" value="'.$this->l('Vérifier').'">
</div> </div>
<input type="hidden" name="product" id="hidden_product_id"> <input type="hidden" name="product" id="hidden_product_id">
<input type="hidden" name="attribute" id="hidden_attribute_id"> <input type="hidden" name="attribute" id="hidden_attribute_id">
</form> </form>
</fieldset>'; </div>
<div class="col-md-5 col-md-offset-2">
<div style="">
<div class="div-title">
<h4 style=""><span class="anticon anticon-target"></span> Produit</h4>
<div class="clearfix"></div>
</div>
<div class="col-md-6 col-md-offset-3 text-center" style="padding:5px;margin-bottom: 10px;color: #fff; display:none" id="loader"><img src="../img/loader_payment.gif" /></div>
<div class="thumbnail" id="ean_from_product" style="display:none;"></div>
</div>
</div>
</div>
</div>
</div>';
// $html = '
// <style>
// .chosen-container { width: 315px !important; }
// .button-container input { margin: 10px 25px; }
// #ean_from_product {
// background-color: rgba(86,84,133,0.7);
// color:#fff;
// margin-top: 5px;
// }
// #ean_from_product p{width: 330px;text-align: center;}
// #ean_from_product p,#ean_from_product img{
// display:inline-block;
// vertical-align:middle;
// margin: 5px;
// }
// #error, #ean_from_product { margin-left: 205px; width: 445px;}
// #error { font-weight: bold; margin-bottom: 20px; color: #CC0000; }
// .margin-form {padding: 0 0 1em 10px;}
// </style>
// <fieldset>
// <legend>'.$this->l('Braderie').'</legend>
// <form id="formBraderie" action="?tab=AdminBraderie&token='.$token.'" method="POST">';
// if ($this->error) {
// $html .= '<p class="margin-form" id="error">'.$this->error.'</p>';
// } else {
// $html .= '<p class="margin-form" id="error">'.$this->error.'</p>';
// }
// $html .='<div class="margin-form" id="ean_input_group" style="display: none;">
// <label>'.$this->l('Code EAN').' : </label>
// <input type="text" name="ean" id="input_ean">
// <div id="ean_from_product"></div>
// </div>
// <hr id="divider" style="display: none;">';
// $html .= '<div class="margin-form">
// <label>'.$this->l('Ventes').' : </label>
// <select class="chosen-select" id="sale" name="sale">
// <option value=""></option>';
// foreach ($categories as $key => $value) {
// $html .= '<option value="'.$value['id_category'].'">'.$value['id_category'].' - '.$value['name'].(!empty($small_titles[(int)$value['id_category']])?' - '.$small_titles[(int)$value['id_category']]:'').'</option>';
// }
// $html .= ' </select>
// </div>
// <div class="margin-form" id="category_input_group" style="display: none;">
// <label>'.$this->l('Catégories').' : </label>
// <select class="chosen-select" id="category" name="category">
// <option value=""></option>
// </select>
// <a href="?tab=AdminCatalog" class="button" id="show_current_category_button" style="margin-left: 20px; display: none">'.$this->l('Voir cette catégorie').'</a>
// </div>
// <div class="margin-form" id="quantity_input_group" style="display: none;">
// <label>'.$this->l('Quantité').' : </label>
// <input type="number" name="quantity" id="input_quantity" value="1">
// </div>
// <div class="margin-form" id="storage_input_group" style="display: none;">
// <label>'.$this->l('Emplacement').' : </label>
// <input type="text" name="storage" id="input_storage">
// </div>
// <div class="margin-form" id="comment_input_group" style="display: none;">
// <label>'.$this->l('Commentaires').' : </label>
// <textarea class="other_textarea" cols="49" rows="3" id="input_comment" name="input_comment"></textarea>
// </div>
// <div class="margin-form button-container" id="button_input_group" style="display: none;">
// <input type="submit" class="button" name="adminbraderie" value="'.$this->l('Ajouter').'" style="margin-left: 200px;" id="add_button">
// <input type="submit" class="button" id="check_button" value="'.$this->l('Vérifier').'">
// </div>
// <input type="hidden" name="product" id="hidden_product_id">
// <input type="hidden" name="attribute" id="hidden_attribute_id">
// </form>
// </fieldset>';
return $html; return $html;
} }

View File

@ -88,55 +88,6 @@ function getProductId()
$result['id_image'] = (!empty($result['id_image_attribute'])) ? $result['id_image_attribute'] : $result['id_image']; $result['id_image'] = (!empty($result['id_image_attribute'])) ? $result['id_image_attribute'] : $result['id_image'];
} }
/*$category_name = Db::getInstance()->getRow('
SELECT cl.`name`
FROM `'._DB_PREFIX_.'category_lang` cl
LEFT JOIN `'._DB_PREFIX_.'privatesale` ps ON (ps.`id_category` = cl.`id_category`)
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` pps ON (pps.`id_sale` = ps.`id_sale`)
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = pps.`id_product`)
WHERE p.`ean13` = '.pSQL($ean).'
AND cl.`id_lang` = '.(int)$cookie->id_lang.'
AND ps.`braderie`= 0
ORDER BY p.`date_add` ASC'
);
if(!isset($category_name) || empty($category_name)) {
$category_name = Db::getInstance()->getRow('
SELECT cl.`name`
FROM `'._DB_PREFIX_.'category_lang` cl
LEFT JOIN `'._DB_PREFIX_.'privatesale` ps ON (ps.`id_category` = cl.`id_category`)
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` pps ON (pps.`id_sale` = ps.`id_sale`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product` = pps.`id_product`)
WHERE pa.`ean13` = '.pSQL($ean).' AND cl.`id_lang` = '.(int)$cookie->id_lang.'
AND ps.`braderie`= 0
ORDER BY pa.`id_product_attribute` ASC'
);
}
$result['category_name'] = $category_name['name'];
$product_name = Db::getInstance()->getRow('
SELECT pl.`name`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`)
WHERE p.`ean13` = '.pSQL($ean).'
AND pl.`id_lang` = '.(int)$cookie->id_lang.'
ORDER BY p.`date_add` ASC
');
if(!isset($product_name) || empty($product_name)) {
$product_name = Db::getInstance()->getRow('
SELECT pl.`name`
FROM `'._DB_PREFIX_.'product_attribute` pa
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = pa.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.`id_attribute` = pac.`id_attribute`)
WHERE pa.`ean13` = '.pSQL($ean).'
AND pl.`id_lang` = '.(int)$cookie->id_lang.'
ORDER BY p.`date_add` ASC
');
}
$result['product_name'] = $product_name['name'];*/
if (!empty($result)) { if (!empty($result)) {
if(isset($result['id_image'])){ if(isset($result['id_image'])){
$image_obj = new Image((int)$result['id_image']); $image_obj = new Image((int)$result['id_image']);
@ -263,6 +214,22 @@ function addToSellout()
} }
if ($product->add()) { if ($product->add()) {
$customs = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'product_customs`
WHERE `id_product` = '.(int)$id_product_old.'
');
if($customs){
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'product_customs`
VALUES (
'.(int) $product->id.',
"'.(!empty($customs['nc8'])?$customs['nc8']:'').'",
"'.(!empty($customs['id_country'])?$customs['id_country']:'').'",
'.($customs['random']?1:0).'
)
');
}
if (!$id_attribute) { if (!$id_attribute) {
$combinationImages = Product::duplicateAttributes($id_product_old, $product->id, $quantity); $combinationImages = Product::duplicateAttributes($id_product_old, $product->id, $quantity);
} else { } else {

View File

@ -0,0 +1,65 @@
<?php
class Image extends ImageCore
{
/**
* @Override Antadis
* Fill image legend when it doesn't exist in every languages
*/
public static function duplicateProductImages($id_product_old, $id_product_new, $combinationImages)
{
$imagesTypes = ImageType::getImagesTypes('products');
$result = Db::getInstance()->ExecuteS('
SELECT `id_image`
FROM `'._DB_PREFIX_.'image`
WHERE `id_product` = '.(int)($id_product_old));
$product_name = DB::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'product_lang`
WHERE `id_product` = '.(int)($id_product_new).'
AND `id_lang` = 2
');
foreach ($result as $row)
{
$imageOld = new Image($row['id_image']);
$imageNew = clone $imageOld;
$imageNew->id_product = (int)($id_product_new);
// @Override
foreach(Language::getLanguages(FALSE) as $language) {
if(empty($imageNew->legend[$language['id_lang']])){
$imageNew->legend[$language['id_lang']] = $product_name;
}
}
// @End Override
if($imageNew->add()) {
$new_path = $imageNew->getPathForCreation();
if(file_exists(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'.jpg')) {
copy(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'.jpg', $new_path.'.jpg');
}
foreach($imagesTypes AS $imageType) {
if(file_exists(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'-'.$imageType['name'].'.jpg')) {
if(!Configuration::get('PS_LEGACY_IMAGES')) {
$imageNew->createImgFolder();
}
copy(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'-'.$imageType['name'].'.jpg', $new_path.'-'.$imageType['name'].'.jpg');
} else {
if(!Configuration::get('PS_LEGACY_IMAGES')) {
$imageNew->createImgFolder();
}
imageResize($new_path.'.jpg', _PS_PROD_IMG_DIR_.$imageNew->getExistingImgPath().'-'.$imageType['name'].'.jpg', (int) $imageType['width'], (int) $imageType['height']);
}
}
self::replaceAttributeImageAssociationId($combinationImages, (int)($imageOld->id), (int)($imageNew->id));
} else {
return FALSE;
}
}
return self::duplicateAttributeImageAssociations($combinationImages);
}
}