I am using Magento 2.4.1, made observer. Event name is checkout_submit_all_after. I want to update order data, customer data, customer address data. Updating Order data is succeeded, but Other data failed. I use "$customer = $this->customerRepository->getById($customerId);" to get customer data, but returned nodata. Please teach me I can't get customer data.
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
class OrderCreateObserver implements ObserverInterface
{
protected $request;
protected $customerRepository;
public function __construct(
RequestInterface $request,
CustomerRepositoryInterface $customerRepository,
){
$this->request = $request;
$this->customerRepository = $customerRepository;
}
public function execute(Observer $observer)
{
$params = $this->request->getParams();
$customerId = $order->getCustomerId();
$customer = $this->customerRepository->getById($customerId);
$customer->setCustomAttribute('updatecolumn', $params['updatecolumn']);
$this->customerRepository->save($customer);
}
}
updated
$customer->getCustomAttribute('updatecolumn')->getValue()
was worked, after
$customer->setCustomAttribute('updatecolumn', $params['updatecolumn']);
but data was not saved