Can't change customers groupId in observerShowing different stores based on customer groupAutomatic Customer...

Potential client has a problematic employee I can't work with

Why didn't Tom Riddle take the presence of Fawkes and the Sorting Hat as more of a threat?

How do you funnel food off a cutting board?

systemd service won't start nodejs

How much mayhem could I cause as a fish?

What makes papers publishable in top-tier journals?

How to access internet and run apt-get through a middle server?

Bash script to truncate subject line of incoming email

Utilizing a Right and Left Outer Joins in same SELECT

How does Leonard in "Memento" remember reading and writing?

Should I always close BufferedReader?

What happens when the wearer of a Shield of Missile Attraction is behind total cover?

I have trouble understanding this fallacy: "If A, then B. Therefore if not-B, then not-A."

Why do neural networks need so many training examples to perform?

Changing the laptop's CPU. Should I reinstall Linux?

How to not let the Identify spell spoil everything?

The effect of fishing on total land area needed to feed an island settlement

What is a DAG (Graph Theory)?

Early credit roll before the end of the film

Book where a space ship journeys to the center of the galaxy to find all the stars had gone supernova

How do I prevent a homebrew Grappling Hook feature from trivializing Tomb of Annihilation?

Is there any risk in sharing info about technologies and products we use with a supplier?

Eww, those bytes are gross

Does the ditching switch allow an A320 to float indefinitely?



Can't change customers groupId in observer


Showing different stores based on customer groupAutomatic Customer Group change based on VAT-ID: Force Magento to check and display message when customer gets to checkout pageGet account type ID before it is changed in admin panelCustomers couldn't login from Safari In magento 1.9Can't login to second store on subdomainSelect the customers logged the last day since an determinated hourWeird error when saving customer dataCSV import not working - Need AssistanceMagento How to add configurable product while placing order programatically?Simple Observer not firing on event













2















I try to change the customers group id in the observer sales_order_place_after but it seems to be impossible. I successfully managed to change the firstname of the customer just for test, but groupId ? No chance...



Can someone explain why it is not possible to change the groupId ?



This is my attempt:



class EaDesign_CustomerGroup_Model_SalesOrderPlaceAfterObserver
{
...

public function changeCustomerGroup(Varien_Event_Observer $observer)
{
try
{
$customer = Mage::getSingleton('customer/session')->getCustomer();
$newGroupId = '7';

$customer->setGroupId($newGroupId); // does not work
//$customer->setData('group_id', $newGroupId); // second attempt, not working too


$customer->setFirstname('hans'); // this works

$customer->save();
if ($customer->save())
{
Mage::Log('customer saved', 7, 'autochange_customer_group.log', true); // this is logged
}


} catch (Exception $e) {

Mage::log('customer session moving ' . $e->getMessage());
}
}


But the customer group is still the same!



I made sure that the customer group id is correct by inspecting the HTML code in the backend:



enter image description here










share|improve this question

























  • Customer is saved twice, remove this one $customer->save(); before the if and try. as well as print $customer->getData() and $customer->getOrigData() before and after save, which gives you an idea, why its not set.

    – Haijerome
    Feb 19 at 16:43











  • I removed the second save, but it still fails. I placed getOrigData before and after and there was no change in the groupId. getData shows the new ID. What is going on?

    – Black
    Feb 20 at 8:37
















2















I try to change the customers group id in the observer sales_order_place_after but it seems to be impossible. I successfully managed to change the firstname of the customer just for test, but groupId ? No chance...



Can someone explain why it is not possible to change the groupId ?



This is my attempt:



class EaDesign_CustomerGroup_Model_SalesOrderPlaceAfterObserver
{
...

public function changeCustomerGroup(Varien_Event_Observer $observer)
{
try
{
$customer = Mage::getSingleton('customer/session')->getCustomer();
$newGroupId = '7';

$customer->setGroupId($newGroupId); // does not work
//$customer->setData('group_id', $newGroupId); // second attempt, not working too


$customer->setFirstname('hans'); // this works

$customer->save();
if ($customer->save())
{
Mage::Log('customer saved', 7, 'autochange_customer_group.log', true); // this is logged
}


} catch (Exception $e) {

Mage::log('customer session moving ' . $e->getMessage());
}
}


But the customer group is still the same!



I made sure that the customer group id is correct by inspecting the HTML code in the backend:



enter image description here










share|improve this question

























  • Customer is saved twice, remove this one $customer->save(); before the if and try. as well as print $customer->getData() and $customer->getOrigData() before and after save, which gives you an idea, why its not set.

    – Haijerome
    Feb 19 at 16:43











  • I removed the second save, but it still fails. I placed getOrigData before and after and there was no change in the groupId. getData shows the new ID. What is going on?

    – Black
    Feb 20 at 8:37














2












2








2








I try to change the customers group id in the observer sales_order_place_after but it seems to be impossible. I successfully managed to change the firstname of the customer just for test, but groupId ? No chance...



Can someone explain why it is not possible to change the groupId ?



This is my attempt:



class EaDesign_CustomerGroup_Model_SalesOrderPlaceAfterObserver
{
...

public function changeCustomerGroup(Varien_Event_Observer $observer)
{
try
{
$customer = Mage::getSingleton('customer/session')->getCustomer();
$newGroupId = '7';

$customer->setGroupId($newGroupId); // does not work
//$customer->setData('group_id', $newGroupId); // second attempt, not working too


$customer->setFirstname('hans'); // this works

$customer->save();
if ($customer->save())
{
Mage::Log('customer saved', 7, 'autochange_customer_group.log', true); // this is logged
}


} catch (Exception $e) {

Mage::log('customer session moving ' . $e->getMessage());
}
}


But the customer group is still the same!



I made sure that the customer group id is correct by inspecting the HTML code in the backend:



enter image description here










share|improve this question
















I try to change the customers group id in the observer sales_order_place_after but it seems to be impossible. I successfully managed to change the firstname of the customer just for test, but groupId ? No chance...



Can someone explain why it is not possible to change the groupId ?



This is my attempt:



class EaDesign_CustomerGroup_Model_SalesOrderPlaceAfterObserver
{
...

public function changeCustomerGroup(Varien_Event_Observer $observer)
{
try
{
$customer = Mage::getSingleton('customer/session')->getCustomer();
$newGroupId = '7';

$customer->setGroupId($newGroupId); // does not work
//$customer->setData('group_id', $newGroupId); // second attempt, not working too


$customer->setFirstname('hans'); // this works

$customer->save();
if ($customer->save())
{
Mage::Log('customer saved', 7, 'autochange_customer_group.log', true); // this is logged
}


} catch (Exception $e) {

Mage::log('customer session moving ' . $e->getMessage());
}
}


But the customer group is still the same!



I made sure that the customer group id is correct by inspecting the HTML code in the backend:



enter image description here







magento-1.9 magento-1 event-observer sales-order customer-group






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 59 mins ago







Black

















asked Feb 19 at 16:14









BlackBlack

321319




321319













  • Customer is saved twice, remove this one $customer->save(); before the if and try. as well as print $customer->getData() and $customer->getOrigData() before and after save, which gives you an idea, why its not set.

    – Haijerome
    Feb 19 at 16:43











  • I removed the second save, but it still fails. I placed getOrigData before and after and there was no change in the groupId. getData shows the new ID. What is going on?

    – Black
    Feb 20 at 8:37



















  • Customer is saved twice, remove this one $customer->save(); before the if and try. as well as print $customer->getData() and $customer->getOrigData() before and after save, which gives you an idea, why its not set.

    – Haijerome
    Feb 19 at 16:43











  • I removed the second save, but it still fails. I placed getOrigData before and after and there was no change in the groupId. getData shows the new ID. What is going on?

    – Black
    Feb 20 at 8:37

















Customer is saved twice, remove this one $customer->save(); before the if and try. as well as print $customer->getData() and $customer->getOrigData() before and after save, which gives you an idea, why its not set.

– Haijerome
Feb 19 at 16:43





Customer is saved twice, remove this one $customer->save(); before the if and try. as well as print $customer->getData() and $customer->getOrigData() before and after save, which gives you an idea, why its not set.

– Haijerome
Feb 19 at 16:43













I removed the second save, but it still fails. I placed getOrigData before and after and there was no change in the groupId. getData shows the new ID. What is going on?

– Black
Feb 20 at 8:37





I removed the second save, but it still fails. I placed getOrigData before and after and there was no change in the groupId. getData shows the new ID. What is going on?

– Black
Feb 20 at 8:37










1 Answer
1






active

oldest

votes


















0














I noticed that it is working with the same code in another magento installation where the same git branch is checked out. So it was clear that the error was caused by difference in the database, or in other words: by magento settings.



So I compared the settings from both installations and after alot of comparing I found out that it was due to the setting in (following is translated from german...) System -> Configuration -> Customers -> Customerconfiguration -> Create Customer Options -> Activate automatic customer group. After setting the value to No it suddenly works.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262508%2fcant-change-customers-groupid-in-observer%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I noticed that it is working with the same code in another magento installation where the same git branch is checked out. So it was clear that the error was caused by difference in the database, or in other words: by magento settings.



    So I compared the settings from both installations and after alot of comparing I found out that it was due to the setting in (following is translated from german...) System -> Configuration -> Customers -> Customerconfiguration -> Create Customer Options -> Activate automatic customer group. After setting the value to No it suddenly works.






    share|improve this answer




























      0














      I noticed that it is working with the same code in another magento installation where the same git branch is checked out. So it was clear that the error was caused by difference in the database, or in other words: by magento settings.



      So I compared the settings from both installations and after alot of comparing I found out that it was due to the setting in (following is translated from german...) System -> Configuration -> Customers -> Customerconfiguration -> Create Customer Options -> Activate automatic customer group. After setting the value to No it suddenly works.






      share|improve this answer


























        0












        0








        0







        I noticed that it is working with the same code in another magento installation where the same git branch is checked out. So it was clear that the error was caused by difference in the database, or in other words: by magento settings.



        So I compared the settings from both installations and after alot of comparing I found out that it was due to the setting in (following is translated from german...) System -> Configuration -> Customers -> Customerconfiguration -> Create Customer Options -> Activate automatic customer group. After setting the value to No it suddenly works.






        share|improve this answer













        I noticed that it is working with the same code in another magento installation where the same git branch is checked out. So it was clear that the error was caused by difference in the database, or in other words: by magento settings.



        So I compared the settings from both installations and after alot of comparing I found out that it was due to the setting in (following is translated from german...) System -> Configuration -> Customers -> Customerconfiguration -> Create Customer Options -> Activate automatic customer group. After setting the value to No it suddenly works.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        BlackBlack

        321319




        321319






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262508%2fcant-change-customers-groupid-in-observer%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

            How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

            夢乃愛華...