我为药房工作,我们正在努力实施它,以便当客户检查处方药时,他们必须有一个物理地址存档。我们有标准的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());
}
答案 0 :(得分:2)
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...');