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 class Mage_Adminhtml_Block_Customer_Edit_Tab_View_Sales extends Mage_Adminhtml_Block_Template
00035 {
00036
00037
00038
00039
00040
00041
00042 protected $_collection;
00043
00044 protected $_groupedCollection;
00045 protected $_websiteCounts;
00046
00047
00048
00049
00050
00051
00052 protected $_currency;
00053
00054 public function __construct()
00055 {
00056 parent::__construct();
00057 $this->setId('customer_view_sales_grid');
00058 }
00059
00060 public function _beforeToHtml()
00061 {
00062 $this->_currency = Mage::getModel('directory/currency')
00063 ->load(Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE))
00064 ;
00065
00066 $this->_collection = Mage::getResourceModel('sales/sale_collection')
00067 ->setCustomerFilter(Mage::registry('current_customer'))
00068 ->load()
00069 ;
00070
00071 $this->_groupedCollection = array();
00072
00073 foreach ($this->_collection as $sale) {
00074 if (!is_null($sale->getStoreId())) {
00075 $store = Mage::app()->getStore($sale->getStoreId());
00076 $websiteId = $store->getWebsiteId();
00077 $groupId = $store->getGroupId();
00078 $storeId = $store->getId();
00079
00080 $sale->setWebsiteId($store->getWebsiteId());
00081 $sale->setWebsiteName($store->getWebsite()->getName());
00082 $sale->setGroupId($store->getGroupId());
00083 $sale->setGroupName($store->getGroup()->getName());
00084 }
00085 else {
00086 $websiteId = 0;
00087 $groupId = 0;
00088 $storeId = 0;
00089
00090 $sale->setStoreName(Mage::helper('customer')->__('Deleted Stores'));
00091 }
00092
00093 $this->_groupedCollection[$websiteId][$groupId][$storeId] = $sale;
00094 $this->_websiteCounts[$websiteId] = isset($this->_websiteCounts[$websiteId]) ? $this->_websiteCounts[$websiteId] + 1 : 1;
00095 }
00096
00097 return parent::_beforeToHtml();
00098 }
00099
00100 public function getWebsiteCount($websiteId)
00101 {
00102 return isset($this->_websiteCounts[$websiteId]) ? $this->_websiteCounts[$websiteId] : 0;
00103 }
00104
00105 public function getRows()
00106 {
00107 return $this->_groupedCollection;
00108 }
00109
00110 public function getTotals()
00111 {
00112 return $this->_collection->getTotals();
00113 }
00114
00115 public function getPriceFormatted($price)
00116 {
00117 return $this->_currency->format($price);
00118 }
00119
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136