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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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