Jump to content

[Solved] Adding Extra Image Fields To Category


dawb

Recommended Posts

Hi,

 

I am currently trying to override the categories class so that we can have an image for say a small banner and a different image for a large banner, rather than just resizing the one image. I have got the image fields added into the form fine. What I am wondering is if it is neccessary to create new delete/add functions eg processForceDeleteImage. Or is it possible to set these up so that they are just processed through the standard function?

 

From what I can see it is only possible to process the one image file. Is this correct, as it seems rather limiting to only allow one image file per page?

 

I have looked in the documentation but there does not seem to be anything about adding new image options...

 

Thanks for the help.

Edited by dawb (see edit history)
Link to comment
Share on other sites

Thanks for the quick reply Robin. I will look at creating duplicate functions. Is it possible for you to point me in the right direction with regards to the function that deals with uploading the image once the form is submitted as I can't seem to see how this happens.

 

Thanks a lot for your help

Link to comment
Share on other sites

Brilliant thanks Robin, I've got them uploading properly now.

 

Sorry one more question is there a variable that I can set so that the image previews are of these images? eg for each of the image fields names. As at the moment it seems to automatically pull through the 'image' file for ever image field.

 

Thanks

Link to comment
Share on other sites

I have found the field variable 'thumb' used in the $fields_form array but this does not seem to attach the thumb to the fields. They are still generating a thumb based on the original 'image' field. Do you know if there are any other variables that I need to include in this?

 

Also do you know where I can find documentation on the available fields/options within the $fields_form array?

Edited by dawb (see edit history)
Link to comment
Share on other sites

  • 3 months later...

Hi,

 

I am currently trying to override the categories class so that we can have an image for say a small banner and a different image for a large banner, rather than just resizing the one image. I have got the image fields added into the form fine. What I am wondering is if it is neccessary to create new delete/add functions eg processForceDeleteImage. Or is it possible to set these up so that they are just processed through the standard function?

 

From what I can see it is only possible to process the one image file. Is this correct, as it seems rather limiting to only allow one image file per page?

 

I have looked in the documentation but there does not seem to be anything about adding new image options...

 

Thanks for the help.

 

Hi,

 

 

I'm so interested to know how can i add a custom upload image field to my category page in back office.

 

Do you share with us how you did it please ?

Link to comment
Share on other sites

  • 2 weeks later...

Hi, I did this by editing the category.php and the adminCategoriesController.php files and looking at where the existing image is added.

 

The main function that you will need to update in category.php is the _construct. You will also need to add the file fields into the adminCategoriesController. I have put an example of this below:

array(
 'type' => 'file',
 'label' => $this->l('Tile Image:'),
 'name' => 'smallTile',
 'id' => 'smallTile',
 'class' => 'smallTile',
 'display_image' => true,
 'image' => $smallTile ? $smallTile : false,
 'size' => $smallTile ? filesize(_PS_CAT_IMG_DIR_.'/'.$obj->id.'-smallTile.' . $this->imageType) / 1000 : false,
 'desc' => $this->l('Upload a tile for the category list (470px x 223px)')
   ),

 

You will also need to update the postImage, uploadImage and postProcess functions. You will also need to create new functions for the forceDelete and delete. I have put examples of these below:

 

public function postProcess(){
 if (!in_array($this->display, array('edit', 'add'))){
  $this->multishop_context_group = false;
 }
 if (Tools::isSubmit('forcedeleteImage') || isset($_FILES['image'])){
  $this->processForceDeleteImage();
  if (Tools::isSubmit('forcedeleteImage'))
   Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminCategories').'&conf=7');
 }
 if (isset($_FILES['smallTile']) && $_FILES['smallTile']['size'] != '0'){
  $this->processForceDeleteSmallTile();
 }

 if (isset($_FILES['bigBan']) && $_FILES['bigBan']['size'] != '0'){
  $this->processForceDeleteBigBan();
 }

 return AdminController::postProcess();
}
public function processForceDeleteSmallTile(){
 $category = $this->loadObject(true);
 if (Validate::isLoadedObject($category)){
  $this->deleteSmallTile();
 }
}
public function deleteSmallTile(){
 Tools::displayAsDeprecated();
 $dir = null;
 /* Deleting object images and thumbnails (cache) */
 if (key_exists('dir', $this->fieldSmallTileSettings)){
  $dir = $this->fieldSmallTileSettings['dir'].'/';
  $id = (int)Tools::getValue('id_category');
  // Delete temp image
  if (file_exists(_PS_TMP_IMG_DIR_ . 'category_' . $id . '.' . $this->fieldSmallTileSettings['name']) && !unlink(_PS_TMP_IMG_DIR_ . 'category_' . $id . '.' . $this->fieldSmallTileSettings['name'])){
   return false;
  }
  // Delete old image
  if (file_exists(_PS_IMG_DIR_ . $dir . $id . $this->fieldSmallTileSettings['dashName'] . '.'.$this->imageType) && !unlink(_PS_IMG_DIR_.$dir.$id.$this->fieldSmallTileSettings['dashName'].'.'.$this->imageType)){
   return false;
  }
 }
 return true;
}

Link to comment
Share on other sites

Hi, the small tile variable is the images thumbnail. Thought I had included it above, it should look something like

 

$smallTile = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.'/'.$obj->id.'-smallTile.' . $this->imageType, $this->table.'_'.(int)$obj->id.'.smallTile', 350, 'png', true);

Link to comment
Share on other sites

hi jack, yes that is what the first array is from (see below). If you add this to the fields_form array under inputs. The smallTile variable is used to display the thumbnail for the front end of the form

 

array(
	 'type' => 'file',
	 'label' => $this->l('Tile Image:'),
	 'name' => 'smallTile',
	 'id' => 'smallTile',
	 'class' => 'smallTile',
	 'display_image' => true,
	 'image' => $smallTile ? $smallTile : false,
	 'size' => $smallTile ? filesize(_PS_CAT_IMG_DIR_.'/'.$obj->id.'-smallTile.' . $this->imageType) / 1000 : false,
	 'desc' => $this->l('Upload a tile for the category list (470px x 223px)')

Link to comment
Share on other sites

As i can see in form helper template

 

{elseif $input.type == 'file'}
   {if isset($input.display_image) && $input.display_image}
       {if isset($fields_value.image) && $fields_value.image}
           <div id="image">
               {$fields_value.image}
               <p align="center">{l s='File size'} {$fields_value.size}kb</p>
               <a href="{$current}&{$identifier}={$form_id}&token={$token}&deleteImage=1">
                   <img src="../img/admin/delete.gif" alt="{l s='Delete'}" /> {l s='Delete'}
               </a>

 

$fields_value.image is used to display in all 'file'-type field,

when `display_image` is set.

 

This code not support more then one image field without changes.

Any thoughts?

 

Link to comment
Share on other sites

Unfortunately not, from what I could find on here and from looking at the class it only handles one image. That is why I had to create mutliple extra image functions to allow for different banners for the categories (a real pain)

 

If you do manage to do this without creating extra functions please post your answer on here. thanks

Edited by dawb (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...