Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6147999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:12:13+00:00 2026-05-23T19:12:13+00:00

I’d like to be able to save the value of an attribute without saving

  • 0

I’d like to be able to save the value of an attribute without saving it’s parent entity. I have created a new customer attribute via my module’s sql/setup file (ref), and now I want to populate that attribute for each of the existing customers. I’ve created a Backend model for the attribute that detects null values during the entity load (afterLoad) and generates the content, but I am hesitant to save the entity at that point in the process.

class Aligent_Referral_Model_Customer_Attribute_Backend_Referralcode extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
public function afterLoad($oCustomer)
{
    $vAttrCode = $this->getAttribute()->getAttributeCode();
    $vValue = $oCustomer->getData($vAttrCode);
    if (empty($vValue)){
        $oCustomer->setData($vAttrCode, Mage::helper('referral')->generateRafCode($oCustomer));
    }
    return $this;
}
}

Ideally, I’d like to call something like $this->getAttribute()->setValue('blah')->save() in that afterLoad method so that it doesn’t rely on the user clicking save.

I could write a script that loads a collection of all customers and walks them to set the value, but there’s over 50,000 customers and I’m concerned about the performance impact of running that on a production server…

Any thoughts appreciated.
JD

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:12:15+00:00Added an answer on May 23, 2026 at 7:12 pm

    So one option that works it to write directly to the database. This isn’t particularly elegant but quite effective in achieving the “lazy-load” approach to populating a new attribute for existing customers (or other entities). Here is the additional code in the Attribute_Backend_Referralcode to what I posted in the question:

    $vAttrValue = 'some string';
    $oCustomer->setData($vAttrCode, $vAttrValue);
    $iAttrId = $this->getAttribute()->getAttributeId();
    $data = array(
                'entity_type_id' => $oCustomer->getEntityTypeId(),
                'attribute_id' => $iAttrId,
                'entity_id' => $oCustomer->getId(),
                'value' => $vAttrValue,
            );
    $vTableName = $this->getAttribute()->getBackend()->getTable();
    Mage::getResourceModel('table/alias')->getWriteAdapter()->insert($vTableName, $data);
    

    It requires exposing a public method to get the Write Adapter on the Mysql4 model, but no big deal there.

    Still interested to know if there is an approach that uses the EAV model layer better…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.