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
00035 abstract class Mage_Sales_Model_Order_Pdf_Items_Abstract extends Mage_Core_Model_Abstract
00036 {
00037
00038
00039
00040
00041
00042 protected $_order;
00043
00044
00045
00046
00047
00048
00049 protected $_source;
00050
00051
00052
00053
00054
00055
00056 protected $_item;
00057
00058
00059
00060
00061
00062
00063 protected $_pdf;
00064
00065
00066
00067
00068
00069
00070 protected $_pdfPage;
00071
00072
00073
00074
00075
00076
00077
00078 public function setOrder(Mage_Sales_Model_Order $order)
00079 {
00080 $this->_order = $order;
00081 return $this;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090 public function setSource(Mage_Core_Model_Abstract $source)
00091 {
00092 $this->_source = $source;
00093 return $this;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 public function setItem(Varien_Object $item)
00103 {
00104 $this->_item = $item;
00105 return $this;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114 public function setPdf(Mage_Sales_Model_Order_Pdf_Abstract $pdf)
00115 {
00116 $this->_pdf = $pdf;
00117 return $this;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 public function setPage(Zend_Pdf_Page $page)
00127 {
00128 $this->_pdfPage = $page;
00129 return $this;
00130 }
00131
00132
00133
00134
00135
00136
00137
00138 public function getOrder()
00139 {
00140 if (is_null($this->_order)) {
00141 Mage::throwException(Mage::helper('sales')->__('Order object is not specified.'));
00142 }
00143 return $this->_order;
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 public function getSource()
00153 {
00154 if (is_null($this->_source)) {
00155 Mage::throwException(Mage::helper('sales')->__('Source object is not specified.'));
00156 }
00157 return $this->_source;
00158 }
00159
00160
00161
00162
00163
00164
00165
00166 public function getItem()
00167 {
00168 if (is_null($this->_item)) {
00169 Mage::throwException(Mage::helper('sales')->__('Item object is not specified.'));
00170 }
00171 return $this->_item;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 public function getPdf()
00181 {
00182 if (is_null($this->_pdf)) {
00183 Mage::throwException(Mage::helper('sales')->__('PDF object is not specified.'));
00184 }
00185 return $this->_pdf;
00186 }
00187
00188
00189
00190
00191
00192
00193
00194 public function getPage()
00195 {
00196 if (is_null($this->_pdfPage)) {
00197 Mage::throwException(Mage::helper('sales')->__('PDF page object is not specified.'));
00198 }
00199 return $this->_pdfPage;
00200 }
00201
00202
00203
00204
00205
00206 abstract public function draw();
00207
00208 protected function _formatOptionValue($value)
00209 {
00210 $order = $this->getOrder();
00211
00212 $resultValue = '';
00213 if (is_array($value)) {
00214 if (isset($value['qty'])) {
00215 $resultValue .= sprintf('%d', $value['qty']) . ' x ';
00216 }
00217
00218 $resultValue .= $value['title'];
00219
00220 if (isset($value['price'])) {
00221 $resultValue .= " " . $order->formatPrice($value['price']);
00222 }
00223 return $resultValue;
00224 } else {
00225 return $value;
00226 }
00227 }
00228
00229 protected function _parseDescription()
00230 {
00231 $description = $this->getItem()->getDescription();
00232 if (preg_match_all('/<li.*?>(.*?)<\/li>/i', $description, $matches)) {
00233 return $matches[1];
00234 }
00235
00236 return array($description);
00237 }
00238
00239 public function getItemOptions() {
00240 $result = array();
00241 if ($options = $this->getItem()->getOrderItem()->getProductOptions()) {
00242 if (isset($options['options'])) {
00243 $result = array_merge($result, $options['options']);
00244 }
00245 if (isset($options['additional_options'])) {
00246 $result = array_merge($result, $options['additional_options']);
00247 }
00248 if (isset($options['attributes_info'])) {
00249 $result = array_merge($result, $options['attributes_info']);
00250 }
00251 }
00252 return $result;
00253 }
00254
00255 protected function _setFontRegular($size = 7)
00256 {
00257 $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertineC_Re-2.8.0.ttf');
00258 $this->getPage()->setFont($font, $size);
00259 return $font;
00260 }
00261
00262 protected function _setFontBold($size = 7)
00263 {
00264 $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Bd-2.8.1.ttf');
00265 $this->getPage()->setFont($font, $size);
00266 return $font;
00267 }
00268
00269 protected function _setFontItalic($size = 7)
00270 {
00271 $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf');
00272 $this->getPage()->setFont($font, $size);
00273 return $font;
00274 }
00275
00276 public function getSku($item)
00277 {
00278 if ($item->getOrderItem()->getProductOptionByCode('simple_sku'))
00279 return $item->getOrderItem()->getProductOptionByCode('simple_sku');
00280 else
00281 return $item->getSku();
00282 }
00283 }