Joomla pagination across different components - joomla

Because pagination is using getUserStateFromRequest method to get the limit and limitstart variable, I'm having a problem where as I navigate from one component to another, I'm shown a no items found message.
To clarify, I have a products component that has 3 pages worth of products listed. Then I have a branches component with 2 pages worth of branch information. So if I navigate to the third page in the products list, and then go to the branches component, nothing is displayed.
Has anyone any idea how to stop this from happening? Any way to maybe clear the session data?

What I ended up doing was this,
in line 624 in libraries/joomla/application/application.php file I added the following lines
$this->setUserState('option','default');
$curr_comp = JRequest::getCmd( 'option' );;
if($this->getUserState('option') != $curr_comp)
{
$this->setUserState($option . 'limitstart',0);
$this->setUserState('option',$curr_comp);
}
so the whole function reads this,
public function getUserStateFromRequest($key, $request, $default = null, $type = 'none')
{
$this->setUserState('option','default');
$curr_comp = JRequest::getCmd( 'option' );
if($this->getUserState('option') != $curr_comp)
{
$this->setUserState($option . 'limitstart',0);
$this->setUserState('option',$curr_comp);
}
$cur_state = $this->getUserState($key, $default);
$new_state = JRequest::getVar($request, null, 'default', $type);
// Save the new value only if it was set in this request.
if ($new_state !== null)
{
$this->setUserState($key, $new_state);
}
else
{
$new_state = $cur_state;
}
return $new_state;
}
This seems to be working fine at the moment. But please test before implementing on a live site

To prevent editing the core files, but with the effect limited to your extension (so other extensions could load at the wrong page, but not yours), and if your model extends modellist, override the getStart() method:
public function getStart()
{
$store = $this->getStoreId('getstart');
$input = JFactory::getApplication()->input;
$start = $limitstart = $input->getInt('limitstart', 0);
$this->setState('list.start', $limitstart); // maybe redundant
$limit = $this->getState('list.limit');
$total = $this->getTotal();
if ($start > $total - $limit)
{
$start = max(0, (int) (ceil($total / $limit) - 1) * $limit);
}
// Add the total to the internal cache.
$this->cache[$store] = $start;
return $this->cache[$store];
}
If you want a solution that works system-wide and for all extensions, you should be able to override modellist with your implementation in a plugin. Start here.

This is an old question, but I just had the same issue as the OP, but in my case with Joomla 3.4.3.
After a lot of digging and testing, I discovered a solution for this that doesn't involve any plugin or core change:
If you put limitstart=0 in the URL, the pagination will restart for that page, and this solves the problem between menus.
The way to implement this could be either with javascript, or by overriding the menu module, I chose the override:
I just need this in some menus, so I placed a CSS class into the
menu link (edit the menu, and in the "Link Type" tab, place the CSS
class in the "Link CSS Style" field), in my case it was "
video-area" (without the quotes).
Add override (add the module to the html folder of your template,
in my case it was the menu module, so it was a matter of adding the
mod_menu folder: templatefolder/html/mod_menu)
In the override of the component part of the module
(default_component.php), check to see if we have the CSS class, if
so, add the extra query to the URL (I edited case 0):
case 0: $paginationLinks = ""; if(isset($class) && strpos($class, '
video-area') !== false){ $paginationLinks =
"?limitstart=0&limit=12"; } ?><a <?php echo $class; ?>href="<?php
echo $item->flink; ?><?php echo $paginationLinks;?>" <?php echo
$title; ?>><span><?php echo $linktype; ?></span></a><?php break;
That's it! it solved my problem, and even the pagination links have the extra query :)
BONUS: notice that I have &limit=12, this changes the limit for the pagination into 12 per page, without any extra code!, (before, I had a lot of code to implement this, and by adding this to the menu it calculates the correct page number and totals, and filters the query, nice one Joomla!)

Related

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

Joomla - renderModule function strips javascript

please help, I've a problem with Joomla's function renderModule.. I am trying to render module with this function, but it unfortunately strips javascript from the the rendered module.
I use the function in my own module which includes other modules according to current article..
The code is as following:
<?php
$moduleType = "j15html";
$moduleName = "test";
$option = JRequest::getVar( 'option', '' );
$view = JRequest::getVar( 'view', '' );
$id = JRequest::getInt( 'id', 0 );
$moduleName .= $id;
//echo $view;
if ( $option == "com_content" && $view == "article" ) {
//echo $moduleName;
$module = JModuleHelper::getModule($moduleType, $moduleName);
//print_r($module);
if ( ! empty( $module ) ) {
$attribs = array();
echo JModuleHelper::renderModule( $module, $attribs );
}
}
When I set the position of the included module to any position used in my template and set it to displat in particular menu section, it renders properly even with javascript and so on..
Any advices how to make this thing working?
You didn't mention which version of Joomla you're using - but you may want to check out SOURCERER it keeps coding how you put it and does not strip out extra coding.
Make sure you read the how-to so you know how to use it because it can seem a little confusing at first, but it has a button to 'change the tags' from < to << or [ which do not get stripped out by the WYSIWYG editor in Joomla!.
Of course, that could be your issue also, if your WYSIWYG editor is on (by default it is) and you're inputting code - it strips it. An easy way is to just turn it off under global options, then when you save the code doesn't get stripped. Just turning off the WYSIWYG editor is the quick/easy/simple solution - but if you turn it back on and open that module again, the code will be gone. So it can be a tricky solution if others may like using the editor or if you're using lots of custom code around your side. In that case the plugin I mentioned above is a great solution.

How to display Magento Custom Options Individually

My Magento site has a product which has a few Custom Options, one text, one file upload and four drop down lists.
The design of the site dictates that I need to show these options throughout the product view page and not all in one group.
Is there a function that I can call to return the HTML of a single Custom Option?
There are ways to do this that are tantamount to cheating.
Your shop requires javascript to operate and there is a lot you can do with Prototype before the page renders, by using the on dom:loaded event. You can attach your custom options to wherever you want in the DOM, or you can hide them and put something else where you want it on the page that updates the form element. You may want to do this if you have to capture a colour name but don't want to put oodles of colours on every product - a textbox can go on the product and your control can write to it.
The benefit of some $$('cheating') is that you don't have to go too deep into Magento code for what is a 'design consideration'.
I didn't understand correctly about group. If you mean category then ;
create a new attribute set which this attribute set should contain attributes that you want to show. After that, when you create a product, select this attribute set instead of default. So that, only this attributes will be available in the specified products.
Try the following code snippets ( don't forget to change "attribute_code")
Let say, you want to show Multi Select list in your product page, in that case :
$selectArray = $this->getProduct()->getAttributeText('YOUR_ATTRIBUTE_CODE');
$endOfArray = end($selectArray);
echo "<ul class='set-some-class'>";
foreach($selectArray as $selectionItem) {
echo "<li> . $selectionItem";
if($selectionItem != $endOfArray) {
echo "</li>\n";
} else {
echo "</ul>";
}
}
For page other than product view page, in that case:
$attribute = Mage::getModel('catalog/product')->getAttribute('catalog_product', 'YOUR_ATTRIBUTE_CODE');
$options = $attribute->getSource()->getAllOptions(true, true);
$lastOption = end($options);
echo "<ul class='set-some-class'";
foreach($options as $option) {
echo $option['label'];
if($option != $lastOption) {
echo "<li>\n";
} else {
echo "</ul>";
}
}

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

Determining which section is being viewed

Folks, I am trying to implement a rudimentary feature in Joomla but having no luck getting my head around it.
My client has setup Joomla with several sections; each section having its own categories and eventually content underneath.
I need each section to have a slightly different color component (e.g. Section A and its all subsequent child pages red, Section B - blue, etc); certain borders and backgrounds need to be unique according to each section.
I have one theme which is used by all sections. Somewhere in the theme file, I need to detect which section I am on, and based on that set a css variable accordingly:
<html>
<body class="cars-section">
</body>
</html>
All I need is to set my body's class to the right section, and all my coloring has been setup to work magically.
Any ideas how this can be done in the Joomla world? Is there another way of doing such a thing.
You need to pick the section ID up from the request.
Use this to get the relevant request variables:
<?php
$option = JRequest::getWord('option', null);
$view = JRequest::getWord('view', null);
$idalias = JRequest::getVar('id', null);
if (strpos($idalias, ":") != false) {
$idandalias = explode(":", $idalias);
$id = $idandalias[0];
} else {
$id = JRequest::getInt ('id' , 0);
}
Then use something like this to see what section you are in, if you are on a section page:
if ( $option=="com_content" && $view=="section" ) {
$sectid = $id;
}
In section pages you can just use the request, but in other pages you need to do a database query as well:
else {
$database =& JFactory::getDBO();
if ( $option=="com_content" && $view=="category" ) {
$query = "SELECT section FROM jos_categories WHERE id=$id";
}
if ( $option=="com_content" && $view=="article" } {
$query = "SELECT sectionid FROM jos_content WHERE id=$id";
}
$database->setQuery($query);
$sectid = $database->loadResult();
}
When you have the section ID you can use it to set and insert the right class.
if ( $sectid == '3' ) {
$my_cars_section_class = 'three';
}
?>
<body class="<?php echo $my_cars_section_class; ?>">
Something like that should do it.
There are a couple of ways to achieve body css-classing:
Utilize Joomla's menu page class suffix system.
Output the class based on the selected menu link from within the template. Of course, if you plan to do this, you'll need to modify your template a bit.
$menu = &JSite::getMenu();
$active = $menu->getActive();
<body <?php if($active->alias) echo 'class="' .$active->alias .'"' ?>>

Resources