1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: abstract class Mage_Sales_Model_Order_Pdf_Items_Abstract extends Mage_Core_Model_Abstract
35: {
36: 37: 38: 39: 40:
41: protected $_order;
42:
43: 44: 45: 46: 47:
48: protected $_source;
49:
50: 51: 52: 53: 54:
55: protected $_item;
56:
57: 58: 59: 60: 61:
62: protected $_pdf;
63:
64: 65: 66: 67: 68:
69: protected $_pdfPage;
70:
71: 72: 73: 74: 75: 76:
77: public function setOrder(Mage_Sales_Model_Order $order)
78: {
79: $this->_order = $order;
80: return $this;
81: }
82:
83: 84: 85: 86: 87: 88:
89: public function setSource(Mage_Core_Model_Abstract $source)
90: {
91: $this->_source = $source;
92: return $this;
93: }
94:
95: 96: 97: 98: 99: 100:
101: public function setItem(Varien_Object $item)
102: {
103: $this->_item = $item;
104: return $this;
105: }
106:
107: 108: 109: 110: 111: 112:
113: public function setPdf(Mage_Sales_Model_Order_Pdf_Abstract $pdf)
114: {
115: $this->_pdf = $pdf;
116: return $this;
117: }
118:
119: 120: 121: 122: 123: 124:
125: public function setPage(Zend_Pdf_Page $page)
126: {
127: $this->_pdfPage = $page;
128: return $this;
129: }
130:
131: 132: 133: 134: 135: 136:
137: public function getOrder()
138: {
139: if (is_null($this->_order)) {
140: Mage::throwException(Mage::helper('sales')->__('Order object is not specified.'));
141: }
142: return $this->_order;
143: }
144:
145: 146: 147: 148: 149: 150:
151: public function getSource()
152: {
153: if (is_null($this->_source)) {
154: Mage::throwException(Mage::helper('sales')->__('Source object is not specified.'));
155: }
156: return $this->_source;
157: }
158:
159: 160: 161: 162: 163: 164:
165: public function getItem()
166: {
167: if (is_null($this->_item)) {
168: Mage::throwException(Mage::helper('sales')->__('Item object is not specified.'));
169: }
170: return $this->_item;
171: }
172:
173: 174: 175: 176: 177: 178:
179: public function getPdf()
180: {
181: if (is_null($this->_pdf)) {
182: Mage::throwException(Mage::helper('sales')->__('PDF object is not specified.'));
183: }
184: return $this->_pdf;
185: }
186:
187: 188: 189: 190: 191: 192:
193: public function getPage()
194: {
195: if (is_null($this->_pdfPage)) {
196: Mage::throwException(Mage::helper('sales')->__('PDF page object is not specified.'));
197: }
198: return $this->_pdfPage;
199: }
200:
201: 202: 203: 204:
205: abstract public function draw();
206:
207: 208: 209: 210: 211: 212:
213: protected function _formatOptionValue($value)
214: {
215: $order = $this->getOrder();
216:
217: $resultValue = '';
218: if (is_array($value)) {
219: if (isset($value['qty'])) {
220: $resultValue .= sprintf('%d', $value['qty']) . ' x ';
221: }
222:
223: $resultValue .= $value['title'];
224:
225: if (isset($value['price'])) {
226: $resultValue .= " " . $order->formatPrice($value['price']);
227: }
228: return $resultValue;
229: } else {
230: return $value;
231: }
232: }
233:
234: 235: 236: 237: 238:
239: protected function _parseDescription()
240: {
241: $description = $this->getItem()->getDescription();
242: if (preg_match_all('/<li.*?>(.*?)<\/li>/i', $description, $matches)) {
243: return $matches[1];
244: }
245:
246: return array($description);
247: }
248:
249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259:
260: public function getItemPricesForDisplay()
261: {
262: $order = $this->getOrder();
263: $item = $this->getItem();
264: if (Mage::helper('tax')->displaySalesBothPrices()) {
265: $prices = array(
266: array(
267: 'label' => Mage::helper('tax')->__('Excl. Tax') . ':',
268: 'price' => $order->formatPriceTxt($item->getPrice()),
269: 'subtotal' => $order->formatPriceTxt($item->getRowTotal())
270: ),
271: array(
272: 'label' => Mage::helper('tax')->__('Incl. Tax') . ':',
273: 'price' => $order->formatPriceTxt($item->getPriceInclTax()),
274: 'subtotal' => $order->formatPriceTxt($item->getRowTotalInclTax())
275: ),
276: );
277: } elseif (Mage::helper('tax')->displaySalesPriceInclTax()) {
278: $prices = array(array(
279: 'price' => $order->formatPriceTxt($item->getPriceInclTax()),
280: 'subtotal' => $order->formatPriceTxt($item->getRowTotalInclTax()),
281: ));
282: } else {
283: $prices = array(array(
284: 'price' => $order->formatPriceTxt($item->getPrice()),
285: 'subtotal' => $order->formatPriceTxt($item->getRowTotal()),
286: ));
287: }
288: return $prices;
289: }
290:
291: 292: 293: 294: 295:
296: public function getItemOptions() {
297: $result = array();
298: if ($options = $this->getItem()->getOrderItem()->getProductOptions()) {
299: if (isset($options['options'])) {
300: $result = array_merge($result, $options['options']);
301: }
302: if (isset($options['additional_options'])) {
303: $result = array_merge($result, $options['additional_options']);
304: }
305: if (isset($options['attributes_info'])) {
306: $result = array_merge($result, $options['attributes_info']);
307: }
308: }
309: return $result;
310: }
311:
312: 313: 314: 315: 316: 317:
318: protected function _setFontRegular($size = 7)
319: {
320: $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');
321: $this->getPage()->setFont($font, $size);
322: return $font;
323: }
324:
325: 326: 327: 328: 329: 330:
331: protected function _setFontBold($size = 7)
332: {
333: $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Bd-2.8.1.ttf');
334: $this->getPage()->setFont($font, $size);
335: return $font;
336: }
337:
338: 339: 340: 341: 342: 343:
344: protected function _setFontItalic($size = 7)
345: {
346: $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf');
347: $this->getPage()->setFont($font, $size);
348: return $font;
349: }
350:
351: 352: 353: 354: 355: 356:
357: public function getSku($item)
358: {
359: if ($item->getOrderItem()->getProductOptionByCode('simple_sku'))
360: return $item->getOrderItem()->getProductOptionByCode('simple_sku');
361: else
362: return $item->getSku();
363: }
364: }
365: