0

I am trying to add a customer attribute Mobile in customer_entity_varchar and It's not working. I can't see my attribute in eav_attribute table. Here are my codes.

local/Vaibhav/Mobile/etc/config.xml

<?xml version="1.0"?>    
<config>
        <modules>
            <Vaibhav_Mobile>
                <version>0.1.0</version>
            </Vaibhav_Mobile>
        </modules>
        <global>
            <resources>
                <Vaibhav_Mobile_setup>
                    <setup>
                        <module>Vaibhav_Mobile</module>
                        <class>Mage_Customer_Model_Entity_Setup</class>
                    </setup>
                    <connection>
                        <use>core_setup</use>
                    </connection>
                </Vaibhav_Mobile_setup>
                <Vaibhav_Mobile_write>
                    <connection>
                        <use>core_write</use>
                    </connection>
                </Vaibhav_Mobile_write>
                <Vaibhav_Mobile_read>
                    <connection>
                        <use>core_read</use>
                    </connection>
                </Vaibhav_Mobile_read>
            </resources>
        </global>
    </config>

local/Vaibhav/Mobile/sql/vaibhav_mobile_setup/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);

$installer->addAttribute("customer", "mobile",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Mobile",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => "Mobile"

        ));

        $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "mobile");


$setup->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'mobile',
    '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();

etc/modules/Vaibhav_Mobile.xml

<?xml version="1.0"?>
    <config>
        <modules>
            <Vaibhav_Mobile>
                <active>true</active>
                <codePool>local</codePool>
                <version>0.1.0</version>
            </Vaibhav_Mobile>
        </modules>
    </config>

I can't see any error also. Can anyone help me out with this issue?

5
  • check core_resource table what version of your module? Feb 27 '17 at 7:09
  • @PrasantaHatui I can't see in core_resource table also. It's very weird. However, I can see in the admin panel -> system -> configuration -> advance Feb 27 '17 at 7:14
  • Please ensure your script was executed or not Feb 27 '17 at 7:16
  • You can try to create an upgrade script Feb 27 '17 at 7:17
  • @PrasantaHatui I have tried with upgrade script also. Feb 27 '17 at 7:19
1

Change your config.xml file like this:

<?xml version="1.0"?>    
<config>
    <modules>
        <Vaibhav_Mobile>
            <version>0.1.0</version>
        </Vaibhav_Mobile>
    </modules>
    <global>
        <resources>
            <vaibhav_mobile_setup>
                <setup>
                    <module>Vaibhav_Mobile</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
            </vaibhav_mobile_setup>
        </resources>
    </global>
</config>

Relevant change which you need to notice here is change of resource node. Here it is changed to vaibhav_mobile_setup instead of Vaibhav_Mobile_setup, which is important in order to correctly point towards your install script location.

After these changes made, you need to clear all cache and remove the entry corresponds to your module from core_resource table if it exists.

EDIT

It is always a good habit to define your own setup resources for your module. Here you are trying to reuse Mage_Customer_Model_Entity_Setup resource class, which has no issue in use case. But it is always better to define your own setup resource class, let's say Vaibhav_Mobile_Model_Customer_Setup and which then inherits from Mage_Customer_Model_Entity_Setup.

8
  • Should I create Model Class also? As of now there is no Model Class. Feb 27 '17 at 7:18
  • You can avoid that in that case. Feb 27 '17 at 7:22
  • Just now I made the changes as you said. Still, I can't find in core_resource Feb 27 '17 at 7:25
  • okay. put your site in development mode and try again. Also look for any log errors in var/log folder. Also please see my edit. Feb 27 '17 at 7:28
  • Also in your further check. Put a die() call in your install script. It is the best way to check whether your install script is working or not Feb 27 '17 at 7:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.