Description
There is no ability to change validation rules for Mage_Customer_Model_Address (Mage_Customer_Model_Address_Abstract::validate). For example, I changed "is_required" field for attribute "lastname" to false and when i was trying to place order without lastname field i got an error: Please enter the last name.
I want to customize validate logic and there is only 2 bad ways (rewrite model, place the same file to app/code/local). I think the best solution is validator. Something like this should be (pseudo code):
class AddressForm {
public function __construct($model) {
$this->_configure();
$this->_fillByModel();
}
protected function _configure() {
$this->addField('firstname')->addValidator(new ValidatorEmpty());
....................................(the same for each field that i want to see in form and validate)
}
public function isValid() {
for each validator do {
$validator->validate();
}
return $result;
}
}
Usage:
$form = new AddressForm($quote->getBillingAddress());
if ($form->isValid()) {
$quote->getBillingAddress()->save();
}
I think that it's better if validation process is in controller then it will easy to change validation logic. More easy solution for you make checking address attributes for required flag and another rules