VirtueMart Forum

VirtueMart 2 + 3 => Product creation => Topic started by: 2cool on March 15, 2021, 16:43:13 pm

Title: reuse product image different file title
Post by: 2cool on March 15, 2021, 16:43:13 pm
For my shop I have lots of products using the same image with different product specifications.
Most of the time
Right now when I change 'File Title' and 'Displayed image subtitle' this is changed for all other products too.

Is it possible to have different titles and subtitles? or should I copy each image?

Regards,
Pas
Title: Re: reuse product image different file title
Post by: Jörgen on March 15, 2021, 18:50:46 pm
Should it not be possible to use two different media descriptions. But referring to the same image. Never tested.
Jörgen
Title: Re: reuse product image different file title
Post by: pinochico on March 15, 2021, 20:29:53 pm
You should copy each image, sorry
Title: Re: reuse product image different file title
Post by: 2cool on March 15, 2021, 20:37:16 pm
I was afraid of this answer :(
I normally duplicate a product and change the specifications (size and description) and use these changes also as file title and displayed image subtitle.

Is there an easy way to duplicate the images maybe?

Regards,
Pas
Title: Re: reuse product image different file title
Post by: pinochico on March 15, 2021, 20:46:53 pm
Hmm, it was good to find out how and where the information is stored
- file title
- image subtitle

I don't think they attach to the product, but to the picture.
And according to your own words, you only have it in the DB once.

But I may be wrong, I don't know exactly if you are talking about a meta title or an image title.
A screenshot would help me
Title: Re: reuse product image different file title
Post by: 2cool on March 15, 2021, 21:12:23 pm
Hi Pinochico,

This is the settings 'File Title' and 'Displayed image subtitle'
I set both to product specifications. So for example 'ill add '95x190cm white'
Correct me if i'm wrong but this is displayed beneath each product image.

Thanks,
Pas
Title: Re: reuse product image different file title
Post by: pinochico on March 15, 2021, 22:10:54 pm
In table #__virtuemart_product_medias are only:
id
virtuemart_product_id   
virtuemart_media_id
ordering

In table #__virtuemart_medias are only:
virtuemart_media_id
file_title
file_description

then all info about you wrote is connected only to medias.

If you have image in DB only one time (don't use upload button for the same image), then I have right - information are the same for the same picture.
If you need other info for image to other product, you have to upload the same image again and again for every product == you create new row in DB medias
Title: Re: reuse product image different file title
Post by: Jörgen on March 15, 2021, 22:28:28 pm
This a kind of wonky, but if You create a image media with a filename that exists You will get a new media item.
This item gets an extra extension added f.e _typeless
If You then add your image url to the media item, you will actually get two media items that point to the same image :)
In other words only one image stored on the disk, but two media items.

There must be a better way to do this, but it is actually doable.

Jörgen @ Kreativ Fotografi
Title: Re: reuse product image different file title
Post by: Studio 42 on March 16, 2021, 11:03:45 am
Nice trick Jörgen.
But a solution is perhaps to add a clone functionality for media(not possible in core for now) and call a ajax plugin for eg.
It's possible to add this button in the media list view, for eg. so you can select multiples medias
In tihs case you can use smae file.
The only problem i see, is if you update a file, only 1 record get updated with the new file.
Title: Re: reuse product image different file title
Post by: Jörgen on March 16, 2021, 12:44:32 pm
Hello Patrick

Quote
The only problem i see, is if you update a file, only 1 record get updated with the new file.

Do not really understand what You mean by update a file ? Changing  the file content, but keeping the name will still use the same file in every media item.

Do you perhaps mean changing file name for all items at once? If that is wanted, then you can just change the content of the image file.


Jörgen @ Kreativ Fotografi
Title: Re: reuse product image different file title
Post by: AH on March 16, 2021, 12:50:56 pm
Quote
For my shop I have lots of products using the same image with different product specifications.
Most of the time
Right now when I change 'File Title' and 'Displayed image subtitle' this is changed for all other products too.

Is it possible to have different titles and subtitles? or should I copy each image?

Maybe this will help - you can adapt it to get the title to be the product name etc:-

This is very common - If you have NOT added meta data for an image you can "define it on the fly" in the product/category page displaying the image by making overrides to the views

Then your image ALT will be the product name that is displaying the image:

For product pages you can do

products/default_images.php

Code: [Select]

//QUORVIA ADD ALT AS product name  IF EMPTY META
if (empty ($this->product->images[0]->file_meta)) {
$this->product->images[0]->file_meta  = $this->product->product_name;
}

and if you want to do something similar for the category browse page

in and override to sublayouts/products.php
Code: [Select]

// display thumb image
//QUORVIA ADD ALT as description IF EMPTY META
if (empty ($product->images[0]->file_meta)) {
$product->images[0]->file_meta  = $product->product_name;
}
echo $product->images[0]->displayMediaThumb('class="browseProductImage " width="150" height="150" loading="lazy"', false);
?>

Title: Re: reuse product image different file title
Post by: pinochico on March 16, 2021, 13:28:01 pm
Don't forget about east europe language (č,ř,ž,... ) or french language (') in product name or mad admin (", ¨,...), then you must use php function for product name ($product->product_name).

If you forget, then html code will be broken (alt have to only one time use "")
Title: Re: reuse product image different file title
Post by: AH on March 16, 2021, 14:41:20 pm
Good point -

Not tested on a multi-lingual site

Luckily - I do not have a multi lingual site
Title: Re: reuse product image different file title
Post by: Studio 42 on March 16, 2021, 15:01:26 pm
Hello Patrick

Quote
The only problem i see, is if you update a file, only 1 record get updated with the new file.

Do not really understand what You mean by update a file ? Changing  the file content, but keeping the name will still use the same file in every media item.

Do you perhaps mean changing file name for all items at once? If that is wanted, then you can just change the content of the image file.


Jörgen @ Kreativ Fotografi

In the product form, you can replace a image by another image.
If you do this, then the reference for other clones in media DB using this image is not updated because media id is not the same for the clones.
Do you understand better ?
Title: Re: reuse product image different file title
Post by: Jörgen on March 16, 2021, 15:49:42 pm
Yes, I think I got what you mean. Will check later.

Jörgen
Title: Re: reuse product image different file title
Post by: 2cool on March 16, 2021, 17:33:49 pm
Thanks all, makes things a lot clearer ;)

So when I duplicate a product and change this it would not work.
As Jörgen said sound kind of workable but i'm not sure how this is done...in media can I duplicate a file??

This a kind of wonky, but if You create a image media with a filename that exists You will get a new media item.
This item gets an extra extension added f.e _typeless
If You then add your image url to the media item, you will actually get two media items that point to the same image :)
In other words only one image stored on the disk, but two media items.

Thanks,
Pas