1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Sales
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Sales order details block
29: *
30: * @category Mage
31: * @package Mage_Sales
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Sales_Block_Order_Print_Shipment extends Mage_Sales_Block_Items_Abstract
36: {
37: /**
38: * Tracks for Shippings
39: *
40: * @var array
41: */
42: protected $_tracks = array();
43:
44: /**
45: * Order shipments collection
46: *
47: * @var array|Mage_Sales_Model_Mysql4_Order_Shipment_Collection
48: */
49: protected $_shipmentsCollection;
50:
51: /**
52: * Load all tracks and save it to local cache by shipments
53: *
54: * @return Mage_Sales_Block_Order_Print_Shipment
55: */
56: protected function _beforeToHtml()
57: {
58: $tracksCollection = $this->getOrder()->getTracksCollection();
59:
60: foreach($tracksCollection->getItems() as $track) {
61: $shipmentId = $track->getParentId();
62: $this->_tracks[$shipmentId][] = $track;
63: }
64:
65: $shipment = Mage::registry('current_shipment');
66: if($shipment) {
67: $this->_shipmentsCollection = array($shipment);
68: } else {
69: $this->_shipmentsCollection = $this->getOrder()->getShipmentsCollection();
70: }
71:
72: return parent::_beforeToHtml();
73: }
74:
75: protected function _prepareLayout()
76: {
77: if ($headBlock = $this->getLayout()->getBlock('head')) {
78: $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId()));
79: }
80: $this->setChild(
81: 'payment_info',
82: $this->helper('payment')->getInfoBlock($this->getOrder()->getPayment())
83: );
84: }
85:
86: public function getBackUrl()
87: {
88: return Mage::getUrl('*/*/history');
89: }
90:
91: public function getPrintUrl()
92: {
93: return Mage::getUrl('*/*/print');
94: }
95:
96: public function getPaymentInfoHtml()
97: {
98: return $this->getChildHtml('payment_info');
99: }
100:
101: public function getOrder()
102: {
103: return Mage::registry('current_order');
104: }
105:
106: public function getShipment()
107: {
108: return Mage::registry('current_shipment');
109: }
110:
111: protected function _prepareItem(Mage_Core_Block_Abstract $renderer)
112: {
113: $renderer->setPrintStatus(true);
114:
115: return parent::_prepareItem($renderer);
116: }
117:
118: /**
119: * Retrieve order shipments collection
120: *
121: * @return array|Mage_Sales_Model_Mysql4_Order_Shipment_Collection
122: */
123: public function getShipmentsCollection()
124: {
125: return $this->_shipmentsCollection;
126: }
127:
128: /**
129: * Getter for order tracking numbers collection per shipment
130: *
131: * @param Mage_Sales_Model_Order_Shipment $shipment
132: * @return array
133: */
134: public function getShipmentTracks($shipment)
135: {
136: $tracks = array();
137: if (!empty($this->_tracks[$shipment->getId()])) {
138: $tracks = $this->_tracks[$shipment->getId()];
139: }
140: return $tracks;
141: }
142:
143: /**
144: * Getter for shipment address by format
145: *
146: * @param Mage_Sales_Model_Order_Shipment $shipment
147: * @return string
148: */
149: public function getShipmentAddressFormattedHtml($shipment)
150: {
151: $shippingAddress = $shipment->getShippingAddress();
152: if(!($shippingAddress instanceof Mage_Sales_Model_Order_Address)) {
153: return '';
154: }
155: return $shippingAddress->format('html');
156: }
157:
158: /**
159: * Getter for billing address of order by format
160: *
161: * @param Mage_Sales_Model_Order $order
162: * @return string
163: */
164: public function getBillingAddressFormattedHtml($order)
165: {
166: $billingAddress = $order->getBillingAddress();
167: if(!($billingAddress instanceof Mage_Sales_Model_Order_Address)) {
168: return '';
169: }
170: return $billingAddress->format('html');
171: }
172:
173: /**
174: * Getter for billing address of order by format
175: *
176: * @param Mage_Sales_Model_Order_Shipment $shipment
177: * @return array
178: */
179: public function getShipmentItems($shipment)
180: {
181: $res = array();
182: foreach ($shipment->getItemsCollection() as $item) {
183: if (!$item->getOrderItem()->getParentItem()) {
184: $res[] = $item;
185: }
186: }
187: return $res;
188: }
189: }
190:
191: