Post by bhy » 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:

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'] = '';
                        }
The current code is:

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'));
                        }
The code that follows (AFAIK unchanged from the original OC's code):

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'))
                                );
                        }
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ň

bhy
New member

Posts

Joined
Fri Jul 17, 2015 7:28 pm

Post by straightlight » Fri Mar 06, 2020 11:08 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.
Since it is about a custom modification you are requesting about, if there are no extensions on the Marketplace that suits your needs, based on this request, you could always create a new service request in the Commercial Support section of the forum or contact me directly to get this done as a custom job.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: Google [Bot] and 309 guests