0

I want to add a Drop-down option on my Magento E-commerce website's registration page.I have already seen a post here showing the steps to add a licence option on the registration page, I copied the same steps but in the end I failed as because I am not getting any drop-down option + I am getting a field name licence on my Magento admin Panel > Customer section.

Please if some one can guide me with the proper steps, as in how to add a new option on my registration page saying "where did you hear about us" and giving a drop-down option of like Facebook, Instagram, Google, Twitter, Others, etc. Please can some one help me with this.

0

Hi Here I have added Selection Box for Social Media in Register page

app/etc/modules/Custom_Register.xml

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

app/code/local/Custom/Register/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Custom_Register>
      <version>0.1.0</version>
    </Custom_Register>
  </modules>
  <global>
    <helpers>
      <register>
        <class>Custom_Register_Helper</class>
      </register>
    </helpers>
    <models>
      <register>
        <class>Custom_Register_Model</class>
        <resourceModel>register_mysql4</resourceModel>
      </register>
    </models>
    <resources>
      <customerattribute_setup>
        <setup>
          <module>Custom_Register</module>
          <class>Mage_Customer_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </customerattribute_setup>
      <customerattribute_write>
        <connection>
          <use>core_write</use>
        </connection>
      </customerattribute_write>
      <customerattribute_read>
        <connection>
          <use>core_read</use>
        </connection>
      </customerattribute_read>
    </resources>
  </global>
</config> 

app/code/local/Custom/Register/Helper/Data.php

<?php
class Custom_Register_Helper_Data extends Mage_Core_Helper_Abstract
{
}

app/code/local/Custom/Register/Model/Eav/Entity/Attribute/Source/Customeroptions.php

<?php
class Custom_Register_Model_Eav_Entity_Attribute_Source_Customeroptions extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    /**
     * Retrieve all options array
     *
     * @return array
     */
    public function getAllOptions()
    {
        if (is_null($this->_options)) {
            $this->_options = array(

                array(
                    "label" => Mage::helper("eav")->__("Facebook"),
                    "value" =>  1
                ),

                array(
                    "label" => Mage::helper("eav")->__("Instagram"),
                    "value" =>  2
                ),

            );
        }
        return $this->_options;
    }

    /**
     * Retrieve option array
     *
     * @return array
     */
    public function getOptionArray()
    {
        $_options = array();
        foreach ($this->getAllOptions() as $option) {
            $_options[$option["value"]] = $option["label"];
        }
        return $_options;
    }

    /**
     * Get a text for option value
     *
     * @param string|integer $value
     * @return string
     */
    public function getOptionText($value)
    {
        $options = $this->getAllOptions();
        foreach ($options as $option) {
            if ($option["value"] == $value) {
                return $option["label"];
            }
        }
        return false;
    }

    /**
     * Retrieve Column(s) for Flat
     *
     * @return array
     */
    public function getFlatColums()
    {
        $columns = array();
        $columns[$this->getAttribute()->getAttributeCode()] = array(
            "type"      => "tinyint(1)",
            "unsigned"  => false,
            "is_null"   => true,
            "default"   => null,
            "extra"     => null
        );

        return $columns;
    }

    /**
     * Retrieve Indexes(s) for Flat
     *
     * @return array
     */
    public function getFlatIndexes()
    {
        $indexes = array();

        $index = "IDX_" . strtoupper($this->getAttribute()->getAttributeCode());
        $indexes[$index] = array(
            "type"      => "index",
            "fields"    => array($this->getAttribute()->getAttributeCode())
        );

        return $indexes;
    }

    /**
     * Retrieve Select For Flat Attribute update
     *
     * @param int $store
     * @return Varien_Db_Select|null
     */
    public function getFlatUpdateSelect($store)
    {
        return Mage::getResourceModel("eav/entity_attribute")
            ->getFlatUpdateSelect($this->getAttribute(), $store);
    }
}

app/code/local/Custom/Register/sql/customerattribute_setup/mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();


$installer->addAttribute("customer", "socialmedia",  array(
    "type"     => "int",
    "backend"  => "",
    "label"    => "Social Media",
    "input"    => "select",
    "source"   => "register/eav_entity_attribute_source_customeroptions",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

    ));

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


$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();

Finally Add Selection Box in Frontend Page from

app/design/frontend/base/default/template/persistent/customer/form/register.phtml

| improve this answer | |
  • can you explain me step by step, as earlier post i saw it explained to make a custom extension. So how will i be doing the above process. Sorry i am very new – user66190 May 4 '18 at 11:18
  • please check with updated answer – Ravi Oza May 4 '18 at 12:24
  • can you tell me the last step, i means what code to be added in the register.phtml. thanks a lot for help – user66190 May 5 '18 at 5:27

Your Answer

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