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:
35: class Mage_Adminhtml_Block_Sales_Order_Shipment_Packaging extends Mage_Adminhtml_Block_Template
36: {
37: 38: 39: 40: 41:
42: public function getShipment()
43: {
44: return Mage::registry('current_shipment');
45: }
46:
47: 48: 49: 50: 51:
52: public function getConfigDataJson()
53: {
54: $shipmentId = $this->getShipment()->getId();
55: $orderId = $this->getRequest()->getParam('order_id');
56: $urlParams = array();
57:
58: $itemsQty = array();
59: $itemsPrice = array();
60: $itemsName = array();
61: $itemsWeight = array();
62: $itemsProductId = array();
63:
64: if ($shipmentId) {
65: $urlParams['shipment_id'] = $shipmentId;
66: $createLabelUrl = $this->getUrl('*/sales_order_shipment/createLabel', $urlParams);
67: $itemsGridUrl = $this->getUrl('*/sales_order_shipment/getShippingItemsGrid', $urlParams);
68: foreach ($this->getShipment()->getAllItems() as $item) {
69: $itemsQty[$item->getId()] = $item->getQty();
70: $itemsPrice[$item->getId()] = $item->getPrice();
71: $itemsName[$item->getId()] = $item->getName();
72: $itemsWeight[$item->getId()] = $item->getWeight();
73: $itemsProductId[$item->getId()] = $item->getProductId();
74: $itemsOrderItemId[$item->getId()] = $item->getOrderItemId();
75: }
76: } else if ($orderId) {
77: $urlParams['order_id'] = $orderId;
78: $createLabelUrl = $this->getUrl('*/sales_order_shipment/save', $urlParams);
79: $itemsGridUrl = $this->getUrl('*/sales_order_shipment/getShippingItemsGrid', $urlParams);
80:
81: foreach ($this->getShipment()->getAllItems() as $item) {
82: $itemsQty[$item->getOrderItemId()] = $item->getQty()*1;
83: $itemsPrice[$item->getOrderItemId()] = $item->getPrice();
84: $itemsName[$item->getOrderItemId()] = $item->getName();
85: $itemsWeight[$item->getOrderItemId()] = $item->getWeight();
86: $itemsProductId[$item->getOrderItemId()] = $item->getProductId();
87: $itemsOrderItemId[$item->getOrderItemId()] = $item->getOrderItemId();
88: }
89: }
90: $data = array(
91: 'createLabelUrl' => $createLabelUrl,
92: 'itemsGridUrl' => $itemsGridUrl,
93: 'errorQtyOverLimit' => Mage::helper('sales')->__('The quantity you want to add exceeds the total shipped quantity for some of selected Product(s)'),
94: 'titleDisabledSaveBtn' => Mage::helper('sales')->__('Products should be added to package(s)'),
95: 'validationErrorMsg' => Mage::helper('sales')->__('The value that you entered is not valid.'),
96: 'shipmentItemsQty' => $itemsQty,
97: 'shipmentItemsPrice' => $itemsPrice,
98: 'shipmentItemsName' => $itemsName,
99: 'shipmentItemsWeight' => $itemsWeight,
100: 'shipmentItemsProductId' => $itemsProductId,
101: 'shipmentItemsOrderItemId' => $itemsOrderItemId,
102: 'customizable' => $this->_getCustomizableContainers(),
103: );
104: return Mage::helper('core')->jsonEncode($data);
105: }
106:
107: 108: 109: 110: 111:
112: public function getContainers()
113: {
114: $order = $this->getShipment()->getOrder();
115: $storeId = $this->getShipment()->getStoreId();
116: $address = $order->getShippingAddress();
117: $carrier = $order->getShippingCarrier();
118: $countryShipper = Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $storeId);
119: if ($carrier) {
120: $params = new Varien_Object(array(
121: 'method' => $order->getShippingMethod(true)->getMethod(),
122: 'country_shipper' => $countryShipper,
123: 'country_recipient' => $address->getCountryId(),
124: ));
125: return $carrier->getContainerTypes($params);
126: }
127: return array();
128: }
129:
130: 131: 132: 133: 134:
135: protected function _getCustomizableContainers()
136: {
137: $carrier = $this->getShipment()->getOrder()->getShippingCarrier();
138: if ($carrier) {
139: return $carrier->getCustomizableContainerTypes();
140: }
141: return array();
142: }
143:
144: 145: 146: 147: 148: 149:
150: public function getContainerTypeByCode($code)
151: {
152: $carrier = $this->getShipment()->getOrder()->getShippingCarrier();
153: if ($carrier) {
154: $containerTypes = $carrier->getContainerTypes();
155: $containerType = !empty($containerTypes[$code]) ? $containerTypes[$code] : '';
156: return $containerType;
157: }
158: return '';
159: }
160:
161: 162: 163: 164: 165: 166:
167: public function getDeliveryConfirmationTypeByCode($code)
168: {
169: $countryId = $this->getShipment()->getOrder()->getShippingAddress()->getCountryId();
170: $carrier = $this->getShipment()->getOrder()->getShippingCarrier();
171: if ($carrier) {
172: $params = new Varien_Object(array('country_recipient' => $countryId));
173: $confirmationTypes = $carrier->getDeliveryConfirmationTypes($params);
174: $confirmationType = !empty($confirmationTypes[$code]) ? $confirmationTypes[$code] : '';
175: return $confirmationType;
176: }
177: return '';
178: }
179:
180: 181: 182: 183: 184: 185:
186: public function getContentTypeByCode($code)
187: {
188: $contentTypes = $this->getContentTypes();
189: if (!empty($contentTypes[$code])) {
190: return $contentTypes[$code];
191: }
192: return '';
193: }
194:
195: 196: 197: 198: 199:
200: public function getPackages()
201: {
202: $packages = $this->getShipment()->getPackages();
203: if ($packages) {
204: $packages = unserialize($packages);
205: } else {
206: $packages = array();
207: }
208: return $packages;
209: }
210:
211: 212: 213: 214: 215: 216: 217:
218: public function getShipmentItem($itemId, $itemsOf)
219: {
220: $items = $this->getShipment()->getAllItems();
221: foreach ($items as $item) {
222: if ($itemsOf == 'order' && $item->getOrderItemId() == $itemId) {
223: return $item;
224: } else if ($itemsOf == 'shipment' && $item->getId() == $itemId) {
225: return $item;
226: }
227: }
228: return new Varien_Object();
229: }
230:
231: 232: 233: 234: 235:
236: public function displayCustomsValue()
237: {
238: $storeId = $this->getShipment()->getStoreId();
239: $order = $this->getShipment()->getOrder();
240: $address = $order->getShippingAddress();
241: $shipperAddressCountryCode = Mage::getStoreConfig(
242: Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID,
243: $storeId
244: );
245: $recipientAddressCountryCode = $address->getCountryId();
246: if ($shipperAddressCountryCode != $recipientAddressCountryCode) {
247: return true;
248: }
249: return false;
250: }
251:
252: 253: 254: 255: 256:
257: public function getDeliveryConfirmationTypes()
258: {
259: $countryId = $this->getShipment()->getOrder()->getShippingAddress()->getCountryId();
260: $carrier = $this->getShipment()->getOrder()->getShippingCarrier();
261: $params = new Varien_Object(array('country_recipient' => $countryId));
262: if ($carrier && is_array($carrier->getDeliveryConfirmationTypes($params))) {
263: return $carrier->getDeliveryConfirmationTypes($params);
264: }
265: return array();
266: }
267:
268: 269: 270: 271: 272:
273: public function getPrintButton()
274: {
275: $data['shipment_id'] = $this->getShipment()->getId();
276: $url = $this->getUrl('*/sales_order_shipment/printPackage', $data);
277: return $this->getLayout()
278: ->createBlock('adminhtml/widget_button')
279: ->setData(array(
280: 'label' => Mage::helper('sales')->__('Print'),
281: 'onclick' => 'setLocation(\'' . $url . '\')'
282: ))
283: ->toHtml();
284: }
285:
286: 287: 288: 289: 290:
291: public function isGirthAllowed()
292: {
293: return $this
294: ->getShipment()
295: ->getOrder()
296: ->getShippingCarrier()
297: ->isGirthAllowed($this->getShipment()->getOrder()->getShippingAddress()->getCountryId());
298: }
299:
300: 301: 302: 303: 304:
305: public function getContentTypes()
306: {
307: $order = $this->getShipment()->getOrder();
308: $storeId = $this->getShipment()->getStoreId();
309: $address = $order->getShippingAddress();
310: $carrier = $order->getShippingCarrier();
311: $countryShipper = Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $storeId);
312: if ($carrier) {
313: $params = new Varien_Object(array(
314: 'method' => $order->getShippingMethod(true)->getMethod(),
315: 'country_shipper' => $countryShipper,
316: 'country_recipient' => $address->getCountryId(),
317: ));
318: return $carrier->getContentTypes($params);
319: }
320: return array();
321: }
322:
323: 324: 325: 326: 327:
328: public function getCustomValueCurrencyCode()
329: {
330: $orderInfo = $this->getShipment()->getOrder();
331: return $orderInfo->getBaseCurrency()->getCurrencyCode();
332: }
333:
334: 335: 336: 337: 338: 339:
340: public function displayPrice($price)
341: {
342: return $this->getShipment()->getOrder()->formatPriceTxt($price);
343: }
344:
345: 346: 347: 348: 349: 350:
351: public function displayCustomsPrice($price)
352: {
353: $orderInfo = $this->getShipment()->getOrder();
354: return $orderInfo->getBaseCurrency()->formatTxt($price);
355: }
356:
357: 358: 359: 360: 361: 362:
363: public function getQtyOrderedItem($itemId)
364: {
365: if ($itemId) {
366: return $this->getShipment()->getOrder()->getItemById($itemId)->getQtyOrdered()*1;
367: } else {
368: return;
369: }
370: }
371: }
372: