VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: kittmaster on September 17, 2015, 03:22:30 AM

Title: [Solved] I have a 90K product issue with whitespace......
Post by: kittmaster on September 17, 2015, 03:22:30 AM
I'm using an automated script to create the file names and I just found a critical error in it. Here is an example of my media file name:

14100XPERCENTXOFXDISINXXYOUXARMANDOX127X1992X7311360X1327634828X1309729597X226-FRONT COVER_90x90.jpg

As you can see "FRONT COVER" has a space which I forgot to use an underscore or hyphen in the name.

Here is the code I'm using for the thumbnail creation:



<?php 
                $db 
JFactory::getDbo(); 
                
$db->setQuery('SELECT m.file_url_thumb FROM #__virtuemart_product_medias pm,#__virtuemart_medias m WHERE (pm.virtuemart_product_id='.$item->virtuemart_product_id.')AND(pm.virtuemart_media_id=m.virtuemart_media_id)'); 
                
$res $db->LoadResult(); 
echo "<img src=\"$res\">";
?>




What I'm getting is:

htxp://wxw.mysite.blah/14100XPERCENTXOFXDISINXXYOUXARMANDOX127X1992X7311360X1327634828X1309729597X226-FRONT

because of the space breaking the link image.

Anyone have a way to reparse the file path to deal with the space in it? There is no way in the world I can redo all the products and media because it will break my previous invoices and history order etc.

I need to find a way to deal with this but not sure how to handle it.

Can anyone provide some guidance on how to retool this?

Thanks in advance.

Chris

Title: Re: I have a 90K product issue with whitespace......
Post by: balai on September 17, 2015, 09:31:41 AM
Why don't you run an update query for that table?
Title: Re: I have a 90K product issue with whitespace......
Post by: kittmaster on September 17, 2015, 14:46:13 PM
Because all of the file names have the space so it would still be a mismatch.
Title: Re: I have a 90K product issue with whitespace......
Post by: balai on September 17, 2015, 16:34:05 PM
Try to encode the src
http://php.net/manual/en/function.urlencode.php
Title: Re: I have a 90K product issue with whitespace......
Post by: kittmaster on September 17, 2015, 17:41:48 PM
That worked great, took a minute to figure out the best way to do it, but this is my solution and it works great. This is being used in a template override so it can't be overwritten by the core updates.


<td align="left" colspan="2" >
<?php 
                $db 
JFactory::getDbo(); 
                
$db->setQuery('SELECT m.file_url_thumb FROM #__virtuemart_product_medias pm,#__virtuemart_medias m WHERE (pm.virtuemart_product_id='.$item->virtuemart_product_id.')AND(pm.virtuemart_media_id=m.virtuemart_media_id)'); 
                
$res $db->LoadResult();
rawurlencode('$res');
                echo 
"<img src=\"http://www.test.example.com/$res\">";
//echo "<img src=\"$res\">"; // Original parse from another virtuemart 2 thread
?>

</td>


Thanks for the pointer and the help.

Chris