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: 36: 37: 38: 39: 40:
41: class Eabi_Livehandler_Model_Action_Postoffice_Send extends Eabi_Livehandler_Model_Action_Abstract {
42: 43: 44: 45:
46: protected $_code = 'postoffice_send';
47: protected $_label;
48: private static $_module_exists;
49:
50: public function __construct() {
51: if (self::$_module_exists === null) {
52: $modulesArray = (array)Mage::getConfig()->getNode('modules')->children();
53: self::$_module_exists = isset($modulesArray['Eabi_Postoffice']);
54: }
55:
56: }
57:
58:
59:
60:
61: 62: 63: 64:
65: public function canDisplay(Mage_Sales_Model_Order $order) {
66: if (self::$_module_exists) {
67: $this->_label = $this->_getOfficeHelper()->__('Send shipping data to server');
68: if ($this->_getOfficeHelper()->isDataSent($order->getIncrementId()) === false) {
69: $barcode = $this->_getOfficeHelper()->getBarcode($order->getIncrementId());
70: if (is_string($barcode)) {
71: return false;
72: }
73:
74: return true;
75: }
76: }
77: return false;
78: }
79:
80: 81: 82: 83: 84: 85: 86:
87: public function performDesiredAction(Mage_Sales_Model_Order $order, array $params) {
88:
89:
90: $shippingMethod = $order->getShippingMethod();
91: $paymentMethod = $order->getPayment();
92: $errors = array();
93:
94: $shippingCarrierCode = substr($shippingMethod, 0, strpos($shippingMethod, '_'));
95: $shippingMethodModel = Mage::getModel('shipping/shipping')->getCarrierByCode($shippingCarrierCode, $order->getStoreId());
96:
97: if (!($shippingMethodModel instanceof Eabi_Postoffice_Model_Carrier_Abstract)){
98: $errors[] = $this->_getOfficeHelper()->__('This carrier is not subclass of Eabi_Postoffice_Model_Carrier_Abstract');
99: }
100: $shippingMethodModel->setStoreId($order->getStoreId());
101:
102:
103: if (!count($errors) && !$shippingMethodModel->isAutoSendAvailable()) {
104: $errors[] = $this->_getOfficeHelper()->__('Automatic data sending is not available for the selected carrier');
105: }
106:
107: if (!method_exists($this->_getOfficeHelper(), 'canSendData')) {
108:
109: if (!count($errors) && round($order->getTotalDue(), 2) > 0 && (!$shippingMethodModel->getConfigData('enable_cod') ||
110: (!count($errors) && $shippingMethodModel->getConfigData('enable_cod') && $paymentMethod->getMethod() != 'eabicodpayment'))) {
111: $errors[] = $this->_getOfficeHelper()->__('This order has not yet been fully paid');
112: }
113: } else {
114: if (!$this->_getOfficeHelper()->canSendData($order)) {
115: $errors[] = $this->_getOfficeHelper()->__('This order has not yet been fully paid');
116: }
117: }
118:
119:
120:
121:
122: if (!count($errors) && ($order->isCanceled() || $order->getIsVirtual())) {
123: $errors[] = $this->_getOfficeHelper()->__('This order cannot be shipped');
124: }
125:
126:
127:
128: $messages = array();
129: if (!count($errors)) {
130: $this->_getOfficeHelper()->sendManualOrderData($order->getIncrementId(), $shippingMethodModel->getConfigData('senddata_event'));
131: $messages[] = $this->_getOfficeHelper()->__('Data sent to server, please verify the status from the order comments');
132:
133: }
134:
135:
136: $result = array(
137: 'messages' => $messages,
138: 'errors' => $errors,
139: 'needs_reload' => false,
140: 'is_action_error' => false,
141: );
142: return $result;
143: }
144:
145: 146: 147: 148:
149: protected function _getOfficeHelper() {
150: return Mage::helper('eabi_postoffice');
151: }
152:
153: }
154:
155: