We know that Joomla 1.6 and up has access levels groups settings but this little hack could help everyone from 1.5 and up
this there outputs the params from specific Joomla menu item
$menus = &JSite::getMenu();
print_r($menus ->_items[170]);
where 170 are the parameters for menu item id 170 , now
there is a setting called published , what I am trying to achieve is show menu item to visitors only by globally setting the $menus ->_items[170]->published to 0 instead 1 when user is logged in
but changing that array value is hard so if you could please just check if you can change the value output from 1 to 0 by using provided info.
f we can get that to work than code snippet could be something like
if ( !$user->id ) {
$menus = &JSite::getMenu(); $menus ->_items[170]->set('published',0); }
but set() does not work for menu item id's
Thank you!
Why not just set the menu item access to registered in the menu parameters? Then the item only displays when the user is logged in. This is a built in behavior in Joomla.
Related
I have a dropdown menu in d3.js, and I would like to get the index from the selected option. It's a list of a bit more than 50 flight companies, and right now I have this :
function choixCompagnie(){
let compagnieChoisie = d3.select(this).property('value')
}
This function activates whenever there is a change on the drop down, like so :
d3.select("#selectCompagnie")
.on("change",choixCompagnie)
The property('value') means that for instance if I click the first line of my drop down menu, which is Aer Lingus, my compagnieChoisie variable will get the value Aer Lingus instead of 0.
I need it because I then need to access some properties company by company, and my objects are in an array. So in my database I need to access the properties like this data[index].randomProperty and not like this data["Company Name"].randomProperty, since the company name is already a property.
I don't know if this makes sense, sorry if I'm using the wrong terms I'm fairly new to coding.
Thanks for the help !
edit : here is a working example http://blockbuilder.org/ArnaudStephanUNIL/a18332a561579eb929091faaff91fb6f, where the drop down gets the value but not the index
You should access your data like this:
function choixCompagnie(){
let compagnieChoisie = d3.select(this).property('value')
console.log(data.find(d => d.compagnie === compagnieChoisie).accidents);
}
I found a better, easier way to get the index from a drop down menu :
<select id="selectOptions"></select>
Once you initialized your drop down menu, you simply have to do this :
var options = ["option1","option2"];
options.forEach(function(d,i){
d3.select("#selectOptions")
.append("option")
.attr("value",i)
.text(d);
})
I am trying to add a new root category on a local install of Magento CE 1.8.1, however when I press the save category button, I get the following error in the console and nothing happens on screen.
I have tried to reinstall all the core files etc but nothing seems to fix this issue.
Uncaught TypeError: Cannot read property 'split' of undefined
This is a Javascript error in the ajax routine that sends the form data to the Magento server. The code that is causing the error is
var path = params['general[path]'].split('/');
the general[path] represents the category hierarchy so a root category should always have a
params['general[path]'] = 1
but a sub category will have the id of it's parent category.
It is an odd error for you to get. Can you make sub categories successfully? Can you work out why the form submission is not setting the field general[path]? If you inspect the HTML page source of the 'add new root category page' you should see some code like this, no?
<input id="group_4path" type="hidden" value="1" name="general[path]">
The error you are getting suggests that you don't have that line of HTML in your new root category form. (Or possibly that there is a Javascript error prior to this, about setting the category path, but start by looking for that HTML and please report back. You could add some JavaScript break points to inspect the variables and try to understand why general[path] ends up being undefined.)
The real problem
starts in Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes
In the _prepareForm function is a if-condition (if ($this->getAddHiddenFields())) which ensures that the hidden fields general[id] and general[path] are not rendered because it always returns false.
A bad solution would be to remove the if condition.
but as core changes are bad, is the new wonder what is getAddHiddenFields() and why does it return false?
The Solution (for now):
In the database table eav_attribute_group search for an entry that matches the following query:
SELECT * FROM `eav_attribute_group` WHERE default_id = 1 AND sort_order > 1;
and Set the sort_order to 1
The Explanation:
The answer to my first question (what is getAddHiddenFields()):
getAddHiddenFields() is a magic method and returns the value of the varien object field 'add_hidden_fields'.
The Value of 'add_hidden_fields' is set by setAddHiddenFields() in Mage_Adminhtml_Block_Catalog_Category_Tabs->_prepareLayout().
For the answer to my second question (why does it always return false) i created a little Debug log:
# Debug log of Mage_Adminhtml_Block_Catalog_Category_Tabs->_prepareLayout()
init $defaultGroupId with: 0
check group 157 is 0 or isDefault //Note 1 (see further down below)
if ($defaultGroupId(0) == 0 or $group->getIsDefault():false)
set $defaultGroupId to 157
check group 3 is 0 or isDefault
if ($defaultGroupId(157) == 0 or $group->getIsDefault():false) //Note 2 (see further down below)
check group 10 is 0 or isDefault
if ($defaultGroupId(157) == 0 or $group->getIsDefault():false)
[...]
process groupId 157
groupId 157 has no attributes
if (!$attributes) { continue; }
process groupId 3
groupId 3 has attributes
if (!$attributes) { continue; }
$active = $defaultGroupId == $group->getId();
setAddHiddenFields($active (false)))
process groupId 10
groupId 10 has attributes
if (!$attributes) { continue; }
setAddHiddenFields($active (false)))
[...]
Note 1: remember $defaultGroupId is initalized with 0 so the first entry of groupCollection would be set as default (Because of this the current solution is to set the defaultGroups sortOrder to 1)
Note 2: Oh look the nextmystery $group->getIsDefault() of group 3 returns FALSE (in my case is group 3 General and in the Database is_default = 1)
I have not tested yet, because the current solution is currently sufficient for me.
I am just creating a custom mod_menu in Joomla 3
I wonder if anyone could be so kind and explain what this block of code means since I can not find any reference to the parameter $item->params->get('aliasoptions) also what does this block of code actually do to the menu item? - (line 37 - code taken from default.php in tmpl folder from mod_menu)
$aliasToId = $item->params->get('aliasoptions');
if (count($path) > 0 && $aliasToId == $path[count($path) - 1])
{
$class .= ' active';
}
elseif (in_array($aliasToId, $path))
{
$class .= ' alias-parent-active';
}
Any explanation to this would be most helpful, I am wondering if it's actually needed?
Thats the corresponding function from the helper.php
case 'alias':
// If this is an alias use the item id stored in the parameters to make the link.
$item->flink = 'index.php?Itemid=' . $item->params->get('aliasoptions');
break;
So if you look at the function in default.php you will see this piece of code:
foreach ($list as $i => &$item) :
$class = 'item-'.$item->id;
and following with an if clause and after that the code you are asking for.
So what it basically does (in my understanding):
Use the item id defined in itemparameters (basically its just the item id xD ) if the link is just an alias for another menu item. Without it Joomla shouldnt be able to set the correct active menu links.
You can set Menu Item Aliases by choosing them in the Menu Item Type selection: "System Links -> Menu Item Alias", when creating or editing menu items ;)
I hope this helps ^^
Using CI 2.1.1 and the native Cart library
If I insert an item (with same product id, same options) more than once, it replaces instead of increasing the qty.
Could this be a bug, am I missing something, or what would be the best way to add this functionality myself?
So this was my solution, a change to System/libraries/Cart.php on line no. 233 to 244
There may be better ways to do this but it does the trick. I don't understand why the functionality isn't there already
// EDIT: added check if idential rowid/item already in cart, then just increase qty
// without this addition, it would not increase qty but simply replace the item
if (array_key_exists($rowid, $this->_cart_contents))
{
$this->_cart_contents[$rowid]['qty'] += $items['qty'];
}
else
{
// let's unset this first, just to make sure our index contains only the data from this submission
unset($this->_cart_contents[$rowid]);
// Create a new index with our new row ID
$this->_cart_contents[$rowid]['rowid'] = $rowid;
// And add the new items to the cart array
foreach ($items as $key => $val)
{
$this->_cart_contents[$rowid][$key] = $val;
}
}
It's not a bug. Look at it this way: you're telling CI that you want 1 productX in your cart. If it's already there, it stays that way. The rowid does get updated.
Editing the core libraries is not a good idea. That makes your application depend on the changes you made and it can break it when you update CI and forget to change the core again.
If you really want to be able to increase the qty every time the user clicks on Add then
I would suggest is to do something similar to what you did, but in you model.
Check if the product is already in cart, get the qty and add existing qty to the new one.
Does this make sense?
I have custom Joomla(v1.5) component and currently working with component's router. The problem is I can't remove id numbers from SEF url. I get:
http://myaddress.com/componentalias/17-city-alias/130-item-alias
What I want to get:
http://myaddress.com/componentalias/city-alias/item-alias
Take a look at router.php methods below:
function ComponentnameBuildRoute(&$query) {
$segments = array();
if(isset($query['city_id'])){
$segments[] = $query['city_id'];
unset($query['city_id']);
}
if(isset($query['item_id'])){
$segments[] = $query['item_id'];
unset($query['item_id']);
}
if(isset($query['task'])){
switch($query['task']){
case 'pay':
$segments[] = JText::_('payment');
unset($query['task']);
break;
}
}
unset($query['view']);
return $segments;
}
/*
* Function to convert a SEF URL back to a system URL
*/
function ComponentnameParseRoute($segments) {
$var = array();
if(isset($segments[0])){
$cityData = explode(':',$segments[0]);
if(isset($cityData[0])){
$vars['city_id'] = $cityData[0];
}
}
if(isset($segments[1])){
$itemData = explode(':',$segments[1]);
if(isset($itemData[0])){
$vars['item_id'] = $itemData[0];
}
}
if(isset($segments[2])){
switch($segments[2]){
case JText::_('payment'):
$vars['task'] = 'pay';
break;
}
}
return $vars;
}
Any ideas? Your help would be appreciated.
The best place to start with your router.php file is reading this article (it's a bit dated but still good) and then reviewing the com_content's router.php file (components/com_content/router.php). You will notice that articles do achieve what you want so best to look at working code and got from there.
Longer answer:
You can only get rid of the item ID variables in a path to a content element if a menu item exists that points directly to the item, otherwise there is no way to find the item.
SEF URLs in Joomla! 1.5 etc are made from the alias' of the individual elements
eg. If I have this menu structure:
Recipes (The menu)
-- Seafood (<-- Category blog where category alias is `seafood` )
-- Grilled Snapper (<-- Recipe Item where item alias is `grilled-snapper` )
-- 'Other category' (<-- Another Category blog )
Full ID Removal
In the case where you're building the SEF URL for a recipe you can build the route by looking for the menu item it might appear in by getting the site menu $menu = &JSite::getMenu(); and comparing the query id in the current menu item against id value in the $query array passed in.
If you have a match you can build the segments up using the alias from the menu path and the recipe alias. (And reverse the process in your ParseRoute($segments) method).
So, from this example above you could build a SEF URL to the Grilled Snapper recipe that looks something like: recipes/seafood/grilled-snapper.
Partial ID Removal
Now say you also have another recipe (e.g. 'Garlic Prawns' alias garlic-prawns) that isn't directly linked to a menu but will appear in the 'Seafood' category blog page. In this situation you would end up with recipes/seafood/2:garlic-prawns
If you don't have a match (like the Garlic Prawns), you can build up partial match if your component has list views like category blogs or in our example Recipe category pages... Essentially in this case you look at the current menu item and determine if it's a list/category view that would contain the content item.
If it is then the path to the category/list view form you initial segments, but as there is no menu item for the article you will still have to use the ID of the item in the last element of the URL.
No Menu Item for content item or a list/category view
When the content item is being linked to directly (e.g. from an article, module or search result) and there are no menu items that point to it or could contain it then you can still create a URL without id's in it but you will be providing the path in the form of direct component access URL.
eg. /component/recipes/recipe/ice-cream-sundae where recipes is the name of the component, recipe is the view and ice-cream-sundae is the alias of the article.