00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Wishlist_Model_Mysql4_Product_Collection
00036 extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
00037 {
00038
00039
00040
00041
00042
00043
00044 public function addWishlistFilter(Mage_Wishlist_Model_Wishlist $wishlist)
00045 {
00046 $this->_joinFields['e_id'] = array(
00047 'table' => 'e',
00048 'field' => 'entity_id'
00049 );
00050
00051 $this->joinTable('wishlist/item',
00052 'product_id=e_id',
00053 array(
00054 'product_id' => 'product_id',
00055 'wishlist_item_description' => 'description',
00056 'store_id' => 'store_id',
00057 'added_at' => 'added_at',
00058 'wishlist_id' => 'wishlist_id',
00059 'wishlist_item_id' => 'wishlist_item_id',
00060 ),
00061 array(
00062 'wishlist_id' => $wishlist->getId(),
00063 'store_id' => array('in' => $wishlist->getSharedStoreIds())
00064 )
00065 );
00066 return $this;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076 public function addWishListSortOrder($attribute = 'added_at', $dir = 'desc')
00077 {
00078 $this->setOrder($attribute, $dir);
00079 return $this;
00080 }
00081
00082
00083
00084
00085
00086
00087 public function addStoreData()
00088 {
00089 if (!isset($this->_joinFields['e_id'])) {
00090 return $this;
00091 }
00092
00093 $dayTable = $this->_getAttributeTableAlias('days_in_wishlist');
00094 $this->joinField('store_name', 'core/store', 'name', 'store_id=store_id');
00095 $this->joinField('days_in_wishlist',
00096 'wishlist/item',
00097 "(TO_DAYS('" . Mage::getSingleton('core/date')->date() . "') - TO_DAYS(DATE_ADD(".$dayTable.".added_at, INTERVAL " .(int) Mage::getSingleton('core/date')->getGmtOffset() . " SECOND)))",
00098 'wishlist_item_id=wishlist_item_id'
00099 );
00100
00101 return $this;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 protected function _getAttributeFieldName($attributeCode)
00111 {
00112 if ($attributeCode == 'days_in_wishlist') {
00113 return $this->_joinFields[$attributeCode]['field'];
00114 }
00115 return parent::_getAttributeFieldName($attributeCode);
00116 }
00117 }