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_Adminhtml
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: * Adminhtml customer view wishlist block
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Customer_Edit_Tab_View_Sales extends Mage_Adminhtml_Block_Template
35: {
36:
37: /**
38: * Sales entity collection
39: *
40: * @var Mage_Sales_Model_Entity_Sale_Collection
41: */
42: protected $_collection;
43:
44: protected $_groupedCollection;
45: protected $_websiteCounts;
46:
47: /**
48: * Currency model
49: *
50: * @var Mage_Directory_Model_Currency
51: */
52: protected $_currency;
53:
54: public function __construct()
55: {
56: parent::__construct();
57: $this->setId('customer_view_sales_grid');
58: }
59:
60: public function _beforeToHtml()
61: {
62: $this->_currency = Mage::getModel('directory/currency')
63: ->load(Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE))
64: ;
65:
66: $this->_collection = Mage::getResourceModel('sales/sale_collection')
67: ->setCustomerFilter(Mage::registry('current_customer'))
68: ->setOrderStateFilter(Mage_Sales_Model_Order::STATE_CANCELED, true)
69: ->load()
70: ;
71:
72: $this->_groupedCollection = array();
73:
74: foreach ($this->_collection as $sale) {
75: if (!is_null($sale->getStoreId())) {
76: $store = Mage::app()->getStore($sale->getStoreId());
77: $websiteId = $store->getWebsiteId();
78: $groupId = $store->getGroupId();
79: $storeId = $store->getId();
80:
81: $sale->setWebsiteId($store->getWebsiteId());
82: $sale->setWebsiteName($store->getWebsite()->getName());
83: $sale->setGroupId($store->getGroupId());
84: $sale->setGroupName($store->getGroup()->getName());
85: }
86: else {
87: $websiteId = 0;
88: $groupId = 0;
89: $storeId = 0;
90:
91: $sale->setStoreName(Mage::helper('customer')->__('Deleted Stores'));
92: }
93:
94: $this->_groupedCollection[$websiteId][$groupId][$storeId] = $sale;
95: $this->_websiteCounts[$websiteId] = isset($this->_websiteCounts[$websiteId]) ? $this->_websiteCounts[$websiteId] + 1 : 1;
96: }
97:
98: return parent::_beforeToHtml();
99: }
100:
101: public function getWebsiteCount($websiteId)
102: {
103: return isset($this->_websiteCounts[$websiteId]) ? $this->_websiteCounts[$websiteId] : 0;
104: }
105:
106: public function getRows()
107: {
108: return $this->_groupedCollection;
109: }
110:
111: public function getTotals()
112: {
113: return $this->_collection->getTotals();
114: }
115:
116: /**
117: * @deprecated after 1.4.0.0-rc1
118: *
119: * @param float $price
120: * @return string
121: */
122: public function getPriceFormatted($price)
123: {
124: return $this->_currency->format($price);
125: }
126:
127: /**
128: * Format price by specified website
129: *
130: * @param float $price
131: * @param null|int $websiteId
132: * @return string
133: */
134: public function formatCurrency($price, $websiteId = null)
135: {
136: return Mage::app()->getWebsite($websiteId)->getBaseCurrency()->format($price);
137: }
138:
139: }
140: