Example #1
0
 public function testBindCustomerLogin()
 {
     $customer = new \Magento\Framework\Object(['id' => '1']);
     $observer = new \Magento\Framework\Object(['event' => new \Magento\Framework\Object(['customer' => $customer])]);
     $this->_model->bindCustomerLogin($observer);
     $this->assertTrue($this->_model->getDoCustomerLogin());
     $this->assertEquals($customer->getId(), $this->_model->getCustomerId());
     $this->_model->unsetData();
     $this->_model->setCustomerId('2');
     $this->_model->bindCustomerLogin($observer);
     $this->assertNull($this->_model->getDoCustomerLogin());
     $this->assertEquals('2', $this->_model->getCustomerId());
 }
Example #2
0
 /**
  * Saving information about customer
  *
  * @param   \Magento\Log\Model\Visitor $visitor
  * @return  \Magento\Log\Model\Resource\Visitor
  */
 protected function _saveCustomerInfo($visitor)
 {
     $adapter = $this->_getWriteAdapter();
     if ($visitor->getDoCustomerLogin()) {
         $data = new \Magento\Framework\Object(array('visitor_id' => $visitor->getVisitorId(), 'customer_id' => $visitor->getCustomerId(), 'login_at' => $this->_date->gmtDate(), 'store_id' => $this->_storeManager->getStore()->getId()));
         $bind = $this->_prepareDataForTable($data, $this->getTable('log_customer'));
         $adapter->insert($this->getTable('log_customer'), $bind);
         $visitor->setCustomerLogId($adapter->lastInsertId($this->getTable('log_customer')));
         $visitor->setDoCustomerLogin(false);
     }
     if ($visitor->getDoCustomerLogout() && ($logId = $visitor->getCustomerLogId())) {
         $data = new \Magento\Framework\Object(array('logout_at' => $this->_date->gmtDate(), 'store_id' => (int) $this->_storeManager->getStore()->getId()));
         $bind = $this->_prepareDataForTable($data, $this->getTable('log_customer'));
         $condition = array('log_id = ?' => (int) $logId);
         $adapter->update($this->getTable('log_customer'), $bind, $condition);
         $visitor->setDoCustomerLogout(false);
         $visitor->setCustomerId(null);
         $visitor->setCustomerLogId(null);
     }
     return $this;
 }