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_Items_Renderer_Default extends Mage_Adminhtml_Block_Sales_Items_Abstract
00035 {
00036 public function getItem()
00037 {
00038 return $this->_getData('item');
00039 }
00040
00041
00042
00043
00044
00045
00046 protected $_giftMessage = array();
00047
00048
00049
00050
00051
00052
00053 public function getDefaultSender()
00054 {
00055 if(!$this->getItem()) {
00056 return '';
00057 }
00058
00059 if($this->getItem()->getOrder()) {
00060 return $this->getItem()->getOrder()->getBillingAddress()->getName();
00061 }
00062
00063 return $this->getItem()->getBillingAddress()->getName();
00064 }
00065
00066
00067
00068
00069
00070
00071 public function getDefaultRecipient()
00072 {
00073 if(!$this->getItem()) {
00074 return '';
00075 }
00076
00077 if($this->getItem()->getOrder()) {
00078 if ($this->getItem()->getOrder()->getShippingAddress()) {
00079 return $this->getItem()->getOrder()->getShippingAddress()->getName();
00080 } else if ($this->getItem()->getOrder()->getBillingAddress()) {
00081 return $this->getItem()->getOrder()->getBillingAddress()->getName();
00082 }
00083 }
00084
00085 if ($this->getItem()->getShippingAddress()) {
00086 return $this->getItem()->getShippingAddress()->getName();
00087 } else if ($this->getItem()->getBillingAddress()) {
00088 return $this->getItem()->getBillingAddress()->getName();
00089 }
00090
00091 return '';
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 public function getFieldName($name)
00101 {
00102 return 'giftmessage[' . $this->getItem()->getId() . '][' . $name . ']';
00103 }
00104
00105
00106
00107
00108
00109
00110
00111 public function getFieldId($id)
00112 {
00113 return $this->getFieldIdPrefix() . $id;
00114 }
00115
00116
00117
00118
00119
00120
00121 public function getFieldIdPrefix()
00122 {
00123 return 'giftmessage_item_' . $this->getItem()->getId() . '_';
00124 }
00125
00126
00127
00128
00129
00130
00131 protected function _initMessage()
00132 {
00133 $this->_giftMessage[$this->getItem()->getGiftMessageId()] =
00134 $this->helper('giftmessage/message')->getGiftMessage($this->getItem()->getGiftMessageId());
00135
00136
00137 if(!$this->getMessage()->getSender()) {
00138 $this->getMessage()->setSender($this->getDefaultSender());
00139 }
00140 if(!$this->getMessage()->getRecipient()) {
00141 $this->getMessage()->setRecipient($this->getDefaultRecipient());
00142 }
00143
00144 return $this;
00145 }
00146
00147
00148
00149
00150
00151
00152 public function getMessage()
00153 {
00154 if(!isset($this->_giftMessage[$this->getItem()->getGiftMessageId()])) {
00155 $this->_initMessage();
00156 }
00157
00158 return $this->_giftMessage[$this->getItem()->getGiftMessageId()];
00159 }
00160
00161
00162
00163
00164
00165
00166 public function getSaveUrl()
00167 {
00168 return $this->getUrl('*/sales_order_view_giftmessage/save', array(
00169 'entity' => $this->getItem()->getId(),
00170 'type' => 'order_item',
00171 'reload' => true
00172 ));
00173 }
00174
00175
00176
00177
00178
00179
00180 public function getHtmlId()
00181 {
00182 return substr($this->getFieldIdPrefix(), 0, -1);
00183 }
00184
00185
00186
00187
00188
00189
00190 public function canDisplayContainer()
00191 {
00192 return $this->getRequest()->getParam('reload')!=1;
00193 }
00194
00195
00196
00197
00198
00199
00200 public function canDisplayGiftmessage()
00201 {
00202 return $this->helper('giftmessage/message')->getIsMessagesAvailable(
00203 'order_item', $this->getItem(), $this->getItem()->getOrder()->getStoreId()
00204 );
00205 }
00206 }