bebeboutik/modules/bulkupdate/AdminEditFast.php
Marion Muszynski 19baa665a4 update braderie
2016-04-11 12:13:41 +02:00

139 lines
4.9 KiB
PHP

<?php
if(!defined('_PS_VERSION_')) {
exit;
}
class AdminEditFast extends AdminTab {
public $_html = '';
public function postProcess(){
if (Tools::isSubmit('submitEditFast')){
$products = json_decode(Tools::getValue('id_product'), 0);
$title = Tools::getValue('title');
$short_description = Tools::getValue('short_description');
$description = Tools::getValue('description');
$reference = Tools::getValue('reference');
$id_lang_fast = Tools::getValue('id_lang_fast');
$nbProduct = 0;
foreach ($products as $key => $product) {
if (Validate::isLoadedObject($product = new Product((int)$product))) {
// foreach ($languages as $key => $language) {
// if(isset($title[$product->id])){
// $product->name[$language['id_lang']] = $title[$product->id];
// }
// if(isset($short_description[$product->id])){
// $product->description_short[$language['id_lang']] = $short_description[$product->id];
// }
// if(isset($description[$product->id])){
// $product->description[$language['id_lang']] = $description[$product->id];
// }
// }
if (isset($title[$product->id])) {
$product->name[(int) $id_lang_fast] = $title[$product->id];
}
if (isset($short_description[$product->id])) {
$product->description_short[(int) $id_lang_fast] = $short_description[$product->id];
}
if(isset($description[$product->id])){
$product->description[(int) $id_lang_fast] = $description[$product->id];
}
if(isset($reference[$product->id])){
$product->reference = $reference[$product->id];
}
if ($product->save()) {
$nbProduct++;
} else {
$this->_html .= $product . " erreur";
}
} else {
$this->_html .= $product . " erreur";
}
}
$this->_html .= '<div class="conf">'. $nbProduct. ' produit(s) mis à jour avec succès</div>';
}
}
public function display()
{
global $cookie;
$id_lang = Tools::getValue('id_lang_fast', $cookie->id_lang);
$language = new Language($id_lang);
if (Tools::getIsset('id_product')) {
$this->_html .= '<h2>Edition rapide - '.$language->name.'</h2>';
$this->_html .= '<form method="POST" action="">';
$this->_html .= '<div id="accordion">';
$products = json_decode(Tools::getValue('id_product'));
foreach ($products as $key => $product) {
if (Validate::isLoadedObject($product = new Product((int)$product, FALSE, $id_lang) )) {
$this->_html .= self::displayFormProduct($product);
} else {
$this->_html .= $product . " erreur";
}
}
$this->_html .= '</div>';
$this->_html .= '<br />';
$this->_html .= '<div class="margin-form">';
$this->_html .= '<input type="hidden" value="'.(int) $id_lang.'" name="id_lang_fast">';
$this->_html .= '<input type="submit" class="button" value="Mettre à jour" name="submitEditFast">';
$this->_html .= '</div>';
$this->_html .= '</form>';
}else{
$this->_html .= "<div class='error'>Vous devez choisir des produits dans l'onglet Catalogue</div>";
}
// TinyMCE
global $cookie;
$iso = Language::getIsoById((int)($cookie->id_lang));
$isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en');
$ad = dirname($_SERVER["PHP_SELF"]);
echo '
<script type="text/javascript">
var iso = \''.$isoTinyMCE.'\' ;
var pathCSS = \''._THEME_CSS_DIR_.'\' ;
var ad = \''.$ad.'\' ;
</script>
<link type="text/css" rel="stylesheet" href="'.__PS_BASE_URI__.'js/jquery/accordion/accordion.css" />
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce.inc.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/accordion/accordion.ui.js"></script>
<script type="text/javascript">
$(function() {
// $("#accordion").accordion();
});
</script>';
echo $this->_html;
}
public function displayFormProduct(Product $product) {
$form = '';
$form .= '<h3>'. $product->name .'</h3>';
$form .= '<div>';
$form .= '<fieldset>';
$form .= '<label>Titre</label>';
$form .= '<input type="text" name="title['.(int)$product->id.']" value="'.$product->name.'" size="70" />';
$form .= '<br /><br />';
$form .= '<label>Reference</label>';
$form .= '<input type="text" name="reference['.(int)$product->id.']" value="'.$product->reference.'" size="70" />';
$form .= '<br /><br />';
$form .= '<label>Description courte</label>';
$form .= '<textarea name="short_description['. (int) $product->id.']" class="rte" id="" cols="10" rows="10">'.$product->description_short.'</textarea>';
$form .= '<br /><br />';
$form .= '<label>Description longue</label>';
$form .= '<textarea name="description['. (int) $product->id.']" class="rte" id="" cols="10" rows="10">'.$product->description.'</textarea>';
$form .= '<br /><br />';
$form .= '</fieldset>';
$form .= '</div>';
return $form;
}
}