Magento向控制器添加错误消息


Magento Add Error Message To Controller

我在一家药房工作,我们正在努力实现它,这样当客户检查处方药时,他们必须在文件中有一个物理地址。我们有标准的Magento结账控制器,如果他们的购物车里有处方药,那么在他们浏览该页面后会加载一个自定义控制器。我的问题是,如果他们的文件中没有物理地址,页面将产生错误消息,除非向用户帐户添加物理地址,否则不允许他们继续。

这是我迄今为止在页面控制器中的代码:

    public function checkAddressOnFile()
    {
        return (bool) count(array_filter(Mage::getSingleton('customer/session')->getCustomer()->getAddresses(), function($address) {
            return !preg_match("(?i)^''s*((P(OST)?.?''s*(O(FF(ICE)?)?)?.?''s+(B(IN|OX))?)|B(IN|OX)", $address);
        }));
            Mage::getSingleton('core/session')->addError('Unfortunately we are required to have a physical address on file when shipping any controlled medications. Please note that although we are required to have a physical address on file, we still ship to PO Boxes. We sincerely apologize for the inconvenience.' . $e->getMessage());
    }
public function checkAddressOnFile()
{
    return (bool) count(array_filter(Mage::getSingleton('customer/session')->getCustomer()->getAddresses(), function($address) {
        Mage::getSingleton('core/session')
          ->addError('Unfortunately we are required to have a physical address on file when shipping any controlled medications. Please note that although we are required to have a physical address on file, we still ship to PO Boxes. We sincerely apologize for the inconvenience.' . $e->getMessage());
        return !preg_match("(?i)^''s*((P(OST)?.?''s*(O(FF(ICE)?)?)?.?''s+(B(IN|OX))?)|B(IN|OX)", $address);
    }));
}

通知

Mage::getSingleton('core/session')->addNotice('Notice Text...');

成功消息

Mage::getSingleton('core/session')->addSuccess('Success Text...');

对于错误消息

Mage::getSingleton('core/session')->addError('Error Text...');