0

I had a custom module Vendor_CustomerAccountExtended for customer modifications. Now I wanted to add there a custom attribute for customer(avatar). The problem is that I can create that attribute only if I delete that module from core_resource. What I have to do to create that attribute without this action? Before I start to modify that module I had only config.xml and AccountController. After that I added new lines of code in AccountController and the next files: etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Vendor_CustomerAccountExtended>
      <version>1.0.1</version>
    </Vendor_CustomerAccountExtended>
  </modules>

  <global>
    <helpers>
        <vendor_customeraccountextended>
            <class>Vendor_CustomerAccountExtended_Helper</class>
        </vendor_customeraccountextended>
    </helpers>
    <resources>
        <vendor_customeraccountextended_setup>
            <setup>
                <module>Vendor_CustomerAccountExtended</module>
                <class>Mage_Customer_Model_Resource_Setup</class>
            </setup>
        </vendor_customeraccountextended_setup>
    </resources>
  </global>
 
  <frontend>
    <layout>
      <updates>
          <vendor_customeraccountextended>
              <file>vendor_customeraccountextended.xml</file>
          </vendor_customeraccountextended>
      </updates>
    </layout>
    <translate>
      <modules>
          <Vendor_CustomerAccountExtended>
              <files>
                  <default>Vendor_CustomerAccountExtended.csv</default>
              </files>
          </Vendor_CustomerAccountExtended>
      </modules>
    </translate>
    <routers>
      <customer>
        <args>
          <modules>
            <Vendor_CustomerAccountExtended before="Mage_Customer">Vendor_CustomerAccountExtended</Vendor_CustomerAccountExtended>
          </modules>
        </args>
      </customer>
    </routers>
  </frontend>
</config>

helper/Data.php

<?php
class Vendor_CustomerAccountExtended_Helper_Data extends Mage_Core_Helper_Abstract
{

}

sql/vendor_customeraccountextended_setup/upgrade-1.0.0-1.0.1.php

<?php
$this->addAttribute('customer', 'user_avatar', array(
    'type'      => 'varchar',
    'label'     => 'Avatar',
    'input'     => 'file',
    'position'  => 10,
    'required'  => false,//or true
    'is_system' => 0,
));
$attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'user_avatar');
$attribute->setData('used_in_forms', array(
    'adminhtml_customer',
    'checkout_register',
    'customer_account_create',
    'customer_account_edit',
));
$attribute->setData('is_user_defined', 0);
$attribute->save();
1
  • How do you come to the conclusion that you need to remove the module? You don't have to. Just clear caches. Config.xml is cached in Magento, and if you use Redis, you have to flush Redis first (if required, via redis-cli -h localhost flushall)
    – MLGS
    Jun 11 at 0:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.