Public Member Functions | |
joinCustomers () | |
getSelectCountSql () |
Definition at line 35 of file Collection.php.
getSelectCountSql | ( | ) |
Get SQL for get record count
Reimplemented from Varien_Data_Collection_Db.
Definition at line 78 of file Collection.php.
00079 { 00080 $countSelect = clone $this->_select; 00081 $countSelect->reset(Zend_Db_Select::ORDER); 00082 $countSelect->reset(Zend_Db_Select::GROUP); 00083 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); 00084 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); 00085 00086 $sql = $countSelect->__toString(); 00087 00088 $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(DISTINCT `detail`.`customer_id`) from ', $sql); 00089 00090 return $sql; 00091 }
joinCustomers | ( | ) |
Definition at line 37 of file Collection.php.
00038 { 00039 $customer = Mage::getResourceSingleton('customer/customer'); 00040 //TODO: add full name logic 00041 $firstnameAttr = $customer->getAttribute('firstname'); 00042 $firstnameAttrId = $firstnameAttr->getAttributeId(); 00043 $firstnameTable = $firstnameAttr->getBackend()->getTable(); 00044 00045 if ($firstnameAttr->getBackend()->isStatic()) { 00046 $firstnameField = 'firstname'; 00047 $attrCondition = ''; 00048 } else { 00049 $firstnameField = 'value'; 00050 $attrCondition = ' AND _table_customer_firstname.attribute_id = '.$firstnameAttrId; 00051 } 00052 00053 $this->getSelect()->joinInner(array('_table_customer_firstname' => $firstnameTable), 00054 '_table_customer_firstname.entity_id=detail.customer_id'.$attrCondition, array()); 00055 00056 $lastnameAttr = $customer->getAttribute('lastname'); 00057 $lastnameAttrId = $lastnameAttr->getAttributeId(); 00058 $lastnameTable = $lastnameAttr->getBackend()->getTable(); 00059 00060 if ($lastnameAttr->getBackend()->isStatic()) { 00061 $lastnameField = 'lastname'; 00062 $attrCondition = ''; 00063 } else { 00064 $lastnameField = 'value'; 00065 $attrCondition = ' AND _table_customer_lastname.attribute_id = '.$lastnameAttrId; 00066 } 00067 00068 $this->getSelect()->joinInner(array('_table_customer_lastname' => $lastnameTable), 00069 '_table_customer_lastname.entity_id=detail.customer_id'.$attrCondition, array()) 00070 ->from("", array( 00071 'customer_name' => "CONCAT(_table_customer_firstname.{$firstnameField}, ' ', _table_customer_lastname.{$lastnameField})", 00072 'review_cnt' => "COUNT(main_table.review_id)")) 00073 ->group('detail.customer_id'); 00074 00075 return $this; 00076 }