Before continuing I would like to state that I have been looking for over a week through StackOverFlow, StackExchange, Google, and Alan Storm blogs.
Please don't link to another post I've most likely read it, instead just view my code and compare it to whatever you want to link and tell me why their way works and mine doesn't.
QUESTION: I want to add an attribute to all customers either an Object that has 3 Keys and 3 Values OR 3 separate values. Here is my Setup so far.
app/code/local/Sean/CustomerAddCustomAttr/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Sean_CustomerAddCustomAttr>
<version>0.1.1</version>
</Sean_CustomerAddCustomAttr>
</modules>
<global>
<resources>
<CustomerAddCustomAttr_setup>
<setup>
<module>Sean_CustomerAddCustomAttr</module>
<class>Sean_CustomerAddCustomAttr_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</CustomerAddCustomAttr_setup>
<CustomerAddCustomAttr_write>
<connection>
<use>core_write</use>
</connection>
</CustomerAddCustomAttr_write>
<CustomerAddCustomAttr_read>
<connection>
<use>core_read</use>
</connection>
</CustomerAddCustomAttr_read>
</resources>
</global>
</config>
app/code/local/Sean/CustomerAddCustomAttr/Model/Resource/Eav/Mysql4/Setup.php
<?php
class Sean_CustomerAddCustomAttr_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup {
}
app/code/local/Sean/CustomerAddCustomAttr/sql/CustomerAddCustomAttr_setup/mysql4-install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'silver', array(
'type' => 'int',
'input' => 'int',
'label' => 'Silver Membership',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 0,
'default' => "",
'visible_on_front' => 0,
'source' => NULL,
));
$setup->addAttribute('customer', 'gold', array(
'type' => 'int',
'input' => 'int',
'label' => 'Gold Membership',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 0,
'default' => "",
'visible_on_front' => 0,
'source' => NULL,
));
$setup->addAttribute('customer', 'platinum', array(
'type' => 'int',
'input' => 'int',
'label' => 'Platinum Membership',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 0,
'default' => "",
'visible_on_front' => 0,
'source' => NULL,
));
$installer->endSetup();
I've tested and it gets to my installation page because I tried die("We made it to the installation!) at the top and that showed.
However when I run
$customer = Mage::getSingleton('customer/customer'); var_dump($customer); The current customer and all other customers don't have the Silver Gold and Platinum attributes :/
I can see that the customer doesn't have any new attributes :( Can anyone explain why? Or see an error in my code? I've tried deleting the CustomerAddCustomAttr_setup table and refreshing/clearing the Magento Cache but no cigar :/
I have read the following: http://alanstorm.com/magento_models_orm http://alanstorm.com/magento_controller_hello_world http://excellencemagentoblog.com/blog/2011/10/02/customer-registration-fields-magento1-6/ https://stackoverflow.com/questions/26732761/magento-create-new-customer-attribute Adding custom attribute to Customer http://excellencemagentoblog.com/blog/2011/10/02/customer-registration-fields-magento1-6/ http://www.magecorner.com/adding-custom-customer-attributes/
install-0.0.1.php
, and did not add it after you added the<customerattribute_setup>
node to your config.xml, yes.