1: <?php
2:
3: /*
4:
5: *
6: * NOTICE OF LICENSE
7: *
8: * This source file is subject to the Open Software License (OSL 3.0)
9: * or OpenGPL v3 license (GNU Public License V3.0)
10: * that is bundled with this package in the file LICENSE.txt.
11: * It is also available through the world-wide-web at this URL:
12: * http://opensource.org/licenses/osl-3.0.php
13: * or
14: * http://www.gnu.org/licenses/gpl-3.0.txt
15: * If you did not receive a copy of the license and are unable to
16: * obtain it through the world-wide-web, please send an email
17: * to info@e-abi.ee so we can send you a copy immediately.
18: *
19: * DISCLAIMER
20: *
21: * Do not edit or add to this file if you wish to upgrade this module to newer
22: * versions in the future.
23: *
24: * @category Eabi
25: * @package Eabi_Dpd
26: * @copyright Copyright (c) 2014 Aktsiamaailm LLC (http://en.e-abi.ee/)
27: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28: * @license http://www.gnu.org/licenses/gpl-3.0.txt GNU Public License V3.0
29: * @author Matis Halmann
30: *
31:
32: */
33:
34: /**
35: * <p>Renders button at the Magento Administrators Sales Order Grid, which allows to print packing slip from remote server for carriers which support this feature.</p>
36: * <p>Button is displayed when order shipping method supports remote packing slip printing and parcel data is sent.</p>
37: * <p>Does nothing when Eabi_Postoffice module is not installed</p>
38: *
39: * @author Matis
40: */
41: class Eabi_Livehandler_Model_Action_Postoffice_Print extends Eabi_Livehandler_Model_Action_Abstract {
42: /**
43: * <p>Unique code relative to eabi_livehandler/action</p>
44: * @var string
45: */
46: protected $_code = 'postoffice_print';
47: protected $_label;
48:
49:
50: private static $_module_exists;
51:
52:
53: public function __construct() {
54: if (self::$_module_exists === null) {
55: $modulesArray = (array)Mage::getConfig()->getNode('modules')->children();
56: self::$_module_exists = isset($modulesArray['Eabi_Postoffice']);
57: }
58: $this->_longOnClick = 'return false;';
59:
60: }
61:
62:
63:
64:
65: /**
66: * @param Mage_Sales_Model_Order $order
67: * @return boolean
68: */
69: public function canDisplay(Mage_Sales_Model_Order $order) {
70: if (self::$_module_exists) {
71: $this->_label = Mage::helper('eabi_postoffice')->__('Print packing slip');
72: $barcode = Mage::helper('eabi_postoffice')->getBarcode($order->getIncrementId());
73: if (is_string($barcode) || is_array($barcode)) {
74: $url = Mage::helper('adminhtml')->getUrl('eabi_postoffice/adminhtml_postoffice/addresscardpdf', array('order_id'=> $order->getId()));
75: $this->_onClick = "setLocation('".$url."')";
76: return true;
77: }
78: }
79: return false;
80: }
81:
82: /**
83: * <p>Does nothing</p>
84: * @param Mage_Sales_Model_Order $order
85: * @param array $params
86: * @return array
87: */
88: public function performDesiredAction(Mage_Sales_Model_Order $order, array $params) {
89:
90: $errors = array();
91: $messages = array();
92:
93: $result = array(
94: 'messages' => $messages,
95: 'errors' => $errors,
96: 'needs_reload' => false,
97: 'is_action_error' => false,
98: );
99: return $result;
100: }
101: }
102:
103: