From 90dd61b5bb878c7fd07a167cd3ebf789dd6d7040 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Tue, 18 Apr 2017 12:48:42 +0200 Subject: [PATCH] add multilang on category img thumbs --- adm/tabs/AdminCategories.php | 80 +++++++++++++++------ adm/tabs/AdminProducts.php | 6 +- modules/categoryimg/categoryimg.php | 14 +++- modules/categoryimg/left_img.tpl | 4 +- override/controllers/CategoryController.php | 6 +- override/controllers/ProductController.php | 14 +++- themes/site/category.tpl | 24 ++++--- themes/site/product.tpl | 4 +- themes/site_mobile/product.tpl | 5 +- 9 files changed, 113 insertions(+), 44 deletions(-) diff --git a/adm/tabs/AdminCategories.php b/adm/tabs/AdminCategories.php index bfd327ba..0c686d91 100755 --- a/adm/tabs/AdminCategories.php +++ b/adm/tabs/AdminCategories.php @@ -417,10 +417,10 @@ class AdminCategories extends AdminTab // @Override Antadis /* Delete Image Thumb */ - elseif (isset($_GET['deleteImageThumb'])) + elseif (isset($_GET['deleteImageThumb']) && isset($_GET['id_lang'])) { if (Validate::isLoadedObject($object = $this->loadObject())) { - $this->deleteImageThumb($object); + $this->deleteImageThumb($object,$_GET['id_lang']); Tools::redirectAdmin($currentIndex.'&updatecategory&token='.Tools::getValue('token').'&id_category='.(int)($object->id)); } @@ -442,7 +442,9 @@ class AdminCategories extends AdminTab if ($this->deleted) { // @Override Antadis - $this->deleteImageThumb($object); + foreach (Language::getLanguages(FALSE) as $language) { + $this->deleteImageThumb($object, $language['id_lang']); + } // @End Antadis $object->deleteImage(); $object->deleted = 1; @@ -502,9 +504,22 @@ class AdminCategories extends AdminTab protected function postImage($id) { // @Override Antadis - if (($id_category = (int)(Tools::getValue('id_category'))) && isset($_FILES['image_thumb']) && $_FILES['image_thumb']['name'] != NULL) { - if(!copy($_FILES['image_thumb']['tmp_name'], _PS_CAT_IMG_DIR_.$id_category.'_thumb_vp.jpg')) { - echo $this->displayError($this->l('An error occured during the image upload.')); + if($id_category = (int)(Tools::getValue('id_category'))) { + foreach (Language::getLanguages(FALSE) as $language) { + $id_lang = (int)$language['id_lang']; + if($id_lang == 3 + && (!isset($_FILES['image_thumb_'.$id_lang]) || $_FILES['image_thumb_'.$id_lang]['name'] == '') + && (isset($_FILES['image_thumb_2']) && $_FILES['image_thumb_2']['name'] != '') + ){ + if(!copy($_FILES['image_thumb_2']['tmp_name'], _PS_CAT_IMG_DIR_.$id_category.'_thumb_vp_'.$id_lang.'.jpg')) { + echo $this->displayError($this->l('An error occured during the image upload.')); + } + } + elseif(isset($_FILES['image_thumb_'.$id_lang]) && $_FILES['image_thumb_'.$id_lang]['name'] != '') { + if(!copy($_FILES['image_thumb_'.$id_lang]['tmp_name'], _PS_CAT_IMG_DIR_.$id_category.'_thumb_vp_'.$id_lang.'.jpg')) { + echo $this->displayError($this->l('An error occured during the image upload.')); + } + } } } // @End Antadis @@ -520,10 +535,10 @@ class AdminCategories extends AdminTab } // @Adding Antadis - public function deleteImageThumb($object) + public function deleteImageThumb($object, $id_lang) { - if(file_exists(_PS_ROOT_DIR_.'/img/c/'.$object->id.'_thumb_vp.jpg')) { - unlink(_PS_ROOT_DIR_.'/img/c/'.$object->id.'_thumb_vp.jpg'); + if(file_exists(_PS_ROOT_DIR_.'/img/c/'.$object->id.'_thumb_vp_'.(int)$id_lang.'.jpg')) { + unlink(_PS_ROOT_DIR_.'/img/c/'.$object->id.'_thumb_vp_'.(int)$id_lang.'.jpg'); } } // @End Antadis @@ -626,20 +641,39 @@ class AdminCategories extends AdminTab

'; // @Override Antadis - echo ' -
'; - if(file_exists(_PS_ROOT_DIR_.'/img/c/'.$obj->id.'_thumb_vp.jpg')) { - echo '
- -

- - Supprimer Supprimer -
'; - } - echo '
-

'.$this->l('Upload logo from your computer').'

-
-

'; + echo ' +
'; + foreach($this->_languages as $language) { + echo ' +
'; + if(file_exists(_PS_ROOT_DIR_.'/img/c/'.$obj->id.'_thumb_vp_'.$language['id_lang'].'.jpg')) { + echo '
+ +

+ + Supprimer Supprimer +
'; + } + echo ' +
'; + } + echo '

+
'; + + // echo ' + //
'; + // if(file_exists(_PS_ROOT_DIR_.'/img/c/'.$obj->id.'_thumb_vp.jpg')) { + // echo '
+ // + //

+ // + // Supprimer Supprimer + //
'; + // } + // echo '
+ //

'.$this->l('Upload logo from your computer').'

+ //
+ //

'; // @EndOverride Antadis echo ' diff --git a/adm/tabs/AdminProducts.php b/adm/tabs/AdminProducts.php index c5f44212..2d6c9094 100755 --- a/adm/tabs/AdminProducts.php +++ b/adm/tabs/AdminProducts.php @@ -1934,7 +1934,7 @@ class AdminProducts extends AdminTab } } - if ($array_categories['childrens']) { + if (isset($array_categories['childrens'])) { foreach ($array_categories['childrens'] as $key => $children) { $childrens = Category::getChildren((int) $children['id_category'], $cookie->id_lang); $array_categories['childrens'][$key]['childrens'] = $childrens; @@ -1965,7 +1965,7 @@ class AdminProducts extends AdminTab echo ' '; }*/ - if ($array_categories['childrens']) { + if (isset($array_categories['childrens'])) { foreach ($array_categories['childrens'] as $key => $catchild) { echo '
'; if ($catchild['id_category'] != $id_category) { @@ -2023,7 +2023,7 @@ class AdminProducts extends AdminTab echo '

'; echo '

'.$this->l('Order by product name').'

'; } - if((int)$this->_category->id_oarent !=1 && $cookie->id_employee==1){ + if((int)$this->_category->id_parent !=1 && $cookie->id_employee==1){ echo '

diff --git a/modules/categoryimg/categoryimg.php b/modules/categoryimg/categoryimg.php index 8395907c..aadb719c 100755 --- a/modules/categoryimg/categoryimg.php +++ b/modules/categoryimg/categoryimg.php @@ -42,12 +42,23 @@ class CategoryImg extends Module { } } } - if ($category && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$params['id_category'].'_thumb_vp.jpg') && $params['id_category'] != $category->id) { + + if ($category && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$params['id_category'].'_thumb_vp_'.$id_lang.'.jpg') && $params['id_category'] != $category->id) { + $id_category_thumb = $params['id_category']; + } elseif ($category && $id_parent && file_exists(_PS_ROOT_DIR_.'/img/c/'.$id_parent.'_thumb_vp_'.$id_lang.'.jpg') && $id_parent!= $category->id) { + $id_category_thumb = $id_parent; + } elseif ($category && $parent_bis && file_exists(_PS_ROOT_DIR_.'/img/c/'.$parent_bis.'_thumb_vp_'.$id_lang.'.jpg') && $parent_bis!= $category->id) { + $id_category_thumb = $parent_bis; + + // keeping retrocompatibility + } elseif ($category && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$params['id_category'].'_thumb_vp.jpg') && $params['id_category'] != $category->id) { $id_category_thumb = $params['id_category']; } elseif ($category && $id_parent && file_exists(_PS_ROOT_DIR_.'/img/c/'.$id_parent.'_thumb_vp.jpg') && $id_parent!= $category->id) { $id_category_thumb = $id_parent; } elseif ($category && $parent_bis && file_exists(_PS_ROOT_DIR_.'/img/c/'.$parent_bis.'_thumb_vp.jpg') && $parent_bis!= $category->id) { $id_category_thumb = $parent_bis; + // End retrocompatibility + } else { $id_category_thumb = $category->id; } @@ -57,6 +68,7 @@ class CategoryImg extends Module { $smarty->assign('consumable', ((int) _SHOP_PRIVATESALES_CONSUMABLE == (int) $sale->id)? true : false); $smarty->assign('category', $category); $smarty->assign('is_thumb_vp',(file_exists(_PS_ROOT_DIR_.'/img/c/'.$id_category_thumb.'_thumb_vp.jpg'))); + $smarty->assign('is_thumb_vp_lang',(file_exists(_PS_ROOT_DIR_.'/img/c/'.$id_category_thumb.'_thumb_vp_'.$id_lang.'.jpg'))); $smarty->assign('id_category_thumb',$id_category_thumb); return $this->display(__FILE__, 'left_img.tpl'); } diff --git a/modules/categoryimg/left_img.tpl b/modules/categoryimg/left_img.tpl index 442473b8..bd6c2af5 100755 --- a/modules/categoryimg/left_img.tpl +++ b/modules/categoryimg/left_img.tpl @@ -3,7 +3,9 @@ {$category->name}

- {if $is_thumb_vp} + {if $is_thumb_vp_lang} + {$category->name} + {elseif $is_thumb_vp} {$category->name} {else} diff --git a/override/controllers/CategoryController.php b/override/controllers/CategoryController.php index 1317263d..0cbb4914 100755 --- a/override/controllers/CategoryController.php +++ b/override/controllers/CategoryController.php @@ -1,7 +1,7 @@ getOthersSales(true, null, null, 'current', false, Configuration::get('PRIVATES_SHOW_PUBLIC'), '`date_start` desc', $site_version_front); foreach ($other_sales as $key => &$s) { - if (file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$s['id_category'].'_thumb_vp.jpg')) { + if(file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$s['id_category'].'_thumb_vp_'.$cookie->id_lang.'.jpg')) { + $s['is_thumb_img_lang'] = true; + } elseif (file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$s['id_category'].'_thumb_vp.jpg')) { $s['is_thumb_img'] = true; } else { $s['is_thumb_img'] = false; diff --git a/override/controllers/ProductController.php b/override/controllers/ProductController.php index 4b5bbf9a..a59761f7 100755 --- a/override/controllers/ProductController.php +++ b/override/controllers/ProductController.php @@ -32,12 +32,23 @@ class ProductController extends ProductControllerCore { break; } } - if (isset($third_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$third_step_cat.'_thumb_vp.jpg')) { + + if (isset($third_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$third_step_cat.'_thumb_vp_'.$cookie->id_lang.'.jpg')) { + $id_category_thumb = (int)$third_step_cat; + } elseif (isset($second_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$second_step_cat.'_thumb_vp_'.$cookie->id_lang.'.jpg')) { + $id_category_thumb = (int)$second_step_cat; + } elseif (isset($first_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$first_step_cat.'_thumb_vp_'.$cookie->id_lang.'.jpg')) { + $id_category_thumb = (int)$first_step_cat; + + // Keeping retrocompatibility + } elseif (isset($third_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$third_step_cat.'_thumb_vp.jpg')) { $id_category_thumb = (int)$third_step_cat; } elseif (isset($second_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$second_step_cat.'_thumb_vp.jpg')) { $id_category_thumb = (int)$second_step_cat; } elseif (isset($first_step_cat) && file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$first_step_cat.'_thumb_vp.jpg')) { $id_category_thumb = (int)$first_step_cat; + // End retrocompatibility + } else { // sale cat thumb $id_category_thumb = $sale->id_category; @@ -50,6 +61,7 @@ class ProductController extends ProductControllerCore { 'HOOK_PRIVATESALES_PRODUCT' => Module::hookExec('privatesales_product', array('sale' => $sale)), 'is_sale_home' => ($sale? $sale->id_category == $id_category: FALSE), 'is_thumb_vp' => (file_exists(_PS_ROOT_DIR_.'/img/c/'.$id_category_thumb.'_thumb_vp.jpg')), + 'is_thumb_vp_lang' => (file_exists(_PS_ROOT_DIR_.'/img/c/'.$id_category_thumb.'_thumb_vp_'.$cookie->id_lang.'.jpg')), 'id_category_thumb' => $id_category_thumb, )); diff --git a/themes/site/category.tpl b/themes/site/category.tpl index faec69c7..6a3258ab 100755 --- a/themes/site/category.tpl +++ b/themes/site/category.tpl @@ -70,7 +70,7 @@ $(document).ready(function() { fade: 0 }); }); - + if (($("#submenuw").length > 0)){ var positionElementInPage = $('#submenuw').offset().top; $(window).scroll( @@ -84,10 +84,10 @@ $(document).ready(function() { ); } - $('#privatesales_categories_block_left li span.parent').parent().addClass('active'); + $('#privatesales_categories_block_left li span.parent').parent().addClass('active'); $('#privatesales_categories_block_left li span.parent').live('click', function(e){ e.preventDefault(); - if($(this).parent().hasClass('active')){ + if($(this).parent().hasClass('active')){ $(this).parent().children('ul').hide(); $(this).parent().removeClass('active'); }else{ @@ -95,7 +95,7 @@ $(document).ready(function() { $(this).parent().children('ul').show(); } }); - + if($('#privatesales_categories_block_left').length > 0){ var elem = $('#privatesales_categories_block_left'); @@ -105,11 +105,11 @@ $(document).ready(function() { $(window).scroll(function(){ var scroll = $(window).scrollTop(); var marginApply = scroll + 10; - + if(parseInt(scroll) >= parseInt(initial_position) ){ var position_menu_bas = $(elem).position().top + $(elem).height() + 10; var position_center_bas = $('.main_category_vp').position().top + $('.main_category_vp').height() - 20; - + var top_max = scroll + $(elem).height(); if(top_max > position_center_bas){ @@ -125,14 +125,14 @@ $(document).ready(function() { } }); } - + $(window).load(function() { $('.flexslider').flexslider({ animation: "slide", controlNav: false, slideshow: false, - itemWidth: 300, + itemWidth: 300, pauseOnHover : false, mousewheel: false, }); @@ -144,14 +144,14 @@ $(document).ready(function() {
- {$HOOK_LEFT_COLUMN_VP} + {$HOOK_LEFT_COLUMN_VP}
{if isset($category)} {if $category->id AND $category->active}