I am trying to update custom attribute in magento2 but i am getting error while running this
<?php
namespace test\Org\Controller\Result;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\HTTP\Client\Curl;
use Magento\Customer\Api\CustomerRepositoryInterface;
class Result1 extends \Magento\Framework\App\Action\Action
{
/**
* @var Magento\Framework\View\Result\PageFactory
*/
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('test\Org\Block\Index')
->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 Magento\Customer\Model\ResourceModel\CustomerRepository\Interceptor::getByEmail() Call to undefined method Magento\Customer\Model\ResourceModel\CustomerRepository\Interceptor::getDataModel() ,