Overview

Namespaces

  • None
  • PHP

Classes

  • Eabi_DpdEE_Block_Adminhtml_Config_Form_Field_Country
  • Eabi_DpdEE_Block_Info_Payment
  • Eabi_DpdEE_Block_Invoice
  • Eabi_DpdEE_Block_Order_Courier
  • Eabi_DpdEE_Helper_Data
  • Eabi_DpdEE_Model_Api
  • Eabi_DpdEE_Model_Button_Courier
  • Eabi_DpdEE_Model_Config
  • Eabi_DpdEE_Model_Flat
  • Eabi_DpdEE_Model_Observer
  • Eabi_DpdEE_Model_Payment_Processor
  • Eabi_DpdEE_Model_Post
  • Eabi_DpdEE_Model_Source_Label_Position
  • Eabi_DpdEE_Model_Source_Service
  • Eabi_Livehandler_Adminhtml_LivehandlerController
  • Eabi_Livehandler_Adminhtml_RemoveController
  • Eabi_Livehandler_Block_Adminhtml_Config_Form_Field_Button
  • Eabi_Livehandler_Block_Adminhtml_Config_Form_Field_Remove
  • Eabi_Livehandler_Block_Email
  • Eabi_LiveHandler_Block_Footer
  • Eabi_Livehandler_Helper_Data
  • Eabi_Livehandler_Helper_Keypair
  • Eabi_Livehandler_IndexController
  • Eabi_Livehandler_Model_Abstract
  • Eabi_Livehandler_Model_Action_Abstract
  • Eabi_Livehandler_Model_Action_Postoffice_Print
  • Eabi_Livehandler_Model_Action_Postoffice_Send
  • Eabi_Livehandler_Model_Adminhtml_Gridmanager
  • Eabi_Livehandler_Model_Directory_Collection
  • Eabi_Livehandler_Model_Entry
  • Eabi_Livehandler_Model_File_Object
  • Eabi_Livehandler_Model_Mysql4_Entry
  • Eabi_Livehandler_Model_Mysql4_Entry_Collection
  • Eabi_Livehandler_Model_Ordergrid
  • Eabi_Livehandler_Model_System_Config_Backend_Button
  • Eabi_Postoffice_Adminhtml_PostofficeController
  • Eabi_Postoffice_Block_Adminhtml_Config_Form_Field_License
  • Eabi_Postoffice_Block_Adminhtml_Config_Form_Field_Remove
  • Eabi_Postoffice_Block_Config_Rebuildbutton
  • Eabi_Postoffice_Helper_Countrycode
  • Eabi_Postoffice_Helper_Data
  • Eabi_Postoffice_IndexController
  • Eabi_Postoffice_Model_Carrier_Abstract
  • Eabi_Postoffice_Model_Carrier_Result
  • Eabi_Postoffice_Model_Carriermodule
  • Eabi_Postoffice_Model_Mysql4_Carriermodule
  • Eabi_Postoffice_Model_Mysql4_Carriermodule_Collection
  • Eabi_Postoffice_Model_Mysql4_Office
  • Eabi_Postoffice_Model_Mysql4_Office_Collection
  • Eabi_Postoffice_Model_Observer
  • Eabi_Postoffice_Model_Office
  • Eabi_Postoffice_Model_Orderview
  • Eabi_Postoffice_Model_Source_Sendevent
  • Eabi_Postoffice_Model_Updater
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: /*
  3:   
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * or OpenGPL v3 license (GNU Public License V3.0)
  9:  * that is bundled with this package in the file LICENSE.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * http://opensource.org/licenses/osl-3.0.php
 12:  * or
 13:  * http://www.gnu.org/licenses/gpl-3.0.txt
 14:  * If you did not receive a copy of the license and are unable to
 15:  * obtain it through the world-wide-web, please send an email
 16:  * to info@e-abi.ee so we can send you a copy immediately.
 17:  *
 18:  * DISCLAIMER
 19:  *
 20:  * Do not edit or add to this file if you wish to upgrade this module to newer
 21:  * versions in the future.
 22:  *
 23:  * @category   Eabi
 24:  * @package    Eabi_Dpd
 25:  * @copyright  Copyright (c) 2014 Aktsiamaailm LLC (http://en.e-abi.ee/)
 26:  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 27:  * @license    http://www.gnu.org/licenses/gpl-3.0.txt  GNU Public License V3.0
 28:  * @author     Matis Halmann
 29:  * 
 30: 
 31:  */
 32: 
 33: /**
 34:  *
 35:  * Contains the functions, which helps store administrator to place an order using this carrier or the subclasses of this carrier and
 36:  * also contains actions related to printing packing slips and sending automatic parcel data to the third party carrier server.
 37:  * @author matishalmann
 38:  */
 39: class Eabi_Postoffice_Adminhtml_PostofficeController extends Mage_Adminhtml_Controller_Action {
 40: 
 41:     protected function _initAction() {
 42:         return $this;
 43:     }
 44:     
 45:     protected function _construct() {
 46:         
 47:     }
 48:     
 49:     /**
 50:      *  Rebuilds the list of postoffices for the selected carrier immediately and returns json response.
 51:      * 
 52:      *  
 53:      */
 54:     public function rebuildAction() {
 55:         $result = $this->_rebuild();
 56:         echo json_encode($result);
 57:         die();
 58:     }
 59:     
 60:     protected function _rebuild() {
 61:         $carrierCode = $this->getRequest()->getParam('carrier_code', '');
 62:         if ($carrierCode == '') {
 63:             return array('error' => Mage::helper('eabi_postoffice')->__('Invalid Carrier code'));
 64:         }
 65:         $carrierModule = Mage::getModel('eabi_postoffice/carriermodule')->load($carrierCode, 'carrier_code');
 66:         if (!is_object($carrierModule) ||$carrierModule->getId() <= 0) {
 67:             return array('error' => Mage::helper('eabi_postoffice')->__('Invalid Carrier code'));
 68:         }
 69:         try {
 70:             $carrierModule->updateCarrierData(true);
 71:         } catch (Exception $e) {
 72:             return array('error' => $e->getMessage());
 73:         }
 74:         return array('success' => true);
 75:         
 76:     }
 77:     
 78:     /**
 79:      *  Prints out packing slip pdf for the selected order as response or echoes that barcode is not available.
 80:      * 
 81:      * 
 82:      * @return type 
 83:      */
 84:     public function addresscardpdfAction() {
 85:         $orderId = (int)$this->getRequest()->getParam('order_id', 0);
 86:         if ($orderId <= 0) {
 87:             return;
 88:         }
 89:         $order = Mage::getModel('sales/order')->load($orderId);
 90:         if (!$order || $order->getId() <= 0) {
 91:             return;
 92:         }
 93:         $incrementId = $order->getIncrementId();
 94:         $res = Mage::helper('eabi_postoffice')->getBarcodePdf($incrementId);
 95:         if ($res !== false) {
 96:             header('Content-Type: application/pdf');
 97:             header('Content-Disposition: attachment; filename="addresscard-' . $incrementId . '.pdf"');
 98:             echo $res;
 99:         } else {
100:             echo 'No barcode available';
101:         }
102:     }
103: 
104:     /**
105:      *  Attempts to automatically send the shipment data for the selected order to the third party carrier server
106:      * and returns the result as json response.
107:      * 
108:      * 
109:      *  
110:      */
111:     public function autosendAction() {
112:         $result = $this->_autoSend();
113:         echo json_encode($result);
114:         die();
115:     }
116:     
117:     protected function _autoSend() {
118:         //get the order id
119:         $orderId = (int)$this->getRequest()->getParam('order_id', 0);
120:         if ($orderId <= 0) {
121:             return array('error' => Mage::helper('eabi_postoffice')->__('Invalid Order ID'));
122:         }
123:         $order = Mage::getModel('sales/order')->load($orderId);
124:         if (!$order || $order->getId() <= 0) {
125:             return array('error' => Mage::helper('eabi_postoffice')->__('Invalid Order ID'));
126:         }
127:         
128:         //get the carrier
129:         $shippingMethod = $order->getShippingMethod();
130:         $paymentMethod = $order->getPayment();
131:         
132:         //get the shipping code from the order and call the module from it.
133:         $shippingCarrierCode = substr($shippingMethod, 0, strpos($shippingMethod, '_'));
134:         $shippingMethodModel = Mage::getModel('shipping/shipping')->getCarrierByCode($shippingCarrierCode, $order->getStoreId());
135:         
136:         if (!($shippingMethodModel instanceof Eabi_Postoffice_Model_Carrier_Abstract)){
137:             return array('error' => Mage::helper('eabi_postoffice')->__('This carrier is not subclass of Eabi_Postoffice_Model_Carrier_Abstract'));
138:         }
139:         $shippingMethodModel->setStoreId($order->getStoreId());
140:         
141:         //determine if auto send is available
142:         if (!$shippingMethodModel->isAutoSendAvailable()) {
143:             return array('error' => Mage::helper('eabi_postoffice')->__('Automatic data sending is not available for the selected carrier'));
144:         }
145:         
146:         if (!$this->_getOfficeHelper()->canSendData($order)) {
147:             return array('error' => Mage::helper('eabi_postoffice')->__('This order has not yet been fully paid'));
148:         }
149:         
150:         
151:         if (($order->isCanceled() || $order->getIsVirtual())) {
152:             return array('error' => Mage::helper('eabi_postoffice')->__('This order cannot be shipped'));
153:         }
154:         
155:         
156:         //send the data
157:         Mage::helper('eabi_postoffice')->sendManualOrderData($order->getIncrementId(), $shippingMethodModel->getConfigData('senddata_event'));
158:         
159:         
160:         //return the results
161:         return array('success' => true);
162:         
163:     }
164:     
165:     /**
166:      *  <p>Returns the contents for the selected carriers.</p>
167:      * <p>Mainly it returns two select menus, where first select menu contains all the groups and
168:      * second select menu contains actual offices, which belong to the selected group</p>
169:      * 
170:      * 
171:      * 
172:      * 
173:      * @return html
174:      * @throws Exception 
175:      */
176:     public function officeAction() {
177:         try {
178:             if ($this->getRequest()->isPost()) {
179:                 $this->getResponse()->setHeader('Content-type', 'application/json');
180:                 $jsonResponse = array(
181:                     'html' => false,
182:                     'comment' => false,
183:                 );
184: 
185:                 $post = $this->getRequest()->getPost();
186:                 $storeId = (int)$this->getRequest()->getParam('store_id', 0);
187:                 if ($storeId <= 0) {
188:                     throw new Exception('Store ID must be supplied');
189:                 }
190:                 $url = $this->getUrl('eabi_postoffice/adminhtml_postoffice/office', array('store_id' => $storeId, '_secure' => true));
191:                 $addressId = $post['address_id'];
192:                 $carrierCode = $post['carrier_code'];
193:                 $carrierId = $post['carrier_id'];
194:                 $divId = $post['div_id'];
195:                 $groupId = isset($post['group_id']) ? ((int) $post['group_id']) : 0;
196:                 $placeId = isset($post['place_id']) ? ((int) $post['place_id']) : 0;
197:                 $shippingModel = Mage::getModel('shipping/shipping')->getCarrierByCode($carrierCode, $storeId);
198:                 
199:                 //we are in admin section, so we need to set the store it manually
200:                 $shippingModel->setStoreId($storeId);
201:                 
202:                 if (!$shippingModel->isAjaxInsertAllowed($addressId)) {
203:                     throw new Exception('Invalid Shipping method');
204:                 }
205:                 if (!($shippingModel instanceof Eabi_Postoffice_Model_Carrier_Abstract)) {
206:                     throw new Exception('Invalid Shipping model');
207:                 }
208: 
209:                 if ($placeId > 0) {
210:                     $place = $shippingModel->getTerminal($placeId);
211:                     if ($place) {
212:                         $shippingModel->setOfficeToSession($addressId, $place);
213:                         $jsonResponse['html'] = true;
214:                         $terminalComment = $shippingModel->getTerminalComment($place);
215:                         $isError = $terminalComment->getIsError();
216:                         if ($isError) {
217:                             $jsonResponse['html'] = false;
218:                             $jsonResponse['comment'] = $terminalComment->getComment();
219:                         }
220:                         
221: //                        $jsonResponse['comment'] = '<a id="why-to-buy" href="#" onclick="return false;">*<span class="why-to-buy-tooltip">' .$shippingModel->getTerminalComment($place) . '</span></a>';
222:                         $this->getResponse()->setBody(json_encode($jsonResponse));
223:                         return;
224:                     } else {
225:                         $jsonResponse['html'] = false;
226:                         $this->getResponse()->setBody(json_encode($jsonResponse));
227:                         return;
228:                     }
229:                 }
230: 
231:                 $groups = $shippingModel->getGroups($addressId);
232:                 $html = '';
233: 
234:                 if ($groups) {
235:                      $groupSelectWidth = (int)$shippingModel->getConfigData('group_width');
236:                     $style = '';
237:                     if ($groupSelectWidth > 0) {
238:                         $style = ' style="width:'.$groupSelectWidth.'px"';
239:                     }
240:                     $html .= '<select onclick="return false;" '.$style.' name="' . $carrierCode . '_select_group" onchange="new Ajax.Request(\'' . $url . '\',{method:\'post\',parameters:{carrier_id:\'' . $carrierId . '\',carrier_code:\'' . $carrierCode . '\',div_id:\'' . $divId . '\',address_id:\'' . $addressId . '\',group_id: $(this).getValue()},onSuccess:function(a){$(\'' . $divId . '\').update(a.responseJSON.html)}});">';
241:                     $html .= '<option value="">';
242:                     $html .= htmlspecialchars(Mage::helper('eabi_postoffice')->__('-- select --'));
243:                     $html .= '</option>';
244: 
245:                     foreach ($groups as $group) {
246:                         $html .= '<option value="' . $group->getGroupId() . '"';
247:                         if ($groupId > 0 && $groupId == $group->getGroupId()) {
248:                             $html .= ' selected="selected"';
249:                         }
250:                         $html .= '>';
251:                         $html .= $shippingModel->getGroupTitle($group);
252:                         $html .= '</option>';
253:                     }
254:                     $html .= '</select>';
255:                 }
256: 
257:                 //get the group values
258:                 if ($groupId > 0 || $groups === false) {
259:                     $terminals = array();
260:                     if ($groups !== false) {
261:                         $terminals = $shippingModel->getTerminals($groupId, $addressId);
262:                     } else {
263:                         $terminals = $shippingModel->getTerminals(null, $addressId);
264:                     }
265:                     $officeSelectWidth = (int)$shippingModel->getConfigData('office_width');
266:                     $style = '';
267:                     if ($officeSelectWidth > 0) {
268:                         $style = ' style="width:'.$officeSelectWidth.'px"';
269:                     }
270:                     $html .= '<select onclick="return false;" '.$style.' name="' . $carrierCode . '_select_office"  onchange="var sel = $(this); new Ajax.Request(\'' . $url . '\',{method:\'post\',parameters:{carrier_id:\'' . $carrierId . '\',carrier_code:\'' . $carrierCode . '\',div_id:\'' . $divId . '\',address_id:\'' . $addressId . '\',place_id: sel.getValue()},onSuccess:function(a){  if (a.responseJSON.html === true) { if (typeof a.responseJSON.comment === \'string\') { sel.next().update(a.responseJSON.comment); sel.next().removeClassName(\'eabi_postoffice_comment_error\'); sel.next().show(); $$(\'.eabi_carrier\').each(function() { $(this).addClassName(\'over\'); });} else { sel.next().hide(); } $(\'' . $carrierId . '\').writeAttribute(\'value\', \'' . $carrierCode . '_' . $carrierCode . '_\' + sel.getValue()); $(\'' . $carrierId . '\').click(); }  else if (a.responseJSON.html === false) { if (typeof a.responseJSON.comment === \'string\') { sel.next().update(a.responseJSON.comment); sel.next().addClassName(\'eabi_postoffice_comment_error\'); sel.next().show(); } else { sel.next().hide(); } } else { sel.next().hide(); }}});">';
271:                     $html .= '<option value="">';
272:                     $html .= htmlspecialchars(Mage::helper('eabi_postoffice')->__('-- select --'));
273:                     $html .= '</option>';
274: 
275:                     $optionsHtml = '';
276:                     $previousGroup = false;
277:                     $optGroupHtml = '';
278:                     $groupCount = 0;
279: 
280:                     foreach ($terminals as $terminal) {
281:                         if ($shippingModel->getGroupTitle($terminal) != $previousGroup && !$shippingModel->getConfigData('disable_group_titles')) {
282:                             if ($previousGroup != false) {
283:                                 $optionsHtml .= '</optgroup>';
284:                                 $optionsHtml .= '<optgroup label="'.$shippingModel->getGroupTitle($terminal).'">';
285:                             } else {
286:                                 $optGroupHtml .= '<optgroup label="'.$shippingModel->getGroupTitle($terminal).'">';
287:                             }
288:                             $groupCount++;
289:                         }
290:                         $optionsHtml .= '<option value="' . $terminal->getRemotePlaceId() . '"';
291:                         if (false) {
292:                             $optionsHtml .= ' selected="selected"';
293:                         }
294:                         $optionsHtml .= '>';
295:                         $optionsHtml .= $shippingModel->getTerminalTitle($terminal);
296:                         $optionsHtml .= '</option>';
297:                         
298:                         $previousGroup = $shippingModel->getGroupTitle($terminal);
299:                     }
300:                     if ($groupCount > 1) {
301:                         $html .= $optGroupHtml . $optionsHtml . '</optgroup>';
302:                     } else {
303:                         $html .= $optionsHtml;
304:                     }
305: 
306:                     $html .= '</select>';
307:                     
308:                     
309:                 }
310:                 $html .= '<span class="eabi_postoffice_comment" style="display:none;"></span>';
311: 
312: 
313:                 $jsonResponse['html'] = $html;
314:                 $this->getResponse()->setBody(json_encode($jsonResponse));
315:             } else {
316:                 throw new Exception('Invalid request method');
317:             }
318:         } catch (Exception $e) {
319:             $this->getResponse()->setHeader('HTTP/1.1', '500 Internal error');
320:             $this->getResponse()->setHeader('Status', '500 Internal error');
321:             throw $e;
322:         }
323:         return;
324:     }
325:     
326:     
327:     /**
328:      * <p>If older instance of Eabi_Postoffice exists, then this function attempts to remove it</p>
329:      * @return null
330:      */
331:     public function removeAction() {
332:         $result = array('status' => 'failed');
333:         if ($this->getRequest()->isPost() && $this->getRequest()->getPost('remove') == 'true') {
334:             $dirName = Mage::getBaseDir('code').'/local/Eabi/Postoffice';
335:             if (is_dir($dirName) && file_exists($dirName.'/etc/config.xml')) {
336:                 $directory = new Varien_Io_File();
337:                 $deleteResult = $directory->rmdir($dirName, true);
338:                 if ($deleteResult) {
339:                     $result['status'] = 'success';
340:                 }
341:             }
342:             
343:         }
344:         $this->getResponse()->setRawHeader('Content-type: application/json');
345:         $this->getResponse()->setBody(json_encode($result));
346:         return;
347:     }
348:     
349:     /**
350:      * 
351:      * @return Eabi_Livehandler_Helper_Data
352:      */
353:     protected function _getEabi() {
354:         return Mage::helper('eabi');
355:     }
356:     
357:     /**
358:      * 
359:      * @return Eabi_Postoffice_Helper_Data
360:      */
361:     protected function _getOfficeHelper() {
362:         return Mage::helper('eabi_postoffice');
363:     }
364:     
365:     
366: }
367: 
368: 
DPD Eesti - Pakivedu.ee Shipping module for Magento API documentation generated by ApiGen 2.8.0