Jump to content
bombis

How add default group to customer programmatically?

Recommended Posts

Hello i am trying to assign group and make it the default group for the customer logged.

This is what i tried

$this->context->customer->addGroups(array(7));
 $this->context->customer->id_default_group = 7;

The group assign is doing good but the default is not changing.

 

Any help? Thanks

Share this post


Link to post
Share on other sites

Solved using querys..

$query = "UPDATE `"._DB_PREFIX_."customer` SET id_default_group = 7 WHERE id_customer=". $this->context->customer->id;
                                    Db::getInstance()->Execute($query);

 

Prob. there is a better way to do it but i just needed a temporal solution for a week.

Share this post


Link to post
Share on other sites

maybe you should not forget

$query ="INSERT IGNORE INTO `"._DB_PREFIX_."customer_group` (`id_customer`, `id_group`) values(id_customer=". $this->context->customer->id . ",7)";
Db::getInstance()->Execute($query);

 

Edited by EvaF (see edit history)

Share this post


Link to post
Share on other sites
4 hours ago, EvaF said:

maybe you should not forget


$query ="INSERT IGNORE INTO `"._DB_PREFIX_."customer_group` (`id_customer`, `id_group`) values(id_customer=". $this->context->customer->id . ",7)";
Db::getInstance()->Execute($query);

 

 

Thanks for your suggestion!

Edited by bombis (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More