Ejemplo n.º 1
0
 /**
  * Saving information about customer
  *
  * @param   Mage_Log_Model_Visitor $visitor
  *
  * @return  Mage_Log_Model_Resource_Visitor
  */
 protected function _saveCustomerInfo($visitor)
 {
     $adapter = $this->_getWriteAdapter();
     if ($visitor->getDoCustomerLogout() && ($logId = $visitor->getCustomerLogId())) {
         $resource = Mage::getSingleton('core/resource');
         $connection = $resource->getConnection('core_read');
         $select = new Zend_Db_Select($connection);
         $select->from($resource->getTableName('log/customer'));
         $select->reset(Zend_Db_Select::COLUMNS);
         $select->columns('login_at');
         $select->where('log_id = ?', $logId);
         $loginAt = $connection->fetchOne($select);
         if (!$loginAt) {
             return parent::_saveCustomerInfo($visitor);
         }
         $data = new Varien_Object(array('login_at' => $loginAt, 'logout_at' => Mage::getSingleton('core/date')->gmtDate(), 'store_id' => (int) Mage::app()->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);
     } else {
         return parent::_saveCustomerInfo($visitor);
     }
     return $this;
 }
Ejemplo n.º 2
0
 protected function _requireVisitorWithTwoProducts()
 {
     $visitor = new Mage_Log_Model_Visitor();
     $visitor->setSessionId(md5(time()) . md5(microtime()))->setLastVisitAt(now())->save();
     $item = new Mage_Catalog_Model_Product_Compare_Item();
     $item->setVisitorId($visitor->getId())->setProductId(1)->save();
     $item = new Mage_Catalog_Model_Product_Compare_Item();
     $item->setVisitorId($visitor->getId())->setProductId(2)->save();
     Mage::getSingleton('Mage_Log_Model_Visitor')->load($visitor->getId());
     $this->_assertCompareListEquals(array(1, 2));
 }
Ejemplo n.º 3
0
 protected function _construct()
 {
     parent::_construct();
     if (version_compare(Mage::getVersion(), '1.3.2.2', '>')) {
         $userAgent = Mage::helper('core/http')->getHttpUserAgent();
         if (!$this->_skipRequestLogging) {
             if (empty($userAgent)) {
                 $this->_skipRequestLogging = true;
             }
         }
         //ignore user agents was introduced in 1.4.0.0
         if (!$this->_skipRequestLogging && version_compare(Mage::getVersion(), '1.4.0.0') < 0) {
             $ignoreAgents = Mage::getConfig()->getNode('global/ignore_user_agents');
             if ($ignoreAgents) {
                 $ignoreAgents = $ignoreAgents->asArray();
                 if (in_array($userAgent, $ignoreAgents)) {
                     $this->_skipRequestLogging = true;
                 }
             }
         }
         if (!$this->_skipRequestLogging) {
             if (preg_match("/" . self::USER_AGENT_BOT_PATTERN . "/i", $userAgent)) {
                 $this->_skipRequestLogging = true;
             }
         }
     }
 }
Ejemplo n.º 4
0
 public function getId()
 {
     if ($this->_skipRequestLogging == false) {
         return parent::getId();
     }
     // Return a bogus visitor-ID that is not logged at all, but used in various buggy Magento parts
     return abs(crc32(Mage::getModel('core/session')->getSessionId()));
 }
Ejemplo n.º 5
0
 /**
  * Calculate cache product compare collection
  *
  * @param  bool $logout
  * @return Mage_Catalog_Helper_Product_Compare
  */
 public function calculate($logout = false)
 {
     // first visit
     if (!$this->_catalogSession->hasCatalogCompareItemsCount() && !$this->_customerId) {
         $count = 0;
     } else {
         /** @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection */
         $collection = Mage::getResourceModel('catalog/product_compare_item_collection')->useProductItem(true);
         if (!$logout && $this->_customerSession->isLoggedIn()) {
             $collection->setCustomerId($this->_customerSession->getCustomerId());
         } elseif ($this->_customerId) {
             $collection->setCustomerId($this->_customerId);
         } else {
             $collection->setVisitorId($this->_logVisitor->getId());
         }
         /* Price data is added to consider item stock status using price index */
         $collection->addPriceData();
         $this->_productVisibility->addVisibleInSiteFilterToCollection($collection);
         $count = $collection->getSize();
     }
     $this->_catalogSession->setCatalogCompareItemsCount($count);
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Saving information about quote
  *
  * @param   Mage_Log_Model_Visitor $visitor
  * @return  Mage_Log_Model_Mysql4_Visitor
  */
 protected function _saveQuoteInfo($visitor)
 {
     $write = $this->_getWriteAdapter();
     if ($visitor->getDoQuoteCreate()) {
         $write->insert($this->getTable('log/quote_table'), array('quote_id' => $visitor->getQuoteId(), 'visitor_id' => $visitor->getId(), 'created_at' => now()));
         $visitor->setDoQuoteCreate(false);
     }
     if ($visitor->getDoQuoteDestroy()) {
         /**
          * We have delete quote from log because if original quote was
          * deleted and Mysql restarted we will get key duplication error
          */
         $write->delete($this->getTable('log/quote_table'), $write->quoteInto('quote_id=?', $visitor->getQuoteId()));
         //            $write->update($this->getTable('log/quote_table'),
         //                array('deleted_at'=> now()),
         //                $write->quoteInto('quote_id=?', $visitor->getQuoteId())
         //            );
         $visitor->setDoQuoteDestroy(false);
         $visitor->setQuoteId(null);
     }
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Saving information about quote
  *
  * @param   Mage_Log_Model_Visitor $visitor
  * @return  Mage_Log_Model_Resource_Visitor
  */
 protected function _saveQuoteInfo($visitor)
 {
     $adapter = $this->_getWriteAdapter();
     if ($visitor->getDoQuoteCreate()) {
         $data = new Varien_Object(array('quote_id' => (int) $visitor->getQuoteId(), 'visitor_id' => (int) $visitor->getId(), 'created_at' => Mage::getSingleton('core/date')->gmtDate()));
         $bind = $this->_prepareDataForTable($data, $this->getTable('log/quote_table'));
         $adapter->insert($this->getTable('log/quote_table'), $bind);
         $visitor->setDoQuoteCreate(false);
     }
     if ($visitor->getDoQuoteDestroy()) {
         /**
          * We have delete quote from log because if original quote was
          * deleted and Mysql restarted we will get key duplication error
          */
         $condition = array('quote_id = ?' => (int) $visitor->getQuoteId());
         $adapter->delete($this->getTable('log/quote_table'), $condition);
         $visitor->setDoQuoteDestroy(false);
         $visitor->setQuoteId(null);
     }
     return $this;
 }
Ejemplo n.º 8
0
 public function getCurrentStatus()
 {
     $log = $this->getCustomerLog();
     if ($log->getLogoutAt() || strtotime(now()) - strtotime($log->getLastVisitAt()) > Mage_Log_Model_Visitor::getOnlineMinutesInterval() * 60) {
         return Mage::helper('customer')->__('Offline');
     }
     return Mage::helper('customer')->__('Online');
 }
 /**
  * Enables online only select
  *
  * @param int $minutes
  * @return object
  */
 public function useOnlineFilter($minutes = null)
 {
     if (is_null($minutes)) {
         $minutes = Mage_Log_Model_Visitor::getOnlineMinutesInterval();
     }
     $this->_select->from(array('visitor_table' => $this->_visitorTable))->joinLeft(array('info_table' => $this->_visitorInfoTable), 'info_table.visitor_id=visitor_table.visitor_id')->joinLeft(array('customer_table' => $this->_customerTable), 'customer_table.visitor_id = visitor_table.visitor_id AND customer_table.logout_at IS NULL', array('log_id', 'customer_id', 'login_at', 'logout_at'))->joinLeft(array('url_info_table' => $this->_urlInfoTable), 'url_info_table.url_id = visitor_table.last_url_id')->where('visitor_table.last_visit_at >= ( ? - INTERVAL ' . $minutes . ' MINUTE)', now());
     $customersCollection = AO::getModel('customer/customer')->getCollection();
     /* @var $customersCollection Mage_Customer_Model_Entity_Customer_Collection */
     $firstname = $customersCollection->getAttribute('firstname');
     $lastname = $customersCollection->getAttribute('lastname');
     $email = $customersCollection->getAttribute('email');
     $this->_select->from('', array('type' => 'IF(customer_id, \'' . Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER . '\', \'' . Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR . '\')'))->joinLeft(array('customer_lastname_table' => $lastname->getBackend()->getTable()), 'customer_lastname_table.entity_id=customer_table.customer_id
              AND customer_lastname_table.attribute_id = ' . (int) $lastname->getAttributeId() . '
              ', array('customer_lastname' => 'value'))->joinLeft(array('customer_firstname_table' => $firstname->getBackend()->getTable()), 'customer_firstname_table.entity_id=customer_table.customer_id
              AND customer_firstname_table.attribute_id = ' . (int) $firstname->getAttributeId() . '
              ', array('customer_firstname' => 'value'))->joinLeft(array('customer_email_table' => $email->getBackend()->getTable()), 'customer_email_table.entity_id=customer_table.customer_id', array('customer_email' => 'email'));
     return $this;
 }
Ejemplo n.º 10
0
 /**
  * Saving information about quote
  *
  * @param   Mage_Log_Model_Visitor $visitor
  * @return  Mage_Log_Model_Mysql4_Visitor
  */
 protected function _saveQuoteInfo($visitor)
 {
     $write = $this->_getWriteAdapter();
     if ($visitor->getDoQuoteCreate()) {
         $write->insert($this->getTable('log/quote_table'), array('quote_id' => $visitor->getQuoteId(), 'visitor_id' => $visitor->getId(), 'created_at' => now()));
         $visitor->setDoQuoteCreate(false);
     }
     if ($visitor->getDoQuoteDestroy()) {
         $write->update($this->getTable('log/quote_table'), array('deleted_at' => now()), $write->quoteInto('quote_id=?', $visitor->getQuoteId()));
         $visitor->setDoQuoteDestroy(false);
         $visitor->setQuoteId(null);
     }
     return $this;
 }
 /**
  * get the time spent on the site as a DateInterval
  * returns null if unable to calculate the interval.
  * @param  Mage_Log_Model_Visitor
  * @return DateInterval
  */
 protected function _getTimeSpentOnSite(Mage_Log_Model_Visitor $visitorLog = null)
 {
     if ($visitorLog) {
         $start = date_create_from_format(self::MAGE_DATETIME_FORMAT, $visitorLog->getFirstVisitAt()) ?: null;
         $end = date_create_from_format(self::MAGE_DATETIME_FORMAT, $visitorLog->getLastVisitAt()) ?: null;
         if ($start && $end && $start < $end) {
             $timeSpentOnSite = $end->diff($start);
         }
     }
     return isset($timeSpentOnSite) ? $timeSpentOnSite : null;
 }