1

this is error:

var//log/debug.log:[2019年12月10日 10:59:36] main.CRITICAL: Report ID: webapi-5def7a98e911d; Message: Notice: Undefined index: entity_id in /Applications/MAMP/htdocs/Magento2_3/app/code/SimplifiedMagento/Custom2/Model/PositionRepository.php on line 46 {"exception":"[object] (Exception(code: 0): Report ID: webapi-5def7a98e911d; Message: Notice

This is my service method:

public function getDetails($email)
 {
 $emailId = $email;
 $customer = $this->customerFactory->create();
 $arr = $customer->getCollection()->addFieldToSelect(['entity_id'])->addFieldToFilter('email',$emailId)->getData();
 $entityId = $arr['entity_id'];
 //entity id is above
 $customTable = $this->addDataFactory->create();
 $array = $customTable->getCollection()->addFieldToSelect(['position'])->addFieldToFilter('customer_id',$entityId)->getData();
 $position = $array['position'];
 $obj = $this->positionInterfaceFactory->create()->setPosition($position);
 return $obj;
 }
}
Savan Patel
2,4541 gold badge19 silver badges42 bronze badges
asked Dec 10, 2019 at 11:04

1 Answer 1

1

Replace this line

$entityId = $arr['entity_id'];

With this

$entityId = isset($arr['entity_id']) ? $arr['entity_id'] : '';

Update

public function getDetails($email)
{
 $emailId = $email;
 $customer = $this->customerFactory->create();
 $arr = $customer->getCollection()->addFieldToSelect(['entity_id'])->addFieldToFilter('email',$emailId)->getData();
 $entityId = isset($arr['entity_id']) ? $arr['entity_id'] : '';
 //entity id is above
 if($entityId){
 $customTable = $this->addDataFactory->create();
 $array = $customTable->getCollection()->addFieldToSelect(['position'])->addFieldToFilter('customer_id',$entityId)->getData();
 $position = isset($array['position']) ? $array['position'] : 0;
 $obj = $this->positionInterfaceFactory->create()->setPosition($position);
 return $obj;
 }else{
 return "Entity ID is missing!";
 }
}

Hope this will help you!

answered Dec 10, 2019 at 11:06
10
  • is this a correct way to "select with WHERE clause" in magento 2.3? Commented Dec 10, 2019 at 11:16
  • $arr = $customer->getCollection()->addFieldToSelect(['entity_id'])->addFieldToFilter('email',$emailId)->getData(); Commented Dec 10, 2019 at 11:17
  • Yes, that will return entity ID of given email id Commented Dec 10, 2019 at 11:18
  • should $emailId be in double quotes since it is string? Commented Dec 10, 2019 at 11:23
  • Sorry, I do not understand what you're asking here. Commented Dec 10, 2019 at 11:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.