WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Bakery Shop => Topic started by: Boudi on April 01, 2015, 03:18:28 PM

Title: Bug: Image error in duplicating product
Post by: Boudi on April 01, 2015, 03:18:28 PM
Hi,

Noticed an annoying bug in Bakery 1.71:

Create a product and upload image
Click SAVE
DUPLICATE product
Click SAVE
Change title
Set Online view to ON
Check box to delete image and search/fill the new image to upload
Click SAVE

Bug: the image from the previous product is gone. Both in backend/frontend. Re-upload the image is not possible because the image itself is still in the Media dir.

So the only workaround for now is delete all the Media ID files, reupload the pictures and do NOT duplicate products but create them one by one.

Tested on 2 different setups on different servers.

Boudi
Title: Re: Bug: Image error in duplicating product
Post by: freeSbee on April 01, 2015, 07:00:01 PM
Hi Boudi

Thanks for your bug report and the accurate description of what you have done. It helped me a lot to locate the bug.

Quick fix. Search the file save_item.php (about line 297) for:
Code: [Select]
// Delete image if requested
foreach ($images as $image) {
if ($image['delete_image'] !== false) {
$img_file = $image['delete_image'];
// Thumbs use .jpg extension only
$thumb_file = str_replace (".png", ".jpg", $img_file);
// Try unlinking image and thumb
if (file_exists(WB_PATH.MEDIA_DIRECTORY.'/bakery/images/item'.$item_id.'/'.$img_file)) {
unlink(WB_PATH.MEDIA_DIRECTORY.'/bakery/images/item'.$item_id.'/'.$img_file);
}
if (file_exists(WB_PATH.MEDIA_DIRECTORY.'/bakery/thumbs/item'.$item_id.'/'.$thumb_file)) {
unlink(WB_PATH.MEDIA_DIRECTORY.'/bakery/thumbs/item'.$item_id.'/'.$thumb_file);
}
// Delete image in database
$database->query("DELETE FROM ".TABLE_PREFIX."mod_bakery_images WHERE `filename` = '$img_file'");
// Check if there was a db error
if ($database->is_error()) {
$errors[] = $database->get_error();
}
}
}

Replace by:
Code: [Select]
// Delete image if requested
foreach ($images as $img_id  => $image) {
if ($image['delete_image'] !== false) {
$img_file = $image['delete_image'];
// Thumbs use .jpg extension only
$thumb_file = str_replace (".png", ".jpg", $img_file);
// Try unlinking image and thumb
if (file_exists(WB_PATH.MEDIA_DIRECTORY.'/bakery/images/item'.$item_id.'/'.$img_file)) {
unlink(WB_PATH.MEDIA_DIRECTORY.'/bakery/images/item'.$item_id.'/'.$img_file);
}
if (file_exists(WB_PATH.MEDIA_DIRECTORY.'/bakery/thumbs/item'.$item_id.'/'.$thumb_file)) {
unlink(WB_PATH.MEDIA_DIRECTORY.'/bakery/thumbs/item'.$item_id.'/'.$thumb_file);
}
// Delete image in database
$database->query("DELETE FROM ".TABLE_PREFIX."mod_bakery_images WHERE `img_id` = '$img_id'");
// Check if there was a db error
if ($database->is_error()) {
$errors[] = $database->get_error();
}
}
}


Regards Christoph
Title: Re: Bug: Image error in duplicating product
Post by: Boudi on April 01, 2015, 10:32:43 PM
Allright, thnx  :-)

Test it out tomorrow :)
Title: Re: Bug: Image error in duplicating product
Post by: Boudi on April 02, 2015, 09:46:36 AM
Update:

Bug has gone so happy. :-)

Good idea to implement this in an upgrade.

Again, thnx for your quick respond and solution.

Rgdz

Boudi