PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Info.php

https://github.com/ticean/magento-mirror
PHP | 164 lines | 94 code | 13 blank | 57 comment | 11 complexity | 7ae2812b7a2c76b90ab741d2ed60504a MD5 | raw file
  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) 2010 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. * Order history block
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Sales_Order_View_Info extends Mage_Adminhtml_Block_Sales_Order_Abstract
  34. {
  35. /**
  36. * Retrieve required options from parent
  37. */
  38. protected function _beforeToHtml()
  39. {
  40. if (!$this->getParentBlock()) {
  41. Mage::throwException(Mage::helper('adminhtml')->__('Invalid parent block for this block.'));
  42. }
  43. $this->setOrder($this->getParentBlock()->getOrder());
  44. foreach ($this->getParentBlock()->getOrderInfoData() as $k => $v) {
  45. $this->setDataUsingMethod($k, $v);
  46. }
  47. parent::_beforeToHtml();
  48. }
  49. public function getOrderStoreName()
  50. {
  51. if ($this->getOrder()) {
  52. $storeId = $this->getOrder()->getStoreId();
  53. if (is_null($storeId)) {
  54. $deleted = Mage::helper('adminhtml')->__(' [deleted]');
  55. return nl2br($this->getOrder()->getStoreName()) . $deleted;
  56. }
  57. $store = Mage::app()->getStore($storeId);
  58. $name = array(
  59. $store->getWebsite()->getName(),
  60. $store->getGroup()->getName(),
  61. $store->getName()
  62. );
  63. return implode('<br/>', $name);
  64. }
  65. return null;
  66. }
  67. public function getCustomerGroupName()
  68. {
  69. if ($this->getOrder()) {
  70. return Mage::getModel('customer/group')->load((int)$this->getOrder()->getCustomerGroupId())->getCode();
  71. }
  72. return null;
  73. }
  74. public function getCustomerViewUrl()
  75. {
  76. if ($this->getOrder()->getCustomerIsGuest()) {
  77. return false;
  78. }
  79. return $this->getUrl('*/customer/edit', array('id' => $this->getOrder()->getCustomerId()));
  80. }
  81. public function getViewUrl($orderId)
  82. {
  83. return $this->getUrl('*/sales_order/view', array('order_id'=>$orderId));
  84. }
  85. /**
  86. * Find sort order for account data
  87. * Sort Order used as array key
  88. *
  89. * @param array $data
  90. * @param int $sortOrder
  91. * @return int
  92. */
  93. protected function _prepareAccountDataSortOrder(array $data, $sortOrder)
  94. {
  95. if (isset($data[$sortOrder])) {
  96. return $this->_prepareAccountDataSortOrder($data, $sortOrder + 1);
  97. }
  98. return $sortOrder;
  99. }
  100. /**
  101. * Return array of additional account data
  102. * Value is option style array
  103. *
  104. * @return array
  105. */
  106. public function getCustomerAccountData()
  107. {
  108. $accountData = array();
  109. /* @var $config Mage_Eav_Model_Config */
  110. $config = Mage::getSingleton('eav/config');
  111. $entityType = 'customer';
  112. $customer = Mage::getModel('customer/customer');
  113. foreach ($config->getEntityAttributeCodes($entityType) as $attributeCode) {
  114. /* @var $attribute Mage_Customer_Model_Attribute */
  115. $attribute = $config->getAttribute($entityType, $attributeCode);
  116. if (!$attribute->getIsVisible() || $attribute->getIsSystem()) {
  117. continue;
  118. }
  119. $orderKey = sprintf('customer_%s', $attribute->getAttributeCode());
  120. $orderValue = $this->getOrder()->getData($orderKey);
  121. if ($orderValue != '') {
  122. $customer->setData($attribute->getAttributeCode(), $orderValue);
  123. $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $customer);
  124. $value = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_HTML);
  125. $sortOrder = $attribute->getSortOrder() + $attribute->getIsUserDefined() ? 200 : 0;
  126. $sortOrder = $this->_prepareAccountDataSortOrder($accountData, $sortOrder);
  127. $accountData[$sortOrder] = array(
  128. 'label' => $attribute->getFrontendLabel(),
  129. 'value' => $this->escapeHtml($value, array('br'))
  130. );
  131. }
  132. }
  133. ksort($accountData, SORT_NUMERIC);
  134. return $accountData;
  135. }
  136. /**
  137. * Get link to edit order address page
  138. *
  139. * @param Mage_Sales_Model_Order_Address $address
  140. * @param string $label
  141. * @return string
  142. */
  143. public function getAddressEditLink($address, $label='')
  144. {
  145. if (empty($label)) {
  146. $label = $this->__('Edit');
  147. }
  148. $url = $this->getUrl('*/sales_order/address', array('address_id'=>$address->getId()));
  149. return '<a href="'.$url.'">' . $label . '</a>';
  150. }
  151. }