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;








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










share|improve this question
























  • 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

















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










share|improve this question
























  • 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













0












0








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 you print_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











  • 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
















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










2 Answers
2






active

oldest

votes


















1














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






share|improve this answer























  • 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


















0














 $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






share|improve this answer























  • 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











  • @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











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%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









1














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






share|improve this answer























  • 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















1














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






share|improve this answer























  • 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













1












1








1







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






share|improve this answer













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







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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













0














 $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






share|improve this answer























  • 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











  • @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















0














 $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






share|improve this answer























  • 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











  • @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













0












0








0







 $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






share|improve this answer













 $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







share|improve this answer












share|improve this answer



share|improve this answer










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 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











  • 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











  • 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











  • 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

















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%2f277777%2funcaught-error-call-to-a-member-function-getid-on-null-in%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

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form