Customer_save_after observer - is it an update or a registration?How to update Magento 2.2.x to Magento 2.3 ?...

How to politely refuse in-office gym instructor for steroids and protein

Does a paladin have to announce that they're using Divine Smite before attacking?

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

Is Screenshot Time-tracking Common?

Square Root Distance from Integers

What senses are available to a corpse subjected to a Speak with Dead spell?

Why is a temp table a more efficient solution to the Halloween Problem than an eager spool?

What is a good reason for every spaceship to carry a weapon on board?

How vim overwrites readonly mode?

How would an AI self awareness kill switch work?

What makes papers publishable in top-tier journals?

Does it take energy to move something in a circle?

False written accusations not made public - is there law to cover this?

Which RAF squadrons and aircraft types took part in the bombing of Berlin on the 25th of August 1940?

Why is 'diphthong' pronounced the way it is?

Microtypography protrusion with Polish quotation marks

What game did these black and yellow dice come from?

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

The No-Straight Maze

Does the ditching switch allow an A320 to float indefinitely?

Why avoid shared user accounts?

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

Critique vs nitpicking

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



Customer_save_after observer - is it an update or a registration?


How to update Magento 2.2.x to Magento 2.3 ? Is it possible to upgrade?Magento 2.3 added app/code/magento modules after 2.3 update (with sample data)Update Magento 2.1.9 to 2.3Disable customer registration and loginMagento 2: Update visual swatch option image when options are changedcomposer update --no-dev made website super slowMagento2 Update customer attribute via APIunable to update Magento to latest version from 2.2.4 to 2.3API call and observer on customer creationMagento 2.3 Update Source Stock













1















I have implemented an observer for customer_save_after event. Is there a way to know if it is a new customer registration or an update?



I cannot use the customer_register_success event as it is not triggered when the registration/update is done through the REST API. I assume that's because it's defined inside app/code/Magento/Customer/Controller/Account/CreatePost.php










share|improve this question























  • You are able to check customer email already exist or not. If not customer is new.

    – Aman Alam
    4 hours ago











  • what you want to achieve?

    – Amit Bera
    2 hours ago











  • I want to discriminate update and registration to call another API to sync customer's data, whenever a registration or update takes place from magento REST API

    – diego10
    1 hour ago
















1















I have implemented an observer for customer_save_after event. Is there a way to know if it is a new customer registration or an update?



I cannot use the customer_register_success event as it is not triggered when the registration/update is done through the REST API. I assume that's because it's defined inside app/code/Magento/Customer/Controller/Account/CreatePost.php










share|improve this question























  • You are able to check customer email already exist or not. If not customer is new.

    – Aman Alam
    4 hours ago











  • what you want to achieve?

    – Amit Bera
    2 hours ago











  • I want to discriminate update and registration to call another API to sync customer's data, whenever a registration or update takes place from magento REST API

    – diego10
    1 hour ago














1












1








1








I have implemented an observer for customer_save_after event. Is there a way to know if it is a new customer registration or an update?



I cannot use the customer_register_success event as it is not triggered when the registration/update is done through the REST API. I assume that's because it's defined inside app/code/Magento/Customer/Controller/Account/CreatePost.php










share|improve this question














I have implemented an observer for customer_save_after event. Is there a way to know if it is a new customer registration or an update?



I cannot use the customer_register_success event as it is not triggered when the registration/update is done through the REST API. I assume that's because it's defined inside app/code/Magento/Customer/Controller/Account/CreatePost.php







magento2.3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 4 hours ago









diego10diego10

455




455













  • You are able to check customer email already exist or not. If not customer is new.

    – Aman Alam
    4 hours ago











  • what you want to achieve?

    – Amit Bera
    2 hours ago











  • I want to discriminate update and registration to call another API to sync customer's data, whenever a registration or update takes place from magento REST API

    – diego10
    1 hour ago



















  • You are able to check customer email already exist or not. If not customer is new.

    – Aman Alam
    4 hours ago











  • what you want to achieve?

    – Amit Bera
    2 hours ago











  • I want to discriminate update and registration to call another API to sync customer's data, whenever a registration or update takes place from magento REST API

    – diego10
    1 hour ago

















You are able to check customer email already exist or not. If not customer is new.

– Aman Alam
4 hours ago





You are able to check customer email already exist or not. If not customer is new.

– Aman Alam
4 hours ago













what you want to achieve?

– Amit Bera
2 hours ago





what you want to achieve?

– Amit Bera
2 hours ago













I want to discriminate update and registration to call another API to sync customer's data, whenever a registration or update takes place from magento REST API

– diego10
1 hour ago





I want to discriminate update and registration to call another API to sync customer's data, whenever a registration or update takes place from magento REST API

– diego10
1 hour ago










1 Answer
1






active

oldest

votes


















2














Method 1:



I think after event doesn't work for your case. We should use customer_save_before and get customer id or email and check if it exists or not by using customer repository.



Method 2:



public function execute(MagentoFrameworkEventObserver $observer)
{
$customer = $observer->getEvent()->getCustomer();
if($customer->isObjectNew() )
{
//new customer
}
}





share|improve this answer
























  • I tried $customer->isObjectNew() but never returns true. Am I missing something?

    – diego10
    1 hour ago











  • which event are you using?

    – Bilal Usean
    42 mins ago











  • sorry my bad.. you meant when using customer_save_before. its working there.. but I want to add my code after customer is saved. Is there a way to share the information I'm getting from isObjectNew() on the "before" observer with the "after" observer?

    – diego10
    40 mins ago











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%2f263421%2fcustomer-save-after-observer-is-it-an-update-or-a-registration%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









2














Method 1:



I think after event doesn't work for your case. We should use customer_save_before and get customer id or email and check if it exists or not by using customer repository.



Method 2:



public function execute(MagentoFrameworkEventObserver $observer)
{
$customer = $observer->getEvent()->getCustomer();
if($customer->isObjectNew() )
{
//new customer
}
}





share|improve this answer
























  • I tried $customer->isObjectNew() but never returns true. Am I missing something?

    – diego10
    1 hour ago











  • which event are you using?

    – Bilal Usean
    42 mins ago











  • sorry my bad.. you meant when using customer_save_before. its working there.. but I want to add my code after customer is saved. Is there a way to share the information I'm getting from isObjectNew() on the "before" observer with the "after" observer?

    – diego10
    40 mins ago
















2














Method 1:



I think after event doesn't work for your case. We should use customer_save_before and get customer id or email and check if it exists or not by using customer repository.



Method 2:



public function execute(MagentoFrameworkEventObserver $observer)
{
$customer = $observer->getEvent()->getCustomer();
if($customer->isObjectNew() )
{
//new customer
}
}





share|improve this answer
























  • I tried $customer->isObjectNew() but never returns true. Am I missing something?

    – diego10
    1 hour ago











  • which event are you using?

    – Bilal Usean
    42 mins ago











  • sorry my bad.. you meant when using customer_save_before. its working there.. but I want to add my code after customer is saved. Is there a way to share the information I'm getting from isObjectNew() on the "before" observer with the "after" observer?

    – diego10
    40 mins ago














2












2








2







Method 1:



I think after event doesn't work for your case. We should use customer_save_before and get customer id or email and check if it exists or not by using customer repository.



Method 2:



public function execute(MagentoFrameworkEventObserver $observer)
{
$customer = $observer->getEvent()->getCustomer();
if($customer->isObjectNew() )
{
//new customer
}
}





share|improve this answer













Method 1:



I think after event doesn't work for your case. We should use customer_save_before and get customer id or email and check if it exists or not by using customer repository.



Method 2:



public function execute(MagentoFrameworkEventObserver $observer)
{
$customer = $observer->getEvent()->getCustomer();
if($customer->isObjectNew() )
{
//new customer
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered 2 hours ago









Bilal UseanBilal Usean

4,89423688




4,89423688













  • I tried $customer->isObjectNew() but never returns true. Am I missing something?

    – diego10
    1 hour ago











  • which event are you using?

    – Bilal Usean
    42 mins ago











  • sorry my bad.. you meant when using customer_save_before. its working there.. but I want to add my code after customer is saved. Is there a way to share the information I'm getting from isObjectNew() on the "before" observer with the "after" observer?

    – diego10
    40 mins ago



















  • I tried $customer->isObjectNew() but never returns true. Am I missing something?

    – diego10
    1 hour ago











  • which event are you using?

    – Bilal Usean
    42 mins ago











  • sorry my bad.. you meant when using customer_save_before. its working there.. but I want to add my code after customer is saved. Is there a way to share the information I'm getting from isObjectNew() on the "before" observer with the "after" observer?

    – diego10
    40 mins ago

















I tried $customer->isObjectNew() but never returns true. Am I missing something?

– diego10
1 hour ago





I tried $customer->isObjectNew() but never returns true. Am I missing something?

– diego10
1 hour ago













which event are you using?

– Bilal Usean
42 mins ago





which event are you using?

– Bilal Usean
42 mins ago













sorry my bad.. you meant when using customer_save_before. its working there.. but I want to add my code after customer is saved. Is there a way to share the information I'm getting from isObjectNew() on the "before" observer with the "after" observer?

– diego10
40 mins ago





sorry my bad.. you meant when using customer_save_before. its working there.. but I want to add my code after customer is saved. Is there a way to share the information I'm getting from isObjectNew() on the "before" observer with the "after" observer?

– diego10
40 mins ago


















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%2f263421%2fcustomer-save-after-observer-is-it-an-update-or-a-registration%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)...

夢乃愛華...