[-] CORE : fixed bug #PSCFV-4754 Image sizes are the same for all shops and themes

This commit is contained in:
vAugagneur
2012-12-18 14:59:34 +01:00
parent c138e2dc5b
commit 17350c6149
19 changed files with 80 additions and 57 deletions
+31 -12
View File
@@ -78,6 +78,8 @@ class ImageTypeCore extends ObjectModel
* @var array Image types cache
*/
protected static $images_types_cache = array();
protected static $images_types_name_cache = array();
protected $webserviceParameters = array();
@@ -87,20 +89,17 @@ class ImageTypeCore extends ObjectModel
* @param string|null Image type
* @return array Image type definitions
*/
public static function getImagesTypes($type = null, $id_theme = false)
public static function getImagesTypes($type = null)
{
if (!isset(self::$images_types_cache[$type.($id_theme ? '-'.$id_theme : '')]))
if (!isset(self::$images_types_cache[$type]))
{
$where = 'WHERE 1';
if ($id_theme)
$where .= ' AND id_theme='.(int)$id_theme;
if (!empty($type))
$where .= ' AND '.pSQL($type).' = 1 ';
$query = 'SELECT * FROM `'._DB_PREFIX_.'image_type`'.$where.' ORDER BY `name` ASC';
self::$images_types_cache[$type] = Db::getInstance()->executeS($query);
}
return self::$images_types_cache[$type];
}
@@ -116,9 +115,9 @@ class ImageTypeCore extends ObjectModel
die(Tools::displayError());
Db::getInstance()->executeS('
SELECT `id_image_type`
FROM `'._DB_PREFIX_.'image_type`
WHERE `name` = \''.pSQL($typeName).'\'');
SELECT `id_image_type`
FROM `'._DB_PREFIX_.'image_type`
WHERE `name` = \''.pSQL($typeName).'\'');
return Db::getInstance()->NumRows();
}
@@ -128,9 +127,29 @@ class ImageTypeCore extends ObjectModel
* @param string $name
* @param string $type
*/
public static function getByNameNType($name, $type)
public static function getByNameNType($name, $type = null)
{
return Db::getInstance()->getRow('SELECT `id_image_type`, `name`, `width`, `height`, `products`, `categories`, `manufacturers`, `suppliers`, `scenes` FROM `'._DB_PREFIX_.'image_type` WHERE `name` = \''.pSQL($name).'\' AND `'.pSQL($type).'` = 1');
if (!isset(self::$images_types_name_cache[$name.'_'.$type]))
{
self::$images_types_name_cache[$name.'_'.$type] = 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' : ''));
}
return self::$images_types_name_cache[$name.'_'.$type];
}
}
public static function getFormatedName($name)
{
$theme_name = Context::getContext()->shop->theme_name;
$name_without_theme_name = str_replace(array('_'.$theme_name, $theme_name.'_'), '', $name);
//check if the theme name is already in $name if yes only return $name
if (strstr($name, $theme_name) && self::getByNameNType($name))
return $name;
else if (self::getByNameNType($name_without_theme_name.'_'.$theme_name))
return $name_without_theme_name.'_'.$theme_name;
else
return $theme_name.'_'.$name_without_theme_name;
}
}
+11 -11
View File
@@ -516,11 +516,11 @@ class LanguageCore extends ObjectModel
// delete images
$files_copy = array(
'/en.jpg',
'/en-default-thickbox_default.jpg',
'/en-default-home_default.jpg',
'/en-default-large_default.jpg',
'/en-default-medium_default.jpg',
'/en-default-small_default.jpg'
'/en-default-'.ImageType::getFormatedName('thickbox').'.jpg',
'/en-default-'.ImageType::getFormatedName('home').'.jpg',
'/en-default-'.ImageType::getFormatedName('large').'.jpg',
'/en-default-'.ImageType::getFormatedName('medium').'.jpg',
'/en-default-'.ImageType::getFormatedName('small').'.jpg'
);
$tos = array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_);
foreach ($tos as $to)
@@ -726,12 +726,12 @@ class LanguageCore extends ObjectModel
$files_copy = array(
'/en.jpg',
'/en-default-thickbox_default.jpg',
'/en-default-home_default.jpg',
'/en-default-large_default.jpg',
'/en-default-medium_default.jpg',
'/en-default-small_default.jpg',
'/en-default-scene_default.jpg'
'/en-default-'.ImageType::getFormatedName('thickbox').'.jpg',
'/en-default-'.ImageType::getFormatedName('home').'.jpg',
'/en-default-'.ImageType::getFormatedName('large').'.jpg',
'/en-default-'.ImageType::getFormatedName('medium').'.jpg',
'/en-default-'.ImageType::getFormatedName('small').'.jpg',
'/en-default-'.ImageType::getFormatedName('scene').'.jpg'
);
foreach (array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_) as $to)
foreach ($files_copy as $file)
+1 -1
View File
@@ -40,7 +40,7 @@ class BestSalesControllerCore extends FrontController
'products' => ProductSale::getBestSales($this->context->language->id, $this->p - 1, $this->n, $this->orderBy, $this->orderWay),
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'nbProducts' => $nbProducts,
'homeSize' => Image::getSize('home_default'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')
));
+6 -6
View File
@@ -120,10 +120,10 @@ class CategoryControllerCore extends FrontController
'return_category_name' => Tools::safeOutput($this->category->name),
'path' => Tools::getPath($this->category->id),
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'categorySize' => Image::getSize('category_default'),
'mediumSize' => Image::getSize('medium_default'),
'thumbSceneSize' => Image::getSize('m_scene_default'),
'homeSize' => Image::getSize('home_default'),
'categorySize' => Image::getSize(ImageType::getFormatedName('category')),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'thumbSceneSize' => Image::getSize(ImageType::getFormatedName('m_scene')),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
'allow_oosp' => (int)Configuration::get('PS_ORDER_OUT_OF_STOCK'),
'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'),
'suppliers' => Supplier::getSuppliers()
@@ -144,9 +144,9 @@ class CategoryControllerCore extends FrontController
{
foreach ($sceneImageTypes as $sceneImageType)
{
if ($sceneImageType['name'] == 'm_scene_default')
if ($sceneImageType['name'] == ImageType::getFormatedName('m_scene'))
$thumbSceneImageType = $sceneImageType;
elseif ($sceneImageType['name'] == 'scene_default')
elseif ($sceneImageType['name'] == ImageType::getFormatedName('scene'))
$largeSceneImageType = $sceneImageType;
}
+1 -1
View File
@@ -132,7 +132,7 @@ class CompareControllerCore extends FrontController
'product_features' => $listFeatures,
'products' => $listProducts,
'width' => $width,
'homeSize' => Image::getSize('home_default')
'homeSize' => Image::getSize(ImageType::getFormatedName('home'))
));
$this->context->smarty->assign('HOOK_EXTRA_PRODUCT_COMPARISON', Hook::exec('displayProductComparison', array('list_ids_product' => $ids)));
}
+2 -2
View File
@@ -115,12 +115,12 @@ class ManufacturerControllerCore extends FrontController
$this->pagination($nbProducts);
foreach ($data as &$item)
$item['image'] = (!file_exists(_PS_MANU_IMG_DIR_.'/'.$item['id_manufacturer'].'-medium_default.jpg')) ? $this->context->language->iso_code.'-default' : $item['id_manufacturer'];
$item['image'] = (!file_exists(_PS_MANU_IMG_DIR_.'/'.$item['id_manufacturer'].'-'.ImageType::getFormatedName('medium').'.jpg')) ? $this->context->language->iso_code.'-default' : $item['id_manufacturer'];
$this->context->smarty->assign(array(
'pages_nb' => ceil($nbProducts / (int)($this->n)),
'nbManufacturers' => $nbProducts,
'mediumSize' => Image::getSize('medium_default'),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'manufacturers' => $data,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
));
+1 -1
View File
@@ -60,7 +60,7 @@ class NewProductsControllerCore extends FrontController
'products' => Product::getNewProducts($this->context->language->id, (int)($this->p) - 1, (int)($this->n), false, $this->orderBy, $this->orderWay),
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'nbProducts' => (int)($nbProducts),
'homeSize' => Image::getSize('home_default'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')
));
+1 -1
View File
@@ -53,7 +53,7 @@ class PricesDropControllerCore extends FrontController
'products' => Product::getPricesDrop($this->context->language->id, (int)$this->p - 1, (int)$this->n, false, $this->orderBy, $this->orderWay),
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'nbProducts' => $nbProducts,
'homeSize' => Image::getSize('home_default'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')
));
+9 -5
View File
@@ -345,15 +345,19 @@ class ProductControllerCore extends FrontController
$product_images[(int)$image['id_image']] = $image;
}
if (!isset($cover))
$cover = array('id_image' => $this->context->language->iso_code.'-default', 'legend' => 'No picture', 'title' => 'No picture');
$size = Image::getSize('large_default');
$cover = array(
'id_image' => $this->context->language->iso_code.'-default',
'legend' => 'No picture',
'title' => 'No picture'
);
$size = Image::getSize(ImageType::getFormatedName('large'));
$this->context->smarty->assign(array(
'have_image' => Product::getCover((int)Tools::getValue('id_product')),
'cover' => $cover,
'imgWidth' => (int)$size['width'],
'mediumSize' => Image::getSize('medium_default'),
'largeSize' => Image::getSize('large_default'),
'homeSize' => Image::getSize('home_default'),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'largeSize' => Image::getSize(ImageType::getFormatedName('large')),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
'col_img_dir' => _PS_COL_IMG_DIR_));
if (count($product_images))
$this->context->smarty->assign('images', $product_images);
+3 -3
View File
@@ -81,7 +81,7 @@ class SearchControllerCore extends FrontController
'nbProducts' => $search['total'],
'search_query' => $query,
'instant_search' => $this->instant_search,
'homeSize' => Image::getSize('home_default')));
'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
}
else if (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query))
{
@@ -97,7 +97,7 @@ class SearchControllerCore extends FrontController
'search_products' => $search['result'],
'nbProducts' => $search['total'],
'search_query' => $query,
'homeSize' => Image::getSize('home_default')));
'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
}
else if (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag))
{
@@ -110,7 +110,7 @@ class SearchControllerCore extends FrontController
'products' => $result, // DEPRECATED (since to 1.4), not use this: conflict with block_cart module
'search_products' => $result,
'nbProducts' => $nbProducts,
'homeSize' => Image::getSize('home_default')));
'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
}
else
{
+1 -1
View File
@@ -262,7 +262,7 @@ class StoresControllerCore extends FrontController
$this->assignStores();
$this->context->smarty->assign(array(
'mediumSize' => Image::getSize('medium_default'),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'defaultLat' => (float)Configuration::get('PS_STORES_CENTER_LAT'),
'defaultLong' => (float)Configuration::get('PS_STORES_CENTER_LONG'),
'searchUrl' => $this->context->link->getPageLink('stores'),
+2 -2
View File
@@ -118,12 +118,12 @@ class SupplierControllerCore extends FrontController
$suppliers = Supplier::getSuppliers(true, $this->context->language->id, true, $this->p, $this->n);
foreach ($suppliers as &$row)
$row['image'] = (!file_exists(_PS_SUPP_IMG_DIR_.'/'.$row['id_supplier'].'-medium_default.jpg')) ? $this->context->language->iso_code.'-default' : $row['id_supplier'];
$row['image'] = (!file_exists(_PS_SUPP_IMG_DIR_.'/'.$row['id_supplier'].'-'.ImageType::getFormatedName('medium').'.jpg')) ? $this->context->language->iso_code.'-default' : $row['id_supplier'];
$this->context->smarty->assign(array(
'pages_nb' => ceil($nbProducts / (int)$this->n),
'nbSuppliers' => $nbProducts,
'mediumSize' => Image::getSize('medium_default'),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'suppliers_list' => $suppliers,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
));
@@ -120,8 +120,8 @@ class BlockBestSellers extends Module
$this->smarty->assign(array(
'best_sellers' => $best_sellers,
'mediumSize' => Image::getSize('medium_default'),
'smallSize' => Image::getSize('small_default')
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'smallSize' => Image::getSize(ImageType::getFormatedName('small'))
));
return $this->display(__FILE__, 'blockbestsellers.tpl');
}
@@ -158,7 +158,7 @@ class BlockBestSellers extends Module
$this->smarty->assign(array(
'best_sellers' => $best_sellers,
'homeSize' => Image::getSize('home_default')));
'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
return $this->display(__FILE__, 'blockbestsellers-home.tpl');
}
}
+1 -1
View File
@@ -3868,7 +3868,7 @@ class BlockLayered extends Module
$smarty->assign(
array(
'homeSize' => Image::getSize('home_default'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
'nb_products' => $nb_products,
'category' => (object)array('id' => Tools::getValue('id_category_layered', 1)),
'pages_nb' => (int)($pages_nb),
@@ -101,7 +101,7 @@ class BlockNewProducts extends Module
$this->smarty->assign(array(
'new_products' => $newProducts,
'mediumSize' => Image::getSize('medium_default'),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
));
return $this->display(__FILE__, 'blocknewproducts.tpl');
+1 -1
View File
@@ -92,7 +92,7 @@ class BlockSpecials extends Module
$this->smarty->assign(array(
'special' => $special,
'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
'mediumSize' => Image::getSize('medium_default'),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
));
return $this->display(__FILE__, 'blockspecials.tpl');
+2 -2
View File
@@ -158,7 +158,7 @@ class CrossSelling extends Module
$taxCalc = Product::getTaxCalculationMethod();
foreach ($orderProducts AS &$orderProduct)
{
$orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], 'medium_default');
$orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium'));
$orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']);
if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2))
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL);
@@ -212,7 +212,7 @@ class CrossSelling extends Module
$taxCalc = Product::getTaxCalculationMethod();
foreach ($orderProducts AS &$orderProduct)
{
$orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], 'medium_default');
$orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium'));
$orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']);
if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2))
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL);
+1 -1
View File
@@ -108,7 +108,7 @@ class HomeFeatured extends Module
$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize('home_default'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
));
return $this->display(__FILE__, 'homefeatured.tpl');
+2 -2
View File
@@ -710,7 +710,7 @@ class ProductComments extends Module
'logged' => (int)$this->context->customer->isLogged(true),
'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
'mediumSize' => Image::getSize('medium_default'),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), $this->context->language->id),
'action_url' => '',
'averageTotal' => (int)$average['grade'],
@@ -752,7 +752,7 @@ class ProductComments extends Module
'id_product_comment_form' => (int)Tools::getValue('id_product'),
'secure_key' => $this->secure_key,
'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
'mediumSize' => Image::getSize('medium_default'),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'nbComments' => (int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')),
'productcomments_controller_url' => $this->context->link->getModuleLink('productcomments'),
'productcomments_url_rewriting_activated' => Configuration::get('PS_REWRITING_SETTINGS', 0)