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

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!

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.