Joomla 3.9.12, JoomGallery 3.4
I have a site with joomShopping for e-shop and JoomGallery for portfolio. The site has 2 menus where some menu items of the first are menu item aliases of the second.
Menu structure is
- Home
- Shop(JoomShopping component)
- - Many subcategories
- Portfolio (JoomGallery component) (Gallery view)
- - Portfolio price range 1 (Categories view)
- - Portfolio price range 2
- - Portfolio price range 3
- - Portfolio price range 4
- Other pages
In portfolio categories are subcategories like Portfolio Item 1 (Category view). For ex., Portfolio Item 1 placed in Price range 1.
For better and easier re-linking of products with portfolio items, I made a content plugin like JoomImages which inserts a category thumb (1st image in category or from category settings or by 'imgid' param), title and category description and wraps this in a link to the category.
All works fine except the link construction.
1st way - use JoomGallery's $this->_interface->route()
:
$catlink = $this->_interface->route('index.php?&option=com_joomgallery&view=category&catid=' . $catid);
If I set $catid
as Protfolio item 1 id, I should get a sef url like this in menus:
site.ru/portfolio/price-range-1/portfolio-item-1/ // fine in all menus and sef url is true
However, in my plugin, I got sef url like this:
site.ru/portfolio/price-range-3/portfolio-item-1/ // incorrect -----^^^^^^^^^^^^^
2nd way - use Joomla JRoute::_()
:
$catlink = JRoute::_('index.php?&option=com_joomgallery&view=category&catid=' . $catid);
With this, I generate SEF urls like:
site.ru/component/joomgallery/portfolio-item-1
I understand that I must set an Itemid in the url for rewriting, but how to get it?
function getItemid( $component, $view )
{
$items = JFactory::getApplication()->getMenu( 'site' )->getItems( 'component', $component );
foreach ( $items as $item ) {
if($item->query['view'] === $view){
return $item->id;
}
}
}
From this function, I got an Itemid of Joomgallery's top level menu item - Portfolio.
How do I get site.ru/portfolio/price-range-1/portfolio-itme-1
?