Showing posts with label magento backend. Show all posts
Showing posts with label magento backend. Show all posts

Wednesday, August 11, 2010

Check if user is logged-in in Magento backend



This code snippet will check if a user is currently logged-in on magento backend.. this is useful if you want to integrate pages to your magento website, of course you must check if the user that is accessing the said page is an authenticated user of your magento administration.. that is where this code comes into play.. hope this helps

require_once '../app/Mage.php';
umask(0);

$app = Mage::app('default');

/* Init User Session */
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
$session = Mage::getSingleton('admin/session');

if ($session->isLoggedIn()) {

/* do something if logged in */
echo "the user is logged in";

} else {
/* do something else if not logged in */
echo "the user is NOT logged in";
}

?>

Tuesday, August 10, 2010

How to put a configurable menu in magento backend?

I used up almost two weeks just to get this to work... :(
This Menu can be configured to be displayed in a specific user... (so it means you can see this module in the permission->role resources
  • First is create a Basic Magento Module (recommended to put it in app/code/local)
NOTE: this is just a blog for me to remember or review my achievements so please search the Internet for terminologies or actions that you don't understand.

  • Then in your module's etc/config.xml put this code
<adminhtml>
<acl>
<resources>
<admin>
<children>
<helloworld_options translate="label" module="helloworld">
<title>PRESTOTYPE MENU</title>
<sort_order>999</sort_order>
<children>
<hello_children1>
<title>PRESTOTYPE RELATION</title>
<sort_order>10</sort_order>
</hello_children1>

<hello_children2>
<title>PRESTOTYPE MACHINE</title>
<sort_order>20</sort_order>
</hello_children2>

<hello_children3>
<title>PRESTOTYPE INVOICE</title>
<sort_order>30</sort_order>
</hello_children3>
</children>
</helloworld_options>

<system>
<children>
<config>
<children>
<helloworld_options translate="label" module="helloworld">
<title>PRESTOTYPE MENU</title>
</helloworld_options>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>

  • Then in your module's etc/system.xml put this code
<config>
<tabs>
<hellotest translate="label" module="helloworld">
<label>Hello Testing</label>
<sort_order>9999</sort_order>
</hellotest>
</tabs>

<sections>
<hellotest translate="label" module="helloworld">
<label>INVENTORY</label>
<tab>hellotest</tab>
<frontend_type>text</frontend_type>
<action>helloworld/index/goodbye</action>
<sort_order>1000</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</hellotest>
</sections>
</config>
  • Then in your module's etc/adminhtml.xml put this code
<config>
<menu>
<helloworld_options translate="title" module="helloworld">
<title>Prestotype Inventory</title>
<sort_order>110</sort_order>
<children>
<hello_children1>
<title>Relation</title>
<action>helloworld/index/relation</action>
<sort_order>10</sort_order>
</hello_children1>
<hello_children2>
<title>Machine</title>
<action>helloworld/index/machine</action>
<sort_order>0</sort_order>
</hello_children2>
<hello_children3>
<title>Invoice</title>
<action>helloworld/index/invoice</action>
<sort_order>100</sort_order>
</hello_children3>
</children>
</helloworld_options>
</menu>
</config>
That's IT! BUT what if I want to put an action to the menu like it will open up a new page with the url that I specified? You can put javascript to open a new window.. Here's how

  • In your module's controllers/IndexController.php put this code
public function relationAction() {
echo "<script>window.open ('http://www.yahoo.com','mywindow')</script>";
echo "<script>window.location = 'http://127.0.0.1/magento-backend-menu/admin'</script>";}

public function machineAction() {
echo "<script>window.open ('http://www.stitambayan.com','mywindow')</script>";
echo "<script>window.location = 'http://127.0.0.1/magento-backend-menu/admin'</script>";}

public function invoiceAction() {
echo "<script>window.open ('http://www.yahoo.com','mywindow')</script>";
echo "<script>window.location = 'http://127.0.0.1/magento-backend-menu/admin'</script>";}

public function goodbyeAction() {
echo "<script>window.open ('http://www.javascript-coder.com','mywindow')</script>";}
I just downloaded a sample module and tweaked it... from this url
http://alanstorm.com/custom_magento_system_configuration