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...');
我在一家药房工作,我们正在努力实施它,以便当客户检查处方药时,他们必须有一个实际地址存档。我们有标准的 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...');