I'm trying to create a Wholesale: Yes/No drop down attribute on customer accounts in the admin. After creating my module and install script, I get the following error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'mycompany_wholesale_setup' for key 'PRIMARY'
Here is what I tried:
app/etc/modules/Mycompany_Wholesale.xml
<?xml version="1.0"?> <config> <modules> <Mycompany_Wholesale> <active>true</active> <codePool>local</codePool> <version>0.1.0</version> </Mycompany_Wholesale> </modules> </config> app/code/local/Mycompany/Wholesale/etc/config.xml
<?xml version="1.0"?> <config> <modules> <Mycompany_Wholesale> <version>0.1.0</version> </Mycompany_Wholesale> </modules> <global> <resources> <mycompany_wholesale_setup> <setup> <module>Mycompany_Wholesale</module> <class>Mage_Customer_Model_Entity_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </mycompany_wholesale_setup> <Mycompany_Wholesale_write> <connection> <use>core_write</use> </connection> </Mycompany_Wholesale_write> <Mycompany_Wholesale_read> <connection> <use>core_read</use> </connection> </Mycompany_Wholesale_read> </resources> </global> </config> app/code/local/Mycompany/Wholesale/sql/mycompany_wholesale_setup/mysql4-install-0.1.0.php
<?php $installer = $this; $installer->startSetup(); $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $entityTypeId = $setup->getEntityTypeId('customer'); $attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId); $attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); $setup->addAttribute("customer", "wholesale", array( "type" => "int", "backend" => "", "label" => "Wholesale", "input" => "select", 'source' => 'eav/entity_attribute_source_boolean', "visible" => true, "required" => false, "default" => "", "frontend" => "", "unique" => false, "note" => "Wholesale" )); $attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "wholesale"); $setup->addAttributeToGroup( $entityTypeId, $attributeSetId, $attributeGroupId, 'wholesale', '999' //sort_order ); $used_in_forms=array(); $used_in_forms[]="adminhtml_customer"; //$used_in_forms[]="checkout_register"; //$used_in_forms[]="customer_account_create"; //$used_in_forms[]="customer_account_edit"; //$used_in_forms[]="adminhtml_checkout"; $attribute->setData("used_in_forms", $used_in_forms) ->setData("is_used_for_customer_segment", true) ->setData("is_system", 0) ->setData("is_user_defined", 1) ->setData("is_visible", 1) ->setData("sort_order", 100) ; $attribute->save(); $installer->endSetup(); Any idea what I did wrong or how I can fix the Duplicate entry error? I should also note that I don't have direct access to the DB