
In magento there are some validations which are specified in Mage_Customer_Model_Address_Abstract class and in some cases you might need to change or remove these validations. Overriding abstract class can be tricky in Magento and not recommended as well because the abstract class can be used by quite few classes so impact of changing abstract class is quite high.
But the good news is that you can do this without overwriting abstract class, today we are going to see how can we achieve this.
See below our step by step implemetation -:
Step 1
Create a module under local folder i.e. app/code/local/Scommerce/Validation
Step 2
Register your module by creating Scommerce_Validation.xml under etc/modules directory by adding the following content -:
<Scommerce_Validation>
<active>true</active>
<codePool>local</codePool>
<Scommerce_Validation>
Step 3
Now create a config.xml under your module directory i.e. app/code/local/Scommerce/Validation/etc
<?xml version="1.0"?>
<config>
<modules>
<Scommerce_Validation>
<version>0.0.1</version>
</Scommerce_Validation>
</modules>
<global>
<models>
<scommerce_validation>
<class>Scommerce_Validation_Model</class>
</scommerce_validation>
<customer>
<rewrite>
<address>Scommerce_Validation_Model_Address</address>
</rewrite>
</customer>
</models>
</global>
</config>
Step 4
Now create Address.php inside the model directory of your module i.e. app/code/local/Scommerce/Validation/Model
<?php
class Scommerce_Validation_Model_Address extends Mage_Customer_Model_Address
{
public function validate()
{
$errors = parent::validate();
$helper = Mage::helper('customer');
$stateError = $helper->__('Please enter the state/province.');
if(in_array($stateError, $errors)) {
unset($errors[array_search($stateError, $errors)]);
}
if (empty($errors)) {
return true;
}
return $errors;
}
}
You might have noticed that instead of overriding abstract class, we have overridden address class which is actually calling validate function of the abstract class. This is the most efficient way of dealing with abstract classes in magento. Always try not to override abstract class and find out the child classes which are calling abstract class if you can get around the way we did it above.
Hope you like our implementation but if you have better way than this then please don’t hesistate to share with us. Thanks.



Too useful as every site has its own requirement and validations accordingly. Something which is used very frequently, this article saved my effort and worked straight way.. Great one.
a friend recommended this website to me, he said that your posts are the best so i came to read your post and realized he was right. congratulations for writing so well.
Howdy. Very nice site!! Guy .. Excellent .. Wonderful .. I will bookmark your web site and take the feeds also…I am glad to locate so much useful information here in the post. Thank you for sharing.
Adding this to twitter great info.
Thanks for any other wonderful post. Where else may anyone get that kind of info in such an ideal approach of writing? I have a presentation subsequent week, and I’m on the search for such information.
I simply want to mention I’m very new to weblog and really savored your web page. Most likely I’m going to bookmark your blog . You really come with fantastic well written articles. Many thanks for revealing your web site.
I simply want to mention I am very new to blogging and seriously savored this web-site. Likely I’m planning to bookmark your blog post . You amazingly have awesome articles and reviews. Cheers for sharing with us your web-site.
I like your point of view. Like a problem-solver
I simply want to say I absolutely loved your blog. You actually come with superb articles. Thanks a bunch for sharing with world your web site!!!!
Thanks for posting this.. It’s been a pleasure to read 🙂
I simply want to mention I’m newbie to weblog and definitely enjoyed you’re blog site. Most likely I’m planning to bookmark your website . You certainly have amazing posts. Cheers for sharing with us your web-site.
Good information. thanks for posting!
You absolutely come with awesome articles. Thanks a bunch for sharing your web-site.
Oh my goodness! an incredible post dude. Thank you Still I’m experiencing problem with ur rss . Do not know why Unable to subscribe to it. Is there any individual obtaining identical rss problem? Anyone who knows kindly respond. Thnkx
WONDERFUL Post.thanks for share!!!