From 0aca1d4a6785f72f026b594aaa8b1b773b989003 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Tue, 29 Oct 2013 08:47:41 +0100 Subject: [PATCH] [*] BO : AdminProducts find smallest images --- .../controllers/products/combinations.tpl | 2 +- .../template/controllers/products/images.tpl | 6 +- classes/ImageType.php | 14 ++- controllers/admin/AdminProductsController.php | 13 ++- modules/blocktopmenu/blocktopmenu.php | 102 ++++++++++++------ 5 files changed, 92 insertions(+), 45 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/products/combinations.tpl b/admin-dev/themes/default/template/controllers/products/combinations.tpl index e571f0125..7acfd6d6d 100644 --- a/admin-dev/themes/default/template/controllers/products/combinations.tpl +++ b/admin-dev/themes/default/template/controllers/products/combinations.tpl @@ -252,7 +252,7 @@
  • {/foreach} diff --git a/admin-dev/themes/default/template/controllers/products/images.tpl b/admin-dev/themes/default/template/controllers/products/images.tpl index dff8cbde7..ce12ce071 100644 --- a/admin-dev/themes/default/template/controllers/products/images.tpl +++ b/admin-dev/themes/default/template/controllers/products/images.tpl @@ -92,7 +92,7 @@ - image_id + image_id legend @@ -332,8 +332,8 @@ function imageLine(id, path, position, cover, shops, legend) { line = $("#lineType").html(); - line = line.replace(/image_id/g, id); - line = line.replace(/[a-z]{2}-default/g, path); + line = line.replace(/image_id/g, legend); + line = line.replace(/[a-z]{0,2}-default/g, path); line = line.replace(/image_path/g, path); line = line.replace(/image_position/g, position); line = line.replace(/legend/g, legend); diff --git a/classes/ImageType.php b/classes/ImageType.php index 8c4338cc1..b13d4d6ae 100644 --- a/classes/ImageType.php +++ b/classes/ImageType.php @@ -127,16 +127,20 @@ class ImageTypeCore extends ObjectModel * @param string $name * @param string $type */ - public static function getByNameNType($name, $type = null) + public static function getByNameNType($name, $type = null, $order = null) { - if (!isset(self::$images_types_name_cache[$name.'_'.$type])) + if (!isset(self::$images_types_name_cache[$name.'_'.$type.'_'.$order])) { - self::$images_types_name_cache[$name.'_'.$type] = Db::getInstance()->getRow(' + self::$images_types_name_cache[$name.'_'.$type.'_'.$order] = Db::getInstance()->getRow(' SELECT `id_image_type`, `name`, `width`, `height`, `products`, `categories`, `manufacturers`, `suppliers`, `scenes` FROM `'._DB_PREFIX_.'image_type` - WHERE `name` = \''.pSQL($name).'\' '.(!is_null($type) ? 'AND `'.pSQL($type).'` = 1' : '')); + WHERE + `name` LIKE \''.pSQL($name).'\'' + .(!is_null($type) ? ' AND `'.pSQL($type).'` = 1' : '') + .(!is_null($order) ? ' ORDER BY `'.bqSQL($order).'` ASC' : '') + ); } - return self::$images_types_name_cache[$name.'_'.$type]; + return self::$images_types_name_cache[$name.'_'.$type.'_'.$order]; } public static function getFormatedName($name) diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index a0d049152..39c75722d 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -3595,6 +3595,7 @@ class AdminProductsControllerCore extends AdminController foreach ($images as $k => $image) $images[$k] = new Image($image['id_image']); + if ($this->context->shop->getContext() == Shop::CONTEXT_SHOP) $current_shop_id = (int)$this->context->shop->id; else @@ -3617,6 +3618,12 @@ class AdminProductsControllerCore extends AdminController 'languages' => $this->_languages, 'default_language' => (int)Configuration::get('PS_LANG_DEFAULT') )); + + $type = ImageType::getByNameNType('%', 'products', 'height'); + if (isset($type['name'])) + $data->assign('imageType', $type['name']); + else + $data->assign('imageType', 'small_default'); } else $this->displayWarning($this->l('You must save the product in this shop before adding images.')); @@ -3673,7 +3680,11 @@ class AdminProductsControllerCore extends AdminController $data->assign('available_date', ($this->getFieldValue($product, 'available_date') != 0) ? stripslashes(htmlentities($this->getFieldValue($product, 'available_date'), $this->context->language->id)) : '0000-00-00'); $i = 0; - $data->assign('imageType', ImageType::getByNameNType('small_default', 'products')); + $type = ImageType::getByNameNType('%', 'products', 'height'); + if (isset($type['name'])) + $data->assign('imageType', $type['name']); + else + $data->assign('imageType', 'small_default'); $data->assign('imageWidth', (isset($image_type['width']) ? (int)($image_type['width']) : 64) + 25); foreach ($images as $k => $image) { diff --git a/modules/blocktopmenu/blocktopmenu.php b/modules/blocktopmenu/blocktopmenu.php index d857362dd..2a0d4d163 100644 --- a/modules/blocktopmenu/blocktopmenu.php +++ b/modules/blocktopmenu/blocktopmenu.php @@ -291,51 +291,83 @@ class Blocktopmenu extends Module
    << '.$this->l('Remove').' + +

    '.$this->l('Change order').':

    +
    +
    +