Remove auto-added placeholder image when an image is inserted in administration
Posted: Fri Mar 06, 2020 10:03 pm
Hello, I'm not sure if this belongs here, as it concerns a custom modification that is not an official extension. I'd be happy if you can help me.
The OC version is 2.0.2.0. We are using an import script that downloads product images from an image provider. In case the image is not available from the provider, a placeholder image with a "we are sorry" kind of message is used instead. If the placeholder image is used, it is always the main image. It's not possible to change that in the administration. We would like to be able to override the placeholder image by adding an image in the administration.
The insertion of the placeholder image is called from catalog/controller/product/product.php
The original OC code that we replaced was:
The current code is:
The code that follows (AFAIK unchanged from the original OC's code):
I suppose the reason why the placeholder.jpg is always the main image (when there is no external image) is that the $data['images'] = array(); is called after the placeholder.jpg is inserted. I would need to update our current code to include something from the code that follows, in order to make it possible to replace the placeholder.jpg from the administration. But my PHP "skills" are not good enough for that. Could you give me a hint?
Thank you very much
Petr Břeň
The OC version is 2.0.2.0. We are using an import script that downloads product images from an image provider. In case the image is not available from the provider, a placeholder image with a "we are sorry" kind of message is used instead. If the placeholder image is used, it is always the main image. It's not possible to change that in the administration. We would like to be able to override the placeholder image by adding an image in the administration.
The insertion of the placeholder image is called from catalog/controller/product/product.php
The original OC code that we replaced was:
Code: Select all
if ($product_info['image']) {
$data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
} else {
$data['popup'] = '';
}
if ($product_info['image']) {
$data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
} else {
$data['thumb'] = '';
}
Code: Select all
if ($product_info['external_img'] && !in_array($product_info['external_img'], $this->externalImgInternalStrings)) {
$data['popup'] = $product_info['external_img'];
//$data['thumb'] = $this->model_tool_image->resize($product_info['downloaded_img'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
$data['thumb'] = $product_info['external_img'];
} else {
$data['popup'] = $this->model_tool_image->resize('placeholder.jpg', $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
$data['thumb'] = $this->model_tool_image->resize('placeholder.jpg', $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
}
Code: Select all
$data['images'] = array();
$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
//$results = array();
foreach ($results as $result) {
$data['images'][] = array(
'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
);
}
Thank you very much
Petr Břeň