Search

Aug 18, 2015

Set type customer ( group_id ) from register form in Magento

Step 1: Go to admin -> System -> Config (default) -> Customer Config -> Create new account options (tab) -> Enable Automatic Assignment to Customer Group ( Set = No ) -> Save

Step 2: Edit file ../../Customer/controllers/AccountController.php (from Core file or Module file) 

public function createPostAction()
{
    .....
    $customer = $this->_getCustomer();

    // Start Mod

    if ($this->getRequest()->getPost('group_id')){
        $customer->setGroupId(intval($this->getRequest()->getPost('group_id')));
    } else $customer->getGroupId();

    // End Mod

    ......
    $customer->save();
    ......
}


Step 3: Create register form with name="group_id"

<div class="form-group">
    <label class="radio-inline" for="group_id">
        <input type="radio" name="group_id" value="3">Retailer</label>
    <label class="radio-inline" for="group_id">
        <input type="radio" name="group_id" value="4">Designer</label>
    <label class="radio-inline" for="group_id">
        <input type="radio" name="group_id" value="5">Hospitality</label>    
</div>

Aug 11, 2015

Create custom attribute in magento

Lưu ý: tên biến không được có số app/local/customerAttribute/sql/custom_setup/mysql4-install-0.1.0.php
$installer->addAttribute("customer", "fix_state_issued_by",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "State Issued By",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

));

$attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "fix_state_issued_by");
$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->addAttribute("customer", "fix_resale_expired",  array(
    "type"     => "datetime",
    "backend"  => "eav/entity_attribute_backend_datetime",
    "label"    => "Expiration Date",
    "input"    => "date",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

));

$attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "fix_resale_expired");
$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();