0

I need to register the customer into group B2B (id group 2)

Now... in register.phtml file I insert

<input type="hidden" name="group_id" id="group_id" value="2" />

but it does not work.

In the backend the customer does not have a group

why?

  • Can u please share location of register.phtml? – Amit Bera Oct 31 '16 at 15:30
  • /app/design/frontend/acquedilusso/acquedilusso-child/template/opc/customer/form the file is correct but the group not work – Alessandro Gnola Oct 31 '16 at 16:15
  • You need to register the attribute group_id in the table customer_form_attribute with form_code = customer_account_create. You can get the attribute_id of group_id in the table eav_attribute – kiatng Nov 1 '16 at 2:54
  • Please accept any of the answer, if it helped out to resolve your issue. – Rajeev K Tomy Nov 2 '16 at 16:28
1

I believe you are using a customer register.phtml file which holds a customer registration form. Now you already included your group_id as a hidden field like this:

<input type="hidden" name="group_id" id="group_id" value="2" />

Now it is very important to do following things in your controller action method that deals with this form POST.

public function createPost()
{
    //initialize customer model
    $customer = Mage::getModel('customer/customer');
    $post     = $this->getRequest()->getPost();
    //set customer group id if it exists in post.
    if (isset($post['group_id'])) {
        $customer->setData('group_id', $post['group_id'])
    }
    //this will set default customer group id, if group_id is not set to customer
    $customer->getGroupId();

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

As you can see above, before doing your $customer->save(), you should set customer group id in $customer model.

The best place to look into in this situation is Mage_Customer_AccountController::createPost() method. Specifically you need to go through following two calls in that method.

Hope you get the idea.

Tip: You should really avoid inserting customer group id as hidden field in your form. Since you already know the customer group that you want to set to customer, it is better to deal this in your controller method itself.

  • i solved the problem. it need to insert # into a class. thanks!!! – Alessandro Gnola Nov 7 '16 at 10:02
0

Try running this statement in your database

INSERT INTO customer_form_attribute (form_code, attribute_id)
  SELECT 'customer_account_create', attribute_id 
  FROM eav_attribute WHERE attribute_code = 'group_id'

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.