Jump to content

Recommended Posts

Posted (edited)

hi there,

I have CE1.0.5.0, trying to modify admin/categories.php so that can have the categories images (ref to  Select Product Image Directory in selected image folder...

 /* Make New Image subdirectory for categories */
          $new_dir_cat = preg_replace('/[^a-zA-Z0-9_.-]/i', '_',$_POST['new_directory']);
         $dir_cat = (tep_not_null($new_dir_cat) ? $_POST['directory'] . '/' . $new_dir_cat : $_POST['directory']);
         $dir_cat = ($dir_cat ? $dir_cat .'/' : '');
	        /* Make New subdirectory */
           if ($dir_cat && !is_dir($root_images_dir . $dir_cat)) {
            if (mkdir($root_images_dir . $dir_cat))
                $messageStack->add_session(sprintf(SUCCESS_CREATED_DIRECTORY, $new_dir_cat, $images_dir.$_POST['directory']), 'success');
           }
	        $categories_image = new upload('categories_image');
	        $categories_image->set_destination($root_images_dir . $dir_cat);
	 
	        if ($categories_image->parse() && $categories_image->save()) {
	          tep_db_query("update categories set categories_image = '" . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'");
        }
        
        $OSCOM_Hooks->call('categories', 'insertcategoryupdatecategoryAction');
        
	        tep_redirect(tep_href_link('categories.php', 'cPath=' . $cPath . '&cID=' . $categories_id));
        break;

with the code, i can create a new sub-image folder name, and the new categories image will save into server image/new_image_folder, however,

the /catalog/images/
IMAGE DOES NOT EXIST image.thumb.png.ef99d80f8fbf01f34f4b8500f0ae93f0.png

when hit Edit, the images not show up, because path is still catalog/images/,
if update cat-test-04.jpg it only allow to save under catalog/images/ not the new image sub-solder, it end up saved in both
catalog/images/  and catalog/images/test-cat4/ has  cat-test-04.jpg   but only catalog/images/cat-test-04.jpg will show up in the front end
image.png.ed40f4674de8a6786531e2ce450373e5.png

image.png.ff873846b08ce8f52ff2c1844f8d3a45.png

image.png.cfe97e6b7013bf7f93b63d25d1435fb7.png

 

how can I modify code so that
#1 images in new folder will show up in the front page
#2 images not only limited the location of original website setting path: catalog/images/ 

 

I also want to be able to delete just categories images, not the whole categories details (ref to Delete Category Image (ONLY for osC 2.2)  I followed the installation instruction as below (I only modified a bit of the codes) but it doesn't work, did I make some mistakes?

     
Step #1
	  function tep_remove_category_image($category_id) {
 
    $category_image_query = tep_db_query("select categories_image from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$category_id . "'");
    $category_image = tep_db_fetch_array($category_image_query);
	    $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where categories_image = '" . tep_db_input($category_image['categories_image']) . "'");
    $duplicate_image = tep_db_fetch_array($duplicate_image_query);
	    if ($duplicate_image['total'] < 2) {
      if (file_exists(DIR_FS_CATALOG_IMAGES . $category_image['categories_image'])) {
        unlink(DIR_FS_CATALOG_IMAGES . $category_image['categories_image']);
      }
    }
	    tep_db_query("update " . TABLE_CATEGORIES . " set categories_image ='' where categories_id = '" . (int)$category_id . "'");
  }
	 
	Step #2
case 'delete_category_image_confirm':
        if (isset($_POST['categories_id'])) {
          $categories_id = tep_db_prepare_input($_POST['categories_id']);
            tep_remove_category_image($categories_id);
	        }
	        tep_redirect(tep_href_link('categories.php', 'cPath=' . $cPath));
        break;
	Step #3
	            $contents[] = ['align' => 'center', 'text' =>
            tep_draw_bootstrap_button(IMAGE_EDIT, 'fas fa-cogs', tep_href_link('categories.php', 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=edit_category'), null, null, 'btn-warning mr-2') .
            tep_draw_bootstrap_button(IMAGE_DELETE, 'fas fa-trash', tep_href_link('categories.php', 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=delete_category'), null, null, 'btn-danger xxx text-white mr-2') .
            tep_draw_bootstrap_button(IMAGE_MOVE, 'fas fa-arrows-alt', tep_href_link('categories.php', 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=move_category'), null, null, 'btn-light') .
         // add delete image button
            tep_draw_bootstrap_button(IMAGE_DELETE_IMAGE, 'fas fa-trash', tep_href_link('categories.php', 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=delete_category_image'), null, null, 'btn-danger xxx text-white mr-2')
            ];
	 
	

any help is appreciated, thanks!  Lyn

 

 

Edited by ce7

Share this post


Link to post
Share on other sites
42 minutes ago, ce7 said:

" . TABLE_CATEGORIES . "

would be categories

Share this post


Link to post
Share on other sites

hi, @Fiber

Thank you for remind me the table name, i forgot to mention it is the code in catalog/admin/includes/functions/general.php, so i did not change to "categories".

delete image still not working, but i tested the categories images.

now use test01.jpg as example, it will
#01 no problem to make images/test01.jpg   or images/new_sub_cat/test01.jpg
#02 no problem to upload to server images/test01.jpg   or images/new_sub_cat/test01.jpg
#03 no problem to update the database-categories table, it will show up all the categories image directory and image nameimage.png.1f347c5ff2f3266a2936603be6311fbb.png

image.thumb.png.449bdcab465376764461410e4ba863f6.png

if I manually edit the categories column, categories_images from 
/home/public_html/site.com/images/cat2/cat-test-01.jpg   to    just   cat-test-01.jpg
then the front page will appear the categories image, so this tell me the categories_images only accept image file without directory details... so my question now is
how to change file or code so that column, categories_images will accept image_directory/image_name.jpg and will show up both in admin (no more IMAGES DOES NOT EXIST) and front page?
image.png.eef5c1572649e7308711bcdc2e72ac4e.png

any help is appreciated, thanks!  Lyn

Share this post


Link to post
Share on other sites

Do not know these addons, I only noticed the ". TABLE_CATEGORIES. " 

Share this post


Link to post
Share on other sites

The image URLs are made by appending the image name to the image directory URL.  So you only want the portion of the path after the images directory.  In your example, that would be cat2/cat-test-01.jpg


Always back up before making changes.

Share this post


Link to post
Share on other sites

hi, @ecartz

Thank you the suggestion.
i change back the code:  from $root_images_dir   to   $images_dir ($images_dir = 'images/';)

       // tep_db_query("update categories set categories_image = '" . $root_images_dir . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'");
          tep_db_query("update categories set categories_image = '" . $images_dir . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'");

image.thumb.png.9a4fb8c307060a8bd4ab8701e2d1465f.png

image.thumb.png.b943a279a35c39f108c60361186c5bb7.png

it is still admin and front page not showing the image....

Share this post


Link to post
Share on other sites

Maybe

          tep_db_query("UPDATE categories SET categories_image = '" . tep_db_input($dir_cat . $categories_image->filename) . "' WHERE categories_id = " . (int)$categories_id);

 


Always back up before making changes.

Share this post


Link to post
Share on other sites
Posted (edited)

hi, @ecartz

 i am just self learning oscommerce, not trained programmer, so took me many tries and forgot to change " $images_dir " part, and after your modification, it works great! Thank you so much!!! You are the champion!👍 😘

Edited by ce7

Share this post


Link to post
Share on other sites

hi, @ecartz

About the delete image, it is the addon for osc 2.2 version, in the later version, the main images can not be deleted, the enlarge images, will have a trash icon, i like to just delete the image, is it similiar to your moidification, but instead of UPDATE, but use DELETE?
image.thumb.png.9860d865fae68156c4fb16b4db268cef.png

Share this post


Link to post
Share on other sites

No, the DB update would stay the same.  The only change you'd need to make is " . TABLE_CATEGORIES . " to categories.  Otherwise , the code that you posted should be correct.  Except that it's missing the confirmation step.  You have the button and you have the code that processes the confirmation.  But I don't see the actual step for confirming the deletion. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

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

×