-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move validation of Mage_Customer_Model_Address to another class #17
Comments
Address validation is implemented in Mage_Customer_Model_Address_Abstract::validate() without the ability to customize validation rules in order to guarantee presence of the required data for any payment method. For instance, last name field cannot be optional because some payment methods require value for it (for example, take a look at "Payer Information Fields" section of the PayPal doc https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoDirectPayment). |
What must i do if I dont want to use any online payment method or i want to use payment method that accept only one field - "name"? |
If you don't want to be compatible with online payment methods, as you mentioned previously, class Mage_Customer_Model_Address_Abstract can be rewritten to customize method validate(). |
If I want to customize standard checkout then i need to rewrite a lot of code. Because this method "validation" are called everywhere. I need to rewrite quote and quote addresses because class (alias) for quote addresses also hard coded in quote class and maybe some another classes. |
You said that customer class depends from payment methods. Do you think it's ok? |
Ok, the easiest solution: class Mage_Customer_Model_Address_Abstract {
public function validate() {
return this->getValidator()->validate($this);
}
public function setValidator(Mage_Core_Model_Validator_Interface $validator) {
$this->_validator = $validator;
}
public function getValidator() {
return $this->_validator ? $this->_validator : new Mage_Customer_Model_Address_Validator()
}
} And put logic from validate method to Mage_Customer_Model_Address_Validator class into method validate |
I 100% agree with this. Address validation should be a pluggable functionality. You could implement via an interface or an event. |
The feature was approved by the product management and added to the roadmap. However it's not scheduled yet for the execution. |
…h-issue [API] MAGETWO-31999: oAuth issue [from github]
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):
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
The text was updated successfully, but these errors were encountered: