dawb Posted October 30, 2012 Share Posted October 30, 2012 (edited) 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 February 17, 2013 by dawb (see edit history) Link to comment Share on other sites More sharing options...
CartExpert.net Posted October 31, 2012 Share Posted October 31, 2012 Hi. You can choose both ways. It would be easier if you create separate functions. Regards. Robin. The CartExpert Team Link to comment Share on other sites More sharing options...
dawb Posted October 31, 2012 Author Share Posted October 31, 2012 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 More sharing options...
CartExpert.net Posted October 31, 2012 Share Posted October 31, 2012 Hi. The image upload / delete is dealt with in classes/AdminTab.php (functions postImage and uploadImage), but in your case, you need to create the functions in the file admin/tabs/AdminCategories.php Regards. Robin. The CartExpert Team Link to comment Share on other sites More sharing options...
dawb Posted October 31, 2012 Author Share Posted October 31, 2012 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 More sharing options...
dawb Posted November 1, 2012 Author Share Posted November 1, 2012 (edited) 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 November 1, 2012 by dawb (see edit history) Link to comment Share on other sites More sharing options...
skfreelance Posted February 9, 2013 Share Posted February 9, 2013 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 More sharing options...
dawb Posted February 17, 2013 Author Share Posted February 17, 2013 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 More sharing options...
j4ck Posted February 24, 2013 Share Posted February 24, 2013 'image' => $smallTile ? $smallTile : false What is $smallTile in this example? Link to comment Share on other sites More sharing options...
dawb Posted February 24, 2013 Author Share Posted February 24, 2013 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 More sharing options...
j4ck Posted February 25, 2013 Share Posted February 25, 2013 Hi, Dawb. Did you modify renderForm() method? How you passed current field values (smalltile) to form? Link to comment Share on other sites More sharing options...
dawb Posted February 25, 2013 Author Share Posted February 25, 2013 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 More sharing options...
j4ck Posted February 26, 2013 Share Posted February 26, 2013 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 More sharing options...
dawb Posted February 26, 2013 Author Share Posted February 26, 2013 (edited) 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 February 26, 2013 by dawb (see edit history) Link to comment Share on other sites More sharing options...
arlo Posted April 12, 2013 Share Posted April 12, 2013 Hi how can i insert this in 1.4.7? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now