1

I work for a Pharmacy and we are trying to implement it so that when a customer checks out a prescription medication, they have to have a physical address on file. We have the standard Magento checkout controller, and then a custom controller loads after they go through that page if they have a prescription medication in their cart. My question is how can I make it so if they have no physical address on file, the page will produce an error message and will not allow them to continue unless adding a physical address to their user account.

Here is the code I have thus far, in the controller for the page:

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

1 Answer 1

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

}

For Notice

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

For success message

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

For a error message

Mage::getSingleton('core/session')->addError('Error Text...');
Sign up to request clarification or add additional context in comments.

1 Comment

i apologize that my answer didn't help you but i ll try to give to exact solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.