0

I still cannot figure out how to display the dropdown on the customer registration form at app/design/frontend/base/default/template/persistent/customer/form/register.phtml

Any ideas how?

Setup file:

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


$installer->addAttribute("customer", "customer_group",  array(
    "type"     => "int",
    "backend"  => "",
    "label"    => "Customer Group",
    "input"    => "select",
    "source"   => "customerattribute/eav_entity_attribute_source_customeroptions15505846310",
    "visible"  => true,
    "required" => false,
    "default" => "Business",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

    ));

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


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

Source file:

<?php
class CustomerAttribute_Model_Eav_Entity_Attribute_Source_Customeroptions15505846310 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")->__("Business"),
                    "value" =>  1
                ),

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

                array(
                    "label" => Mage::helper("eav")->__("Institution"),
                    "value" =>  3
                ),

            );
        }
        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);
    }
}
0

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

Added dropdown input with your custom option. Magento can't automatically create the form for the frontend.

In your case:


<select name="customer_group" id="customer_group">
    <option value="1"><?php echo $this->__('Business')?></option>
    <option value="2"><?php echo $this->__('Personal')?></option>
    <option value="3"><?php echo $this->__('Institution')?></option>
</select>
3
  • Hi Sohel; i understand this, but how can I be sure that the selected value would update the value that has been previously set for the customer at the backend? – Julian Murillo Feb 20 '19 at 9:58
  • Registration is not for a new customer? How you set the value before registration? – Sohel Rana Feb 20 '19 at 10:03
  • The module has a default value; but the meaning is that customers can edit it when registering, or when accessing the customer account page or when checking out. – Julian Murillo Feb 20 '19 at 13:22

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.