Extending the Magento OnePage checkout class

Extending the Magento OnePage checkout class

July 24, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Extending the Magento OnePage checkout class

Extending the Magento OnePage checkout class for newsletter subscriptions

Dear Simon,

Thank you for reaching out about extending the Magento OnePage checkout process to add an additional checkbox field for newsletter subscriptions via your new module. I’ll guide you through the final steps needed to ensure that Magento recognizes and uses your alternative save_billing method instead of the original one.

Understanding the configuration file structure

Before we dive into setting up the configuration, let me clarify the purpose of each file in your current setup:

  • layout file (billing.phtml): This file is responsible for rendering the billing section of the checkout page. You’ve already added the checkbox field to this layout file.

    <p>Please untick this box if you do not wish to receive infrequent email updates and newsletters from us.
      <input type="checkbox" name="billing[is_subscribed]" title="" value="1" id="billing:is_subscribed"
             class="checkbox" checked="checked" />
    </p>
    
  • Extended class (app/code/local/Clientname/Checkout/Model/Type/Onepage.php): In this file, you’ve extended the save_billing method of the original Magento OnePage checkout model. You’ve implemented the logic to subscribe users to your newsletter when they check the box.

if (isset($data['is_subscribed'])) {
    $status = Mage::getModel('newsletter/subscriber')->subscribe($data['email']);
}
  • Module definition file (app/etc/modules/Clientname_Checkout.xml): This XML file tells Magento that your module is active and belongs to the local code pool.
<config>
  <modules>
    <Clientname_Checkout>
      <active>true</active>
      <codePool>local</codePool>
    </Clientname_Checkout>
  </modules>
</config>

Configuring Magento to use your extended class

To make Magento recognize and use your alternative save_billing method, you need to create a configuration file at /app/code/local/Clientname/config.xml.

Here’s an example of what this file should look like:

<config>
  <modules>
    <Clientname_Checkout>
      <version>1.0.0</version>
    </Clientname_Checkout>
  </modules>

  <global>
    <models>
      <checkout>
        <rewrite>
          <type_onepage>
            Clientname_Checkout_Model_Type_Onepage
          </type_onepage>
        </rewrite>
      </checkout>
    </models>
  </global>
</config>

In this configuration file:

  1. We specify the version number of your module under <version>.

  2. Under <models> and <checkout>, we use the <rewrite> tag to tell Magento that our Type_Onepage model should replace the original one.

  3. Under <global>, we define the actual rewrite by mapping the original model (type_onepage) to your extended model (Clientname_Checkout_Model_Type_Onepage).

This configuration tells Magento to use your extended class instead of the default one when processing the checkout billing step.

Summary and final steps

In summary, you’ve done an excellent job so far in extending the save_billing method of the OnePage checkout class and adding a new checkbox field for newsletter subscriptions. By creating the configuration file at /app/code/local/Clientname/config.xml as shown above, Magento will recognize your extended class and use it instead of the default one during the billing step.

Remember to clear your cache after making these changes by running the following command in your terminal:

php -f shell/indexer.php reindexall

This will ensure that Magento recompiles its configuration and uses your new model for the OnePage checkout process.

If you face any further issues or need additional assistance, please don’t hesitate to reach out. I’m here to help!

Best regards,

[Your Name] Technical Blogger at Laravel Company

Checkout Extensions Themes Configuration

Our network