// Added logo management to the carrier wizard (still need a "remove image" feature)

This commit is contained in:
Damien Metzger
2013-07-17 18:33:40 +02:00
parent 810120aeb9
commit bfa1294df9
3 changed files with 101 additions and 23 deletions
@@ -0,0 +1,57 @@
{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<script type="text/javascript">
function uploadCarrierLogo()
{
$.ajaxFileUpload({
url: 'ajax-tab.php?tab=AdminCarrierWizard&token={$token|addslashes}&action=uploadLogo',
secureuri: false,
fileElementId: 'carrier_logo_input',
dataType: 'xml',
success: function (data, status) {
data = data.getElementsByTagName('return')[0];
var message = data.getAttribute("message");
if (data.getAttribute("result") == "success")
{
$('#carrier_logo_img').attr('src', message);
$('#logo').val(message);
}
else
alert(message);
}
});
}
</script>
<div id="carrier_logo_block" style="position:absolute;top:10px;right:10px">
<img id="carrier_logo_img" src="{if $carrier_logo}{$carrier_logo}{else}../img/404.gif{/if}" />
<p>
<input id="carrier_logo_input" type="file" onchange="uploadCarrierLogo();" name="carrier_logo_input" />
<input type="hidden" id="logo" name="logo" value="" />
</p>
<p class="preference_description" style="clear:both">
{l s='Format:'} JPG, GIF, PNG. {l s='Filesize:'} {$max_image_size|string_format:"%.2f"} {l s='MB max.'}
</p>
</div>
@@ -97,7 +97,7 @@ class AdminCarrierWizardControllerCore extends AdminController
$carrier = new Carrier();
$this->tpl_view_vars = array(
'enableAllSteps' => (int)Validate::isLoadedObject($carrier),
'enableAllSteps' => Validate::isLoadedObject($carrier),
'wizard_steps' => $this->wizard_steps,
'validate_url' => $this->context->link->getAdminLink('AdminCarrierWizard'),
'carrierlist_url' => $this->context->link->getAdminLink('AdminCarriers').'&conf='.((int)Validate::isLoadedObject($carrier) ? 4 : 3),
@@ -113,6 +113,13 @@ class AdminCarrierWizardControllerCore extends AdminController
if (Shop::isFeatureActive())
array_splice($this->tpl_view_vars['wizard_contents']['contents'], 1, 0, array(0 => $this->renderStepTwo($carrier)));
$this->context->smarty->assign(array(
'max_image_size' => (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE') / 1024 / 1024,
'carrier_logo' => (Validate::isLoadedObject($carrier) && file_exists(_PS_SHIP_IMG_DIR_.$carrier->id.'.jpg') ? _THEME_SHIP_DIR_.$carrier->id.'.jpg' : false)
));
$this->content .= $this->createTemplate('logo.tpl')->fetch();
$this->addjQueryPlugin(array('ajaxfileupload'));
return parent::renderView();
}
@@ -170,12 +177,6 @@ class AdminCarrierWizardControllerCore extends AdminController
'size' => 1,
'desc' => $this->l('Enter "0" for a longest shipping delay, or "9" for the shortest shipping delay.')
),
array(
'type' => 'file',
'label' => $this->l('Logo:'),
'name' => 'logo',
'desc' => $this->l('Upload a logo from your computer.').' (.gif, .jpg, .jpeg '.$this->l('or').' .png)'
),
array(
'type' => 'text',
'label' => $this->l('URL:'),
@@ -443,7 +444,6 @@ class AdminCarrierWizardControllerCore extends AdminController
'name' => $this->getFieldValue($carrier, 'name'),
'delay' => $this->getFieldValue($carrier, 'delay'),
'grade' => $this->getFieldValue($carrier, 'grade'),
'logo' => '',
'url' => $this->getFieldValue($carrier, 'url'),
);
}
@@ -539,6 +539,28 @@ class AdminCarrierWizardControllerCore extends AdminController
}
}
public function ajaxProcessUploadLogo()
{
$allowedExtensions = array('jpeg', 'gif', 'png', 'jpg');
$logo = (isset($_FILES['carrier_logo_input']) ? $_FILES['carrier_logo_input'] : false);
if ($logo && !empty($logo['tmp_name']) && $logo['tmp_name'] != 'none'
&& (!isset($logo['error']) || !$logo['error'])
&& preg_match('/\.(jpe?g|gif|png)$/', $logo['name'])
&& is_uploaded_file($logo['tmp_name']))
{
$file = $logo['tmp_name'];
do $tmp_name = uniqid().'.jpg';
while (file_exists(_PS_TMP_IMG_DIR_.$tmp_name));
if (!ImageManager::resize($file, _PS_TMP_IMG_DIR_.$tmp_name))
die ('<return result="error" message="Impossible to resize the image into '.Tools::safeOutput(_PS_TMP_IMG_DIR_).'" />');
@unlink($file);
die ('<return result="success" message="'.Tools::safeOutput(_PS_TMP_IMG_.$tmp_name).'" />');
}
else
die ('<return result="error" message="Cannot upload file" />');
}
public function ajaxProcessFinishStep()
{
$return = array('has_error' => false);
@@ -573,7 +595,7 @@ class AdminCarrierWizardControllerCore extends AdminController
}
}
if(Validate::isLoadedObject($carrier))
if (Validate::isLoadedObject($carrier))
{
if (!$this->changeGroups((int)$carrier->id))
{
@@ -599,21 +621,20 @@ class AdminCarrierWizardControllerCore extends AdminController
$return['errors'][] = $this->l('An error occurred while saving the tax rules group.');
}
if (!$this->postImage((int)$carrier->id))
if (Tools::getValue('logo'))
{
$return['has_error'] = true;
$return['errors'][] = $this->l('An error occurred while saving carrier logo.');
$logo = basename(Tools::getValue('logo'));
if (!file_exists(_PS_TMP_IMG_DIR_.$logo) || !copy(_PS_TMP_IMG_DIR_.$logo, _PS_SHIP_IMG_DIR_.$carrier->id.'.jpg'))
{
$return['has_error'] = true;
$return['errors'][] = $this->l('An error occurred while saving carrier logo.');
}
}
$return['id_carrier'] = $carrier->id;
}
die(Tools::jsonEncode($return));
}
protected function updateCarrierAsso($id_carrier)
{
}
protected function changeGroups($id_carrier, $delete = true)
{
if ($delete)
+5 -5
View File
@@ -50,6 +50,7 @@ function onShowStepCallback()
$(this).parent('li').addClass($(this).attr('class'));
});
resizeWizard();
$('#carrier_logo_block').prependTo($('#fieldset_form'));
}
function onFinishCallback(obj, context)
@@ -60,12 +61,11 @@ function onFinishCallback(obj, context)
url : validate_url,
async: false,
dataType: 'json',
data : $('#carrier_wizard .stepContainer .content form').serialize()+'&action=finish_step&ajax=1',
success : function(datas)
{
if (datas.has_error)
data : $('#carrier_wizard .stepContainer .content form').serialize() + '&action=finish_step&ajax=1',
success : function(data) {
if (data.has_error)
{
displayError(datas.errors, context.fromStep);
displayError(data.errors, context.fromStep);
resizeWizard();
}
else