如何通过转换适配器在导入过程中显示通知或成功消息?

时间:2016-04-21 13:39:37

标签: php magento magento-1.9

如何在转换适配器导入期间显示通知或成功消息?

我只能通过

显示错误
  

法师:: throwException($消息)

。 负责此操作的班级是 Mage_Adminhtml_Block_System_Convert_Profile_Run

1 个答案:

答案 0 :(得分:1)

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());
}