// Categories thumbnails
This commit is contained in:
@@ -33,7 +33,7 @@ class BlockCategories extends Module
|
||||
{
|
||||
$this->name = 'blockcategories';
|
||||
$this->tab = 'front_office_features';
|
||||
$this->version = '2.0';
|
||||
$this->version = '2.1';
|
||||
$this->author = 'PrestaShop';
|
||||
|
||||
parent::__construct();
|
||||
@@ -54,6 +54,8 @@ class BlockCategories extends Module
|
||||
!$this->registerHook('categoryDeletion') ||
|
||||
!$this->registerHook('actionAdminMetaControllerUpdate_optionsBefore') ||
|
||||
!$this->registerHook('actionAdminLanguagesControllerStatusBefore') ||
|
||||
!$this->registerHook('displayBackOfficeCategory') ||
|
||||
!$this->registerHook('actionBackOfficeCategory') ||
|
||||
!Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4) ||
|
||||
!Configuration::updateValue('BLOCK_CATEG_DHTML', 1))
|
||||
return false;
|
||||
@@ -113,6 +115,56 @@ class BlockCategories extends Module
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function hookDisplayBackOfficeCategory($params)
|
||||
{
|
||||
$this->smarty->assign(array(
|
||||
'name' => 'thumb',
|
||||
'images' => array()
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'views/blockcategories_admin.tpl');
|
||||
}
|
||||
|
||||
public function hookActionBackOfficeCategory($params)
|
||||
{
|
||||
$total_errors = array();
|
||||
|
||||
for ($i=0; $i<3; $i++)
|
||||
if (isset($_FILES['thumb-'.$i]) && $_FILES['thumb-'.$i]['size'] > 0)
|
||||
{
|
||||
$errors = array();
|
||||
// Check image validity
|
||||
$max_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
|
||||
|
||||
if ($error = ImageManager::validateUpload($_FILES['thumb-'.$i], Tools::getMaxUploadSize($max_size)))
|
||||
$errors[] = $error;
|
||||
|
||||
$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
|
||||
|
||||
if (!$tmp_name)
|
||||
$errors[] = Tools::displayError('Invalid Temporary directory');
|
||||
|
||||
if (!move_uploaded_file($_FILES['thumb-'.$i]['tmp_name'], $tmp_name))
|
||||
$errors[] = Tools::displayError('Error uploading thumbnail image');
|
||||
|
||||
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
|
||||
if (!ImageManager::checkImageMemoryLimit($tmp_name))
|
||||
$errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
|
||||
|
||||
// Copy new image
|
||||
if (empty($errors) && !ImageManager::resize($tmp_name, _PS_CAT_IMG_DIR_.Tools::getValue('id_category').'-'.$i.'_thumb.jpg'))
|
||||
$errors[] = Tools::displayError('An error occurred while uploading the image.');
|
||||
|
||||
if (count($errors))
|
||||
$total_errors = array_merge($total_errors, $errors);
|
||||
|
||||
unlink($tmp_name);
|
||||
}
|
||||
|
||||
if (count($total_errors))
|
||||
;//TODO : Show errors
|
||||
}
|
||||
|
||||
public function hookLeftColumn($params)
|
||||
{
|
||||
if (!$this->isCached('blockcategories.tpl', $this->getCacheId()))
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>blockcategories</name>
|
||||
<displayName><![CDATA[Categories block]]></displayName>
|
||||
<version><![CDATA[2.0]]></version>
|
||||
<description><![CDATA[Adds a block featuring product categories.]]></description>
|
||||
<displayName><![CDATA[Bloc catégories]]></displayName>
|
||||
<version><![CDATA[2.1]]></version>
|
||||
<description><![CDATA[Ajoute un bloc proposant une navigation au sein de vos catégories de produits]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[front_office_features]]></tab>
|
||||
<is_configurable>1</is_configurable>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
function upgrade_module_2_1($object)
|
||||
{
|
||||
return ($object->registerHook('displayBackOfficeCategory') && $object->registerHook('actionBackOfficeCategory'));
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{for $foo=0 to 2}
|
||||
<div class="form-group">
|
||||
<input id="{$name}-{$foo}" type="file" name="{$name}-{$foo}" class="hide"/>
|
||||
<div class="dummyfile input-group">
|
||||
<span class="input-group-addon"><i class="icon-file"></i></span>
|
||||
<input id="{$name}-name-{$foo}" type="text" class="disabled" readonly/>
|
||||
<span class="input-group-btn">
|
||||
<button id="{$name}-selectbutton-{$foo}" type="button" class="btn btn-default">
|
||||
<i class="icon-folder-open"></i> {l s='Choose a file'}
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
{if isset($images.$foo) && $images.$foo}
|
||||
<div class="clearfix"> </div>
|
||||
<div id="image" class="thumbnail">
|
||||
{$images.$foo.image}
|
||||
<div class="text-center">
|
||||
<a class="btn btn-default" href="">
|
||||
<i class="icon-remove text-danger"></i> {l s='Delete'}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/for}
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('button[id|="{$name}-selectbutton"]').click(function(e) {
|
||||
var id = $(this).prop('id').replace('{$name}-selectbutton-', '');
|
||||
$('#{$name}-'+id).trigger('click');
|
||||
});
|
||||
$('input[id|="{$name}-name"]').click(function(e){
|
||||
var id = $(this).prop('id').replace('{$name}-name-', '');
|
||||
$('#{$name}-'+id).trigger('click');
|
||||
});
|
||||
$('input[id|="{$name}"]').change(function(e){
|
||||
var val = $(this).val();
|
||||
var id = $(this).prop('id').replace('{$name}-', '');
|
||||
var file = val.split(/[\\/]/);
|
||||
$('#{$name}-name-'+id).val(file[file.length-1]);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user