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

Re: Different Module for Each Virtuemart Category

Hi CreativeDesigns,

I'm so sorry I didn't get to see your replies last night… first it was the weekend, now the blasted time zones are working against us (I'm in New Zealand).

A couple of things:

Am I supposed to put anything in "Quick module position or id include"?

No. In this case we're not actually using MetaMod to include other modules - we're just using it as a way of embedding PHP on the page, with a little additional intelligence that MetaMod has about VirtueMart pages and categories.

Also, not sure what "Auto-enable included modules?" should be set as?

Again, since we're not including modules (just using PHP to create HTML), you don't need to change this. Any setting will work as it's ignored when you don't include any modules.

Can you tell me if you're getting any output at all from this module? If the title of the module doesn't show up, or there's no image (or broken image) at all, then perhaps the MetaMod isn't actually published, OR it's not assigned to the right pages? I'd recommend that you start by setting to display on ALL pages, then trim it down to particular ones later if necessary.

Lastly, there are a couple of things wrong with your final code:

(1) you need this line at the very beginning:

$vm = JomGenius("virtuemart");


(2) The last 2 sections need to be in the opposite order to what you wrote. You also had a stray "}" between the sections, which would have broken it. Also since you are now putting in a leading "/" in each image name, there's no need to add it in the <img> tag as well. So... try them this way. The order is important (check for the pricelist page and set the $img variable before you actually use it in the <img> tag):

if ($option == "com_virtuemart"
  && JRequest::getVar("page") == "shop.pricelist")
    $img = "/newsite/images/pricelist-pic.jpg";
}

if ($img != "") {
  echo '<img src="' . $img . '" />';
}


Lastly, I'd be happy to log in to your site to help you sort this out. I'll send you a PM with my e-mail address to send login details.

Best regards,
Stephen

p.s. I see your developer substituted "&&" instead of "and" in one of the lines. "and" is perfectly valid PHP and I use that instead of "&&" because it's more obvious for people who don't know PHP so well. But either work fine.

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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Hi Stephen,
I wasn't aware of the timezone issue - I checked on your profile yesterday to see where you were, but couldn't see anything. I hope you weren't affected by the earthquakes yesterday..

Will respond to your PM's now.. I think it's better if you take a look where I am going wrong. Your first message to me said that the pages should be set to NONE, because we're inputting the code straight onto the specific pages. Also, no specific pages/menu items have been created for the virtuemart categories which are being called.

Anyways, I hope you can help. Thanks for getting back to me.
Sam

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

Re: Different Module for Each Virtuemart Category

Ok, here's the final solution, as is now working on your site:

Code:

$vm = JomGenius("virtuemart");

$img = "";
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";
}

if ($option == "com_virtuemart"
  && JRequest::getVar("page") == "shop.pricelist") {
    $img = "/newsite/images/pricelist-pic.jpg";
}

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

I also changed the MetaMod to show on ALL pages. In my original e-mail I described the way that in MetaMod you generally set up a bunch of target modules (the modules that are going to be displayed by the MetaMod). It's those ones that have to be set to "none" menu items, not the MetaMod! In your case, we're not even using other modules as we are outputting the code directly from the MetaMod.

So now it's all working nicely.

Nice images by the way smile

Best regards,
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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Thanks Stephen. You're a genius. I'm not sure why half of my homepage has disappeared though?
So basically from now on if I need to add another image to different categories, I should just add them as per the coding above.
Is there a way to say that if the category doesn't have any specific image added to it to default on an image?

I tried adding that in a previous version of the code which didn't work.
The id it's supposed to default to is products_pic2.jpg

I really appreciate your help.
Have mailed Joomla as promised.

Sam

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

Re: Different Module for Each Virtuemart Category

Hi,

The front page problem was caused because MetaMod was assigned to that page but was empty... however this caused your template to think there was a module there, and it reserved some space for it, causing the layout to break.

To fix this, I installed the MetaMod Pro plugin, which just sort of magically fixes the problem smile

To add a default image for any shop.browse pages that don't have an image, use this complete recipe instead:

Code:

$vm = JomGenius("virtuemart");

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

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

if ($option == "com_virtuemart"
  && JRequest::getVar("page") == "shop.pricelist") {
    $img = "pricelist-pic.jpg";
}

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

Notice also that I have taken out the "/newsite/images/" part from each image, and put that in the final line? This is to make it easier to change the path to the images when you move the site to the proper domain (which I guess won't have "/newsite" in it). Now you can just edit that in one place.

The name of the default image on the server, as it is in the code above, is /newsite/images/default.jpg. If you want to change that, just change the "default.jpg" text above.

Hope that makes sense,
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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

you are beyond amazing! thank you so much Stephen! I really appreciate your help. I have given you 5 stars on Joomla, and have given you a very favourable review. smile

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

Re: Different Module for Each Virtuemart Category

Hi Stephen,
Thank you for your help in the past. I really hope you can help me now.
In the past you helped me with the following code:



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

if ($category_id == "1") $img = "/images/royal-porcelain-pic.jpg";
if ($category_id == "2") $img = "/images/glasses-pic3.jpg";
if ($category_id == "3") $img = "/images/bead-cutlery-pic.jpg";
    if ($category_id == "4") $img = "/images/silverware-pic2.jpg";
    if ($category_id == "5") $img = "/images/tables-chairs-pic3.jpg";
if ($category_id == "6") $img = "/images/linen-pic.jpg";
    if ($category_id == "7") $img = "/images/heating-pic2.jpg";
    if ($category_id == "8") $img = "/images/lighting-pic2.jpg";
    if ($category_id == "9") $img = "/images/tableware-pic.jpg";
   
if ($category_id == "10") $img = "/images/extras-pic3.jpg";
if ($category_id == "12") $img = "/images/royal-porcelain-pic.jpg";
if ($category_id == "13") $img = "/images/continental-pic.jpg";
if ($category_id == "14") $img = "/images/glasses-pic3.jpg";
if ($category_id == "15") $img = "/images/glasses-pic3.jpg";
if ($category_id == "16") $img = "/images/bead-cutlery-pic.jpg";
if ($category_id == "18") $img = "/images/tableware-pic.jpg";
if ($category_id == "19") $img = "/images/tableware-pic.jpg";
    if ($category_id == "20") $img = "/images/marquees-pic2.jpg";
    if ($category_id == "21") $img = "/images/stretch-tent-pic.jpg";
}

if ($option == "com_virtuemart"
  && JRequest::getVar("page") == "shop.pricelist") {
    $img = "/images/price_list_pic2.jpg";
}

if ($option == "com_virtuemart"
  && JRequest::getVar("page") == "shop.registration") {
    $img = "/images/register_pic2.jpg";
}

if ($option == 'com_virtuemart'
  and $Itemid == '54'
  and JRequest::getVar("page") == ""
  and JRequest::getVar("id") == ""
) {
    $img = "/images/products_pic3.jpg";
}



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

The problem seems to be that when you click on Products menu item (www.silverspoonhire.co.za/products.html), and then try click on one of the categories on the left hand side, it redirects the URL to registration.html instead of keeping it at products.html

I somehow have a feeling it's to do with this section of the code:

if ($option == 'com_virtuemart'
  and $Itemid == '54'
  and JRequest::getVar("page") == ""
  and JRequest::getVar("id") == ""
) {
    $img = "/images/products_pic3.jpg";
}

but I really wouldn't have a clue..

Can you please let me know your thoughts? It was all working 100% until I added in the above codes. I've really been struggling with this. You are my last hope sad

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

Re: Different Module for Each Virtuemart Category

Hi,

You actually added that new bit of code completely correctly - well done smile

The code you are using above is only going to add that new image onto the page - it isn't going to affect URLs or redirection in any way.

What you are experiencing is VirtueMart Menu Item Hell™, caused by VirtueMart's (and VM modules') inability to correctly calculate which menu item to link to.

You can prove that MetaMod is not related to this, by unpublishing the MetaMod. The problem will still be there.

My guess is that about the same time that you edited the MetaMod, you made some other change to the menu structure of your site, or edited something in VM or the module you are using for the categories.

Can you remember what other changes you made?

Best regards,
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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Different Module for Each Virtuemart Category

Unfortunately I don't remember changing anything sad
Is there any way of figuring this out and fixing it?
I've never experienced this before sad

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

Re: Different Module for Each Virtuemart Category

I was just trying to remember the last time I helped you work on this... at that time, did you have SEF URLs enabled? Have you only just enabled them recently? Perhaps you only noticed the Itemid (menu item) problems once SEF was enabled?

Here's a little more info about how VirtueMart calculates Itemids:

1 - in modules, especially 3rd-party modules for VM, all bets are off as to which Itemid you get. It depends on who programmed the module. Some don't include an Itemid at all.

2 - in menu items, if you create a menu item of type "VirtueMart" you get a brand new Itemid for each one. This is kind of useful, but dangerous with regard to (1) since you don't know which one the modules are going to send you to.

3 - in VM itself (e.g. links from inside the VM component to other product pages, checkout etc): generally these rules are used, which are in the file ps_session.php in the function getShopItemid():

(a) if the VM page you're on already has a URL parameter called shopItemid (or if this in in a cookie or session), then this gets used
(b) if not, the database is checked for VM menu items. The FIRST published VM menu item found (which is usually in order of ascending IDs, but not necessarily) and its ID is used as the Itemid
(c) if still not found, the Itemid of the current page is used
(d) if still not found, Itemid is set to 1.


Therefore, if your SEF "stub" is being set to the wrong thing, then this is due to one of these factors:

i - shopItemId is in the URL or session or cookie, and is pointing to the wrong page.
ii - the VM menu item on your system with the lowest numbered ID is being used. If this is the case, then try to reshuffle your menu items so that the one with the lowest ID is a "generic" one rather than one for a particular category of the shop.
iii - check Itemid "1". Perhaps that's being used?
iv - try turning off SEF URLs and check the URLs that are actually being created. What Itemid is being used (if any at all)? If the links are from modules, see if there's any option in the module configuration for which Itemid will be used for the shop.

Hope that helps. Like I said, this is completely typical VirtueMart Menu Item Hell™.

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
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1696
Total Polls:
6
Total Posts:
5941
Posts this week:
7
User Info:
 
Total Users:
5399
Newest User:
sengkanggrand
Members Online:
0
Guests Online:
131

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