Skip to content

Call to undefined method MagentoCustomerModelResourceModelCustomerRepositoryInterceptor::getByEmail() magento2

I am trying to update custom attribute in magento2 but i am getting error while running this

<?php
    
    namespace testOrgControllerResult;
    
    use MagentoFrameworkAppActionContext;
    use MagentoFrameworkViewResultPageFactory;
    use MagentoFrameworkControllerResultJsonFactory;
    use MagentoFrameworkAppHelperAbstractHelper;
    use MagentoFrameworkHTTPClientCurl;
    use MagentoCustomerApiCustomerRepositoryInterface;
    
    class Result1 extends MagentoFrameworkAppActionAction
    {
    
         /**
         * @var MagentoFrameworkViewResultPageFactory
         */
        protected $resultPageFactory;
        protected $curl;
        protected $resultJsonFactory; 
    
        /**
         * @param Context     $context
         * @param PageFactory $resultPageFactory
         */
        public function __construct(
            Context $context,
            Curl $curl,
            PageFactory $resultPageFactory,
            JsonFactory $resultJsonFactory,
            CustomerRepositoryInterface $customerRepository
            )
        {
            $this->curl = $curl;
            $this->resultPageFactory = $resultPageFactory;
            $this->resultJsonFactory = $resultJsonFactory;
            $this->customerRepository = $customerRepository;        
            return parent::__construct($context);
        }
    
       
    
        public function execute()
        {
            $email = $this->getRequest()->getParam('email');
            //$numtwo = $this->getRequest()->getParam('numtwo');
         $result1 = $this->resultJsonFactory->create();
             $resultPage1 = $this->resultPageFactory->create();
    
            
                    $URL = 'apiurl';
                   
                   
                    $this->curl->setOption(CURLOPT_HEADER, 0);
                    $this->curl->setOption(CURLOPT_TIMEOUT, 60);
                    $this->curl->setOption(CURLOPT_RETURNTRANSFER, true);
                    $this->curl->setOption(CURLOPT_CUSTOMREQUEST, 'GET');
                    //set curl header
                    $this->curl->addHeader("Content-Type", "application/json");
                    //get request with url
                    $this->curl->get($URL);
                    //read response
                    $response = $this->curl->getBody();
                    $customer = $this->customerRepository->getByEmail($email);
                    $customerData = $customer->getDataModel();
                    $customer->setId($customer->getId());
                    $customer->setCustomAttribute('fin_cus_id', 'c123');
                    $customer->updateData($customerData);
                    $customer->save()
                    
                    $resp= json_decode($response, TRUE);
                    $block = $resultPage1->getLayout()
                    ->createBlock('testOrgBlockIndex')
                    ->setTemplate('test_Org::result1.phtml')
                    ->setData('model',$resp['model_list'])
                    ->toHtml();
    
                     $result1->setData(['output' => $block]);
                   // return $response;
          //  $result->setData(['output' => $block]);
           return $result1;
        }
        
    }

Call to undefined method MagentoCustomerModelResourceModelCustomerRepositoryInterceptor::getByEmail()
Call to undefined method MagentoCustomerModelResourceModelCustomerRepositoryInterceptor::getDataModel() ,