Add new attribute to Magento quote/order

Add new attribute to Magento quote/order

July 10, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add new attribute to Magento quote/order

Adding New Attributes to Magento Quote/Order: A Developer’s Guide

Adding custom attributes to the quote or order objects is a common requirement when developing Magento extensions, especially for loyalty programs like the one you’re working on. In your case, you want to add a redeemed_points attribute to track how many points a customer has redeemed during checkout.

Understanding Magento EAV Structure

Magento uses an Entity-Attribute-Value (EAV) model to store and manage custom attributes efficiently across different entities. When you create a new attribute, it gets stored in the eav_attribute table with its configuration details.

In your scenario, you’ve already created the redeemed_points attribute using Magento’s EAV setup:

'quote' => array(
    'entity_model'  => 'sales/quote',
    'table'         => 'sales/flat_quote',
    'attributes'    => array(
        'redeemed_points'   => array('type' => 'static')
    ),
),

This configuration tells Magento to add the redeemed_points attribute to the quote entity (i.e., the quote object). The type: static means it won’t be saved in a separate table like other EAV attributes.

Adding the Attribute Column

You’ve also added the column to the sales_flat_quote table manually:

$installer->getConnection()->addColumn($installer->getTable('sales/flat_quote'), 'redeemed_points', 'bigint(20)');

This step ensures the physical column exists in the database to store your attribute’s value.

Saving Points to the Quote Object

Your code to save points looks correct:

public function savePoints($data)
{
    // Rest of the code...
    $this->getQuote()->setRedeemedPoints($redeemedPoints['points']);
    $this->getQuote()->collectTotals()->save();
}

You’re setting the redeemed_points attribute directly on the quote object and then saving it.

The Missing Piece: Serializing Attributes

The issue lies in how Magento serializes the quote data. When you debug the quote object using FirePHP, you’re looking at the raw serialized data that’s being saved to disk or sent back to the client.

When Magento saves the quote, it serializes the entire object into a format called Varien_Serialize_Data. The redeemed_points attribute is part of this serialized data but isn’t being “popped out” and added as an individual column in the sales_flat_quote table like you might expect.

How to Solve This

To ensure your custom attribute persists across quote saves, you need to manually add it back after deserializing:

  1. First, find where Magento is deserializing the quote data (usually in the sales/observer folder).

  2. Look for the save_order_after or save_quote_after event observers.

  3. In the observer’s execute function, unserialize the quote data and manually add your custom attribute to it:

$quote = Zend_Json_Decoder::decode($quote->getData('items'), true);

$quote['redeemed_points'] = $redeemedPoints['points'];
  1. Then serialize the updated quote data:
$quoteDataArray = Varien_Serialize_Data::serialize($quote);
  1. Finally, save this serialized array back to the sales_flat_quote table.

Conclusion

Adding custom attributes to Magento quotes requires a solid understanding of how the EAV model works and how Magento serializes and deserializes entity data. By manually adding your attribute back after deserialization, you can ensure it persists across quote saves.

Remember that working with serialized data in Magento can be complex, so always test thoroughly to prevent any unexpected behavior.

For a more detailed guide on working with custom attributes in Magento, consider visiting Laravel Company’s Magento development resources.

Checkout Database Extensions Configuration

Our network