Overview

Packages

  • Eabi
    • Dpd
  • None
  • PHP

Classes

  • dpdcodpayment
  • eabi_dpd_courier
  • Eabi_dpd_courierCourierModuleFrontController
  • eabi_dpd_parcelstore
  • eabi_dpd_parcelstore_data_send_executor
  • eabi_dpd_parcelstore_dpd_api
  • eabi_dpd_parcelstore_dpd_helper
  • eabi_dpd_parcelstore_html_helper
  • eabi_dpd_parcelstore_validator_helper
  • Eabi_dpd_parcelstoreCourierModuleFrontController
  • Eabi_Postoffice
  • eabi_postoffice_dialcode_helper
  • Eabi_PostofficePostofficeModuleFrontController

Functions

  • upgrade_module_0_3
  • upgrade_module_0_6
  • upgrade_module_0_8
  • Overview
  • Package
  • 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: if (!defined('_PS_VERSION_')) {
 34:     exit;
 35: }
 36: /**
 37:  * Description of postoffice
 38:  *
 39:  * @author Matis
 40:  */
 41: class Eabi_PostofficePostofficeModuleFrontController extends ModuleFrontController {
 42:     public $ssl = true;
 43:     
 44:     
 45:     /**
 46:      *  <p>Returns the contents for the selected carriers.</p>
 47:      * <p>Mainly it returns two select menus, where first select menu contains all the groups and
 48:      * second select menu contains actual offices, which belong to the selected group</p>
 49:      * @throws Exception when request is not POST request
 50:      */
 51:     public function initContent() {
 52:         try {
 53:             if (isset($_POST) && count($_POST)) {
 54: 
 55:                 $post = $_POST;
 56:                 $url = str_replace('/'.Language::getIsoById(Context::getContext()->language->id).'/', '/', $this->context->link->getModuleLink('eabi_postoffice', 'postoffice', array(), true));
 57:                 $addressId = $post['address_id'];
 58:                 $carrierCode = $post['carrier_code'];
 59:                 $carrierId = $post['carrier_id'];
 60:                 $divId = $post['div_id'];
 61:                 $groupId = isset($post['group_id']) ? ((int) $post['group_id']) : 0;
 62:                 $placeId = isset($post['place_id']) ? ((int) $post['place_id']) : 0;
 63:                 $shippingModel = Module::getInstanceByName($carrierCode);
 64:                 if (!Validate::isLoadedObject($shippingModel)) {
 65:                     throw new Exception(sprintf('Shipping model not found for code %s', $carrierCode));
 66:                 }
 67:             
 68:                 
 69:                 if (!$shippingModel->active) {
 70:                     throw new Exception('Invalid Shipping method');
 71:                 }
 72:                 /* @var $handlerModel Eabi_Postoffice */
 73:                 $handlerModel = Module::getInstanceByName('eabi_postoffice');
 74:                 
 75:                 if (!Validate::isLoadedObject($handlerModel)) {
 76:                     throw new Exception(sprintf('Handler model not found for code %s', 'eabi_postoffice'));
 77:                 }
 78:                 
 79:                 
 80:                 if (!$handlerModel->idFromCode($carrierCode)) {
 81:                     throw new Exception('Invalid Shipping method');
 82:                 }
 83:                 $handlerModel = clone $handlerModel;
 84:                 $handlerModel->setShippingModel($shippingModel);
 85:                 
 86:                 if ($placeId > 0) {
 87:                     $places = $handlerModel->getPostOffices($carrierCode, null, $placeId, null);
 88:                     $place = isset($places[0])?$places[0]:false;
 89:                     if ($place) {
 90:                         $handlerModel->setOfficeToSession($carrierCode, $addressId, $place['remote_place_id'], $groupId);
 91:                         echo 'true';
 92:                         exit;
 93:                     } else {
 94:                         echo 'false';
 95:                         exit;
 96:                     }
 97:                 }
 98:                 $selectedOffice = $handlerModel->getOfficeFromSession($addressId);
 99: 
100: 
101:                 $groups = $handlerModel->getPostOfficeGroups($carrierCode, $addressId);
102:                 $html = '';
103:                 if ($shippingModel->getConfigData('DIS_FIRST') == 'yes') {
104:                     $groups = false;
105:                 }
106:                 if (isset($shippingModel->text) && $shippingModel->text) {
107:                     $html .= '<p class="eabi_shipping_method_title">' . htmlspecialchars($shippingModel->text) . '</p>';
108:                 } else {
109:                     $title = $shippingModel->getConfigData('TITLE');
110:                     $finalTitle = $title;
111:                     if ($this->_isSerialized($title)) {
112:                         $title = @unserialize($title);
113:                         if (is_array($title)) {
114:                             $finalTitle = isset($title[$this->context->language->id]) ? $title[$this->context->language->id] : $title[0];
115:                         }
116:                     }
117: 
118:                     $html .= '<p class="eabi_shipping_method_title">' . htmlspecialchars($finalTitle) . '</p>';
119:                 }
120: 
121:                 if ($groups) {
122:                     $groupSelectWidth = (int)$shippingModel->getConfigData('GR_WIDTH');
123:                     $style = '';
124:                     if ($groupSelectWidth > 0) {
125:                         $style = ' style="width:'.$groupSelectWidth.'px"';
126:                     }
127:                     $html .= '<select onclick="return false;" '.$style.' name="' . $carrierCode . '_select_group" onchange="$.ajax(\'' . $url . '\',{\'type\':\'POST\',data:{carrier_id:\'' . $carrierId . '\',carrier_code:\'' . $carrierCode . '\',div_id:\'' . $divId . '\',address_id:\'' . $addressId . '\',group_id: $(this).val()},success:function(a){$(\'#' . $divId . '\').html(a)}});">';
128:                     $html .= '<option value="">';
129:                     $html .= htmlspecialchars($handlerModel->l('-- select --'));
130:                     $html .= '</option>';
131: 
132:                     foreach ($groups as $group) {
133:                         $html .= '<option value="' . $group['group_id'] . '"';
134:                         if ($groupId > 0 && $groupId == $group['group_id']) {
135:                             $html .= ' selected="selected"';
136:                         }
137:                         if ($groupId <= 0 && $selectedOffice['code'] == $carrierCode
138:                                 && $selectedOffice['group_id'] && $group['group_id'] == $selectedOffice['group_id']) {
139:                             $html .= ' selected="selected"';
140:                             $groupId = $selectedOffice['group_id'];
141:                         }
142:                         $html .= '>';
143:                         $html .= $shippingModel->getGroupTitle($group);
144:                         $html .= '</option>';
145:                     }
146:                     $html .= '</select>';
147:                 }
148: 
149:                 //get the group values
150:                 if ($groupId > 0 || $groups === false) {
151:                     $terminals = array();
152:                     if ($groups !== false) {
153:                         $terminals = $handlerModel->getPostOffices($carrierCode, $groupId, null, $addressId);
154:                     } else {
155:                         $terminals = $handlerModel->getPostOffices($carrierCode, null, null, $addressId);
156:                     }
157:                     $officeSelectWidth = (int)$shippingModel->getConfigData('OF_WIDTH');
158:                     $style = '';
159:                     if ($officeSelectWidth > 0) {
160:                         $style = ' style="width:'.$officeSelectWidth.'px"';
161:                     }
162:                     $carrierIde = 'id_carrier_'.$carrierCode;
163:                     $prestaShopCarrierCode = $handlerModel->getCarrierFromCode($carrierCode);
164:                     $terminalsCount = count($terminals);
165: 
166: 
167: 
168:                     if ($terminalsCount === 1 && $groups === false) {
169:                         $terminal = array_shift($terminals);
170:                         $html .= '<span>';
171: //                        $html .= $shippingModel->getTerminalTitle($terminal);
172:                         $html .= '</span>';
173: 
174:                             $html .= <<<HTML
175:    <script type="text/javascript">
176:        // <![CDATA[
177:        jQuery('input[id=\'{$carrierIde}\']').val('{$prestaShopCarrierCode->id},'); 
178:        jQuery('input[id={$carrierIde}]').removeAttr('disabled').removeAttr('title');
179:        // ]]>
180:    </script>
181: HTML;
182:                     } else {
183:                         $html .= '<select onclick="return false;" ' . $style . ' name="' . $carrierCode . '_select_office"  onchange="var sel = $(this); $.ajax(\'' . $url . '\',{\'type\':\'POST\',data:{carrier_id:\'' . $carrierId . '\',carrier_code:\'' . $carrierCode . '\',div_id:\'' . $divId . '\',address_id:\'' . $addressId . '\',place_id: sel.val()},success:function(a){   if (a == \'true\') {   $(\'input[id=\\\'' . $carrierIde . '\\\']\').val(\'' . $prestaShopCarrierCode->id . ',\'); $(\'input[id=' . $carrierIde . ']\').attr(\'checked\',\'checked\').removeAttr(\'disabled\').change(); }}});">';
184:                         $html .= '<option value="">';
185:                         $html .= htmlspecialchars($handlerModel->l('-- select --'));
186:                         $html .= '</option>';
187: 
188:                         $optionsHtml = '';
189:                         $previousGroup = false;
190:                         $optGroupHtml = '';
191:                         $groupCount = 0;
192: 
193:                         foreach ($terminals as $terminal) {
194:                             if ($shippingModel->getGroupTitle($terminal) != $previousGroup && $shippingModel->getConfigData('DIS_GR_TITLE') != 'yes') {
195:                                 if ($previousGroup != false) {
196:                                     $optionsHtml .= '</optgroup>';
197:                                     $optionsHtml .= '<optgroup label="' . $shippingModel->getGroupTitle($terminal) . '">';
198:                                 } else {
199:                                     $optGroupHtml .= '<optgroup label="' . $shippingModel->getGroupTitle($terminal) . '">';
200:                                 }
201:                                 $groupCount++;
202:                             }
203:                             $optionsHtml .= '<option value="' . $terminal['remote_place_id'] . '"';
204:                             if ($selectedOffice['code'] == $carrierCode && $selectedOffice['place_id'] == $terminal['remote_place_id']) {
205:                                 $optionsHtml .= ' selected="selected"';
206:                             }
207:                             $optionsHtml .= '>';
208:                             $optionsHtml .= $shippingModel->getTerminalTitle($terminal);
209:                             $optionsHtml .= '</option>';
210: 
211:                             $previousGroup = $shippingModel->getGroupTitle($terminal);
212:                         }
213:                         if ($groupCount > 1) {
214:                             $html .= $optGroupHtml . $optionsHtml . '</optgroup>';
215:                         } else {
216:                             $html .= $optionsHtml;
217:                         }
218: 
219:                         $html .= '</select>';
220:                     }
221:                 }
222: 
223: 
224:                 echo $html;
225:             } else {
226:                 throw new Exception('Invalid request method');
227:             }
228:         } catch (Exception $e) {
229:             header('HTTP/1.1 500 Internal error');
230:             header('Status: 500 Internal error');
231: //            echo $e->getMessage();
232:             throw $e;
233:         }
234:         exit;
235:     }
236:     
237:     protected function _isSerialized($input) {
238:         return preg_match('/^([adObis]):/', $input);
239:     }
240:     
241:     
242:     
243: }
244: 
245: 
API documentation generated by ApiGen 2.8.0