Uncaught Error: Call to a member function getId() on null inMulti Store views dataFrequently used functions in model or helperCall to a member function getId() on a non-objecthow do I call function(Helper) from xml in magentoAfter adding <crontab> in my config.xmlCreate a helper in Magento 2Magento 2: How to call helper function in ControllerFatal error: Call to a member function getConfigTimezone() on null Magento 2.2Magento 2: call helper function in ui component formCalling custom constant issueMagento 2 : Call Helper Without Using __construct in Own Module
Fill the maze with a wall-following Snake until it gets stuck
Is this a valid proof that A = B given A ∩ B = A ∪ B?
Having some issue with notation in a Hilbert space
What is "dot" sign in •NO?
Why "amatus est" instead of "*amavitur"
Is there a polite way to ask about one's ethnicity?
How to address players struggling with simple controls?
Time at 1G acceleration to travel 100 000 light years
TV show starring two men who develop various gadgets
Would a 7805 5v regulator drain a 9v battery?
How to prevent cables getting intertwined
Is using Legacy mode is a bad thing to do?
Kelvin type connection
How can caller ID be faked?
How do I become a better writer when I hate reading?
What is the context for Napoleon's quote "[the Austrians] did not know the value of five minutes"?
What is the precise meaning of "подсел на мак"?
Definition of 'vrit'
Can you place a web spell on a surface you cannot see?
I wish, I yearn, for an answer to this riddle
I have found ports on my Samsung smart tv running a display service. What can I do with it?
How much steel armor can you wear and still be able to swim?
What does "vrit' mean with reference to documentaries?
how to find which software is doing ssh connection?
Uncaught Error: Call to a member function getId() on null in
Multi Store views dataFrequently used functions in model or helperCall to a member function getId() on a non-objecthow do I call function(Helper) from xml in magentoAfter adding <crontab> in my config.xmlCreate a helper in Magento 2Magento 2: How to call helper function in ControllerFatal error: Call to a member function getConfigTimezone() on null Magento 2.2Magento 2: call helper function in ui component formCalling custom constant issueMagento 2 : Call Helper Without Using __construct in Own Module
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have some problem about this error, who can tell me why? Thank you!!
Fatal error: Uncaught Error: Call to a member function getId() on null in
helper
|
show 5 more comments
I have some problem about this error, who can tell me why? Thank you!!
Fatal error: Uncaught Error: Call to a member function getId() on null in
helper
Please detail $customer = $this->helperData->getCustomer();
– HoangHieu
Jun 10 at 8:14
sorry,what your mean? @HoangHieu
– niceonelee
Jun 10 at 8:23
$this->helperData->getCustomer(); this function returned null, please detail it.
– HoangHieu
Jun 10 at 8:25
This have no return, just return $collection. and when i changed other code it can work for no login, but login will be error. @HoangHieu
– niceonelee
Jun 10 at 8:33
did youprint_r($customer)
to check is it returning something or not?
– Asad Khan
Jun 10 at 8:39
|
show 5 more comments
I have some problem about this error, who can tell me why? Thank you!!
Fatal error: Uncaught Error: Call to a member function getId() on null in
helper
I have some problem about this error, who can tell me why? Thank you!!
Fatal error: Uncaught Error: Call to a member function getId() on null in
helper
helper
edited 2 days ago
niceonelee
asked Jun 10 at 8:09
niceoneleeniceonelee
334316
334316
Please detail $customer = $this->helperData->getCustomer();
– HoangHieu
Jun 10 at 8:14
sorry,what your mean? @HoangHieu
– niceonelee
Jun 10 at 8:23
$this->helperData->getCustomer(); this function returned null, please detail it.
– HoangHieu
Jun 10 at 8:25
This have no return, just return $collection. and when i changed other code it can work for no login, but login will be error. @HoangHieu
– niceonelee
Jun 10 at 8:33
did youprint_r($customer)
to check is it returning something or not?
– Asad Khan
Jun 10 at 8:39
|
show 5 more comments
Please detail $customer = $this->helperData->getCustomer();
– HoangHieu
Jun 10 at 8:14
sorry,what your mean? @HoangHieu
– niceonelee
Jun 10 at 8:23
$this->helperData->getCustomer(); this function returned null, please detail it.
– HoangHieu
Jun 10 at 8:25
This have no return, just return $collection. and when i changed other code it can work for no login, but login will be error. @HoangHieu
– niceonelee
Jun 10 at 8:33
did youprint_r($customer)
to check is it returning something or not?
– Asad Khan
Jun 10 at 8:39
Please detail $customer = $this->helperData->getCustomer();
– HoangHieu
Jun 10 at 8:14
Please detail $customer = $this->helperData->getCustomer();
– HoangHieu
Jun 10 at 8:14
sorry,what your mean? @HoangHieu
– niceonelee
Jun 10 at 8:23
sorry,what your mean? @HoangHieu
– niceonelee
Jun 10 at 8:23
$this->helperData->getCustomer(); this function returned null, please detail it.
– HoangHieu
Jun 10 at 8:25
$this->helperData->getCustomer(); this function returned null, please detail it.
– HoangHieu
Jun 10 at 8:25
This have no return, just return $collection. and when i changed other code it can work for no login, but login will be error. @HoangHieu
– niceonelee
Jun 10 at 8:33
This have no return, just return $collection. and when i changed other code it can work for no login, but login will be error. @HoangHieu
– niceonelee
Jun 10 at 8:33
did you
print_r($customer)
to check is it returning something or not?– Asad Khan
Jun 10 at 8:39
did you
print_r($customer)
to check is it returning something or not?– Asad Khan
Jun 10 at 8:39
|
show 5 more comments
2 Answers
2
active
oldest
votes
Your error is more logic than syntax, if the customer isn't logged in (guest) you cannot get the user id. I would edit your helper function to check if the user is logged in and return false if not.
public function getCustomer()
$customerSession = $this->customerSession->create();
$customerData = $customerSession->getCustomerData();
if($customerSession->isLoggedIn())
return $customerData;
else
return false;
Then in your getTicket function use something like this :
if ($this->helperData->getCustomer())
// run your code as normal
else
// redirect to login
you should mark this as the answer in that case
– bjornredemption
Jun 10 at 13:39
yes,marked,can you help me see the second issue,thank you @bjornredemption
– niceonelee
Jun 10 at 13:44
add a comment |
$user_id = $customer->getId();
this code return int or null,when return null,the program will automatically throw an error.You should handle your mistakes properly.eg:
if ($user_id)
//your code
else
//your code
im still getting error, can you made a full code let me to see what i wrong, thank you!! @tokey
– niceonelee
Jun 10 at 10:03
getting this1 exception(s): Exception #0 (Exception): Notice: Undefined variable: user_id
– niceonelee
Jun 10 at 10:06
@niceonelee Please show your complete code.
– tokey
Jun 10 at 10:09
please check the original post, this is full file code, thank you! @tokey
– niceonelee
Jun 10 at 10:16
@niceonelee But you didn't modify your code as I suggested.
– tokey
Jun 10 at 10:24
|
show 1 more comment
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277777%2funcaught-error-call-to-a-member-function-getid-on-null-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your error is more logic than syntax, if the customer isn't logged in (guest) you cannot get the user id. I would edit your helper function to check if the user is logged in and return false if not.
public function getCustomer()
$customerSession = $this->customerSession->create();
$customerData = $customerSession->getCustomerData();
if($customerSession->isLoggedIn())
return $customerData;
else
return false;
Then in your getTicket function use something like this :
if ($this->helperData->getCustomer())
// run your code as normal
else
// redirect to login
you should mark this as the answer in that case
– bjornredemption
Jun 10 at 13:39
yes,marked,can you help me see the second issue,thank you @bjornredemption
– niceonelee
Jun 10 at 13:44
add a comment |
Your error is more logic than syntax, if the customer isn't logged in (guest) you cannot get the user id. I would edit your helper function to check if the user is logged in and return false if not.
public function getCustomer()
$customerSession = $this->customerSession->create();
$customerData = $customerSession->getCustomerData();
if($customerSession->isLoggedIn())
return $customerData;
else
return false;
Then in your getTicket function use something like this :
if ($this->helperData->getCustomer())
// run your code as normal
else
// redirect to login
you should mark this as the answer in that case
– bjornredemption
Jun 10 at 13:39
yes,marked,can you help me see the second issue,thank you @bjornredemption
– niceonelee
Jun 10 at 13:44
add a comment |
Your error is more logic than syntax, if the customer isn't logged in (guest) you cannot get the user id. I would edit your helper function to check if the user is logged in and return false if not.
public function getCustomer()
$customerSession = $this->customerSession->create();
$customerData = $customerSession->getCustomerData();
if($customerSession->isLoggedIn())
return $customerData;
else
return false;
Then in your getTicket function use something like this :
if ($this->helperData->getCustomer())
// run your code as normal
else
// redirect to login
Your error is more logic than syntax, if the customer isn't logged in (guest) you cannot get the user id. I would edit your helper function to check if the user is logged in and return false if not.
public function getCustomer()
$customerSession = $this->customerSession->create();
$customerData = $customerSession->getCustomerData();
if($customerSession->isLoggedIn())
return $customerData;
else
return false;
Then in your getTicket function use something like this :
if ($this->helperData->getCustomer())
// run your code as normal
else
// redirect to login
answered Jun 10 at 11:51
bjornredemptionbjornredemption
18317
18317
you should mark this as the answer in that case
– bjornredemption
Jun 10 at 13:39
yes,marked,can you help me see the second issue,thank you @bjornredemption
– niceonelee
Jun 10 at 13:44
add a comment |
you should mark this as the answer in that case
– bjornredemption
Jun 10 at 13:39
yes,marked,can you help me see the second issue,thank you @bjornredemption
– niceonelee
Jun 10 at 13:44
you should mark this as the answer in that case
– bjornredemption
Jun 10 at 13:39
you should mark this as the answer in that case
– bjornredemption
Jun 10 at 13:39
yes,marked,can you help me see the second issue,thank you @bjornredemption
– niceonelee
Jun 10 at 13:44
yes,marked,can you help me see the second issue,thank you @bjornredemption
– niceonelee
Jun 10 at 13:44
add a comment |
$user_id = $customer->getId();
this code return int or null,when return null,the program will automatically throw an error.You should handle your mistakes properly.eg:
if ($user_id)
//your code
else
//your code
im still getting error, can you made a full code let me to see what i wrong, thank you!! @tokey
– niceonelee
Jun 10 at 10:03
getting this1 exception(s): Exception #0 (Exception): Notice: Undefined variable: user_id
– niceonelee
Jun 10 at 10:06
@niceonelee Please show your complete code.
– tokey
Jun 10 at 10:09
please check the original post, this is full file code, thank you! @tokey
– niceonelee
Jun 10 at 10:16
@niceonelee But you didn't modify your code as I suggested.
– tokey
Jun 10 at 10:24
|
show 1 more comment
$user_id = $customer->getId();
this code return int or null,when return null,the program will automatically throw an error.You should handle your mistakes properly.eg:
if ($user_id)
//your code
else
//your code
im still getting error, can you made a full code let me to see what i wrong, thank you!! @tokey
– niceonelee
Jun 10 at 10:03
getting this1 exception(s): Exception #0 (Exception): Notice: Undefined variable: user_id
– niceonelee
Jun 10 at 10:06
@niceonelee Please show your complete code.
– tokey
Jun 10 at 10:09
please check the original post, this is full file code, thank you! @tokey
– niceonelee
Jun 10 at 10:16
@niceonelee But you didn't modify your code as I suggested.
– tokey
Jun 10 at 10:24
|
show 1 more comment
$user_id = $customer->getId();
this code return int or null,when return null,the program will automatically throw an error.You should handle your mistakes properly.eg:
if ($user_id)
//your code
else
//your code
$user_id = $customer->getId();
this code return int or null,when return null,the program will automatically throw an error.You should handle your mistakes properly.eg:
if ($user_id)
//your code
else
//your code
answered Jun 10 at 9:51
tokeytokey
862
862
im still getting error, can you made a full code let me to see what i wrong, thank you!! @tokey
– niceonelee
Jun 10 at 10:03
getting this1 exception(s): Exception #0 (Exception): Notice: Undefined variable: user_id
– niceonelee
Jun 10 at 10:06
@niceonelee Please show your complete code.
– tokey
Jun 10 at 10:09
please check the original post, this is full file code, thank you! @tokey
– niceonelee
Jun 10 at 10:16
@niceonelee But you didn't modify your code as I suggested.
– tokey
Jun 10 at 10:24
|
show 1 more comment
im still getting error, can you made a full code let me to see what i wrong, thank you!! @tokey
– niceonelee
Jun 10 at 10:03
getting this1 exception(s): Exception #0 (Exception): Notice: Undefined variable: user_id
– niceonelee
Jun 10 at 10:06
@niceonelee Please show your complete code.
– tokey
Jun 10 at 10:09
please check the original post, this is full file code, thank you! @tokey
– niceonelee
Jun 10 at 10:16
@niceonelee But you didn't modify your code as I suggested.
– tokey
Jun 10 at 10:24
im still getting error, can you made a full code let me to see what i wrong, thank you!! @tokey
– niceonelee
Jun 10 at 10:03
im still getting error, can you made a full code let me to see what i wrong, thank you!! @tokey
– niceonelee
Jun 10 at 10:03
getting this
1 exception(s): Exception #0 (Exception): Notice: Undefined variable: user_id
– niceonelee
Jun 10 at 10:06
getting this
1 exception(s): Exception #0 (Exception): Notice: Undefined variable: user_id
– niceonelee
Jun 10 at 10:06
@niceonelee Please show your complete code.
– tokey
Jun 10 at 10:09
@niceonelee Please show your complete code.
– tokey
Jun 10 at 10:09
please check the original post, this is full file code, thank you! @tokey
– niceonelee
Jun 10 at 10:16
please check the original post, this is full file code, thank you! @tokey
– niceonelee
Jun 10 at 10:16
@niceonelee But you didn't modify your code as I suggested.
– tokey
Jun 10 at 10:24
@niceonelee But you didn't modify your code as I suggested.
– tokey
Jun 10 at 10:24
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277777%2funcaught-error-call-to-a-member-function-getid-on-null-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Please detail $customer = $this->helperData->getCustomer();
– HoangHieu
Jun 10 at 8:14
sorry,what your mean? @HoangHieu
– niceonelee
Jun 10 at 8:23
$this->helperData->getCustomer(); this function returned null, please detail it.
– HoangHieu
Jun 10 at 8:25
This have no return, just return $collection. and when i changed other code it can work for no login, but login will be error. @HoangHieu
– niceonelee
Jun 10 at 8:33
did you
print_r($customer)
to check is it returning something or not?– Asad Khan
Jun 10 at 8:39