VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Coding Central => Topic started by: jgm196 on May 12, 2014, 21:18:12 PM

Title: Media Categories in email
Post by: jgm196 on May 12, 2014, 21:18:12 PM
Hi, I´m trying to develop a plugin to send category information by email. The email is sent automatically with a cron.

I´m getting all the categories informatión using the category model and the function getChildCategoryList. But all the information about media isn´t sending. So I think that the problem is that this code isn´t working:

if(!empty($childList)){
         if(!class_exists('TableCategory_medias'))require(JPATH_VM_ADMINISTRATOR.DS.'tables'.DS.'category_medias.php');
         foreach($childList as $child){
            $xrefTable = new TableCategory_medias($db);
            $child->virtuemart_media_id = $xrefTable->load($child->virtuemart_category_id);
         }
      }

I don´t know if the problem is that if I`m doing this without being signed in, I can´t access to the table category_medias.

Is there any way to get the image thumbnail of a category with a SQL query? How can I get the image resized of a category?

thanks
Title: Re: Media Categories in email
Post by: GJC Web Design on May 12, 2014, 22:36:17 PM
if it just a once a seldom run cron there's no problem in just using normal queries

either get a cat-> media mapping from jos_virtuemart_category_medias then loop thru and get the media from jos_virtuemart_medias  or if your a bit of a sql guru a JOIN query to do it in less queries
Title: Re: Media Categories in email
Post by: jgm196 on May 13, 2014, 00:50:11 AM
Thanks for your reply,

I know that I can get the file name from the table virtuemart_medias using a SQL query, but if I do that, I only get the file name of the image. If I send my email without using cron (from the backend, being logged in), every works fine, but if I use cron my categories don´t have any information about media. As I said before, I think that there is a problem with this part of code in my category model:

if(!empty($childList)){
         if(!class_exists('TableCategory_medias'))require(JPATH_VM_ADMINISTRATOR.DS.'tables'.DS.'category_medias.php');
         foreach($childList as $child){
            $xrefTable = new TableCategory_medias($db);
            $child->virtuemart_media_id = $xrefTable->load($child->virtuemart_category_id);
         }
      }

If I send the email from the backend,  the helpers (mediahandler.php)(image.php)seems to work and I get al this information:

[file_url_folder] => images/stories/virtuemart/category/
[file_path_folder] => images/stories/virtuemart/category/
[file_url_folder_thumb] => images/stories/virtuemart/category/resized/
[file_name_thumb] => category1_280x165 ) ),
[file_url_thumb] => images/stories/virtuemart/category/resized/category1_280x165.png
[file_url] => images/stories/virtuemart/category/category1.png )

So, how can I get all this information about paths and thumbs using a query  or how can I modify my code to get it works?
Title: Re: Media Categories in email
Post by: Milbo on May 13, 2014, 01:15:02 AM
Use the function in vmmodel. There it is "explained".
Title: Re: Media Categories in email
Post by: jgm196 on May 13, 2014, 01:27:59 AM
My problem is that I can´t get any media_id from categories. So, if a don´t have any media_id I can´t use the function addImages inside vmmodel.

Additional information:

I´ve just try using categoryModel->getCategory, and it works, so this code is working:

$xrefTable = $this->getTable('category_medias');
$this->_data->virtuemart_media_id = $xrefTable->load((int)$this->_id);

And the code inside getCategorychildlist, don´t:

if(!empty($childList)){
         if(!class_exists('TableCategory_medias'))require(JPATH_VM_ADMINISTRATOR.DS.'tables'.DS.'category_medias.php');
         foreach($childList as $child){
            $xrefTable = new TableCategory_medias($db);
            $child->virtuemart_media_id = $xrefTable->load($child->virtuemart_category_id);
         }
      }

Any idea?
Title: Re: Media Categories in email
Post by: Milbo on May 13, 2014, 02:00:39 AM
Actually your code should work, hmm