News:

Support the VirtueMart project and become a member

Main Menu

Category image as Product image if image is not available

Started by eriksimonx, October 17, 2012, 14:27:15 PM

Previous topic - Next topic

eriksimonx

Hi!

I want to use the Category's image instead of the noimage.gif, when virtuemart can't find an available product picture. Which file contains the solution? Thanks!

bytelord

Hello,

You could hack the core to accomplish it. The file you are searching for is your_joomla_folder\administrator\components\com_virtuemart\helpers\image.php
Alternative you could do it by overriding your template files, i suppose, but never test it to be honest. Something like if empty product images and not empty this category image show category media-thumb.

Just a suggestion, if you need help let us know (you need it for category, flypage and product details page?).

btw, it will be a nice feature to be configured from the back end.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

eriksimonx

Hi,

Thanks for your response. I couldn't make it work with hack the helpers/image.php. Now, I trying to edit the components/com_virtuemart/views/category/tmpl/default.php.

But when I change something here:

      // Show Products ?>
      <div class="product floatleft<?php echo $Browsecellwidth . $show_vertical_separator ?>">
         <div class="spacer">
            <div class="width30 floatleft center">
               <?php /** @todo make image popup */
                     echo $product->images[0]->displayMediaThumb('class="browseProductImage" border="0" title="'.$product->product_name.'" ',true,'class="modal"');

The whole category's page will looks like css-less, and the products will disappear too. Please help, what and how should I change?

Guess something like that:

               if empty product image then category->images else
                                                    echo $product->images[0]->displayMediaThumb.......

Thanks,
Erik

bytelord

Hello,

Sorry for taking too long to reply. Because $product->images[0] is not empty so the "if" statement to works need a trick with image->file_name (or file_title, or something else that is empty), so the following code will check if product->image[0]->file_name is not empty, if is not empty will show the product image else will show the category image. The following is for category view. Around line 238, replace with the following code:


<?php /** @todo make image popup - v1*/
if (!empty($product->images[0]->file_name)) {
   echo $product->images[0]->displayMediaThumb ('class="browseProductImage" border="0" title="' $product->product_name '" 'TRUE'class="modal"');
} else {
   echo $this->category->images[0]->displayMediaThumb (""FALSE);
}
?>


if you want modal pop up with category image place the following code:

<?php /** @todo make image popup - v2*/
if (!empty($product->images[0]->file_name)) {
echo $product->images[0]->displayMediaThumb ('class="browseProductImage" border="0" title="' $product->product_name '" 'TRUE'class="modal"');
} else {
echo $this->category->images[0]->displayMediaThumb ('class="browseProductImage" border="0" title="' $product->product_name '" 'TRUE'class="modal"');
}
?>


Test it with 2012d and works fine.

Hope it helps you out!

btw, this will be a nice feature to be implemented on the backend, so selecting no-image to be available the following selection:
1. noimage.gif (custom image)
2. No image at all (nothing, only text)
3. Category image (category image)

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

bytelord

Please make a template override and don't edit the original files.

Some more information about template system & template overrides:

Creating Template overrides: https://forum.virtuemart.net/index.php?topic=98505.0
Template System: https://dev.virtuemart.net/projects/virtuemart/wiki/Hints_for_the_use_of_the_template_system

Also

Use firebug to examine you site code and css styling: https://forum.virtuemart.net/index.php?topic=102850.0

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

gpessoa

Quote from: bytelord on October 20, 2012, 13:40:19 PM

btw, this will be a nice feature to be implemented on the backend, so selecting no-image to be available the following selection:
1. noimage.gif (custom image)
2. No image at all (nothing, only text)
3. Category image (category image)



If you can apply that also to Manufactures, step 1 and 2 it will be great
J 3.10.5; VM 3.4.2; PHP 7.2.34

bytelord

Hello,

Just suggest some features for the backend, but what exactly you wanna do with manufactures? You mean the page template or the module?

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

gpessoa

I mean that in manufacturers, it should be also available:
1. noimage.gif (custom image) - (already On)
2. No image at all (nothing, only text) - (New feature)
J 3.10.5; VM 3.4.2; PHP 7.2.34

bytelord

Hello,

Normally the options will be global, so will effect everywhere. Because that feature does not exist you can easily use the above structure to exclude no image to preview... (no else, just an if)

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

eriksimonx

#9
Quote from: bytelord on October 20, 2012, 13:40:19 PM
Hello,

Sorry for taking too long to reply. Because $product->images[0] is not empty so the "if" statement to works need a trick with image->file_name (or file_title, or something else that is empty), so the following code will check if product->image[0]->file_name is not empty, if is not empty will show the product image else will show the category image. The following is for category view. Around line 238, replace with the following code:


<?php /** @todo make image popup - v1*/
if (!empty($product->images[0]->file_name)) {
   echo $product->images[0]->displayMediaThumb ('class="browseProductImage" border="0" title="' $product->product_name '" 'TRUE'class="modal"');
} else {
   echo $this->category->images[0]->displayMediaThumb (""FALSE);
}
?>


if you want modal pop up with category image place the following code:

<?php /** @todo make image popup - v2*/
if (!empty($product->images[0]->file_name)) {
echo $product->images[0]->displayMediaThumb ('class="browseProductImage" border="0" title="' $product->product_name '" 'TRUE'class="modal"');
} else {
echo $this->category->images[0]->displayMediaThumb ('class="browseProductImage" border="0" title="' $product->product_name '" 'TRUE'class="modal"');
}
?>


Test it with 2012d and works fine.

Hope it helps you out!

btw, this will be a nice feature to be implemented on the backend, so selecting no-image to be available the following selection:
1. noimage.gif (custom image)
2. No image at all (nothing, only text)
3. Category image (category image)

Regards


Thank you, very much!
One more thing, It's working on Category page and on the Product details page, but I have activated the breadcrumbs module and I want to reach the same results with the product images in that too. Maybe I'm wrong, but I guess the solution is somewhere in the mediahandler.php.

Thanks, again!

bytelord

Hello,

Switch breadcrumbs module are you referring? any Example, screenshot?

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

eriksimonx

#11
Oh sorry, I mean Featured products module, which is set to display random products from the self category!

Thanks!

bytelord

Hello,

For this one to work we have to call the category model. The following code could be used inside default.php template of products module. You could create an override for that one by copying the file:
your_joomla_folder\modules\mod_virtuemart_product\tmpl\default.php

to

your_joomla_folder\templates\your_joomla_template\html\mod_virtuemart_product\default.php

Edit the file (keep in mind that product images used twice in the module, one for div based and one for list) ... So you will find the following lines:

if (!empty($product->images[0])) {
$image = $product->images[0]->displayMediaThumb ('class="featuredProductImage" border="0"', FALSE);
} else {
$image = '';
}


Replace with those lines:

if (!empty($product->images[0]->file_name)) {
$image = $product->images[0]->displayMediaThumb ('class="featuredProductImage" border="0"', FALSE);
} else {
$categoryModel = VmModel::getModel('category');
$category = $categoryModel->getCategory($product->virtuemart_category_id);
$categoryModel->addImages($category,1);
$image= $category->images[0]->displayMediaThumb ('class="featuredProductImage" border="0"', FALSE);
}


even better you could load the lines that we bring the model only one time at the start of the code.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

eriksimonx

Thank you very,very much! Now, all of my problems are solved!

bytelord

Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!