Skip to content

Move validation of Mage_Customer_Model_Address to another class #17

Closed
@stalniy

Description

@stalniy

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions