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:  * <p>Displays list of available parcel terminals for current carrier and address if carrier supports parcel terminals feature</p>
 35:  *
 36:  * @author matishalmann
 37:  */
 38: class Eabi_Postoffice_IndexController extends Mage_Core_Controller_Front_Action {
 39:     
 40: 
 41:     /**
 42:      *  <p>Returns the contents for the selected carriers.</p>
 43:      * <p>Mainly it returns two select menus, where first select menu contains all the groups and
 44:      * second select menu contains actual offices, which belong to the selected group</p>
 45:      * 
 46:      * 
 47:      * 
 48:      * 
 49:      * @return html
 50:      * @throws Exception 
 51:      */
 52:     public function officeAction() {
 53:         try {
 54:             if ($this->getRequest()->isPost()) {
 55:                 $this->getResponse()->setHeader('Content-type', 'application/json');
 56:                 $jsonResponse = array(
 57:                     'html' => false,
 58:                     'comment' => false,
 59:                 );
 60:                 
 61:                 $url = Mage::getUrl('eabi_postoffice/index/office', array('_secure' => true));
 62: 
 63:                 $post = $this->getRequest()->getPost();
 64:                 $addressId = $post['address_id'];
 65:                 $carrierCode = $post['carrier_code'];
 66:                 $carrierId = $post['carrier_id'];
 67:                 $divId = $post['div_id'];
 68:                 $groupId = isset($post['group_id']) ? ((int) $post['group_id']) : 0;
 69:                 $placeId = isset($post['place_id']) ? ((int) $post['place_id']) : 0;
 70:                 $shippingModel = Mage::getModel('shipping/shipping')->getCarrierByCode($carrierCode);
 71:                 if (!$shippingModel->isAjaxInsertAllowed($addressId)) {
 72:                     throw new Exception('Invalid Shipping method');
 73:                 }
 74:                 if (!($shippingModel instanceof Eabi_Postoffice_Model_Carrier_Abstract)) {
 75:                     throw new Exception('Invalid Shipping model');
 76:                 }
 77: 
 78:                 if ($placeId > 0) {
 79:                     $place = $shippingModel->getTerminal($placeId);
 80:                     if ($place) {
 81:                         $shippingModel->setOfficeToSession($addressId, $place);
 82:                         $jsonResponse['html'] = true;
 83:                         $terminalComment = $shippingModel->getTerminalComment($place);
 84:                         $isError = $terminalComment->getIsError();
 85:                         if ($isError) {
 86:                             $jsonResponse['html'] = false;
 87:                         }
 88:                         
 89:                         $jsonResponse['comment'] = $terminalComment->getComment();
 90: //                        $jsonResponse['comment'] = '<a id="why-to-buy" href="#" onclick="return false;">*<span class="why-to-buy-tooltip">' .$shippingModel->getTerminalComment($place) . '</span></a>';
 91:                         $this->getResponse()->setBody(json_encode($jsonResponse));
 92:                         return;
 93:                     } else {
 94:                         $jsonResponse['html'] = false;
 95:                         $this->getResponse()->setBody(json_encode($jsonResponse));
 96:                         return;
 97:                     }
 98:                 }
 99: 
100:                 $groups = $shippingModel->getGroups($addressId);
101:                 $html = '';
102: 
103:                 if ($groups) {
104:                     $groupSelectWidth = (int)$shippingModel->getConfigData('group_width');
105:                     $style = '';
106:                     if ($groupSelectWidth > 0) {
107:                         $style = ' style="width:'.$groupSelectWidth.'px"';
108:                     }
109:                     $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)}});">';
110:                     $html .= '<option value="">';
111:                     $html .= htmlspecialchars(Mage::helper('eabi_postoffice')->__('-- select --'));
112:                     $html .= '</option>';
113:                     
114: 
115:                     foreach ($groups as $group) {
116:                         $html .= '<option value="' . $group->getGroupId() . '"';
117:                         if ($groupId > 0 && $groupId == $group->getGroupId()) {
118:                             $html .= ' selected="selected"';
119:                         }
120:                         $html .= '>';
121:                         $html .= $shippingModel->getGroupTitle($group);
122:                         $html .= '</option>';
123:                     }
124:                     $html .= '</select>';
125:                 }
126: 
127:                 //get the group values
128:                 if ($groupId > 0 || $groups === false) {
129:                     $terminals = array();
130:                     if ($groups !== false) {
131:                         $terminals = $shippingModel->getTerminals($groupId, $addressId);
132:                     } else {
133:                         $terminals = $shippingModel->getTerminals(null, $addressId);
134:                     }
135:                     $officeSelectWidth = (int)$shippingModel->getConfigData('office_width');
136:                     $style = '';
137:                     if ($officeSelectWidth > 0) {
138:                         $style = ' style="width:'.$officeSelectWidth.'px"';
139:                     }
140: 
141:                     $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(); $(\'' . $divId. '\').addClassName(\'over\'); setTimeout(function() {$(\'' . $divId. '\').removeClassName(\'over\');}, 1500);} 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(); $(\'' . $divId. '\').addClassName(\'over\'); setTimeout(function() {$(\'' . $divId. '\').removeClassName(\'over\');}, 1500); } else { sel.next().hide(); } } else { sel.next().hide(); }}});">';
142:                     $html .= '<option value="">';
143:                     $html .= htmlspecialchars(Mage::helper('eabi_postoffice')->__('-- select --'));
144:                     $html .= '</option>';
145:                     
146:                     $optionsHtml = '';
147:                     $previousGroup = false;
148:                     $optGroupHtml = '';
149:                     $groupCount = 0;
150: 
151:                     foreach ($terminals as $terminal) {
152:                         if ($shippingModel->getGroupTitle($terminal) != $previousGroup && !$shippingModel->getConfigData('disable_group_titles')) {
153:                             if ($previousGroup != false) {
154:                                 $optionsHtml .= '</optgroup>';
155:                                 $optionsHtml .= '<optgroup label="'.$shippingModel->getGroupTitle($terminal).'">';
156:                             } else {
157:                                 $optGroupHtml .= '<optgroup label="'.$shippingModel->getGroupTitle($terminal).'">';
158:                             }
159:                             $groupCount++;
160:                         }
161:                         $optionsHtml .= '<option value="' . $terminal->getRemotePlaceId() . '"';
162:                         if (false) {
163:                             $optionsHtml .= ' selected="selected"';
164:                         }
165:                         $optionsHtml .= '>';
166:                         $optionsHtml .= $shippingModel->getTerminalTitle($terminal);
167:                         $optionsHtml .= '</option>';
168:                         
169:                         $previousGroup = $shippingModel->getGroupTitle($terminal);
170:                     }
171:                     if ($groupCount > 1) {
172:                         $html .= $optGroupHtml . $optionsHtml . '</optgroup>';
173:                     } else {
174:                         $html .= $optionsHtml;
175:                     }
176: 
177:                     $html .= '</select>';
178:                 }
179:                 $html .= '<span class="eabi_postoffice_comment" style="display:none;"></span>';
180: 
181: 
182:                 $jsonResponse['html'] = $html;
183:                 $this->getResponse()->setBody(json_encode($jsonResponse));
184:             } else {
185:                 throw new Exception('Invalid request method');
186:             }
187:         } catch (Exception $e) {
188:             $this->getResponse()->setHeader('HTTP/1.1', '500 Internal error');
189:             $this->getResponse()->setHeader('Status', '500 Internal error');
190:             throw $e;
191:         }
192:         return;
193:     }
194: 
195: }
196: 
197: 
DPD Eesti - Pakivedu.ee Shipping module for Magento API documentation generated by ApiGen 2.8.0