Post by Opencart-Hellas » Fri Mar 01, 2013 12:31 am

There is an issue at the administration backend when a product does not have an image assigned, the "no_image.jpg" is not showing at the front end. What happens is that the script assigns nothing ' ' instead of "no_image.jpg". This behavior exists even in the latest version v1.5.5.1. Here is a simple fix if someone is interested (The fix is not applied to any additional images, cause in this case, the behavior of not showing anything is needed).

What it does:
At product's create/edit page, in Data TAB, at image filemanager, you get 3 buttons:
(Browse Files | Clear Image | no_image.jpg)

The default behaviour now is to assign no_image.jpg, if no image is assigned manually. If Clear Image is pressed it assigns nothing (as it was by default).

Attachments

no image fix 1.1


Opencart-Hellas.gr - Η Ελληνική κοινότητα του Opencart
Πλήρης Ελληνική μετάφραση OpenCart


User avatar
Active Member

Posts

Joined
Fri Jul 27, 2012 5:30 am
Location - Athens, Hellas

Post by matt71 » Fri Mar 15, 2013 1:18 am

This is an interesting concept as I have been looking for a fix to this problem that will work with 1.5.4.1. However, for those of us that use an upload tool (such as Total Import Pro), this isn't an ideal solution. Isn't there some sort of way to just automatically reference the no_image.jpg when a picture is missing? Then, when the picture is added, it is replaced automatically?

Thanks for your help.

Matt

New member

Posts

Joined
Sat Jan 19, 2013 4:13 am

Post by Opencart-Hellas » Fri Mar 15, 2013 2:58 am

Isn't there some sort of way to just automatically reference the no_image.jpg when a picture is missing? Then, when the picture is added, it is replaced automatically?
It could be done easily, but it would require modding a lot of files. A better and cleaner way to do it, is to ask the developer of the import extension you use, to add a couple of lines of code to implement the logic you require.

Opencart-Hellas.gr - Η Ελληνική κοινότητα του Opencart
Πλήρης Ελληνική μετάφραση OpenCart


User avatar
Active Member

Posts

Joined
Fri Jul 27, 2012 5:30 am
Location - Athens, Hellas

Post by lee420 » Fri Aug 30, 2013 5:14 pm

matt71 wrote:This is an interesting concept as I have been looking for a fix to this problem that will work with 1.5.4.1. However, for those of us that use an upload tool (such as Total Import Pro), this isn't an ideal solution. Isn't there some sort of way to just automatically reference the no_image.jpg when a picture is missing? Then, when the picture is added, it is replaced automatically?

Thanks for your help.

Matt
I am also after something like this. I have imported approx 10,000 products with the part number as the image name. When I sort out the images and upload them to my server they will just show up without having to go through each product.
In the meantime whilst there is no image I would like to have the default no-image to be displayed.
Can any body help?

Newbie

Posts

Joined
Tue Apr 10, 2012 7:35 am

Post by Opencart-Hellas » Fri Aug 30, 2013 8:56 pm

What you are asking is the opposite to the above fix. That is, to assign the "no_image" file at catalog pages where no image file can be found yet. Later, if the file exists, it will show up.
You can implement it at a global level in catalog/model/tool/image.php or in specific areas at the template level.

A) Global method
You can edit line 16 in catalog/model/tool/image.php
Change this:

Code: Select all

			return;
To this:

Code: Select all

//return;
$filename = "data/no_image.jpg";
Adjust path and file name to where your actual "no_image" pic resides, and no image is applied everywhere.
(In the above example "no_image.jpg" resides inside "image/data/" folder. If it resides in "image" folder, omit the "data" path.)

B) Template method
This is also easy to implement but the actual code implementation depends on your template ...
This example illustrates how it could be done in the default theme of Opencart 1.5.5.1 at product's page
Open catalog/view/theme/default/template/product/product.tpl

You modify the line 23 of the following code:

Code: Select all

    <?php if ($thumb || $images) { ?>
    <div class="left">
      <?php if ($thumb) { ?>
      <div class="image"><a href="<?php echo $popup; ?>" title="<?php echo $heading_title; ?>" class="colorbox"><img src="<?php echo $thumb; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" id="image" /></a></div>
      <?php } ?>
      <?php if ($images) { ?>
      <div class="image-additional">
        <?php foreach ($images as $image) { ?>
        <a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="colorbox"><img src="<?php echo $image['thumb']; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" /></a>
        <?php } ?>
      </div>
      <?php } ?>
    </div>
    <?php } ?>
Line 23 is the the last line of the above code.

Code: Select all

<?php } ?>
This line becomes:

Code: Select all

<?php } else { ?> 
    <div class="left">
<div class="image"><img src="image/data/no_image.jpg" title="No Image" alt="No Image" id="image" style="width:228px;height:228px;" /></a></div>
    </div>
      <?php } ?>
At the above code adjust the image file name, path, widht/height according to your needs.
Similar code can be added to any other template files you require the same behaviour.

Opencart-Hellas.gr - Η Ελληνική κοινότητα του Opencart
Πλήρης Ελληνική μετάφραση OpenCart


User avatar
Active Member

Posts

Joined
Fri Jul 27, 2012 5:30 am
Location - Athens, Hellas

Post by lee420 » Fri Sep 06, 2013 2:41 am

Thanks for the reply. After posting I found this by Jay and it seems to do the job. Similar to your method A. Replacing the same line as your code

Code: Select all

if(file_exists(DIR_IMAGE . 'no_image.jpg')) {
				$filename = 'no_image.jpg';
			} else {
				$filename = 'no_image.png';
			}

Newbie

Posts

Joined
Tue Apr 10, 2012 7:35 am

Post by Opencart-Hellas » Fri Sep 06, 2013 3:22 am

Thanks for the reply. After posting I found this by Jay and it seems to do the job. Similar to your method A. Replacing the same line as your code
Whatever you makes you happy ... the outcome of both approaches is exactly the same. The code you posted just adds another check whether the file name 'no_image.jpg' exists, otherwise it assigns 'no_image.png' . This is an overkill since you are the one doing the mod and you already know the file's name and that it exists.

Opencart-Hellas.gr - Η Ελληνική κοινότητα του Opencart
Πλήρης Ελληνική μετάφραση OpenCart


User avatar
Active Member

Posts

Joined
Fri Jul 27, 2012 5:30 am
Location - Athens, Hellas

Post by CZechBoY » Fri Sep 06, 2013 7:49 am

cannot you set up the default value of column in database?

Mass update product descriptions/Hromadná změna popisků zboží


User avatar
Active Member

Posts

Joined
Mon Mar 19, 2012 1:39 am
Location - Europe, Czech republic; Hradec Králové, Brno

Post by Opencart-Hellas » Fri Sep 06, 2013 9:23 pm

cannot you set up the default value of column in database?
You could do that if you like, but its messy and you still have to edit OpenCart's code.

First you change the default value of image column to "no_image.jpg" at the database structure.
Then you have to change the way the model checks for the image file. Otherwise it will override your default database setting with empty.

in admin/model/catalog/product.php:8

Change this:

Code: Select all

		if (isset($data['image'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8')) . "' WHERE product_id = '" . (int)$product_id . "'");
		}
To this:

Code: Select all

		if (isset($data['image']) && $data['image'] != false) {
			$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8')) . "' WHERE product_id = '" . (int)$product_id . "'");
		}

Opencart-Hellas.gr - Η Ελληνική κοινότητα του Opencart
Πλήρης Ελληνική μετάφραση OpenCart


User avatar
Active Member

Posts

Joined
Fri Jul 27, 2012 5:30 am
Location - Athens, Hellas

Post by CZechBoY » Fri Sep 06, 2013 10:31 pm

what about !empty? :)
does not mysql write default value if the column is set to null?

Mass update product descriptions/Hromadná změna popisků zboží


User avatar
Active Member

Posts

Joined
Mon Mar 19, 2012 1:39 am
Location - Europe, Czech republic; Hradec Králové, Brno

Post by Opencart-Hellas » Fri Sep 06, 2013 11:07 pm

what about !empty? :)
Sure, that works too.
does not mysql write default value if the column is set to null?
Yes, but the above code actually produces empty, and not null, if an image is not set (I edited my last post to reflect this).

Opencart-Hellas.gr - Η Ελληνική κοινότητα του Opencart
Πλήρης Ελληνική μετάφραση OpenCart


User avatar
Active Member

Posts

Joined
Fri Jul 27, 2012 5:30 am
Location - Athens, Hellas
Who is online

Users browsing this forum: No registered users and 6 guests