Change group in joomla registration - joomla

I need to change default group when new user registers in Joomla! 2.5. Right now default group is Registered - number 2 in #__user_usergroup_map Group_id column.
I tried to change variable here, (e.g $system = '33';) but it didn't worked:
$this->data->groups = array();
$system = $params->get('new_usertype', 2);
$this->data->groups[] = $system;

There is no need to modify the core files for this.
There is a simple config for this very purpose:
Go to the User Manager
Click on the Options button.
Select the default group.
I tested this with the latest version of J!2.5.

Related

Joomla 1.5 to 2.5 - how to get group names of component settings

I am upgrading a Joomla Website from 1.5 to 2.5 and I have a problem with a custom component which gets the setting params from the JEvents component. The old source tries to get the group names of these settings like this:
$groups = $this->params->getGroups();
But this does not work with Joomla 2.5.
I didn't find useful information on Google, so maybe you can help me out with this.
Thank you very much!
If it's simply the parameters from JEvents that you want to retrieve, then you can use the following:
$app = JFactory::getApplication('site');
$params = $app->getParams('com_events');
$var1 = $params->get('paramName1');
$var2 = $params->get('paramName2');
$var3 = $params->get('paramName3');
Hope this helps
Solved it by myself.
I changed the component input to a Form instead of Parameters and bound the Parameter Data in a JRegistry to the form.
The view works with fieldsets as groups.

Extending Joomla 2.5 Banner Component

I really hope someone can help me.
I need to be able to serve banners in categories which are dependant on a session variable - and can't find a component which does that. So I'd like to extend the Joomla Banner component in order to select banners based on a session variable which contains the category path.
The correct session variable is being stored correctly.
In order to do this I added an option in the banners module .xml to allow for a session variable and the name of the session variable. This is being stored correctly in the module table within the params field along with the other module parameters.
Then I started on the
components > banners > com_banners > models > banners.php
by adding two lines of code in getListQuery where the SQL is assembled. They are:
$sess_vars = $this->getState('filter.sess_vars');
$sess_vars_name = $this->getState('filter.sess_vars_name');
But both variables contain nothing even though the ones the component already has can be retrieved fine. Without a doubt I need to change something somewhere else as well - but just can't figure out what to do.
Any help would be greatly appreciated.
The first thing to do is not hack the core files, hacking the core prevents you from using the built-in update feature to apply the regular bug fixes and security patches released by Joomla! (e.g. the recently released 2.5.9 version).
Rather make a copy of them and modify it so it's called something else like com_mybanners. Apart from the folder name and the entry point file (i.e. banners.php becomes mybanners.php) you will also want to update the components banners.xml to mybanners.php.(You will need to duplicate and modify both the front end /components/com_banners/ and /administrator/components/mybanners.php.)
Because of the way Banners work (i.e. banners are displayed in a module) you will also need to duplicate and modify /modules/mod_banners/,/modules/mod_banners/mod_banners.php and /modules/mod_banners/mod_banners.xml. Changing mod_banners to mod_mybanners in each location.
In Joomla! components the state is usually populated when JModel is instantiated, however, in this case the component is really about managing banners and recording clicks the display is handled by mod_banners. So, you will want to add some code to mod_mybanners.php to use the session variables you want to act on. Normally when a models state is queried you will collect the variables via JInput and add them to your object's state e.g.
protected function populateState()
{
$jApp = JFactory::getApplication('site');
// Load state from the request.
$pk = $jApp->input->get('id',0,'INT');
$this->setState('myItem.id', $pk);
$offset = $jApp->input->get('limitstart',0,'INT');
$this->setState('list.offset', $offset);
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
// Get the user permissions
$user = JFactory::getUser();
if ((!$user->authorise('core.edit.state', 'com_mycomponent')) && (!$user->authorise('core.edit', 'com_mycomponent')))
{
$this->setState('filter.published', 1);
$this->setState('filter.archived', 2);
}
}
The populateState() method is called when a state is read by the getState method.
This means you will have to change your copy of /components/com_banners/models/banner.php to capture your variables into the objects state similar to my example above.
From there it's all your own code.
You can find all of this information in the Developing a Model-View-Controller tutorial on the Joomla Doc's site

Magento saving a product option for an attribute with a dropdown type

I have written code that automatically imports products basically something like:
$product->setName('my name');
$product->save();
This is fine for free fill text boxes, but how would I go about setting say manufacturer, which is a drop down menu? Is there also a way that if the option doesnt exist, then it will automagically add it?
Thanks
This is tested in 1.5.0.1, you just need to target the correct attribute ID. As #B00MER stated, the attribute will not be created that you are targetting but if the attribute exist, this will create the options.
$eav_entity_setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$new_option['attribute_id'] = $id;
$new_option['value']['_custom_'.$value][0] = $value;
$eav_entity_setup->addAttributeOption($new_option);
Documentation about addAttributeOption can be found here.
http://freegento.com/doc/d0/d7b/_eav_2_model_2_entity_2_setup_8php-source.html#l00603
You will need to create the functionality yourself unfortunately. And by default Magento will not 'automagically' create a option if one doesn't pre-exist.
To simply set the ID of the value you want (Say Sony was ID 12) you can do:
$product->setData('mfr', '12');
However you may find a lot more insight here on steps to do what your looking for:
http://www.arscommunity.com/wiki/magento/configurable-products-creation-code

Magento - Determine if order was placed through admin

I was wondering if there was anyway of determining whether an order was placed via the website or through the admin backend (by an admin user)?
And also (optionally) the logged in admin users name that placed the order?
Something like:
$orderId = 100000010;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$location = $order->getWhereTheOrderWasPlaced();
$userThatDidTheOrder = $order->getUserThatDidTheOrder();
I've done a get_class_methods() call on the order $object but nothing jumps out at me.
Thanks!
By default magenta only store the remote_ip in table sales_flat_order for order that is place by customer (and admin order is null).
So try
if(!empty($order->getRemoteIp()){
//place online
}
else{
// place by admin
}
See Programmatically differentiate between admin & customer-placed orders
I asked this question a while back.. here's the answer I got: Differentiating Backend vs. Frontend Purchases in Magento

Magento - Adminhtml - Default website in new customer form

I am developing an online store for my customer and, we only have one website in our Magento setup.
In the admin panel when I go to Add a customer screen, in the "Associate to Website" field I see "Admin" selected by default. I would like to have my website there by default.
I think one possible way would be to write some code in:
Mage_Adminhtml_Block_Customer_Edit_Tab_Account::initForm
The cleanest way to do this is the just set the default value in your database. This will require no code changes at all.
UPDATE eav_attribute
SET default_value = 1
WHERE attribute_code = 'website_id'
The sample MySQL statement above sets your default website_id to 1.
Or You can simply edit array in:
Mage_Customer_Model_Customer_Attribute_Source_Website::getAllOptions()
I took the hint from Lrrr's answer and populated the drop-down with only user added websites, that is "Please Select" and "Admin" are no more available as options there by adding the following line:
$form->getElement('website_id')->setValues(Mage::getSingleton('adminhtml/system_store')->getWebsiteValuesForForm());
at the end of this function:
Mage_Adminhtml_Block_Customer_Edit_Tab_Account::initForm
The ideal way would be of course to override the above function in one's own module, but in our case overriding the above class creates conflict for another extension that we have installed, so I took this way round.

Resources