Guest Posted May 8, 2007 Share Posted May 8, 2007 okay.. I've got it all working fine and I've just finished getting it to create seperate folders for each category and subcategory as well. There's probably a slightly smoother way of coding it but here's my code: // copy image only if modified $cid = explode('_', $cPath); $cdat = tep_db_query("SELECT categories_name FROM categories_description WHERE categories_id = '" . $cid[0] . "' && language_id = '1'"); $cat = tep_db_fetch_array($cdat); $subcdat = tep_db_query("SELECT categories_name FROM categories_description WHERE categories_id = '" . $cid[1] . "' && language_id = '1'"); $subc = tep_db_fetch_array($subcdat); $categoryfile = $cat[categories_name] . "/"; if($subc[categories_name] != ''){ $subcfile = $subc[categories_name] . "/"; }else{ $subcfile = ''; } $products_image = new upload('products_image'); $products_image->set_destination(DIR_FS_CATALOG_IMAGES . DIR_FS_PRODUCTS_IMAGES . $categoryfile . $subcfile); if ($products_image->parse() && $products_image->save()) { $products_image_name = DIR_FS_PRODUCTS_IMAGES . $categoryfile . $subcfile . $products_image->filename; } else { $products_image_name = (isset($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : ''); } break; } } it's the part starting on about line 316 First off it explodes the $cPath to get the correct category or subcategory, then it gets the category name and sets it as $cat. Then it gets the subcategory name and sets it as $subc (this could probably be done with a foreach statement..). After that it sets the category file directory as $categoryfile, then checks if you're in a subcategory. If you are then it sets the subcategory directory, otherwise it sets it as blank. If youdon't set it as blank and you're not viewing a sub category it'll be set as '/' so you'll end up with an extra slash. After that it's just the saving functions with the added variables in. I've checked it and it works perfectly for both categories and sub categories. Although you need to create the files yourself, otherwise you'll get a file doesn't exist error. Please feel free to edit the above for smoother running and let me know what you come up with! Thanks Link to comment Share on other sites More sharing options...
psynaptic Posted May 8, 2007 Share Posted May 8, 2007 To be honest I'm pretty happy to just have a separate directory for each categories and manufacturers as these images tend to be quite minimal compared to products. The products sub directory categorisation is what I imagine most people will be interested in. That bug fix I posted about above also applies to the manufacturers image upload. Try adding a manufacturers image and then editing it without adding a new image. If you get a no upload warning you have the same bug. Just change the code in the bug fix above to replace the manufacters new upload code: find: if ($manufacturers_image = new upload('manufacturers_image', DIR_FS_CATALOG_IMAGES . DIR_FS_MANUFACTURERS_IMAGES)) { tep_db_query("update " . TABLE_MANUFACTURERS . " set manufacturers_image = '" . DIR_FS_MANUFACTURERS_IMAGES . $manufacturers_image->filename . "' where manufacturers_id = '" . (int)$manufacturers_id . "'"); } replace with: $manufacturers_image = new upload('manufacturers_image'); $manufacturers_image->set_destination(DIR_FS_CATALOG_IMAGES . DIR_FS_MANUFACTURERS_IMAGES); if ($manufacturers_image->parse() && $manufacturers_image->save()) { tep_db_query("update " . TABLE_MANUFACTURERS . " set manufacturers_image = '" . DIR_FS_MANUFACTURERS_IMAGES . $manufacturers_image->filename . "' where manufacturers_id = '" . (int)$manufacturers_id . "'"); } My Profile | Contribs I like most: 'On The Fly' Auto Thumbnailer, Active Countries, Header Tags Controller, Ultimate SEO URLs, UK Based osC, UK Postcode Validation, Open Featured Sets, UK Postcode Based Carrier Shipping Link to comment Share on other sites More sharing options...
Guest Posted May 8, 2007 Share Posted May 8, 2007 ah, thanks! hadn't realised that. Link to comment Share on other sites More sharing options...
psynaptic Posted May 8, 2007 Share Posted May 8, 2007 You're welcome ;) Maybe you should include the fix in your contribution. My code is still hanging when going to add a new product. It's the bit where it's going to the preview page. Any ideas? What does your code look like around the new upload products image? My Profile | Contribs I like most: 'On The Fly' Auto Thumbnailer, Active Countries, Header Tags Controller, Ultimate SEO URLs, UK Based osC, UK Postcode Validation, Open Featured Sets, UK Postcode Based Carrier Shipping Link to comment Share on other sites More sharing options...
Guest Posted May 8, 2007 Share Posted May 8, 2007 Yeah. I probably will. here's my whole products part: // copy image only if modified $cid = explode('_', $cPath); $cdat = tep_db_query("SELECT categories_name FROM categories_description WHERE categories_id = '" . $cid[0] . "' && language_id = '1'"); $cat = tep_db_fetch_array($cdat); $subcdat = tep_db_query("SELECT categories_name FROM categories_description WHERE categories_id = '" . $cid[1] . "' && language_id = '1'"); $subc = tep_db_fetch_array($subcdat); $categoryfile = $cat[categories_name] . "/"; if($subc[categories_name] != ''){ $subcfile = $subc[categories_name] . "/"; }else{ $subcfile = ''; } $products_image = new upload('products_image'); $products_image->set_destination(DIR_FS_CATALOG_IMAGES . DIR_FS_PRODUCTS_IMAGES . $categoryfile . $subcfile); if ($products_image->parse() && $products_image->save()) { $products_image_name = DIR_FS_PRODUCTS_IMAGES . $categoryfile . $subcfile . $products_image->filename; } else { $products_image_name = (isset($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : ''); } break; } } // check if the catalog image directory exists if (is_dir(DIR_FS_CATALOG_IMAGES . DIR_FS_PRODUCTS_IMAGES . $categoryfile . $subcfile)) { if (!is_writeable(DIR_FS_CATALOG_IMAGES . DIR_FS_PRODUCTS_IMAGES . $categoryfile . $subcfile)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error'); } else { $messageStack->add(ERROR_CATALOG_PRODUCT_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error'); } For the last error I made my own message so I could define what's causing errors easier. not sure what would cause it to hang though.. Link to comment Share on other sites More sharing options...
psynaptic Posted May 8, 2007 Share Posted May 8, 2007 Apart from your changes my code is exactly the same. When you go to add a product with a new image and click the preview button does it hang? My Profile | Contribs I like most: 'On The Fly' Auto Thumbnailer, Active Countries, Header Tags Controller, Ultimate SEO URLs, UK Based osC, UK Postcode Validation, Open Featured Sets, UK Postcode Based Carrier Shipping Link to comment Share on other sites More sharing options...
candleman Posted May 8, 2007 Share Posted May 8, 2007 Sorry for hijacking this thread, but I just installed your "change default image directories" mod v1.1 on a fairly vanilla install of osc and I get the following error when clicking on the catalog link in admin Parse error: syntax error, unexpected T_CASE in /admin/categories.php on line 95 Line 95 for me is case 'delete_category_confirm': I'm don't know enough about php to know what it wrong. Thanks for any help. Currently running 76 contibutions. Link to comment Share on other sites More sharing options...
Guest Posted May 8, 2007 Share Posted May 8, 2007 Sorry for hijacking this thread, but I just installed your "change default image directories" mod v1.1 on a fairly vanilla install of osc and I get the following error when clicking on the catalog link in admin Parse error: syntax error, unexpected T_CASE in /admin/categories.php on line 95 Line 95 for me is case 'delete_category_confirm': I'm don't know enough about php to know what it wrong. Thanks for any help. you've probably missed out a closing } or something.. maybe I made a slight mistake copying the code into the text file... here's everything you should have from '$categories_image = new upload('categories_image');' to line 95: $categories_image = new upload('categories_image'); $categories_image->set_destination(DIR_FS_CATALOG_IMAGES . DIR_FS_CATEGORIES_IMAGES); if ($categories_image->parse() && $categories_image->save()) { tep_db_query("update " . TABLE_CATEGORIES . " set categories_image = '" . DIR_FS_CATEGORIES_IMAGES . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'"); } if (USE_CACHE == 'true') { tep_reset_cache_block('categories'); tep_reset_cache_block('also_purchased'); } tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories_id)); break; case 'delete_category_confirm': hope this works note: I've litterally copied and pasted this from my file Link to comment Share on other sites More sharing options...
Guest Posted May 8, 2007 Share Posted May 8, 2007 Apart from your changes my code is exactly the same. When you go to add a product with a new image and click the preview button does it hang? what do you mean by hang? When I add a new product a go to preview it takes about a second or two to load the next page, but that's all. Is it just the loading time you mean? Link to comment Share on other sites More sharing options...
psynaptic Posted May 8, 2007 Share Posted May 8, 2007 Apart from your changes my code is exactly the same. When you go to add a product with a new image and click the preview button does it hang? This is only a problem when adding a new image not already on the server. My Profile | Contribs I like most: 'On The Fly' Auto Thumbnailer, Active Countries, Header Tags Controller, Ultimate SEO URLs, UK Based osC, UK Postcode Validation, Open Featured Sets, UK Postcode Based Carrier Shipping Link to comment Share on other sites More sharing options...
psynaptic Posted May 8, 2007 Share Posted May 8, 2007 what do you mean by hang? When I add a new product a go to preview it takes about a second or two to load the next page, but that's all. Is it just the loading time you mean? It hangs for about 5 minutes, maybe more. It does work after those 5 minutes but it's a long time to wait. I can click the preview button again and it's fine but I would rather have my application in good shape that work around these little problems. My Profile | Contribs I like most: 'On The Fly' Auto Thumbnailer, Active Countries, Header Tags Controller, Ultimate SEO URLs, UK Based osC, UK Postcode Validation, Open Featured Sets, UK Postcode Based Carrier Shipping Link to comment Share on other sites More sharing options...
Guest Posted May 8, 2007 Share Posted May 8, 2007 It hangs for about 5 minutes, maybe more. It does work after those 5 minutes but it's a long time to wait. I can click the preview button again and it's fine but I would rather have my application in good shape that work around these little problems. hmm I don't know. I've just testing uploading a new image with a new product and it works straight away no problem. Maybe it's conflicting with the auto thumbnail contrib? trying to downscale it before it's uploaded or something... Link to comment Share on other sites More sharing options...
psynaptic Posted May 8, 2007 Share Posted May 8, 2007 I'm stumped. There is a stripslashes feeding a hidden field in there but I doubt that would make it hang. I wonder how one might test for this. Have you picked an image thumbnail mod yet? My Profile | Contribs I like most: 'On The Fly' Auto Thumbnailer, Active Countries, Header Tags Controller, Ultimate SEO URLs, UK Based osC, UK Postcode Validation, Open Featured Sets, UK Postcode Based Carrier Shipping Link to comment Share on other sites More sharing options...
Guest Posted May 8, 2007 Share Posted May 8, 2007 I'm stumped. There is a stripslashes feeding a hidden field in there but I doubt that would make it hang. I wonder how one might test for this. Have you picked an image thumbnail mod yet? no, I haven't looked into thumbnail mods yet.. I haven't found the need, but I might do once I start adding proper products into my shop. I'm just testing at the moment. Link to comment Share on other sites More sharing options...
psynaptic Posted May 8, 2007 Share Posted May 8, 2007 When you do find the need I recommend On-The-Fly Auto Thumbnailer ;) My Profile | Contribs I like most: 'On The Fly' Auto Thumbnailer, Active Countries, Header Tags Controller, Ultimate SEO URLs, UK Based osC, UK Postcode Validation, Open Featured Sets, UK Postcode Based Carrier Shipping Link to comment Share on other sites More sharing options...
Guest Posted May 8, 2007 Share Posted May 8, 2007 hehe thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.