Magento Admin notification - magento

I would like to add a notification in the Admin area, something like 'Latest message' bar but under it.
I have tried using the AdminhtmlNotification module but that only adds a new message into the 'Latest message' queue and if my message is not the last one in is only displayed in the grid.
Thanks in advance for your help,
Denis Rendler

All you have to do is to add your own block under notifications handler of adminhtml layout.
<?xml version="1.0"?>
<layout>
<default>
<reference name="notifications">
<block type="extension/adminhtml_notifications" name="extension_notifications" template="extension/notification.phtml"/>
</reference>
</default>
</layout>
And then create and edit the file extension/notification.phtml:
<?php if ($message = $this->getMessage()) : ?>
<div class="notification-global">Hello!</div>
<?php endif; ?>
For more information, check this article:
https://www.openstream.ch/developer-blog/adding-magento-admin-notifications-to-your-extension/

Related

what is the correct way to add block as a child of an another block in xml in magento?

I have two custom magento blocks called "exe2" and "example".
The exe2 block gets the contents of the example block using the getChildHtml function, but it keeps just returning empty strings to me and only the exe2 contents make it to the screen.
Here is my code my code:
exe2 xml file:
<layout version = "0.1.0">
<test_example_view>
<block type = "exemplum_mod2/exe2" name = "exemplum.mod2.exe2" template="exemplum/mod2/exe2.phtml">
<reference name = "exemplum.mod2.exe2">
<block type="exemplum/example" name="exemplum.example" template="exemplum/example1/example.phtml" />
</reference>
</block>
</test_example_view>
example xml file
<layout version="0.1.0">
<default>
<block type="exemplum/example" name="exemplum.example" template="exemplum/example1/example.phtml" />
</default>
Here is the exe2 phtml file that has the getChildHtml call in it:
<h1> 2nd </h1>
<?php
echo $this->getMessage();
echo $this->getChildHtml("exemplum.mod2.exe2");
?>
hello
example.phtml file:
<h1>Hello there</h1>
And finally heres the controller file that loads the blocks:
<?php
class exemplum_example1_ExampleController extends Mage_Core_Controller_Front_Action{
public function viewAction(){
$this->loadLayout();
$block = $this->getLayout()->createBlock('exemplum_mod2/exe2');
$block->setTemplate("exemplum/mod2/exe2.phtml");
$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();
}
}
What is the correct way to add one block as the child block of a another block in the xml file? Every solution that i found on google didn't seem to work in my case so what am i doing wrong here?

Is there any way to modify this tracking.phtml on magento admin?

When we choose one of the option below, the field 'title' automatically filled with selected value from carrier options.
I want to do the same for 'number' field, it would be filled with something when I choose my custom carrier. Is there any way to modify this tracking form? If yes, how?
Thank's in advance
Add following observer in your module's config.xml
<events>
<adminhtml_block_html_before>
<observers>
<add_script_on_shipment>
<class>yourmodule/observer</class>
<method>addScript</method>
</add_script_on_shipment>
</observers>
</adminhtml_block_html_before>
</events>
Put following code in Observer.php
public function addScript($observer) {
$block = $observer->getEvent()->getBlock();
if (($block instanceof Mage_Adminhtml_Block_Sales_Order_Shipment_View_Tracking) && $block->getType() != 'core/template' /*&& is your carrier active*/) {
$shipment = $block->getShipment();
$_child = clone $block;
$_child->setType('core/template');
$block->setChild('calling_block', $_child);
$block->setTemplate('yourmodule/custom_script.phtml');
}
}
add following code with required modifications in custom_script.phtml
<?php echo $this->getChildHtml('calling_block');?>
<script type="text/javascript">
/*your custom javascript code to bind onchange event*/
</script>
Look in the file app/design/adminhtml/default/default/layout/sales.xml, tracking.phtml is used several times. If this change is for a module then create a layout file 'yourmodule.xml' and enable it from your config file. Otherwise name it 'local.xml'. It's contents will have to be an update something like this:
<?xml version="1.0"?>
<layout>
<adminhtml_sales_order_shipment_new>
<reference name="shipment_tracking">
<action method="setTemplate">
<template>your/new/tracking.phtml</template>
</action>
</reference>
</adminhtml_sales_order_shipment_new>
</layout>
Also if you want to minimize number of copypasted layout statements you can use
<update handle="handle_name" /> inside different controller action handles. For example:
<my_handle_name>
<reference name="shipment_tracking">
<action method="setTemplate">
<template>your/new/tracking.phtml</template>
</action>
</reference>
</my_handle_name>
<adminhtml_sales_order_shipment_new>
<update handle="my_handle_name"/>
</adminhtml_sales_order_shipment_new>

Magento not displaying custom block

I'm trying to have just a little "hello world" like module to learn how to make modules. I've got a fairly fresh install of Magento 1.7 on a Mac OSX 10.6 local server. I'm following Pierrefay's Turtorial and I cant get the block to display. I've been all over the web, but nothing has worked. The module's page just shows the default look with the 'dog' and the 'Back to School' ad. I've got Alan's Layoutviewer module. I'm currently in debug mode and emptying the cache like mad. I have already told Mag. not to cache anything,anyway. I've managed to reach the point where I'm not generating error messages (I'm also in debug mode and have execption.log and system.log pulled up).
My Controller:
<?php
class Nationwide_Cartonplugin_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction ()
{
$this->loadLayout();
$this->renderLayout();
//var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
//exit("bailing early at ".__LINE__." in ".__FILE__);
//echo "Carton Exists";
//Mage::log(
// $this->getLayout()->getUpdate()->getHandles(),
// null, ‘layout.log’ );
//Mage::log(
// $this->getLayout()->getUpdate()->asString(),
// null, ‘layout.log’ );
}
public function mamethodeAction ()
{
echo 'test mymethod';
}
}
My Config:
<?xml version="1.0"?>
<config>
<modules>
<Nationwide_Cartonplugin>
<version>1.1.0</version>
</Nationwide_Cartonplugin>
</modules>
<global>
<blocks>
<cartonplugin>
<class>Nationwide_Cartonplugin_Block</class>
</cartonplugin>
</blocks>
</global>
<frontend>
<routers>
<cartonplugin>
<use>standard</use>
<args>
<module>Nationwide_Cartonplugin</module>
<frontName>carton</frontName>
</args>
</cartonplugin>
</routers>
<layout>
<updates>
<cartonplugin>
<file>carton.xml</file>
</cartonplugin>
</updates>
</layout>
</frontend>
</config>
My Layout: (frontend/default/nationwide/layout/carton.xml)(I'm using default & nationwide in the admin setup)
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="content">
</reference>
</default>
<cartonplugin_index_index>
<reference name="content">
<block output="toHtml" type="cartonplugin/myblock" name="myblock"
template="cartonplugin/cartondisplay.phtml"/>
</reference>
</cartonplugin_index_index>
</layout>
Uncomenting the references generate a "not valid template" error.
My Template: (frontend/default/nationwide/template/cartonplugin/cartondisplay.phtml)
<?php
//echo $this->methodcarblock();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello World</title>
<style type="text/css">
body {
background-color:#f00;
}
</style>
</head>
<body>
<div class="test1">
<?php echo $this->methodcarblock(); ?>
</div>
</body>
</html>
My block:
<?php
class Nationwide_Cartonplugin_Block_Myblock extends Mage_Core_Block_Template
{
public function methodcarblock()
{
return 'informations about my block !!';
}
}
It seems I follow everying on the web and nothing still works, other than echoing from the index action. I would greatly appreciate any help.
You are getting no errors when uncommenting because Magento just doesn't try to call the block :) So this a silent error...
Indeed, as says the error, Magento is trying to reach file frontend/base/default/template/cartonplugin/cartondisplay.phtml which means that your design configuration is (I guess) not correct if the file frontend/default/nationwide/template/cartonplugin/cartondisplay.phtml really exists.
So, are you sure your package / theme is correctly configured in the system configuration, design tab? Make sure that package is "default" and theme templates is "nationwide".
Something like the picture below is a good configuration to tell Magento to call templates that reside in frontend/default/nationwide/template/ instead of frontend/base/default/template/ (may need some fine tuning depending on your existing configuration and store views)
At a glance, change
<block type="cartonplugin/myblock" name="myblock" template="cartonplugin/cartondisplay.phtml"/>
to
<block output="toHtml" type="cartonplugin/myblock" name="myblock" template="cartonplugin/cartondisplay.phtml"/>
This is necessary because Mage_Core_Controller_Varien_Action::renderLayout() assumes an output block has been set as an entry point for rendering. Typically setting an output block and method is not necessary because the root block defined in page.xml is an output block.

Magento: Add content block at the end of the structual block "content"

I'm trying to add a content block to Magento, which should be visible on every side below the main content. I want to archive this with a custom extension, so I can copy this extension and it workes without touching core design files.
My extension includes the following layout update:
<default>
<reference name="content">
<block type="mymod/blockname" name="myblockname" after="-" template="mymod/block.phtml"/>
</reference>
</default>
My problem is, that the attribute after="-" is not working. The block always showes up at the top of the content block. Seems before and after have no consequence.
If I move the block to i.e. footer, the attributes before and after are working fine.
How can I place my block at the bottom of block "content"
As far as I can see the problem is that you specify your block in the "default" layout handle while most of the content in the "content" block is added by other layout handles which are applied later. That's why the added dependencies in your XML registration file (mentioned by Fabian) are not helping.
Please consider these two options depending on your needs:
1. If you really want to include your block on all frontend pages
In your XML layout file (local.xml or a custom one), add a new layout handle:
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<!-- your other adjustments for default, category_product_view and so on go here -->
<add_my_block>
<reference name="content">
<block type="mymod/blockname" name="myblockname" after="-" template="mymod/block.phtml"/>
</reference>
</add_my_block>
</layout>
Now you create an event observer to inject your layout handle into your layout:
<?php
class YourCompany_YourExtension_Model_Observer
{
/**
* Adds a block at the end of the content block.
*
* Uses the event 'controller_action_layout_load_before'.
*
* #param Varien_Event_Observer $observer
* #return YourCompany_YourExtension_Model_Observer
*/
public function addBlockAtEndOfMainContent(Varien_Event_Observer $observer)
{
$layout = $observer->getEvent()->getLayout()->getUpdate();
$layout->addHandle('add_my_block');
return $this;
}
}
Then you register the event observer in your XML extension configuration file (config.xml):
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<modules>
<YourCompany_YourExtension>
<version>0.0.1</version>
</YourCompany_YourExtension>
</modules>
<frontend>
<events>
<controller_action_layout_load_before>
<observers>
<mymod_add_block_at_end_of_main_content>
<type>singleton</type>
<class>mymod/observer</class>
<method>addBlockAtEndOfMainContent</method>
</mymod_add_block_at_end_of_main_content>
</observers>
</controller_action_layout_load_before>
</events>
<!-- declaring your layout xml etc. -->
</frontend>
<global>
<!-- declaring your block classes etc. -->
<models>
<mymod>
<class>YourCompany_YourExtension_Model</class>
</mymod>
</models>
</global>
</config>
Now your block should end up below the other blocks. I tested this successfully for the homepage, customer login page and category view page. If you have to exclude your block on a few pages, you can check in your event observer if the block should be excluded on that certain page.
2. If you want to include your block only on some pages
Add a layout handle to your XML layout file just as we did before but instead of creating and registering an event observer, just tell your XML layout file to use the custom layout handle in some areas:
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<catalog_category_default>
<update handle="add_my_block" />
</catalog_category_default>
<catalog_category_layered>
<update handle="add_my_block" />
</catalog_category_layered>
<cms_page>
<update handle="add_my_block" />
</cms_page>
<!-- and so on -->
<add_my_block>
<reference name="content">
<block type="mymod/blockname" name="myblockname" after="-" template="mymod/block.phtml"/>
</reference>
</add_my_block>
</layout>

Magento Adding a Block to an index Action Page

I am creating a module that will have its own page at mysite.com/memymodule/index/index
I want to add functionality from a template file from at templates/me/template.phtml
I have an index controller like this:
<?php
class me_mymodule_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
?>
I have a layout update mymodule.xml that looks like this:
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodule_index_index>
<reference name="content">
<block type="core/template" name="me.mymodule" template="me/template.phtml" />
</reference>
</mymodule_index_index>
</layout>
The frontName of the module is mymodule
When the page renders the content block is completely empty and the content of template.phtml is completely ignored.
Help much appreciated :-)
Try this Code within your Controller's Action -
var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
exit("Your Layout Path is ".__LINE__." in ".__FILE__);
This code tells you about the Tag which you need to create within Layout.xml.
Also check Config.xml that the Layout Update Section is correctly defined or not.
Hope it'll be beneficial for you.
THANKS

Resources