0

I have a form in which when a particular code is given, the customer group should be changed to apply discounts.

I have tried the following code, it changes the customer group. I can see the discounted prices in Product list page as well as Product detail page. But in the cart and checkout process it doesnt apply.

$this->session->setCustomerGroupId("3");

Can someone please help in solving the issue.

  • Hi, I was looking a fix for the same issue, did you finally achieve to do this ? Thanks ! – magentodev Aug 29 '19 at 17:33
1
$this->session->setCustomerGroupId("3");

This only saves the customer group id in the session (which is temporary). I think in the Checkout, the actual Customers Group ID is used again.

You can set the customers group id (persistent) with the following code:

$this->session->getCustomer()->setGroupId("3")->save();

You have to make sure, that the customer is logged in before. You can check that with the following:

$this->session->isLoggedIn()
| improve this answer | |
  • Thanks David, I would like to change that for guest customer as well and i do not want to change the customer group permanently. I just want to change the group until the customer orders something or the session expires. – Dhanraj Feb 14 '16 at 19:40
  • ok, this will not work with the customer group since a guest is not a customer yet, it gets always the NOT_LOGGED_IN group while customers always get the one from db. You should use coupon codes btw, they already do what you are trying to achieve; enter a code and get a discount – David Verholen Feb 14 '16 at 20:08
  • I don't think $this->session->setCustomerGroupId("3") actually does anything. It does mark the session data but any tier prices for customer group 3 are not used and if they register they are registered as a general user. – Alex May 11 '16 at 11:34

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.