Ejemplo n.º 1
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;
 }