News:

Support the VirtueMart project and become a member

Main Menu

Manufacturer description on category page

Started by techrahul87, May 01, 2012, 09:38:52 AM

Previous topic - Next topic

techrahul87

hello everyone

I am using joomla 2.5 and virtuemart 2.0 .
When we create the manufacturer we save the name and description for that manufacturer.

Now if user clicks on that manufacturer it takes to the category pages where it shows different product under selected manufacturer. I want to display the description of that manufacturer in that page. Am I missing a setting or I have to just customize the code  >:(

techrahul87

no reply at all...............
hmmmmmmmmmmm.......
I have done the coding myself................it is fun :-)

usrnbe

Hello techrahul87,

would you mind posting your solution? or what you did to get it done?

regards

techrahul87

hey usrnbe..

I got the default.php of category page..
/components/com_virtuemart/views/category/tmpl/default.php

echo '<h1>'.$this->products[0]->mf_name.'</h1>';
echo '<p>'.$this->products[0]->mf_desc.'</p>';

add these lines before product for each loop... but this is not the perfect solution... it is just a quick fix....
It is only for the product which are under same manufacture.
if u get some issue please respond...

Vovchic

Quote from: techrahul87 on May 12, 2012, 09:52:01 AM
hey usrnbe..

I got the default.php of category page..
/components/com_virtuemart/views/category/tmpl/default.php

echo '<h1>'.$this->products[0]->mf_name.'</h1>';
echo '<p>'.$this->products[0]->mf_desc.'</p>';

add these lines before product for each loop... but this is not the perfect solution... it is just a quick fix....
It is only for the product which are under same manufacture.
if u get some issue please respond...

Hello, please, help me...
After using this method: while clicking on category from main menu it also appears the random manufacturer description. I don't need any manufacturer description to appear. I need manufacturer description only on the page where it shows different products under selected manufacturer. Could anybody help me to solve the problem???

Peter Pillen

#5
@vovchic

first you need to adapt your manufacturer menu module to link directly to the category view. You must first find your default manufacturer template. Then change the code which is normally found twice in this file.

file modules\mod_virtuemart_manufacturer\tmpl\default.php

<?php
$link = JROUTE::_('index.php?option=com_virtuemart&view=manufacturer&virtuemart_manufacturer_id=' . $manufacturer->virtuemart_manufacturer_id);
//change to this
$link = "index.php?option=com_virtuemart&view=category&virtuemart_category_id=&virtuemart_manufacturer_id=" . $manufacturer->virtuemart_manufacturer_id;
?>

note: I tried it before with the JROUTE, but that didn't work.

To show the manufacturer details in the category view, you need to locate your category template and add the following there where you the description to appear. I added this code after the empty keyword check.

file templates\***your template***\html\com_virtuemart\category\default.php


<?php
 
if (empty($this->keyword)) {
echo $this->category->category_description ;
//check to see if category is manufacturer --> this below is added
$jinput JFactory::getApplication()->input;
$trigger="virtuemart_manufacturer_id";
$mid $jinput->get->get($trigger);
if (!empty($mid)) {
$lang=&JFactory::getLanguage();
$dba=JFactory::getDBO();
$dba->setQuery("SELECT * FROM #__virtuemart_manufacturers_".str_replace("-","_",strtolower($lang->getTag()))." WHERE ".$trigger."=".$mid.";");
$dba->query();
$muresult=$dba->loadAssoc();
$dbb JFactory::getDBO();
$dbb->setQuery("SELECT virtuemart_media_id FROM #__virtuemart_manufacturer_medias WHERE virtuemart_manufacturer_id=".$mid.";");
$dbb->query();
$media_id $dbb->loadResult();
$dbc JFactory::getDBO();
$dbc->setQuery("SELECT file_url_thumb FROM #__virtuemart_medias WHERE virtuemart_media_id=".$media_id.";");
$dbc->query();
$file_url $dbc->loadResult();
}
}

if (!empty($file_url)) {
?>

<img src="<? echo $file_url ?>" alt="<? echo $this->category->category_name ?>" align="right" style="margin:0 25px 0 25px">
<?php 

echo 
"<h1>";
echo 
$this->category->category_name;
echo 
"</h1>";
if(!empty($muresult['mf_desc'])) {
echo $muresult['mf_desc'];
}
 ?>

<div class="clear"></div>

Vovchic

Quote from: P2 Peter on January 08, 2013, 19:50:18 PM
@vovchic

first you need to adapt your manufacturer menu module to link directly to the category view. You must first find your default manufacturer template. Then change the code which is normally found twice in this file.

file modules\mod_virtuemart_manufacturer\tmpl\default.php

<?php
$link = JROUTE::_('index.php?option=com_virtuemart&view=manufacturer&virtuemart_manufacturer_id=' . $manufacturer->virtuemart_manufacturer_id);
//change to this
$link = "index.php?option=com_virtuemart&view=category&virtuemart_category_id=&virtuemart_manufacturer_id=" . $manufacturer->virtuemart_manufacturer_id;
?>

note: I tried it before with the JROUTE, but that didn't work.

To show the manufacturer details in the category view, you need to locate your category template and add the following there where you the description to appear. I added this code after the empty keyword check.

file templates\***your template***\html\com_virtuemart\category\default.php


<?php
 
if (empty($this->keyword)) {
echo $this->category->category_description ;
//check to see if category is manufacturer --> this below is added
$jinput JFactory::getApplication()->input;
$trigger="virtuemart_manufacturer_id";
$mid $jinput->get->get($trigger);
if (!empty($mid)) {
$lang=&JFactory::getLanguage();
$dba=JFactory::getDBO();
$dba->setQuery("SELECT * FROM #__virtuemart_manufacturers_".str_replace("-","_",strtolower($lang->getTag()))." WHERE ".$trigger."=".$mid.";");
$dba->query();
$muresult=$dba->loadAssoc();
$dbb JFactory::getDBO();
$dbb->setQuery("SELECT virtuemart_media_id FROM #__virtuemart_manufacturer_medias WHERE virtuemart_manufacturer_id=".$mid.";");
$dbb->query();
$media_id $dbb->loadResult();
$dbc JFactory::getDBO();
$dbc->setQuery("SELECT file_url_thumb FROM #__virtuemart_medias WHERE virtuemart_media_id=".$media_id.";");
$dbc->query();
$file_url $dbc->loadResult();
}
}

if (!empty($file_url)) {
?>

<img src="<? echo $file_url ?>" alt="<? echo $this->category->category_name ?>" align="right" style="margin:0 25px 0 25px">
<?php 

echo 
"<h1>";
echo 
$this->category->category_name;
echo 
"</h1>";
if(!empty($muresult['mf_desc'])) {
echo $muresult['mf_desc'];
}
 ?>

<div class="clear"></div>


IT WORK'S! Thank you so much!

sandstorm

I can't get this to work properly?

I have followed the exact steps shown by P2 Peter (Thanks for your post there Peter!).

My manufacturer description shows up when view all the manufacturer products, but the Manufacturer title doesnt show until I refresh the page.
If I follow the link to my manufacturers page from my menu, from the home page. Then the title doesnt show up. 
If I follow a manufacturer link from my menu, from another manufacturer page, then the Manufacturer title does show up.

From homepage -> no title
From manufacturer page -> title is there. (refreshing page also falls into this category).
see screengrab video here of how it doesnt work for me vimeo.com/79286164

This has worked OK for me historically (though set up a slightly different way, P2 PETER's solution looks cleaner/neater), but I have recently updated from VM 2.0.18 to 2.0.22C and this seems to have broken something.
Anybody have any ideas on how to fix this/
Anybody else have this working OK in VM 2.0.22C or above?

Thanks in advance - Andy
J3.6.4 / PHP7.0.12
VM3.0.16

Peter Pillen

My code still works in 2.0.24 BUT ... in version 2.0.22 there was something not working right with the cached categoryid. In short ... your bug reminds me of problem in an earlier version. I felt that something went wrong with the variable $categoryId = ShopFunctionsF::getLastVisitedCategoryId(); in the file \components\com_virtuemart\views\category\view.html.php but it was fixed pretty soon in a later version. So updating to 2.0.24 could fix this in my opinion.

The code you see here above is still the same like I have today and I confirm it still works.


sandstorm

Thanks for your reply Peter, that helped me out!  8)
I updated to 2.0.24b in a test site and this solved the problem. So I just now swapped the file \components\com_virtuemart\views\category\view.html.php from 2.0.24b into my live 2.0.22c site and this also seems to fix the issue. So I will look to update properly soon.

On another note (& I dont really know what I'm talking about here, it was just mentioned to me by my VM template/theme developer), Is there anyway to reproduce your code here, not using the JFactory::getApplication()->input; ?
The theme/template dev thisnk we should maybe use ordinary PHP <?php echo $_GET["name"]; ?> , but like I say, I dont really know about this, just wanted to share that with you in case it helps?

Thanks again,
Andy
J3.6.4 / PHP7.0.12
VM3.0.16

Peter Pillen

Changing

$jinput = JFactory::getApplication()->input;
$trigger="virtuemart_manufacturer_id";
$mid = $jinput->get->get($trigger);

to

$mid = $_GET["virtuemart_manufacturer_id"];

... should work as well, but only if SEF is disabled. $_GET gets its information from url variables so with GET it looks in the url after "virtuemart_manufacturer_id" and returns the value if there is one. But you understand that when you enable the SEF, no "virtuemart_manufacturer_id" remains in the url and thus this code won't work anymore.

I believe I used $jinput = JFactory::getApplication()->input specifically because it fetches the original non-seffed-url even if SEF is enabled. So it works in both settings and the coding is correct Joomla usage, so it should be "updateproof" for a long while.

sandstorm

Thanks again for your response & explanation, that's helped me understand a bit better.
I use SH404SEF, so I will keep the code we are using.
Andy

Get over to #JAB14 in Germany next June & I'll make sure to buy you a beer!
J3.6.4 / PHP7.0.12
VM3.0.16

@ntonio

Hi,

Maybe anybody have a solution of this problem for VirtueMart 3?

leonardo.rueda

#13
I found a quick solution for this problem on VM 3

Go to com_virtuemart/views/categories/view.html.php

On line 487 you will find the following if statement:


      if ($virtuemart_manufacturer_id>0 and !empty($this->products['products'])){

         if (!empty($this->products['products'][0])) $title .=' '.$this->products['products'][0]->mf_name ;
         // Override Category name when viewing manufacturers products !IMPORTANT AFTER page title.
         if (!empty($this->products['products'][0]) and isset($category->category_name)) $category->category_name =  $this->products['products'][0]->mf_name  ;
             
      }



Replace with

  if ($virtuemart_manufacturer_id>0 and !empty($this->products['products'])){

         if (!empty($this->products['products'][0])) $title .=' '.$this->products['products'][0]->mf_name ;
         // Override Category name when viewing manufacturers products !IMPORTANT AFTER page title.
         if (!empty($this->products['products'][0]) and isset($category->category_name)) $category->category_name =  $this->products['products'][0]->mf_name  ;
          // Manufacturer details on category view
          echo '<h1>' . $this->products['products'][0]->mf_name . '</h1><p>' . $this->products['products'][0]->mf_desc ."</p>"   ;
      }

Notes:

-After you add this code... you will find that  the Manufacturer title and description are shown as desired.

-However, you will notice you get the Manufacturer Title twice...(Second time after manufacturer description)...for this you could either hide it with css or change this second title to something like "Manufacturer Products", like this


  if ($virtuemart_manufacturer_id>0 and !empty($this->products['products'])){

         if (!empty($this->products['products'][0])) $title .=' '.$this->products['products'][0]->mf_name ;
         // Override Category name when viewing manufacturers products !IMPORTANT AFTER page title.
         if (!empty($this->products['products'][0]) and isset($category->category_name)) $category->category_name =  $this->products['products'][0]->mf_name . "Products"  ;
          // Manufacturer details on category view
          echo '<h1>' . $this->products['products'][0]->mf_name . '</h1><p>' . $this->products['products'][0]->mf_desc ."</p>"   ;
      }


-Manufacturer's additional info will not show on a simple category view page, witch is nice.

I do have a final Question: Is there a way to save this file in a way that is not over written once VM is updated to a new version?

I hope someone finds this useful.

Ghost

Your VM or template is outdated because current VM version already shows manufacturer description.

To answer your question, yes, there is a way. Create a template override instead of editing the view.