简体   繁体   中英

How to display notice or success message during the import by Convert Adapter?

How to display notice or success message during the import by the Convert Adapter ?

I can only display error by

Mage::throwException($message)

. Class responsible for this is Mage_Adminhtml_Block_System_Convert_Profile_Run .

Magento actually have some kind a session message stack. (Something quite similar to the message bags you can find, for example on Symphony).

Those are quite easy to use, just get the session associated to the area you are in and use on of the functions addError , addWarning , addNotice or addSuccess .

Since you are on the data flow module, the session you are looking to is dataflow/session . Take care to get this model via a singleton otherwise, you will end up with odd multiple sessions.

Mage::getSingleton('dataflow/session')->addSuccess($this->__('This will add a success message'));

The other are :

Mage::getSingleton('dataflow/session')->addNotice($this->__('This a notice'));
Mage::getSingleton('dataflow/session')->addWarning($this->__('That a warning'));
Mage::getSingleton('dataflow/session')->addError($this->__('And finally an error'));

And the reason you actually get an error message when you throw an exception, is because somewhere on Magento core, there is a

try {
    // the code or class instantiation on which you throw your exception happens here
} catch (Mage_Core_Exception $e) {
    Mage::getSingleton('dataflow/session')->addError($e->getMessage());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM