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:  *
  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: if (!defined('_PS_VERSION_')) {
 34:     exit;
 35: }
 36: 
 37: if (!class_exists('eabi_dpd_parcelstore', false)) {
 38:     Module::getInstanceByName('eabi_dpd_parcelstore');
 39: }
 40: 
 41: /**
 42:  * <p>Represents DPD courier shipping method.</p>
 43:  * <p>Extra order data is stored under specialized order comment</p>
 44:  * <p>Can perform following business actions:</p>
 45:  * <ul>
 46:      <li>Calculate shipping price based on country and weight</li>
 47:      <li>Send information about shipment data to DPD server.</li>
 48:      <li>Call courier to pick up the shipment that was ordered using this carrier.</li>
 49:  </ul>
 50:  * @author Matis
 51:  */
 52: class eabi_dpd_courier extends eabi_dpd_parcelstore {
 53:     const CONST_PREFIX = 'E_DPDEEC_';
 54:     
 55:     const NAME = 'eabi_dpd_courier';
 56:     
 57:     
 58:     /**
 59:      * <p>Holds generated form fields data</p>
 60:      * @var array
 61:      * @see eabi_dpd_parcelstore_html_helper
 62:      */
 63:     private $form_fields = array();
 64:     
 65: 
 66:     /**
 67:      * <p>Since it is inherited from DPD parcelstore, then parent shippig method is stored here.</p>
 68:      * @var string
 69:      */
 70:     protected $_parent_code;
 71:     
 72: 
 73:     /**
 74:      *
 75:      * @var eabi_dpd_parcelstore_data_send_executor
 76:      */
 77:     public $dataSendExecutor;
 78:     
 79:     /**
 80:      * <p>Evaluates to true, if current shipment method has already been rendered</p>
 81:      * @var bool
 82:      */
 83:     protected $_carrierDisplayed = false;
 84:     
 85: 
 86:     /**
 87:      * <p>Initiates module. Is used because PrestaShop requires special Module initiation which is done in parent class</p>
 88:      */
 89:     protected function _construct() {
 90:         $this->_const_prefix = eabi_dpd_courier::CONST_PREFIX;
 91:         $this->name = 'eabi_dpd_courier';
 92:         $this->tab = 'shipping_logistics';
 93:         $this->_parent_code = eabi_dpd_parcelstore::NAME;
 94:         $this->version = '0.4';
 95:         $this->dependencies[] = 'eabi_dpd_parcelstore';
 96:         $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.7');
 97:         $this->displayName = $this->l('DPD kulleriga koju või tööle');
 98:         $this->description = $this->l('DPD offers high-quality shipping service from Estonia to whole Europe.');
 99:         $this->confirmUninstall = $this->l('Are you sure you want to delete your details?');
100:         if (file_exists(_PS_MODULE_DIR_ . eabi_dpd_parcelstore::NAME. '/datasend-executor.php')) {
101:             if (!class_exists(eabi_dpd_parcelstore::NAME . '_data_send_executor', false)) {
102:                 require_once(_PS_MODULE_DIR_ . eabi_dpd_parcelstore::NAME . '/datasend-executor.php');
103:             }
104:             $executorClass = eabi_dpd_parcelstore::NAME . '_data_send_executor';
105:             $this->dataSendExecutor = new $executorClass($this);
106:             $this->dataSendExecutor->setConfigPrefix(eabi_dpd_parcelstore::CONST_PREFIX);
107:         }
108:         if (!$this->_getHelperModule() || !$this->getConfigData('TITLE') OR !$this->getConfigData('HANDLING_FEE')) {
109:             $this->warning = $this->l('Details must be configured in order to use this module correctly');
110:         }
111:         
112:         
113:         $this->form_fields = array();
114:         
115:         
116:     }
117:     
118:     
119:     /**
120:      * <p>Not used</p>
121:      */
122:     private function init() {
123:     }
124:     
125:     /**
126:      * <p>Prepares op=order request to be sent via DPD API.</p>
127:      * @param OrderCore $order Order that is using this carrier
128:      * @param AddressCore $address address, that is from that order (one order can support multiple addresses)
129:      * @param array $selectedOfficeId selected entry from table <code>eabi_postoffice</code>
130:      * @param bool $forceCod true if request should be sent as cod request
131:      * @return array request that is passed directly to DPD
132:      */
133:     public function getRequestForAutoSendData($order, $address, $selectedOfficeId, $forceCod = false) {
134:         $telephone = $address->phone_mobile;
135:         if (!$telephone) {
136:             $telephone = $address->phone;
137:         }
138:         
139:         $requestData = array(
140:             'Sh_name' => $address->firstname.' '.$address->lastname,
141:             'Sh_company' => $address->company,
142:             'Sh_street' => implode(' ', array($address->address1, $address->address2)),
143:             'Sh_postal' => $address->postcode,
144:             'Sh_country' => strtolower(Country::getIsoById($address->id_country)),
145:             'Sh_city' => $address->city,
146:             'Sh_contact' => $address->firstname.' '.$address->lastname,
147:             'Sh_phone' => $telephone,
148:             'Po_remark' => $this->_getRemark($order),
149:             'Sh_remark' => '',
150:             'Sh_pudo' => 'false',
151:             'Sh_parcel_qty' => $this->_getNumberOfPackagesForOrder($order),
152:             'Sh_cust_reference' => $order->id,
153:         );
154:         if ($address->id_state) {
155:             $requestData['Sh_city'] = $address->city . ', ' . State::getNameById($address->id_state);
156:         }
157:         //add cash on delivery
158:         if (!$order->hasBeenPaid() && $forceCod) {
159:             $requestData['Sh_cod_amount'] = number_format(round($order->total_paid_tax_incl, 2), 2, '.', '');
160:             $requestData['Sh_cod_currency'] = $this->_getCurrencyIso($order->id_currency);
161:         }
162:         
163: //        echo '<pre>'.htmlspecialchars(print_r($requestData, true), ENT_COMPAT | ENT_HTML401 | ENT_IGNORE).'</pre>';
164: //        exit;
165:         
166:         return $requestData;
167:         
168:     }
169:     
170: 
171:     
172:     /**
173:      * <p>Performs following actions:</p>
174:      * <ul>
175:          <li>Registers hook <code>extraCarrier</code></li>
176:          <li>Registers carrier with name <code>eabi_dpdee_courier</code></li>
177:          <li>Registers hook with name <code>paymentConfirm</code> - for auto sending data after payment</li>
178:          <li>Registers hook with name <code>actionAdminControllerSetMedia</code> - for adding css,js scripts</li>
179:          <li>Registers hook with name <code>displayBackOfficeFooter</code> - for adding call to courier button</li>
180:          <li>Registers hook with name <code>displayHeader</code> - for adding css,js scripts</li>
181:          <li>Registers hook with name <code>displayFooter</code> - for removing shipping methods at onepage checkouts, if <code>HOOK_EXTRACARRIER</code> is not called</li>
182:      </ul>
183:      * @return boolean
184:      */
185:     protected function _install() {
186:         if (!$this->registerHook('extraCarrier')
187:                 || !$this->_getHelperModule()->addCarrierModule($this->name, get_class($this), self::TRACKING_URL) or !$this->registerHook('paymentConfirm')
188:                 || !$this->registerHook('actionAdminControllerSetMedia')
189:                 || !$this->registerHook('displayBackOfficeFooter')
190:                 || !$this->registerHook('displayHeader')
191:                 || !$this->registerHook('displayFooter')
192:                 || !$this->upgrade_module_0_3()) {
193:             return false;
194:         }
195:         return true;
196:     }
197:     
198:     
199:     /**
200:      * <p>Performs following actions:</p>
201:      * <ul>
202:          <li>Unregisters hook <code>extraCarrier</code></li>
203:          <li>Removes carrier with name <code>eabi_dpdee_courier</code></li>
204:          <li>Unregisters hook with name <code>paymentConfirm</code></li>
205:          <li>Unregisters hook with name <code>actionAdminControllerSetMedia</code></li>
206:          <li>Unregisters hook with name <code>displayBackOfficeFooter</code></li>
207:          <li>Unregisters hook with name <code>displayHeader</code></li>
208:          <li>Unregisters hook with name <code>displayFooter</code></li>
209:         <li>If <code>dataSendExecutor</code> is available, then <code>uninstall()</code> method will be called on same object</li>
210:      </ul>
211:      * @return boolean
212:      */
213:     protected function _uninstall() {
214:         if (!$this->unregisterHook('extraCarrier') || !$this->unregisterHook('paymentConfirm')
215:                 || !$this->unregisterHook('displayBackOfficeFooter')
216:                 || !$this->unregisterHook('displayHeader')
217:                 || !$this->unregisterHook('displayFooter')) {
218:             return false;
219:         }
220:         //TODO: remove in future releases, now it is left because there was hook rename from:
221:         //displayBackOfficeHeader => actionAdminControllerSetMedia
222:         $this->unregisterHook('displayBackOfficeHeader');
223:         $this->unregisterHook('actionAdminControllerSetMedia');
224:         if (!$this->_getHelperModule()->removeCarrierModule($this->name)) {
225:             return false;
226:         }
227: 
228:         return true;
229:         
230:     }
231:     
232:     
233:     
234:     
235:     /**
236:      * <p>Automatic data sending is executed at the moment, when order is marked as Paid.</p>
237:      * @param array $params
238:      * @return string
239:      */
240:     public function hookPaymentConfirm(&$params) {
241:         if ($this->dataSendExecutor != null) {
242:             $this->dataSendExecutor->hookpaymentConfirm($params);
243:         }
244:         return '';
245:     }
246: 
247:     /**
248:      * <p>For adding CSS,JS scripts in backoffice</p>
249:      */
250:     public function hookActionAdminControllerSetMedia() {
251:         $path = __PS_BASE_URI__.'modules/'.eabi_dpd_parcelstore::NAME.'/';
252:         $this->context->controller->addCSS($path . 'css/'.  eabi_dpd_parcelstore::NAME.'.css', 'all');
253:         $this->context->controller->addJqueryPlugin('loadTemplate', $path .'js/plugins/');
254:         $this->context->controller->addJS($path . 'js/'.eabi_dpd_parcelstore::NAME.'.js');
255:         
256:     }
257:     
258:     /**
259:      * <p>For adding CSS,JS scripts in frontend</p>
260:      */
261:     public function hookDisplayHeader() {
262:         $path = __PS_BASE_URI__.'modules/'.eabi_dpd_parcelstore::NAME.'/';
263:         $this->context->controller->addCSS($path . 'css/'.eabi_dpd_parcelstore::NAME.'-public.css', 'all');
264:         $this->context->controller->addJS($path . 'js/'.eabi_dpd_parcelstore::NAME.'-public.js');
265:     }
266:     
267:     /**
268:      * <p>For adding HOOK_EXTRACARRIER callout, when original callout did not occur when it had to.</p>
269:      * <p>PrestaShop does not call extracarrier when for example address is not entered yet</p>
270:      * @return string
271:      */
272:     public function hookDisplayFooter() {
273:         $className = 'OrderOpcController';
274:         $php_self = 'order-opc';
275:         if ($this->context->controller instanceof $className && $this->context->controller->php_self == $php_self) {
276:             if (!$this->_carrierDisplayed) {
277:                 return $this->hookExtraCarrier(array('cart' => $this->context->cart));
278:             }
279: //            return '<pre>'.htmlspecialchars(print_r('junnike', true)).'</pre>';
280:         }
281:     }
282: 
283:     
284:     
285:     
286:     /**
287:      * <p>Saves configuration entered from the admin form and returns HTML generated during process.</p>
288:      * @return string any generated HTML from the postprocess, for example success message
289:      */
290:     private function _postProcess() {
291:         $html = '';
292:         $data = $_POST;
293:         if (isset($data['btnSubmit'])) {
294:             foreach ($this->_initFormFields() as $formFieldName => $formFieldDataSet) {
295:                 //multiselect must be normalized to CSV string
296:                 if ($formFieldDataSet['type'] == 'multiselect') {
297:                     if (!isset($data[strtoupper($formFieldName)])) {
298:                         $data[strtoupper($formFieldName)] = '';
299:                     }
300:                     if (is_array($data[strtoupper($formFieldName)])) {
301:                         $data[strtoupper($formFieldName)] = implode(',', $data[strtoupper($formFieldName)]);
302:                     }
303:                 }
304:                 
305:                 //country_select_html is always submitted as array
306:                 if (is_array($data[strtoupper($formFieldName)])) {
307:                     $data[strtoupper($formFieldName)] = serialize($data[strtoupper($formFieldName)]);
308:                 }
309:                 Configuration::updateValue(self::CONST_PREFIX . strtoupper($formFieldName), $data[strtoupper($formFieldName)]);
310:             }
311:             $this->_getHelperModule()->setTaxGroup($this->name, $this->getConfigData('TAX'));
312:             
313:             
314:             $title = $this->getConfigData('TITLE');
315:             $finalTitle = $title;
316:             if ($this->_isSerialized($title)) {
317:                 $title = @unserialize($title);
318:                 if (is_array($title)) {
319:                     $finalTitle = isset($title[$this->context->language->id])?$title[$this->context->language->id]:$title[0];
320:                 }
321:             }
322:             $this->_getHelperModule()->setDisplayName($this->name, $finalTitle);
323:             
324:             $this->_getHelperModule()->refresh($this->name, true);
325:             
326:             
327:             $html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('ok') . '" /> ' . $this->l('Settings updated') . '</div>';
328:         }
329:         return $html;
330:     }
331: 
332:     /**
333:      * <p>Displayes admin configuration form header</p>
334:      * @return string html
335:      */
336:     private function _displayFormHeader() {
337:         $html = '<img src="../modules/'.$this->name.'/'.$this->name.'.png" style="float:left; margin-right:15px;"><b>' . $this->l('DPD offers high-quality shipping service from Estonia to whole Europe.') . '</b><br /><br />
338:         ' . $this->l('DPD courier service can be used in Estonia, Baltics and Europe.') . '<br />';
339:         return $html;
340:     }
341:     
342: 
343: 
344: 
345: 
346:     /**
347:      * <p>This hook is called right after PrestaShop own carriers are rendered.</p>
348:      * <p>Returns HTML, which:</p>
349:      * <ul>
350:          <li>Replaces PrestaShop carrier element with ajax refreshing select menu element</li>
351:          <li>Hides PrestaShop carrier, when this carrier should not be available</li>
352:      </ul>
353:      * <p>Current PrestaShops <code>extraCarrier</code> hook uses following parameters:</p>
354:      * <ul>
355:          <li><code>cart</code> - Cart instance for current customer or order</li>
356:          <li><code>address</code> - Address instance for current cart</li>
357:      </ul>
358:      * <p>Checks following and hides if:</p>
359:      * <ul>
360:          <li>Shipping is not allowed for the specified country</li>
361:          <li>Products in the cart contain specific HTML comment string</li>
362:          <li>Any of the products is overweight</li>
363:      </ul>
364:      * @param array $params
365:      * @return string
366:      */
367:     public function hookExtraCarrier($params) {
368:         //if this shipping method is available or not
369:         $shouldHide = false;
370:         $this->_carrierDisplayed = true;
371: 
372:         /* @var $cart CartCore */
373:         $cart = $params['cart'];
374:         $summaryDetails = $cart->getSummaryDetails();
375: 
376:         //check if this shipping method is in allowed country list
377:         if ($this->getConfigData('SALLOWSPECIFIC') == '1') {
378:             $allowedCountries = explode(',', $this->getConfigData('SPECIFICCOUNTRY'));
379:             if (!in_array(Country::getIsoById($summaryDetails['delivery']->id_country), $allowedCountries)) {
380:                 $shouldHide = true;
381:             }
382:         }
383: 
384:         //check if address exists and if not, then create dummy address
385:         if (!$summaryDetails['delivery']->country) {
386:             $shouldHide = true;
387:             if (!isset($params['address']) || !$params['address']) {
388:                 $params['address'] = (object) array(
389:                             'id' => '0',
390:                 );
391:             }
392:         }
393:         
394:         //check if cart contains any of the products which contain forbidden html comment
395:         if ($this->getConfigData('CHECKITEMS') == 'yes' && !$shouldHide) {
396:             $prods = $cart->getProducts();
397:             foreach ($prods as $prod) {
398:                 if (stripos($prod['description_short'], '<!-- no dpd_ee_module -->') !== false) {
399:                     $shouldHide = true;
400:                     break;
401:                 }
402:             }
403:         }
404:         
405:         //weight check
406:         $loadedProductWeights = array();
407:         if (($this->getConfigData('MAX_PACKAGE_WEIGHT') > 0 || $this->getConfigData('MIN_PACKAGE_WEIGHT') > 0) && !$shouldHide) {
408:             $products = $cart->getProducts();
409:             foreach ($products as $product) {
410:                 if ($product['is_virtual']) {
411:                     continue;
412:                 }
413:                 for ($i = 0; $i < $product['cart_quantity']; $i++) {
414:                     $loadedProductWeights[] = $product['weight'];
415:                 }
416:                 if ($this->getConfigData('MAX_PACKAGE_WEIGHT') > 0 && !$shouldHide) {
417:                     if (max($loadedProductWeights) > (float)$this->getConfigData('MAX_PACKAGE_WEIGHT')) {
418:                         $shouldHide = true;
419:                     }
420:                 }
421:                 if ($this->getConfigData('MIN_PACKAGE_WEIGHT') > 0 && !$shouldHide) {
422:                     if (min($loadedProductWeights) > (float)$this->getConfigData('MIN_PACKAGE_WEIGHT')) {
423:                         $shouldHide = true;
424:                     }
425:                 }
426:             }
427:         }
428: 
429:         $title = $this->getConfigData('TITLE');
430:         $finalTitle = $title;
431:         if ($this->_isSerialized($title)) {
432:             $title = @unserialize($title);
433:             if (is_array($title)) {
434:                 $finalTitle = isset($title[$this->context->language->id]) ? $title[$this->context->language->id] : $title[0];
435:             }
436:         }
437:         
438: 
439: 
440:         $extraParams = array(
441:             'id_address_delivery' => $cart->id_address_delivery,
442:             'price' => $this->getOrderShippingCost($cart),
443:             'title' => $finalTitle,
444:             'logo' => __PS_BASE_URI__ . 'modules/' . $this->name . '/logo.gif',
445:             'id_address_invoice' => $cart->id_address_invoice,
446:             'error_message' => '', //not required since phone nr is mandatory
447:             'is_default' => false,
448:         );
449:         
450:         return $this->_getHelperModule()->displayExtraCarrier($this->name, $extraParams, $shouldHide);
451:         
452:         
453:         
454:         
455:     }
456:     
457: 
458:     /**
459:      * <p>PrestaShop implementation for displaing configuration form for this module</p>
460:      * @return string
461:      */
462:     public function getContent() {
463:         $html = '<h2>'.$this->displayName.'</h2>';
464:         
465:         if (!empty($_POST)) {
466:             $postErrors = $this->_postValidation();
467:             if (!sizeof($postErrors)) {
468:                 $html .= $this->_postProcess();
469:             } else {
470:                 foreach ($postErrors as $err) {
471:                     $html .= '<div class="alert error">' . $err . '</div>';
472:                 }
473:                 
474:             }
475:         }
476:         else {
477:             $html .= '<br />';
478:             
479:         }
480:         $html .= $this->_displayFormHeader();
481:         $html .= $this->_displayForm();
482:         
483:         
484:         return $html;
485:     }
486:     
487:     /**
488:      * <p>Fetches configuration for this instance and if not found, then attempts to look to parent instance.</p>
489:      * @param string $param
490:      * @return mixed
491:      */
492:     public function getConfigData($param) {
493:         $value = Configuration::get(eabi_dpd_courier::CONST_PREFIX . $param);
494:         if ($value === null || $value === false) {
495:             $formFields = $this->_initFormFields();
496:             if (isset($formFields[strtolower($param)]) && $formFields[strtolower($param)]['default']) {
497:                 return $formFields[strtolower($param)]['default'];
498:             }
499:             return Configuration::get(eabi_dpd_parcelstore::CONST_PREFIX . $param);
500:         }
501:         return $value;
502:     }
503:     
504:     
505: 
506: 
507:     /**
508:      * <p>Renders form HTML from the form fields configuration</p>
509:      * @param string $action action url
510:      * @param string $method form element method attribute
511:      * @param array $formFields form fields array
512:      * @return string resulting html
513:      */
514:     protected function _initFormFields() {
515:         if (count($this->form_fields)) {
516:             return $this->form_fields;
517:         }
518:         $yesno = array(
519:             'yes' => $this->l('Yes'),
520:             'no' => $this->l('No'),
521:         );
522:         $boxUnits = array(
523:             'order' => $this->l('Per Order'),
524:             'item' => $this->l('Per Package'),
525:         );
526:         $countryUnits = array(
527:             '0' => $this->l('All Allowed Countries'),
528:             '1' => $this->l('Specific Countries'),
529:         );
530: 
531:         $this->form_fields = array(
532:             'title' => array(
533:                 'title' => $this->l('Title'),
534:                 'type' => 'multilang',
535:                 'description' => $this->l('This controls the title which the user sees during checkout.'),
536:                 'default' => $this->l('DPD kulleriga koju või tööle'),
537:                 'css' => 'width: 300px;',
538:             ),
539:             'handling_fee' => array(
540:                 'title' => $this->l('Price'),
541:                 'type' => 'text',
542:                 'description' => '',
543:                 'default' => '5.80',
544:                 'css' => 'width: 300px;',
545:                 'validate' => array('required_entry', 'validate_number'),
546:             ),
547:             'tax' => array(
548:                 'title' => $this->l('Tax Id'),
549:                 'type' => 'select',
550:                 'description' => $this->l('Prices here are tax inclusive'),
551:                 'default' => '',
552:                 'css' => 'width: 300px;',
553:                 'validate' => array(),
554:                 'options' => $this->_getHelperModule()->getTaxes(),
555:             ),
556:             'handling_fee_country' => array(
557:                 'title' => $this->l('Price per country'),
558:                 'type' => 'countryprice',
559:                 'description' => $this->l('If country is not listed here, but this method is available, then general handling fee is applied'),
560:                 'default' => 'a:3:{s:18:"_1388700940288_288";a:5:{s:10:"country_id";s:2:"EE";s:10:"base_price";s:3:"5.8";s:8:"kg_price";s:4:"1.28";s:18:"free_shipping_from";s:0:"";s:7:"cod_fee";s:4:"2.50";}s:18:"_1388700961178_178";a:5:{s:10:"country_id";s:2:"LV";s:10:"base_price";s:5:"10.38";s:8:"kg_price";s:4:"3.15";s:18:"free_shipping_from";s:0:"";s:7:"cod_fee";s:4:"2.50";}s:18:"_1388700962221_221";a:5:{s:10:"country_id";s:2:"LT";s:10:"base_price";s:5:"11.75";s:8:"kg_price";s:4:"3.85";s:18:"free_shipping_from";s:0:"";s:7:"cod_fee";s:4:"2.50";}}',
561:                 'css' => 'width: 300px;',
562:                 'validate' => array('validate_handling_fee_country'),
563:             ),
564:             'checkitems' => array(
565:                 'title' => sprintf($this->l('Disable this carrier if product\'s short description contains HTML comment %s'), '&lt;!-- no dpd_ee_module --&gt;'),
566:                 'type' => 'select',
567:                 'description' => '',
568:                 'default' => 'no',
569:                 'css' => 'width: 300px;',
570:                 'options' => $yesno,
571:             ),
572:             'max_package_weight' => array(
573:                 'title' => $this->l('Maximum allowed package weight for this carrier'),
574:                 'type' => 'text',
575:                 'description' => '',
576:                 'default' => '31.5',
577:                 'css' => 'width: 300px;',
578:             ),
579:             'handling_action' => array(
580:                 'title' => $this->l('Handling action'),
581:                 'type' => 'select',
582:                 'description' => $this->l('Per Order: Shipping cost equals Shipping price')
583:                 . '<br/>' . $this->l('Per Package: Shipping cost equals Number of Items in cart multiplied by shipping price')
584:                 ,
585:                 'default' => 'yes',
586:                 'css' => 'width: 300px;',
587:                 'options' => $boxUnits,
588:             ),
589:             'free_groups' => array(
590:                 'title' => $this->l('Client groups who can get free shipping'),
591:                 'type' => 'multiselect',
592:                 'description' => $this->l('hold down CTRL / CMD button to select/deselect multiple'),
593:                 'default' => '',
594:                 'css' => 'width: 300px;',
595:                 'options' => $this->_getHelperModule()->getClientGroups(),
596:             ),
597:             'enable_free_shipping' => array(
598:                 'title' => $this->l('Enable free shipping'),
599:                 'type' => 'select',
600:                 'description' => '',
601:                 'default' => 'no',
602:                 'css' => 'width: 300px;',
603:                 'options' => $yesno,
604:             ),
605:             'free_shipping_from' => array(
606:                 'title' => $this->l('Free shipping subtotal'),
607:                 'type' => 'text',
608:                 'description' => '',
609:                 'default' => '',
610:                 'css' => 'width: 300px;',
611:                 'validate' => array('validate_number'),
612:             ),
613:             'sallowspecific' => array(
614:                 'title' => $this->l('Ship to applicable countries'),
615:                 'type' => 'select',
616:                 'description' => '',
617:                 'default' => '1',
618:                 'css' => 'width: 300px;',
619:                 'options' => $countryUnits,
620:             ),
621:             'specificcountry' => array(
622:                 'title' => $this->l('Ship to Specific countries'),
623:                 'type' => 'multiselect',
624:                 'description' => '',
625:                 'default' => 'EE,LV,LT',
626:                 'css' => 'width: 300px;',
627:                 'options' => $this->_getHelperModule()->getCountriesAsOptions(),
628:             ),
629:             
630:         );
631:         
632:         
633:         
634:         return $this->form_fields;
635:     }
636:     
637: 
638:     /**
639:      * <p>We need this to override addressId, so always one terminal would be available</p>
640:      * @param type $code
641:      * @param type $groupId
642:      * @param type $officeId
643:      * @param null $addressId
644:      */
645:     public function __getPostOffices($code, &$groupId = null, &$officeId = null, &$addressId = null) {
646:         $addressId = null;
647:     }
648:     
649:     /**
650:      * <p>This function is called when store administrator is viewing the order.</p>
651:      * <p>Nothing</p>
652:      * @param int $cart_id id cart for the order
653:      * @return string html string
654:      */
655:     public function displayInfoByCart($cart_id) {
656:         if ($this->dataSendExecutor != null) {
657:             $extraInfo = $this->dataSendExecutor->displayInfoByCart($cart_id);
658:             if ($extraInfo) {
659:                 return '<div class="eabi_dpd_parcelstore_chosen">'. $extraInfo.'</div>';
660:             }
661:         }
662:         return false;
663:     }
664:     
665:     
666:     /**
667:      * 
668:      * @return eabi_dpd_parcelstore_html_helper
669:      */
670:     protected function _getHtmlHelper() {
671:         /* @var $helper eabi_dpd_parcelstore_html_helper */
672:         $helper = $this->_getHelperModule()->helper('html_helper', eabi_dpd_parcelstore::NAME);
673:         $helper->setContext($this->context)->setModuleInstance(Module::getInstanceByName(eabi_dpd_parcelstore::NAME));
674:         return $helper;
675:     }
676:     
677:     
678:     
679: 
680:     /**
681:      * <p>Does nothing, <code>eabi_postoffice</code> module calls this</p>
682:      * @param int $lastUpdated
683:      * @return null
684:      */
685:     public function setLastUpdated($lastUpdated) {
686:         return;
687:     }
688: 
689:     /**
690:      * <p>Returns current timestamp, <code>eabi_postoffice</code> module calls this</p>
691:      * @return int
692:      */
693:     public function getLastUpdated() {
694:         return time();
695:     }
696:     
697:     
698:     /**
699:      * <p>Returns empty string, <code>eabi_postoffice</code> module calls this</p>
700:      * @return int
701:      */
702:     public function getGroupTitle($group) {
703:         return '';
704:     }
705: 
706: 
707:     /**
708:      * <p>Returns parcel terminal name when short names are enabled.</p>
709:      * <p>Returns parcel terminal name with address, telephone, opening times when short names are disabled.</p>
710:      * @param string $terminal
711:      * @return string
712:      */
713:     public function getTerminalTitle($terminal) {
714:         $title = $this->getConfigData('TITLE');
715:         $finalTitle = $title;
716:         if ($this->_isSerialized($title)) {
717:             $title = @unserialize($title);
718:             if (is_array($title)) {
719:                 $finalTitle = isset($title[$this->context->language->id]) ? $title[$this->context->language->id] : $title[0];
720:             }
721:         }
722:         
723:         return htmlspecialchars($finalTitle);
724:     }
725: 
726:     
727:     
728:     /**
729:      * <p>Returns parcel terminal name when short names are enabled.</p>
730:      * <p>Returns parcel terminal name with address, telephone, opening times when short names are disabled.</p>
731:      * @param array $terminal
732:      * @return string
733:      */
734:     public function getAdminTerminalTitle($terminal) {
735:         $title = $this->getConfigData('TITLE');
736:         $finalTitle = $title;
737:         if ($this->_isSerialized($title)) {
738:             $title = @unserialize($title);
739:             if (is_array($title)) {
740:                 $finalTitle = isset($title[$this->context->language->id]) ? $title[$this->context->language->id] : $title[0];
741:             }
742:         }
743:         
744:         return htmlspecialchars($finalTitle);
745:     }
746:     
747:     
748:     
749:     
750:     /**
751:      * <p>This carrier has no parcel terminal selection feature, so one entry must still be added with shipping method title defined for this carrier.</p>
752:      * @return array single office element
753:      */
754:     public function getOfficeList() {
755:         //we have only one item to insert here
756:         $result = array();
757:         $result[] = array(
758:             'place_id' => 1,
759:             'name' => $this->getConfigData('TITLE'),
760:             'city' => '',
761:             'county' => '',
762:             'description' => '',
763:             'country' => '',
764:             'zip' => '',
765:             'group_sort' => 0,
766:         );
767:         return $result;
768:         
769:     }
770:     
771:     /* module upgrades */
772: 
773:     /**
774:      * <p>Adds 2.5€ COD fee to Estonia, Latvia, Lithuania</p>
775:      * @return bool
776:      */
777:     public function upgrade_module_0_3() {
778:         /*
779:          * Set default CASH on delivery fee to following countries:
780:          *  EE
781:          *  LV
782:          *  LT
783:          * 
784:          * Set this fee to all defined config scopes
785:          */
786:         $configPaths = array(
787:             'E_DPDEEC_HANDLING_FEE_COUNTRY',
788:         );
789:         $countriesToApply = array(
790:             'EE', 'LV', 'LT',
791:         );
792:         $db = Db::getInstance();
793: 
794: 
795: 
796:         $inConfigPaths = implode("','", $configPaths);
797:         $sql = "SELECT * FROM `"._DB_PREFIX_."configuration` where `name` IN ('{$inConfigPaths}')";
798:         $configDatas = $db->executeS($sql, true);
799: 
800:         foreach ($configDatas as $configData) {
801:             $oldShippingPriceSet = @unserialize($configData['value']);
802:             //update value
803:             if (is_array($oldShippingPriceSet)) {
804:                 foreach ($oldShippingPriceSet as $randomKey => $countryPrices) {
805:                     if (in_array($countryPrices['country_id'], $countriesToApply)) {
806:                         if (!isset($countryPrices['cod_fee']) || !$countryPrices['cod_fee']) {
807:                             $oldShippingPriceSet[$randomKey]['cod_fee'] = '2.50';
808:                         }
809:                     }
810:                 }
811:                 //update done -re-serialize and save
812:                 $configData['value'] = serialize($oldShippingPriceSet);
813:                 $idConfiguration = $configData['id_configuration'];
814:                 //we cannot update primary key
815:                 unset($configData['id_configuration']);
816:                 
817:                 //we do not need to update those, since mainly they are empty strings
818:                 //and on int check they throw error like incorrect integer value
819:                 unset($configData['id_shop']);
820:                 unset($configData['id_shop_group']);
821:                 unset($configData['name']);
822:                 
823:                 $res = $db->update('configuration', $configData, "id_configuration = '{$db->escape($idConfiguration)}'");
824:                 if ($res === false) {
825:                     return false;
826:                 }
827:             }
828:         }
829:         return true;
830:     }
831:     
832:     
833: 
834: }
835: 
API documentation generated by ApiGen 2.8.0