New Zenner
- Join Date:
- Mar 2013
- Posts:
- 95
- Plugin Contributions:
- 0
how to prevent image from being deleted when a product is deleted?
is there a way to prevent this? im on zen cart 1.5.x
Views: 1,576
New Zenner
is there a way to prevent this? im on zen cart 1.5.x
Black Belt
To my knowledge, the image is not deleted when the associated product is deleted
Zen-Venom Get Bitten
New Zenner
it was deleted in mine, i just tested it using the admin.
Oba-san
The image is deleted when a Product is deleted if that image is not used by another Product ...
About the only way to change this, without customizing the code, would be to change the image on the Product before deleting it with an image you do not care about ... then when the image is deleted it does not matter ...
If you really need the image after deleting the Product, you could always just FTP that image back to the server ...
Linda McGrath
If you have to think ... you haven't been zenned ...
Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here
Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!
New Zenner
which code should i customize and which part?
Oba-san
To prevent the deletion of a Product from deleting the image(s) for it you would have to edit the file:
/your_secret_admin/includes/functions/general.php
and add the code in RED around line 1362:
function zen_remove_product($product_id, $ptc = 'true') {
global $db;
$product_image = $db->Execute("select products_image
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$product_id . "'");
$duplicate_image = $db->Execute("select count(*) as total
from " . TABLE_PRODUCTS . "
where products_image = '" . zen_db_input($product_image->fields['products_image']) . "'");
[B]// ===============
// =============== CODE CHANGED: TURN OFF DELETION OF IMAGES WHEN PRODUCTS ARE DELETED
// ===============
[/B] if ([B]false && [/B]$duplicate_image->fields['total'] < 2 and $product_image->fields['products_image'] != '' && PRODUCTS_IMAGE_NO_IMAGE != substr($product_image->fields['products_image'], strrpos($product_image->fields['products_image'], '/')+1)) {
NOTE: Making this change means the images will NEVER be deleted from the server unless you manually delete them
Linda McGrath
If you have to think ... you haven't been zenned ...
Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here
Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!
New Zenner
Ajeh:
To prevent the deletion of a Product from deleting the image(s) for it you would have to edit the file:
/your_secret_admin/includes/functions/general.phpand add the code in RED around line 1362:
function zen_remove_product($product_id, $ptc = 'true') {
global $db;
$product_image = $db->Execute("select products_image
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$product_id . "'");
$duplicate_image = $db->Execute("select count(*) as total
from " . TABLE_PRODUCTS . "
where products_image = '" . zen_db_input($product_image->fields['products_image']) . "'");
[B]// ===============
// =============== CODE CHANGED: TURN OFF DELETION OF IMAGES WHEN PRODUCTS ARE DELETED
// ===============
[/B] if ([B]false && [/B]$duplicate_image->fields['total'] < 2 and $product_image->fields['products_image'] != '' && PRODUCTS_IMAGE_NO_IMAGE != substr($product_image->fields['products_image'], strrpos($product_image->fields['products_image'], '/')+1)) {
>
>
> NOTE: Making this change means the images will NEVER be deleted from the server unless you manually delete them
thanks, it worked like a charm
Oba-san
Thanks for the update that this worked for you to prevent Product Images from being deleted from the server when you deleted Products ... :smile:
Be sure you do periodic maintenance on the server for images that are no longer needed or they will build up over time ...
Linda McGrath
If you have to think ... you haven't been zenned ...
Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here
Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!
Tell staff why this post should be reviewed.