Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Different Module for Each Virtuemart Category

Different Module for Each Virtuemart Category

I went onto the VirtueMart forum to find out how I could have a different module for each category in my shop. Someone said to try this MetaMod Module. I downloaded it and have had a look. I still can't work this out though.

It provides me only with the available module names. So it will say VirtueMart, but not the different categories.

I see there is a block at the bottom which asks me to insert PHP code.. However, none of their examples provide what I am looking for as a solution. For example, there is nothing there that specifies "if Category = x" then show Y..

Also, another problem I seem to be facing is that the module that needs to be displayed on each individual category page in Virtuemart is an image.. In the past, I would have used the Custom HTML module.. With MetaMod, I do not see a spot to even include the code for the image..

Its only 7am here now.. Maybe i'm still sleeping? Am I missing something? smile

CreativeDesigns
Junior Modder
ranks
useravatar
Offline
24 Posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Hi,

Thanks for taking the time to ask the question on the forum. I'm sure we can get you up to speed quickly.

To deal with VirtueMart we'll need to construct a little bit of PHP code. Don't worry, it's not much and it should be pretty easy to understand.

If this is your first time with MetaMod, please read the Quick Start guide. This will help you to understand the basics of how it works:

http://www.metamodpro.com/metamod/quick-start

I'm not sure if you found the "Recipes" page for VirtueMart, but this page has lots of different examples of things you can do:

http://www.metamodpro.com/metamod/recip … mart-pages

In particular, you might want to look at this recipe on that page:

"Display a certain module only on browse pages, with a different module for each category"


The usual method of using MetaMod is that you create your other modules as usual, but then use MetaMod to selectively include/display any of the other modules depending on the conditions that you code, e.g. VM category.

So generally you would create a bunch of Custom HTML modules, assign each of them to "None" menu items (see the Quick Start guide to find out why), then create a MetaMod in the position where you want the other modules to appear. Then write the PHP code to selectively include the other modules, or none.

In your case however, you say that all you want to do is to show an image. In this case you don't really need to create all those other modules (unless you really want to). You can choose to just output HTML directly from the PHP box in MetaMod. You can utilise all the same sorts of conditional statements that you would use if you were including modules.

So, something like this:

$vm = JomGenius("virtuemart");
$catid = $vm->info("category_id"); // on browse pages or product detail pages
$img = "";
if ($catid == 40) $img = "foo.jpg";
if ($catid == 41) $img = "bar.jpg";
if ($catid == 42) $img = "wombat.jpg";
// ... add more as appropriate
if ($img != "") {
  // customise path as appropriate for your site
  echo '<img src="/images/stories/vm/' . $img . '" />';
}


If you just want to name your images with the category id number (e.g. 45.jpg) then it's even easier:

$vm = JomGenius("virtuemart");
$catid = (int)$vm->info("category_id"); // on browse pages or product detail pages
if ($catid != 0) {
  // customise path as appropriate for your site
  echo '<img src="/images/stories/vm/' . $catid . '.jpg" />';
}

Of course, you then need an image for every single category, otherwise there will be some broken images on the page.


Hope that gets you started,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Hi Stephen,
Thank you so much for your post. It has really helped a lot.
I have followed the steps:
$vm = JomGenius("virtuemart");
$catid = $vm->info("category_id"); // on browse pages or product detail pages
$img = "";
if ($catid == 40) $img = "foo.jpg";
if ($catid == 41) $img = "bar.jpg";
if ($catid == 42) $img = "wombat.jpg";
// ... add more as appropriate
if ($img != "") {
  // customise path as appropriate for your site
  echo '<img src="/images/stories/vm/' . $img . '" />';
}


For the category id's, I have edited these:
if ($catid == 42) $img = "wombat.jpg";

and have added more as necessary.
However, I am not understanding 100% as to what to do with the code below it:

if ($img != "") {
  // customise path as appropriate for your site
  echo '<img src="/images/stories/vm/' . $img . '" />';

Right now, all i've done is said if category is a certain number, then to display an image, however, no image displays, so I presume I need to edit the last bit of code somehow smile

this is what my code says currently:

$vm = JomGenius("virtuemart");
$catid = $vm->info("category_id"); // on browse pages or product detail pages
$img = "images/products-pic2.jpg";
if ($catid == 4) $img = "images/silverware-pic.jpg";
if ($catid == 5) $img = "images/tables-chairs-pic.jpg";
if ($catid == 7) $img = "images/heating-pic.jpg";
if ($catid == 8) $img = "images/lighting-pic.jpg";
if ($catid == 10) $img = "images/extras-pic.jpg";
if ($catid == 20) $img = "images/marquees-pic.jpg";
// ... add more as appropriate


if ($img != "") {
  // customise path as appropriate for your site
  echo '<img src="/images/' . $img . '" />';
}

CreativeDesigns
Junior Modder
ranks
useravatar
Offline
24 Posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Another question.. I need to show a completely different image on a page : http://www.silverspoonhire.co.za/newsit … .pricelist

this one unfortunately has no category ID or anything.. What would you suggest I do here?

CreativeDesigns
Junior Modder
ranks
useravatar
Offline
24 Posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Please can someone help me?

CreativeDesigns
Junior Modder
ranks
useravatar
Offline
24 Posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Hi,

this code at the bottom of the recipe is important:

if ($img != "") {
  // customise path as appropriate for your site
  echo '<img src="/images/' . $img . '" />';
}

What this does is to take the $img that was calculated earlier, and makes it into an HTML <img> tag.

If you look at the path of the image in that code, it assumes that you have put all the images into this folder on your server:

/images/

... and then, each image is named with the name that you gave it in the preceding code.

You'll notice that this makes a path name that has "images" in it twice.

So you probably should remove the extra "images" word from either the individual items, or from the final "echo" statement.

e.g. if you want to keep your individual image paths as they are, then you could modify those final lines to this:

if ($img != "") {
  // customise path as appropriate for your site
  echo '<img src="/' . $img . '" />';
}

That puts in a leading "/" which is probably a good idea, especially if you are using SEF URLs.

The proof of the pudding is in the eating... check the URLs that get generated by this module, and if no images appear then just adjust the paths until you get them right.

For the pricelist page, you could add this just above the "if ($img ..." line above:

if ($option == "com_virtuemart"
  and JRequest::getVar("page") == "shop.pricelist")
    $img = "image/some_other_image.jpg";


Hope that helps,
Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Hi Stephen,
Ok, i've changed the bottom section to
if ($img != "") {
  // customise path as appropriate for your site
  echo '<img src="/' . $img . '" />';
}

but nothing has changed.
Am I supposed to put anything in "Quick module position or id include"?
Also, not sure what "Auto-enable included modules?" should be set as?

CreativeDesigns
Junior Modder
ranks
useravatar
Offline
24 Posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Unfortunately the pricelist thing didn't work either sad

CreativeDesigns
Junior Modder
ranks
useravatar
Offline
24 Posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Would it be easier if I gave you the backend logins to take a look and see what im doing wrong?
I promise i've followed everything step by step sad

CreativeDesigns
Junior Modder
ranks
useravatar
Offline
24 Posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

I thought I should also point out that i've gotten one of my developers to look at this module and the coding that has been inserted. He found some stuff that was wrong.. he corrected it, yet it still won't work. Here is the code he used..

if ( $vm->check("pagetype = shop.browse") ) {
  $category_id = $vm->info( "category_id" );

if ($category_id == "4") $img = "/newsite/images/silverware-pic.jpg";
if ($category_id == "5") $img = "/newsite/images/tables-chairs-pic.jpg";
if ($category_id == "7") $img = "/newsite/images/heating-pic.jpg";
if ($category_id == "8") $img = "/newsite/images/lighting-pic.jpg";
if ($category_id == "10") $img = "/newsite/images/extras-pic.jpg";
if ($category_id == "20") $img = "/newsite/images/marquees-pic.jpg";

// on browse pages or product detail pages


if ($img != "") {
  // customise path as appropriate for your site
  echo '<img src="/' . $img . '" />';
}
}
if ($option == "com_virtuemart"
  && JRequest::getVar("page") == "shop.pricelist")
    $img = "/newsite/images/pricelist-pic.jpg";
}



So clearly I must be doing something else wrong..

CreativeDesigns
Junior Modder
ranks
useravatar
Offline
24 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1667
Total Polls:
6
Total Posts:
5909
Total Posts Today:
1
User Info:
 
Total Users:
10075
Newest User:
rsker57
Members Online:
0
Guests Online:
224

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked