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>Represents DPD parcel terminal shipping method.</p>
 36:  * <p>Extra order data is stored under specialized order comment</p>
 37:  * <p>Can perform following business actions:</p>
 38:  * <ul>
 39:      <li>Calculate shipping price based on country and weight</li>
 40:      <li>Display list of user selectable parcel terminals, which is auto updated.</li>
 41:      <li>Send information about shipment data to DPD server.</li>
 42:      <li>Display tracking link to user when tracking code is added to the shipment.</li>
 43:      <li>Call courier to pick up the shipment that was ordered using this carrier.</li>
 44:      <li>Print out packing slip PDF from Order view.</li>
 45:  </ul>
 46:  *
 47:  * @author matishalmann
 48:  */
 49: class Eabi_DpdEE_Model_Post extends Eabi_Postoffice_Model_Carrier_Abstract {
 50: 
 51:     protected $_code = Eabi_DpdEE_Model_Config::SHIPPING_METHOD_CODE_PARCEL_TERMINAL;
 52:     
 53:     /**
 54:      * If order comment starts with prefix marked here and is not visible on the frontend, then it is considered as extra data order comment.
 55:      */
 56:     const ORDER_COMMENT_START_PREFIX = '-----EABI_DPDEE-----';
 57:     
 58: 
 59:     /**
 60:      * <p>%s in the URL is replaced with tracking number.</p>
 61:      * @var string
 62:      */
 63:     protected $_tracking_url = 'https://tracking.dpd.de/cgi-bin/delistrack?typ=1&lang=en&pknr=%s';
 64: 
 65: 
 66: 
 67:     /**
 68:      * <p>If disable shipping by product comment is allowed and product's short description in shopping cart contains html comment &lt;!-- no dpd_ee_module --&gt; then it returns false.</p>
 69:      * @param Mage_Shipping_Model_Rate_Request $request
 70:      * @return boolean true if this method is available.
 71:      * @see Eabi_Postoffice_Model_Carrier_Abstract::_isAvailable()
 72:      */
 73:     protected function _isAvailable(Mage_Shipping_Model_Rate_Request $request) {
 74:         $productItem = true;
 75:         if ($this->getConfigData('checkitems') == 1) {
 76:             $productItem = true;
 77:             if ($request->getAllItems()) {
 78:                 foreach ($request->getAllItems() as $item) {
 79:                     $custom = Mage::getModel('catalog/product')->load($item->getProduct()->getId());
 80:                     $desc = $custom->getShortDescription();
 81:                     if (stristr($desc, '<!-- no dpd_ee_module -->')) {
 82:                         $productItem = false;
 83:                         break;
 84:                     }
 85:                     if (stristr($desc, '<!-- no dpd_ee_parcelstore -->')) {
 86:                         $productItem = false;
 87:                         break;
 88:                     }
 89:                 }
 90:             }
 91:         }
 92:         if (!$productItem) {
 93:             return false;
 94:         }
 95:         return true;
 96:     }
 97:     
 98:     
 99:     /**
100:      * <p>Attemps to calculate shipping price from price-country shipping price matrix.</p>
101:      * <p>If unsuccessful, then default handling fee is returned.</p>
102:      * <p>If shipping calculation mode is set Per Item, then price will be multiplied by number of packages</p>
103:      * @param Mage_Shipping_Model_Rate_Request $request
104:      * @param double $price
105:      * @return double
106:      */
107:     public function _calculateAdditionalShippingPrice(Mage_Shipping_Model_Rate_Request $request, $price) {
108:         $shippingMatrix = $this->_decodeShippingMatrix($this->getConfigDataForThis('handling_fee_country'));
109:         if ($request->getDestCountryId() && isset($shippingMatrix[$request->getDestCountryId()])) {
110:             //free price?
111:             if ($shippingMatrix[$request->getDestCountryId()]['free_shipping_from'] !== '') {
112:                 if ($request->getPackageValueWithDiscount() >= $shippingMatrix[$request->getDestCountryId()]['free_shipping_from']) {
113:                     return 0;
114:                 }
115:             }
116:             //subtraction is required because edges are 0-10,10.00001-20,....,....
117:             $packageWeight = $request->getPackageWeight() - 0.000001;
118:             $weightSet = 10;
119:             //we need to have price per every kg, where
120:             //0-10kg consists only base price
121:             //10,1-20kg equals base price + extra price
122:             //20,1-30kg equals base price + extra price * 2
123:             $extraWeightCost = max(floor($packageWeight / $weightSet) * $shippingMatrix[$request->getDestCountryId()]['kg_price'], 0);
124:             
125:             $handlingFee = $shippingMatrix[$request->getDestCountryId()]['base_price'];
126:             if ($this->getConfigData('handling_action') == 'P') {
127:                 $handlingFee = ($this->_getOfficeHelper()->getNumberOfPackagesFromItemWeights($request->getEabiProductWeights(), $this->getConfigData('max_package_weight'))  - $this->getFreeBoxes()) * $handlingFee;
128:             }
129:             $handlingFee += $extraWeightCost;
130:             
131:             return $handlingFee; 
132:         }
133:         return $price;
134:     }
135:     
136:     
137:     /**
138:      * <p>Decodes json encoded string to assoc array (array keys are country ISO codes) and returns in following format:</p>
139:      * <ul>
140:          <li><code>country_id</code> - Country ISO code, also array key for this element</li>
141:          <li><code>base_price</code> - base shipping price up to 10kg</li>
142:          <li><code>kg_price</code> - additional shipping price for each 10kg</li>
143:          <li><code>free_shipping_from</code> - when and if to apply free shipping</li>
144:      </ul>
145:      * @param string $input
146:      * @return array
147:      */
148:     protected function _decodeShippingMatrix($input) {
149:         $shippingMatrix = @unserialize($input);
150:         $result = array();
151:         if (!is_array($shippingMatrix)) {
152:             return $result;
153:         }
154:         foreach ($shippingMatrix as $countryDefinition) {
155:             $result[$countryDefinition['country_id']] = $countryDefinition;
156:         }
157:         return $result;
158:     }
159:     
160:     
161:     
162:     /**
163:      * <p>Fetches one line long human readable parcel terminal description from DPD Pudo instance</p>
164:      * @param array $parcelT
165:      * @return string
166:      */
167:     protected function _getDescription($parcelT) {
168:         if (!isset($parcelT['Pudo_worktime']) || !$parcelT['Pudo_worktime']) {
169:             return trim($parcelT['Sh_street'] . ' ' . $parcelT['Sh_city'] . ' ' . $parcelT['Sh_postal']. ', ' . $parcelT['Sh_country']. ' '.$parcelT['Sh_phone']);
170:         } else {
171:             return trim($parcelT['Sh_street'] . ' ' . $parcelT['Sh_city'] . ' ' . $parcelT['Sh_postal']. ', ' . $parcelT['Sh_country']. ' '.$parcelT['Sh_phone']
172:                     .' '.$this->_getDpdHelper()->getOpeningsDescriptionFromTerminal($parcelT['Pudo_worktime'], Zend_Locale::getLocaleToTerritory(strtoupper($parcelT['Sh_country']))));
173:         }
174:     }
175:     
176:     
177:     
178:     
179:     /**
180:      *
181:      * If the barcode function is available globally
182:      * @return boolean 
183:      */
184:     public function isBarcodeFunctionAvailable() {
185:         
186:         return $this->isAutoSendAvailable();
187:     }
188:     
189:     /**
190:      * <p>Sends parcel data to DPD server for specified order and selected parcel terminal id.</p>
191:      * @param Mage_Sales_Model_Order $order
192:      * @param type $selectedOfficeId
193:      * @return array comma separated parcel numbers in array key of 'barcode'
194:      */
195:     public function autoSendData(Mage_Sales_Model_Order $order, $selectedOfficeId) {
196:         $shippingAddress = $order->getShippingAddress();
197:         $selectedOffice = $this->getTerminal($selectedOfficeId);
198:         $requestData = array(
199:             'Sh_name' => $shippingAddress->getName(),
200:             'Sh_company' => $shippingAddress->getCompany(),
201:             'Sh_street' => $this->_getStreetFromDescription($selectedOffice),
202:             'Sh_postal' => $selectedOffice->getZipCode(),
203:             'Sh_country' => strtolower($selectedOffice->getCountry()),
204:             'Sh_city' => $selectedOffice->getCity(),
205:             'Sh_contact' => $selectedOffice->getName(),
206:             'Sh_phone' => $this->_getPhoneFromDescription($selectedOffice),
207:             'Po_remark' => $this->_getRemark($order),
208:             'Sh_remark' => '',
209:             'Sh_pudo' => 'true',
210:             'Sh_pudo_id' => $selectedOfficeId,
211:             'Sh_parcel_qty' => $this->_getNumberOfPackagesForOrder($order),
212:             'Sh_cust_reference' => $order->getIncrementId(),
213:         );
214:         
215:         //add cash on delivery
216:         if ($order->getTotalDue() > 0) {
217:             $requestData['Sh_cod_amount'] = number_format(round($order->getTotalDue(), 2), 2, '.', '');
218:             $requestData['Sh_cod_currency'] = $order->getCurrency();
219:         }
220:         
221:         $phoneNumbers = $this->_getDialCodeHelper()->separatePhoneNumberFromCountryCode($shippingAddress->getTelephone(), $shippingAddress->getCountryId());
222:         $requestData['Sh_notify_phone_code'] = $phoneNumbers['dial_code'];
223:         $requestData['Sh_notify_contact_phone'] = $phoneNumbers['phone_number'];
224:         $requestResult = $this->_getDpdHelper()->getApi($this->getStore(), $this->_code)
225:                 ->autoSendData($requestData);
226:         
227:         $this->_setDataToOrder($order, $requestResult);
228:         
229:         //on failure return false
230:         //is success
231:         return array('barcode' => '##'.  implode(',', $requestResult['Parcel_numbers']).'##');
232:     }
233:     
234:     
235:     
236:     /**
237:      * <p>Returns empty string</p>
238:      * @param Mage_Sales_Model_Order $order
239:      * @return string
240:      */
241:     protected function _getRemark($order) {
242:         return '';
243:     }
244: 
245: 
246:     /**
247:      * <p>Returns true if parcel data is sent to DPD server for specified order.</p>
248:      * @param Mage_Sales_Model_Order $order
249:      * @return boolean
250:      */
251:     public function isDataSent(Mage_Sales_Model_Order $order) {
252:         $orderData = $this->getDataFromOrder($order);
253:         if (isset($orderData['DPD_OrderID'])) {
254:             return true;
255:         }
256:         return false;
257:     }
258:     
259:     /**
260:      * <p>Returns packing slip URL if data is sent or false otherwise.</p>
261:      * @param Mage_Sales_Model_Order $order
262:      * @return boolean|string
263:      */
264:     public function getBarcode(Mage_Sales_Model_Order $order) {
265:         if (!$this->isBarcodeFunctionAvailable()) {
266:             return false;
267:         }
268:         
269:         $orderData = $this->getDataFromOrder($order);
270:         if (isset($orderData['PDF_URL']) && $orderData['PDF_URL']) {
271:             return $orderData['PDF_URL'];
272:         }
273:         return false;
274:     }
275: 
276:     /**
277:      * <p>Returns Packing slip PDF file, which can be echoed to browser for current order if one exists.</p>
278:      * @param Mage_Sales_Model_Order $order
279:      * @return string
280:      */
281:     public function getBarcodePdf(Mage_Sales_Model_Order $order) {
282:         $orderData = $this->getDataFromOrder($order);
283:         if (isset($orderData['PDF_URL']) && $orderData['PDF_URL']) {
284:             return file_get_contents(urldecode($orderData['PDF_URL']));
285:         }
286:     }
287:     
288:     
289:     
290:     
291:     /**
292:      * <p>Attempts to decode extra data stored within order commetns and return it as array.</p>
293:      * @param Mage_Sales_Model_Order $order
294:      * @return array
295:      */
296:     public function getDataFromOrder(Mage_Sales_Model_Order $order) {
297:         return $this->_getOfficeHelper()->getDataFromOrder($order, self::ORDER_COMMENT_START_PREFIX);
298:     }
299:     
300:     /**
301:      * <p>Sets extra data to order and creates specialized order comment for it when neccessary.</p>
302:      * @param Mage_Sales_Model_Order $order
303:      * @param array $data
304:      * @return array
305:      */
306:     public function _setDataToOrder(Mage_Sales_Model_Order $order, $data = array()) {
307:         return $this->_getOfficeHelper()->setDataToOrder($order, $data, self::ORDER_COMMENT_START_PREFIX);
308:     }
309: 
310: 
311: 
312: 
313: 
314:     /**
315:      * <p>Returns array of parcel terminals from DPD server or boolean false if fetching failed.</p>
316:      * @return array|boolean
317:      * @see Eabi_Postoffice_Model_Carrier_Abstract::getOfficeList()
318:      */
319:     public function getOfficeList() {
320:         $body = $this->_getDpdHelper()->getApi($this->getStore(), $this->_code)->getOfficeList();
321:         if (!$body || !is_array($body) || !isset($body['data'])) {
322:             return false;
323:         }
324:         $result = array();
325:         foreach ($body['data'] as $remoteParcelTerminal) {
326:                 $result[] = array(
327:                     'place_id' => $remoteParcelTerminal['Sh_pudo_id'],
328:                     'name' => $remoteParcelTerminal['Pudo_name'],
329:                     'city' => trim($remoteParcelTerminal['Sh_city']),
330:                     'county' => '',
331:                     'description' => $this->_getDescription($remoteParcelTerminal),
332:                     'country' => $remoteParcelTerminal['Sh_country'],
333:                     'zip' => $remoteParcelTerminal['Sh_postal'],
334:                     'group_sort' => $this->getGroupSort($remoteParcelTerminal['Sh_city']),
335:                 );
336:             
337:         }
338:         if (count($result) == 0) {
339:             return false;
340:         }
341:         return $result;
342:     }
343:     
344:     
345: 
346:     /**
347:      * <p>Returns parcel terminal name when short names are enabled.</p>
348:      * <p>Returns parcel terminal name with address, telephone, opening times when short names are disabled.</p>
349:      * @param Eabi_Postoffice_Model_Office $office
350:      * @return string
351:      * @see Eabi_Postoffice_Model_Carrier_Abstract::getTerminalTitle()
352:      */
353:     public function getTerminalTitle(Eabi_Postoffice_Model_Office $office) {
354:         if ($this->getConfigData('shortname')) {
355:             return htmlspecialchars($office->getName());
356:         }
357:         return htmlspecialchars($office->getName() . ' (' . $office->getDescription().')');
358:     }
359:     
360:     
361:     /**
362:      * <p>Returns parcel terminal name when short names are enabled.</p>
363:      * <p>Returns parcel terminal name with address, telephone, opening times when short names are disabled.</p>
364:      * @param Eabi_Postoffice_Model_Office $office
365:      * @return string
366:      * @see Eabi_Postoffice_Model_Carrier_Abstract::getAdminTerminalTitle()
367:      */
368:     public function getAdminTerminalTitle(Eabi_Postoffice_Model_Office $office) {
369:         if ($this->getConfigData('shortname')) {
370:             return htmlspecialchars($office->getGroupName().' - '.$office->getName());
371:         }
372:         return htmlspecialchars($office->getGroupName().' - '.$office->getName() . ' ' . $office->getDescription());
373:     }
374:     
375: 
376:     /**
377:      * 
378:      * @param Eabi_Postoffice_Model_Office $selectedOffice
379:      * @return type
380:      */
381:     private function _getStreetFromDescription(Eabi_Postoffice_Model_Office $selectedOffice) {
382:         $zip = $selectedOffice->getZipCode();
383:         $encoding = 'UTF-8';
384:         return trim(mb_substr($selectedOffice->getDescription(), 0, mb_strpos($selectedOffice->getDescription(), $zip, 0, $encoding), $encoding));
385:     }
386:     
387:     /**
388:      * 
389:      * @param Eabi_Postoffice_Model_Office $selectedOffice
390:      * @return string|array
391:      */
392:     private function _getPhoneFromDescription(Eabi_Postoffice_Model_Office $selectedOffice) {
393:         $zip = $selectedOffice->getZipCode();
394:         $country = $selectedOffice->getCountry();
395:         $matches = array();
396:         $isMatched = preg_match('/(?s:[\+][0-9]+)/', $selectedOffice->getDescription(), $matches);
397:         if ($isMatched) {
398:             return $matches[0];
399:         }
400:         return '';
401:     }
402:     
403: 
404:     /**
405:      * <p>Groups parcel terminals by following rules:</p>
406:      * <ul>
407:          <li>In Estonia parcel terminals from Tallinn, Tartu, Pärnu are displayed first respectively and remaining parcel terminals are displayed in alphabetical order.</li>
408:          <li>In Latvia parcel terminals from Riga, Daugavpils, Liepaja, Jelgava, Jurmala are displayed first respectively and remaining parcel terminals are displayed in alphabetical order.</li>
409:          <li>In Lithuania parcel terminals from Vilnius, Kaunas, Klaipeda, Siauliai, Alytus are displayed first respectively and remaining parcel terminals are displayed in alphabetical order.</li>
410:      </ul>
411:      * @param string $group_name
412:      * @return int
413:      * @see Eabi_Postoffice_Model_Carrier_Abstract::getGroupSort()
414:      */
415:     public function getGroupSort($group_name) {
416:         $group_name = trim(strtolower($group_name));
417:         $sorts = array(
418:             //Estonia
419:             'tallinn' => 20,
420:             'tartu' => 19,
421:             'pärnu' => 18,
422:             
423:             //Latvia
424:             'riga' => 20,
425:             'daugavpils' => 19,
426:             'liepaja' => 18,
427:             'jelgava' => 17,
428:             'jurmala' => 16,
429:             
430:             
431:             //Lithuania
432:             'vilnius' => 20,
433:             'kaunas' => 19,
434:             'klaipeda' => 18,
435:             'siauliai' => 17,
436:             'alytus' => 16,
437:             
438:         );
439:         if (isset($sorts[$group_name]) && $this->getConfigData('sort_offices')) {
440:             return $sorts[$group_name];
441:         }
442:         if (strpos($group_name, '/') > 0 && $this->getConfigData('sort_offices')) {
443:             return 0;
444:         }
445:         return 0;
446:     }
447:     
448:     /**
449:      * <p>Indicates if specified order has been picked up by courier.</p>
450:      * <p>Should return the following</p>
451:      * <ul>
452:          <li><b>true</b> - If the order has been picked up by courier</li>
453:          <li><b>false</b> - If the order has not been picked up by courier</li>
454:          <li><b>null</b> - If courier pickup is not applicable to specified order</li>
455:      </ul>
456:      * @param Mage_Sales_Model_Order $order
457:      * @return null|bool
458:      */
459:     public function isPickedUpByCourier(Mage_Sales_Model_Order $order) {
460:         if (!$this->getConfigData('courier_enable')) {
461:             return null;
462:         }
463:         $orderData = $this->getDataFromOrder($order);
464:         if (isset($orderData['courier_call_id']) && $orderData['courier_call_id']) {
465:             return true;
466:         }
467:         return false;
468:     }
469:     
470:     
471:     /**
472:      * <p>Returns number or parcels for the order according to Maximum Package Weight defined in DPD settings</p>
473:      * @param Mage_Sales_Model_Order $order
474:      * @return int
475:      * @see Eabi_Postoffice_Helper_Data::getNumberOfPackagesFromItemWeights()
476:      */
477:     protected function _getNumberOfPackagesForOrder(Mage_Sales_Model_Order $order) {
478:         $productWeights = array();
479:         foreach ($order->getAllVisibleItems() as $orderItem) {
480:             /* @var $orderItem Mage_Sales_Model_Order_Item */
481:             for ($i = 0; $i < ($orderItem->getQtyOrdered() - $orderItem->getQtyRefunded()); $i++) {
482:                 $productWeights[] = $orderItem->getWeight();
483:             }
484:             
485:         }
486:         return $this->_getOfficeHelper()->getNumberOfPackagesFromItemWeights($productWeights, $this->getConfigData('max_package_weight'));
487:     }
488:     
489:     
490:     /**
491:      * Gets config data only for this instance
492:      * @param string $field
493:      * @return mixed
494:      */
495:     public function getConfigDataForThis($field) {
496:         if (empty($this->_code)) {
497:             return false;
498:         }
499:         $path = 'carriers/'.$this->_code.'/'.$field;
500:         return Mage::getStoreConfig($path, $this->getStore());
501:     }
502:     
503:     /**
504:      * <p>Override this function in order to return senddata_event always manual, when http_request_timeout is greater than 10 seconds</p>
505:      * @param string $field
506:      * @return mixed
507:      */
508:     public function getConfigData($field) {
509:         if (empty($this->_code)) {
510:             return false;
511:         }
512:         return $this->_getConfigDataOverride($field, $this->_code);
513:     }
514:     
515:     /**
516:      * <p>Override is performed here</p>
517:      * @param string $field
518:      * @param string $code
519:      * @return string
520:      * @see Eabi_DpdEE_Model_Post::getConfigData()
521:      */
522:     protected function _getConfigDataOverride($field, $code) {
523:         if ($field == 'senddata_event') {
524:             $timeout = Mage::getStoreConfig('carriers/'.$code.'/http_request_timeout', $this->getStore());
525:             if ($timeout > 10) {
526:                 return 'manual';
527:             }
528:         }
529:         $path = 'carriers/'.$code.'/'.$field;
530:         return Mage::getStoreConfig($path, $this->getStore());
531:     }
532:     
533:     
534:     /**
535:      * <p>Takes Cash on delivery fee from <code>handling_fee_country</code> matrix, from field <code>cod_fee</code> and appends it to shipping price when set and is equal or greater than 0</p>
536:      * @param Mage_Shipping_Model_Rate_Request $request
537:      * @return double|int
538:      */
539:     protected function _applyPriceFromCod(Mage_Shipping_Model_Rate_Request $request) {
540:         
541:         if ($this->_getQuote() && !$this->_getQuote()->isVirtual() && Mage::getStoreConfig('payment/dpdcodpayment/active') && $this->_getQuote()->getPayment() && $this->_getQuote()->getPayment()->getMethod() && $this->_getQuote()->getPayment()->getMethod() == Eabi_DpdEE_Model_Config::PAYMENT_METHOD_COD && strpos($this->_getQuote()->getShippingAddress()->getShippingMethod(), $this->getCarrierCode()) === 0) {
542: 
543:             $shippingMatrix = $this->_decodeShippingMatrix($this->getConfigDataForThis('handling_fee_country'));
544:             if ($request->getDestCountryId() && isset($shippingMatrix[$request->getDestCountryId()])) {
545:                 //free price?
546:                 if (isset($shippingMatrix[$request->getDestCountryId()]['cod_fee']) && $shippingMatrix[$request->getDestCountryId()]['cod_fee'] !== '') {
547:                     $codFee = (float) str_replace(',', '.', $shippingMatrix[$request->getDestCountryId()]['cod_fee']);
548:                     if ($codFee >= 0) {
549:                         return $codFee;
550:                     }
551:                 }
552:             }
553:         }
554:         return 0;
555:     }
556:     
557:     /**
558:      * <p>Returns cash on delivery fee based on address</p>
559:      * <p>Does not check if Cash on delivery is available</p>
560:      * <p>Returns false if country is unspecified.</p>
561:      * @param Mage_Customer_Model_Address $address
562:      * @return boolean|float
563:      */
564:     public function getCodFee($address) {
565:         if ($address->getCountryId()) {
566: 
567: 
568:             $shippingMatrix = $this->_decodeShippingMatrix($this->getConfigDataForThis('handling_fee_country'));
569:             if ($address->getCountryId() && isset($shippingMatrix[$address->getCountryId()])) {
570:                 //free price?
571:                 if (isset($shippingMatrix[$address->getCountryId()]['cod_fee']) && $shippingMatrix[$address->getCountryId()]['cod_fee'] !== '') {
572:                     $codFee = (float) str_replace(',', '.', $shippingMatrix[$address->getCountryId()]['cod_fee']);
573:                     if ($codFee >= 0) {
574:                         return $codFee;
575:                     }
576:                 }
577:             }
578: 
579:         }
580: 
581:         return false;
582:     }
583: 
584:     
585:     /**
586:      * <p>Returns true if cash on delivery is allowed for specified address</p>
587:      * <p>Checks if COD is allowed by configuration variable <code>payment/dpdcodpayment/active</code> and COD fee is determined in shipping price matrix</p>
588:      * @param Mage_Customer_Model_Address $address
589:      * @return boolean
590:      */
591:     public function isCodEnabled($address) {
592:         $shippingMatrix = $this->_decodeShippingMatrix($this->getConfigDataForThis('handling_fee_country'));
593:         if ($address->getCountryId() && isset($shippingMatrix[$address->getCountryId()]) && isset($shippingMatrix[$address->getCountryId()]['cod_fee'])
594:                 && $shippingMatrix[$address->getCountryId()]['cod_fee'] !== '') {
595:             $codFee = (double) str_replace(',', '.', $shippingMatrix[$address->getCountryId()]['cod_fee']);
596:             if ($codFee >= 0) {
597:                 return true;
598:             }
599:         }
600:         return false;
601:     }
602: 
603:     /**
604:      * 
605:      * @return Eabi_DpdEE_Helper_Data
606:      */
607:     protected function _getDpdHelper() {
608:         return Mage::helper('eabi_dpdee');
609:     }
610:     
611: 
612:     
613: 
614: }
615: 
616: 
DPD Eesti - Pakivedu.ee Shipping module for Magento API documentation generated by ApiGen 2.8.0