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_Sales_Order_View extends Mage_Adminhtml_Block_Widget_Form_Container
00035 {
00036
00037 public function __construct()
00038 {
00039 $this->_objectId = 'order_id';
00040 $this->_controller = 'sales_order';
00041 $this->_mode = 'view';
00042
00043 parent::__construct();
00044
00045 $this->_removeButton('delete');
00046 $this->_removeButton('reset');
00047 $this->_removeButton('save');
00048 $this->setId('sales_order_view');
00049
00050 if ($this->_isAllowedAction('edit') && $this->getOrder()->canEdit()) {
00051 $onclickJs = 'deleteConfirm(\''
00052 . Mage::helper('sales')->__('Are you sure? This order will be cancelled and a new one will be created instead')
00053 . '\', \'' . $this->getEditUrl() . '\');';
00054 $this->_addButton('order_edit', array(
00055 'label' => Mage::helper('sales')->__('Edit'),
00056 'onclick' => $onclickJs,
00057 ));
00058 // see if order has non-editable products as items
00059 $nonEditableTypes = array_keys(Mage::getResourceSingleton('sales/order')->aggregateProductsByTypes(
00060 $this->getOrder()->getId(), array_keys(Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()), false
00061 ));
00062 if ($nonEditableTypes) {
00063 $this->_updateButton('order_edit', 'onclick',
00064 'if (!confirm(\'' . Mage::helper('sales')->__(
00065 'This order contains (%s) items and therefore cannot be edited through the admin interface at this time, if you wish to continue editing the (%s) items will be removed, the order will be cancelled and a new order will be placed',
00066 implode(', ', $nonEditableTypes),
00067 implode(', ', $nonEditableTypes)
00068 ) . '\')) return false;' . $onclickJs
00069 );
00070 }
00071 }
00072
00073 if ($this->_isAllowedAction('cancel') && $this->getOrder()->canCancel()) {
00074 $message = Mage::helper('sales')->__('Are you sure you want to cancel this order?');
00075 $this->_addButton('order_cancel', array(
00076 'label' => Mage::helper('sales')->__('Cancel'),
00077 'onclick' => 'deleteConfirm(\''.$message.'\', \'' . $this->getCancelUrl() . '\')',
00078 ));
00079 }
00080
00081 if ($this->_isAllowedAction('creditmemo') && $this->getOrder()->canCreditmemo()) {
00082 $this->_addButton('order_creditmemo', array(
00083 'label' => Mage::helper('sales')->__('Credit Memo'),
00084 'onclick' => 'setLocation(\'' . $this->getCreditmemoUrl() . '\')',
00085 ));
00086 }
00087
00088 if ($this->_isAllowedAction('hold') && $this->getOrder()->canHold()) {
00089 $this->_addButton('order_hold', array(
00090 'label' => Mage::helper('sales')->__('Hold'),
00091 'onclick' => 'setLocation(\'' . $this->getHoldUrl() . '\')',
00092 ));
00093 }
00094
00095 if ($this->_isAllowedAction('unhold') && $this->getOrder()->canUnhold()) {
00096 $this->_addButton('order_unhold', array(
00097 'label' => Mage::helper('sales')->__('Unhold'),
00098 'onclick' => 'setLocation(\'' . $this->getUnholdUrl() . '\')',
00099 ));
00100 }
00101
00102 if ($this->_isAllowedAction('invoice') && $this->getOrder()->canInvoice()) {
00103 $_label = $this->getOrder()->getForcedDoShipmentWithInvoice()?'Invoice and Ship':'Invoice';
00104 $this->_addButton('order_invoice', array(
00105 'label' => Mage::helper('sales')->__('%s', $_label),
00106 'onclick' => 'setLocation(\'' . $this->getInvoiceUrl() . '\')',
00107 ));
00108 }
00109
00110 if ($this->_isAllowedAction('ship') && $this->getOrder()->canShip()
00111 && !$this->getOrder()->getForcedDoShipmentWithInvoice()) {
00112 $this->_addButton('order_ship', array(
00113 'label' => Mage::helper('sales')->__('Ship'),
00114 'onclick' => 'setLocation(\'' . $this->getShipUrl() . '\')',
00115 ));
00116 }
00117
00118 if ($this->_isAllowedAction('reorder') && $this->getOrder()->canReorder()) {
00119 $this->_addButton('order_reorder', array(
00120 'label' => Mage::helper('sales')->__('Reorder'),
00121 'onclick' => 'setLocation(\'' . $this->getReorderUrl() . '\')',
00122 ));
00123 }
00124 }
00125
00126
00127
00128
00129
00130
00131 public function getOrder()
00132 {
00133 return Mage::registry('sales_order');
00134 }
00135
00136
00137
00138
00139
00140
00141 public function getOrderId()
00142 {
00143 return $this->getOrder()->getId();
00144 }
00145
00146 public function getHeaderText()
00147 {
00148 if ($_extOrderId = $this->getOrder()->getExtOrderId()) {
00149 $_extOrderId = '[' . $_extOrderId . '] ';
00150 } else {
00151 $_extOrderId = '';
00152 }
00153 $text = Mage::helper('sales')->__('Order # %s %s| Order Date %s',
00154 $this->getOrder()->getRealOrderId(),
00155 $_extOrderId,
00156 $this->formatDate($this->getOrder()->getCreatedAtDate(), 'medium', true)
00157 );
00158 return $text;
00159 }
00160
00161 public function getUrl($params='', $params2=array())
00162 {
00163 $params2['order_id'] = $this->getOrderId();
00164 return parent::getUrl($params, $params2);
00165 }
00166
00167 public function getEditUrl()
00168 {
00169 return $this->getUrl('*/sales_order_edit/start');
00170 }
00171
00172 public function getCancelUrl()
00173 {
00174 return $this->getUrl('*
00175
00176
00177
00178
00179 sales_order_invoice/start');
00180 }
00181
00182 public function getCreditmemoUrl()
00183 {
00184 return $this->getUrl('*/sales_order_creditmemo/start');
00185 }
00186
00187 public function getHoldUrl()
00188 {
00189 return $this->getUrl('*
00190
00191
00192
00193
00194 */unhold');
00195 }
00196
00197 public function getShipUrl()
00198 {
00199 return $this->getUrl('*/sales_order_shipment/start');
00200 }
00201
00202 public function getCommentUrl()
00203 {
00204 return $this->getUrl('*
00205
00206
00207
00208
00209 sales_order_create/reorder');
00210 }
00211
00212 protected function _isAllowedAction($action)
00213 {
00214 return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/' . $action);
00215 }
00216 }