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:  *
  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: 
 34: /**
 35:  * <p>Renders HTML block which allows to call DPD courier to pick up shipment.</p>
 36:  * <p>Template is located at <b>eabi_dpdee/order/courier.phtml</b> in adminhtml theme folder</p>
 37:  * <p>Information that can be sent to courier:</p>
 38:  * <ul>
 39:      <li>Merchant can pick suitable date from available list when courier should come</li>
 40:      <li>Merchant can pick suitable time-range from available list for the selected date</li>
 41:      <li>Merchant can specify how many envelopes, parcels, pallets should be picked up</li>
 42:      <li>Merchant can leave comment for the courier</li>
 43:      <li>By default one checked order equals one parcel</li>
 44:  </ul>
 45:  *
 46:  * @author Matis
 47:  */
 48: class Eabi_DpdEE_Block_Order_Courier extends Mage_Core_Block_Template {
 49:     protected $_dateFormat = 'yyyy-MM-dd';
 50:     protected $_timeFormat = 'HHmm';
 51:     protected $_timeFormatNice = 'HH:mm';
 52:     
 53:     protected $_availableDates;
 54:     protected $_apiResult;
 55:     
 56:     public function _construct() {
 57:         $this->setTemplate('eabi_dpdee/order/courier.phtml');
 58:         parent::_construct();
 59:     }
 60:     
 61:     /**
 62:      * <p>Only one block is allowed per page</p>
 63:      * @return string
 64:      */
 65:     public function getHtmlId() {
 66:         return 'eabi_carrier_order_courier_box';
 67:     }
 68:     
 69: 
 70: 
 71: 
 72: 
 73:     /**
 74:      * <p>Fetches list of available pickup dates from DPD server and returns it as HTML select string</p>
 75:      * @return string
 76:      */
 77:     public function getAvailableDates() {
 78:         if ($this->_availableDates) {
 79:             return $this->_availableDates;
 80:         }
 81:         $showOnlyDates = false;
 82:         $datesResult = $this->_getDpdHelper()->getApi($this->getStoreId(), $this->getCode())->getCourierCollectionTimes();
 83:         $this->_apiResult = $datesResult;
 84:         $dateObj = null;
 85: 
 86:         $resultString = '';
 87: //        $resultString .= '<pre>'.htmlspecialchars(print_r($datesResult, true)).'</pre>';
 88:             $resultString .= '<select name="Po_Date" id="Po_date" onchange="updateDpdEeTimes(this);">';
 89:             $resultString .= '<option value="-">'.$this->_getDpdHelper()->__(' - select pickup date - ').'</option>';
 90: 
 91:         foreach ($datesResult['Po_date'] as $dateString) {
 92:             if (is_null($dateObj)) {
 93:                 $dateObj = new Zend_Date($dateString, $this->_dateFormat);
 94:             }
 95:             $dateObj->set($dateString, $this->_dateFormat);
 96:             if ($dateObj->isToday() && !$showOnlyDates) {
 97:                 //today
 98:                 $resultString .= $this->_getDateInputLabel($this->_getDpdHelper()->__('Today'), $dateString);
 99:             } else if ($dateObj->isTomorrow() && !$showOnlyDates) {
100:                 //tomorrow
101:                 $resultString .= $this->_getDateInputLabel($this->_getDpdHelper()->__('Tomorrow'), $dateString);
102:             } else {
103:                 //other dates
104:                 $resultString .= $this->_getDateInputLabel($dateString, $dateString);
105:             }
106:         }
107:         $resultString .= '</select>';
108: 
109:         //do availabletimes as well
110:         $this->_availableDates = $resultString;
111:         return $this->_availableDates;
112:     }
113:     
114:     
115:     /**
116:      * <p>Fetches available pickup times from DPD server and returns it as json encoded object</p>
117:      * <p>Format:</p>
118:      * <pre>
119:      *  array(
120:      *      '2013-12-24' => 'html select menu with available time ranges',
121:      *      '2013-12-25' => 'html select menu with available time ranges',
122:      *      ....
123:      * );
124:      * </pre>
125:      * @return string
126:      */
127:     public function getAvailabeTimes() {
128:         if (!$this->_apiResult) {
129:             $this->getAvailableDates();
130:         }
131:         $availableTimes = array();
132:         $timeDateObject = null;
133:         //array key is date, content is html with select menu
134:         $availableTimes["-"] = $this->_getDpdHelper()->__('Select pickup date first');
135:         foreach ($this->_apiResult['Po_date'] as $key => $dateString) {
136:             $timeFrom = $this->_normalizeTime($this->_apiResult['Po_time_from'][$key]);
137:             $timeTo = $this->_normalizeTime($this->_apiResult['Po_time_til'][$key]);
138:             $timeWindow = $this->_normalizeTime($this->_apiResult['Minimal_time_window'][$key]);
139:             $availableTimes[$dateString] = $this->_getTimeSelectMenu($timeFrom, $timeTo, $timeWindow);
140:         }
141:         return json_encode($availableTimes);
142:     }
143:     
144:     /**
145:      * <p>Normalizes DPD times to Zend_Date objects.</p>
146:      * <p>For example 930 should be displayed as 09:30 and 9 should be displayed as 09:00</p>
147:      * @param string $input
148:      * @return Zend_Date
149:      */
150:     protected function _normalizeTime($input) {
151:         if (strlen($input) === 1) {
152:             $input = '0'.$input .'00';
153:         }
154:         if (strlen($input) === 2) {
155:             $input = $input .'00';
156:         }
157:         if (strlen($input) === 3) {
158:             $input = '0'.$input;
159:         }
160:         $date = new Zend_Date($input, $this->_timeFormat);
161:         $date->setTimezone('Etc/GMT+0');
162:         return $date;
163:     }
164: 
165: 
166:     /**
167:      * <p>Takes earliest possible time, latest possible time, minimum allowed timewindow and renders it into one select menu with pickup time ranges.</p>
168:      * <p>All arguments have to be within same date.</p>
169:      * <p>Pickup time ranges are always displayed within narrowest possible timewindow.</p>
170:      * @param Zend_Date $timeFrom earliest time possible
171:      * @param Zend_Date $timeTo latest time possible
172:      * @param Zend_Date $timeWindow minimal allowed time between start and end time.
173:      * @return string HTML select menu
174:      */
175:     protected function _getTimeSelectMenu(Zend_Date $timeFrom, Zend_Date $timeTo, Zend_Date $timeWindow) {
176:         $position = $timeFrom->get('H');
177:         $result = '<select name="Po_Time" id="Po_Time">';
178:         do {
179:             $endTime = clone $timeFrom;
180:             $endTime->add($timeWindow);
181:             if ($timeTo->isEarlier($endTime)) {
182:                 $timeDisplay = htmlspecialchars(ltrim($timeFrom->get($this->_timeFormat), '0') . '-' . ltrim($timeTo->get($this->_timeFormat), '0'));
183:                 $timeDisplayNice = htmlspecialchars($timeFrom->get($this->_timeFormatNice) . '-' . $timeTo->get($this->_timeFormatNice));
184:             } else {
185:                 $timeDisplay = htmlspecialchars(ltrim($timeFrom->get($this->_timeFormat), '0') . '-' . ltrim($endTime->get($this->_timeFormat), '0'));
186:                 $timeDisplayNice = htmlspecialchars($timeFrom->get($this->_timeFormatNice) . '-' . $endTime->get($this->_timeFormatNice));
187:             }
188:             $result .= '<option value="' . $timeDisplay . '">' . $timeDisplayNice . '</option>';
189:             $timeFrom->setTimestamp($timeFrom->getTimestamp() + 60 * 60);
190:         } while ($timeFrom->get(Zend_Date::HOUR_SHORT) + $timeWindow->get(Zend_Date::HOUR_SHORT) <= $timeTo->get(Zend_Date::HOUR_SHORT));
191:         $result .= '</select>';
192:         return $result;
193:     }
194: 
195:     protected function _getDateInputLabel($label, $value) {
196:         return '<option value="'.  htmlspecialchars($value).'" >'.  htmlspecialchars($label).'</option>';
197:     }
198:     
199:     /**
200:      * <p>Returns shipping method code that this courier HTML block is used by.</p>
201:      * @return string
202:      */
203:     public function getCode() {
204:         if (!$this->getData('code')) {
205:             return 'eabidpdee';
206:         }
207:         return $this->getData('code');
208:     }
209:     
210:     /**
211:      * <p>Returns default envelope quantity</p>
212:      * @return string
213:      */
214:     public function getEnvelopeQty() {
215:         return '0';
216:     }
217:     
218:     
219:     /**
220:      * <p>Returns default parcel quantity</p>
221:      * @return string
222:      */
223:     public function getParcelQty() {
224:         return '1';
225:         
226:     }
227:     
228:     
229:     /**
230:      * <p>Returns default pallet quantity</p>
231:      * @return string
232:      */
233:     public function getPalletQty() {
234:         return '0';
235:         
236:     }
237:     
238:     /**
239:      * 
240:      * @return Eabi_DpdEE_Helper_Data
241:      */
242:     protected function _getDpdHelper() {
243:         return Mage::helper('eabi_dpdee');
244:     }
245:     
246:     
247: }
248: 
DPD Eesti - Pakivedu.ee Shipping module for Magento API documentation generated by ApiGen 2.8.0