I have one special field called some_id in customer data and I want to save the some_id and quote_id in database.

I am using sales_quote_save_afterevent to save both ids. But my customer session is not accessible here.

Can anyone knows here how can we do that?

protected $customerSession;

public function __construct(   
    \Magento\Customer\Model\Session $customerSession
    $this->customerSession = $customerSession;

 public function execute(Observer $observer)
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/cust.log');
        $logger = new \Zend\Log\Logger();
        $logger->info('new observer');
        $quote = $observer->getQuote();
       $logger->log("Customer Name ". $this->customerSession->getName());
      $logger->log("Quote id ". $quote->getId());

  • "But my customer session is not accessible here." how are oyu trying to access it? you need to provide us code Apr 12 '19 at 11:52
  • updated the code
    – Daniel_12
    Apr 12 '19 at 11:59
  • and what is not working? are you getting an exception? Apr 12 '19 at 12:01
  • not getting customer data, am logged in
    – Daniel_12
    Apr 12 '19 at 12:03
  • am expecting customer data here , am getting nohing
    – Daniel_12
    Apr 12 '19 at 12:16

Try this:

$logger->log("Customer Name ". $this->customerSession->getCustomerData()->getName());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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