Author Topic: $Itemid problem with mainmenu  (Read 52059 times)

loiseau

  • Beginner
  • *
  • Posts: 31
Re: $Itemid problem with mainmenu
« Reply #30 on: January 24, 2009, 16:21:28 pm »
After update to vm 1.1.3, always got the itemid problem :

I've tried the vm-expert hack and it's ok. That's cool ! But i've got a problem with some modules like the featured products : when I clik on a featured product, the link is not good (display the good product like shop.browse ?!)
I think I have to add a modification in the productsnapshot ...

But the vm-expert hack is ok, try this !

Thanks all

Micha

  • Jr. Member
  • **
  • Posts: 71
Re: $Itemid problem with mainmenu
« Reply #31 on: January 26, 2009, 11:20:43 am »
With the hack my itemid problem is also solved but my breadcrumb is showing dubble items like: Mainpage/cat1/subcat1/cat1/subcat1
I turned it off until there is a good total solution. Thanks 4 the hack because that part is ok!

MiC

ctene

  • Beginner
  • *
  • Posts: 1
Re: $Itemid problem with mainmenu
« Reply #32 on: March 23, 2009, 17:12:22 pm »
Fixed the problem in a different way - the problem file is the right one - in administrator/components/com_virtuemart/classes/ps_session.php change:

function getShopItemid() {

if( empty( $_REQUEST['shopItemid'] )) {
$db = new ps_DB;
$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");
if( $db->next_record() ) {
$_REQUEST['shopItemid'] = $db->f("id");
}

to

function getShopItemid() {

if( empty( $_REQUEST['shopItemid'] )) {
$db = new ps_DB;
$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");
if( $db->next_record() ) {
$_REQUEST['shopItemid'] = $_GET['Itemid'];
}

My best Guess and strongest suspicion is that this query:

$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");

produces the wrong result, I did not have much time to trace it all back to the reason but bypassed the issue with obtaining the correct item ID via a GET and nicely enough it even seems to work flawlessly with SEO URLz as well :) (but thats what we wanted to begin with, rite? :D)

webbie

  • Beginner
  • *
  • Posts: 1
Re: $Itemid problem with mainmenu
« Reply #33 on: June 10, 2009, 13:38:48 pm »
Hi ctene!

thank you so much with that perfect solution! Works like a charm! You rock!
;)

ejohnson

  • Beginner
  • *
  • Posts: 38
Re: $Itemid problem with mainmenu
« Reply #34 on: June 18, 2009, 19:36:55 pm »
Has anyone solved the problem with the $Itemid in Virtuemarts Extended Search Plugin? The URLs and Categories are all showing the same.

I've applied the VM-Expert Hack to the ps_session.php file and it's fixed issues like the pagination, but not this plugins. I've also edited the getShopItemid() to be:

Code: [Select]
if( empty( $_REQUEST['shopItemid'] )) {
   $db = new ps_DB;
   $db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");
   if( $db->next_record() ) {
      $_REQUEST['shopItemid'] = $_GET['Itemid'];
   }
   else {
      if( !empty( $_REQUEST['Itemid'] )) {
         $_REQUEST['shopItemid'] = intval( $_REQUEST['Itemid'] );
      }
      else {
         $_REQUEST['shopItemid'] = 1;
      }
   }
} else {
   return intval($_REQUEST['Itemid']);
}

return intval($_REQUEST['shopItemid']);

Am I missing something?

I deleted the menu item Candida and Food Allergy and tried again. For the parameters I placed 7 in for the category ID and shop.browse for the page. It now appears that it is ignoring the parameters. If you go here, http://74.53.203.210/~canary/ and click on the menu item for Candida and Food Allergy, it does not take me to that page. It takes me to the default home page for VirtueMart as if I had just gone to http://74.53.203.210/~canary/index.php?option=com_virtuemart.
Anymore suggestions?

How do I remove the ItemID parameter off of the url links in the scrolling products window? I tried looking in the plugins folder and removing ItemID from the vmxsearch.plugin.php file, but no such luck.

Thanks for your help.
Rick

marco

  • Beginner
  • *
  • Posts: 9
Re: $Itemid problem with mainmenu
« Reply #35 on: January 21, 2010, 23:36:32 pm »
The problem in in the query: the query is:

find this: function url($text, $createAbsoluteURI=false, $encodeAmpersands=true, $ignoreSEF=false )

then you see the query (example for the category_id)

$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%category_id=$ii_cat_id%' AND published=1");

The problem is THIS: if i have in jos_menu an item with "category_id=33" and another with "category_id=3", the first one will always turns up even when i am linking to the "3" category. Is that clear?

I right query is:

$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%category_id=$ii_cat_id\n%' AND published=1");

---

note: you have to change % in \n% also in product_id search, flypage and page search.

THE ENTIRE RIGHT FUNCION IS HERE: change from

if(!defined('_VM_IS_BACKEND')) {

to

$Itemid = NULL;
}"

with this:



if(!defined('_VM_IS_BACKEND')) {
         
         // Strip the parameters from the $text variable and parse to a temporary array
         $tmp_text=str_replace('amp;','',substr($text,strpos($text,'?')));
         if(substr($tmp_text,0,1)=='?') $tmp_text=substr($tmp_text,1);
         
         parse_str($tmp_text,$ii_arr);

         // Init the temp. Itemid
         $tmp_Itemid='';

         $db = new ps_DB;
         
         // Check if there is a menuitem for a product_id (highest priority)
         if (!empty($ii_arr['product_id'])) {
            if ($ii_product_id=intval($ii_arr['product_id'])) {
               $db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%product_id=$ii_product_id\n%' AND published=1");
               if( $db->next_record() ) $tmp_Itemid = $db->f("id");
            }
         } else {
            // Check if there is a menuitem for a category_id
            // This only checks for the exact category ID, it might be good to check for parents also. But at the moment, this would produce a lot of queries
            if (!empty($ii_arr['category_id'])) {
               $ii_cat_id=intval($ii_arr['category_id']);
               if ( $ii_cat_id && $tmp_Itemid=='') {
                  $db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%category_id=$ii_cat_id\n%' AND published=1");
                  if( $db->next_record() ) $tmp_Itemid = $db->f("id");
               }
            }
            // Check if there is a menuitem for a flypage
            if (!empty($ii_arr['flypage'])) {
               $ii_flypage=$db->getEscaped(vmget($ii_arr,'flypage'));
               if ($ii_flypage && $tmp_Itemid=='') {
                  $db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%flypage=$ii_flypage\n%' AND published=1");
                  if( $db->next_record() ) $tmp_Itemid = $db->f("id");
               }
            }
            // Check if there is a menuitem for a page
            if (!empty($ii_arr['page'])) {
               $ii_page=$db->getEscaped(vmget($ii_arr,'page' ));
               if ($ii_page && $tmp_Itemid=='') {
                  $db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%page=$ii_page\n%' AND published=1");
                  if( $db->next_record() ) $tmp_Itemid = $db->f("id");
               }
            }            
         }
         // If we haven't found an Itemid, use the standard VM-Itemid
         $Itemid = "&Itemid=" . ($tmp_Itemid ? $tmp_Itemid : $this->getShopItemid());
      } else {
         $Itemid = NULL;
      }



it works!




palden

  • Beginner
  • *
  • Posts: 12
Re: $Itemid problem with mainmenu
« Reply #36 on: January 28, 2010, 09:37:43 am »
thanks ctene ! you code works for me as well !! Cheers !!!

palden

  • Beginner
  • *
  • Posts: 12
Re: $Itemid problem with mainmenu
« Reply #37 on: January 28, 2010, 09:53:05 am »
Oops! hang-on ! the solution from ctene works on this problem at this side, but messed up the check out page in the other side. you will seen the check out page contains the category page.  Not perfect yet.

hope a perfect solution comes out soon !


noojeeit

  • Beginner
  • *
  • Posts: 1
Re: $Itemid problem with mainmenu
« Reply #38 on: November 16, 2010, 07:26:05 am »
So, Virtuemart 1.1.5 menu routing mostly works, but I want the default ItemId to be the link to the store front, rather than just whatever the first random menu link to a store item happens to be.  The following patch achieves this, and my routing now works as expected:

Code: [Select]
diff --git a/administrator/components/com_virtuemart/classes/ps_session.php b/administrator/components/com_virtuemart/classes/ps_session.php
index 8f6ac15..b4a7293 100644
--- a/administrator/components/com_virtuemart/classes/ps_session.php
+++ b/administrator/components/com_virtuemart/classes/ps_session.php
@@ -460,11 +460,19 @@ class vm_ps_session {
 
                if( empty( $_REQUEST['shopItemid'] )) {
                        $db = new ps_DB;
-                       $db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");
-                       if( $db->next_record() ) {
+                       $db->query( "SELECT id,params FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");
+                       while( $db->next_record() ) {
+                               $params = $db->f("params");
+                               foreach(array("product_id", "category_id", "flypage", "page") as $parameter) {
+                                       if (strpos($params,$parameter."=\n")!==false) {
+                                               continue 2;
+                                       }
+                               }
                                $_REQUEST['shopItemid'] = $db->f("id");
+                               break;
                        }
-                       else {
+               }
+               if( empty( $_REQUEST['shopItemid'] )) {
                                if( !empty( $_REQUEST['Itemid'] )) {
                                        $_REQUEST['shopItemid'] = intval( $_REQUEST['Itemid'] );
                                }
@@ -472,7 +480,6 @@ class vm_ps_session {
                                        $_REQUEST['shopItemid'] = 1;
                                }
                        }
-               }
 
                return intval($_REQUEST['shopItemid']);

yiun

  • Beginner
  • *
  • Posts: 5
Re: $Itemid problem with mainmenu
« Reply #39 on: July 03, 2011, 02:15:44 am »
If someone has the problem again:

First create a UserClass directory:
Quote
./components/com_virtuemart/themes/default/user_class/

Then create a file:
Quote
./components/com_virtuemart/themes/default/user_class/ps_session.php

Here overwrite the method getShopItemid(). For example:
Quote
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

class ps_session extends vm_ps_session {

   function getShopItemid() {

      if( empty($_REQUEST['shopItemid']) ) {

         if( $_REQUEST['page'] == "shop.product_details"
            || $_REQUEST['page'] == "shop.browse"
         ){
            
            $_REQUEST['shopItemid'] = 3;
         }

         else if( $_REQUEST['page'] == "account.billing"
            || $_REQUEST['page'] == "account.index"
         ){

            $_REQUEST['shopItemid'] = 4;
         }
            
         else{
            $_REQUEST['shopItemid'] = 5;
         }

      }

      return intval($_REQUEST['shopItemid']);

/*      it is also possible to use the parent method:*/
/*      return parent::getShopItemid();*/
   }

}

If the class is called by virtuemart our function will used instead of the normal function.
To this example: If the variable $shopItemid isnt set, so our method will do it: If the page is "shop.product_details" or "shop.browse" with 3; if it is "account.billing" or "account.index" with 4; otherwise with 5. Then the value will returned.

Now you just have to modify the pages/itemsIDs for your project.

Kub

  • Beginner
  • *
  • Posts: 14
Re: $Itemid problem with mainmenu
« Reply #40 on: July 10, 2011, 18:46:01 pm »
Hello,

i need help for this Script, i will use per Category other ItemId´s, but the Script works not correctly?

Code: [Select]
<?php
if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
class 
ps_session extends vm_ps_session {
function getShopItemid() {
if( empty( $_REQUEST['shopItemid'] )) {

$category_id vmGet($_REQUEST'category_id'0);


$db = new ps_DB;
$q "SELECT * FROM #__{vm}_category,#__{vm}_category_xref ";
$q .= "WHERE #__{vm}_category.category_id='$category_id' ";
$q .= "AND #__{vm}_category_xref.category_child_id=#__{vm}_category.category_id";
$db->query($q);
$db->next_record();
echo $db->f('category_parent_id');
$catid $db->f('category_parent_id');

if ($catid == "1") {
$_REQUEST['shopItemid'] = 9;

else if ($catid == "2") {
$_REQUEST['shopItemid'] = 10;
}
else if ($catid == "3") {
$_REQUEST['shopItemid'] = 11;
}
else if ($catid == "4") {
$_REQUEST['shopItemid'] = 12;
}
else if ($catid == "5") {
$_REQUEST['shopItemid'] = 13;
}
else if ($catid == "6") {
$_REQUEST['shopItemid'] = 14;
}
else {
$_REQUEST['shopItemid'] = 15;
}

return intval($_REQUEST['shopItemid']);
}

}

?>

Thanks

yiun

  • Beginner
  • *
  • Posts: 5
Re: $Itemid problem with mainmenu
« Reply #41 on: July 16, 2011, 05:43:27 am »
Hi Kub,

on the first view I can't see any mistake. Maybe there is s.th. wrong in the database-query.
Check the value of $catid! Is it ok?

You have to specify the problem, "works not correctly" isn't enough.
Have you recognized any changes since you have implemented the script?

Don't forget the correct filename/directory and (especially in Linux) the file-privileges!

Hope you haven't give up yet  :P

Kub

  • Beginner
  • *
  • Posts: 14
Re: $Itemid problem with mainmenu
« Reply #42 on: July 16, 2011, 11:32:39 am »
Hi yiun,

i think the Problem is
Code: [Select]
$category_id = vmGet($_REQUEST, 'category_id', 0); i must make a Db Select without this, but i havent a Idea. Can you help?

yiun

  • Beginner
  • *
  • Posts: 5
Re: $Itemid problem with mainmenu
« Reply #43 on: July 17, 2011, 19:18:17 pm »
With the command you are just searching in the request-variable (which is defined by POST-Method) for the "category_id". The following command searches in the request-variable (POST-method) AND in the url (GET-method).
Code: [Select]
$category_id = vmRequest::getInt('category_id');It is also possible to set a default-value and just allow one method (GET or POST).
In this file you'll find all the methods with possible parameters:
Code: [Select]
./administrator/components/com_virtuemart/classes/request.class.php
I assume you know the GET- and POST-method. If not, just google "html get post".

Hope it helps!