I am trying to debug external module in Magento. In that, when i logged in admin end, I have got pop up with some message and also got one notification message.Installed module generate the code for script to alert the popup message,div to display the notification. This HTML is generated and appended in DASHBOARD page which is having body class as " adminhtml-dashboard-index"
I guess there might be some way to push the generated code with dashboard page.
What are the possible ways to add external module notification or some html or generated js script with core module like DASHBOARD?
Hope you understand my question...
Thanks in advance
Here's one way to drop a block in there. Observe the adminhtml_block_html_before event:
<events>
<adminhtml_block_html_before>
<observers>
<super_adminhtml_block_html_before>
<class>super/observer</class>
<method>beforeAdminHtml</method>
</super_adminhtml_block_html_before>
</observers>
</adminhtml_block_html_before>
</events>
Then, create a new block and append it to the notifications block.
public function beforeAdminHtml($observer)
{
$block = $observer->getEvent()->getBlock();
if ($block->getNameInLayout() == 'root') {
$extendBlock = $this->_createMyNoticeBlock();
if ($extendBlock) {
$block->getChild('notifications')->append($extendBlock);
}
}
}
I used this to insert my own HTML block where the notifications usually show within the header - shows not only on the dashboard but on all the admin pages.
Related
I have a module that needs a canonical link injected into <head> on literally every page on frontend. Is there a way to do it? Currently, given my module doesn't need its own page on frontend, nor any controllers whatsoever, I have only set the helper in my config.xml. Now, I do have an xml in layout, but the problem is that I need to change canonical link attributes based on user input(in admin), so XML doesn't fit. Yes, I could indeed fopen said fronted layout xml file, then replace what I need, then write new content back to it, but I wanted to check first whether there's other way for achieving that.
You can hook in on the core_block_abstract_prepare_layout_before event and use the Head block's addLinkRel method to add the link tag.
In your config.xml you need to define an observer like so:
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<your_module>
<class>Your_Module_Model_Observer</class>
<method>addCanonicalLink</method>
</your_module>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
Create an observer class in the Model directory
<?php
class Your_Module_Model_Observer {
public function addCanonicalLink(Varien_Event_Observer $observer) {
$block = $observer->getData('block');
if ($block->getNameInLayout() === 'head') {
// this will add <link rel="canonical" href="http://your-url.com">
$block->addLinkRel('canonical', 'http://your-url.com');
// If you need more attributes on the link tag use addItem instead
// This will add <link rel="canonical" href="http://your-url" attr="Your Attribute">
// $block->addItem('link_rel', 'http://your-url', 'rel="canonical" attr="Your Attribute"')
}
}
}
Update:
Since the core head.phtml template files run echo $this->getChildHtml() (render all children) it is possible to insert tags by adding a core/text block as a child and add a text string to it (just like you already tried with xml). If addItem doesn't fit your needs, this is more flexible as you can insert any string this way. Replace thie $block->addLinkRel line with
$canonical = $block->getLayout()->createBlock('core/text')
->setText('<link rel="canonical" href="http://your-url.com">')
$block->append($canonical);
I want to display a line at this url of magento:
index.php/customer/account/create/
I tried to put event in config.xml, in my module...
(I am using custom local module to customize my magento)
<controller_action_predispatch_customer_account_create>
<observers>
<namespace_modulename_controller_action_predispatch_customer_account_create_observer>
<type>singleton</type>
<class>Namespace_Modulename_Model_Observer</class>
<method>onCustomerAccountCreateBefore</method>
</namespace_modulename_controller_action_predispatch_customer_account_create_observer>
</observers>
</controller_action_predispatch_customer_account_create>
And when I echo in the function, in observer.php,
public function onCustomerAccountCreateBefore (Varien_Event_Observer $observer)
{
Mage::log('function triggered',null,'logs.log');
echo 'test';
}
It successfully logs everything, and it prints test on the screen, but the problem is, it prints test on the top of screen, I don't want it to print test on top of screen but somewhere in the middle like before the register form, above the register form or below it, but not on top of screen...
I have created a magento plugin and I need to add custom notification to magento admin just below the admin menu where the LATEST and CRITICAL error are shown.
I have also tried the steps from this link https://www.openstream.ch/developer-blog/adding-magento-admin-notifications-to-your-extension/. The custom notification are not shown still.
What I need is to display my custom error notification in admin section default just like how other notifications are displayed.
Can anyone tell me the steps to do that?
I was also looking for the same solution. I decided to check opensource repositories and i happen to come across a working version of the "Openstream" turorial you had mentioned.
all you have to do is:
download the files from here
drop the files in your Magento app folder
edit the config.xml file with your feed address/directory
flush Magento cache
Refresh page and you should see your feed.
Here's another extension with similar features: custom notification
i haven't tried this one...
I hope one of these help you!
There is a singleton for that!
... } catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
add the exception or whatever you want. This doesn't need to be in a try catch.
Set Your Message.
Mage::getSingleton("core/session")->addSuccess("Add success message");
Mage::getSingleton("core/session")->addError(" Add error message");
Mage::getSingleton("core/session")->addNotice("Add notification message");
Display Your Message. (Optional If use custom Extension Or not Defined)
<?php echo $this->getChildHtml('global_messages'); ?>
3.Define Block in Layout. (Optional If use custom Extension Or not Defined)
<block type="core/messages" name="global_messages" as="global_messages"/>
I have a custom block within Magento Community which rewrites the Orders Tab in Adminhtml and replaces it with a Fullcalendar(arshaw.com's one) which displays events for when products are to be shipped.
I have implemented a JSON feed which relies on my custom modules controller to populate and save the data. This works beautifully and I can see the products once I click on Month / Today / Prev / Next. However, this is not how it should work. It should render when the page loads, except all I see are the buttons.
I have tried referencing the tab in javascript which it is in eg.
jQuery('#diagram_tab_orders_content').tabs({
show: function(event, ui) {
jQuery('#dashCalendar').fullCalendar('render');
}
Where #dashCalendar is the id / class of my tag.
Except this does not render the calendar. It does nothing but change the CSS of diagram_tab_orders_content.
I've seen a similar topic on Stackoverflow where you must explicitly reference the tab where the calendar is in order for it to render properly. This is what I'm trying to achieve in order for the calendar to render when the document is ready.
Any suggestions on how to make this calendar render when the document is ready would be much appreciated.
So I've figured out the issue with the calendar and it pertains to the tabs within Magento. Referencing the tabs explicitly within Javascript causes issues with the rendering, thus I had to rewrite the Dashboard block.
Config.xml in my ModuleName/etc folder:
<global>
<!-- Blocks -->
<blocks>
<adminhtml>
<rewrite>
<dashboard>ModuleName_Block_Adminhtml_Calendar</dashboard>
</rewrite>
</adminhtml>
</blocks>
</global>
Then within my ModuleName/Block/Calendar.php file I set the template:
public function __construct()
{ //this creates the template block for the calendar
parent::__construct();
$this->setId('Calendar');
$this->setTemplate('moduleName/calendar/calendar.phtml');
}
Copy/Paste the fullcalendar's JSON Example page provided, set your events: tag to your .php file which generates / requests data from your database using JSON. Customise your Theme if you want using the provided CSS and you will see the calendar render with the events when you log into your Adminhtml. Below you will see 'Populate'. Its an action within my Controller which retrieves the data and echo's out a JSON feed to the Calendar.
events: {
url: "<? echo $this->getUrl('moduleName/adminhtml_calendar/populate') ?>"
},
Now the Calendar renders with events properly.
What I want to achieve:
Clicking on a product link/image (at least in certain areas) to open a pop-up with the full product information (basically all the contents of the product view page).
What I did/tried so far:
created all the stuff outside the ajax php code (the module, links, templates, rewrites)
created the ajax controller (which can be accessed with a link similar to: http://test.com/index.php/ajaxproductview/ajax/index/id/2 ).
to follow various tutorials ( like this or this ) - that helped me get this far. But I don't want to load my custom block, I want the default product view block(s).
tried to add some code in the indexAction(). It gets there, but the code fails. I don't get any errors/notices/reports, just what it seems like an infinite loop that kills my processor.
$body = $this
->getLayout()
->createBlock('product.info') // taken from catalog.xml
->toHtml();
$this->getResponse()->setBody($body);
All the other pages work fine, and it's a fresh magento with only magneto and my module installed and activated.
My AJAX function simply gets this HTML response, puts it into a div, and opens a pop-up.
My question(s) is(are) - how can I set the product id, so the block knows what product to load, and how can I load this block correctly. I also tried something similar to this:
Thank you.
PS: I also tried this:
$layout = $this->getLayout();
$update = $layout->getUpdate();
$update->load('catalog_product_view');
$layout->generateXml();
$layout->generateBlocks();
$output = $layout->getOutput(); // $output is an empty string
The Product controller uses a helper to set the active product. You should be able to do the same in your controller!
Try this before you do your layouting:
$productId = (int) $this->getRequest()->getParam('id');
Mage::helper('catalog/product')->initProduct($productId, $this);
Another thing to be aware of:
If you add a block like the product.info block. It needs additional child blocks if it calls them in its template file.
It would be easiest to use a custom layout xml file. You can then add a specific layout for your action handle (your action handle consists of your routers node in your module's etc/config.xml file under <frontend><routers>, e.g. <Yourmodule> node, make sure to lowercase it! And then with underscores add the controller name and action name, in your case index_index) like this:
<yourmodule_index_index>
<remove name="right"/>
<remove name="left"/>
<block type="catalog/product_view" name="root" output="toHtml" template="catalog/product/view.phtml">
<!-- Add all the child blocks you need -->
</block>
</yourmodule_index_index>
This makes the view.phtml the root block which renders itself using its toHtml method.
Therefore, in your controller action, all you need is my two lines above and then:
$this->loadLayout();
$this->renderLayout();