How can we override abstract class in Magento?

How can we override abstract class in Magento?

August 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How can we override abstract class in Magento?

Overriding Abstract Classes in Magento: A Comprehensive Guide

When working on customizations for your e-commerce store built using Magento, there may come a time when you need to override an abstract class to make specific changes or modifications. One common scenario is overriding the Mage_Customer_Model_Address_Abstract class to disable telephone number validation.

Understanding Magento’s Class Hierarchy

Magento follows a model-view-controller (MVC) architecture, which means that most business logic and data operations are handled by models. These models are organized in a hierarchical structure, with abstract classes serving as the base for more specific implementations.

In this case, Mage_Customer_Model_Address_Abstract is an abstract class that provides core functionality for customer address management. It defines common properties and methods used across different address types like shipping and billing addresses.

The Traditional Approach: Direct File Copying

The traditional approach to overriding a Magento abstract class involves directly copying the original file from the core folder to your custom extension’s folder, usually named local. For example:

Original file location:

app/code/core/Mage/Customer/Model/Address/Abstract.php

Copied file location (traditional approach):

app/code/local/Téléphone/Customer/Model/Address/Abstract.php

This method allows you to modify the original code directly. However, it is not considered a good practice because:

  1. It violates Magento’s coding standards and best practices.
  2. It may lead to conflicts with future updates or upgrades of the core files.
  3. It makes your customizations difficult to manage and maintain.

The Correct Approach: Extension Inheritance

The recommended approach for overriding abstract classes in Magento is through inheritance using a custom extension. This involves creating a new model that extends the original abstract class and providing the desired modifications.

Here’s how you can achieve this:

  1. Create a new module folder under app/code/local with your custom namespace (e.g., Téléphone).
app/code/local/Téléphone
  1. Inside the module folder, create the necessary directories for models, etc. configurations.
app/code/local/Téléphone/Customer
    ├── Model
    │   └── Address
    └── etc
        └── config.xml
  1. Create a new file named Abstract.php inside the Address directory and extend the original abstract class:
<?php
class Telephone_Customer_Model_Address_Abstract extends Mage_Customer_Model_Address_Abstract
{
    public function validate()
    {
        // Your custom validation logic here, without telephone number validation
    }
}
  1. Update your config.xml file to define the new model in your extension:
<?xml version="1.0"?>
<config>
    <modules>
        <Telephone_Customer>
            <version>0.0.1</version>
        </Telephone_Customer>
    </modules>

    <global>
        <models>
            <telephone_customer>
                <class>Telephone_Customer_Model</class>
            </telephone_customer>

            <customer>
                <rewrite>
                    <address_abstract>Telephone_Customer_Model_Address_Abstract</address_abstract>
                </rewrite>
            </customer>
        </models>
    </global>
</config>

This approach allows you to override the abstract class while adhering to Magento’s coding standards and best practices. It provides a clean separation between your customizations and the core code, making your extensions more maintainable and upgrade-safe.

Conclusion

Overriding abstract classes in Magento requires a clear understanding of the platform’s architecture and proper implementation following the recommended approach. By creating a custom extension that extends the original class, you can make the desired modifications while maintaining the integrity and upgradability of your store.

Remember to always test your customizations thoroughly before deploying them to a live environment to ensure they work as expected without negative side effects on other core functionalities.

For more advanced Magento customization techniques and best practices, feel free to explore our Magento Development Resources at Laravel Company.

Extensions Customers

Our network