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;
}
}
1 Answer 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!
-
is this a correct way to "select with WHERE clause" in magento 2.3?Ankur Anand– Ankur Anand2019年12月10日 11:16:51 +00:00Commented Dec 10, 2019 at 11:16
-
$arr = $customer->getCollection()->addFieldToSelect(['entity_id'])->addFieldToFilter('email',$emailId)->getData();Ankur Anand– Ankur Anand2019年12月10日 11:17:14 +00:00Commented Dec 10, 2019 at 11:17
-
Yes, that will return entity ID of given email idKishan Savaliya– Kishan Savaliya2019年12月10日 11:18:21 +00:00Commented Dec 10, 2019 at 11:18
-
should $emailId be in double quotes since it is string?Ankur Anand– Ankur Anand2019年12月10日 11:23:21 +00:00Commented Dec 10, 2019 at 11:23
-
Sorry, I do not understand what you're asking here.Kishan Savaliya– Kishan Savaliya2019年12月10日 11:24:27 +00:00Commented Dec 10, 2019 at 11:24