Forums / All Other Contributions/Addons / how to prevent image from being deleted when a product is deleted?

how to prevent image from being deleted when a product is deleted?

Views: 1,576

Results 1 to 8 of 8
7 Mar 2013, 2:59 AM
#1
denniszc avatar

denniszc

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

7 Mar 2013, 3:08 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: how to prevent image from being deleted when a product is deleted?

To my knowledge, the image is not deleted when the associated product is deleted

Zen-Venom Get Bitten

7 Mar 2013, 3:32 AM
#3
denniszc avatar

denniszc

New Zenner

Join Date:
Mar 2013
Posts:
95
Plugin Contributions:
0

Re: how to prevent image from being deleted when a product is deleted?

it was deleted in mine, i just tested it using the admin.

7 Mar 2013, 3:35 AM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: how to prevent image from being deleted when a product is deleted?

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 ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

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!

7 Mar 2013, 3:47 AM
#5
denniszc avatar

denniszc

New Zenner

Join Date:
Mar 2013
Posts:
95
Plugin Contributions:
0

Re: how to prevent image from being deleted when a product is deleted?

which code should i customize and which part?

7 Mar 2013, 4:01 AM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: how to prevent image from being deleted when a product is deleted?

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 ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

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!

7 Mar 2013, 8:28 AM
#7
denniszc avatar

denniszc

New Zenner

Join Date:
Mar 2013
Posts:
95
Plugin Contributions:
0

Re: how to prevent image from being deleted when a product is deleted?

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.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

thanks, it worked like a charm
7 Mar 2013, 2:01 PM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: how to prevent image from being deleted when a product is deleted?

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 ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

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!