Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Reports_Block_Product_Abstract
  • Mage_Reports_Block_Product_Compared
  • Mage_Reports_Block_Product_Viewed
  • Mage_Reports_Block_Product_Widget_Compared
  • Mage_Reports_Block_Product_Widget_Viewed
  • Mage_Reports_Exception
  • Mage_Reports_Helper_Data
  • Mage_Reports_Model_Config
  • Mage_Reports_Model_Event
  • Mage_Reports_Model_Event_Observer
  • Mage_Reports_Model_Event_Type
  • Mage_Reports_Model_Flag
  • Mage_Reports_Model_Grouped_Collection
  • Mage_Reports_Model_Mysql4_Accounts_Collection
  • Mage_Reports_Model_Mysql4_Coupons_Collection
  • Mage_Reports_Model_Mysql4_Customer_Collection
  • Mage_Reports_Model_Mysql4_Customer_Orders_Collection
  • Mage_Reports_Model_Mysql4_Customer_Totals_Collection
  • Mage_Reports_Model_Mysql4_Entity_Summary_Collection_Abstract
  • Mage_Reports_Model_Mysql4_Event
  • Mage_Reports_Model_Mysql4_Event_Collection
  • Mage_Reports_Model_Mysql4_Event_Type
  • Mage_Reports_Model_Mysql4_Event_Type_Collection
  • Mage_Reports_Model_Mysql4_Invoiced_Collection
  • Mage_Reports_Model_Mysql4_Order_Collection
  • Mage_Reports_Model_Mysql4_Product_Collection
  • Mage_Reports_Model_Mysql4_Product_Downloads_Collection
  • Mage_Reports_Model_Mysql4_Product_Index_Abstract
  • Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract
  • Mage_Reports_Model_Mysql4_Product_Index_Compared
  • Mage_Reports_Model_Mysql4_Product_Index_Compared_Collection
  • Mage_Reports_Model_Mysql4_Product_Index_Viewed
  • Mage_Reports_Model_Mysql4_Product_Index_Viewed_Collection
  • Mage_Reports_Model_Mysql4_Product_Lowstock_Collection
  • Mage_Reports_Model_Mysql4_Product_Ordered_Collection
  • Mage_Reports_Model_Mysql4_Product_Sold_Collection
  • Mage_Reports_Model_Mysql4_Product_Viewed_Collection
  • Mage_Reports_Model_Mysql4_Quote_Collection
  • Mage_Reports_Model_Mysql4_Refunded_Collection
  • Mage_Reports_Model_Mysql4_Report_Abstract
  • Mage_Reports_Model_Mysql4_Report_Collection
  • Mage_Reports_Model_Mysql4_Review_Collection
  • Mage_Reports_Model_Mysql4_Review_Customer_Collection
  • Mage_Reports_Model_Mysql4_Review_Product_Collection
  • Mage_Reports_Model_Mysql4_Shipping_Collection
  • Mage_Reports_Model_Mysql4_Tag_Collection
  • Mage_Reports_Model_Mysql4_Tag_Customer_Collection
  • Mage_Reports_Model_Mysql4_Tag_Product_Collection
  • Mage_Reports_Model_Mysql4_Tax_Collection
  • Mage_Reports_Model_Mysql4_Wishlist_Collection
  • Mage_Reports_Model_Mysql4_Wishlist_Product_Collection
  • Mage_Reports_Model_Product_Index_Abstract
  • Mage_Reports_Model_Product_Index_Compared
  • Mage_Reports_Model_Product_Index_Viewed
  • Mage_Reports_Model_Report
  • Mage_Reports_Model_Resource_Accounts_Collection
  • Mage_Reports_Model_Resource_Coupons_Collection
  • Mage_Reports_Model_Resource_Customer_Collection
  • Mage_Reports_Model_Resource_Customer_Orders_Collection
  • Mage_Reports_Model_Resource_Customer_Totals_Collection
  • Mage_Reports_Model_Resource_Entity_Summary_Collection_Abstract
  • Mage_Reports_Model_Resource_Event
  • Mage_Reports_Model_Resource_Event_Collection
  • Mage_Reports_Model_Resource_Event_Type
  • Mage_Reports_Model_Resource_Event_Type_Collection
  • Mage_Reports_Model_Resource_Helper_Mysql4
  • Mage_Reports_Model_Resource_Invoiced_Collection
  • Mage_Reports_Model_Resource_Order_Collection
  • Mage_Reports_Model_Resource_Product_Collection
  • Mage_Reports_Model_Resource_Product_Downloads_Collection
  • Mage_Reports_Model_Resource_Product_Index_Abstract
  • Mage_Reports_Model_Resource_Product_Index_Collection_Abstract
  • Mage_Reports_Model_Resource_Product_Index_Compared
  • Mage_Reports_Model_Resource_Product_Index_Compared_Collection
  • Mage_Reports_Model_Resource_Product_Index_Viewed
  • Mage_Reports_Model_Resource_Product_Index_Viewed_Collection
  • Mage_Reports_Model_Resource_Product_Lowstock_Collection
  • Mage_Reports_Model_Resource_Product_Ordered_Collection
  • Mage_Reports_Model_Resource_Product_Sold_Collection
  • Mage_Reports_Model_Resource_Product_Viewed_Collection
  • Mage_Reports_Model_Resource_Quote_Collection
  • Mage_Reports_Model_Resource_Refunded_Collection
  • Mage_Reports_Model_Resource_Report_Abstract
  • Mage_Reports_Model_Resource_Report_Collection
  • Mage_Reports_Model_Resource_Report_Collection_Abstract
  • Mage_Reports_Model_Resource_Report_Product_Viewed
  • Mage_Reports_Model_Resource_Report_Product_Viewed_Collection
  • Mage_Reports_Model_Resource_Review_Collection
  • Mage_Reports_Model_Resource_Review_Customer_Collection
  • Mage_Reports_Model_Resource_Review_Product_Collection
  • Mage_Reports_Model_Resource_Shipping_Collection
  • Mage_Reports_Model_Resource_Shopcart_Product_Collection
  • Mage_Reports_Model_Resource_Tag_Collection
  • Mage_Reports_Model_Resource_Tag_Customer_Collection
  • Mage_Reports_Model_Resource_Tag_Product_Collection
  • Mage_Reports_Model_Resource_Tax_Collection
  • Mage_Reports_Model_Resource_Wishlist_Collection
  • Mage_Reports_Model_Resource_Wishlist_Product_Collection
  • Mage_Reports_Model_Session
  • Mage_Reports_Model_Test
  • Mage_Reports_Model_Totals

Interfaces

  • Mage_Reports_Model_Resource_Helper_Interface
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Reports
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Reports Product Index Abstract Resource Model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Reports
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: abstract class Mage_Reports_Model_Resource_Product_Index_Abstract extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Fields List for update in forsedSave
 39:      *
 40:      * @var array
 41:      */
 42:     protected $_fieldsForUpdate    = array('store_id', 'added_at');
 43: 
 44:     /**
 45:      * Update Customer from visitor (Customer logged in)
 46:      *
 47:      * @param Mage_Reports_Model_Product_Index_Abstract $object
 48:      * @return Mage_Reports_Model_Resource_Product_Index_Abstract
 49:      */
 50:     public function updateCustomerFromVisitor(Mage_Reports_Model_Product_Index_Abstract $object)
 51:     {
 52:         /**
 53:          * Do nothing if customer not logged in
 54:          */
 55:         if (!$object->getCustomerId() || !$object->getVisitorId()) {
 56:             return $this;
 57:         }
 58:         $adapter = $this->_getWriteAdapter();
 59:         $select  = $adapter->select()
 60:             ->from($this->getMainTable())
 61:             ->where('visitor_id = ?', $object->getVisitorId());
 62: 
 63:         $rowSet = $select->query()->fetchAll();
 64:         foreach ($rowSet as $row) {
 65: 
 66:             /* We need to determine if there are rows with known
 67:                customer for current product.
 68:              */
 69: 
 70:             $select = $adapter->select()
 71:                 ->from($this->getMainTable())
 72:                 ->where('customer_id = ?', $object->getCustomerId())
 73:                 ->where('product_id = ?', $row['product_id']);
 74:             $idx = $adapter->fetchRow($select);
 75: 
 76:             if ($idx) {
 77:             /* If we are here it means that we have two rows: one with known customer, but second just visitor is set
 78:              * One row should be updated with customer_id, second should be deleted
 79:              *
 80:              */
 81:                 $adapter->delete($this->getMainTable(), array('index_id = ?' => $row['index_id']));
 82:                 $where = array('index_id = ?' => $idx['index_id']);
 83:                 $data  = array(
 84:                     'visitor_id'    => $object->getVisitorId(),
 85:                     'store_id'      => $object->getStoreId(),
 86:                     'added_at'      => Varien_Date::now(),
 87:                 );
 88:             } else {
 89:                 $where = array('index_id = ?' => $row['index_id']);
 90:                 $data  = array(
 91:                     'customer_id'   => $object->getCustomerId(),
 92:                     'store_id'      => $object->getStoreId(),
 93:                     'added_at'      => Varien_Date::now()
 94:                 );
 95:             }
 96: 
 97:             $adapter->update($this->getMainTable(), $data, $where);
 98: 
 99:         }
100:         return $this;
101:     }
102: 
103:     /**
104:      * Purge visitor data by customer (logout)
105:      *
106:      * @param Mage_Reports_Model_Product_Index_Abstract $object
107:      * @return Mage_Reports_Model_Resource_Product_Index_Abstract
108:      */
109:     public function purgeVisitorByCustomer(Mage_Reports_Model_Product_Index_Abstract $object)
110:     {
111:         /**
112:          * Do nothing if customer not logged in
113:          */
114:         if (!$object->getCustomerId()) {
115:             return $this;
116:         }
117: 
118:         $bind   = array('visitor_id'      => null);
119:         $where  = array('customer_id = ?' => (int)$object->getCustomerId());
120:         $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where);
121: 
122:         return $this;
123:     }
124: 
125:     /**
126:      * Save Product Index data (forced save)
127:      *
128:      * @param Mage_Reports_Model_Product_Index_Abstract $object
129:      * @return Mage_Reports_Model_Resource_Product_Index_Abstract
130:      */
131:     public function save(Mage_Core_Model_Abstract  $object)
132:     {
133:         if ($object->isDeleted()) {
134:             return $this->delete($object);
135:         }
136: 
137:         $this->_serializeFields($object);
138:         $this->_beforeSave($object);
139:         $this->_checkUnique($object);
140: 
141:         $data = $this->_prepareDataForSave($object);
142:         unset($data[$this->getIdFieldName()]);
143: 
144:         $matchFields = array('product_id', 'store_id');
145: 
146:         Mage::getResourceHelper('reports')->mergeVisitorProductIndex(
147:             $this->getMainTable(),
148:             $data,
149:             $matchFields
150:         );
151: 
152: 
153:         $this->unserializeFields($object);
154:         $this->_afterSave($object);
155: 
156:         return $this;
157:     }
158: 
159: 
160:     /**
161:      * Clean index (visitor)
162:      *
163:      * @return Mage_Reports_Model_Resource_Product_Index_Abstract
164:      */
165:     public function clean()
166:     {
167:         while (true) {
168:             $select = $this->_getReadAdapter()->select()
169:                 ->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName()))
170:                 ->joinLeft(
171:                     array('visitor_table' => $this->getTable('log/visitor')),
172:                     'main_table.visitor_id = visitor_table.visitor_id',
173:                     array())
174:                 ->where('main_table.visitor_id > ?', 0)
175:                 ->where('visitor_table.visitor_id IS NULL')
176:                 ->limit(100);
177:             $indexIds = $this->_getReadAdapter()->fetchCol($select);
178: 
179:             if (!$indexIds) {
180:                 break;
181:             }
182: 
183:             $this->_getWriteAdapter()->delete(
184:                 $this->getMainTable(),
185:                 $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . ' IN(?)', $indexIds)
186:             );
187:         }
188:         return $this;
189:     }
190: 
191:     /**
192:      * Add information about product ids to visitor/customer
193:      *
194:      *
195:      * @param Mage_Reports_Model_Product_Index_Abstract $object
196:      * @param array $productIds
197:      * @return Mage_Reports_Model_Resource_Product_Index_Abstract
198:      */
199:     public function registerIds(Varien_Object $object, $productIds)
200:     {
201:         $row = array(
202:             'visitor_id'    => $object->getVisitorId(),
203:             'customer_id'   => $object->getCustomerId(),
204:             'store_id'      => $object->getStoreId(),
205:         );
206:         $addedAt    = Varien_Date::toTimestamp(true);
207:         $data = array();
208:         foreach ($productIds as $productId) {
209:             $productId = (int) $productId;
210:             if ($productId) {
211:                 $row['product_id'] = $productId;
212:                 $row['added_at']   = Varien_Date::formatDate($addedAt);
213:                 $data[] = $row;
214:             }
215:             $addedAt -= ($addedAt > 0) ? 1 : 0;
216:         }
217: 
218:         $matchFields = array('product_id', 'store_id');
219:         foreach ($data as $row) {
220:             Mage::getResourceHelper('reports')->mergeVisitorProductIndex(
221:                 $this->getMainTable(),
222:                 $row,
223:                 $matchFields
224:             );
225:         }
226:         return $this;
227:     }
228: }
229: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0