Joomla get menu item id - joomla

I have a component that has a simple payment form. I just want to get the current menu item id. I've tried several things to get the id.
//get the active menu item id
$app = JFactory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$activeId = $active->id;
JLog::add('active id is: '.$activeId); //I get nothing returned
$currentMenuId = JSite::getMenu()->getActive()->id ;
JLog::add('menu id is: '.$currentMenuId); //I get nothing returned
//try to see what the current url is
$currenturl = JURI::current();
JLog::add('current url is: '.$currenturl); //I get mysite.com/index.php
I use $activeId code in my plugins without problems but it doesn't work in my component. What am I missing?

$app = JFactory::getApplication();
$menu = $app->getMenu()->getActive()->id;
echo $menu;
Hope this is what you're looking for

Related

how to get product images url for storeid

I've created a magento product with no default (Admin) images, but
I've properly setted an image as thumbnail, small_image and imageset for the "italian" store view.
If I use the following code in a phtml files I'get the correct image url:
echo "url = " . Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(95,95)
I get :
media/catalog/product/cache/6/image/80x/9df78eab33525d08d6e5fb8d27136e95/1/9/1901186_10152274267007184_1589016979_n_7.jpg
Inside a controller for an ajax callback fucntion I use the following:
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
echo "url = " . Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(95,95);
but I alwais get the placeholder image
/media/catalog/product/cache/6/thumbnail/95x95/9df78eab33525d08d6e5fb8d27136e95/placeholder/websites/3/LOGO_1.png
I try to set the product storeId before loading the product data but no result:
$product = Mage::getModel('catalog/product');
$product = $product->setStoreId(6);
$product = $product->loadByAttribute('sku',$sku);
echo "vediamo " . Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(95,95);;
Thank for any helps and sorry for my english.
Giuseppe
This is working for me
$cathlpimg = new Mage_Catalog_Helper_Image();
echo $cathlpimg->init($_item, 'image')->resize(200);
I'm surprised to see that didn't work - the key thing for me was to specify the store ID before calling load(), but I can see you already tried that.
Although, strictly speaking, you didn't use load(), you used loadByAttribute(). Maybe it doesn't work in quite the same way. Have you tried:
$product = Mage::getModel('catalog/product');
$product = $product->setStoreId(6);
$product = $product->load($id);
If you only know the sku and not the ID, just use this:
$id = Mage::getModel('catalog/product')->getIdBySku($sku);

Call parameters of a menu in a module in joomla3 with k2

I want to get parameters of a specific menu in joomla3/k2
I can get current menu by this code:
$params = K2HelperUtilities::getParams('com_k2');
$_myparam=$params->get('menu-meta_url');
Now how can I call $params->get('menu-meta_url') form another page or module?!
Well - if you just want to get the current menu params... you can use the default.
$itemid = JRequest::getVar('Itemid');
$menu = &JSite::getMenu();
$active = $menu->getItem($itemid);
$params = $menu->getParams( $active->id );

how to get default store view label on magento

I have this code:
$options = ($_Item->getProductOptions());
How I can have the default view label name of the option and not of the translated store view one?
Thanks.
this particular code depends on the class of the $item object.
Theoretically, you would get the default view label by loading the product in admin store:
Mage::getModel('catalog/product')->setStoreId(0)->load(PRODUCT_ID);
In your case, it might be something close to:
$productId = $item->getProductId();
$product = Mage::getModel('catalog/product')->setStoreId(0)->load($productId);
$label = $product->getName();
setStoreId(0) before loading the object is the key component.

Where is Itemid used to flag active menu item in Joomla 2.5.6?

Can anyone please help me with the process flow through which the Joomla Itemid parameter ends up being the highlighted menu item?
I have embedded a 3rd party application in Joomla and by temporarily changing the php environment within the application.
I am able to get joomla html and insert the 3rd party html by replacing a token.
Simplified Code:
if ($_SERVER['REQUEST_METHOD'] == 'GET' ) {
$_SERVER['REQUEST_METHOD'] = '';
}
$_SERVER['REQUEST_URI'] = '/joomla/index.php?view=mycom&option=com_mycom&Itemid=103';
$_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = '/joomla/index.php';
$_SERVER['QUERY_STRING'] = 'view=mycom&option=com_mycom&Itemid=103';
ob_start();
require_once '/joomla/index.php';
$joomlaHTML = ob_get_clean();
echo str_replace($replacementToken, $thirdPartyHTML, $joomlaHTML);
In v1.5.x, the menu item with ID 103 is properly highlighted but in v2.5.6, it isn't and the Home item is always highlighted. I think it used to be highlighted correctly in v1.6.x and earlier versions of 2.5.x as well but not sure.
I wanted to find how the process flows (where this is set) so I can see what tweaks I need to make.
DELETED WRONG INFO
Thanks Dayo! you saved my day with this:
// force highlight the external url menu item
$Itemid = JRequest::getVar('Itemid');
$menu = JSite::getMenu();
$menu->setActive($Itemid);
I don't fully understand the breadcrumb part, but I managed to get it working by editing my component's controller.php to read:
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// force highlight the external url menu item
$Itemid = JRequest::getVar('Itemid');
$menu = JSite::getMenu();
$menu->setActive($Itemid);
// force fix the breadcrumb
$app = JFactory::getApplication('site');
$pathway =& $app->getPathway();
$bcrumbs = &JPathway::getInstance('site');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* MyCom Component Controller
*/
class MyComController extends JController
{
}
Look in the following File
Check the
/modules/mod_menu/mod_menu.php
File and you will see two functions has been called "getActive" and "getDefault"
Which can be find in following file
/libraries/joomla/application/menu.php
I think it can be customized easily now

How do you use JRoute in Joomla to route to a Search menu item?

I am trying to create a a box in a template in Joomla! that will display all of the keywords and link them to their appropriate search page. I have a menu item set, however, I don't want to hard-code the menu item into the template, so I want to use the JRoute object to generate the SEF url.
I am using this function:
JRoute::_('index.php?option=com_search&searchword='.$keyword);
or this:
JRoute::_('index.php?option=com_search&view=search&searchword='.$keyword);
however, this generates a url like this:
/component/search/?searchword=africa
when it ought to create a search url like this:
/searchmenuitem?searchword=africa
I have searched extensivly online and havn't found a solution to this problem. Any ideas would be greatly appreciated.
Ok, so some additional information for you.. I am only experiencing the problem when I try and route the URL from a template in com_content. If I try and route the url from a template in com_search everything works perfectly. So, what is it about com_content that is causing this to not work properly?
thanks!
david
In joomla administration page go to the menu item you've chosen for the search results page and get the id of that menu item (itemId).
Than you can try using:
JRoute::_('index.php?option=com_search&view=search&Itemid=256&searchword=asdsadasdsa');
or even
JRoute::_('index.php?Itemid=256&searchword=asdsadasdsa');
both should result in: /searchmenuitem.html?searchword=asdsadasdsa
EDIT:
To make it more comforable you could add itemId as a param to your template.
There is another way, where u can get the itemId from the database (this method is required on multilingual websites). Let me know if you want it.
EDIT2:
Here it is:
$db =& JFactory::getDBO();
$lang =& JFactory::getLanguage()->getTag();
$uri = 'index.php?option=com_search&view=search';
$db->setQuery('SELECT id FROM #__menu WHERE link LIKE '. $db->Quote( $uri .'%' ) .' AND language='. $db->Quote($lang) .' LIMIT 1' );
$itemId = ($db->getErrorNum())? 0 : intval($db->loadResult());
I use this kind of method to get a menu item id of specific component and view
function getSearchItemId() {
$menu = &JSite::getMenu();
$component = &JComponentHelper::getComponent('com_search');
//get only com_search menu items
$items = $menu->getItems('componentid', $component->id);
foreach ($items as $item) {
if (isset($item->query['view']) && $item->query['view'] === 'search') {
return $item->id;
}
}
return false;
}
Then I use this method to get the sef url
function getRouteUrl($route)
{
jimport('joomla.application.router');
// Get the global site router.
$config = &JFactory::getConfig();
$router = JRouter::getInstance('site');
$router->setMode($config->getValue('sef', 1));
$uri = &$router->build($url);
$path = $uri->toString(array('path', 'query', 'fragment'));
return $path;
}
This just works in any template.
use like this
$itemid = getSearchItemId();
//returns valid sef url
$url = getRouteUrl('index.php?Itemid='.$itemid);
You really do not need to do sql on the menu table to get ids. Just search the menu object.
Try to create new menu in the joomla backend called for instance 'hidden-menu'. It will never be shown in the front. But it will be used by JRoute Then add to this menu new menuitem called 'searchmenuitem' with link to com_search. That is all. Now you can call
JRoute::_('index.php?option=com_search&view=search&searchword=asdsadasdsa');
and it will be ceonverted into this
/searchmenuitem.html?searchword=asdsadasdsa

Resources