I'm having some serious trouble with Opencart cache image. I have a software which synchronizes the information (products, categories) etc with Opencart.
Whenever I update a product which has already an image, I just replace (in the FTP) the image - since it has the same description (the id).
--- First upload product ---
image/myfolder/id_of_image.jpg
--- Second upload product (update) ---
image/myfolder/id_of_image.jpg -> It is replaced
--- Third upload product (update) ---
image/myfolder/id_of_image.jpg -> It is replaced
And so on. What happens is that Opencart continues with the same image set in the first sync. This is not a browser issue since different browsers shows the same first image sync.
Opencart forces the image to resize whenever opening the product page, and creates a new internal file like 19301-500x445.jpg
, depending on the image size. This only happens if the sized image doesn't exists already!
// Within the file catalog/model/tool/image
$image_old = $filename;
$image_new = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '.' . $extension;
if (!is_file(DIR_IMAGE . $image_new) || (filectime(DIR_IMAGE . $image_old) > filectime(DIR_IMAGE . $image_new)))
{
}
I can manage to avoid cache issue by setting the time()
in the filename, but by this way opencart will constantly create new images unnecessarily.
$image_new = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '-' . time() . '.' . $extension;
Deleting image/cache/myfolder/*
does no effect whatsoever.