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_Sales_Model_Order_Config extends Mage_Core_Model_Config_Base
00035 {
00036 private $_states;
00037
00038 public function __construct()
00039 {
00040 parent::__construct(Mage::getConfig()->getNode('global/sales/order'));
00041 }
00042
00043 protected function _getStatus($status)
00044 {
00045 return $this->getNode('statuses/'.$status);
00046 }
00047
00048 protected function _getState($state)
00049 {
00050 return $this->getNode('states/'.$state);
00051 }
00052
00053
00054
00055
00056
00057
00058
00059 public function getStateDefaultStatus($state)
00060 {
00061 $status = false;
00062 if ($stateNode = $this->_getState($state)) {
00063 if ($stateNode->statuses) {
00064 foreach ($stateNode->statuses->children() as $statusNode) {
00065 if (!$status) {
00066 $status = $statusNode->getName();
00067 }
00068 $attributes = $statusNode->attributes();
00069 if (isset($attributes['default'])) {
00070 $status = $statusNode->getName();
00071 }
00072 }
00073 }
00074 }
00075 return $status;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 public function getStatusLabel($status)
00085 {
00086 if ($statusNode = $this->_getStatus($status)) {
00087 $status = (string) $statusNode->label;
00088 return Mage::helper('sales')->__($status);
00089 }
00090 return $status;
00091 }
00092
00093
00094
00095
00096
00097
00098 public function getStatuses()
00099 {
00100 $statuses = array();
00101 foreach ($this->getNode('statuses')->children() as $status) {
00102 $label = (string) $status->label;
00103 $statuses[$status->getName()] = Mage::helper('sales')->__($label);
00104 }
00105 return $statuses;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 public function getStateStatuses($state, $addLabels = true)
00118 {
00119 $statuses = array();
00120 if (empty($state) || !is_array($state)) {
00121 $state = array($state);
00122 }
00123 foreach ($state as $_state) {
00124 if ($stateNode = $this->_getState($_state)) {
00125 foreach ($stateNode->statuses->children() as $statusNode) {
00126 $status = $statusNode->getName();
00127 if ($addLabels) {
00128 $statuses[$status] = $this->getStatusLabel($status);
00129 }
00130 else {
00131 $statuses[] = $status;
00132 }
00133 }
00134 }
00135 }
00136 return $statuses;
00137 }
00138
00139
00140
00141
00142
00143
00144 public function getVisibleOnFrontStates()
00145 {
00146 $this->_getStates();
00147 return $this->_states['visible'];
00148 }
00149
00150
00151
00152
00153
00154
00155 public function getInvisibleOnFrontStates()
00156 {
00157 $this->_getStates();
00158 return $this->_states['invisible'];
00159 }
00160
00161 private function _getStates()
00162 {
00163 if (null === $this->_states) {
00164 $this->_states = array(
00165 'all' => array(),
00166 'visible' => array(),
00167 'invisible' => array(),
00168 'statuses' => array(),
00169 );
00170 foreach ($this->getNode('states')->children() as $state) {
00171 $name = $state->getName();
00172 $this->_states['all'][] = $name;
00173 if ($state->visible_on_front){
00174 $this->_states['visible'][] = $name;
00175 }
00176 else {
00177 $this->_states['invisible'][] = $name;
00178 }
00179 foreach ($state->statuses->children() as $status) {
00180 $this->_states['statuses'][$name][] = $status->getName();
00181 }
00182 }
00183 }
00184 }
00185 }