tig_postnl - Version 1.2.0

Version Notes

==== v1.2.0 =====
==== New features ====
- Added delivery options to the checkout flow. Customers can now choose where, when and how they want their order shipped when choosing their preferred shipping method.
- Added support for evening delivery, early pickup locations and parcel dispenser locations.
- Added Dutch postcode validation support.
- Added the option to create a parcelware export csv file directly from the Magento backend.
- Added a MijnPakket login feature. Customers who have a MijnPakket account can use this feature to automatically fill in their preferred billing and shipping address.

==== Minor improvements ====
- Refactored the label printing functionality. Shipping labels will now be opened in a separate window from where they may be printed or downloaded.
- Added the option to select where on an A4 page the shipping labels will start printing. This allows you to re-use partially used sticker-sheets.
- Added many new customization options for the shipment grid in the Magento backend.
- Added the ability to view and edit a chosen post office delivery address from the Magento backend.
- Added the option to only show the PostNL Checkout feature to customers who have a MijnPakket account.
- Refactored many sections of the source code to improve readability and extensibility.
- Moved several configuration settings.
- Merged the 'test/live mode' settings of PostNl Checkout and Label Printing & Confirming functionality. There is now a single option to set the entire extension to test or live mode.
- Added the option to upload separate csv files for the PostNL shipping method in 'table rate' configuration.

==== Bug fixes ====
- Fixed an issue where it was not possible to choose to only manually send track & trace information.
- Fixed several typos and translation errors.

==== v1.1.5 =====

==== Bug fixes ====
- Fixed a problem with account validation only using test mode account credentials
- Made a minor security improvement to the notification system.
- Fixed an issue where shipments could not be confirmed if the shipping address did not have an email address.
- Fixed an issue where PostNl Checkout would incorrectly identify a product as being out of stock.
- Fixed an issue where for some shops PostNl Checkout would not function due to incorrect usage of https in an http environment.

==== v1.1.4 =====

==== New features ====
- Added a default test account to the extension. New installation will automatically have a PostNL test account pre-configured.
- Added the option to undo a confirmation as long as the shipment has not been received by PostNL.
- Added the option to delete shipping labels. This allows you to correct an address after a shipping label has been printed. Before this change if you noticed an error in the address after you had already printed a shipping label, you had to place en entire new order to correct it. Now you can simply delete the shipping label, edit the address and print a new shipping label with the new address.

==== Minor change ====
- The validate settings button in the extension’s configuration page now also validates settings while the extension is set to test mode.
- Removed the 'EU Pack Standard (Belgium only, no signature)' product option. If you use this option, please contact the Total Internet Group servicedesk.
- The extension's test mode is now available by default. In earlier versions you had to allow test mode through a setting under advanced options.
- When a confirmation expires, the barcode's track & trace link will now also be removed.
- Improved various texts and translations.

==== Bug fixes ====
- Solved an issue where certain configurations of the PostNL shipping method would only appear if the Magento tablerates shipping method was also active.
- Solved an issue where filtering the order and shipment grids in the Magento backend on certain columns would cause an error.
- Solved an issue where the shipment status cron would stop as soon as it encountered an error, rather than continue processing the remaining shipments.
- Solved an issue where you could not confirm a shipment without a barcode due to process locking when developer mode is active.
- Solved issue in Safari where labels would be printed as .pdf.html, rather than just .pdf files.

==== v1.1.3 ====

- FIxed an issue with the extension's activation procedure.

==== v1.1.2 ====

- Updated manual.

==== v1.1.1 ====

- Fixed issue where filtering the first column of the shipment grid could cause errors.
- Removed PHP extension dependencies from the PostNL extension packages. Magento connect would sometimes falsely report a PHP extension as missing preventing the PostNL extension from being installed.

==== v1.1.0 ====

- First public release.

==== v1.0.8 ====

- Improved compatibility with Magento 1.6 and 1.11.

==== v1.0.7 ====

- Improved configuration fields.
- Improved translations.

==== v1.0.6 ====

- Improved shipment grid interface. It shoulod now be more clear which shipments have been confirmed and when they should be handed over to PostNL.
- Improved PostNL Checkout payment method handling. The Checkout summary page should now remember your chosen bank when you attempt to pay using iDEAL. 100% support for all payment methods is not guaranteed.

==== v1.0.5 ====

- Several bug fixes.
- Improved configuration interface.

==== v1.0.4 ====

- Several minor bug fixes.
- Improved Dutch translations.
- Added additional information to several fields in system/config.

==== v1.0.3 ====

- Several bug fixes. Including an issue preventing the extension from functioning properly with the compiler active.
- Several improvements to the Dutch translations.
- Improved the extension's system > config interface
- Added the Klarna payment method to PostNL Checkout

==== v1.0.2 ====

- A large number of bug fixes and general improvements
- Improved error handling. Almost all errors will now automatically provide you with a link where you can find more information and a possible solution.

==== v1.0.1 ====

- Added a filter to the possible product options you may select, based on the selected orders when mass-creating shipments from the order grid.
- Improved several translations.
- Fixed several minor bugs.

==== v1.0.0 ====

This is the initial beta release of the extension. If you have any questions, please contact the Total Internet Group Servicedesk

Download this release

Release Info

Developer TIG
Extension tig_postnl
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.1.5 to 1.2.0

Files changed (128) hide show
  1. app/code/community/TIG/PostNL/Block/Adminhtml/Carrier/Postnl/Tablerate/Grid.php +58 -0
  2. app/code/community/TIG/PostNL/Block/Adminhtml/CronNotification.php +32 -27
  3. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/ProductOptions.php +49 -39
  4. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/Create/ShipmentOptions.php +56 -51
  5. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/ShippingStatus.php +43 -35
  6. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tab/StatusHistory.php +39 -39
  7. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tabs.php +31 -29
  8. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form.php +96 -54
  9. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ActivateButton.php +27 -24
  10. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ActivatedFieldHeader.php +39 -33
  11. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/Anchor.php +92 -0
  12. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ConfigCheck.php +9 -5
  13. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/InfoBox.php +22 -16
  14. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/Obscure.php +90 -0
  15. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/SplitAddressCheck.php +44 -30
  16. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/SupportTab.php +57 -25
  17. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/TablerateExport.php +82 -0
  18. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/TablerateImport.php +90 -0
  19. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/TextBox/Abstract.php +29 -22
  20. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ValidateButton.php +25 -24
  21. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/WarningBox.php +22 -16
  22. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Fieldset.php +18 -18
  23. app/code/community/TIG/PostNL/Block/Adminhtml/Template.php +60 -0
  24. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Action.php +97 -61
  25. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Barcode.php +28 -26
  26. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmDate.php +27 -27
  27. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmStatus.php +26 -23
  28. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/DeliveryDate.php +80 -0
  29. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShipmentType.php +106 -53
  30. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingDescription.php +123 -0
  31. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingPhase.php +20 -20
  32. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Time.php +32 -28
  33. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Translate.php +19 -19
  34. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/YesNo.php +23 -23
  35. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Massaction/LabelStartPos.php +51 -0
  36. app/code/community/TIG/PostNL/Block/Adminhtml/WindowsTheme.php +86 -0
  37. app/code/community/TIG/PostNL/Block/Checkout/Cart/CheckoutLink.php +47 -18
  38. app/code/community/TIG/PostNL/Block/Checkout/Cart/Js.php +102 -58
  39. app/code/community/TIG/PostNL/Block/Checkout/Summary.php +48 -41
  40. app/code/community/TIG/PostNL/Block/Core/JsTranslate.php +215 -0
  41. app/code/community/TIG/PostNL/Block/Core/ShippingStatus.php +41 -33
  42. app/code/community/TIG/PostNL/Block/Core/Template.php +60 -0
  43. app/code/community/TIG/PostNL/Block/DeliveryOptions/Checkout/AddPhoneNumber.php +124 -0
  44. app/code/community/TIG/PostNL/Block/DeliveryOptions/Checkout/DeliveryOptions.php +560 -0
  45. app/code/community/TIG/PostNL/Block/DeliveryOptions/Js.php +70 -0
  46. app/code/community/TIG/PostNL/Block/DeliveryOptions/Template.php +123 -0
  47. app/code/community/TIG/PostNL/Block/DeliveryOptions/Theme.php +120 -0
  48. app/code/community/TIG/PostNL/Block/Mijnpakket/AccountNotification.php +355 -0
  49. app/code/community/TIG/PostNL/Block/Mijnpakket/Js.php +143 -0
  50. app/code/community/TIG/PostNL/Block/Mijnpakket/LoginButton.php +216 -0
  51. app/code/community/TIG/PostNL/Block/Mijnpakket/OrderSuccessJs.php +70 -0
  52. app/code/community/TIG/PostNL/Exception.php +42 -44
  53. app/code/community/TIG/PostNL/Helper/AddressValidation.php +400 -0
  54. app/code/community/TIG/PostNL/Helper/Carrier.php +54 -51
  55. app/code/community/TIG/PostNL/Helper/Checkout.php +40 -55
  56. app/code/community/TIG/PostNL/Helper/Cif.php +578 -197
  57. app/code/community/TIG/PostNL/Helper/Data.php +310 -87
  58. app/code/community/TIG/PostNL/Helper/DeliveryOptions.php +739 -0
  59. app/code/community/TIG/PostNL/Helper/Mijnpakket.php +105 -0
  60. app/code/community/TIG/PostNL/Helper/Parcelware.php +146 -0
  61. app/code/community/TIG/PostNL/Helper/Webservices.php +59 -86
  62. app/code/community/TIG/PostNL/Model/AddressValidation/Cendris.php +101 -0
  63. app/code/community/TIG/PostNL/Model/AddressValidation/Cendris/Abstract.php +113 -0
  64. app/code/community/TIG/PostNL/Model/AddressValidation/Observer/AddressBook.php +110 -0
  65. app/code/community/TIG/PostNL/Model/AddressValidation/Observer/OneStepCheckout.php +129 -0
  66. app/code/community/TIG/PostNL/Model/AddressValidation/Observer/Onepage.php +170 -0
  67. app/code/community/TIG/PostNL/Model/AddressValidation/System/Config/Backend/ValidateAccount.php +284 -0
  68. app/code/community/TIG/PostNL/Model/Admin/Logging/Handler/Postnl.php +66 -0
  69. app/code/community/TIG/PostNL/Model/Admin/Logging/Observer.php +67 -0
  70. app/code/community/TIG/PostNL/Model/Adminhtml/Observer/OrderGrid.php +95 -19
  71. app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentGrid.php +338 -75
  72. app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentView.php +90 -26
  73. app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/ShipmentGridColumns.php +33 -17
  74. app/code/community/TIG/PostNL/Model/{Core → Adminhtml}/System/Config/Source/ShipmentGridMassaction.php +22 -18
  75. app/code/community/TIG/PostNL/Model/Carrier/Postnl.php +162 -47
  76. app/code/community/TIG/PostNL/Model/Carrier/Resource/Tablerate.php +152 -0
  77. app/code/community/TIG/PostNL/Model/Carrier/Resource/Tablerate/Collection.php +53 -0
  78. app/code/community/TIG/PostNL/Model/Carrier/System/Config/Backend/Tablerate.php +50 -0
  79. app/code/community/TIG/PostNL/Model/Carrier/System/Config/Source/RateType.php +17 -17
  80. app/code/community/TIG/PostNL/Model/Carrier/System/Config/Source/TablerateSource.php +62 -0
  81. app/code/community/TIG/PostNL/Model/Carrier/Tablerate.php +54 -0
  82. app/code/community/TIG/PostNL/Model/Checkout/Cif.php +218 -189
  83. app/code/community/TIG/PostNL/Model/Checkout/Observer/Order.php +29 -25
  84. app/code/community/TIG/PostNL/Model/Checkout/Observer/Shipment.php +32 -29
  85. app/code/community/TIG/PostNL/Model/Checkout/Order.php +20 -135
  86. app/code/community/TIG/PostNL/Model/Checkout/Service.php +972 -868
  87. app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/ActivePaymentMethods.php +20 -20
  88. app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/CmsPage.php +35 -32
  89. app/code/community/TIG/PostNL/Model/Core/Cif.php +331 -325
  90. app/code/community/TIG/PostNL/Model/Core/Cif/Abstract.php +349 -226
  91. app/code/community/TIG/PostNL/Model/Core/Cif/Exception.php +46 -43
  92. app/code/community/TIG/PostNL/Model/Core/Label.php +55 -40
  93. app/code/community/TIG/PostNL/Model/Core/Observer/Barcode.php +62 -37
  94. app/code/community/TIG/PostNL/Model/Core/Observer/Cron.php +44 -7
  95. app/code/community/TIG/PostNL/Model/Core/Observer/SaveShipment.php +27 -25
  96. app/code/community/TIG/PostNL/Model/Core/Order.php +247 -0
  97. app/code/community/TIG/PostNL/Model/{Checkout → Core}/Resource/Order.php +19 -19
  98. app/code/community/TIG/PostNL/Model/{Checkout → Core}/Resource/Order/Collection.php +20 -20
  99. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment.php +17 -17
  100. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode.php +16 -16
  101. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode/Collection.php +17 -17
  102. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Collection.php +17 -17
  103. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label.php +16 -16
  104. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label/Collection.php +17 -17
  105. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Status/History.php +17 -17
  106. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Status/History/Collection.php +17 -17
  107. app/code/community/TIG/PostNL/Model/Core/Shipment.php +890 -310
  108. app/code/community/TIG/PostNL/Model/Core/Shipment/Barcode.php +41 -21
  109. app/code/community/TIG/PostNL/Model/Core/Shipment/Label.php +31 -21
  110. app/code/community/TIG/PostNL/Model/Core/Shipment/Process.php +54 -37
  111. app/code/community/TIG/PostNL/Model/Core/Shipment/Status/History.php +63 -36
  112. app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/ValidateDefaultOption.php +152 -0
  113. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/AllProductOptions.php +175 -61
  114. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/Attributes.php +24 -20
  115. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/DebugMode.php +16 -16
  116. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/Direction.php +16 -16
  117. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/EuProductOptions.php +4 -0
  118. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalProductOptions.php +32 -30
  119. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalpackShipmentType.php +74 -0
  120. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/LabelSize.php +16 -16
  121. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakjeGemakProductOptions.php +92 -41
  122. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakketautomaatProductOptions.php +113 -0
  123. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ReferenceType.php +16 -16
  124. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StandardProductOptions.php +111 -52
  125. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetField.php +30 -30
  126. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetFieldWithDefault.php +18 -18
  127. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/WeightUnit.php +18 -18
  128. app/code/community/TIG/PostNL/Model/DeliveryOptions/Cif.php +394 -0
app/code/community/TIG/PostNL/Block/Adminhtml/Carrier/Postnl/Tablerate/Grid.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Block_Adminhtml_Carrier_Postnl_Tablerate_Grid
40
+ extends Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid
41
+ {
42
+ /**
43
+ * Prepare shipping table rate collection
44
+ *
45
+ * @return Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid
46
+ */
47
+ protected function _prepareCollection()
48
+ {
49
+ /** @var $collection Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection */
50
+ $collection = Mage::getResourceModel('postnl_carrier/tablerate_collection');
51
+ $collection->setConditionFilter($this->getConditionName())
52
+ ->setWebsiteFilter($this->getWebsiteId());
53
+
54
+ $this->setCollection($collection);
55
+
56
+ return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
57
+ }
58
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/CronNotification.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,20 +33,25 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_CronNotification extends Mage_Adminhtml_Block_Abstract
40
  {
 
 
 
 
 
41
  /**
42
  * Cron expression for cronjobs working in 'always' cron mode
43
  */
44
  const ALWAYS_CRON_EXPR = 'always';
45
-
46
  /**
47
  * Check to see if the cron is running. This is done by checking if the last executed cron task
48
  * was executed less than 1 hour ago.
49
- *
50
  * @return boolean
51
  */
52
  public function isCronActive()
@@ -56,7 +61,7 @@ class TIG_PostNL_Block_Adminhtml_CronNotification extends Mage_Adminhtml_Block_A
56
  */
57
  $coreResource = Mage::getSingleton('core/resource');
58
  $readConnection = $coreResource->getConnection('core_read');
59
-
60
  /**
61
  * Create an array of cronjobs that need to be ignored
62
  */
@@ -66,7 +71,7 @@ class TIG_PostNL_Block_Adminhtml_CronNotification extends Mage_Adminhtml_Block_A
66
  if (!isset($cronData['schedule']) || !isset($cronData['schedule']['cron_expr'])) {
67
  continue;
68
  }
69
-
70
  /**
71
  * Cron jobs with the cron_expr 'always' work on a different cron mode
72
  */
@@ -74,13 +79,13 @@ class TIG_PostNL_Block_Adminhtml_CronNotification extends Mage_Adminhtml_Block_A
74
  $ignoreCronjobs[] = $cronjob;
75
  }
76
  }
77
-
78
  /**
79
  * Select the last executed cronjob
80
  */
81
  $select = $readConnection->select();
82
  $select->from($coreResource->getTablename('cron/schedule'), array('MAX(executed_at)'));
83
-
84
  /**
85
  * Filter out the invalid cronjobs
86
  */
@@ -88,19 +93,19 @@ class TIG_PostNL_Block_Adminhtml_CronNotification extends Mage_Adminhtml_Block_A
88
  $ignoreCronjobs = implode(',', $ignoreCronjobs);
89
  $select->where('job_code NOT IN (?)', $ignoreCronjobs);
90
  }
91
-
92
  /**
93
  * Get the last execution time of a PostNL cronjob
94
  */
95
  $lastExecutionTime = $readConnection->fetchOne($select);
96
-
97
  /**
98
  * If no execution time was found it means the cron has never run before
99
  */
100
  if (!$lastExecutionTime) {
101
  return false;
102
  }
103
-
104
  /**
105
  * Check if the last execution time was more than an hour ago.
106
  * If no crontask has been executed in an hour it's likely that something is wrong.
@@ -108,11 +113,11 @@ class TIG_PostNL_Block_Adminhtml_CronNotification extends Mage_Adminhtml_Block_A
108
  $currentTimestamp = Mage::getModel('core/date')->gmtTimestamp();
109
  $oneHourAgoTimestamp = strtotime('-1 hour', $currentTimestamp);
110
  $lastExecutionTimestamp = strtotime($lastExecutionTime);
111
-
112
  if ($lastExecutionTimestamp < $oneHourAgoTimestamp) {
113
  return false;
114
  }
115
-
116
  return true;
117
  }
118
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_CronNotification extends TIG_PostNL_Block_Adminhtml_Template
40
  {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_adminhtml_cronnotification';
45
+
46
  /**
47
  * Cron expression for cronjobs working in 'always' cron mode
48
  */
49
  const ALWAYS_CRON_EXPR = 'always';
50
+
51
  /**
52
  * Check to see if the cron is running. This is done by checking if the last executed cron task
53
  * was executed less than 1 hour ago.
54
+ *
55
  * @return boolean
56
  */
57
  public function isCronActive()
61
  */
62
  $coreResource = Mage::getSingleton('core/resource');
63
  $readConnection = $coreResource->getConnection('core_read');
64
+
65
  /**
66
  * Create an array of cronjobs that need to be ignored
67
  */
71
  if (!isset($cronData['schedule']) || !isset($cronData['schedule']['cron_expr'])) {
72
  continue;
73
  }
74
+
75
  /**
76
  * Cron jobs with the cron_expr 'always' work on a different cron mode
77
  */
79
  $ignoreCronjobs[] = $cronjob;
80
  }
81
  }
82
+
83
  /**
84
  * Select the last executed cronjob
85
  */
86
  $select = $readConnection->select();
87
  $select->from($coreResource->getTablename('cron/schedule'), array('MAX(executed_at)'));
88
+
89
  /**
90
  * Filter out the invalid cronjobs
91
  */
93
  $ignoreCronjobs = implode(',', $ignoreCronjobs);
94
  $select->where('job_code NOT IN (?)', $ignoreCronjobs);
95
  }
96
+
97
  /**
98
  * Get the last execution time of a PostNL cronjob
99
  */
100
  $lastExecutionTime = $readConnection->fetchOne($select);
101
+
102
  /**
103
  * If no execution time was found it means the cron has never run before
104
  */
105
  if (!$lastExecutionTime) {
106
  return false;
107
  }
108
+
109
  /**
110
  * Check if the last execution time was more than an hour ago.
111
  * If no crontask has been executed in an hour it's likely that something is wrong.
113
  $currentTimestamp = Mage::getModel('core/date')->gmtTimestamp();
114
  $oneHourAgoTimestamp = strtotime('-1 hour', $currentTimestamp);
115
  $lastExecutionTimestamp = strtotime($lastExecutionTime);
116
+
117
  if ($lastExecutionTimestamp < $oneHourAgoTimestamp) {
118
  return false;
119
  }
120
+
121
  return true;
122
  }
123
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/ProductOptions.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,77 +33,87 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
 
 
38
  */
39
- class TIG_PostNL_Block_Adminhtml_Sales_Order_ProductOptions extends Mage_Adminhtml_Block_Abstract
40
- {
 
 
 
 
 
41
  /**
42
  * Get available product options
43
- *
44
  * @return array
45
  */
46
  public function getExtraCoverProductOptions()
47
  {
48
- if ($this->getData('extra_cover_product_options')) {
49
- return $this->getData('extra_cover_product_options');
50
  }
51
-
52
  $productOptions = Mage::getModel('postnl_core/system_config_source_allProductOptions')
53
  ->getExtraCoverOptions(true);
54
-
55
  $this->setExtraCoverProductOptions($productOptions);
56
  return $productOptions;
57
  }
58
-
59
  /**
60
  * Get available GlobalPack product option
61
- *
62
  * @return string
63
  */
64
  public function getGlobalPackProductOption()
65
  {
66
- if ($this->getData('globalpack_product_option')) {
67
- return $this->getData('globalpack_product_option');
68
  }
69
-
70
  $globalPackProductOption = Mage::getModel('postnl_core/system_config_source_globalProductOptions')
71
  ->getAvailableOptions();
72
-
73
  if (empty($globalPackProductOption)) {
74
  return '';
75
  }
76
-
77
  $optionValue = $globalPackProductOption[0]['value'];
78
  $this->setGlobalpackProductOption($optionValue);
79
  return $optionValue;
80
  }
81
-
82
  /**
83
  * Gets an array of shipment types for use with GlobalPack shipments
84
- *
85
  * @return array
86
  */
87
  public function getShipmentTypes()
88
  {
89
  $shipmentTypes = Mage::helper('postnl/cif')->getShipmentTypes();
90
-
91
  return $shipmentTypes;
92
  }
93
-
94
  /**
95
  * Check if the PostNL module is enabled before rendering
96
- *
97
  * @return string | parent::_toHtml()
98
- *
99
  * @see Mage_Adminhtml_Block_Abstract::_toHtml()
100
  */
101
  protected function _toHtml()
102
- {
103
- if (!Mage::helper('postnl')->isEnabled()) {
104
- return '';
105
  }
106
-
107
  return parent::_toHtml();
108
  }
109
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasExtraCoverProductOptions()
40
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_ProductOptions setExtraCoverProductOptions(array $value)
41
+ * @method boolean hasGlobalpackProductOption()
42
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_ProductOptions setGlobalpackProductOption(array $value)
43
  */
44
+ class TIG_PostNL_Block_Adminhtml_Sales_Order_ProductOptions extends TIG_PostNL_Block_Adminhtml_Template
45
+ {
46
+ /**
47
+ * @var string
48
+ */
49
+ protected $_eventPrefix = 'postnl_adminhtml_sales_order_productoptions';
50
+
51
  /**
52
  * Get available product options
53
+ *
54
  * @return array
55
  */
56
  public function getExtraCoverProductOptions()
57
  {
58
+ if ($this->hasExtraCoverProductOptions()) {
59
+ return $this->_getData('extra_cover_product_options');
60
  }
61
+
62
  $productOptions = Mage::getModel('postnl_core/system_config_source_allProductOptions')
63
  ->getExtraCoverOptions(true);
64
+
65
  $this->setExtraCoverProductOptions($productOptions);
66
  return $productOptions;
67
  }
68
+
69
  /**
70
  * Get available GlobalPack product option
71
+ *
72
  * @return string
73
  */
74
  public function getGlobalPackProductOption()
75
  {
76
+ if ($this->hasGlobalpackProductOption()) {
77
+ return $this->_getData('globalpack_product_option');
78
  }
79
+
80
  $globalPackProductOption = Mage::getModel('postnl_core/system_config_source_globalProductOptions')
81
  ->getAvailableOptions();
82
+
83
  if (empty($globalPackProductOption)) {
84
  return '';
85
  }
86
+
87
  $optionValue = $globalPackProductOption[0]['value'];
88
  $this->setGlobalpackProductOption($optionValue);
89
  return $optionValue;
90
  }
91
+
92
  /**
93
  * Gets an array of shipment types for use with GlobalPack shipments
94
+ *
95
  * @return array
96
  */
97
  public function getShipmentTypes()
98
  {
99
  $shipmentTypes = Mage::helper('postnl/cif')->getShipmentTypes();
100
+
101
  return $shipmentTypes;
102
  }
103
+
104
  /**
105
  * Check if the PostNL module is enabled before rendering
106
+ *
107
  * @return string | parent::_toHtml()
108
+ *
109
  * @see Mage_Adminhtml_Block_Abstract::_toHtml()
110
  */
111
  protected function _toHtml()
112
+ {
113
+ if (!Mage::helper('postnl')->isEnabled()) {
114
+ return '';
115
  }
116
+
117
  return parent::_toHtml();
118
  }
119
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/Create/ShipmentOptions.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,14 +33,19 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions extends Mage_Adminhtml_Block_Abstract
40
  {
 
 
 
 
 
41
  /**
42
  * Get current shipment
43
- *
44
  * @return Mage_Sales_Model_Order_Shipment
45
  */
46
  public function getShipment()
@@ -48,16 +53,16 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
48
  if ($this->getData('shipment')) {
49
  return $this->getData('shipment');
50
  }
51
-
52
- $shipment = Mage::registry('current_shipment');
53
-
54
  $this->setShipment($shipment);
55
  return $shipment;
56
  }
57
-
58
  /**
59
  * Get available product options for the current shipment
60
- *
61
  * @return array
62
  */
63
  public function getProductOptions()
@@ -65,18 +70,18 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
65
  if ($this->getData('product_options')) {
66
  return $this->getData('product_options');
67
  }
68
-
69
  $shipment = $this->getShipment();
70
-
71
  $productOptions = Mage::helper('postnl/cif')->getProductOptionsForShipment($shipment);
72
-
73
  $this->setProductOptions($productOptions);
74
  return $productOptions;
75
  }
76
-
77
  /**
78
  * Get the default product option for the current shipment
79
- *
80
  * @return string
81
  */
82
  public function getDefaultProductOption()
@@ -84,30 +89,30 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
84
  if ($this->getData('default_product_option')) {
85
  return $this->getData('default_product_option');
86
  }
87
-
88
  $shipment = $this->getShipment();
89
-
90
  $productOption = Mage::helper('postnl/cif')->getDefaultProductOptionForShipment($shipment);
91
-
92
  $this->setDefaultProductOption($productOption);
93
  return $productOption;
94
  }
95
-
96
  /**
97
  * Gets an array of shipment types for use with GlobalPack shipments
98
- *
99
  * @return array
100
  */
101
  public function getShipmentTypes()
102
  {
103
  $shipmentTypes = Mage::helper('postnl/cif')->getShipmentTypes();
104
-
105
  return $shipmentTypes;
106
  }
107
-
108
  /**
109
  * Check if the current shipment is belgian
110
- *
111
  * @return boolean
112
  */
113
  public function isBelgium()
@@ -116,48 +121,48 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
116
  if ($shipment->getShippingAddress()->getCountry() == 'BE') {
117
  return true;
118
  }
119
-
120
  return false;
121
  }
122
-
123
  /**
124
  * Gets the number of parcels in this shipment based on it's weight
125
- *
126
  * @return int
127
  */
128
  public function getParcelCount()
129
  {
130
  $shipment = $this->getShipment();
131
-
132
  $parcelCount = Mage::helper('postnl/cif')->getParcelCount($shipment);
133
  return $parcelCount;
134
  }
135
-
136
  /**
137
  * Do a few checks to see if the template should be rendered before actually rendering it
138
- *
139
  * @return string | parent::_toHtml()
140
- *
141
  * @see Mage_Adminhtml_Block_Abstract::_toHtml()
142
  */
143
  protected function _toHtml()
144
  {
145
  $helper = Mage::helper('postnl');
146
- if (!$helper->isEnabled()) {
147
- return '';
148
- }
149
-
150
  $shipment = $this->getShipment();
151
-
152
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
153
- if (!in_array($shipment->getOrder()->getShippingMethod(), $postnlShippingMethods)) {
154
- return '';
155
  }
156
-
157
  if (Mage::helper('postnl/cif')->isGlobalShipment($shipment) && !$helper->isGlobalAllowed()) {
158
  return '';
159
  }
160
-
161
  return parent::_toHtml();
162
  }
163
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions extends TIG_PostNL_Block_Adminhtml_Template
40
  {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_adminhtml_sales_order_shipment_create_shipmentoptions';
45
+
46
  /**
47
  * Get current shipment
48
+ *
49
  * @return Mage_Sales_Model_Order_Shipment
50
  */
51
  public function getShipment()
53
  if ($this->getData('shipment')) {
54
  return $this->getData('shipment');
55
  }
56
+
57
+ $shipment = Mage::registry('current_shipment');
58
+
59
  $this->setShipment($shipment);
60
  return $shipment;
61
  }
62
+
63
  /**
64
  * Get available product options for the current shipment
65
+ *
66
  * @return array
67
  */
68
  public function getProductOptions()
70
  if ($this->getData('product_options')) {
71
  return $this->getData('product_options');
72
  }
73
+
74
  $shipment = $this->getShipment();
75
+
76
  $productOptions = Mage::helper('postnl/cif')->getProductOptionsForShipment($shipment);
77
+
78
  $this->setProductOptions($productOptions);
79
  return $productOptions;
80
  }
81
+
82
  /**
83
  * Get the default product option for the current shipment
84
+ *
85
  * @return string
86
  */
87
  public function getDefaultProductOption()
89
  if ($this->getData('default_product_option')) {
90
  return $this->getData('default_product_option');
91
  }
92
+
93
  $shipment = $this->getShipment();
94
+
95
  $productOption = Mage::helper('postnl/cif')->getDefaultProductOptionForShipment($shipment);
96
+
97
  $this->setDefaultProductOption($productOption);
98
  return $productOption;
99
  }
100
+
101
  /**
102
  * Gets an array of shipment types for use with GlobalPack shipments
103
+ *
104
  * @return array
105
  */
106
  public function getShipmentTypes()
107
  {
108
  $shipmentTypes = Mage::helper('postnl/cif')->getShipmentTypes();
109
+
110
  return $shipmentTypes;
111
  }
112
+
113
  /**
114
  * Check if the current shipment is belgian
115
+ *
116
  * @return boolean
117
  */
118
  public function isBelgium()
121
  if ($shipment->getShippingAddress()->getCountry() == 'BE') {
122
  return true;
123
  }
124
+
125
  return false;
126
  }
127
+
128
  /**
129
  * Gets the number of parcels in this shipment based on it's weight
130
+ *
131
  * @return int
132
  */
133
  public function getParcelCount()
134
  {
135
  $shipment = $this->getShipment();
136
+
137
  $parcelCount = Mage::helper('postnl/cif')->getParcelCount($shipment);
138
  return $parcelCount;
139
  }
140
+
141
  /**
142
  * Do a few checks to see if the template should be rendered before actually rendering it
143
+ *
144
  * @return string | parent::_toHtml()
145
+ *
146
  * @see Mage_Adminhtml_Block_Abstract::_toHtml()
147
  */
148
  protected function _toHtml()
149
  {
150
  $helper = Mage::helper('postnl');
151
+ if (!$helper->isEnabled()) {
152
+ return '';
153
+ }
154
+
155
  $shipment = $this->getShipment();
156
+
157
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
158
+ if (!in_array($shipment->getOrder()->getShippingMethod(), $postnlShippingMethods)) {
159
+ return '';
160
  }
161
+
162
  if (Mage::helper('postnl/cif')->isGlobalShipment($shipment) && !$helper->isGlobalAllowed()) {
163
  return '';
164
  }
165
+
166
  return parent::_toHtml();
167
  }
168
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/ShippingStatus.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,32 +33,37 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_ShippingStatus extends Mage_Core_Block_Template
40
- {
41
- /**
 
 
 
 
 
42
  * Available status classes for the status bar html element
43
- */
44
  const CLASS_UNCONFIRMED = '';
45
  const CLASS_COLLECTION = 'status-collection';
46
  const CLASS_DISTRIBUTION = 'status-distribution';
47
  const CLASS_TRANSIT = 'status-transit';
48
  const CLASS_DELIVERED = 'status-delivered';
49
  const CLASS_NOT_POSTNL = 'hidden';
50
-
51
  /**
52
  * Get the current shipping status for a shipment
53
- *
54
  * @param Mage_Sales_Model_Order_Shipment $shipment
55
- *
56
  * @return string
57
  */
58
  public function getShippingStatus($shipment)
59
  {
60
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
61
-
62
  /**
63
  * Check if the postnl shipment exists. Otherwise it was probably not shipped using PostNL.
64
  * Even if it was, we would not be able to check the status of it anyway.
@@ -66,18 +71,18 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_ShippingStatus extend
66
  if (!$postnlShipment->getId()) {
67
  return self::CLASS_NOT_POSTNL;
68
  }
69
-
70
  switch ($postnlShipment->getShippingPhase()) {
71
- case 1:
72
  $class = self::CLASS_COLLECTION;
73
  break;
74
- case 2:
75
  $class = self::CLASS_DISTRIBUTION;
76
  break;
77
- case 3:
78
  $class = self::CLASS_TRANSIT;
79
  break;
80
- case 4:
81
  $class = self::CLASS_DELIVERED;
82
  break;
83
  default:
@@ -86,27 +91,30 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_ShippingStatus extend
86
  }
87
  return $class;
88
  }
89
-
90
  /**
91
  * Checks if a given shipment has been confirmed with PostNL
92
- *
93
  * @param Mage_Sales_Model_Order_Shipment
94
- *
95
  * @return boolean
96
  */
97
  public function isConfirmed($shipment)
98
  {
 
 
 
99
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
100
  if ($postnlShipment->getConfirmStatus() == $postnlShipment::CONFIRM_STATUS_CONFIRMED) {
101
  return true;
102
  }
103
-
104
  return false;
105
  }
106
-
107
  /**
108
  * Check if the PostNL module is enabled. Otherwise return an empty string.
109
- *
110
  * @return string | Mage_Core_Block_Template::_toHtml()
111
  */
112
  protected function _toHtml()
@@ -114,7 +122,7 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_ShippingStatus extend
114
  if (!Mage::helper('postnl')->isEnabled()) {
115
  return '';
116
  }
117
-
118
  return parent::_toHtml();
119
  }
120
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_ShippingStatus extends TIG_PostNL_Block_Adminhtml_Template
40
+ {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_adminhtml_sales_order_shipment_view_shippingstatus';
45
+
46
+ /**
47
  * Available status classes for the status bar html element
48
+ */
49
  const CLASS_UNCONFIRMED = '';
50
  const CLASS_COLLECTION = 'status-collection';
51
  const CLASS_DISTRIBUTION = 'status-distribution';
52
  const CLASS_TRANSIT = 'status-transit';
53
  const CLASS_DELIVERED = 'status-delivered';
54
  const CLASS_NOT_POSTNL = 'hidden';
55
+
56
  /**
57
  * Get the current shipping status for a shipment
58
+ *
59
  * @param Mage_Sales_Model_Order_Shipment $shipment
60
+ *
61
  * @return string
62
  */
63
  public function getShippingStatus($shipment)
64
  {
65
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
66
+
67
  /**
68
  * Check if the postnl shipment exists. Otherwise it was probably not shipped using PostNL.
69
  * Even if it was, we would not be able to check the status of it anyway.
71
  if (!$postnlShipment->getId()) {
72
  return self::CLASS_NOT_POSTNL;
73
  }
74
+
75
  switch ($postnlShipment->getShippingPhase()) {
76
+ case 1:
77
  $class = self::CLASS_COLLECTION;
78
  break;
79
+ case 2:
80
  $class = self::CLASS_DISTRIBUTION;
81
  break;
82
+ case 3:
83
  $class = self::CLASS_TRANSIT;
84
  break;
85
+ case 4:
86
  $class = self::CLASS_DELIVERED;
87
  break;
88
  default:
91
  }
92
  return $class;
93
  }
94
+
95
  /**
96
  * Checks if a given shipment has been confirmed with PostNL
97
+ *
98
  * @param Mage_Sales_Model_Order_Shipment
99
+ *
100
  * @return boolean
101
  */
102
  public function isConfirmed($shipment)
103
  {
104
+ /**
105
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipment
106
+ */
107
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
108
  if ($postnlShipment->getConfirmStatus() == $postnlShipment::CONFIRM_STATUS_CONFIRMED) {
109
  return true;
110
  }
111
+
112
  return false;
113
  }
114
+
115
  /**
116
  * Check if the PostNL module is enabled. Otherwise return an empty string.
117
+ *
118
  * @return string | Mage_Core_Block_Template::_toHtml()
119
  */
120
  protected function _toHtml()
122
  if (!Mage::helper('postnl')->isEnabled()) {
123
  return '';
124
  }
125
+
126
  return parent::_toHtml();
127
  }
128
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tab/StatusHistory.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,22 +33,22 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory extends Mage_Adminhtml_Block_Widget_Grid
40
  {
41
  /**
42
  * Class constructor
43
- *
44
  * @return TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory
45
- *
46
  * @see Mage_Adminhtml_Block_Widget_Grid::__construct()
47
  */
48
  public function __construct()
49
  {
50
  parent::__construct();
51
-
52
  /**
53
  * Set some base variables for this grid
54
  */
@@ -57,44 +57,44 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory ext
57
  $this->setDefaultSort('timestamp');
58
  $this->setDefaultDir('DESC');
59
  $this->setUseAjax(true);
60
-
61
  $postnlShipment = Mage::registry('current_postnl_shipment');
62
  $this->setPostnlShipment($postnlShipment);
63
-
64
  return $this;
65
  }
66
-
67
  /**
68
  * Get the basic collection for this grid
69
- *
70
  * @return TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory
71
- *
72
  * @see Mage_Adminhtml_Block_Widget_Grid::_prepareCollection
73
  */
74
  protected function _prepareCollection()
75
  {
76
  $postnlShipmentId = $this->getPostnlShipment()->getId();
77
-
78
  $collection = Mage::getResourceModel('postnl_core/shipment_status_history_collection');
79
  $collection->addFieldToFilter('parent_id', array('eq' => $postnlShipmentId));
80
-
81
  $this->setCollection($collection);
82
 
83
  parent::_prepareCollection();
84
  return $this;
85
  }
86
-
87
  /**
88
  * Prepares the grid's columns for rendering
89
- *
90
  * @return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns
91
- *
92
  * @see Mage_Adminhtml_Block_Widget_Grid::addColumn()
93
  */
94
  protected function _prepareColumns()
95
  {
96
  $helper = Mage::helper('postnl');
97
-
98
  $this->addColumn('date',
99
  array(
100
  'header' => $helper->__('Date'),
@@ -105,7 +105,7 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory ext
105
  'renderer' => 'adminhtml/widget_grid_column_renderer_date',
106
  'filter_time' => true,
107
  ));
108
-
109
  $this->addColumn('timestamp',
110
  array(
111
  'header' => $helper->__('Time'),
@@ -116,14 +116,14 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory ext
116
  'filter' => false,
117
  'sortable' => false,
118
  ));
119
-
120
  $this->addColumn('code',
121
  array(
122
  'header' => $helper->__('Status Code'),
123
  'index' => 'code',
124
  'width' => '100px',
125
  ));
126
-
127
  $this->addColumn('description',
128
  array(
129
  'header' => $helper->__('Description'),
@@ -134,23 +134,23 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory ext
134
 
135
  return parent::_prepareColumns();
136
  }
137
-
138
  /**
139
- * Gets a link to this shipment's mijnpakket page as the grid's header.
140
- *
141
- * @return string
142
  */
143
  public function getGridHeader()
144
  {
145
  $helper = Mage::helper('postnl');
146
-
147
  $postnlShipment = $this->getPostnlShipment();
148
  $url = $postnlShipment->getBarcodeUrl();
149
-
150
  $urlTitle = $helper->__('Mijnpakket');
151
  $urlText = $helper->__('View this shipment in mijnpakket');
152
  $html = "<a href='{$url}' title='{$urlTitle}' target='_blank'>{$urlText}</a>";
153
-
154
  return $html;
155
  }
156
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory extends Mage_Adminhtml_Block_Widget_Grid
40
  {
41
  /**
42
  * Class constructor
43
+ *
44
  * @return TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory
45
+ *
46
  * @see Mage_Adminhtml_Block_Widget_Grid::__construct()
47
  */
48
  public function __construct()
49
  {
50
  parent::__construct();
51
+
52
  /**
53
  * Set some base variables for this grid
54
  */
57
  $this->setDefaultSort('timestamp');
58
  $this->setDefaultDir('DESC');
59
  $this->setUseAjax(true);
60
+
61
  $postnlShipment = Mage::registry('current_postnl_shipment');
62
  $this->setPostnlShipment($postnlShipment);
63
+
64
  return $this;
65
  }
66
+
67
  /**
68
  * Get the basic collection for this grid
69
+ *
70
  * @return TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory
71
+ *
72
  * @see Mage_Adminhtml_Block_Widget_Grid::_prepareCollection
73
  */
74
  protected function _prepareCollection()
75
  {
76
  $postnlShipmentId = $this->getPostnlShipment()->getId();
77
+
78
  $collection = Mage::getResourceModel('postnl_core/shipment_status_history_collection');
79
  $collection->addFieldToFilter('parent_id', array('eq' => $postnlShipmentId));
80
+
81
  $this->setCollection($collection);
82
 
83
  parent::_prepareCollection();
84
  return $this;
85
  }
86
+
87
  /**
88
  * Prepares the grid's columns for rendering
89
+ *
90
  * @return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns
91
+ *
92
  * @see Mage_Adminhtml_Block_Widget_Grid::addColumn()
93
  */
94
  protected function _prepareColumns()
95
  {
96
  $helper = Mage::helper('postnl');
97
+
98
  $this->addColumn('date',
99
  array(
100
  'header' => $helper->__('Date'),
105
  'renderer' => 'adminhtml/widget_grid_column_renderer_date',
106
  'filter_time' => true,
107
  ));
108
+
109
  $this->addColumn('timestamp',
110
  array(
111
  'header' => $helper->__('Time'),
116
  'filter' => false,
117
  'sortable' => false,
118
  ));
119
+
120
  $this->addColumn('code',
121
  array(
122
  'header' => $helper->__('Status Code'),
123
  'index' => 'code',
124
  'width' => '100px',
125
  ));
126
+
127
  $this->addColumn('description',
128
  array(
129
  'header' => $helper->__('Description'),
134
 
135
  return parent::_prepareColumns();
136
  }
137
+
138
  /**
139
+ * Gets a link to this shipment's MijnPakket page as the grid's header.
140
+ *
141
+ * @return string
142
  */
143
  public function getGridHeader()
144
  {
145
  $helper = Mage::helper('postnl');
146
+
147
  $postnlShipment = $this->getPostnlShipment();
148
  $url = $postnlShipment->getBarcodeUrl();
149
+
150
  $urlTitle = $helper->__('Mijnpakket');
151
  $urlText = $helper->__('View this shipment in mijnpakket');
152
  $html = "<a href='{$url}' title='{$urlTitle}' target='_blank'>{$urlText}</a>";
153
+
154
  return $html;
155
  }
156
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tabs.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,17 +33,16 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
40
  {
41
  /**
42
  * Constructor for the tabs container
43
- *
44
- * @return null
45
- *
46
- * @see Mage_Adminhtml_Block_Widget_Tabs::__construct()
47
  */
48
  public function __construct()
49
  {
@@ -52,16 +51,17 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tabs extends Mage_Adm
52
  $this->setDestElementId('sales_order_shipment_view');
53
  $this->setTitle(Mage::helper('sales')->__('Shipment View'));
54
  }
55
-
56
  /**
57
  * Add the main tabs to the page. Layout XML may be used to add more if desired
58
- *
59
  * @return Mage_Adminhtml_Block_Widget_Tabs::_prepareLayout()
60
  */
61
  protected function _prepareLayout()
62
  {
63
  /**
64
- * Add the 'information' tab. this contains all default features of the shipment view page and is selected by default
 
65
  */
66
  $this->addTab('shipment_info', array(
67
  'label' => Mage::helper('sales')->__('Information'),
@@ -69,33 +69,35 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tabs extends Mage_Adm
69
  ->getBlock('form')
70
  ->toHtml(),
71
  ));
72
-
73
  /**
74
  * Get the current shipment's ID and attempt to load a corresponding postnl shipment
75
  */
76
  $shipmentId = Mage::registry('current_shipment')->getId();
77
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipmentId, 'shipment_id');
78
-
79
  /**
80
- * Only show the status history tab if a postnl shipment entity was found for the current shipment
 
81
  */
82
- if ($postnlShipment->getId()) {
 
83
  /**
84
  * Add the status history tab. This is added by PostNL
85
  */
86
  $this->addTab('shipment_status_history', array(
87
  'label' => Mage::helper('postnl')->__('Shipping event history'),
88
  'url' => $this->getUrl(
89
- 'postnl/adminhtml_shipment/statusHistory',
90
  array(
91
- '_current' => true,
92
  'shipment_id' => $shipmentId
93
  )
94
  ),
95
  'class' => 'ajax',
96
  ));
97
  }
98
-
99
  return parent::_prepareLayout();
100
  }
101
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
40
  {
41
  /**
42
  * Constructor for the tabs container
43
+ *
44
+ * @return \TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tabs
45
+ @see Mage_Adminhtml_Block_Widget_Tabs::__construct()
 
46
  */
47
  public function __construct()
48
  {
51
  $this->setDestElementId('sales_order_shipment_view');
52
  $this->setTitle(Mage::helper('sales')->__('Shipment View'));
53
  }
54
+
55
  /**
56
  * Add the main tabs to the page. Layout XML may be used to add more if desired
57
+ *
58
  * @return Mage_Adminhtml_Block_Widget_Tabs::_prepareLayout()
59
  */
60
  protected function _prepareLayout()
61
  {
62
  /**
63
+ * Add the 'information' tab. this contains all default features of the shipment view page and is selected by
64
+ * default.
65
  */
66
  $this->addTab('shipment_info', array(
67
  'label' => Mage::helper('sales')->__('Information'),
69
  ->getBlock('form')
70
  ->toHtml(),
71
  ));
72
+
73
  /**
74
  * Get the current shipment's ID and attempt to load a corresponding postnl shipment
75
  */
76
  $shipmentId = Mage::registry('current_shipment')->getId();
77
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipmentId, 'shipment_id');
78
+
79
  /**
80
+ * Only show the status history tab if a postnl shipment entity was found for the current shipment and the
81
+ * current admin user is allowed to view the complete shipment status history.
82
  */
83
+ $historyAllowed = Mage::helper('postnl')->checkIsPostnlActionAllowed('view_complete_status');
84
+ if ($historyAllowed && $postnlShipment->getId()) {
85
  /**
86
  * Add the status history tab. This is added by PostNL
87
  */
88
  $this->addTab('shipment_status_history', array(
89
  'label' => Mage::helper('postnl')->__('Shipping event history'),
90
  'url' => $this->getUrl(
91
+ 'postnl_admin/adminhtml_shipment/statusHistory',
92
  array(
93
+ '_current' => true,
94
  'shipment_id' => $shipmentId
95
  )
96
  ),
97
  'class' => 'ajax',
98
  ));
99
  }
100
+
101
  return parent::_prepareLayout();
102
  }
103
  }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,33 +33,50 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
38
  */
39
  class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block_System_Config_Form
40
  {
41
  /**
42
- * For Magento versions below these versions we need to execute some special backwards compatgibility code.
43
  */
44
  const MINIMUM_VERSION_COMPATIBILITY = '1.7.0.0';
45
  const MINIMUM_ENTERPRISE_VERSION_COMPATIBILITY = '1.12.0.0';
46
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  /**
48
  * Creates the system > config > edit form for the PostNL section.
49
- *
50
- * The only reason we have a custom form, rather than the default Adminhtml form is because the default form doesn't allow
51
- * for 'forwards' field dependency.
52
- *
53
- * Due to the way the form is initialized, each fieldset is initialized with it's fields in order. Due to this order a field
54
  * can only depend on a field that is in the same fieldset or in a fieldset that is already initialized. An example:
55
  * We have fieldset_a containing field_a. We also have fieldset_b containing field_b. If field_a depends on field_b, this
56
- * is not possible. When field_a is initialized, fieldset_b and therefore field_b, will not yet have been initialized and
57
  * will not be available.
58
- *
59
  * We have split the initialization of fieldsets and fields. This way Magento will first initialize all fieldsets and then
60
  * init all fields. So when field_a is initialized, fieldset_b is already available and the dependency will work.
61
  *
62
- * @return TIG_PostNL_Block_Adminhtml_System_Config_Edit_Form
63
  */
64
  public function initForm()
65
  {
@@ -91,7 +108,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
91
  }
92
  $this->_initGroup($form, $group, $section);
93
  }
94
-
95
  /*************************
96
  * This part is new
97
  ************************/
@@ -99,7 +116,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
99
  if (!isset($this->_fieldsets[$group->getName()])) {
100
  continue;
101
  }
102
-
103
  $fieldset = $this->_fieldsets[$group->getName()];
104
  $this->initFields($fieldset, $group, $section);
105
  }
@@ -113,11 +130,13 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
113
  /**
114
  * Init config group
115
  *
116
- * @param Varien_Data_Form $form
117
- * @param Varien_Simplexml_Element $group
118
- * @param Varien_Simplexml_Element $section
119
  * @param Varien_Data_Form_Element_Fieldset|null $parentElement
120
- *
 
 
121
  * @return void
122
  */
123
  protected function _initGroup($form, $group, $section, $parentElement = null)
@@ -127,7 +146,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
127
  } else {
128
  $fieldsetRenderer = $this->_defaultFieldsetRenderer;
129
  }
130
-
131
  $fieldsetRenderer->setForm($this)
132
  ->setConfigData($this->_configData);
133
 
@@ -141,6 +160,14 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
141
  $fieldsetConfig['expanded'] = (bool)$group->expanded;
142
  }
143
 
 
 
 
 
 
 
 
 
144
  $fieldset = new Varien_Data_Form_Element_Fieldset($fieldsetConfig);
145
  $fieldset->setId($section->getName() . '_' . $group->getName())
146
  ->setRenderer($fieldsetRenderer)
@@ -178,16 +205,16 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
178
  }
179
 
180
  /**
181
- * Init fieldset fields. Copied from EE1.13 Mage_Adminhtml_Block_System_Config_Form::initFields to allow for cross-fieldset
182
- * dependencies in CE 1.6. Only made a small change to core code for backwards compatibility.
183
  *
184
  * @param Varien_Data_Form_Element_Fieldset $fieldset
185
- * @param Varien_Simplexml_Element $group
186
- * @param Varien_Simplexml_Element $section
187
- * @param string $fieldPrefix
188
- * @param string $labelPrefix
189
- *
190
- * @return Mage_Adminhtml_Block_System_Config_Form
191
  */
192
  public function initFields($fieldset, $group, $section, $fieldPrefix='', $labelPrefix='')
193
  {
@@ -240,19 +267,29 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
240
  }
241
 
242
  $data = $this->_configDataObject->getConfigDataValue($path, $inherit, $this->_configData);
243
-
244
  /**
245
- * Because Magento 1.6 and 1.11 retrieved config data in a different manner, we need to provide backwards
246
- * compatibility for those versions.
247
  */
 
248
  $isEnterprise = Mage::helper('postnl')->isEnterprise();
249
- if (!$data
250
- && (
251
- ($isEnterprise
252
- && version_compare(Mage::getVersion(), self::MINIMUM_ENTERPRISE_VERSION_COMPATIBILITY, '<') === true)
253
- || (version_compare(Mage::getVersion(), self::MINIMUM_VERSION_COMPATIBILITY, '<') === true)
254
- )
255
- ) {
 
 
 
 
 
 
 
 
 
256
  if (isset($this->_configData[$path])) {
257
  $data = $this->_configData[$path];
258
  $inherit = false;
@@ -261,7 +298,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
261
  $inherit = true;
262
  }
263
  }
264
-
265
  if ($element->frontend_model) {
266
  $fieldRenderer = Mage::getBlockSingleton((string)$element->frontend_model);
267
  } else {
@@ -375,8 +412,8 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
375
  'scope' => $this->getScope(),
376
  'scope_id' => $this->getScopeId(),
377
  'scope_label' => $this->getScopeLabel($element),
378
- 'can_use_default_value' => $this->canUseDefaultValue((int)$element->show_in_default),
379
- 'can_use_website_value' => $this->canUseWebsiteValue((int)$element->show_in_website),
380
  ));
381
  $this->_prepareFieldOriginalData($field, $element);
382
 
@@ -384,6 +421,10 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
384
  $field->addClass($element->validate);
385
  }
386
 
 
 
 
 
387
  if (isset($element->frontend_type)
388
  && 'multiselect' === (string)$element->frontend_type
389
  && isset($element->can_be_empty)
@@ -407,7 +448,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
407
  $sourceModel->setPath($path);
408
  }
409
  if ($method) {
410
- if ($fieldType == 'multiselect') {
411
  $optionArray = $sourceModel->$method();
412
  } else {
413
  $optionArray = array();
@@ -422,6 +463,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
422
  }
423
  }
424
  }
 
425
  return $this;
426
  }
427
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasFieldsetParam()
40
+ * @method TIG_PostNL_Block_Adminhtml_System_Config_Form setFieldsetParam(string $value)
41
  */
42
  class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block_System_Config_Form
43
  {
44
  /**
45
+ * For Magento versions below these versions we need to execute some special backwards compatibility code.
46
  */
47
  const MINIMUM_VERSION_COMPATIBILITY = '1.7.0.0';
48
  const MINIMUM_ENTERPRISE_VERSION_COMPATIBILITY = '1.12.0.0';
49
+
50
+ /**
51
+ * Gets the fieldset parameter from the GET superglobal if available.
52
+ *
53
+ * @return null|string
54
+ */
55
+ public function getFieldsetParam()
56
+ {
57
+ if ($this->hasFieldsetParam()) {
58
+ return $this->getData('fieldset_param');
59
+ }
60
+
61
+ $fieldsetparam = Mage::app()->getRequest()->getParam('fieldset');
62
+
63
+ $this->setFieldsetParam($fieldsetparam);
64
+ return $fieldsetparam;
65
+ }
66
+
67
  /**
68
  * Creates the system > config > edit form for the PostNL section.
69
+ *
70
+ * Due to the way the form is initialized, each fieldset is initialized with it's fields in order. Due to this order a field
 
 
 
71
  * can only depend on a field that is in the same fieldset or in a fieldset that is already initialized. An example:
72
  * We have fieldset_a containing field_a. We also have fieldset_b containing field_b. If field_a depends on field_b, this
73
+ * is not possible. When field_a is initialized, fieldset_b and therefore field_b, will not yet have been initialized and
74
  * will not be available.
75
+ *
76
  * We have split the initialization of fieldsets and fields. This way Magento will first initialize all fieldsets and then
77
  * init all fields. So when field_a is initialized, fieldset_b is already available and the dependency will work.
78
  *
79
+ * @return TIG_PostNL_Block_Adminhtml_System_Config_Form
80
  */
81
  public function initForm()
82
  {
108
  }
109
  $this->_initGroup($form, $group, $section);
110
  }
111
+
112
  /*************************
113
  * This part is new
114
  ************************/
116
  if (!isset($this->_fieldsets[$group->getName()])) {
117
  continue;
118
  }
119
+
120
  $fieldset = $this->_fieldsets[$group->getName()];
121
  $this->initFields($fieldset, $group, $section);
122
  }
130
  /**
131
  * Init config group
132
  *
133
+ * @param Varien_Data_Form $form
134
+ * @param Varien_Simplexml_Element $group
135
+ * @param Varien_Simplexml_Element $section
136
  * @param Varien_Data_Form_Element_Fieldset|null $parentElement
137
+ *
138
+ * @throws TIG_PostNL_Exception
139
+ *
140
  * @return void
141
  */
142
  protected function _initGroup($form, $group, $section, $parentElement = null)
146
  } else {
147
  $fieldsetRenderer = $this->_defaultFieldsetRenderer;
148
  }
149
+
150
  $fieldsetRenderer->setForm($this)
151
  ->setConfigData($this->_configData);
152
 
160
  $fieldsetConfig['expanded'] = (bool)$group->expanded;
161
  }
162
 
163
+ /**
164
+ * Added support for a 'fieldset' URL parameter that forces a certain fieldset to the expanded state.
165
+ */
166
+ $fieldsetParam = $this->getFieldsetParam();
167
+ if ($fieldsetParam && $fieldsetParam == $group->getName()) {
168
+ $fieldsetConfig['expanded'] = true;
169
+ }
170
+
171
  $fieldset = new Varien_Data_Form_Element_Fieldset($fieldsetConfig);
172
  $fieldset->setId($section->getName() . '_' . $group->getName())
173
  ->setRenderer($fieldsetRenderer)
205
  }
206
 
207
  /**
208
+ * Init fieldset fields. Copied from EE1.13 Mage_Adminhtml_Block_System_Config_Form::initFields to allow for
209
+ * cross-fieldset dependencies in CE 1.6. Only made a small change to core code for backwards compatibility.
210
  *
211
  * @param Varien_Data_Form_Element_Fieldset $fieldset
212
+ * @param Varien_Simplexml_Element $group
213
+ * @param Varien_Simplexml_Element $section
214
+ * @param string $fieldPrefix
215
+ * @param string $labelPrefix
216
+ *
217
+ * @return $this
218
  */
219
  public function initFields($fieldset, $group, $section, $fieldPrefix='', $labelPrefix='')
220
  {
267
  }
268
 
269
  $data = $this->_configDataObject->getConfigDataValue($path, $inherit, $this->_configData);
270
+
271
  /**
272
+ * Because Magento 1.6 and 1.11 retrieved config data in a different manner, we need to provide
273
+ * backwards compatibility for those versions.
274
  */
275
+ $version = Mage::getVersion();
276
  $isEnterprise = Mage::helper('postnl')->isEnterprise();
277
+
278
+ /**
279
+ * Get the minimum version requirement for the current Magento edition.
280
+ */
281
+ if($isEnterprise) {
282
+ $minimumVersion = self::MINIMUM_ENTERPRISE_VERSION_COMPATIBILITY;
283
+ } else {
284
+ $minimumVersion = self::MINIMUM_VERSION_COMPATIBILITY;
285
+ }
286
+
287
+ /**
288
+ * Check if the current version is below the minimum version requirement.
289
+ */
290
+ $isBelowMinimumVersion = version_compare($version, $minimumVersion, '<');
291
+
292
+ if (!$data && $isBelowMinimumVersion === true) {
293
  if (isset($this->_configData[$path])) {
294
  $data = $this->_configData[$path];
295
  $inherit = false;
298
  $inherit = true;
299
  }
300
  }
301
+
302
  if ($element->frontend_model) {
303
  $fieldRenderer = Mage::getBlockSingleton((string)$element->frontend_model);
304
  } else {
412
  'scope' => $this->getScope(),
413
  'scope_id' => $this->getScopeId(),
414
  'scope_label' => $this->getScopeLabel($element),
415
+ 'can_use_default_value' => $this->canUseDefaultValue($element),
416
+ 'can_use_website_value' => $this->canUseWebsiteValue($element),
417
  ));
418
  $this->_prepareFieldOriginalData($field, $element);
419
 
421
  $field->addClass($element->validate);
422
  }
423
 
424
+ if (isset($element->autocomplete)) {
425
+ $field->setAutocomplete($element->autocomplete);
426
+ }
427
+
428
  if (isset($element->frontend_type)
429
  && 'multiselect' === (string)$element->frontend_type
430
  && isset($element->can_be_empty)
448
  $sourceModel->setPath($path);
449
  }
450
  if ($method) {
451
+ if ($fieldType == 'multiselect' || $element->multidimensional) {
452
  $optionArray = $sourceModel->$method();
453
  } else {
454
  $optionArray = array();
463
  }
464
  }
465
  }
466
+
467
  return $this;
468
  }
469
  }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ActivateButton.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,8 +33,10 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
38
  */
39
  class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivateButton
40
  extends Mage_Adminhtml_Block_System_Config_Form_Field
@@ -44,25 +46,25 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivateButton
44
  * XML path to 'is_activated' flag
45
  */
46
  const XML_PATH_IS_ACTIVATED = 'postnl/general/is_activated';
47
-
48
  /**
49
  * Gets the element's html. In this case: a button redirecting the user to the extensionControl controller
50
- *
 
 
51
  * @return string
52
  */
53
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
54
  {
55
  $this->setElement($element);
56
-
57
- $url = $this->getUrl('postnl/adminhtml_extensionControl/activate');
58
-
59
  $isActivated = Mage::getStoreConfig(self::XML_PATH_IS_ACTIVATED, Mage_Core_Model_App::ADMIN_STORE_ID);
60
  if ($isActivated === '1') {
61
  $label = $this->__('Finish activation');
62
  } else {
63
  $label = $this->__('Activate the extension');
64
  }
65
-
66
  $html = $this->getLayout()->createBlock('adminhtml/widget_button')
67
  ->setId($element->getHtmlId())
68
  ->setType('button')
@@ -73,12 +75,13 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivateButton
73
 
74
  return $html;
75
  }
76
-
77
  /**
78
  * Render the element without a scope label
79
- *
 
80
  * @return string
81
- *
82
  * @see parent::render()
83
  */
84
  public function render(Varien_Data_Form_Element_Abstract $element)
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivateButton setElement(Varien_Data_Form_Element_Abstract $value)
40
  */
41
  class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivateButton
42
  extends Mage_Adminhtml_Block_System_Config_Form_Field
46
  * XML path to 'is_activated' flag
47
  */
48
  const XML_PATH_IS_ACTIVATED = 'postnl/general/is_activated';
49
+
50
  /**
51
  * Gets the element's html. In this case: a button redirecting the user to the extensionControl controller
52
+ *
53
+ * @param Varien_Data_Form_Element_Abstract $element
54
+ *
55
  * @return string
56
  */
57
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
58
  {
59
  $this->setElement($element);
60
+
 
 
61
  $isActivated = Mage::getStoreConfig(self::XML_PATH_IS_ACTIVATED, Mage_Core_Model_App::ADMIN_STORE_ID);
62
  if ($isActivated === '1') {
63
  $label = $this->__('Finish activation');
64
  } else {
65
  $label = $this->__('Activate the extension');
66
  }
67
+
68
  $html = $this->getLayout()->createBlock('adminhtml/widget_button')
69
  ->setId($element->getHtmlId())
70
  ->setType('button')
75
 
76
  return $html;
77
  }
78
+
79
  /**
80
  * Render the element without a scope label
81
+ *
82
+ * @param Varien_Data_Form_Element_Abstract $element
83
  * @return string
84
+ *
85
  * @see parent::render()
86
  */
87
  public function render(Varien_Data_Form_Element_Abstract $element)
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ActivatedFieldHeader.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,21 +33,27 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivatedFieldHeader extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
 
40
  {
 
 
 
 
 
41
  /**
42
  * Template file used
43
- *
44
  * @var string
45
  */
46
  protected $_template = 'TIG/PostNL/system/config/form/field/field_header.phtml';
47
-
48
  /**
49
  * Get the element's label
50
- *
51
  * @return string
52
  */
53
  public function getLabel()
@@ -55,42 +61,42 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivatedFieldHeader e
55
  if (!$this->getElement()) {
56
  return '';
57
  }
58
-
59
  $element = $this->getElement();
60
  $label = $element->getLabel();
61
-
62
  $section = $this->getRequest()->getParam('section');
63
  $website = $this->getRequest()->getParam('website');
64
  $store = $this->getRequest()->getParam('store');
65
-
66
  $urlParams = array(
67
  '_secure' => true,
68
  );
69
-
70
  if ($section) {
71
  $urlParams['section'] = $section;
72
  }
73
-
74
  if ($website) {
75
  $urlParams['website'] = $website;
76
  }
77
-
78
  if ($store) {
79
  $urlParams['store'] = $store;
80
  }
81
-
82
- $url = $this->getUrl('postnl/adminhtml_extensionControl/showActivationFields', $urlParams);
83
- $onclick = "confirmSetLocation('"
84
- . $this->__("Are you sure? The PostNL extension will not function until you\'ve reactivated the extension.")
85
- . "', '"
86
- . $url
87
  . "');";
88
-
89
  $label = sprintf(
90
  $label,
91
  $onclick
92
  );
93
-
94
  return $label;
95
  }
96
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivatedFieldHeader
40
+ extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
41
  {
42
+ /**
43
+ * @var string
44
+ */
45
+ protected $_eventPrefix = 'postnl_adminhtml_system_config_form_field_activatedfieldheader';
46
+
47
  /**
48
  * Template file used
49
+ *
50
  * @var string
51
  */
52
  protected $_template = 'TIG/PostNL/system/config/form/field/field_header.phtml';
53
+
54
  /**
55
  * Get the element's label
56
+ *
57
  * @return string
58
  */
59
  public function getLabel()
61
  if (!$this->getElement()) {
62
  return '';
63
  }
64
+
65
  $element = $this->getElement();
66
  $label = $element->getLabel();
67
+
68
  $section = $this->getRequest()->getParam('section');
69
  $website = $this->getRequest()->getParam('website');
70
  $store = $this->getRequest()->getParam('store');
71
+
72
  $urlParams = array(
73
  '_secure' => true,
74
  );
75
+
76
  if ($section) {
77
  $urlParams['section'] = $section;
78
  }
79
+
80
  if ($website) {
81
  $urlParams['website'] = $website;
82
  }
83
+
84
  if ($store) {
85
  $urlParams['store'] = $store;
86
  }
87
+
88
+ $url = $this->getUrl('postnl_admin/adminhtml_extensionControl/showActivationFields', $urlParams);
89
+ $onclick = "confirmSetLocation('"
90
+ . $this->__("Are you sure? The PostNL extension will not function until you\'ve reactivated the extension.")
91
+ . "', '"
92
+ . $url
93
  . "');";
94
+
95
  $label = sprintf(
96
  $label,
97
  $onclick
98
  );
99
+
100
  return $label;
101
  }
102
  }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/Anchor.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_Anchor
40
+ extends Varien_Data_Form_Element_Link
41
+ implements Varien_Data_Form_Element_Renderer_Interface
42
+ {
43
+ /**
44
+ * Get the element's HTML.
45
+ *
46
+ * @return string
47
+ */
48
+ public function getElementHtml()
49
+ {
50
+ $originalData = $this->getElement()->getOriginalData();
51
+ $anchorName = $originalData['anchor_name'];
52
+
53
+ $html = $this->getBeforeElementHtml();
54
+ $html .= '<a name="' . $anchorName . '"></a>';
55
+ $html .= $this->getAfterElementHtml();
56
+
57
+ return $html;
58
+ }
59
+
60
+ /**
61
+ * Get the element's HTML ID
62
+ *
63
+ * @return string
64
+ */
65
+ public function getHtmlId()
66
+ {
67
+ if (!$this->getElement()) {
68
+ return '';
69
+ }
70
+
71
+ $element = $this->getElement();
72
+ $id = $element->getHtmlId();
73
+
74
+ return $id;
75
+ }
76
+
77
+ /**
78
+ * Render field html
79
+ *
80
+ * @param Varien_Data_Form_Element_Abstract $element
81
+ * @return string
82
+ */
83
+ public function render(Varien_Data_Form_Element_Abstract $element)
84
+ {
85
+ $this->setElement($element);
86
+
87
+ $this->setBeforeElementHtml('<tr id="row_' . $this->getHtmlId() . '"><td colspan="5">');
88
+ $this->setAfterElementHtml('</tr></td>');
89
+
90
+ return $this->getElementHtml();
91
+ }
92
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ConfigCheck.php CHANGED
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  *
39
  * @method boolean hasPostnlHelper()
@@ -42,6 +42,11 @@
42
  class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ConfigCheck
43
  extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
44
  {
 
 
 
 
 
45
  /**
46
  * XML paths to use GlobalPack/Checkout settings
47
  */
@@ -178,13 +183,12 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ConfigCheck
178
  */
179
  public function isCheckoutEnabled()
180
  {
181
- $checkoutEnabled = Mage::getStoreConfigFlag(self::XML_PATH_USE_CHECKOUT, Mage_Core_Model_App::ADMIN_STORE_ID);
182
- if (!$checkoutEnabled) {
 
183
  return true;
184
  }
185
 
186
- $helper = Mage::helper('postnl/checkout');
187
-
188
  return $helper->isCheckoutEnabled(false);
189
  }
190
 
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  *
39
  * @method boolean hasPostnlHelper()
42
  class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ConfigCheck
43
  extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
44
  {
45
+ /**
46
+ * @var string
47
+ */
48
+ protected $_eventPrefix = 'postnl_adminhtml_system_config_form_field_configcheck';
49
+
50
  /**
51
  * XML paths to use GlobalPack/Checkout settings
52
  */
183
  */
184
  public function isCheckoutEnabled()
185
  {
186
+ $helper = Mage::helper('postnl/checkout');
187
+
188
+ if (!$helper->isCheckoutActive()) {
189
  return true;
190
  }
191
 
 
 
192
  return $helper->isCheckoutEnabled(false);
193
  }
194
 
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/InfoBox.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -36,11 +36,17 @@
36
  * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_InfoBox extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
 
40
  {
 
 
 
 
 
41
  /**
42
  * Template file used
43
- *
44
  * @var string
45
  */
46
  protected $_template = 'TIG/PostNL/system/config/form/field/info_box.phtml';
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
36
  * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_InfoBox
40
+ extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
41
  {
42
+ /**
43
+ * @var string
44
+ */
45
+ protected $_eventPrefix = 'postnl_adminhtml_system_config_form_field_infobox';
46
+
47
  /**
48
  * Template file used
49
+ *
50
  * @var string
51
  */
52
  protected $_template = 'TIG/PostNL/system/config/form/field/info_box.phtml';
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/Obscure.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_Obscure
40
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
41
+ {
42
+ /**
43
+ * Gets the element's HTML.
44
+ *
45
+ * @param Varien_Data_Form_Element_Abstract $element
46
+ *
47
+ * @return string
48
+ *
49
+ * @see Varien_Data_Form_Element_Abstract::getElementHtml()
50
+ */
51
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
52
+ {
53
+ $html = '<input id="'
54
+ . $element->getHtmlId()
55
+ . '" name="'
56
+ . $element->getName()
57
+ . '" value="'
58
+ . $element->getEscapedValue()
59
+ . '" '
60
+ . $element->serialize($this->getHtmlAttributes())
61
+ . '/>'
62
+ . "\n"
63
+ . $element->getAfterElementHtml();
64
+
65
+ return $html;
66
+ }
67
+
68
+ /**
69
+ * Gets a list of supported HTML attributes for this element.
70
+ *
71
+ * @return array
72
+ */
73
+ public function getHtmlAttributes()
74
+ {
75
+ $attributes = array(
76
+ 'type',
77
+ 'title',
78
+ 'class',
79
+ 'style',
80
+ 'onclick',
81
+ 'onchange',
82
+ 'disabled',
83
+ 'readonly',
84
+ 'tabindex',
85
+ 'autocomplete',
86
+ );
87
+
88
+ return $attributes;
89
+ }
90
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/SplitAddressCheck.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,26 +33,33 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_SplitAddressCheck extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
 
40
  {
41
  /**
42
- * XML path to split street configuration option
43
  */
44
- const XML_PATH_SPLIT_STREET = 'postnl/cif_address/split_street';
45
-
 
 
 
 
 
 
46
  /**
47
- * Template file used
48
- *
49
  * @var string
50
  */
51
  protected $_template = 'TIG/PostNL/system/config/form/field/split_address_check.phtml';
52
-
53
  /**
54
- * Get if the split_street field is enabled
55
- *
56
  * @return boolean
57
  */
58
  public function getIsAddressSplit()
@@ -63,14 +70,21 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_SplitAddressCheck exte
63
  * Check if the split_street field is enabled based on the current scope
64
  */
65
  if ($request->getParam('store')) {
66
- $splitStreet = (bool) Mage::getStoreConfig(self::XML_PATH_SPLIT_STREET, $request->getparam('store'));
 
67
  } elseif ($request->getParam('website')) {
68
  $website = Mage::getModel('core/website')->load($request->getparam('website'), 'code');
69
- $splitStreet = (bool) $website->getConfig(self::XML_PATH_SPLIT_STREET, $website->getId());
 
70
  } else {
71
- $splitStreet = (bool) Mage::getStoreConfig(self::XML_PATH_SPLIT_STREET, Mage_Core_Model_App::ADMIN_STORE_ID);
 
 
 
 
 
72
  }
73
-
74
- return $splitStreet;
75
  }
76
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_SplitAddressCheck
40
+ extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
41
  {
42
  /**
43
+ * Xpaths to split street configuration options.
44
  */
45
+ const XPATH_SPLIT_STREET = 'postnl/cif_address/split_street';
46
+ const XPATH_USE_POSTCODE_CHECK = 'postnl/cif_address/use_postcode_check';
47
+
48
+ /**
49
+ * @var string
50
+ */
51
+ protected $_eventPrefix = 'postnl_adminhtml_system_config_form_field_splitaddresscheck';
52
+
53
  /**
54
+ * Template file used.
55
+ *
56
  * @var string
57
  */
58
  protected $_template = 'TIG/PostNL/system/config/form/field/split_address_check.phtml';
59
+
60
  /**
61
+ * Get if the split_street field or the postcode check is enabled.
62
+ *
63
  * @return boolean
64
  */
65
  public function getIsAddressSplit()
70
  * Check if the split_street field is enabled based on the current scope
71
  */
72
  if ($request->getParam('store')) {
73
+ $usePostcodeCheck = Mage::getStoreConfigFlag(self::XPATH_USE_POSTCODE_CHECK, $request->getparam('store'));
74
+ $splitStreet = Mage::getStoreConfigFlag(self::XPATH_SPLIT_STREET, $request->getparam('store'));
75
  } elseif ($request->getParam('website')) {
76
  $website = Mage::getModel('core/website')->load($request->getparam('website'), 'code');
77
+ $usePostcodeCheck = (bool) $website->getConfig(self::XPATH_USE_POSTCODE_CHECK, $website->getId());
78
+ $splitStreet = (bool) $website->getConfig(self::XPATH_SPLIT_STREET, $website->getId());
79
  } else {
80
+ $usePostcodeCheck = Mage::getStoreConfigFlag(self::XPATH_USE_POSTCODE_CHECK, Mage_Core_Model_App::ADMIN_STORE_ID);
81
+ $splitStreet = Mage::getStoreConfigFlag(self::XPATH_SPLIT_STREET, Mage_Core_Model_App::ADMIN_STORE_ID);
82
+ }
83
+
84
+ if ($usePostcodeCheck || $splitStreet) {
85
+ return true;
86
  }
87
+
88
+ return false;
89
  }
90
  }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/SupportTab.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,29 +33,36 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_SupportTab extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
 
40
  {
41
  /**
42
- * Css file loaded for PostNL's system > config section
 
 
 
 
 
43
  */
44
  const SYSTEM_CONFIG_EDIT_CSS_FILE = 'css/TIG/PostNL/system_config_edit_postnl.css';
45
-
 
46
  /**
47
  * Template file used
48
- *
49
  * @var string
50
  */
51
  protected $_template = 'TIG/PostNL/system/config/form/field/support_tab.phtml';
52
-
53
  /**
54
- * Add a new css file to the head. We couldn't do this from layout.xml, because it would have loaded
55
  * for all System > Config pages, rather than just PostNL's section.
56
- *
57
  * @return Mage_Adminhtml_Block_Abstract::_prepareLayout()
58
- *
59
  * @see Mage_Adminhtml_Block_Abstract::_prepareLayout()
60
  */
61
  protected function _prepareLayout()
@@ -63,7 +70,32 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_SupportTab extends TIG
63
  $this->getLayout()
64
  ->getBlock('head')
65
  ->addCss(self::SYSTEM_CONFIG_EDIT_CSS_FILE);
66
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  return parent::_prepareLayout();
68
  }
69
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_SupportTab
40
+ extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
41
  {
42
  /**
43
+ * @var string
44
+ */
45
+ protected $_eventPrefix = 'postnl_adminhtml_system_config_form_field_supporttab';
46
+
47
+ /**
48
+ * Css files loaded for PostNL's system > config section
49
  */
50
  const SYSTEM_CONFIG_EDIT_CSS_FILE = 'css/TIG/PostNL/system_config_edit_postnl.css';
51
+ const MAGENTO_16_CSS_FILE = 'css/TIG/PostNL/system_config_edit_postnl_magento16.css';
52
+
53
  /**
54
  * Template file used
55
+ *
56
  * @var string
57
  */
58
  protected $_template = 'TIG/PostNL/system/config/form/field/support_tab.phtml';
59
+
60
  /**
61
+ * Add a new css file to the head. We couldn't do this from layout.xml, because it would have loaded
62
  * for all System > Config pages, rather than just PostNL's section.
63
+ *
64
  * @return Mage_Adminhtml_Block_Abstract::_prepareLayout()
65
+ *
66
  * @see Mage_Adminhtml_Block_Abstract::_prepareLayout()
67
  */
68
  protected function _prepareLayout()
70
  $this->getLayout()
71
  ->getBlock('head')
72
  ->addCss(self::SYSTEM_CONFIG_EDIT_CSS_FILE);
73
+
74
+ /**
75
+ * For Magento 1.6 and 1.11 we need to add another css file.
76
+ */
77
+ $helper = Mage::helper('postnl');
78
+ $isEnterprise = $helper->isEnterprise();
79
+
80
+ /**
81
+ * Get the minimum version requirement for the current Magento edition.
82
+ */
83
+ if($isEnterprise) {
84
+ $minimumVersion = '1.12.0.0';
85
+ } else {
86
+ $minimumVersion = '1.7.0.0';
87
+ }
88
+
89
+ /**
90
+ * Check if the current version is below the minimum version requirement.
91
+ */
92
+ $isBelowMinimumVersion = version_compare(Mage::getVersion(), $minimumVersion, '<');
93
+ if ($isBelowMinimumVersion) {
94
+ $this->getLayout()
95
+ ->getBlock('head')
96
+ ->addCss(self::MAGENTO_16_CSS_FILE);
97
+ }
98
+
99
  return parent::_prepareLayout();
100
  }
101
  }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/TablerateExport.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TablerateExport
40
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
41
+ implements Varien_Data_Form_Element_Renderer_Interface
42
+ {
43
+ /**
44
+ * @param Varien_Data_Form_Element_Abstract $element
45
+ *
46
+ * @return string
47
+ */
48
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
49
+ {
50
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button');
51
+
52
+ $params = array(
53
+ 'website' => $buttonBlock->getRequest()->getParam('website')
54
+ );
55
+
56
+ $onClick = 'setLocation(\''
57
+ . Mage::helper('adminhtml')->getUrl("postnl_admin/adminhtml_config/exportTablerates", $params)
58
+ . 'conditionName/\' + $(\'carriers_postnl_condition_name\').value + \'/tablerates.csv\' )';
59
+
60
+ $data = array(
61
+ 'label' => Mage::helper('postnl')->__('Export CSV'),
62
+ 'onclick' => $onClick,
63
+ 'id' => $element->getHtmlId(),
64
+ 'type' => 'button',
65
+ 'class' => 'scalable postnl-button',
66
+ );
67
+
68
+ $html = $buttonBlock->setData($data)->toHtml();
69
+
70
+ return $html;
71
+ }
72
+
73
+ /**
74
+ * @param Varien_Data_Form_Element_Abstract $element
75
+ *
76
+ * @return string
77
+ */
78
+ public function render(Varien_Data_Form_Element_Abstract $element)
79
+ {
80
+ return parent::render($element);
81
+ }
82
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/TablerateImport.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TablerateImport
40
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
41
+ implements Varien_Data_Form_Element_Renderer_Interface
42
+ {
43
+ /**
44
+ * Get a hidden form element and some JS to support it.
45
+ *
46
+ * @param Varien_Data_Form_Element_Abstract $element
47
+ *
48
+ * @return string
49
+ *
50
+ * @see Mage_Adminhtml_Block_System_Config_Form_Field_Import
51
+ */
52
+ public function _getJsHtml(Varien_Data_Form_Element_Abstract $element)
53
+ {
54
+ $html = '<input id="postnl_time_condition" type="hidden" name="'.$element->getName().'" value="'.time().'" />';
55
+
56
+ $html .= "<script type='text/javascript'>
57
+ document.observe('dom:loaded', function() {
58
+ Event.observe($('carriers_postnl_condition_name'), 'change', checkConditionName.bind(this));
59
+ function checkConditionName(event)
60
+ {
61
+ var conditionNameElement = Event.element(event);
62
+ if (conditionNameElement && conditionNameElement.id) {
63
+ $('postnl_time_condition').value = '_' + conditionNameElement.value + '/' + Math.random();
64
+ }
65
+ }
66
+ });
67
+ </script>";
68
+
69
+ return $html;
70
+ }
71
+
72
+ /**
73
+ * Render the element.
74
+ *
75
+ * @param Varien_Data_Form_Element_Abstract $element
76
+ *
77
+ * @return string
78
+ */
79
+ public function render(Varien_Data_Form_Element_Abstract $element)
80
+ {
81
+ $element->setType('file')
82
+ ->removeClass('input-text');
83
+
84
+ $html = parent::render($element);
85
+
86
+ $html .= $this->_getJsHtml($element);
87
+
88
+ return $html;
89
+ }
90
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/TextBox/Abstract.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -35,21 +35,29 @@
35
  *
36
  * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
38
  */
39
  abstract class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
40
- extends Mage_Adminhtml_Block_Abstract
41
  implements Varien_Data_Form_Element_Renderer_Interface
42
  {
 
 
 
 
 
43
  /**
44
  * Template file used
45
- *
46
  * @var string
47
  */
48
  protected $_template = '';
49
-
50
  /**
51
  * Get the element's HTML ID
52
- *
53
  * @return string
54
  */
55
  public function getHtmlId()
@@ -57,10 +65,10 @@ abstract class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstr
57
  if (!$this->getElement()) {
58
  return '';
59
  }
60
-
61
  $element = $this->getElement();
62
  $id = $element->getHtmlId();
63
-
64
  return $id;
65
  }
66
 
@@ -73,8 +81,7 @@ abstract class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstr
73
  public function render(Varien_Data_Form_Element_Abstract $element)
74
  {
75
  $this->setElement($element);
76
-
77
  return $this->toHtml();
78
  }
79
  }
80
-
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
35
  *
36
  * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method Varien_Data_Form_Element_Abstract getElement()
40
+ * @method TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract setElement(Varien_Data_Form_Element_Abstract $value)
41
  */
42
  abstract class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
43
+ extends TIG_PostNL_Block_Adminhtml_Template
44
  implements Varien_Data_Form_Element_Renderer_Interface
45
  {
46
+ /**
47
+ * @var string
48
+ */
49
+ protected $_eventPrefix = 'postnl_adminhtml_system_config_form_field_textbox_abstract';
50
+
51
  /**
52
  * Template file used
53
+ *
54
  * @var string
55
  */
56
  protected $_template = '';
57
+
58
  /**
59
  * Get the element's HTML ID
60
+ *
61
  * @return string
62
  */
63
  public function getHtmlId()
65
  if (!$this->getElement()) {
66
  return '';
67
  }
68
+
69
  $element = $this->getElement();
70
  $id = $element->getHtmlId();
71
+
72
  return $id;
73
  }
74
 
81
  public function render(Varien_Data_Form_Element_Abstract $element)
82
  {
83
  $this->setElement($element);
84
+
85
  return $this->toHtml();
86
  }
87
  }
 
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ValidateButton.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,24 +33,24 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ValidateButton
40
  extends Mage_Adminhtml_Block_System_Config_Form_Field
41
  implements Varien_Data_Form_Element_Renderer_Interface
42
- {
43
  /**
44
  * Gets the element's html. In this case: a button redirecting the user to the extensionControl controller
45
- *
 
 
46
  * @return string
47
  */
48
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
49
  {
50
  $this->setElement($element);
51
-
52
- $url = $this->getUrl('postnl/adminhtml_extensionControl/activate');
53
-
54
  $html = $this->getLayout()->createBlock('adminhtml/widget_button')
55
  ->setId($element->getHtmlId())
56
  ->setType('button')
@@ -61,12 +61,13 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ValidateButton
61
 
62
  return $html;
63
  }
64
-
65
  /**
66
  * Render the element without a scope label and without the 'use default' checkbox.
67
- *
 
68
  * @return string
69
- *
70
  * @see parent::render()
71
  */
72
  public function render(Varien_Data_Form_Element_Abstract $element)
@@ -74,7 +75,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ValidateButton
74
  $element->unsScope()
75
  ->unsCanUseWebsiteValue()
76
  ->unsCanUseDefaultValue();
77
-
78
  return parent::render($element);
79
  }
80
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ValidateButton
40
  extends Mage_Adminhtml_Block_System_Config_Form_Field
41
  implements Varien_Data_Form_Element_Renderer_Interface
42
+ {
43
  /**
44
  * Gets the element's html. In this case: a button redirecting the user to the extensionControl controller
45
+ *
46
+ * @param Varien_Data_Form_Element_Abstract $element
47
+ *
48
  * @return string
49
  */
50
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
51
  {
52
  $this->setElement($element);
53
+
 
 
54
  $html = $this->getLayout()->createBlock('adminhtml/widget_button')
55
  ->setId($element->getHtmlId())
56
  ->setType('button')
61
 
62
  return $html;
63
  }
64
+
65
  /**
66
  * Render the element without a scope label and without the 'use default' checkbox.
67
+ *
68
+ * @param Varien_Data_Form_Element_Abstract $element
69
  * @return string
70
+ *
71
  * @see parent::render()
72
  */
73
  public function render(Varien_Data_Form_Element_Abstract $element)
75
  $element->unsScope()
76
  ->unsCanUseWebsiteValue()
77
  ->unsCanUseDefaultValue();
78
+
79
  return parent::render($element);
80
  }
81
  }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/WarningBox.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -36,11 +36,17 @@
36
  * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_WarningBox extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
 
40
  {
 
 
 
 
 
41
  /**
42
  * Template file used
43
- *
44
  * @var string
45
  */
46
  protected $_template = 'TIG/PostNL/system/config/form/field/warning_box.phtml';
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
36
  * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_WarningBox
40
+ extends TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_TextBox_Abstract
41
  {
42
+ /**
43
+ * @var string
44
+ */
45
+ protected $_eventPrefix = 'postnl_adminhtml_system_config_form_field_warningbox';
46
+
47
  /**
48
  * Template file used
49
+ *
50
  * @var string
51
  */
52
  protected $_template = 'TIG/PostNL/system/config/form/field/warning_box.phtml';
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Fieldset.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_System_Config_Form_Fieldset extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
@@ -42,7 +42,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Fieldset extends Mage_Adminh
42
  * Return header comment part of html for fieldset
43
  *
44
  * @param Varien_Data_Form_Element_Abstract $element
45
- *
46
  * @return string
47
  */
48
  protected function _getHeaderCommentHtml($element)
@@ -51,13 +51,13 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Fieldset extends Mage_Adminh
51
  if (!$comment) {
52
  return '';
53
  }
54
-
55
  $commentHtml = '<div class="box">'
56
  . '<p>'
57
  . $comment
58
  . '</p>'
59
  . '</div>';
60
-
61
  return $commentHtml;
62
  }
63
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_System_Config_Form_Fieldset extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
42
  * Return header comment part of html for fieldset
43
  *
44
  * @param Varien_Data_Form_Element_Abstract $element
45
+ *
46
  * @return string
47
  */
48
  protected function _getHeaderCommentHtml($element)
51
  if (!$comment) {
52
  return '';
53
  }
54
+
55
  $commentHtml = '<div class="box">'
56
  . '<p>'
57
  . $comment
58
  . '</p>'
59
  . '</div>';
60
+
61
  return $commentHtml;
62
  }
63
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Template.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ abstract class TIG_PostNL_Block_Adminhtml_Template extends Mage_Adminhtml_Block_Abstract
40
+ {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_adminhtml_template';
45
+
46
+ /**
47
+ * Renders a template block. Also throws 2 events based on the current event prefix.
48
+ *
49
+ * @return string
50
+ */
51
+ protected function _toHtml()
52
+ {
53
+ Mage::dispatchEvent($this->_eventPrefix . '_to_html_before');
54
+
55
+ $html = parent::_toHtml();
56
+
57
+ Mage::dispatchEvent($this->_eventPrefix . '_to_html_after');
58
+ return $html;
59
+ }
60
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Action.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,10 +33,10 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Action
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
41
  {
42
  /**
@@ -46,12 +46,12 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Action
46
  const COUNTRY_ID_COLUMN = 'country_id';
47
  const LABELS_PRINTED_COLUMN = 'labels_printed';
48
  const CONFIRM_STATUS_COLUMN = 'confirm_status';
49
-
50
  /**
51
  * Renders column
52
  *
53
  * @param Varien_Object $row
54
- *
55
  * @return string
56
  */
57
  public function render(Varien_Object $row)
@@ -60,102 +60,138 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Action
60
  if (empty($actions) || !is_array($actions)) {
61
  return '&nbsp;';
62
  }
63
-
64
  $actionLinks = array();
65
  foreach ($actions as $action) {
66
  /**
67
- * Check if this action is allowed.
 
 
68
  */
69
  if (!$this->_isActionAllowed($row, $action)) {
70
  continue;
71
  }
72
-
73
- $action = $this->_disableAction($row, $action);
74
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  if (is_array($action)) {
76
  $actionLinks[] = $this->_toLinkHtml($action, $row);
77
  }
78
  }
79
-
80
  $output = implode(' / ', $actionLinks);
81
-
82
  return $output;
83
  }
84
-
85
  /**
86
  * Checks if a certain action is allowed for this row
87
- *
88
  * @param Mage_Sales_Model_Order_Shipment $row
89
- * @param array $action
90
- *
91
  * @return boolean
92
  */
93
- protected function _isActionAllowed($row, $action)
94
  {
95
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
96
-
97
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
98
-
99
  /**
100
  * If this is a PostNL action, but this shipment was not shipped using PosTNL, skip it
101
  */
102
- if (array_key_exists('is_postnl', $action)
103
  && $action['is_postnl']
104
  && !in_array($shippingMethod, $postnlShippingMethods)
105
  ) {
 
106
  return false;
107
  }
108
-
 
109
  return true;
110
  }
111
-
112
  /**
113
  * In some cases an action must be disabled
114
- *
115
  * @param Mage_Sales_Model_Order_Shipment $row
116
- * @param array $action
117
- *
118
  * @return array
119
  */
120
- protected function _disableAction($row, $action)
121
  {
122
- $helper = Mage::helper('postnl');
123
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
124
- $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
125
-
126
- $euCountries = Mage::helper('postnl/cif')->getEuCountries();
127
- $countryId = $row->getData(self::COUNTRY_ID_COLUMN);
128
  $confirmStatus = $row->getData(self::CONFIRM_STATUS_COLUMN);
129
-
130
  /**
131
- * Right now only the confirm action needs to be disabled in certain instances
132
- */
133
- if ($action['caption'] != $helper->__('Confirm')) {
134
- return $action;
135
- }
136
-
137
- /**
138
- * If the shipment is confirmed, we can't confirm it again
139
  */
140
  if ($confirmStatus == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
141
- $action['style'] = 'color:gray; cursor:not-allowed;';
142
- $action['onClick'] = 'return false;';
143
- $action['title'] = $helper->__('This shipment has already been confirmed.');
144
  return $action;
145
  }
146
-
147
  /**
148
  * EU shipments can only confirm after their labels have been printed
149
  */
150
  if (in_array($countryId, $euCountries)
151
  && !$row->getData(self::LABELS_PRINTED_COLUMN)
152
  ){
153
- $action['style'] = 'color:gray; cursor:not-allowed;;';
154
- $action['onClick'] = 'return false;';
155
- $action['title'] = $helper->__("You must first print a shipping label for this shipment.");
156
  return $action;
157
  }
158
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  return $action;
160
  }
161
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Action
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
41
  {
42
  /**
46
  const COUNTRY_ID_COLUMN = 'country_id';
47
  const LABELS_PRINTED_COLUMN = 'labels_printed';
48
  const CONFIRM_STATUS_COLUMN = 'confirm_status';
49
+
50
  /**
51
  * Renders column
52
  *
53
  * @param Varien_Object $row
54
+ *
55
  * @return string
56
  */
57
  public function render(Varien_Object $row)
60
  if (empty($actions) || !is_array($actions)) {
61
  return '&nbsp;';
62
  }
63
+
64
  $actionLinks = array();
65
  foreach ($actions as $action) {
66
  /**
67
+ * Check if this action is allowed.
68
+ *
69
+ * @var Mage_Sales_Model_Order_Shipment $row
70
  */
71
  if (!$this->_isActionAllowed($row, $action)) {
72
  continue;
73
  }
74
+
75
+ /**
76
+ * The confirm action may need to be disabled.
77
+ */
78
+ if (isset($action['code']) && $action['code'] == 'postnl_confirm') {
79
+ $action = $this->_checkDisableAction($row, $action);
80
+ }
81
+
82
+ /**
83
+ * The print label action needs to use a custom onclick event.
84
+ */
85
+ if (isset($action['code']) && $action['code'] == 'postnl_print_label') {
86
+ $printLabelUrl = $this->getUrl(
87
+ 'postnl_admin/adminhtml_shipment/printLabel',
88
+ array('shipment_id' => $row->getId())
89
+ );
90
+
91
+ $action['onClick'] = "printLabel('{$printLabelUrl}')";
92
+ }
93
+
94
+ if (isset($action['code'])) {
95
+ unset($action['code']);
96
+ }
97
+
98
  if (is_array($action)) {
99
  $actionLinks[] = $this->_toLinkHtml($action, $row);
100
  }
101
  }
102
+
103
  $output = implode(' / ', $actionLinks);
104
+
105
  return $output;
106
  }
107
+
108
  /**
109
  * Checks if a certain action is allowed for this row
110
+ *
111
  * @param Mage_Sales_Model_Order_Shipment $row
112
+ * @param array &$action
113
+ *
114
  * @return boolean
115
  */
116
+ protected function _isActionAllowed($row, &$action)
117
  {
118
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
119
+
120
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
121
+
122
  /**
123
  * If this is a PostNL action, but this shipment was not shipped using PosTNL, skip it
124
  */
125
+ if (array_key_exists('is_postnl', $action)
126
  && $action['is_postnl']
127
  && !in_array($shippingMethod, $postnlShippingMethods)
128
  ) {
129
+ unset($action['is_postnl']);
130
  return false;
131
  }
132
+
133
+ unset($action['is_postnl']);
134
  return true;
135
  }
136
+
137
  /**
138
  * In some cases an action must be disabled
139
+ *
140
  * @param Mage_Sales_Model_Order_Shipment $row
141
+ * @param array $action
142
+ *
143
  * @return array
144
  */
145
+ protected function _checkDisableAction($row, $action)
146
  {
147
+ $helper = Mage::helper('postnl/cif');
148
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
149
+
150
+ $euCountries = $helper->getEuCountries();
151
+ $countryId = $row->getData(self::COUNTRY_ID_COLUMN);
 
152
  $confirmStatus = $row->getData(self::CONFIRM_STATUS_COLUMN);
153
+
154
  /**
155
+ * If the shipment is confirmed, we can't confirm it again.
156
+ *
157
+ * @var $postnlShipmentClass TIG_PostNL_Model_Core_Shipment
 
 
 
 
 
158
  */
159
  if ($confirmStatus == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
160
+ $message = $helper->__('This shipment has already been confirmed.');
161
+ $action = $this->_disableAction($action, $message);
162
+
163
  return $action;
164
  }
165
+
166
  /**
167
  * EU shipments can only confirm after their labels have been printed
168
  */
169
  if (in_array($countryId, $euCountries)
170
  && !$row->getData(self::LABELS_PRINTED_COLUMN)
171
  ){
172
+ $message = $helper->__("You must first print a shipping label for this shipment.");
173
+ $action = $this->_disableAction($action, $message);
174
+
175
  return $action;
176
  }
177
+
178
+ return $action;
179
+ }
180
+
181
+ /**
182
+ * Disable a specified action.
183
+ *
184
+ * @param array $action
185
+ * @param string $message
186
+ *
187
+ * @return array
188
+ */
189
+ protected function _disableAction($action, $message = '')
190
+ {
191
+ $action['style'] = 'color:gray; cursor:not-allowed;';
192
+ $action['onClick'] = 'return false;';
193
+ $action['title'] = $message;
194
+
195
  return $action;
196
  }
197
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Barcode.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,10 +33,10 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Barcode
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
  {
42
  /**
@@ -46,14 +46,14 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Barcode
46
  const POSTCODE_COLUMN = 'postcode';
47
  const COUNTRY_ID_COLUMN = 'country_id';
48
  const CONFIRM_STATUS_COLUMN = 'confirm_status';
49
-
50
  /**
51
  * Renders the barcode column. This column will be empty for non-PostNL shipments.
52
- * If the shipment has been confirmed, it will be displayed as a track& trace URL.
53
  * Otherwise the bare code will be displayed.
54
  *
55
  * @param Varien_Object $row
56
- *
57
  * @return string
58
  */
59
  public function render(Varien_Object $row)
@@ -66,7 +66,7 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Barcode
66
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
67
  return parent::render($row);
68
  }
69
-
70
  /**
71
  * Check if any data is available
72
  */
@@ -75,15 +75,17 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Barcode
75
  $value = Mage::helper('postnl')->__('No barcode available.');
76
  return $value;
77
  }
78
-
79
  /**
80
- * If the shipment hasn't been confirmed yet, the barcode will not be known by PostNL track & trace
 
 
81
  */
82
  $postnlShipmentClassName = Mage::getConfig()->getModelClassName('postnl_core/shipment');
83
  if ($row->getData(self::CONFIRM_STATUS_COLUMN) != $postnlShipmentClassName::CONFIRM_STATUS_CONFIRMED) {
84
  return $value;
85
  }
86
-
87
  /**
88
  * Create a track & trace URL based on shipping destination
89
  */
@@ -93,11 +95,11 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Barcode
93
  'countryCode' => $countryCode,
94
  'postcode' => $postcode,
95
  );
96
-
97
  $barcodeUrl = Mage::helper('postnl/carrier')->getBarcodeUrl($value, $destinationData, false, true);
98
-
99
  $barcodeHtml = "<a href='{$barcodeUrl}' target='_blank'>{$value}</a>";
100
-
101
  return $barcodeHtml;
102
  }
103
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Barcode
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
  {
42
  /**
46
  const POSTCODE_COLUMN = 'postcode';
47
  const COUNTRY_ID_COLUMN = 'country_id';
48
  const CONFIRM_STATUS_COLUMN = 'confirm_status';
49
+
50
  /**
51
  * Renders the barcode column. This column will be empty for non-PostNL shipments.
52
+ * If the shipment has been confirmed, it will be displayed as a track& trace URL.
53
  * Otherwise the bare code will be displayed.
54
  *
55
  * @param Varien_Object $row
56
+ *
57
  * @return string
58
  */
59
  public function render(Varien_Object $row)
66
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
67
  return parent::render($row);
68
  }
69
+
70
  /**
71
  * Check if any data is available
72
  */
75
  $value = Mage::helper('postnl')->__('No barcode available.');
76
  return $value;
77
  }
78
+
79
  /**
80
+ * If the shipment hasn't been confirmed yet, the barcode will not be known by PostNL track & trace.
81
+ *
82
+ * @var $postnlShipmentClassName TIG_PostNL_Model_Core_Shipment
83
  */
84
  $postnlShipmentClassName = Mage::getConfig()->getModelClassName('postnl_core/shipment');
85
  if ($row->getData(self::CONFIRM_STATUS_COLUMN) != $postnlShipmentClassName::CONFIRM_STATUS_CONFIRMED) {
86
  return $value;
87
  }
88
+
89
  /**
90
  * Create a track & trace URL based on shipping destination
91
  */
95
  'countryCode' => $countryCode,
96
  'postcode' => $postcode,
97
  );
98
+
99
  $barcodeUrl = Mage::helper('postnl/carrier')->getBarcodeUrl($value, $destinationData, false, true);
100
+
101
  $barcodeHtml = "<a href='{$barcodeUrl}' target='_blank'>{$value}</a>";
102
+
103
  return $barcodeHtml;
104
  }
105
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmDate.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,10 +33,10 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmDate
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Date
41
  {
42
  /**
@@ -44,12 +44,12 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmDate
44
  */
45
  const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
  const CONFIRM_STATUS_COLUMN = 'confirm_status';
47
-
48
  /**
49
  * Renders column.
50
  *
51
  * @param Varien_Object $row
52
- *
53
  * @return string
54
  */
55
  public function render(Varien_Object $row)
@@ -59,46 +59,46 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmDate
59
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
60
  return parent::render($row);
61
  }
62
-
63
  $value = $row->getData($this->getColumn()->getIndex());
64
  $now = date('Ymd', Mage::getModel('core/date')->gmtTimestamp());
65
-
66
  /**
67
  * Check if the shipment should be confirmed today
68
  */
69
  if ($now == date('Ymd', strtotime($value))) {
70
  return Mage::helper('postnl')->__('Today');
71
  }
72
-
73
  /**
74
  * Check if the shipment should be confirmed somewhere in the future
75
  */
76
  if ($now < date('Ymd', strtotime($value))) {
77
  $confirmDate = new DateTime($value);
78
  $today = new DateTime($now);
79
-
80
  /**
81
  * Get the number of days until the shipment should be confirmed
82
  */
83
  $diff = $today->diff($confirmDate)->format('%a');
84
-
85
  /**
86
  * Check if it should be confirmed tomorrow
87
  */
88
  if ($diff == 1) {
89
  $renderedValue = Mage::helper('postnl')->__('Tomorrow');
90
-
91
  return $renderedValue;
92
  }
93
-
94
  /**
95
  * Render the number of days before the shipment should be confirmed
96
  */
97
  $renderedValue = Mage::helper('postnl')->__('%s days from now', $diff);
98
-
99
  return $renderedValue;
100
  }
101
-
102
  /**
103
  * Finally, simply render the date
104
  */
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmDate
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Date
41
  {
42
  /**
44
  */
45
  const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
  const CONFIRM_STATUS_COLUMN = 'confirm_status';
47
+
48
  /**
49
  * Renders column.
50
  *
51
  * @param Varien_Object $row
52
+ *
53
  * @return string
54
  */
55
  public function render(Varien_Object $row)
59
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
60
  return parent::render($row);
61
  }
62
+
63
  $value = $row->getData($this->getColumn()->getIndex());
64
  $now = date('Ymd', Mage::getModel('core/date')->gmtTimestamp());
65
+
66
  /**
67
  * Check if the shipment should be confirmed today
68
  */
69
  if ($now == date('Ymd', strtotime($value))) {
70
  return Mage::helper('postnl')->__('Today');
71
  }
72
+
73
  /**
74
  * Check if the shipment should be confirmed somewhere in the future
75
  */
76
  if ($now < date('Ymd', strtotime($value))) {
77
  $confirmDate = new DateTime($value);
78
  $today = new DateTime($now);
79
+
80
  /**
81
  * Get the number of days until the shipment should be confirmed
82
  */
83
  $diff = $today->diff($confirmDate)->format('%a');
84
+
85
  /**
86
  * Check if it should be confirmed tomorrow
87
  */
88
  if ($diff == 1) {
89
  $renderedValue = Mage::helper('postnl')->__('Tomorrow');
90
+
91
  return $renderedValue;
92
  }
93
+
94
  /**
95
  * Render the number of days before the shipment should be confirmed
96
  */
97
  $renderedValue = Mage::helper('postnl')->__('%s days from now', $diff);
98
+
99
  return $renderedValue;
100
  }
101
+
102
  /**
103
  * Finally, simply render the date
104
  */
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmStatus.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -36,19 +36,19 @@
36
  * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmStatus
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
- {
42
  /**
43
  * Additional column names used
44
  */
45
  const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
-
47
  /**
48
  * Renders the column value as a Yes or No value
49
  *
50
  * @param Varien_Object $row
51
- *
52
  * @return string
53
  */
54
  public function render(Varien_Object $row)
@@ -61,7 +61,7 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmStatus
61
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
62
  return parent::render($row);
63
  }
64
-
65
  /**
66
  * Check if any data is available
67
  */
@@ -69,20 +69,23 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmStatus
69
  if (is_null($value) || $value === '') {
70
  return parent::render($row);
71
  }
72
-
 
 
 
73
  $postnlShipmentClass = Mage::app()->getConfig()->getModelClassName('postnl_core/shipment');
74
  if ($value == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
75
  $value = Mage::helper('postnl')->__('Confirmed');
76
  return $value;
77
  }
78
-
79
  if ($value == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED) {
80
  $value = Mage::helper('postnl')->__('Unconfirmed');
81
  return $value;
82
  }
83
-
84
  $value = Mage::helper('postnl')->__('Confirmation Expired');
85
-
86
  return $value;
87
  }
88
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
36
  * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmStatus
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
+ {
42
  /**
43
  * Additional column names used
44
  */
45
  const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
+
47
  /**
48
  * Renders the column value as a Yes or No value
49
  *
50
  * @param Varien_Object $row
51
+ *
52
  * @return string
53
  */
54
  public function render(Varien_Object $row)
61
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
62
  return parent::render($row);
63
  }
64
+
65
  /**
66
  * Check if any data is available
67
  */
69
  if (is_null($value) || $value === '') {
70
  return parent::render($row);
71
  }
72
+
73
+ /**
74
+ * @var $postnlShipmentClass TIG_PostNL_Model_Core_Shipment
75
+ */
76
  $postnlShipmentClass = Mage::app()->getConfig()->getModelClassName('postnl_core/shipment');
77
  if ($value == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
78
  $value = Mage::helper('postnl')->__('Confirmed');
79
  return $value;
80
  }
81
+
82
  if ($value == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED) {
83
  $value = Mage::helper('postnl')->__('Unconfirmed');
84
  return $value;
85
  }
86
+
87
  $value = Mage::helper('postnl')->__('Confirmation Expired');
88
+
89
  return $value;
90
  }
91
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/DeliveryDate.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_DeliveryDate
40
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Date
41
+ {
42
+ /**
43
+ * Additional column names used
44
+ */
45
+ const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
+ const CONFIRM_DATE_COLUMN = 'confirm_date';
47
+
48
+ /**
49
+ * Renders column.
50
+ *
51
+ * @param Varien_Object $row
52
+ *
53
+ * @return string
54
+ */
55
+ public function render(Varien_Object $row)
56
+ {
57
+ $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
58
+ $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
59
+ if (!in_array($shippingMethod, $postnlShippingMethods)) {
60
+ return parent::render($row);
61
+ }
62
+
63
+ $value = $row->getData($this->getColumn()->getIndex());
64
+
65
+ /**
66
+ * If no delivery date is specified, calculate the date as being 1 day after the confirm date
67
+ */
68
+ if (!$value) {
69
+ $confirmDate = $row->getData(self::CONFIRM_DATE_COLUMN);
70
+ $deliveryDate = date('Y-m-d H:i:s', strtotime($confirmDate . ' + 1 day'));
71
+
72
+ $row->setData($this->getColumn()->getIndex(), $deliveryDate);
73
+ }
74
+
75
+ /**
76
+ * Finally, simply render the date
77
+ */
78
+ return parent::render($row);
79
+ }
80
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShipmentType.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,27 +33,34 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShipmentType
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
- {
42
  /**
43
  * Additional column names used
44
  */
45
- const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
- const IS_PAKJE_GEMAK_COLUMN = 'is_pakje_gemak';
47
-
 
 
48
  /**
49
  * Renders the column value as a shipment type value (Domestic, EPS or GlobalPack)
50
  *
51
  * @param Varien_Object $row
52
- *
53
  * @return string
54
  */
55
  public function render(Varien_Object $row)
56
  {
 
 
 
 
 
57
  /**
58
  * The shipment was not shipped using PostNL
59
  */
@@ -62,70 +69,116 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShipmentType
62
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
63
  return '';
64
  }
65
-
66
  /**
67
- * Check if any data is available
68
  */
69
- $value = $row->getData($this->getColumn()->getIndex());
70
  if (is_null($value) || $value === '') {
71
  return '';
72
  }
73
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  if ($row->getData(self::IS_PAKJE_GEMAK_COLUMN)) {
75
- $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>pakje_gemak</div>";
76
- $renderedValue .= Mage::helper('postnl')->__('Post Office');
 
 
 
77
  return $renderedValue;
78
  }
79
-
80
  /**
81
- * Check if this order is domestic
82
  */
83
  if ($value == 'NL') {
84
- $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>standard</div>";
85
- $renderedValue .= Mage::helper('postnl')->__('Domestic');
 
 
 
86
  return $renderedValue;
87
  }
88
-
89
  /**
90
- * Check if this order's shipping address is in an EU country
91
  */
92
- $euCountries = Mage::helper('postnl/cif')->getEuCountries();
93
  if (in_array($value, $euCountries)) {
94
- $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>eps</div>";
95
- $renderedValue .= Mage::helper('postnl')->__('EPS');
 
 
 
96
  return $renderedValue;
97
  }
98
-
99
  /**
100
- * If none of the above, it's an international order
101
  */
102
- $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>global_pack</div>";
103
- $renderedValue .= Mage::helper('postnl')->__('GlobalPack');
104
-
 
 
105
  return $renderedValue;
106
  }
107
 
108
  /**
109
- * Renders the <col> element of the column. Added check for $this->getColumn()->getDisplay() == 'none' that causes the
110
- * entire element to be hidden
111
- *
112
  * @return string
113
- *
114
  * @see Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract::renderProperty()
115
  */
116
  public function renderProperty()
117
  {
118
- if ($this->getColumn()->hasData('display')
119
- && $this->getColumn()->getDisplay() == 'none'
120
- ) {
121
- return 'style="display:none;"';
122
- }
123
-
124
  $out = '';
 
 
 
 
125
  $width = $this->_defaultWidth;
126
 
127
- if ($this->getColumn()->hasData('width')) {
128
- $customWidth = $this->getColumn()->getData('width');
129
  if ((null === $customWidth) || (preg_match('/^[0-9]+%?$/', $customWidth))) {
130
  $width = $customWidth;
131
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShipmentType
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
+ {
42
  /**
43
  * Additional column names used
44
  */
45
+ const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
+ const IS_PAKJE_GEMAK_COLUMN = 'is_pakje_gemak';
47
+ const IS_PAKKETAUTOMAAT_COLUMN = 'is_pakketautomaat';
48
+ const DELIVERY_OPTION_TYPE_COLUMN = 'delivery_option_type';
49
+
50
  /**
51
  * Renders the column value as a shipment type value (Domestic, EPS or GlobalPack)
52
  *
53
  * @param Varien_Object $row
54
+ *
55
  * @return string
56
  */
57
  public function render(Varien_Object $row)
58
  {
59
+ /**
60
+ * @var Mage_Adminhtml_Block_Widget_Grid_Column $column
61
+ */
62
+ $column = $this->getColumn();
63
+
64
  /**
65
  * The shipment was not shipped using PostNL
66
  */
69
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
70
  return '';
71
  }
72
+
73
  /**
74
+ * Check if any data is available.
75
  */
76
+ $value = $row->getData($column->getIndex());
77
  if (is_null($value) || $value === '') {
78
  return '';
79
  }
80
+
81
+ $helper = Mage::helper('postnl/cif');
82
+
83
+ $optionType = $row->getData(self::DELIVERY_OPTION_TYPE_COLUMN);
84
+ if ($optionType == 'Avond') {
85
+ $label = $helper->__('Domestic');
86
+ $comment = $helper->__('Evening Delivery');
87
+
88
+ $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>avond</div><b>{$label}"
89
+ . "</b><br /><em>{$comment}</em>";
90
+
91
+ return $renderedValue;
92
+ }
93
+
94
+ if ($optionType == 'PGE') {
95
+ $label = $helper->__('Post Office');
96
+ $comment = $helper->__('Early Pickup');
97
+
98
+ $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>pakje_gemak_express"
99
+ . "</div><b>{$label}</b><br /><em>{$comment}</em>";
100
+
101
+ return $renderedValue;
102
+ }
103
+
104
+ if ($row->getData(self::IS_PAKKETAUTOMAAT_COLUMN)) {
105
+ $label = $helper->__('Parcel Dispenser');
106
+
107
+ $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>pakketautomaat</div><b>"
108
+ . "{$label}</b>";
109
+
110
+ return $renderedValue;
111
+ }
112
+
113
  if ($row->getData(self::IS_PAKJE_GEMAK_COLUMN)) {
114
+ $label = $helper->__('Post Office');
115
+
116
+ $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>pakje_gemak</div><b>"
117
+ . "{$label}</b>";
118
+
119
  return $renderedValue;
120
  }
121
+
122
  /**
123
+ * Check if this order is domestic.
124
  */
125
  if ($value == 'NL') {
126
+ $label = $helper->__('Domestic');
127
+
128
+ $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>standard</div><b>"
129
+ . "{$label}</b>";
130
+
131
  return $renderedValue;
132
  }
133
+
134
  /**
135
+ * Check if this order's shipping address is in an EU country.
136
  */
137
+ $euCountries = $helper->getEuCountries();
138
  if (in_array($value, $euCountries)) {
139
+ $label = $helper->__('EPS');
140
+
141
+ $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>eps</div><b>{$label}"
142
+ . "</b>";
143
+
144
  return $renderedValue;
145
  }
146
+
147
  /**
148
+ * If none of the above apply, it's an international order.
149
  */
150
+ $label = $helper->__('GlobalPack');
151
+
152
+ $renderedValue = "<div id='postnl-shipmenttype-{$row->getId()}' class='no-display'>global_pack</div><b>{$label}"
153
+ . "</b>";
154
+
155
  return $renderedValue;
156
  }
157
 
158
  /**
159
+ * Renders the <col> element of the column. Added check for $this->getColumn()->getDisplay() == 'none' that causes
160
+ * the entire element to be hidden.
161
+ *
162
  * @return string
163
+ *
164
  * @see Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract::renderProperty()
165
  */
166
  public function renderProperty()
167
  {
168
+ /**
169
+ * @var Mage_Adminhtml_Block_Widget_Grid_Column $column
170
+ */
171
+ $column = $this->getColumn();
172
+
 
173
  $out = '';
174
+ if ($column->hasData('display')) {
175
+ $out .= " style='display:{$column->getDisplay()};'";
176
+ }
177
+
178
  $width = $this->_defaultWidth;
179
 
180
+ if ($column->hasData('width')) {
181
+ $customWidth = $column->getData('width');
182
  if ((null === $customWidth) || (preg_match('/^[0-9]+%?$/', $customWidth))) {
183
  $width = $customWidth;
184
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingDescription.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShippingDescription
40
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
+ {
42
+ /**
43
+ * Additional column names used
44
+ */
45
+ const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
+ const PRODUCT_CODE_COLUMN = 'product_code';
47
+
48
+ /**
49
+ * Renders the column value as a Yes or No value
50
+ *
51
+ * @param Varien_Object $row
52
+ *
53
+ * @return string
54
+ */
55
+ public function render(Varien_Object $row)
56
+ {
57
+ /**
58
+ * The shipment was not shipped using PostNL
59
+ */
60
+ $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
61
+ $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
62
+ if (!in_array($shippingMethod, $postnlShippingMethods)) {
63
+ return parent::render($row);
64
+ }
65
+
66
+ /**
67
+ * Check if any data is available
68
+ */
69
+ $value = $row->getData($this->getColumn()->getIndex());
70
+ if (is_null($value) || $value === '') {
71
+ return parent::render($row);
72
+ }
73
+
74
+ /**
75
+ * Get this row's product code and join it to this cell.
76
+ */
77
+ $productCode = $this->getProductCode($row);
78
+ $renderedvalue = '<strong>'
79
+ . parent::render($row)
80
+ . '</strong><br />'
81
+ . $productCode;
82
+
83
+ return $renderedvalue;
84
+ }
85
+
86
+ /**
87
+ * Get product_code column contents.
88
+ *
89
+ * @param Varien_Object $row
90
+ *
91
+ * @return string
92
+ *
93
+ * @see Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Options::render()
94
+ */
95
+ public function getProductCode(Varien_Object $row)
96
+ {
97
+ $options = $this->getColumn()->getOptions();
98
+ $showMissingOptionValues = (bool)$this->getColumn()->getShowMissingOptionValues();
99
+
100
+ $value = '';
101
+ if (empty($options) || !is_array($options)) {
102
+ return $value;
103
+ }
104
+
105
+ $value = $row->getData(self::PRODUCT_CODE_COLUMN);
106
+ if (is_array($value)) {
107
+ $res = array();
108
+ foreach ($value as $item) {
109
+ if (isset($options[$item])) {
110
+ $res[] = $this->escapeHtml($options[$item]);
111
+ }
112
+ elseif ($showMissingOptionValues) {
113
+ $res[] = $this->escapeHtml($item);
114
+ }
115
+ }
116
+ return implode(', ', $res);
117
+ } elseif (isset($options[$value])) {
118
+ return $this->escapeHtml($options[$value]);
119
+ }
120
+
121
+ return $this->escapeHtml($value);
122
+ }
123
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingPhase.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,32 +33,32 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShippingPhase
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
- {
42
  /**
43
  * Renders the column value as a human readable value
44
  *
45
  * @param Varien_Object $row
46
- *
47
  * @return string
48
  */
49
  public function render(Varien_Object $row)
50
  {
51
  $value = $row->getData($this->getColumn()->getIndex());
52
-
53
  if (empty($value)) {
54
  return '';
55
  }
56
-
57
  $shippingPhases = Mage::helper('postnl/cif')->getShippingPhases();
58
  if (array_key_exists($value, $shippingPhases)) {
59
  $value = $shippingPhases[$value];
60
  }
61
-
62
  return Mage::helper('postnl')->__($value);
63
  }
64
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShippingPhase
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
+ {
42
  /**
43
  * Renders the column value as a human readable value
44
  *
45
  * @param Varien_Object $row
46
+ *
47
  * @return string
48
  */
49
  public function render(Varien_Object $row)
50
  {
51
  $value = $row->getData($this->getColumn()->getIndex());
52
+
53
  if (empty($value)) {
54
  return '';
55
  }
56
+
57
  $shippingPhases = Mage::helper('postnl/cif')->getShippingPhases();
58
  if (array_key_exists($value, $shippingPhases)) {
59
  $value = $shippingPhases[$value];
60
  }
61
+
62
  return Mage::helper('postnl')->__($value);
63
  }
64
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Time.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,12 +33,12 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Time
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
41
- {
42
  /**
43
  * Date format string
44
  */
@@ -47,7 +47,7 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Time
47
  /**
48
  * Retrieve datetime format
49
  *
50
- * @return unknown
51
  */
52
  protected function _getFormat()
53
  {
@@ -72,21 +72,25 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Time
72
  * Renders grid column
73
  *
74
  * @param Varien_Object $row
 
75
  * @return string
76
  */
77
  public function render(Varien_Object $row)
78
  {
79
- if ($data = $this->_getValue($row)) {
80
- $format = $this->_getFormat();
81
- try {
82
- $data = Mage::app()->getLocale()
83
- ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
84
- } catch (Exception $e) {
85
- $data = Mage::app()->getLocale()
86
- ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
87
- }
88
- return $data;
 
 
 
89
  }
90
- return $this->getColumn()->getDefault();
91
  }
92
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Time
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
41
+ {
42
  /**
43
  * Date format string
44
  */
47
  /**
48
  * Retrieve datetime format
49
  *
50
+ * @return string
51
  */
52
  protected function _getFormat()
53
  {
72
  * Renders grid column
73
  *
74
  * @param Varien_Object $row
75
+ *
76
  * @return string
77
  */
78
  public function render(Varien_Object $row)
79
  {
80
+ $data = $this->_getValue($row);
81
+ if (!$data) {
82
+ return $this->getColumn()->getDefault();
83
+ }
84
+
85
+ $format = $this->_getFormat();
86
+ try {
87
+ $data = Mage::app()->getLocale()
88
+ ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
89
+ } catch (Exception $e) {
90
+ Mage::helper('postnl')->logException($e);
91
+
92
+ return $this->getColumn()->getDefault();
93
  }
94
+ return $data;
95
  }
96
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Translate.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,24 +33,24 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Translate
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
- {
42
  /**
43
- * Translate the column's value before rendering it
44
  *
45
  * @param Varien_Object $row
46
- *
47
  * @return string
48
  */
49
  public function render(Varien_Object $row)
50
  {
51
  $helper = Mage::helper('postnl');
52
  $value = $row->getData($this->getColumn()->getIndex());
53
-
54
  return $helper->__($value);
55
  }
56
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Translate
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
+ {
42
  /**
43
+ * Translate the column's value before rendering it.
44
  *
45
  * @param Varien_Object $row
46
+ *
47
  * @return string
48
  */
49
  public function render(Varien_Object $row)
50
  {
51
  $helper = Mage::helper('postnl');
52
  $value = $row->getData($this->getColumn()->getIndex());
53
+
54
  return $helper->__($value);
55
  }
56
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/YesNo.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,22 +33,22 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_YesNo
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
- {
42
  /**
43
  * Additional column names used
44
  */
45
  const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
-
47
  /**
48
  * Renders the column value as a Yes or No value
49
  *
50
  * @param Varien_Object $row
51
- *
52
  * @return string
53
  */
54
  public function render(Varien_Object $row)
@@ -61,7 +61,7 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_YesNo
61
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
62
  return parent::render($row);
63
  }
64
-
65
  /**
66
  * Check if any data is available
67
  */
@@ -69,14 +69,14 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_YesNo
69
  if (is_null($value) || $value === '') {
70
  return parent::render($row);
71
  }
72
-
73
  if ($value == 0) {
74
  $value = Mage::helper('postnl')->__('No');
75
  return $value;
76
  }
77
-
78
  $value = Mage::helper('postnl')->__('Yes');
79
-
80
  return $value;
81
  }
82
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_YesNo
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
41
+ {
42
  /**
43
  * Additional column names used
44
  */
45
  const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
+
47
  /**
48
  * Renders the column value as a Yes or No value
49
  *
50
  * @param Varien_Object $row
51
+ *
52
  * @return string
53
  */
54
  public function render(Varien_Object $row)
61
  if (!in_array($shippingMethod, $postnlShippingMethods)) {
62
  return parent::render($row);
63
  }
64
+
65
  /**
66
  * Check if any data is available
67
  */
69
  if (is_null($value) || $value === '') {
70
  return parent::render($row);
71
  }
72
+
73
  if ($value == 0) {
74
  $value = Mage::helper('postnl')->__('No');
75
  return $value;
76
  }
77
+
78
  $value = Mage::helper('postnl')->__('Yes');
79
+
80
  return $value;
81
  }
82
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Massaction/LabelStartPos.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * Observer to edit the sales > shipments grid
40
+ *
41
+ * @method TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid setCollection(Varien_Data_Collection $value)
42
+ * @method Varien_Data_Collection getCollection()
43
+ * @method TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid setBlock(Mage_Core_Block_Abstract $value)
44
+ */
45
+ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Massaction_LabelStartPos extends Mage_Adminhtml_Block_Abstract
46
+ {
47
+ /**
48
+ * @var string
49
+ */
50
+ protected $_template = 'TIG/PostNL/widget/grid/massaction/label_start_pos.phtml';
51
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/WindowsTheme.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasIsOldMagento()
40
+ * @method TIG_PostNL_Block_Adminhtml_WindowsTheme setIsOldMagento()
41
+ */
42
+ class TIG_PostNL_Block_Adminhtml_WindowsTheme extends TIG_PostNL_Block_Adminhtml_Template
43
+ {
44
+ /**
45
+ * For Magento versions below these versions we need to execute some special backwards compatibility code.
46
+ */
47
+ const MINIMUM_VERSION_COMPATIBILITY = '1.7.0.0';
48
+ const MINIMUM_ENTERPRISE_VERSION_COMPATIBILITY = '1.12.0.0';
49
+
50
+ /**
51
+ * @var string
52
+ */
53
+ protected $_eventPrefix = 'postnl_adminhtml_windowstheme';
54
+
55
+ /**
56
+ * Checks whether the current version of Magento is an old version (C.E. 1.6 or E.E. 1.11).
57
+ *
58
+ * @return boolean
59
+ */
60
+ public function getIsOldMagento()
61
+ {
62
+ if ($this->hasIsOldMagento()) {
63
+ return $this->_getData('is_old_magento');
64
+ }
65
+
66
+ $version = Mage::getVersion();
67
+ $isEnterprise = Mage::helper('postnl')->isEnterprise();
68
+
69
+ /**
70
+ * Get the minimum version requirement for the current Magento edition.
71
+ */
72
+ if($isEnterprise) {
73
+ $minimumVersion = self::MINIMUM_ENTERPRISE_VERSION_COMPATIBILITY;
74
+ } else {
75
+ $minimumVersion = self::MINIMUM_VERSION_COMPATIBILITY;
76
+ }
77
+
78
+ /**
79
+ * Check if the current version is below the minimum version requirement.
80
+ */
81
+ $isOldVersion = version_compare($version, $minimumVersion, '<');
82
+
83
+ $this->setIsOldMagento($isOldVersion);
84
+ return $isOldVersion;
85
+ }
86
+ }
app/code/community/TIG/PostNL/Block/Checkout/Cart/CheckoutLink.php CHANGED
@@ -33,34 +33,44 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
 
 
38
  */
39
- class TIG_PostNL_Block_Checkout_Cart_CheckoutLink extends Mage_Core_Block_Template
40
  {
41
  /**
42
- * Base URLs of the checkout button
 
 
 
 
 
43
  */
44
  const CHECKOUT_BUTTON_TEST_BASE_URL = 'https://tppcb-sandbox.e-id.nl/Button/Checkout';
45
  const CHECKOUT_BUTTON_LIVE_BASE_URL = 'https://checkout.postnl.nl/Button/Checkout';
46
 
47
  /**
48
- * XML path to public webshop ID setting
49
  */
50
- const XML_PATH_PUBLIC_WEBSHOP_ID = 'postnl/cif/public_webshop_id';
51
 
52
  /**
53
- * XML path to 'hide_button_if_disallowed' setting
54
  */
55
- const XML_PATH_HIDE_BUTTON_IF_DISALLOWED = 'postnl/checkout/hide_button_if_disallowed';
56
 
57
  /**
58
- * XML path to the 'instruction_cms_page' setting
59
  */
60
- const XML_PATH_INSTRUCTION_CMS_PAGE = 'postnl/checkout/instruction_cms_page';
61
 
62
  /**
63
- * Gets the checkout URL
64
  *
65
  * @return string
66
  */
@@ -72,7 +82,26 @@ class TIG_PostNL_Block_Checkout_Cart_CheckoutLink extends Mage_Core_Block_Templa
72
  }
73
 
74
  /**
75
- * Check if the button should be disabled
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  *
77
  * @return boolean
78
  */
@@ -86,7 +115,7 @@ class TIG_PostNL_Block_Checkout_Cart_CheckoutLink extends Mage_Core_Block_Templa
86
  }
87
 
88
  /**
89
- * Check if the button should be displayed
90
  *
91
  * @return boolean
92
  */
@@ -124,7 +153,7 @@ class TIG_PostNL_Block_Checkout_Cart_CheckoutLink extends Mage_Core_Block_Templa
124
  }
125
 
126
  /**
127
- * Gets this webshop's public ID
128
  *
129
  * @return string
130
  */
@@ -134,14 +163,14 @@ class TIG_PostNL_Block_Checkout_Cart_CheckoutLink extends Mage_Core_Block_Templa
134
  return $this->getData('public_webshop_id');
135
  }
136
 
137
- $webshopId = Mage::getStoreConfig(self::XML_PATH_PUBLIC_WEBSHOP_ID, Mage::app()->getStore()->getId());
138
 
139
  $this->setPublicWebshopId($webshopId);
140
  return $webshopId;
141
  }
142
 
143
  /**
144
- * Gets the checkout button src attribute
145
  *
146
  * @param boolean $forceDisabled
147
  *
@@ -170,13 +199,13 @@ class TIG_PostNL_Block_Checkout_Cart_CheckoutLink extends Mage_Core_Block_Templa
170
  }
171
 
172
  /**
173
- * Gets the URL of a CMS page containing instructions on how to use PostNL Checkout
174
  *
175
  * @return boolean|string
176
  */
177
  public function getInstructionUrl()
178
  {
179
- $instructionPage = Mage::getStoreConfig(self::XML_PATH_INSTRUCTION_CMS_PAGE, Mage::app()->getStore()->getId());
180
  if (!$instructionPage) {
181
  return false;
182
  }
@@ -186,7 +215,7 @@ class TIG_PostNL_Block_Checkout_Cart_CheckoutLink extends Mage_Core_Block_Templa
186
  }
187
 
188
  /**
189
- * Returns the block's html. Checks if the 'use_postnl_checkout' param is set. If not, returns and empty string
190
  *
191
  * @return string
192
  */
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasPublicWebshopId()
40
+ * @method TIG_PostNL_Block_Checkout_Cart_CheckoutLink setPublicWebshopId(string $value)
41
+ * @method boolean hasDoLoginCheck()
42
+ * @method TIG_PostNL_Block_Checkout_Cart_CheckoutLink setDoLoginCheck(boolean $value)
43
  */
44
+ class TIG_PostNL_Block_Checkout_Cart_CheckoutLink extends TIG_PostNL_Block_Core_Template
45
  {
46
  /**
47
+ * @var string
48
+ */
49
+ protected $_eventPrefix = 'postnl_checkout_cart_checkoutlink';
50
+
51
+ /**
52
+ * Base URLs of the checkout button.
53
  */
54
  const CHECKOUT_BUTTON_TEST_BASE_URL = 'https://tppcb-sandbox.e-id.nl/Button/Checkout';
55
  const CHECKOUT_BUTTON_LIVE_BASE_URL = 'https://checkout.postnl.nl/Button/Checkout';
56
 
57
  /**
58
+ * Xpath to public webshop ID setting.
59
  */
60
+ const XPATH_PUBLIC_WEBSHOP_ID = 'postnl/cif/public_webshop_id';
61
 
62
  /**
63
+ * Xpath to the 'instruction_cms_page' setting.
64
  */
65
+ const XPATH_INSTRUCTION_CMS_PAGE = 'postnl/checkout/instruction_cms_page';
66
 
67
  /**
68
+ * Xpath to 'show exclusively for mijnpakket users' setting.
69
  */
70
+ const XPATH_SHOW_EXCLUSIVELY_FOR_MIJNPAKKET_USERS = 'postnl/checkout/show_exclusively_for_mijnpakket_users';
71
 
72
  /**
73
+ * Gets the checkout URL.
74
  *
75
  * @return string
76
  */
82
  }
83
 
84
  /**
85
+ * Returns whether or not we need to check if the current customer is logged in with mijnpakket before showing
86
+ * PostNL Checkout.
87
+ *
88
+ * @return bool
89
+ */
90
+ public function getDoLoginCheck()
91
+ {
92
+ if ($this->hasDoLoginCheck()) {
93
+ return $this->_getData('do_login_check');
94
+ }
95
+
96
+ $storeId = Mage::app()->getStore()->getId();
97
+ $doLoginCheck = Mage::getStoreConfigFlag(self::XPATH_SHOW_EXCLUSIVELY_FOR_MIJNPAKKET_USERS, $storeId);
98
+
99
+ $this->setDoLoginCheck($doLoginCheck);
100
+ return $doLoginCheck;
101
+ }
102
+
103
+ /**
104
+ * Check if the button should be disabled.
105
  *
106
  * @return boolean
107
  */
115
  }
116
 
117
  /**
118
+ * Check if the button should be displayed.
119
  *
120
  * @return boolean
121
  */
153
  }
154
 
155
  /**
156
+ * Gets this webshop's public ID.
157
  *
158
  * @return string
159
  */
163
  return $this->getData('public_webshop_id');
164
  }
165
 
166
+ $webshopId = Mage::getStoreConfig(self::XPATH_PUBLIC_WEBSHOP_ID, Mage::app()->getStore()->getId());
167
 
168
  $this->setPublicWebshopId($webshopId);
169
  return $webshopId;
170
  }
171
 
172
  /**
173
+ * Gets the checkout button src attribute.
174
  *
175
  * @param boolean $forceDisabled
176
  *
199
  }
200
 
201
  /**
202
+ * Gets the URL of a CMS page containing instructions on how to use PostNL Checkout.
203
  *
204
  * @return boolean|string
205
  */
206
  public function getInstructionUrl()
207
  {
208
+ $instructionPage = Mage::getStoreConfig(self::XPATH_INSTRUCTION_CMS_PAGE, Mage::app()->getStore()->getId());
209
  if (!$instructionPage) {
210
  return false;
211
  }
215
  }
216
 
217
  /**
218
+ * Returns the block's html. Checks if the 'use_postnl_checkout' param is set. Otherwise returns an empty string.
219
  *
220
  * @return string
221
  */
app/code/community/TIG/PostNL/Block/Checkout/Cart/Js.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,144 +33,188 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
 
 
 
 
 
 
 
 
38
  */
39
- class TIG_PostNL_Block_Checkout_Cart_Js extends Mage_Core_Block_Template
40
  {
 
 
 
 
 
41
  /**
42
  * XML path for webshop ID setting
43
  */
44
  const XML_PATH_PUBLIC_WEBSHOP_ID = 'postnl/cif/public_webshop_id';
45
-
46
  /**
47
  * XML path of show_summary_page setting
48
  */
49
  const XML_PATH_SHOW_SUMMARY_PAGE = 'postnl/checkout/show_summary_page';
50
-
51
  /**
52
  * URLs of the primary PostNL Checkout JS files for test and live mode
53
  */
54
- const TEST_CHECKOUT_JS_URL = 'https://tppwscheckout-sandbox.e-id.nl/Checkout2/Scripts/Checkout.js';
55
- const LIVE_CHECKOUT_JS_URL = 'https://mijnpakket.postnl.nl/Checkout2/Scripts/Checkout.js';
56
-
 
 
57
  /**
58
  * Possible Checkout environments
59
  */
60
  const TEST_ENVIRONMENT = 'PostNL_OP_Checkout.environment_sandbox';
61
  const LIVE_ENVIRONMENT = 'PostNL_OP_Checkout.environment_production';
62
-
63
  /**
64
  * Gets the current store's webshop ID
65
- *
66
  * @return string
67
  */
68
  public function getWebshopId()
69
  {
70
- if ($this->getData('webshop_id')) {
71
- return $this->getData('webshop_id');
72
  }
73
-
74
  $storeId = Mage::app()->getStore()->getId();
75
-
76
  $webshopId = Mage::getStoreConfig(self::XML_PATH_PUBLIC_WEBSHOP_ID, $storeId);
77
-
78
  $this->setWebshopId($webshopId);
79
  return $webshopId;
80
  }
81
-
82
  /**
83
  * Gets the correct checkout js URL depending on whether PostNL Checkout is set to test or live mode
84
- *
85
  * @return string
86
  */
87
  public function getCheckoutJsUrl()
88
  {
89
- if ($this->getData('checkout_js_url')) {
90
- return $this->getData('checkout_js_url');
91
  }
92
-
93
  $storeId = Mage::app()->getStore()->getId();
94
-
95
  if (Mage::helper('postnl/checkout')->isTestMode($storeId)) {
96
  $url = self::TEST_CHECKOUT_JS_URL;
97
-
98
  $this->setCheckoutJsUrl($url);
99
  return $url;
100
  }
101
-
102
  $url = self::LIVE_CHECKOUT_JS_URL;
103
-
104
  $this->setCheckoutJsUrl($url);
105
  return $url;
106
  }
107
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  /**
109
  * Gets the current PostNL Checkout environment value
110
- *
111
  * @return string
112
  */
113
  public function getEnvironment()
114
  {
115
- if ($this->getData('environment')) {
116
- return $this->getData('environment');
117
  }
118
-
119
  $storeId = Mage::app()->getStore()->getId();
120
-
121
  if (Mage::helper('postnl/checkout')->isTestMode($storeId)) {
122
  $environment = self::TEST_ENVIRONMENT;
123
-
124
  $this->setEnvironment($environment);
125
  return $environment;
126
  }
127
-
128
  $environment = self::LIVE_ENVIRONMENT;
129
-
130
  $this->setEnvironment($environment);
131
  return $environment;
132
  }
133
-
134
  /**
135
  * Gets a URL to which the user will be redirected after finishing the order in the PostNL overlay.
136
- *
137
  * @return string
138
  */
139
  public function getContinueUrl()
140
  {
141
- if ($this->getData('continue_url')) {
142
- return $this->getData('continue_url');
143
  }
144
-
145
  $storeId = Mage::app()->getStore()->getId();
146
  $showConfirmPage = Mage::getStoreConfigFlag(self::XML_PATH_SHOW_SUMMARY_PAGE, $storeId);
147
  if ($showConfirmPage) {
148
  $url = $this->getUrl('postnl/checkout/summary');
149
-
150
  $this->setContinueUrl($url);
151
  return $url;
152
  }
153
-
154
  $url = $this->getUrl('postnl/checkout/finishCheckout');
155
-
156
  $this->setContinueUrl($url);
157
  return $url;
158
  }
159
-
160
  /**
161
  * Returns the block's html. Checks if the 'use_postnl_checkout' param is set. If not, returns and empty string
162
- *
163
  * @return string
164
  */
165
  protected function _toHtml()
166
  {
167
  $quote = Mage::getSingleton('checkout/session')->getQuote();
168
-
169
  $canUseCheckout = Mage::helper('postnl/checkout')->canUsePostnlCheckout($quote);
170
  if (!$canUseCheckout) {
171
  return '';
172
  }
173
-
174
  return parent::_toHtml();
175
  }
176
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasWebshopId()
40
+ * @method TIG_PostNL_Block_Checkout_Cart_Js setWebshopId(string $value)
41
+ * @method boolean hasCheckoutJsUrl()
42
+ * @method TIG_PostNL_Block_Checkout_Cart_Js setCheckoutJsUrl(string $value)
43
+ * @method boolean hasCheckoutPremiumJsUrl()
44
+ * @method TIG_PostNL_Block_Checkout_Cart_Js setCheckoutPremiumJsUrl(string $value)
45
+ * @method boolean hasEnvironment()
46
+ * @method TIG_PostNL_Block_Checkout_Cart_Js setEnvironment(string $value)
47
+ * @method boolean hasContinueUrl()
48
+ * @method TIG_PostNL_Block_Checkout_Cart_Js setContinueUrl(string $value)
49
  */
50
+ class TIG_PostNL_Block_Checkout_Cart_Js extends TIG_PostNL_Block_Core_Template
51
  {
52
+ /**
53
+ * @var string
54
+ */
55
+ protected $_eventPrefix = 'postnl_checkout_cart_js';
56
+
57
  /**
58
  * XML path for webshop ID setting
59
  */
60
  const XML_PATH_PUBLIC_WEBSHOP_ID = 'postnl/cif/public_webshop_id';
61
+
62
  /**
63
  * XML path of show_summary_page setting
64
  */
65
  const XML_PATH_SHOW_SUMMARY_PAGE = 'postnl/checkout/show_summary_page';
66
+
67
  /**
68
  * URLs of the primary PostNL Checkout JS files for test and live mode
69
  */
70
+ const TEST_CHECKOUT_JS_URL = 'https://tppwscheckout-sandbox.e-id.nl/Checkout2/Scripts/Checkout.js';
71
+ const LIVE_CHECKOUT_JS_URL = 'https://mijnpakket.postnl.nl/Checkout2/Scripts/Checkout.js';
72
+ const TEST_CHECKOUT_PREMIUM_JS_URL = 'https://tppwscheckout-sandbox.e-id.nl/Checkout2/CheckoutPremium.js';
73
+ const LIVE_CHECKOUT_PREMIUM_JS_URL = 'https://mijnpakket.postnl.nl/Checkout2/CheckoutPremium.js';
74
+
75
  /**
76
  * Possible Checkout environments
77
  */
78
  const TEST_ENVIRONMENT = 'PostNL_OP_Checkout.environment_sandbox';
79
  const LIVE_ENVIRONMENT = 'PostNL_OP_Checkout.environment_production';
80
+
81
  /**
82
  * Gets the current store's webshop ID
83
+ *
84
  * @return string
85
  */
86
  public function getWebshopId()
87
  {
88
+ if ($this->hasWebshopId()) {
89
+ return $this->_getData('webshop_id');
90
  }
91
+
92
  $storeId = Mage::app()->getStore()->getId();
93
+
94
  $webshopId = Mage::getStoreConfig(self::XML_PATH_PUBLIC_WEBSHOP_ID, $storeId);
95
+
96
  $this->setWebshopId($webshopId);
97
  return $webshopId;
98
  }
99
+
100
  /**
101
  * Gets the correct checkout js URL depending on whether PostNL Checkout is set to test or live mode
102
+ *
103
  * @return string
104
  */
105
  public function getCheckoutJsUrl()
106
  {
107
+ if ($this->hasCheckoutJsUrl()) {
108
+ return $this->_getData('checkout_js_url');
109
  }
110
+
111
  $storeId = Mage::app()->getStore()->getId();
112
+
113
  if (Mage::helper('postnl/checkout')->isTestMode($storeId)) {
114
  $url = self::TEST_CHECKOUT_JS_URL;
115
+
116
  $this->setCheckoutJsUrl($url);
117
  return $url;
118
  }
119
+
120
  $url = self::LIVE_CHECKOUT_JS_URL;
121
+
122
  $this->setCheckoutJsUrl($url);
123
  return $url;
124
  }
125
+
126
+ /**
127
+ * Gets the correct checkout premium js URL depending on whether PostNL Checkout is set to test or live mode
128
+ *
129
+ * @return string
130
+ */
131
+ public function getCheckoutPremiumJsUrl()
132
+ {
133
+ if ($this->hasCheckoutPremiumJsUrl()) {
134
+ return $this->_getData('checkout_premium_js_url');
135
+ }
136
+
137
+ $storeId = Mage::app()->getStore()->getId();
138
+
139
+ if (Mage::helper('postnl/checkout')->isTestMode($storeId)) {
140
+ $url = self::TEST_CHECKOUT_PREMIUM_JS_URL;
141
+
142
+ $this->setCheckoutPremiumJsUrl($url);
143
+ return $url;
144
+ }
145
+
146
+ $url = self::LIVE_CHECKOUT_PREMIUM_JS_URL;
147
+
148
+ $this->setCheckoutPremiumJsUrl($url);
149
+ return $url;
150
+ }
151
+
152
  /**
153
  * Gets the current PostNL Checkout environment value
154
+ *
155
  * @return string
156
  */
157
  public function getEnvironment()
158
  {
159
+ if ($this->hasEnvironment()) {
160
+ return $this->_getData('environment');
161
  }
162
+
163
  $storeId = Mage::app()->getStore()->getId();
164
+
165
  if (Mage::helper('postnl/checkout')->isTestMode($storeId)) {
166
  $environment = self::TEST_ENVIRONMENT;
167
+
168
  $this->setEnvironment($environment);
169
  return $environment;
170
  }
171
+
172
  $environment = self::LIVE_ENVIRONMENT;
173
+
174
  $this->setEnvironment($environment);
175
  return $environment;
176
  }
177
+
178
  /**
179
  * Gets a URL to which the user will be redirected after finishing the order in the PostNL overlay.
180
+ *
181
  * @return string
182
  */
183
  public function getContinueUrl()
184
  {
185
+ if ($this->hasContinueUrl()) {
186
+ return $this->_getData('continue_url');
187
  }
188
+
189
  $storeId = Mage::app()->getStore()->getId();
190
  $showConfirmPage = Mage::getStoreConfigFlag(self::XML_PATH_SHOW_SUMMARY_PAGE, $storeId);
191
  if ($showConfirmPage) {
192
  $url = $this->getUrl('postnl/checkout/summary');
193
+
194
  $this->setContinueUrl($url);
195
  return $url;
196
  }
197
+
198
  $url = $this->getUrl('postnl/checkout/finishCheckout');
199
+
200
  $this->setContinueUrl($url);
201
  return $url;
202
  }
203
+
204
  /**
205
  * Returns the block's html. Checks if the 'use_postnl_checkout' param is set. If not, returns and empty string
206
+ *
207
  * @return string
208
  */
209
  protected function _toHtml()
210
  {
211
  $quote = Mage::getSingleton('checkout/session')->getQuote();
212
+
213
  $canUseCheckout = Mage::helper('postnl/checkout')->canUsePostnlCheckout($quote);
214
  if (!$canUseCheckout) {
215
  return '';
216
  }
217
+
218
  return parent::_toHtml();
219
  }
220
  }
app/code/community/TIG/PostNL/Block/Checkout/Summary.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Checkout_Summary extends Mage_Sales_Block_Items_Abstract
@@ -42,7 +42,7 @@ class TIG_PostNL_Block_Checkout_Summary extends Mage_Sales_Block_Items_Abstract
42
  * PakjeGemak address type
43
  */
44
  const PAKJE_GEMAK_ADDRESS_TYPE = 'pakje_gemak';
45
-
46
  /**
47
  * Get active or custom quote
48
  *
@@ -53,49 +53,49 @@ class TIG_PostNL_Block_Checkout_Summary extends Mage_Sales_Block_Items_Abstract
53
  if ($this->hasQuote()) {
54
  return $this->getData('quote');
55
  }
56
-
57
  $quote = Mage::registry('current_quote');
58
-
59
  $this->setQuote($quote);
60
  return $quote;
61
  }
62
-
63
  /**
64
  * Get all visible items in the quote
65
- *
66
  * @return array
67
  */
68
  public function getItems()
69
  {
70
  $quote = $this->getQuote();
71
-
72
  return $quote->getAllVisibleItems();
73
  }
74
-
75
  /**
76
  * Gets an optional pakje_gemak address from the quote
77
- *
78
  * @return boolean | Mage_Sales_Model_Quote_Address
79
  */
80
  public function getPakjeGemakAddress()
81
  {
82
  $quote = $this->getQuote();
83
-
84
  $addresses = $quote->getAddressesCollection();
85
-
86
  foreach ($addresses as $address) {
87
  if ($address->getAddressType() == self::PAKJE_GEMAK_ADDRESS_TYPE) {
88
  $address = Mage::getModel('sales/quote_address')->load($address->getId());
89
  return $address;
90
  }
91
  }
92
-
93
  return false;
94
  }
95
-
96
  /**
97
  * Gets the shipping address's shipping description
98
- *
99
  * @return string
100
  */
101
  public function getShippingDescription()
@@ -105,13 +105,13 @@ class TIG_PostNL_Block_Checkout_Summary extends Mage_Sales_Block_Items_Abstract
105
  if ($address->hasShippingDescription()) {
106
  return $address->getShippingDescription();
107
  }
108
-
109
  $method = $address->getShippingMethod();
110
 
111
  if (!$method) {
112
  return '';
113
  }
114
-
115
  $shippingDescription = '';
116
  foreach ($address->getAllShippingRates() as $rate) {
117
  if ($rate->getCode() == $method) {
@@ -120,44 +120,51 @@ class TIG_PostNL_Block_Checkout_Summary extends Mage_Sales_Block_Items_Abstract
120
  break;
121
  }
122
  }
123
-
124
  return $shippingDescription;
125
  }
126
-
 
 
 
127
  public function getPaymentOption()
128
  {
129
  $paymentData = Mage::registry('postnl_payment_data');
 
 
 
 
130
  $methodCode = $paymentData['method'];
131
  $optionValue = $paymentData['option'];
132
-
133
  if (!$optionValue) {
134
  return false;
135
  }
136
-
137
  $optionConversionArray = Mage::helper('postnl/checkout')->getOptionConversionArray();
138
  if (!array_key_exists($methodCode, $optionConversionArray)) {
139
  return $optionValue;
140
  }
141
-
142
  $methodArray = $optionConversionArray[$methodCode];
143
  if (!array_key_exists($optionValue, $methodArray)) {
144
  return $optionValue;
145
  }
146
-
147
  $convertedOption = $methodArray[$optionValue];
148
  return $convertedOption;
149
  }
150
-
151
  /**
152
  * Gets the PostNL order associated with the current quote
153
- *
154
- * @return TIG_PostNL_Model_Checkout_Order
155
  */
156
  public function getPostnlOrder()
157
  {
158
  $quote = $this->getQuote();
159
- $postnlOrder = Mage::getModel('postnl_checkout/order')->load($quote->getId(), 'quote_id');
160
-
161
  return $postnlOrder;
162
  }
163
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Block_Checkout_Summary extends Mage_Sales_Block_Items_Abstract
42
  * PakjeGemak address type
43
  */
44
  const PAKJE_GEMAK_ADDRESS_TYPE = 'pakje_gemak';
45
+
46
  /**
47
  * Get active or custom quote
48
  *
53
  if ($this->hasQuote()) {
54
  return $this->getData('quote');
55
  }
56
+
57
  $quote = Mage::registry('current_quote');
58
+
59
  $this->setQuote($quote);
60
  return $quote;
61
  }
62
+
63
  /**
64
  * Get all visible items in the quote
65
+ *
66
  * @return array
67
  */
68
  public function getItems()
69
  {
70
  $quote = $this->getQuote();
71
+
72
  return $quote->getAllVisibleItems();
73
  }
74
+
75
  /**
76
  * Gets an optional pakje_gemak address from the quote
77
+ *
78
  * @return boolean | Mage_Sales_Model_Quote_Address
79
  */
80
  public function getPakjeGemakAddress()
81
  {
82
  $quote = $this->getQuote();
83
+
84
  $addresses = $quote->getAddressesCollection();
85
+
86
  foreach ($addresses as $address) {
87
  if ($address->getAddressType() == self::PAKJE_GEMAK_ADDRESS_TYPE) {
88
  $address = Mage::getModel('sales/quote_address')->load($address->getId());
89
  return $address;
90
  }
91
  }
92
+
93
  return false;
94
  }
95
+
96
  /**
97
  * Gets the shipping address's shipping description
98
+ *
99
  * @return string
100
  */
101
  public function getShippingDescription()
105
  if ($address->hasShippingDescription()) {
106
  return $address->getShippingDescription();
107
  }
108
+
109
  $method = $address->getShippingMethod();
110
 
111
  if (!$method) {
112
  return '';
113
  }
114
+
115
  $shippingDescription = '';
116
  foreach ($address->getAllShippingRates() as $rate) {
117
  if ($rate->getCode() == $method) {
120
  break;
121
  }
122
  }
123
+
124
  return $shippingDescription;
125
  }
126
+
127
+ /**
128
+ * @return boolean|string
129
+ */
130
  public function getPaymentOption()
131
  {
132
  $paymentData = Mage::registry('postnl_payment_data');
133
+ if (!isset($paymentData['method']) || !isset($paymentData['option'])) {
134
+ return false;
135
+ }
136
+
137
  $methodCode = $paymentData['method'];
138
  $optionValue = $paymentData['option'];
139
+
140
  if (!$optionValue) {
141
  return false;
142
  }
143
+
144
  $optionConversionArray = Mage::helper('postnl/checkout')->getOptionConversionArray();
145
  if (!array_key_exists($methodCode, $optionConversionArray)) {
146
  return $optionValue;
147
  }
148
+
149
  $methodArray = $optionConversionArray[$methodCode];
150
  if (!array_key_exists($optionValue, $methodArray)) {
151
  return $optionValue;
152
  }
153
+
154
  $convertedOption = $methodArray[$optionValue];
155
  return $convertedOption;
156
  }
157
+
158
  /**
159
  * Gets the PostNL order associated with the current quote
160
+ *
161
+ * @return TIG_PostNL_Model_Core_Order
162
  */
163
  public function getPostnlOrder()
164
  {
165
  $quote = $this->getQuote();
166
+ $postnlOrder = Mage::getModel('postnl_core/order')->load($quote->getId(), 'quote_id');
167
+
168
  return $postnlOrder;
169
  }
170
  }
app/code/community/TIG/PostNL/Block/Core/JsTranslate.php ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Block_Core_JsTranslate extends TIG_PostNL_Block_Core_Template
40
+ {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_core_jstemplate';
45
+
46
+ /**
47
+ * Translate file name
48
+ */
49
+ const JAVASCRIPT_TRANSLATE_CONFIG_FILENAME = 'jstranslator.xml';
50
+
51
+ /**
52
+ * The template file used by this block.
53
+ *
54
+ * @var string app/design/frontend/base/default/template/TIG/PostNL/page/html/js_translate.phtml
55
+ */
56
+ protected $_template = 'TIG/PostNL/core/page/html/js_translate.phtml';
57
+
58
+ /**
59
+ * Array of JS translations
60
+ *
61
+ * @var array|null
62
+ */
63
+ protected $_translateData = null;
64
+
65
+ /**
66
+ * Translate config
67
+ *
68
+ * @var Varien_Simplexml_Config|null
69
+ */
70
+ protected $_config = null;
71
+
72
+ /**
73
+ * @param array|null $translateData
74
+ *
75
+ * @return $this
76
+ */
77
+ public function setTranslateData($translateData)
78
+ {
79
+ $this->_translateData = $translateData;
80
+
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * @return array|null
86
+ */
87
+ public function getTranslateData()
88
+ {
89
+ return $this->_translateData;
90
+ }
91
+
92
+ /**
93
+ * @param null|Varien_Simplexml_Config $config
94
+ *
95
+ * @return TIG_PostNL_Block_Core_JsTranslate
96
+ */
97
+ public function setConfig($config)
98
+ {
99
+ $this->_config = $config;
100
+
101
+ return $this;
102
+ }
103
+
104
+ /**
105
+ * @return null|Varien_Simplexml_Config
106
+ */
107
+ public function getConfig()
108
+ {
109
+ return $this->_config;
110
+ }
111
+
112
+ /**
113
+ * Get JS translations for PostNL JS files.
114
+ *
115
+ * @return string
116
+ */
117
+ public function getPostnlTranslateData()
118
+ {
119
+ $messages = $this->_getTranslateData();
120
+
121
+ $json = Mage::helper('core')->jsonEncode($messages);
122
+ return $json;
123
+ }
124
+
125
+ /**
126
+ * Get JS translations from jstranslate.xml files. These files are only supported since Magento 1.7, so we made
127
+ * this block to provide forwards compatibility to Magento 1.6.
128
+ *
129
+ * Because Magento 1.6 doesn't have a cache entry for these xml files, we don't use caching.
130
+ *
131
+ * @return array
132
+ */
133
+ protected function _getTranslateData()
134
+ {
135
+ if ($this->getTranslateData() !== null) {
136
+ return $this->getTranslateData();
137
+ }
138
+
139
+ $translateData = array();
140
+ $messages = $this->_getXmlConfig()->getXpath('*/message');
141
+
142
+ if (empty($messages)) {
143
+ $this->setTranslateData($translateData);
144
+
145
+ return $translateData;
146
+ }
147
+
148
+ $helper = Mage::helper('postnl');
149
+
150
+ /**
151
+ * @var Varien_Simplexml_Element $message
152
+ */
153
+ foreach ($messages as $message) {
154
+ $messageText = (string) $message;
155
+ $module = $message->getParent()->getAttribute("module");
156
+
157
+ /**
158
+ * We only want to parse PostNL's translations.
159
+ */
160
+ if (!$module || $module != 'postnl') {
161
+ continue;
162
+ }
163
+ $translateData[$messageText] = $helper->__($messageText);
164
+ }
165
+
166
+ foreach ($translateData as $key => $value) {
167
+ if ($key == $value) {
168
+ unset($translateData[$key]);
169
+ }
170
+ }
171
+
172
+ $this->setTranslateData($translateData);
173
+
174
+ return $translateData;
175
+ }
176
+
177
+ /**
178
+ * Load config from files and try to cache it
179
+ *
180
+ * @return Varien_Simplexml_Config
181
+ */
182
+ protected function _getXmlConfig()
183
+ {
184
+ if ($this->getConfig() !== null)
185
+ return $this->getConfig();
186
+
187
+ $xmlConfig = new Varien_Simplexml_Config();
188
+ $xmlConfig->loadString('<?xml version="1.0"?><jstranslator></jstranslator>');
189
+ Mage::getConfig()->loadModulesConfiguration(self::JAVASCRIPT_TRANSLATE_CONFIG_FILENAME, $xmlConfig);
190
+
191
+ $this->setConfig($xmlConfig);
192
+
193
+ return $xmlConfig;
194
+ }
195
+
196
+ /**
197
+ * Check if the current Magento version is below 1.7 or 1.12 for Magento community and enterprise, respectively. If
198
+ * so, render the template. If not, return an empty string.
199
+ *
200
+ * @return string
201
+ */
202
+ protected function _toHtml()
203
+ {
204
+ $helper = Mage::helper('postnl');
205
+ if (!$helper->isEnterprise() && version_compare(Mage::getVersion(), '1.7.0.0', '>=')) {
206
+ return '';
207
+ }
208
+
209
+ if ($helper->isEnterprise() && version_compare(Mage::getVersion(), '1.12.0.0', '>=')) {
210
+ return '';
211
+ }
212
+
213
+ return parent::_toHtml();
214
+ }
215
+ }
app/code/community/TIG/PostNL/Block/Core/ShippingStatus.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,67 +33,75 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Block_Core_ShippingStatus extends Mage_Core_Block_Template
40
  {
 
 
 
 
 
41
  /**
42
  * Checks if a given shipment has been confirmed with PostNL
43
- *
44
  * @param Mage_Sales_Model_Order_Shipment
45
- *
46
  * @return boolean
47
  */
48
  public function isConfirmed($shipment)
49
  {
 
 
 
50
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
51
  if ($postnlShipment->getConfirmStatus() == $postnlShipment::CONFIRM_STATUS_CONFIRMED) {
52
  return true;
53
  }
54
-
55
  return false;
56
  }
57
-
58
  /**
59
  * Checks if a given shipment has been confirmed with PostNL
60
- *
61
  * @param Mage_Sales_Model_Order_Shipment
62
- *
63
  * @return string
64
  */
65
  public function getConfirmedAt($shipment)
66
  {
67
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
68
-
69
  $confirmedAt = Mage::helper('core')->formatDate($postnlShipment->getConfirmedAt(), 'medium', false);
70
-
71
  return $confirmedAt;
72
  }
73
-
74
  /**
75
  * Checks if a given shipment has been confirmed with PostNL
76
- *
77
  * @param Mage_Sales_Model_Order_Shipment
78
- *
79
  * @return boolean
80
  */
81
  public function getTrackingUrl($shipment)
82
  {
83
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
84
-
85
  $barcodeUrl = $postnlShipment->getBarcodeUrl(true);
86
-
87
  $trackingUrl = "<a href={$barcodeUrl} title='mijnpakket' target='_blank'>"
88
  . $this->__('here')
89
  . '</a>';
90
-
91
  return $trackingUrl;
92
  }
93
-
94
  /**
95
  * Check if the PostNL module is enabled. Otherwise return an empty string.
96
- *
97
  * @return string | Mage_Core_Block_Template::_toHtml()
98
  */
99
  protected function _toHtml()
@@ -101,7 +109,7 @@ class TIG_PostNL_Block_Core_ShippingStatus extends Mage_Core_Block_Template
101
  if (!Mage::helper('postnl')->isEnabled()) {
102
  return '';
103
  }
104
-
105
  return parent::_toHtml();
106
  }
107
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Block_Core_ShippingStatus extends TIG_PostNL_Block_Core_Template
40
  {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_core_shippingstatus';
45
+
46
  /**
47
  * Checks if a given shipment has been confirmed with PostNL
48
+ *
49
  * @param Mage_Sales_Model_Order_Shipment
50
+ *
51
  * @return boolean
52
  */
53
  public function isConfirmed($shipment)
54
  {
55
+ /**
56
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipment
57
+ */
58
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
59
  if ($postnlShipment->getConfirmStatus() == $postnlShipment::CONFIRM_STATUS_CONFIRMED) {
60
  return true;
61
  }
62
+
63
  return false;
64
  }
65
+
66
  /**
67
  * Checks if a given shipment has been confirmed with PostNL
68
+ *
69
  * @param Mage_Sales_Model_Order_Shipment
70
+ *
71
  * @return string
72
  */
73
  public function getConfirmedAt($shipment)
74
  {
75
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
76
+
77
  $confirmedAt = Mage::helper('core')->formatDate($postnlShipment->getConfirmedAt(), 'medium', false);
78
+
79
  return $confirmedAt;
80
  }
81
+
82
  /**
83
  * Checks if a given shipment has been confirmed with PostNL
84
+ *
85
  * @param Mage_Sales_Model_Order_Shipment
86
+ *
87
  * @return boolean
88
  */
89
  public function getTrackingUrl($shipment)
90
  {
91
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
92
+
93
  $barcodeUrl = $postnlShipment->getBarcodeUrl(true);
94
+
95
  $trackingUrl = "<a href={$barcodeUrl} title='mijnpakket' target='_blank'>"
96
  . $this->__('here')
97
  . '</a>';
98
+
99
  return $trackingUrl;
100
  }
101
+
102
  /**
103
  * Check if the PostNL module is enabled. Otherwise return an empty string.
104
+ *
105
  * @return string | Mage_Core_Block_Template::_toHtml()
106
  */
107
  protected function _toHtml()
109
  if (!Mage::helper('postnl')->isEnabled()) {
110
  return '';
111
  }
112
+
113
  return parent::_toHtml();
114
  }
115
  }
app/code/community/TIG/PostNL/Block/Core/Template.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ abstract class TIG_PostNL_Block_Core_Template extends Mage_Core_Block_Template
40
+ {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_core_template';
45
+
46
+ /**
47
+ * Renders a template block. Also throws 2 events based on the current event prefix.
48
+ *
49
+ * @return string
50
+ */
51
+ protected function _toHtml()
52
+ {
53
+ Mage::dispatchEvent($this->_eventPrefix . '_to_html_before');
54
+
55
+ $html = parent::_toHtml();
56
+
57
+ Mage::dispatchEvent($this->_eventPrefix . '_to_html_after');
58
+ return $html;
59
+ }
60
+ }
app/code/community/TIG/PostNL/Block/DeliveryOptions/Checkout/AddPhoneNumber.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasPhoneNumber()
40
+ * @method TIG_PostNL_Block_DeliveryOptions_Checkout_AddPhoneNumber setPhoneNumber(string $phoneNumber)
41
+ * @method boolean hasShippingAddress()
42
+ * @method TIG_PostNL_Block_DeliveryOptions_Checkout_AddPhoneNumber setShippingAddress(Mage_Sales_Model_Quote_Address $address)
43
+ * @method boolean hasQuote()
44
+ * @method TIG_PostNL_Block_DeliveryOptions_Checkout_AddPhoneNumber setQuote(Mage_Sales_Model_Quote $quote)
45
+ */
46
+ class TIG_PostNL_Block_DeliveryOptions_Checkout_AddPhoneNumber extends TIG_PostNL_Block_DeliveryOptions_Template
47
+ {
48
+ /**
49
+ * @var string
50
+ */
51
+ protected $_eventPrefix = 'postnl_deliveryoptions_checkout_addphonenumber';
52
+
53
+ /**
54
+ * @var string
55
+ */
56
+ protected $_template = 'TIG/PostNL/delivery_options/addphonenumber.phtml';
57
+
58
+ /**
59
+ * Gets a phone number.
60
+ *
61
+ * @return string
62
+ */
63
+ public function getPhoneNumber()
64
+ {
65
+ if ($this->hasPhoneNumber()) {
66
+ return $this->_getData('phone_number');
67
+ }
68
+
69
+ $shippingAddress = $this->getShippingAddress();
70
+ $phoneNumber = $shippingAddress->getTelephone();
71
+
72
+ /**
73
+ * OSC often replaces missing required fields by a single dash. We want to avoid this behaviour.
74
+ */
75
+ if ($phoneNumber == '-') {
76
+ $phoneNumber = '';
77
+ }
78
+
79
+ $this->setPhoneNumber($phoneNumber);
80
+ return $phoneNumber;
81
+ }
82
+
83
+ /**
84
+ * Gets a shipping address object.
85
+ *
86
+ * @return Mage_Sales_Model_Quote_Address
87
+ */
88
+ public function getShippingAddress()
89
+ {
90
+ if ($this->hasShippingAddress()) {
91
+ return $this->_getData('shipping_address');
92
+ }
93
+
94
+ $quote = $this->getQuote();
95
+ if (!$quote) {
96
+ $shippingAddress = Mage::getModel('sales/quote_address');
97
+
98
+ $this->setShippingAddress($shippingAddress);
99
+ return $shippingAddress;
100
+ }
101
+
102
+ $shippingAddress = $quote->getShippingAddress();
103
+
104
+ $this->setShippingAddress($shippingAddress);
105
+ return $shippingAddress;
106
+ }
107
+
108
+ /**
109
+ * Get the current quote.
110
+ *
111
+ * @return Mage_Sales_Model_Quote
112
+ */
113
+ public function getQuote()
114
+ {
115
+ if ($this->hasQuote()) {
116
+ return $this->_getData('quote');
117
+ }
118
+
119
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
120
+
121
+ $this->setQuote($quote);
122
+ return $quote;
123
+ }
124
+ }
app/code/community/TIG/PostNL/Block/DeliveryOptions/Checkout/DeliveryOptions.php ADDED
@@ -0,0 +1,560 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method string getMethodName()
40
+ * @method TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions setStreetnameField(int $value)
41
+ * @method TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions setHousenumberField(int $value)
42
+ * @method boolean hasTaxDisplayType()
43
+ * @method TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions setTaxDisplayType(int $value)
44
+ */
45
+ class TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions extends TIG_PostNL_Block_DeliveryOptions_Template
46
+ {
47
+ /**
48
+ * @var string
49
+ */
50
+ protected $_eventPrefix = 'postnl_deliveryoptions_checkout_deliveryoptions';
51
+
52
+ /**
53
+ * Xpath to 'allow_streetview' setting.
54
+ */
55
+ const XPATH_ALLOW_STREETVIEW = 'postnl/delivery_options/allow_streetview';
56
+
57
+ /**
58
+ * Currently selected shipping address.
59
+ *
60
+ * @var Mage_Sales_Model_Quote_Address|null
61
+ */
62
+ protected $_shippingAddress = null;
63
+
64
+ /**
65
+ * The earliest possible delivery date.
66
+ *
67
+ * @var null|string
68
+ */
69
+ protected $_deliveryDate = null;
70
+
71
+ /**
72
+ * Set the currently selected shipping address.
73
+ *
74
+ * @param Mage_Sales_Model_Quote_Address|null $shippingAddress
75
+ *
76
+ * @return TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions
77
+ */
78
+ public function setShippingAddress($shippingAddress)
79
+ {
80
+ $this->_shippingAddress = $shippingAddress;
81
+
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Gets the current quote.
87
+ *
88
+ * @return Mage_Sales_Model_Quote
89
+ */
90
+ public function getQuote()
91
+ {
92
+ if ($this->hasData('quote')) {
93
+ return $this->_getData('quote');
94
+ }
95
+
96
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
97
+
98
+ $this->setData('quote', $quote);
99
+ return $quote;
100
+ }
101
+
102
+ /**
103
+ * Get the currently selected shipping address.
104
+ *
105
+ * @return Mage_Sales_Model_Quote_Address|null
106
+ */
107
+ public function getShippingAddress()
108
+ {
109
+ $shippingAddress = $this->_shippingAddress;
110
+ if ($shippingAddress !== null) {
111
+ return $shippingAddress;
112
+ }
113
+
114
+ $shippingAddress = $this->_getShippingAddress();
115
+
116
+ if (!$shippingAddress) {
117
+ $shippingAddress = Mage::getModel('sales/quote_address');
118
+ }
119
+
120
+ $this->setShippingAddress($shippingAddress);
121
+ return $shippingAddress;
122
+ }
123
+
124
+ /**
125
+ * Gets a shipping address from the current quote or from the customer if the customer is logged in.
126
+ *
127
+ * @return Mage_Customer_Model_Address|Mage_Sales_Model_Quote_Address
128
+ */
129
+ protected function _getShippingAddress()
130
+ {
131
+ $quote = $this->getQuote();
132
+ $shippingAddress = $quote->getShippingAddress();
133
+
134
+ /**
135
+ * If we have billing data, the customer may still be entering their address, so we shouldn't do anything else
136
+ * for now.
137
+ */
138
+ if (Mage::app()->getRequest()->getPost('billing')) {
139
+ return $shippingAddress;
140
+ }
141
+
142
+ $customerHelper = Mage::helper('customer');
143
+
144
+ /**
145
+ * OneStepCheckout sometimes stores a partial shipping address in the quote. This hack is meant to detect this
146
+ * and retrieve the full address from the customer's account if available. This is only done if we have no
147
+ * billing data in the $_POST superglobal to prevent conflicts with customers still entering their address.
148
+ */
149
+ if (
150
+ (
151
+ !$shippingAddress->getPostcode()
152
+ || $shippingAddress->getPostcode() == '-'
153
+ || !$shippingAddress->getStreetFull()
154
+ )
155
+ && $shippingAddress->getId()
156
+ && $shippingAddress->getCustomerAddressId()
157
+ && $customerHelper->isLoggedIn()
158
+ ) {
159
+ $shippingAddress = $quote->getCustomer()->getAddressById($shippingAddress->getCustomerAddressId());
160
+ }
161
+
162
+ /**
163
+ * If we still don't have a full address, get the customer's default shipping address if available.
164
+ */
165
+ if (
166
+ (
167
+ !$shippingAddress->getPostcode()
168
+ || $shippingAddress->getPostcode() == '-'
169
+ || !$shippingAddress->getStreetFull()
170
+ )
171
+ && $customerHelper->isLoggedIn()
172
+ && $customerHelper->customerHasAddresses()
173
+ ) {
174
+ $shippingAddress = Mage::getSingleton('customer/session')->getCustomer()->getDefaultShippingAddress();
175
+ }
176
+
177
+ return $shippingAddress;
178
+ }
179
+
180
+ /**
181
+ * Get the currently selected shipping address's postcode.
182
+ *
183
+ * @return string
184
+ */
185
+ public function getPostcode()
186
+ {
187
+ $postcode = $this->getShippingAddress()->getPostcode();
188
+
189
+ $postcode = str_replace(' ', '', strtoupper($postcode));
190
+
191
+ return $postcode;
192
+ }
193
+
194
+ /**
195
+ * Get the earliest possible delivery date.
196
+ *
197
+ * @return null|string
198
+ */
199
+ public function getDeliveryDate()
200
+ {
201
+ $deliveryDate = $this->_deliveryDate;
202
+
203
+ if ($deliveryDate !== null) {
204
+ return $deliveryDate;
205
+ }
206
+
207
+ $quote = $this->getQuote();
208
+ $postcode = $this->getPostcode();
209
+
210
+ try {
211
+ $deliveryDate = $this->_getDeliveryDate($postcode, $quote);
212
+ } catch (Exception $e) {
213
+ Mage::helper('postnl')->logException($e);
214
+
215
+ $tomorrow = strtotime('tomorrow', Mage::getModel('core/date')->timestamp());
216
+ $deliveryDate = date('d-m-Y', $tomorrow);
217
+ }
218
+
219
+ $this->setDeliveryDate($deliveryDate);
220
+ return $deliveryDate;
221
+ }
222
+
223
+ /**
224
+ * Set the earliest possible delivery date.
225
+ *
226
+ * @param string $deliveryDate
227
+ *
228
+ * @return TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions
229
+ */
230
+ public function setDeliveryDate($deliveryDate)
231
+ {
232
+ $this->_deliveryDate = $deliveryDate;
233
+
234
+ return $this;
235
+ }
236
+
237
+ /**
238
+ * Get the fee charged for evening timeframes.
239
+ *
240
+ * @param boolean $formatted
241
+ * @param boolean $includingTax
242
+ *
243
+ * @return float
244
+ */
245
+ public function getEveningFee($formatted = false, $includingTax = true)
246
+ {
247
+ return Mage::helper('postnl/deliveryOptions')->getEveningFee($formatted, $includingTax);
248
+ }
249
+
250
+ /**
251
+ * Get the fee charged for PakjeGemak Express.
252
+ *
253
+ * @param boolean $formatted
254
+ * @param boolean $includingTax
255
+ *
256
+ * @return float
257
+ */
258
+ public function getExpressFee($formatted = false, $includingTax = true)
259
+ {
260
+ return Mage::helper('postnl/deliveryOptions')->getExpressFee($formatted, $includingTax);
261
+ }
262
+
263
+ /**
264
+ * Get either the evening or express fee as a float or int.
265
+ *
266
+ * @param string $type
267
+ * @param boolean $includingTax
268
+ *
269
+ * @return float|int
270
+ */
271
+ public function getFee($type, $includingTax = false) {
272
+ switch ($type) {
273
+ case 'evening':
274
+ $fee = $this->getEveningFee(false, $includingTax);
275
+ break;
276
+ case 'express':
277
+ $fee = $this->getExpressFee(false, $includingTax);
278
+ break;
279
+ default:
280
+ return 0;
281
+ }
282
+
283
+ /**
284
+ * If no fee is entered or an invalid value was entered, return an empty string.
285
+ */
286
+ if (!$fee || $fee > 2 || $fee < 0) {
287
+ return 0;
288
+ }
289
+
290
+ return $fee;
291
+ }
292
+
293
+ /**
294
+ * Get either the evening or the express fee as a currency value.
295
+ *
296
+ * @param string $type
297
+ * @param boolean $includingTax
298
+ *
299
+ * @return string
300
+ */
301
+ public function getFeeText($type, $includingTax = false)
302
+ {
303
+ switch ($type) {
304
+ case 'evening':
305
+ $feeText = $this->getEveningFee(true, $includingTax);
306
+ break;
307
+ case 'express':
308
+ $feeText = $this->getExpressFee(true, $includingTax);
309
+ break;
310
+ default:
311
+ return 0;
312
+ }
313
+
314
+ return $feeText;
315
+ }
316
+
317
+ /**
318
+ * Get the field used for the address's streetname.
319
+ *
320
+ * @return int
321
+ */
322
+ public function getStreetnameField()
323
+ {
324
+ if ($this->hasData('streetname_field')) {
325
+ return $this->_getData('streetname_field');
326
+ }
327
+
328
+ $streetnameField = Mage::helper('postnl/addressValidation')->getStreetnameField();
329
+
330
+ $this->setStreetnameField($streetnameField);
331
+ return $streetnameField;
332
+ }
333
+
334
+ /**
335
+ * Get the field used for the address's housenumber.
336
+ *
337
+ * @return int
338
+ */
339
+ public function getHousenumberField()
340
+ {
341
+ if ($this->hasData('housenumber_field')) {
342
+ return $this->_getData('housenumber_field');
343
+ }
344
+
345
+ $housenumberField = Mage::helper('postnl/addressValidation')->getHousenumberField();
346
+
347
+ $this->setHousenumberField($housenumberField);
348
+ return $housenumberField;
349
+ }
350
+
351
+ /**
352
+ * Gets an array containing the selected shipping address's streetname, housenumber and housenumber extension.
353
+ *
354
+ * @return array
355
+ */
356
+ public function getStreetData()
357
+ {
358
+ $storeId = Mage::app()->getStore()->getId();
359
+ $address = $this->getShippingAddress();
360
+
361
+ try {
362
+ $streetData = Mage::helper('postnl/cif')->getStreetData($storeId, $address, false);
363
+ } catch (Exception $e) {
364
+ Mage::helper('postnl')->logException($e);
365
+
366
+ $streetData = array(
367
+ 'streetname' => '',
368
+ 'housenumber' => '',
369
+ 'housenumberExtension' => '',
370
+ 'fullStreet' => '',
371
+ );
372
+ }
373
+ return $streetData;
374
+ }
375
+
376
+ /**
377
+ * Gets tax display type.
378
+ *
379
+ * @return int
380
+ */
381
+ public function getTaxDisplayType()
382
+ {
383
+ if ($this->hasTaxDisplayType()) {
384
+ return $this->_getData('tax_display_type');
385
+ }
386
+
387
+ $taxDisplayType = Mage::getSingleton('tax/config')->getShippingPriceDisplayType();
388
+
389
+ $this->setTaxDisplayType($taxDisplayType);
390
+ return $taxDisplayType;
391
+ }
392
+
393
+ /**
394
+ * Checks whether PakjeGemak locations are allowed.
395
+ *
396
+ * @return boolean
397
+ */
398
+ public function canUsePakjeGemak()
399
+ {
400
+ $storeId = Mage::app()->getStore()->getId();
401
+
402
+ $canUsePakjeGemak = Mage::helper('postnl/deliveryOptions')->canUsePakjeGemak($storeId);
403
+ return $canUsePakjeGemak;
404
+ }
405
+
406
+ /**
407
+ * Checks whether PakjeGemak Express locations are allowed.
408
+ *
409
+ * @return boolean
410
+ */
411
+ public function canUsePakjeGemakExpress()
412
+ {
413
+ $storeId = Mage::app()->getStore()->getId();
414
+
415
+ $canUsePakjeGemakExpress = Mage::helper('postnl/deliveryOptions')->canUsePakjeGemakExpress($storeId);
416
+ return $canUsePakjeGemakExpress;
417
+ }
418
+
419
+ /**
420
+ * Checks whether Pakket Automaat locations are allowed.
421
+ *
422
+ * @return boolean
423
+ */
424
+ public function canUsePakketAutomaat()
425
+ {
426
+ $storeId = Mage::app()->getStore()->getId();
427
+
428
+ $canUsePakketAutomaat = Mage::helper('postnl/deliveryOptions')->canUsePakketAutomaat($storeId);
429
+ return $canUsePakketAutomaat;
430
+ }
431
+
432
+ /**
433
+ * Checks whether timeframes are allowed.
434
+ *
435
+ * @return boolean
436
+ */
437
+ public function canUseTimeframes()
438
+ {
439
+ $storeId = Mage::app()->getStore()->getId();
440
+
441
+ $canUsePakketAutomaat = Mage::helper('postnl/deliveryOptions')->canUseTimeframes($storeId);
442
+ return $canUsePakketAutomaat;
443
+ }
444
+
445
+ /**
446
+ * Checks whether evening timeframes are allowed.
447
+ *
448
+ * @return boolean
449
+ */
450
+ public function canUseEveningTimeframes()
451
+ {
452
+ $storeId = Mage::app()->getStore()->getId();
453
+
454
+ $canUsePakketAutomaat = Mage::helper('postnl/deliveryOptions')->canUseEveningTimeframes($storeId);
455
+ return $canUsePakketAutomaat;
456
+ }
457
+
458
+ /**
459
+ * Checks whether google streetview is allowed.
460
+ *
461
+ * @return boolean
462
+ */
463
+ public function canUseStreetView()
464
+ {
465
+ $storeId = Mage::app()->getStore()->getId();
466
+
467
+ $streetviewAllowed = Mage::getStoreConfigFlag(self::XPATH_ALLOW_STREETVIEW, $storeId);
468
+ return $streetviewAllowed;
469
+ }
470
+
471
+ /**
472
+ * Checks whether the current theme uses cufon.
473
+ *
474
+ * @return boolean
475
+ */
476
+ public function getUseCufon()
477
+ {
478
+ /**
479
+ * @var Varien_Simplexml_Element $theme
480
+ */
481
+ $theme = $this->getCurrentTheme();
482
+ if (!$theme) {
483
+ return false;
484
+ }
485
+
486
+ /**
487
+ * @var Varien_Simplexml_Element $files
488
+ */
489
+ $useCufon = (string) $theme->use_cufon;
490
+ if (!$useCufon) {
491
+ return false;
492
+ }
493
+
494
+ if ($useCufon === '1' || strcasecmp($useCufon, 'true') === 0) {
495
+ return true;
496
+ }
497
+
498
+ return false;
499
+ }
500
+
501
+ /**
502
+ * Checks if debug mode is allowed. Debug mode is enabled if the PostNl extension's debug mode is set to 'full'.
503
+ *
504
+ * @return bool
505
+ */
506
+ public function isDebugEnabled()
507
+ {
508
+ $helper = Mage::helper('postnl');
509
+ $debugMode = $helper->getDebugMode();
510
+
511
+ if ($debugMode > 1) {
512
+ return true;
513
+ }
514
+
515
+ return false;
516
+ }
517
+
518
+ /**
519
+ * Checks if delivery options are allowed for the current quote.
520
+ *
521
+ * @return bool
522
+ */
523
+ public function canUseDeliveryOptions()
524
+ {
525
+ $helper = Mage::helper('postnl/deliveryOptions');
526
+ return $helper->canUseDeliveryOptions($this->getQuote());
527
+ }
528
+
529
+ /**
530
+ * get the first possible delivery date from PostNL.
531
+ *
532
+ * @param string $postcode
533
+ * @param Mage_Sales_Model_Quote $quote
534
+ *
535
+ * @throws TIG_PostNL_Exception
536
+ *
537
+ * @return string
538
+ */
539
+ protected function _getDeliveryDate($postcode, Mage_Sales_Model_Quote $quote) {
540
+ $postcode = str_replace(' ', '', strtoupper($postcode));
541
+
542
+ $validator = new Zend_Validate_PostCode('nl_NL');
543
+ if (!$validator->isValid($postcode)) {
544
+ throw new TIG_PostNL_Exception(
545
+ $this->__(
546
+ 'Invalid postcode supplied for GetDeliveryDate request: %s Postcodes may only contain 4 numbers '
547
+ . 'and 2 letters.',
548
+ $postcode
549
+ ),
550
+ 'POSTNL-0131'
551
+ );
552
+ }
553
+
554
+ $cif = Mage::getModel('postnl_deliveryoptions/cif');
555
+ $response = $cif->setStoreId(Mage::app()->getStore()->getId())
556
+ ->getDeliveryDate($postcode, $quote);
557
+
558
+ return $response;
559
+ }
560
+ }
app/code/community/TIG/PostNL/Block/DeliveryOptions/Js.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasApiKey()
40
+ * @method TIG_PostNL_Block_DeliveryOptions_Js setApiKey()
41
+ */
42
+ class TIG_PostNL_Block_DeliveryOptions_Js extends TIG_PostNL_Block_DeliveryOptions_Template
43
+ {
44
+ /**
45
+ * @var string
46
+ */
47
+ protected $_eventPrefix = 'postnl_deliveryoptions_js';
48
+
49
+ /**
50
+ * @var string
51
+ */
52
+ protected $_template = 'TIG/PostNL/delivery_options/js.phtml';
53
+
54
+ /**
55
+ * Get the configured Google maps API key.
56
+ *
57
+ * @return string
58
+ */
59
+ public function getApiKey()
60
+ {
61
+ if ($this->hasApiKey()) {
62
+ return $this->_getData('api_key');
63
+ }
64
+
65
+ $apiKey = Mage::getStoreConfig('postnl/google_maps/api_key', Mage::app()->getStore()->getId());
66
+
67
+ $this->setApiKey($apiKey);
68
+ return $apiKey;
69
+ }
70
+ }
app/code/community/TIG/PostNL/Block/DeliveryOptions/Template.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ abstract class TIG_PostNL_Block_DeliveryOptions_Template extends TIG_PostNL_Block_Core_Template
40
+ {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_deliveryoptions_template';
45
+
46
+ /**
47
+ * Xpath to the current theme setting.
48
+ */
49
+ const XPATH_THEME = 'postnl/delivery_options/theme';
50
+
51
+ /**
52
+ * @var null|boolean|Varien_Simplexml_Element
53
+ */
54
+ protected $_currentTheme = null;
55
+
56
+ /**
57
+ * @var null|boolean
58
+ */
59
+ protected $_canUseDeliveryOptions = null;
60
+
61
+ /**
62
+ * Gets the current theme.
63
+ *
64
+ * @return bool|null|Varien_Simplexml_Element
65
+ */
66
+ public function getCurrentTheme()
67
+ {
68
+ if ($this->_currentTheme !== null) {
69
+ return $this->_currentTheme;
70
+ }
71
+
72
+ $currentTheme = Mage::getStoreConfig(self::XPATH_THEME, Mage::app()->getStore()->getId());
73
+
74
+ $config = Mage::getConfig()->getNode('tig/delivery_options/themes');
75
+
76
+ /**
77
+ * @var Varien_Simplexml_Element $theme
78
+ */
79
+ $theme = $config->$currentTheme;
80
+
81
+ if (!$theme) {
82
+ $this->_currentTheme = false;
83
+ return false;
84
+ }
85
+
86
+ $this->_currentTheme = $theme;
87
+ return $theme;
88
+ }
89
+
90
+ /**
91
+ * Check if PostNL delivery options are available for the current quote.
92
+ *
93
+ * @return boolean
94
+ */
95
+ public function canUseDeliveryOptions()
96
+ {
97
+ if ($this->_canUseDeliveryOptions !== null) {
98
+ return $this->_canUseDeliveryOptions;
99
+ }
100
+
101
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
102
+
103
+ $helper = Mage::helper('postnl/deliveryOptions');
104
+ $canUseDeliveryOptions = $helper->canUseDeliveryOptions($quote, false);
105
+
106
+ $this->_canUseDeliveryOptions = $canUseDeliveryOptions;
107
+ return $canUseDeliveryOptions;
108
+ }
109
+
110
+ /**
111
+ * Render the template if allowed.
112
+ *
113
+ * @return string
114
+ */
115
+ protected function _toHtml()
116
+ {
117
+ if (!$this->canUseDeliveryOptions()) {
118
+ return '';
119
+ }
120
+
121
+ return parent::_toHtml();
122
+ }
123
+ }
app/code/community/TIG/PostNL/Block/DeliveryOptions/Theme.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasIsOsc()
40
+ */
41
+ class TIG_PostNL_Block_DeliveryOptions_Theme extends TIG_PostNL_Block_DeliveryOptions_Template
42
+ {
43
+ /**
44
+ * @var string
45
+ */
46
+ protected $_eventPrefix = 'postnl_deliveryoptions_theme';
47
+
48
+ /**
49
+ * @var string
50
+ */
51
+ protected $_template = 'TIG/PostNL/delivery_options/theme.phtml';
52
+
53
+ /**
54
+ * Gets whether the current checkout page is OneStepCheckout.
55
+ *
56
+ * @return boolean|mixed
57
+ */
58
+ public function getIsOsc()
59
+ {
60
+ if (!$this->hasIsOsc()) {
61
+ return false;
62
+ }
63
+
64
+ return $this->_getData('is_osc');
65
+ }
66
+
67
+ /**
68
+ * Gets a css file path for the current theme.
69
+ *
70
+ * @return string
71
+ */
72
+ public function getThemeCssFile()
73
+ {
74
+ /**
75
+ * @var Varien_Simplexml_Element $theme
76
+ */
77
+ $theme = $this->getCurrentTheme();
78
+ if (!$theme) {
79
+ return '';
80
+ }
81
+
82
+ /**
83
+ * @var Varien_Simplexml_Element $files
84
+ */
85
+ $files = $theme->files;
86
+ if (!$files) {
87
+ return '';
88
+ }
89
+
90
+ if ($this->getIsOsc()) {
91
+ $file = (string) $files->onestepcheckout;
92
+ } else {
93
+ $file = (string) $files->onepage;
94
+ }
95
+
96
+ return $file;
97
+ }
98
+
99
+ /**
100
+ * Check if PostNL delivery options are available for the current quote.
101
+ *
102
+ * @return string
103
+ */
104
+ protected function _toHtml()
105
+ {
106
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
107
+
108
+ $helper = Mage::helper('postnl/deliveryOptions');
109
+
110
+ if (!$helper->canUseDeliveryOptions($quote, false)) {
111
+ return '';
112
+ }
113
+
114
+ if (!$this->getThemeCssFile()) {
115
+ return '';
116
+ }
117
+
118
+ return parent::_toHtml();
119
+ }
120
+ }
app/code/community/TIG/PostNL/Block/Mijnpakket/AccountNotification.php ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasCanShowNotification()
40
+ * @method TIG_PostNL_Block_Mijnpakket_AccountNotification setCanShowNotification(bool $value)
41
+ * @method boolean hasCanShowCreateAccountLink()
42
+ * @method TIG_PostNL_Block_Mijnpakket_AccountNotification setCanShowCreateAccountLink(bool $value)
43
+ * @method boolean hasCanShowAppLink()
44
+ * @method TIG_PostNL_Block_Mijnpakket_AccountNotification setCanShowAppLink(bool $value)
45
+ * @method boolean hasPublicWebshopId()
46
+ * @method TIG_PostNL_Block_Mijnpakket_AccountNotification setPublicWebshopId(string $value)
47
+ * @method boolean hasOrder()
48
+ * @method TIG_PostNL_Block_Mijnpakket_AccountNotification setOrder(mixed $value)
49
+ * @method boolean hasShippingAddress()
50
+ * @method TIG_PostNL_Block_Mijnpakket_AccountNotification setShippingAddress(mixed $value)
51
+ * @method boolean hasCreateAccountUrl()
52
+ * @method TIG_PostNL_Block_Mijnpakket_AccountNotification setCreateAccountUrl(string $value)
53
+ * @method boolean hasCreateAccountBaseUrl()
54
+ * @method TIG_PostNL_Block_Mijnpakket_AccountNotification setCreateAccountBaseUrl(string $value)
55
+ */
56
+ class TIG_PostNL_Block_Mijnpakket_AccountNotification extends TIG_PostNL_Block_Core_Template
57
+ {
58
+ /**
59
+ * @var string
60
+ */
61
+ protected $_eventPrefix = 'postnl_mijnpakket_accountnotification';
62
+
63
+ /**
64
+ * Base URL to create a new MijnPakket account.
65
+ */
66
+ const CREATE_ACCOUNT_BASE_URL = 'https://mijnpakket.postnl.nl/Register/RegisterFromWebshop?';
67
+
68
+ /**
69
+ * The webshop's public webshop ID is used to secure communications with PostNL's servers.
70
+ */
71
+ const XPATH_PUBLIC_WEBSHOP_ID = 'postnl/cif/public_webshop_id';
72
+
73
+ /**
74
+ * Xpaths determining various options regarding the MijnPakket notification.
75
+ */
76
+ const XPATH_MIJNPAKKET_NOTIFICATION = 'postnl/delivery_options/mijnpakket_notification';
77
+ const XPATH_SHOW_CREATE_MIJNPAKKET_ACCOUNT_LINK = 'postnl/delivery_options/show_create_mijnpakket_account_link';
78
+ const XPATH_SHOW_MIJNPAKKET_APP_LINK = 'postnl/delivery_options/show_mijnpakket_app_link';
79
+
80
+ /**
81
+ * @var string
82
+ */
83
+ protected $_template = 'TIG/PostNL/mijnpakket/account_notification.phtml';
84
+
85
+ /**
86
+ * Checks if showing the MijnPakket notification is allowed.
87
+ *
88
+ * @return bool|mixed
89
+ */
90
+ public function getCanShowNotification()
91
+ {
92
+ if ($this->hasCanShowNotification()) {
93
+ return $this->_getData('can_show_notification');
94
+ }
95
+
96
+ if (!Mage::helper('postnl/deliveryOptions')->canUseDeliveryOptions()) {
97
+ $this->setCanShowNotification(false);
98
+ return false;
99
+ }
100
+
101
+ $storeId = Mage::app()->getStore()->getId();
102
+ $canShowNotification = Mage::getStoreConfigFlag(self::XPATH_MIJNPAKKET_NOTIFICATION, $storeId);
103
+
104
+ $this->setCanShowNotification($canShowNotification);
105
+ return $canShowNotification;
106
+ }
107
+
108
+ /**
109
+ * Checks if showing the MijnPakket create account link is allowed.
110
+ *
111
+ * @return bool|mixed
112
+ */
113
+ public function getCanShowCreateAccountLink()
114
+ {
115
+ if ($this->hasCanShowCreateAccountLink()) {
116
+ return $this->_getData('can_show_create_account_link');
117
+ }
118
+
119
+ $storeId = Mage::app()->getStore()->getId();
120
+ $canShowLink = Mage::getStoreConfigFlag(self::XPATH_SHOW_CREATE_MIJNPAKKET_ACCOUNT_LINK, $storeId);
121
+
122
+ $this->setCanShowCreateAccountLink($canShowLink);
123
+ return $canShowLink;
124
+ }
125
+
126
+ /**
127
+ * Checks if showing the MijnPakket app link is allowed.
128
+ *
129
+ * @return bool|mixed
130
+ */
131
+ public function getCanShowAppLink()
132
+ {
133
+ if ($this->hasCanShowAppLink()) {
134
+ return $this->_getData('can_show_app_link');
135
+ }
136
+
137
+ $storeId = Mage::app()->getStore()->getId();
138
+ $canShowLink = Mage::getStoreConfigFlag(self::XPATH_SHOW_MIJNPAKKET_APP_LINK, $storeId);
139
+
140
+ $this->setCanShowAppLink($canShowLink);
141
+ return $canShowLink;
142
+ }
143
+
144
+ /**
145
+ * Get the current public webshop ID.
146
+ *
147
+ * @return string
148
+ */
149
+ public function getPublicWebshopId()
150
+ {
151
+ if ($this->hasPublicWebshopId()) {
152
+ return $this->_getData('public_webshop_id');
153
+ }
154
+
155
+ $publicWebshopId = Mage::getStoreConfig(self::XPATH_PUBLIC_WEBSHOP_ID, Mage::app()->getStore()->getId());
156
+
157
+ $this->setPublicWebshopId($publicWebshopId);
158
+ return $publicWebshopId;
159
+ }
160
+
161
+ /**
162
+ * Gets the last placed order.
163
+ *
164
+ * @return Mage_Sales_Model_Order|boolean
165
+ */
166
+ public function getOrder()
167
+ {
168
+ if ($this->hasOrder()) {
169
+ return $this->_getData('order');
170
+ }
171
+
172
+ $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
173
+ if (!$orderId) {
174
+ return false;
175
+ }
176
+
177
+ $order = Mage::getModel('sales/order')->load($orderId);
178
+
179
+ $this->setOrder($order);
180
+ return $order;
181
+ }
182
+
183
+ /**
184
+ * Gets the shipping address of the last placed order.
185
+ *
186
+ * @return Mage_Sales_Model_Order_Address|boolean
187
+ */
188
+ public function getShippingAddress()
189
+ {
190
+ if ($this->hasShippingAddress()) {
191
+ return $this->_getData('shipping_address');
192
+ }
193
+
194
+ $order = $this->getOrder();
195
+ if (!$order) {
196
+ $this->setShippingAddress(false);
197
+ return false;
198
+ }
199
+
200
+ $shippingAddress = $order->getShippingAddress();
201
+ if (!$shippingAddress) {
202
+ $this->setShippingAddress(false);
203
+ return false;
204
+ }
205
+
206
+ $this->setShippingAddress($shippingAddress);
207
+ return $shippingAddress;
208
+ }
209
+
210
+ /**
211
+ * Gets the base create MijnPakket account URL.
212
+ *
213
+ * @return string
214
+ */
215
+ public function getCreateAccountBaseUrl()
216
+ {
217
+ if ($this->hasCreateAccountBaseUrl()) {
218
+ return $this->_getData('create_account_base_url');
219
+ }
220
+
221
+ $baseUrl = self::CREATE_ACCOUNT_BASE_URL;
222
+
223
+ $this->setCreateAccountBaseUrl($baseUrl);
224
+ return $baseUrl;
225
+ }
226
+
227
+ /**
228
+ * Form the create MijnPakket account url based on the hardcoded base URL and a dynamic set of parameters.
229
+ *
230
+ * @return string
231
+ */
232
+ public function getCreateAccountUrl()
233
+ {
234
+ if ($this->hasCreateAccountUrl()) {
235
+ return $this->_getData('create_account_url');
236
+ }
237
+
238
+ $baseUrl = $this->getCreateAccountBaseUrl();
239
+
240
+ /**
241
+ * Add the optional params to the base url.
242
+ */
243
+ $urlParams = $this->_getUrlParams();
244
+ $queryString = http_build_query($urlParams);
245
+
246
+ $createAccountUrl = $baseUrl . $queryString;
247
+
248
+ $this->setCreateAccountUrl($createAccountUrl);
249
+ return $createAccountUrl;
250
+ }
251
+
252
+ /**
253
+ * Gets all the URL parameters to create a MijnPakket account. While alle parameters are optional, the more we add,
254
+ * the less the customer will have to add manually later on.
255
+ *
256
+ * @return array
257
+ */
258
+ protected function _getUrlParams()
259
+ {
260
+ /**
261
+ * get the webshop's public ID. This should be the only parameter that is always available.
262
+ */
263
+ $publicWebshopId = $this->getPublicWebshopId();
264
+
265
+ /**
266
+ * If no order or shipping address is available, return just the public webshop ID.
267
+ */
268
+ $order = $this->getOrder();
269
+ $shippingAddress = $this->getShippingAddress();
270
+ if (!$order || !$shippingAddress) {
271
+ return array('webshopPublicId' => $publicWebshopId);
272
+ }
273
+
274
+ $helper = Mage::helper('postnl/mijnpakket');
275
+
276
+ /**
277
+ * Get the basic order parameters.
278
+ */
279
+ $firstname = $shippingAddress->getFirstname();
280
+ $params = array(
281
+ 'webshopPublicId' => $publicWebshopId,
282
+ 'initials' => $helper->getInitials($firstname),
283
+ 'firstName' => $firstname,
284
+ 'middleName' => $shippingAddress->getMiddlename(),
285
+ 'lastName' => $shippingAddress->getLastname(),
286
+ 'email' => $shippingAddress->getEmail(),
287
+ 'postalCode' => $shippingAddress->getPostcode(),
288
+ 'business' => 'P',
289
+ );
290
+
291
+ /**
292
+ * If this address hads a VAT ID, it's probably a B2B client.
293
+ */
294
+ $vat = $shippingAddress->getVatId();
295
+ if ($vat) {
296
+ $params['business'] = 'Z';
297
+ }
298
+
299
+ /**
300
+ * Optionally add the dob.
301
+ */
302
+ $dob = $shippingAddress->getDob();
303
+ if ($dob) {
304
+ $dob = date('d-m-Y', strtotime($dob));
305
+ $params['birthDate'] = $dob;
306
+ }
307
+
308
+ /**
309
+ * If we have a mobile phonenumber for this address, add that as well.
310
+ *
311
+ * @var TIG_PostNL_Model_Core_Order $postnlOrder
312
+ */
313
+ $postnlOrder = Mage::getModel('postnl_core/order')->load($order->getId(), 'order_id');
314
+ if ($postnlOrder->getId() && $postnlOrder->getMobilePhoneNumber()) {
315
+ $params['mobileNumber'] = $postnlOrder->getMobilePhoneNumber();
316
+ }
317
+
318
+ /**
319
+ * Get the split address data of this order.
320
+ */
321
+ $streetData = false;
322
+ try {
323
+ $streetData = Mage::helper('postnl/cif')->getStreetData($order->getStoreId(), $shippingAddress, false);
324
+ } catch (Exception $e) {
325
+ Mage::helper('postnl')->logException($e);
326
+ }
327
+
328
+ /**
329
+ * If we have split address data, add the housenumber and housenumber extension.
330
+ */
331
+ if ($streetData && isset($streetData['housenumber'])) {
332
+ $params['houseNumber'] = $streetData['housenumber'];
333
+
334
+ if (isset($streetData['housenumberExtension']) && !empty($streetData['housenumberExtension'])) {
335
+ $params['houseNumberSuffix'] = $streetData['housenumberExtension'];
336
+ }
337
+ }
338
+
339
+ return $params;
340
+ }
341
+
342
+ /**
343
+ * Check if MijnPakket notification can be shown before rendering the template.
344
+ *
345
+ * @return string
346
+ */
347
+ protected function _toHtml()
348
+ {
349
+ if (!$this->getCanShowNotification()) {
350
+ return '';
351
+ }
352
+
353
+ return parent::_toHtml();
354
+ }
355
+ }
app/code/community/TIG/PostNL/Block/Mijnpakket/Js.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasIsTestMode()
40
+ * @method TIG_PostNL_Block_Mijnpakket_Js setIsTestMode(boolean $value)
41
+ * @method boolean hasBaseUrl()
42
+ * @method TIG_PostNL_Block_Mijnpakket_Js setBaseUrl(string $value)
43
+ */
44
+ class TIG_PostNL_Block_Mijnpakket_Js extends TIG_PostNL_Block_Core_Template
45
+ {
46
+ /**
47
+ * @var string
48
+ */
49
+ protected $_eventPrefix = 'postnl_mijnpakket_js';
50
+
51
+ /**
52
+ * @var string
53
+ */
54
+ protected $_template = 'TIG/PostNL/mijnpakket/js.phtml';
55
+
56
+ /**
57
+ * Available URl's for PostNL's login API.
58
+ */
59
+ const LIVE_BASE_URL = 'https://mijnpakket.postnl.nl/';
60
+ const TEST_BASE_URL = 'https://tppwscheckout-sandbox.e-id.nl/';
61
+ const LOGIN_JS_PATH = 'Checkout2/Login.js';
62
+ const CHECKOUT_PREMIUM_JS_PATH = 'Checkout2/CheckoutPremium.js';
63
+
64
+ /**
65
+ * @return boolean
66
+ */
67
+ public function getIsTestMode()
68
+ {
69
+ if ($this->hasIsTestMode()) {
70
+ return $this->_getData('is_test_mode');
71
+ }
72
+
73
+ $isTestMode = Mage::helper('postnl/mijnpakket')->isTestMode();
74
+
75
+ $this->setIsTestMode($isTestMode);
76
+ return $isTestMode;
77
+ }
78
+
79
+ /**
80
+ * Gets the current base URL based on whether the extension is set to test mode.
81
+ *
82
+ * @return string
83
+ */
84
+ public function getBaseUrl()
85
+ {
86
+ if ($this->hasBaseUrl()) {
87
+ return $this->_getData('base_url');
88
+ }
89
+
90
+ $isTestMode = $this->getIsTestMode();
91
+ if ($isTestMode) {
92
+ $baseUrl = self::TEST_BASE_URL;
93
+ } else {
94
+ $baseUrl = self::LIVE_BASE_URL;
95
+ }
96
+
97
+ $this->setBaseUrl($baseUrl);
98
+ return $baseUrl;
99
+ }
100
+
101
+ /**
102
+ * gets the Mijnpakket Login JS URL for either live or test mode.
103
+ *
104
+ * @return string
105
+ */
106
+ public function getLoginJsUrl()
107
+ {
108
+ $baseUrl = $this->getBaseUrl();
109
+
110
+ $url = $baseUrl . self::LOGIN_JS_PATH;
111
+
112
+ return $url;
113
+ }
114
+
115
+ /**
116
+ * Get the Checkout premium JS URL which is used to check if the customer has a MijnPakket account.
117
+ *
118
+ * @return string
119
+ */
120
+ public function getCheckoutPremiumJsUrl()
121
+ {
122
+ $baseUrl = $this->getBaseUrl();
123
+
124
+ $url = $baseUrl . self::CHECKOUT_PREMIUM_JS_PATH;
125
+
126
+ return $url;
127
+ }
128
+
129
+ /**
130
+ * Check if the current customer may login using Mijnpakket.
131
+ *
132
+ * @return string
133
+ */
134
+ protected function _tohtml()
135
+ {
136
+ $helper = Mage::helper('postnl/mijnpakket');
137
+ if (!$helper->canLoginWithMijnpakket()) {
138
+ return '';
139
+ }
140
+
141
+ return parent::_toHtml();
142
+ }
143
+ }
app/code/community/TIG/PostNL/Block/Mijnpakket/LoginButton.php ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasIsTestMode()
40
+ * @method TIG_PostNL_Block_Mijnpakket_LoginButton setIsTestMode(boolean $value)
41
+ * @method boolean hasBaseUrl()
42
+ * @method TIG_PostNL_Block_Mijnpakket_LoginButton setBaseUrl(string $value)
43
+ * @method boolean hasPublicWebshopId()
44
+ * @method TIG_PostNL_Block_Mijnpakket_LoginButton setPublicWebshopId(string $value)
45
+ * @method boolean hasSavedMijnpakketData()
46
+ * @method TIG_PostNL_Block_Mijnpakket_LoginButton setSavedMijnpakketData(string $value)
47
+ * @method boolean hasButtonUrl()
48
+ * @method TIG_PostNL_Block_Mijnpakket_LoginButton setButtonUrl(string $value)
49
+ * @method boolean hasDisabledButtonUrl()
50
+ * @method TIG_PostNL_Block_Mijnpakket_LoginButton setDisabledButtonUrl(string $value)
51
+ */
52
+ class TIG_PostNL_Block_Mijnpakket_LoginButton extends TIG_PostNL_Block_Core_Template
53
+ {
54
+ /**
55
+ * @var string
56
+ */
57
+ protected $_eventPrefix = 'postnl_mijnpakket_loginbutton';
58
+
59
+ /**
60
+ * The webshop's public webshop ID is used to secure communications with PostNL's servers.
61
+ */
62
+ const XPATH_PUBLIC_WEBSHOP_ID = 'postnl/cif/public_webshop_id';
63
+
64
+ /**
65
+ * Available URl's for PostNL's login buttons.
66
+ */
67
+ const LIVE_BASE_URL = 'https://checkout.postnl.nl/';
68
+ const TEST_BASE_URL = 'https://tppcb-sandbox.e-id.nl/';
69
+ const BUTTON_URL_PATH = 'Button/PremiumLogin';
70
+
71
+ /**
72
+ * @var string
73
+ */
74
+ protected $_template = 'TIG/PostNL/mijnpakket/login_button.phtml';
75
+
76
+ /**
77
+ * @return boolean
78
+ */
79
+ public function getIsTestMode()
80
+ {
81
+ if ($this->hasIsTestMode()) {
82
+ return $this->_getData('is_test_mode');
83
+ }
84
+
85
+ $isTestMode = Mage::helper('postnl/mijnpakket')->isTestMode();
86
+
87
+ $this->setIsTestMode($isTestMode);
88
+ return $isTestMode;
89
+ }
90
+
91
+ /**
92
+ * Gets the current base URL based on whether the extension is set to test mode.
93
+ *
94
+ * @return string
95
+ */
96
+ public function getBaseUrl()
97
+ {
98
+ if ($this->hasBaseUrl()) {
99
+ return $this->_getData('base_url');
100
+ }
101
+
102
+ $isTestMode = $this->getIsTestMode();
103
+ if ($isTestMode) {
104
+ $baseUrl = self::TEST_BASE_URL;
105
+ } else {
106
+ $baseUrl = self::LIVE_BASE_URL;
107
+ }
108
+
109
+ $this->setBaseUrl($baseUrl);
110
+ return $baseUrl;
111
+ }
112
+
113
+ /**
114
+ * Get the current public webshop ID.
115
+ *
116
+ * @return string
117
+ */
118
+ public function getPublicWebshopId()
119
+ {
120
+ if ($this->hasPublicWebshopId()) {
121
+ return $this->_getData('public_webshop_id');
122
+ }
123
+
124
+ $publicWebshopId = Mage::getStoreConfig(self::XPATH_PUBLIC_WEBSHOP_ID, Mage::app()->getStore()->getId());
125
+
126
+ $this->setPublicWebshopId($publicWebshopId);
127
+ return $publicWebshopId;
128
+ }
129
+
130
+ /**
131
+ * Get saved MijnPakket data if available.
132
+ *
133
+ * @return array|null
134
+ */
135
+ public function getSavedMijnpakketData()
136
+ {
137
+ if ($this->hasSavedMijnpakketData()) {
138
+ return $this->_getData('saved_mijnpakket_data');
139
+ }
140
+
141
+ $data = Mage::getSingleton('checkout/session')->getPostnlMijnpakketData();
142
+
143
+ $this->setSavedMijnpakketData($data);
144
+ return $data;
145
+ }
146
+
147
+ /**
148
+ * Gets the button URL.
149
+ *
150
+ * @return string
151
+ */
152
+ public function getButtonUrl()
153
+ {
154
+ if ($this->hasButtonUrl()) {
155
+ return $this->_getData('button_url');
156
+ }
157
+
158
+ $baseUrl = $this->getBaseUrl();
159
+ $url = $baseUrl . self::BUTTON_URL_PATH;
160
+
161
+ $url .= '?publicId=' . $this->getPublicWebshopId();
162
+
163
+ $this->setButtonUrl($url);
164
+ return $url;
165
+ }
166
+
167
+ /**
168
+ * Gets the URL for the disabled button.
169
+ *
170
+ * @return string
171
+ */
172
+ public function getDisabledButtonUrl()
173
+ {
174
+ if ($this->hasDisabledButtonUrl()) {
175
+ return $this->_getData('disabled_button_url');
176
+ }
177
+
178
+ $buttonUrl = $this->getButtonUrl();
179
+ $buttonUrl .= '&disabled=true';
180
+
181
+ $this->setDisabledButtonUrl($buttonUrl);
182
+ return $buttonUrl;
183
+ }
184
+
185
+ /**
186
+ * Checks if debug mode is allowed. Debug mode is enabled if the PostNl extension's debug mode is set to 'full'.
187
+ *
188
+ * @return bool
189
+ */
190
+ public function isDebugEnabled()
191
+ {
192
+ $helper = Mage::helper('postnl');
193
+ $debugMode = $helper->getDebugMode();
194
+
195
+ if ($debugMode > 1) {
196
+ return true;
197
+ }
198
+
199
+ return false;
200
+ }
201
+
202
+ /**
203
+ * Check if the current customer may login using MijnPakket.
204
+ *
205
+ * @return string
206
+ */
207
+ protected function _tohtml()
208
+ {
209
+ $helper = Mage::helper('postnl/mijnpakket');
210
+ if (!$helper->canLoginWithMijnpakket()) {
211
+ return '';
212
+ }
213
+
214
+ return parent::_toHtml();
215
+ }
216
+ }
app/code/community/TIG/PostNL/Block/Mijnpakket/OrderSuccessJs.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasIsTestMode()
40
+ * @method TIG_PostNL_Block_Mijnpakket_Js setIsTestMode(boolean $value)
41
+ * @method boolean hasBaseUrl()
42
+ * @method TIG_PostNL_Block_Mijnpakket_Js setBaseUrl(string $value)
43
+ */
44
+ class TIG_PostNL_Block_Mijnpakket_OrderSuccessJs extends TIG_PostNL_Block_Checkout_Cart_Js
45
+ {
46
+ /**
47
+ * @var string
48
+ */
49
+ protected $_eventPrefix = 'postnl_mijnpakket_ordersuccessjs';
50
+
51
+ /**
52
+ * @var string
53
+ */
54
+ protected $_template = 'TIG/PostNL/mijnpakket/order_success_js.phtml';
55
+
56
+ /**
57
+ * Check if the current customer may login using Mijnpakket.
58
+ *
59
+ * @return string
60
+ */
61
+ protected function _tohtml()
62
+ {
63
+ $helper = Mage::helper('postnl/mijnpakket');
64
+ if (!$helper->canLoginWithMijnpakket()) {
65
+ return '';
66
+ }
67
+
68
+ return TIG_PostNL_Block_Core_Template::_toHtml();
69
+ }
70
+ }
app/code/community/TIG/PostNL/Exception.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,34 +33,32 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
-
40
  /**
41
- * General exception class for TIG_PostNL module
42
- *
43
  * @see Mage_Core_Exception
44
  */
45
  class TIG_PostNL_Exception extends Mage_Core_Exception
46
  {
47
  /**
48
- * Our codes are string, however the core Exception class only accepts integers, so we need to overload it.
49
- *
50
- * @param string $message
51
- * @param mixed $code
52
  * @param Exception|null $previous
53
- *
54
- * @return void
55
- *
56
  * @see Exception::__construct()
57
- *
58
  * @link http://www.php.net/manual/en/exception.construct.php
59
  */
60
  public function __construct($message, $code = 0, Exception $previous = null)
61
  {
62
  parent::__construct($message, 0, $previous);
63
-
64
  /**
65
  * Replace the code with the actual, non-integer code
66
  */
@@ -69,40 +67,40 @@ class TIG_PostNL_Exception extends Mage_Core_Exception
69
  $this->code = $code;
70
  }
71
  }
72
-
73
  /**
74
  * Custom __toString method that includes the error code, if preset.
75
- *
76
  * @return string
77
- *
78
  * @see Exception::__toString()
79
- *
80
  * @link http://www.php.net/manual/en/exception.tostring.php
81
  */
82
  public function __toString()
83
  {
84
- $string = "exception '"
85
- . __CLASS__
86
- . "' with message '"
87
  . $this->getMessage()
88
  . "'";
89
-
90
  $code = $this->getCode();
91
  if ($code !== 0 && !empty($code)) {
92
- $string .= " and code: '"
93
- . $this->getCode()
94
  . "'";
95
  }
96
-
97
- $string .= " in "
98
- . $this->getFile()
99
- . ':'
100
- . $this->getLine()
101
- . PHP_EOL
102
  . 'Stack trace:'
103
  . PHP_EOL
104
  . $this->getTraceAsString();
105
-
106
  return $string;
107
  }
108
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+
40
  /**
41
+ * General exception class for TIG_PostNL extension
42
+ *
43
  * @see Mage_Core_Exception
44
  */
45
  class TIG_PostNL_Exception extends Mage_Core_Exception
46
  {
47
  /**
48
+ * Our error codes are strings, however the core Exception class only accepts integers, so we need to overload it.
49
+ *
50
+ * @param string $message
51
+ * @param mixed $code
52
  * @param Exception|null $previous
53
+ *
 
 
54
  * @see Exception::__construct()
55
+ *
56
  * @link http://www.php.net/manual/en/exception.construct.php
57
  */
58
  public function __construct($message, $code = 0, Exception $previous = null)
59
  {
60
  parent::__construct($message, 0, $previous);
61
+
62
  /**
63
  * Replace the code with the actual, non-integer code
64
  */
67
  $this->code = $code;
68
  }
69
  }
70
+
71
  /**
72
  * Custom __toString method that includes the error code, if preset.
73
+ *
74
  * @return string
75
+ *
76
  * @see Exception::__toString()
77
+ *
78
  * @link http://www.php.net/manual/en/exception.tostring.php
79
  */
80
  public function __toString()
81
  {
82
+ $string = "exception '"
83
+ . __CLASS__
84
+ . "' with message '"
85
  . $this->getMessage()
86
  . "'";
87
+
88
  $code = $this->getCode();
89
  if ($code !== 0 && !empty($code)) {
90
+ $string .= " and code: '"
91
+ . $this->getCode()
92
  . "'";
93
  }
94
+
95
+ $string .= " in "
96
+ . $this->getFile()
97
+ . ':'
98
+ . $this->getLine()
99
+ . PHP_EOL
100
  . 'Stack trace:'
101
  . PHP_EOL
102
  . $this->getTraceAsString();
103
+
104
  return $string;
105
  }
106
  }
app/code/community/TIG/PostNL/Helper/AddressValidation.php ADDED
@@ -0,0 +1,400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
40
+ {
41
+ /**
42
+ * XML path to use_postcode_check setting
43
+ */
44
+ const XML_PATH_USE_POSTCODE_CHECK = 'postnl/cif_address/use_postcode_check';
45
+
46
+ /**
47
+ * Constants containing XML paths to cif address configuration options
48
+ */
49
+ const XML_PATH_SPLIT_STREET = 'postnl/cif_address/split_street';
50
+ const XML_PATH_STREETNAME_FIELD = 'postnl/cif_address/streetname_field';
51
+ const XML_PATH_HOUSENUMBER_FIELD = 'postnl/cif_address/housenr_field';
52
+ const XML_PATH_SPLIT_HOUSENUMBER = 'postnl/cif_address/split_housenr';
53
+ const XML_PATH_HOUSENUMBER_EXTENSION_FIELD = 'postnl/cif_address/housenr_extension_field';
54
+
55
+ /**
56
+ * XML paths to flags that dtermine which environment allows the postcode check functionality
57
+ */
58
+ const XML_PATH_POSTCODE_CHECK_IN_CHECKOUT = 'postnl/cif_address/postcode_check_in_checkout';
59
+ const XML_PATH_POSTCODE_CHECK_IN_ADDRESSBOOK = 'postnl/cif_address/postcode_check_in_addressbook';
60
+
61
+ /**
62
+ * XML paths that control some features of postcode check
63
+ */
64
+ const XML_PATH_POSTCODE_CHECK_MAX_ATTEMPTS = 'postnl/cif_address/postcode_check_max_attempts';
65
+ const XML_PATH_POSTCODE_CHECK_TIMEOUT = 'postnl/cif_address/postcode_check_timeout';
66
+
67
+ /**
68
+ * Xpath to OSC street fields sort order.
69
+ */
70
+ const XPATH_STREET_FIELD_SORT_ORDER = 'onestepcheckout/sortordering_fields/street';
71
+
72
+ /**
73
+ * Log filename to log all cendris exceptions
74
+ */
75
+ const CENDRIS_EXCEPTION_LOG_FILE = 'TIG_PostNL_Cendris_Exception.log';
76
+
77
+ /**
78
+ * Log filename to log cendris calls
79
+ */
80
+ const CENDRIS_DEBUG_LOG_FILE = 'TIG_PostNL_Cendris_Debug.log';
81
+
82
+ /**
83
+ * @var null|string|int
84
+ */
85
+ protected $_oscStreetFieldSortOrder = null;
86
+
87
+ /**
88
+ * Gets the current street field sort order for OSC.
89
+ *
90
+ * @return int|string
91
+ */
92
+ public function getOscStreetFieldSortOrder()
93
+ {
94
+ if ($this->_oscStreetFieldSortOrder !== null) {
95
+ return $this->_oscStreetFieldSortOrder;
96
+ }
97
+
98
+ $storeId = Mage::app()->getStore()->getId();
99
+ $streetFieldOrder = Mage::getStoreConfig(self::XPATH_STREET_FIELD_SORT_ORDER, $storeId);
100
+
101
+ $this->_oscStreetFieldSortOrder = $streetFieldOrder;
102
+ return $streetFieldOrder;
103
+ }
104
+
105
+ /**
106
+ * Checks whether the given store uses split address lines.
107
+ *
108
+ * @param int|null $storeId
109
+ *
110
+ * @return boolean
111
+ */
112
+ public function useSplitStreet($storeId = null)
113
+ {
114
+ if (is_null($storeId)) {
115
+ $storeId = Mage::app()->getStore()->getId();
116
+ }
117
+
118
+ if ($this->isPostcodeCheckEnabled($storeId)) {
119
+ return true;
120
+ }
121
+
122
+ $useSplitStreet = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_STREET, $storeId);
123
+ return $useSplitStreet;
124
+ }
125
+
126
+ /**
127
+ * Checks whether the given store uses split housenumber values.
128
+ *
129
+ * @param int|null $storeId
130
+ *
131
+ * @return boolean
132
+ */
133
+ public function useSplitHousenumber($storeId = null)
134
+ {
135
+ if (is_null($storeId)) {
136
+ $storeId = Mage::app()->getStore()->getId();
137
+ }
138
+
139
+ if ($this->isPostcodeCheckEnabled($storeId)) {
140
+ return true;
141
+ }
142
+
143
+ $useSplitStreet = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_HOUSENUMBER, $storeId);
144
+ return $useSplitStreet;
145
+ }
146
+
147
+ /**
148
+ * Gets the address field number used for the streetname field.
149
+ *
150
+ * @param int|null $storeId
151
+ *
152
+ * @return int
153
+ */
154
+ public function getStreetnameField($storeId = null)
155
+ {
156
+ if (is_null($storeId)) {
157
+ $storeId = Mage::app()->getStore()->getId();
158
+ }
159
+
160
+ if ($this->isPostcodeCheckEnabled($storeId)) {
161
+ return 1;
162
+ }
163
+
164
+ $streetnameField = (int) Mage::getStoreConfig(self::XML_PATH_STREETNAME_FIELD, $storeId);
165
+ return $streetnameField;
166
+ }
167
+
168
+ /**
169
+ * Gets the address field number used for the housenumber field.
170
+ *
171
+ * @param int|null $storeId
172
+ *
173
+ * @return int
174
+ */
175
+
176
+ public function getHousenumberField($storeId = null)
177
+ {
178
+ if (is_null($storeId)) {
179
+ $storeId = Mage::app()->getStore()->getId();
180
+ }
181
+
182
+ if ($this->isPostcodeCheckEnabled($storeId)) {
183
+ return 2;
184
+ }
185
+
186
+ $housenumberField = (int) Mage::getStoreConfig(self::XML_PATH_HOUSENUMBER_FIELD, $storeId);
187
+ return $housenumberField;
188
+ }
189
+
190
+ /**
191
+ * Gets the address field number used for the housenumber extension field.
192
+ *
193
+ * @param int|null $storeId
194
+ *
195
+ * @return int
196
+ */
197
+ public function getHousenumberExtensionField($storeId = null)
198
+ {
199
+ if (is_null($storeId)) {
200
+ $storeId = Mage::app()->getStore()->getId();
201
+ }
202
+
203
+ if ($this->isPostcodeCheckEnabled($storeId)) {
204
+ return 3;
205
+ }
206
+
207
+ $housenumberExtensionField = (int) Mage::getStoreConfig(self::XML_PATH_HOUSENUMBER_EXTENSION_FIELD, $storeId);
208
+ return $housenumberExtensionField;
209
+ }
210
+
211
+ /**
212
+ * Gets the number of seconds before postcode check times out.
213
+ *
214
+ * @param int|null $storeId
215
+ *
216
+ * @return int
217
+ */
218
+ public function getPostcodeCheckTimeoutDelay($storeId = null)
219
+ {
220
+ if (is_null($storeId)) {
221
+ $storeId = Mage::app()->getStore()->getId();
222
+ }
223
+
224
+ $timeout = (int) Mage::getStoreConfig(self::XML_PATH_POSTCODE_CHECK_TIMEOUT, $storeId);
225
+ return $timeout;
226
+ }
227
+
228
+ /**
229
+ * Gets the number of times a customer may attempt to enter their postcode and housenumber before postcode check disables
230
+ * itself.
231
+ *
232
+ * @param int|null $storeId
233
+ *
234
+ * @return string|int
235
+ */
236
+ public function getPostcodeCheckMaxAttempts($storeId = null)
237
+ {
238
+ if (is_null($storeId)) {
239
+ $storeId = Mage::app()->getStore()->getId();
240
+ }
241
+
242
+ $maxAttempts = (int) Mage::getStoreConfig(self::XML_PATH_POSTCODE_CHECK_MAX_ATTEMPTS, $storeId);
243
+ if (!$maxAttempts) {
244
+ return 'false';
245
+ }
246
+
247
+ return $maxAttempts;
248
+ }
249
+
250
+ /**
251
+ * Wrapper for the getAttributeValidationClass method to prevent errors in Magento 1.6.
252
+ *
253
+ * @param $attribute
254
+ *
255
+ * @return string
256
+ */
257
+ public function getAttributeValidationClass($attribute)
258
+ {
259
+ $addressHelper = Mage::helper('customer/address');
260
+ if (is_callable(array($addressHelper, 'getAttributeValidationClass'))) {
261
+ return $addressHelper->getAttributeValidationClass($attribute);
262
+ }
263
+
264
+ return '';
265
+ }
266
+
267
+ /**
268
+ * Check if the Postcode Check is active.
269
+ *
270
+ * @param int|null $storeId
271
+ *
272
+ * @return boolean
273
+ */
274
+ public function isPostcodeCheckActive($storeId = null)
275
+ {
276
+ if (is_null($storeId)) {
277
+ $storeId = Mage::app()->getStore()->getId();
278
+ }
279
+
280
+ $usePostcodeCheck = Mage::getStoreConfigFlag(self::XML_PATH_USE_POSTCODE_CHECK, $storeId);
281
+ return $usePostcodeCheck;
282
+ }
283
+
284
+ /**
285
+ * Checks if the Postcode Check is enabled and ready for use.
286
+ *
287
+ * @param int|null $storeId
288
+ *
289
+ * @param bool $environment
290
+ *
291
+ * @return boolean
292
+ */
293
+ public function isPostcodeCheckEnabled($storeId = null, $environment = false)
294
+ {
295
+ if (is_null($storeId)) {
296
+ $storeId = Mage::app()->getStore()->getId();
297
+ }
298
+
299
+ $isPostnlEnabled = $this->isEnabled($storeId, false);
300
+ if (!$isPostnlEnabled) {
301
+ return false;
302
+ }
303
+
304
+ $isPostcodeCheckActive = $this->isPostcodeCheckActive($storeId);
305
+ if (!$isPostcodeCheckActive) {
306
+ return false;
307
+ }
308
+
309
+ /**
310
+ * Check to see if the postcode check functionality is allowed for the specified environment.
311
+ */
312
+ $environmentAllowed = false;
313
+ switch ($environment) {
314
+ case 'checkout':
315
+ $environmentAllowed = Mage::getStoreConfigFlag(self::XML_PATH_POSTCODE_CHECK_IN_CHECKOUT, $storeId);
316
+ break;
317
+ case 'addressbook':
318
+ $environmentAllowed = Mage::getStoreConfigFlag(self::XML_PATH_POSTCODE_CHECK_IN_ADDRESSBOOK, $storeId);
319
+ break;
320
+ case false:
321
+ $environmentAllowed = true;
322
+ break;
323
+ //no default
324
+ }
325
+
326
+ return $environmentAllowed;
327
+ }
328
+
329
+ /**
330
+ * Logs a cendris request and response for debug purposes.
331
+ *
332
+ * @param Zend_Soap_Client $client
333
+ *
334
+ * @return TIG_PostNL_Helper_Webservices
335
+ *
336
+ * @see Mage::log()
337
+ */
338
+ public function logCendrisCall(Zend_Soap_Client $client)
339
+ {
340
+ if (!$this->isLoggingEnabled()) {
341
+ return $this;
342
+ }
343
+
344
+ $this->createLogDir();
345
+
346
+ $requestXml = $this->formatXml($client->getLastRequest());
347
+ $responseXML = $this->formatXml($client->getLastResponse());
348
+
349
+ $logMessage = 'Request sent:'
350
+ . PHP_EOL
351
+ . $requestXml
352
+ . PHP_EOL
353
+ . 'Response received:'
354
+ . PHP_EOL
355
+ . $responseXML;
356
+
357
+ $file = self::POSTNL_LOG_DIRECTORY . DS . self::CENDRIS_DEBUG_LOG_FILE;
358
+ $this->log($logMessage, Zend_Log::DEBUG, $file);
359
+
360
+ return $this;
361
+ }
362
+
363
+ /**
364
+ * Logs a cendris exception in the database and/or a log file
365
+ *
366
+ * @param Mage_Core_Exception|TIG_PostNL_Exception|SoapFault $exception
367
+ * @param Zend_Soap_Client|boolean $client
368
+ *
369
+ * @return TIG_PostNL_Helper_Webservices
370
+ *
371
+ * @see Mage::logException()
372
+ */
373
+ public function logCendrisException($exception, $client = false)
374
+ {
375
+ if (!$this->isExceptionLoggingEnabled()) {
376
+ return $this;
377
+ }
378
+
379
+ $logMessage = PHP_EOL . $exception->__toString();
380
+
381
+ if ($client && $client instanceof Zend_Soap_Client) {
382
+ $requestXml = $this->formatXml($client->getLastRequest());
383
+ $responseXML = $this->formatXml($client->getLastResponse());
384
+
385
+ $logMessage .= PHP_EOL
386
+ . 'Request sent:'
387
+ . PHP_EOL
388
+ . $requestXml
389
+ . PHP_EOL
390
+ . 'Response received:'
391
+ . PHP_EOL
392
+ . $responseXML;
393
+ }
394
+
395
+ $file = self::POSTNL_LOG_DIRECTORY . DS . self::CENDRIS_EXCEPTION_LOG_FILE;
396
+ $this->log($logMessage, Zend_Log::ERR, $file, false, true);
397
+
398
+ return $this;
399
+ }
400
+ }
app/code/community/TIG/PostNL/Helper/Carrier.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -42,13 +42,13 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
42
  * Shipping carrier code used by PostNL
43
  */
44
  const POSTNL_CARRIER = 'postnl';
45
-
46
  /**
47
  * PostNL shipping methods
48
  */
49
  const POSTNL_FLATRATE_METHOD = 'flatrate';
50
  const POSTNL_TABLERATE_METHOD = 'tablerate';
51
-
52
  /**
53
  * Localised track and trace base URL's
54
  */
@@ -57,15 +57,15 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
57
  const POSTNL_TRACK_AND_TRACE_DE_BASE_URL = 'http://parcels-de.tntpost.com/de/mytrackandtrace/TrackAndTrace.aspx?';
58
  const POSTNL_TRACK_AND_TRACE_FR_BASE_URL = 'http://parcels-fr.tntpost.com/fr/mytrackandtrace/TrackAndTrace.aspx?';
59
  const POSTNL_TRACK_AND_TRACE_INT_BASE_URL = 'http://www.postnlpakketten.nl/klantenservice/tracktrace/basicsearch.aspx?';
60
-
61
  /**
62
  * XML path to rate type setting
63
  */
64
  const XML_PATH_RATE_TYPE = 'carriers/postnl/rate_type';
65
-
66
  /**
67
  * Array of possible PostNL shipping methods
68
- *
69
  * @var array
70
  */
71
  protected $_postnlShippingMethods = array(
@@ -73,10 +73,10 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
73
  'postnl_flatrate',
74
  'postnl_tablerate',
75
  );
76
-
77
  /**
78
  * Gets an array of possible PostNL shipping methods
79
- *
80
  * @return array
81
  */
82
  public function getPostnlShippingMethods()
@@ -84,24 +84,27 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
84
  $shippingMethods = $this->_postnlShippingMethods;
85
  return $shippingMethods;
86
  }
87
-
88
  /**
89
  * Alias for getCurrentPostnlShippingMethod()
90
- *
91
  * @return string
92
- *
93
  * @see TIG_PostNL_Helper_Carrier::getCurrentPostnlShippingMethod()
94
- *
95
  * @deprecated
96
  */
97
  public function getPostnlShippingMethod()
98
  {
99
  return $this->getCurrentPostnlShippingMethod();
100
  }
101
-
102
  /**
103
  * Returns the PostNL shipping method
104
- *
 
 
 
105
  * @return string
106
  */
107
  public function getCurrentPostnlShippingMethod($storeId = null)
@@ -109,13 +112,13 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
109
  if (Mage::registry('current_postnl_shipping_method') !== null) {
110
  return Mage::registry('current_postnl_shipping_method');
111
  }
112
-
113
  if (is_null($storeId)) {
114
  $storeId = Mage::app()->getStore()->getId();
115
  }
116
-
117
  $rateType = Mage::getStoreConfig(self::XML_PATH_RATE_TYPE, $storeId);
118
-
119
  $carrier = self::POSTNL_CARRIER;
120
  switch ($rateType) {
121
  case 'flat':
@@ -130,19 +133,19 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
130
  'POSTNL-0036'
131
  );
132
  }
133
-
134
  Mage::register('current_postnl_shipping_method', $shippingMethod);
135
  return $shippingMethod;
136
  }
137
-
138
  /**
139
  * Constructs a PostNL track & trace url based on a barcode and the destination of the package (country and zipcode)
140
- *
141
  * @param string $barcode
142
  * @param mixed $destination An array or object containing the shipment's destination data
143
  * @param boolean | string $lang
144
  * @param boolean $forceNl
145
- *
146
  * @return string
147
  */
148
  public function getBarcodeUrl($barcode, $destination = false, $lang = false, $forceNl = false)
@@ -153,17 +156,17 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
153
  $countryCode = $destination['countryCode'];
154
  $postcode = $destination['postcode'];
155
  }
156
-
157
  if (is_object($destination) && $destination instanceof Varien_Object) {
158
  $countryCode = $destination->getCountry();
159
  $postcode = $destination->getPostcode();
160
  }
161
-
162
  /**
163
  * Get the diutch track & trace URL for dutch shipments or for the admin
164
  */
165
  if ($forceNl
166
- || (!empty($countryCode)
167
  && $countryCode == 'NL'
168
  )
169
  ) {
@@ -172,22 +175,22 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
172
  /**
173
  * For dutch shipments add the postcode. For international shipments add an 'international' flag
174
  */
175
- if (!empty($postcode)
176
- && !empty($countryCode)
177
  && $countryCode == 'NL'
178
  ) {
179
  $barcodeUrl .= '&p=' . $postcode;
180
  } else {
181
  $barcodeUrl .= '&i=true';
182
  }
183
-
184
  return $barcodeUrl;
185
  }
186
-
187
  /**
188
  * Get localized track & trace URLs for UK, DE and FR shipments
189
  */
190
- if (isset($countryCode)
191
  && ($countryCode == 'UK'
192
  || $countryCode == 'GB'
193
  )
@@ -196,43 +199,43 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
196
  . '&B=' . $barcode
197
  . '&D=GB'
198
  . '&lang=en';
199
-
200
  return $barcodeUrl;
201
  }
202
-
203
  if (isset($countryCode) && $countryCode == 'DE') {
204
  $barcodeUrl = self::POSTNL_TRACK_AND_TRACE_DE_BASE_URL
205
  . '&B=' . $barcode
206
  . '&D=DE'
207
  . '&lang=de';
208
-
209
  return $barcodeUrl;
210
  }
211
-
212
  if (isset($countryCode) && $countryCode == 'FR') {
213
  $barcodeUrl = self::POSTNL_TRACK_AND_TRACE_FR_BASE_URL
214
  . '&B=' . $barcode
215
  . '&D=FR'
216
  . '&lang=fr';
217
-
218
  return $barcodeUrl;
219
  }
220
-
221
  /**
222
  * Get a general track & trace URL for all other destinations
223
  */
224
  $barcodeUrl = self::POSTNL_TRACK_AND_TRACE_INT_BASE_URL
225
  . '&B=' . $barcode
226
  . '&I=true';
227
-
228
  if ($lang) {
229
  $barcodeUrl .= '&lang=' . strtolower($lang);
230
  }
231
-
232
  if ($countryCode) {
233
  $barcodeUrl .= '&D=' . $countryCode;
234
  }
235
-
236
  return $barcodeUrl;
237
  }
238
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
42
  * Shipping carrier code used by PostNL
43
  */
44
  const POSTNL_CARRIER = 'postnl';
45
+
46
  /**
47
  * PostNL shipping methods
48
  */
49
  const POSTNL_FLATRATE_METHOD = 'flatrate';
50
  const POSTNL_TABLERATE_METHOD = 'tablerate';
51
+
52
  /**
53
  * Localised track and trace base URL's
54
  */
57
  const POSTNL_TRACK_AND_TRACE_DE_BASE_URL = 'http://parcels-de.tntpost.com/de/mytrackandtrace/TrackAndTrace.aspx?';
58
  const POSTNL_TRACK_AND_TRACE_FR_BASE_URL = 'http://parcels-fr.tntpost.com/fr/mytrackandtrace/TrackAndTrace.aspx?';
59
  const POSTNL_TRACK_AND_TRACE_INT_BASE_URL = 'http://www.postnlpakketten.nl/klantenservice/tracktrace/basicsearch.aspx?';
60
+
61
  /**
62
  * XML path to rate type setting
63
  */
64
  const XML_PATH_RATE_TYPE = 'carriers/postnl/rate_type';
65
+
66
  /**
67
  * Array of possible PostNL shipping methods
68
+ *
69
  * @var array
70
  */
71
  protected $_postnlShippingMethods = array(
73
  'postnl_flatrate',
74
  'postnl_tablerate',
75
  );
76
+
77
  /**
78
  * Gets an array of possible PostNL shipping methods
79
+ *
80
  * @return array
81
  */
82
  public function getPostnlShippingMethods()
84
  $shippingMethods = $this->_postnlShippingMethods;
85
  return $shippingMethods;
86
  }
87
+
88
  /**
89
  * Alias for getCurrentPostnlShippingMethod()
90
+ *
91
  * @return string
92
+ *
93
  * @see TIG_PostNL_Helper_Carrier::getCurrentPostnlShippingMethod()
94
+ *
95
  * @deprecated
96
  */
97
  public function getPostnlShippingMethod()
98
  {
99
  return $this->getCurrentPostnlShippingMethod();
100
  }
101
+
102
  /**
103
  * Returns the PostNL shipping method
104
+ *
105
+ * @param null $storeId
106
+ *
107
+ * @throws TIG_PostNL_Exception
108
  * @return string
109
  */
110
  public function getCurrentPostnlShippingMethod($storeId = null)
112
  if (Mage::registry('current_postnl_shipping_method') !== null) {
113
  return Mage::registry('current_postnl_shipping_method');
114
  }
115
+
116
  if (is_null($storeId)) {
117
  $storeId = Mage::app()->getStore()->getId();
118
  }
119
+
120
  $rateType = Mage::getStoreConfig(self::XML_PATH_RATE_TYPE, $storeId);
121
+
122
  $carrier = self::POSTNL_CARRIER;
123
  switch ($rateType) {
124
  case 'flat':
133
  'POSTNL-0036'
134
  );
135
  }
136
+
137
  Mage::register('current_postnl_shipping_method', $shippingMethod);
138
  return $shippingMethod;
139
  }
140
+
141
  /**
142
  * Constructs a PostNL track & trace url based on a barcode and the destination of the package (country and zipcode)
143
+ *
144
  * @param string $barcode
145
  * @param mixed $destination An array or object containing the shipment's destination data
146
  * @param boolean | string $lang
147
  * @param boolean $forceNl
148
+ *
149
  * @return string
150
  */
151
  public function getBarcodeUrl($barcode, $destination = false, $lang = false, $forceNl = false)
156
  $countryCode = $destination['countryCode'];
157
  $postcode = $destination['postcode'];
158
  }
159
+
160
  if (is_object($destination) && $destination instanceof Varien_Object) {
161
  $countryCode = $destination->getCountry();
162
  $postcode = $destination->getPostcode();
163
  }
164
+
165
  /**
166
  * Get the diutch track & trace URL for dutch shipments or for the admin
167
  */
168
  if ($forceNl
169
+ || (!empty($countryCode)
170
  && $countryCode == 'NL'
171
  )
172
  ) {
175
  /**
176
  * For dutch shipments add the postcode. For international shipments add an 'international' flag
177
  */
178
+ if (!empty($postcode)
179
+ && !empty($countryCode)
180
  && $countryCode == 'NL'
181
  ) {
182
  $barcodeUrl .= '&p=' . $postcode;
183
  } else {
184
  $barcodeUrl .= '&i=true';
185
  }
186
+
187
  return $barcodeUrl;
188
  }
189
+
190
  /**
191
  * Get localized track & trace URLs for UK, DE and FR shipments
192
  */
193
+ if (isset($countryCode)
194
  && ($countryCode == 'UK'
195
  || $countryCode == 'GB'
196
  )
199
  . '&B=' . $barcode
200
  . '&D=GB'
201
  . '&lang=en';
202
+
203
  return $barcodeUrl;
204
  }
205
+
206
  if (isset($countryCode) && $countryCode == 'DE') {
207
  $barcodeUrl = self::POSTNL_TRACK_AND_TRACE_DE_BASE_URL
208
  . '&B=' . $barcode
209
  . '&D=DE'
210
  . '&lang=de';
211
+
212
  return $barcodeUrl;
213
  }
214
+
215
  if (isset($countryCode) && $countryCode == 'FR') {
216
  $barcodeUrl = self::POSTNL_TRACK_AND_TRACE_FR_BASE_URL
217
  . '&B=' . $barcode
218
  . '&D=FR'
219
  . '&lang=fr';
220
+
221
  return $barcodeUrl;
222
  }
223
+
224
  /**
225
  * Get a general track & trace URL for all other destinations
226
  */
227
  $barcodeUrl = self::POSTNL_TRACK_AND_TRACE_INT_BASE_URL
228
  . '&B=' . $barcode
229
  . '&I=true';
230
+
231
  if ($lang) {
232
  $barcodeUrl .= '&lang=' . strtolower($lang);
233
  }
234
+
235
  if ($countryCode) {
236
  $barcodeUrl .= '&D=' . $countryCode;
237
  }
238
+
239
  return $barcodeUrl;
240
  }
241
  }
app/code/community/TIG/PostNL/Helper/Checkout.php CHANGED
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
@@ -42,7 +42,6 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
42
  * XML path to checkout on/off switch
43
  */
44
  const XML_PATH_CHECKOUT_ACTIVE = 'postnl/checkout/active';
45
- const XML_PATH_USE_CHECKOUT = 'postnl/cif/use_checkout';
46
 
47
  /**
48
  * XML path to all PostNL Checkout payment methods.
@@ -53,7 +52,7 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
53
  /**
54
  * XML path to test / live mode setting
55
  */
56
- const XML_PATH_TEST_MODE = 'postnl/checkout/mode';
57
 
58
  /**
59
  * XML path for config options used to determine whether or not PostNL Checkout is available
@@ -99,8 +98,8 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
99
  );
100
 
101
  /**
102
- * Array containing conversions between PostNL CHeckout payment option fields and those used by Magento payment methods.
103
- * This array should be extended as time goes on in order to support as many payment methods as possible.
104
  *
105
  * @var array
106
  */
@@ -153,7 +152,8 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
153
  }
154
 
155
  /**
156
- * Returns a conversion array used to convert PostNL Checkout payment method fields to those used by Magento payment methods.
 
157
  *
158
  * @return array
159
  */
@@ -166,8 +166,8 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
166
  $conversionObject = new Varien_Object($conversionArray);
167
 
168
  /**
169
- * You can observe this event in order to add (or modify) conversion options. This prevents you from having to overload
170
- * this helper if you want to change this functionality.
171
  */
172
  Mage::dispatchEvent(
173
  'postnl_checkout_option_conversion_before',
@@ -176,7 +176,7 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
176
  )
177
  );
178
 
179
- return $conversionObject->getConversionArray();;
180
  }
181
 
182
  /**
@@ -251,7 +251,9 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
251
  $errors = array(
252
  array(
253
  'code' => 'POSTNL-0106',
254
- 'message' => $this->__('No standard product options are enabled. At least 1 option must be active.'),
 
 
255
  )
256
  );
257
  Mage::register('postnl_enabled_checkout_errors', $errors);
@@ -271,7 +273,9 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
271
  $errors = array(
272
  array(
273
  'code' => 'POSTNL-0101',
274
- 'message' => $this->__("The quote's total weight is below the miniumum required to use PostNL Checkout."),
 
 
275
  )
276
  );
277
  Mage::register('postnl_enabled_checkout_errors', $errors);
@@ -344,6 +348,7 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
344
  }
345
 
346
  $totalWeight = 0;
 
347
  foreach ($quoteItems as $item) {
348
  $totalWeight += $item->getRowWeight();
349
  }
@@ -382,33 +387,6 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
382
  return false;
383
  }
384
 
385
- /**
386
- * Check if the module is set to test mode
387
- *
388
- * @return boolean
389
- */
390
- public function isTestMode($storeId = false)
391
- {
392
- if (Mage::registry('postnl_checkout_test_mode') !== null) {
393
- return Mage::registry('postnl_checkout_test_mode');
394
- }
395
-
396
- if ($storeId === false) {
397
- $storeId = Mage::app()->getStore()->getId();
398
- }
399
-
400
- $testModeAllowed = $this->isTestModeAllowed();
401
- if (!$testModeAllowed) {
402
- Mage::register('postnl_checkout_test_mode', false);
403
- return false;
404
- }
405
-
406
- $testMode = Mage::getStoreConfigFlag(self::XML_PATH_TEST_MODE, $storeId);
407
-
408
- Mage::register('postnl_checkout_test_mode', $testMode);
409
- return $testMode;
410
- }
411
-
412
  /**
413
  * Checks if PostNL Checkout is active
414
  *
@@ -422,9 +400,7 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
422
  $storeId = Mage::app()->getStore()->getId();
423
  }
424
 
425
- $useCheckout = Mage::getStoreConfigFlag(self::XML_PATH_USE_CHECKOUT, $storeId);
426
-
427
- if (!$useCheckout) {
428
  return false;
429
  }
430
 
@@ -493,7 +469,9 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
493
  $errors = array();
494
 
495
  /**
496
- * Get the system > config fields for this section
 
 
497
  */
498
  $configFields = Mage::getSingleton('adminhtml/config');
499
  $sections = $configFields->getSections('postnl');
@@ -506,22 +484,29 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
506
  foreach ($requiredFields as $requiredField) {
507
  $value = Mage::getStoreConfig($requiredField, $storeId);
508
 
509
- if ($value === null || $value === '') {
510
- $fieldParts = explode('/', $requiredField);
511
- $field = $fieldParts[2];
512
- $group = $fieldParts[1];
513
 
514
- $label = (string) $section->groups->$group->fields->$field->label;
515
- $groupLabel = (string) $section->groups->$group->label;
516
- $groupName = $section->groups->$group->getName();
517
 
518
- $errors[] = array(
519
- 'code' => 'POSTNL-0034',
520
- 'message' => $this->__('%s > %s is required.', $this->__($groupLabel), $this->__($label)),
521
- );
522
 
523
- $this->saveConfigState(array('postnl_' . $groupName => 1));
524
- }
 
 
 
 
 
 
 
 
525
  }
526
 
527
  /**
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
42
  * XML path to checkout on/off switch
43
  */
44
  const XML_PATH_CHECKOUT_ACTIVE = 'postnl/checkout/active';
 
45
 
46
  /**
47
  * XML path to all PostNL Checkout payment methods.
52
  /**
53
  * XML path to test / live mode setting
54
  */
55
+ const XML_PATH_TEST_MODE = 'postnl/cif/mode';
56
 
57
  /**
58
  * XML path for config options used to determine whether or not PostNL Checkout is available
98
  );
99
 
100
  /**
101
+ * Array containing conversions between PostNL CHeckout payment option fields and those used by Magento payment
102
+ * methods. This array should be extended as time goes on in order to support as many payment methods as possible.
103
  *
104
  * @var array
105
  */
152
  }
153
 
154
  /**
155
+ * Returns a conversion array used to convert PostNL Checkout payment method fields to those used by Magento payment
156
+ * methods.
157
  *
158
  * @return array
159
  */
166
  $conversionObject = new Varien_Object($conversionArray);
167
 
168
  /**
169
+ * You can observe this event in order to add (or modify) conversion options. This prevents you from having to
170
+ * overload this helper if you want to change this functionality.
171
  */
172
  Mage::dispatchEvent(
173
  'postnl_checkout_option_conversion_before',
176
  )
177
  );
178
 
179
+ return $conversionObject->getConversionArray();
180
  }
181
 
182
  /**
251
  $errors = array(
252
  array(
253
  'code' => 'POSTNL-0106',
254
+ 'message' => $this->__(
255
+ 'No standard product options are enabled. At least 1 option must be active.'
256
+ ),
257
  )
258
  );
259
  Mage::register('postnl_enabled_checkout_errors', $errors);
273
  $errors = array(
274
  array(
275
  'code' => 'POSTNL-0101',
276
+ 'message' => $this->__(
277
+ "The quote's total weight is below the miniumum required to use PostNL Checkout."
278
+ ),
279
  )
280
  );
281
  Mage::register('postnl_enabled_checkout_errors', $errors);
348
  }
349
 
350
  $totalWeight = 0;
351
+ /** @var Mage_Sales_Model_Quote_Item $item */
352
  foreach ($quoteItems as $item) {
353
  $totalWeight += $item->getRowWeight();
354
  }
387
  return false;
388
  }
389
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  /**
391
  * Checks if PostNL Checkout is active
392
  *
400
  $storeId = Mage::app()->getStore()->getId();
401
  }
402
 
403
+ if (!parent::isActive()) {
 
 
404
  return false;
405
  }
406
 
469
  $errors = array();
470
 
471
  /**
472
+ * Get the system > config fields for this section.
473
+ *
474
+ * @var Varien_Simplexml_Element $section
475
  */
476
  $configFields = Mage::getSingleton('adminhtml/config');
477
  $sections = $configFields->getSections('postnl');
484
  foreach ($requiredFields as $requiredField) {
485
  $value = Mage::getStoreConfig($requiredField, $storeId);
486
 
487
+ if ($value !== null && $value !== '') {
488
+ continue;
489
+ }
 
490
 
491
+ $fieldParts = explode('/', $requiredField);
492
+ $field = $fieldParts[2];
493
+ $group = $fieldParts[1];
494
 
495
+ /**
496
+ * @var Varien_Simplexml_Element $sectionGroup
497
+ */
498
+ $sectionGroup = $section->groups->$group;
499
 
500
+ $label = (string) $sectionGroup->fields->$field->label;
501
+ $groupLabel = (string) $sectionGroup->label;
502
+ $groupName = $sectionGroup->getName();
503
+
504
+ $errors[] = array(
505
+ 'code' => 'POSTNL-0034',
506
+ 'message' => $this->__('%s > %s is required.', $this->__($groupLabel), $this->__($label)),
507
+ );
508
+
509
+ $this->saveConfigState(array('postnl_' . $groupName => 1));
510
  }
511
 
512
  /**
app/code/community/TIG/PostNL/Helper/Cif.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,10 +33,10 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
-
40
  /**
41
  * Helper class for CIF operations
42
  */
@@ -46,44 +46,56 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
46
  * Log filename to log all CIF exceptions
47
  */
48
  const CIF_EXCEPTION_LOG_FILE = 'TIG_PostNL_CIF_Exception.log';
49
-
50
  /**
51
  * Log filename to log CIF calls
52
  */
53
  const CIF_DEBUG_LOG_FILE = 'TIG_PostNL_CIF_Debug.log';
54
-
55
  /**
56
  * available barcode types
57
  */
58
  const DUTCH_BARCODE_TYPE = 'NL';
59
  const EU_BARCODE_TYPE = 'EU';
60
  const GLOBAL_BARCODE_TYPE = 'GLOBAL';
61
-
62
  /**
63
  * XML path to infinite label printiong setting
64
  */
65
  const XML_PATH_INFINITE_LABEL_PRINTING = 'postnl/advanced/infinite_label_printing';
66
-
67
  /**
68
  * XML path to weight unit used
69
  */
70
  const XML_PATH_WEIGHT_UNIT = 'postnl/cif_labels_and_confirming/weight_unit';
71
-
72
  /**
73
  * XML path to weight per parcel config setting
74
  */
75
- const XML_PATH_WEIGHT_PER_PARCEL = 'postnl/cif_labels_and_confirming/weight_per_parcel';
76
-
77
  /**
78
  * XML paths to default product options settings
79
  */
80
- const XML_PATH_DEFAULT_STANDARD_PRODUCT_OPTION = 'postnl/cif_product_options/default_product_option';
81
- const XML_PATH_DEFAULT_EU_PRODUCT_OPTION = 'postnl/cif_product_options/default_eu_product_option';
82
- const XML_PATH_DEFAULT_GLOBAL_PRODUCT_OPTION = 'postnl/cif_product_options/default_global_product_option';
83
-
 
 
 
 
 
 
 
 
 
 
 
 
84
  /**
85
  * Array of countries to which PostNL ships using EPS. Other EU countries are shipped to using GlobalPack
86
- *
87
  * @var array
88
  */
89
  protected $_euCountries = array(
@@ -111,24 +123,24 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
111
  'CZ',
112
  'SE',
113
  );
114
-
115
  /**
116
  * Array of country-restricted product codes
117
- *
118
  * Array is constructed as follows:
119
  * <restricted code> => array(<allowed country>, <allowed country>, <allowed country>,...)
120
- *
121
  * @var array
122
  */
123
  protected $_countryRestrictedProductCodes = array(
124
  '4955' => array(
125
- 'BE',
126
- ),
127
  );
128
-
129
  /**
130
- * Array of supported shipment types
131
- *
132
  * @var array
133
  */
134
  protected $_shipmentTypes = array(
@@ -138,10 +150,23 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
138
  'commercial_sample' => 'Commercial Sample',
139
  'returned_goods' => 'Returned Goods',
140
  );
141
-
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  /**
143
  * Array of possible shipping phases
144
- *
145
  * @var array
146
  */
147
  protected $_shippingPhases = array(
@@ -151,30 +176,55 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
151
  '4' => 'Delivered',
152
  '99' => 'Shipment not found',
153
  );
154
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  /**
156
  * Get an array of EU countries
157
- *
158
  * @return array
159
  */
160
  public function getEuCountries()
161
  {
162
  return $this->_euCountries;
163
  }
164
-
165
  /**
166
  * Gets an array of country-restricted product codes
167
- *
168
  * @return array
169
  */
170
  public function getCountryRestrictedProductCodes()
171
  {
172
  return $this->_countryRestrictedProductCodes;
173
  }
174
-
175
  /**
176
  * Get an array of standard product codes
177
- *
 
 
178
  * @return array
179
  */
180
  public function getStandardProductCodes($storeId = false)
@@ -182,10 +232,25 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
182
  $standardProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
183
  return $standardProductCodes->getAvailableOptions($storeId, true);
184
  }
185
-
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  /**
187
  * Get an array of pakjegemak product codes
188
- *
 
 
189
  * @return array
190
  */
191
  public function getPakjeGemakProductCodes($storeId = false)
@@ -193,10 +258,40 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
193
  $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
194
  return $pakjeGemakProductCodes->getAvailableOptions($storeId, true);
195
  }
196
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  /**
198
  * Get an array of eu product codes
199
- *
 
 
200
  * @return array
201
  */
202
  public function getEuProductCodes($storeId = false)
@@ -204,10 +299,12 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
204
  $euProductCodes = Mage::getSingleton('postnl_core/system_config_source_euProductOptions');
205
  return $euProductCodes->getAvailableOptions($storeId, true);
206
  }
207
-
208
  /**
209
  * Get an array of global product codes
210
- *
 
 
211
  * @return array
212
  */
213
  public function getGlobalProductCodes($storeId = false)
@@ -215,56 +312,86 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
215
  $globalProductCodes = Mage::getSingleton('postnl_core/system_config_source_globalProductOptions');
216
  return $globalProductCodes->getAvailableOptions($storeId, true);
217
  }
218
-
219
  /**
220
  * Get an array of possible shipment types
221
- *
222
  * @return array
223
  */
224
  public function getShipmentTypes()
225
  {
226
  return $this->_shipmentTypes;
227
  }
228
-
 
 
 
 
 
 
 
 
 
 
229
  /**
230
  * Get an array of possible shipping phases
231
- *
232
  * @return array
233
  */
234
  public function getShippingPhases()
235
  {
236
  $shippingPhases = $this->_shippingPhases;
237
- foreach ($shippingPhases as $key => &$value) {
238
  $value = $this->__($value);
239
  }
240
-
241
  return $shippingPhases;
242
  }
243
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  /**
245
  * Checks if infinite label printing is enabled in the module configuration.
246
- *
247
  * @return boolean
248
  */
249
  public function allowInfinitePrinting()
250
  {
251
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
252
  $enabled = Mage::getStoreConfigFlag(self::XML_PATH_INFINITE_LABEL_PRINTING, $storeId);
253
-
254
  return $enabled;
255
  }
256
  /**
257
  * Checks which barcode type is applicable for this shipment
258
- *
259
  * Possible return values:
260
  * - NL
261
  * - EU
262
  * - GLOBAL
263
- *
264
- * @var Mage_Sales_Model_Order_Shipment
265
- *
266
  * @return string | TIG_PostNL_Helper_Cif
267
- *
268
  * @throws TIG_PostNL_Exception
269
  */
270
  public function getBarcodeTypeForShipment($shipment)
@@ -273,30 +400,28 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
273
  $barcodeType = self::DUTCH_BARCODE_TYPE;
274
  return $barcodeType;
275
  }
276
-
277
  if ($shipment->isEuShipment()) {
278
  $barcodeType = self::EU_BARCODE_TYPE;
279
  return $barcodeType;
280
  }
281
-
282
  if ($shipment->isGlobalShipment()) {
283
  $barcodeType = self::GLOBAL_BARCODE_TYPE;
284
  return $barcodeType;
285
  }
286
-
287
  throw new TIG_PostNL_Exception(
288
  $this->__('Unable to get valid barcodetype for postnl shipment id #%s', $shipment->getId()),
289
  'POSTNL-0029'
290
  );
291
-
292
- return $this;
293
  }
294
-
295
  /**
296
  * Get a list of available product options for a specified shipment
297
- *
298
  * @param Mage_Sales_Model_Order_Shipment $shipment
299
- *
300
  * @return array | null
301
  */
302
  public function getProductOptionsForShipment($shipment)
@@ -307,305 +432,357 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
307
  if ($this->isPakjeGemakShipment($shipment)) {
308
  $options = Mage::getModel('postnl_core/system_config_source_pakjeGemakProductOptions')
309
  ->getAvailableOptions();
310
-
 
 
 
 
 
 
 
 
 
 
311
  return $options;
312
  }
313
-
314
  /**
315
  * Dutch product options
316
  */
317
  if ($this->isDutchShipment($shipment)) {
318
  $options = Mage::getModel('postnl_core/system_config_source_standardProductOptions')
319
  ->getAvailableOptions();
320
-
321
  return $options;
322
  }
323
-
324
  /**
325
  * EU product options
326
  */
327
  if ($this->isEuShipment($shipment)) {
328
  $options = Mage::getModel('postnl_core/system_config_source_euProductOptions')
329
  ->getAvailableOptions();
330
-
331
  return $options;
332
  }
333
-
334
  /**
335
  * Global product options
336
  */
337
  if ($this->isGlobalShipment($shipment)) {
338
  $options = Mage::getModel('postnl_core/system_config_source_globalProductOptions')
339
  ->getAvailableOptions();
340
-
341
  return $options;
342
  }
343
-
344
  return null;
345
  }
346
-
347
  /**
348
  * Check if a given shipment is PakjeGemak
349
- *
350
- * @param TIG_PostNL_Model_Core_Shipment | Mage_Sales_Model_Order_Shipment $shipment
351
- *
352
  * @return boolean
353
- *
354
- * @see TIG_PostNL_Model_Core_Shipment->isDutchSHipment();
355
  */
356
  public function isPakjeGemakShipment($shipment)
357
  {
358
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
359
  if ($shipment instanceof $postnlShipmentClass) {
 
 
 
360
  return $shipment->isPakjeGemakShipment();
361
  }
362
-
363
  $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
364
  $tempPostnlShipment->setShipment($shipment);
365
-
366
  return $tempPostnlShipment->isPakjeGemakShipment();
367
  }
368
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  /**
370
  * Check if a given shipment is dutch
371
- *
372
  * @param TIG_PostNL_Model_Core_Shipment | Mage_Sales_Model_Order_Shipment $shipment
373
- *
374
  * @return boolean
375
- *
376
  * @see TIG_PostNL_Model_Core_Shipment->isDutchSHipment();
377
  */
378
  public function isDutchShipment($shipment)
379
  {
380
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
381
  if ($shipment instanceof $postnlShipmentClass) {
 
 
 
382
  return $shipment->isDutchShipment();
383
  }
384
-
385
  $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
386
  $tempPostnlShipment->setShipment($shipment);
387
-
388
  return $tempPostnlShipment->isDutchShipment();
389
  }
390
-
391
  /**
392
  * Check if a given shipment has an EU destination
393
- *
394
  * @param TIG_PostNL_Model_Core_Shipment | Mage_Sales_Model_Order_Shipment $shipment
395
- *
396
  * @return boolean
397
- *
398
- * @see TIG_PostNL_Model_Core_Shipment->isDutchSHipment();
399
  */
400
  public function isEuShipment($shipment)
401
  {
402
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
403
  if ($shipment instanceof $postnlShipmentClass) {
 
 
 
404
  return $shipment->isEuShipment();
405
  }
406
-
407
  $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
408
  $tempPostnlShipment->setShipment($shipment);
409
-
410
  return $tempPostnlShipment->isEuShipment();
411
  }
412
-
413
  /**
414
  * Check if a given shipment has a global destination
415
- *
416
- * @param TIG_PostNL_Model_Core_Shipment | Mage_Sales_Model_Order_Shipment $shipment
417
- *
418
  * @return boolean
419
- *
420
- * @see TIG_PostNL_Model_Core_Shipment->isDutchSHipment();
421
  */
422
  public function isGlobalShipment($shipment)
423
  {
424
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
425
  if ($shipment instanceof $postnlShipmentClass) {
 
 
 
426
  return $shipment->isGlobalShipment();
427
  }
428
-
429
  $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
430
  $tempPostnlShipment->setShipment($shipment);
431
-
432
  return $tempPostnlShipment->isGlobalShipment();
433
  }
434
-
435
  /**
436
  * Gets the default product option for a shipment
437
- *
438
  * @param Mage_Sales_Model_Order_Shipment
439
- *
440
  * @return string
441
  */
442
  public function getDefaultProductOptionForShipment($shipment)
443
  {
444
  $postnlShipment = Mage::getModel('postnl_core/shipment');
445
  $postnlShipment->setShipment($shipment);
446
-
447
  $productOption = $postnlShipment->getDefaultProductCode();
448
-
449
  return $productOption;
450
  }
451
-
452
  /**
453
  * Get an array of all default product options. This is a simple method to quickly get a list of default options based on
454
  * the current storeview.
455
- *
456
  * This does not take into account the possible use of an alternative default for dutch shipments. For that you need to use
457
  * TIG_PostNL_Model_Core_Shipment::getDefaultProductCode() which is more precise.
458
- *
459
  * @return array
460
  */
461
  public function getDefaultProductOptions()
462
  {
463
  $storeId = Mage::app()->getStore()->getId();
464
-
465
- $defaultDutchOption = Mage::getStoreConfig(self::XML_PATH_DEFAULT_STANDARD_PRODUCT_OPTION, $storeId);
466
- $defaultEuOption = Mage::getStoreConfig(self::XML_PATH_DEFAULT_EU_PRODUCT_OPTION, $storeId);
467
- $defaultGlobalOption = Mage::getStoreConfig(self::XML_PATH_DEFAULT_GLOBAL_PRODUCT_OPTION, $storeId);
468
-
 
 
 
 
469
  $defaultOptions = array(
470
- 'dutch' => $defaultDutchOption,
471
- 'eu' => $defaultEuOption,
472
- 'global' => $defaultGlobalOption,
 
473
  );
474
-
475
  return $defaultOptions;
476
  }
477
-
478
  /**
479
  * Gets the number of parcels in this shipment based on it's weight
480
- *
481
  * @param Mage_Sales_Model_Order_Shipment $shipment
482
- *
483
  * @return int
484
  */
485
  public function getParcelCount($shipment)
486
  {
487
  $postnlShipment = Mage::getModel('postnl_core/shipment');
488
  $postnlShipment->setShipment($shipment);
489
-
490
  /**
491
  * Only NL shipments support multi-colli shipments
492
  */
493
  if (!$postnlShipment->isDutchShipment()) {
494
  return 1;
495
  }
496
-
497
  /**
498
  * get this shipment's total weight
499
  */
500
  $weight = $postnlShipment->getTotalWeight(true);
501
-
502
  /**
503
  * get the weight per parcel
504
  */
505
  $weightPerParcel = Mage::getStoreConfig(self::XML_PATH_WEIGHT_PER_PARCEL, $shipment->getStoreId());
506
  $weightPerParcel = $this->standardizeWeight($weightPerParcel, $shipment->getStoreId());
507
-
508
  /**
509
  * calculate the number of parcels needed to ship the total weight of this shipment
510
  */
511
  $parcelCount = ceil($weight / $weightPerParcel);
512
-
513
  return $parcelCount;
514
  }
515
-
516
  /**
517
  * Checks if a given postnl shipment exists using Zend_Validate_Db_RecordExists.
518
- *
519
  * @param string $shipmentId
520
- *
521
  * @return boolean
522
- *
523
  * @see Zend_Validate_Db_RecordExists
524
- *
525
  * @link http://framework.zend.com/manual/1.12/en/zend.validate.set.html#zend.validate.Db
526
  */
527
  public function postnlShipmentExists($shipmentId)
528
  {
529
  $coreResource = Mage::getSingleton('core/resource');
530
  $readAdapter = $coreResource->getConnection('core_read');
531
-
532
- $validator = Mage::getModel('Zend_Validate_Db_RecordExists',
533
  array(
534
  'table' => $coreResource->getTableName('postnl_core/shipment'),
535
  'field' => 'shipment_id',
536
  'adapter' => $readAdapter,
537
  )
538
  );
539
-
540
  $postnlShipmentExists = $validator->isValid($shipmentId);
541
-
542
  if ($postnlShipmentExists) {
543
  return true;
544
  }
545
-
546
  return false;
547
  }
548
-
549
  /**
550
  * Checks if a given barcode exists using Zend_Validate_Db_RecordExists.
551
- *
552
  * @param string $barcode
553
- *
554
  * @return boolean
555
- *
556
  * @see Zend_Validate_Db_RecordExists
557
- *
558
  * @link http://framework.zend.com/manual/1.12/en/zend.validate.set.html#zend.validate.Db
559
  */
560
  public function barcodeExists($barcode)
561
  {
562
  $coreResource = Mage::getSingleton('core/resource');
563
  $readAdapter = $coreResource->getConnection('core_read');
564
-
565
  /**
566
  * Check if the barcode exists as a main barcode
567
  */
568
- $validator = Mage::getModel('Zend_Validate_Db_RecordExists',
569
  array(
570
  'table' => $coreResource->getTableName('postnl_core/shipment'),
571
  'field' => 'main_barcode',
572
  'adapter' => $readAdapter,
573
  )
574
  );
575
-
576
  $barcodeExists = $validator->isValid($barcode);
577
-
578
  if ($barcodeExists) {
579
  return true;
580
  }
581
-
582
  /**
583
  * Check if the barcode exists as a secondary barcode
584
  */
585
- $validator = Mage::getModel('Zend_Validate_Db_RecordExists',
586
  array(
587
  'table' => $coreResource->getTableName('postnl_core/shipment_barcode'),
588
  'field' => 'barcode',
589
  'adapter' => $readAdapter,
590
  )
591
  );
592
-
593
  $barcodeExists = $validator->isValid($barcode);
594
-
595
  if ($barcodeExists) {
596
  return true;
597
  }
598
-
599
  return false;
600
  }
601
-
602
  /**
603
  * Convert a given weight to kilogram or gram
604
- *
605
  * @param float $weight The weight to be converted
606
  * @param int | null $storeId Store Id used to determine the weight unit that was originally used
607
  * @param boolean $toGram Optional parameter to convert to gram instead of kilogram
608
- *
609
  * @return float
610
  */
611
  public function standardizeWeight($weight, $storeId = null, $toGram = false)
@@ -613,10 +790,9 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
613
  if (is_null($storeId)) {
614
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
615
  }
616
-
617
  $unitUsed = Mage::getStoreConfig(self::XML_PATH_WEIGHT_UNIT, $storeId);
618
-
619
- $returnWeight = $weight;
620
  switch ($unitUsed) {
621
  case 'tonne':
622
  $returnWeight = $weight * 1000;
@@ -657,9 +833,6 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
657
  case 'pound':
658
  $returnWeight = $weight * 0.45359237;
659
  break;
660
- case 'shortton':
661
- $returnWeight = $weight * 907;
662
- break;
663
  case 'ounce':
664
  $returnWeight = $weight * 0.028349523125;
665
  break;
@@ -690,75 +863,283 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
690
  if ($toGram === true) {
691
  $returnWeight *= 1000;
692
  }
693
-
694
  return $returnWeight;
695
  }
696
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
697
  /**
698
  * Logs a CIF request and response for debug purposes.
699
- *
700
  * N.B.: if file logging is enabled, the log will be forced
701
- *
702
- * @param SoapClient $client
703
- *
704
  * @return TIG_PostNL_Helper_Cif
705
- *
706
  * @see Mage::log()
707
- *
708
- * @todo add additional debug options
709
- *
710
  */
711
  public function logCifCall($client)
712
  {
713
- if (!$this->isLoggingEnabled()) {
714
  return $this;
715
  }
716
-
717
  $requestXml = $this->formatXml($client->getLastRequest());
718
  $responseXML = $this->formatXml($client->getLastResponse());
719
-
720
  $logMessage = "Request sent:\n"
721
  . $requestXml
722
  . "\nResponse received:\n"
723
  . $responseXML;
724
-
725
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::CIF_DEBUG_LOG_FILE;
726
  $this->log($logMessage, Zend_Log::DEBUG, $file);
727
-
728
  return $this;
729
  }
730
-
731
  /**
732
- * Logs a CIF exception in the database and/or a log file
733
- *
734
- * N.B.: if file logging is enabled, the log will be forced
735
- *
736
  * @param Mage_Core_Exception | TIG_PostNL_Model_Core_Cif_Exception $exception
737
- *
738
  * @return TIG_PostNL_Helper_Cif
739
- *
740
  * @see Mage::logException()
741
- *
742
- * @todo add additional debug options
743
  */
744
  public function logCifException($exception)
745
  {
746
  if (!$this->isExceptionLoggingEnabled()) {
747
  return $this;
748
  }
749
-
750
  if ($exception instanceof TIG_PostNL_Model_Core_Cif_Exception) {
751
  $requestXml = $this->formatXml($exception->getRequestXml());
752
  $responseXML = $this->formatXml($exception->getResponseXml());
753
-
754
  $logMessage = '';
755
-
756
  $errorNumbers = $exception->getErrorNumbers();
757
  if (!empty($errorNumbers)) {
758
  $errorNumbers = implode(', ', $errorNumbers);
759
  $logMessage .= "Error numbers received: {$errorNumbers}\n";
760
  }
761
-
762
  $logMessage .= "<<< REQUEST SENT >>>\n"
763
  . $requestXml
764
  . "\n<<< RESPONSE RECEIVED >>>\n"
@@ -766,10 +1147,10 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
766
  } else {
767
  $logMessage = "\n" . $exception->__toString();
768
  }
769
-
770
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::CIF_EXCEPTION_LOG_FILE;
771
  $this->log($logMessage, Zend_Log::ERR, $file, false, true);
772
-
773
  return $this;
774
  }
775
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+
40
  /**
41
  * Helper class for CIF operations
42
  */
46
  * Log filename to log all CIF exceptions
47
  */
48
  const CIF_EXCEPTION_LOG_FILE = 'TIG_PostNL_CIF_Exception.log';
49
+
50
  /**
51
  * Log filename to log CIF calls
52
  */
53
  const CIF_DEBUG_LOG_FILE = 'TIG_PostNL_CIF_Debug.log';
54
+
55
  /**
56
  * available barcode types
57
  */
58
  const DUTCH_BARCODE_TYPE = 'NL';
59
  const EU_BARCODE_TYPE = 'EU';
60
  const GLOBAL_BARCODE_TYPE = 'GLOBAL';
61
+
62
  /**
63
  * XML path to infinite label printiong setting
64
  */
65
  const XML_PATH_INFINITE_LABEL_PRINTING = 'postnl/advanced/infinite_label_printing';
66
+
67
  /**
68
  * XML path to weight unit used
69
  */
70
  const XML_PATH_WEIGHT_UNIT = 'postnl/cif_labels_and_confirming/weight_unit';
71
+
72
  /**
73
  * XML path to weight per parcel config setting
74
  */
75
+ const XML_PATH_WEIGHT_PER_PARCEL = 'postnl/cif_labels_and_confirming/weight_per_parcel';
76
+
77
  /**
78
  * XML paths to default product options settings
79
  */
80
+ const XML_PATH_DEFAULT_STANDARD_PRODUCT_OPTION = 'postnl/cif_product_options/default_product_option';
81
+ const XML_PATH_DEFAULT_EU_PRODUCT_OPTION = 'postnl/cif_product_options/default_eu_product_option';
82
+ const XML_PATH_DEFAULT_GLOBAL_PRODUCT_OPTION = 'postnl/cif_product_options/default_global_product_option';
83
+ const XML_PATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION = 'postnl/cif_product_options/default_pakketautomaat_product_option';
84
+
85
+ /**
86
+ * Regular expression used to split streetname from housenumber. This regex works well for dutch addresses, but may
87
+ * fail for international addresses. We strongly recommend using split address lines instead.
88
+ */
89
+ const SPLIT_STREET_REGEX = '#\A(.*?)\s+(\d+[a-zA-Z]{0,1}\s{0,1}[-]{1}\s{0,1}\d*[a-zA-Z]{0,1}|\d+[a-zA-Z-]{0,1}\d*[a-zA-Z]{0,1})#';
90
+
91
+ /**
92
+ * Regular expression used to split housenumber and housenumber extension
93
+ */
94
+ const SPLIT_HOUSENUMBER_REGEX = '#^([\d]+)(.*)#s';
95
+
96
  /**
97
  * Array of countries to which PostNL ships using EPS. Other EU countries are shipped to using GlobalPack
98
+ *
99
  * @var array
100
  */
101
  protected $_euCountries = array(
123
  'CZ',
124
  'SE',
125
  );
126
+
127
  /**
128
  * Array of country-restricted product codes
129
+ *
130
  * Array is constructed as follows:
131
  * <restricted code> => array(<allowed country>, <allowed country>, <allowed country>,...)
132
+ *
133
  * @var array
134
  */
135
  protected $_countryRestrictedProductCodes = array(
136
  '4955' => array(
137
+ 'BE',
138
+ ),
139
  );
140
+
141
  /**
142
+ * Array of supported shipment types.
143
+ *
144
  * @var array
145
  */
146
  protected $_shipmentTypes = array(
150
  'commercial_sample' => 'Commercial Sample',
151
  'returned_goods' => 'Returned Goods',
152
  );
153
+
154
+ /**
155
+ * Array of supported shipment types and their numeric counterparts.
156
+ *
157
+ * @var array
158
+ */
159
+ protected $_numericShipmentTypes = array(
160
+ 'Gift' => 0,
161
+ 'Documents' => 1,
162
+ 'Commercial Goods' => 2,
163
+ 'Commercial Sample' => 3,
164
+ 'Returned Goods' => 4,
165
+ );
166
+
167
  /**
168
  * Array of possible shipping phases
169
+ *
170
  * @var array
171
  */
172
  protected $_shippingPhases = array(
176
  '4' => 'Delivered',
177
  '99' => 'Shipment not found',
178
  );
179
+
180
+ /**
181
+ * Array of countires which may send their full street data in a single line,
182
+ * rather than having to split them into streetname, housenr and extension parts
183
+ *
184
+ * @var array
185
+ */
186
+ protected $_allowedFullStreetCountries = array(
187
+ 'NL',
188
+ 'BE'
189
+ );
190
+
191
+ /**
192
+ * Array of EPS product codes and their combi-label counterparts.
193
+ *
194
+ * @var array
195
+ */
196
+ protected $_combiLabelProductCodes = array(
197
+ '4940' => '4950',
198
+ '4924' => '4954',
199
+ '4946' => '4955',
200
+ '4944' => '4952',
201
+ );
202
+
203
  /**
204
  * Get an array of EU countries
205
+ *
206
  * @return array
207
  */
208
  public function getEuCountries()
209
  {
210
  return $this->_euCountries;
211
  }
212
+
213
  /**
214
  * Gets an array of country-restricted product codes
215
+ *
216
  * @return array
217
  */
218
  public function getCountryRestrictedProductCodes()
219
  {
220
  return $this->_countryRestrictedProductCodes;
221
  }
222
+
223
  /**
224
  * Get an array of standard product codes
225
+ *
226
+ * @param bool $storeId
227
+ *
228
  * @return array
229
  */
230
  public function getStandardProductCodes($storeId = false)
232
  $standardProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
233
  return $standardProductCodes->getAvailableOptions($storeId, true);
234
  }
235
+
236
+ /**
237
+ * Get an array of evening delivery product codes.
238
+ *
239
+ * @param bool $storeId
240
+ *
241
+ * @return array
242
+ */
243
+ public function getAvondProductCodes($storeId = false)
244
+ {
245
+ $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
246
+ return $pakjeGemakProductCodes->getAvailableAvondOptions($storeId, true);
247
+ }
248
+
249
  /**
250
  * Get an array of pakjegemak product codes
251
+ *
252
+ * @param bool $storeId
253
+ *
254
  * @return array
255
  */
256
  public function getPakjeGemakProductCodes($storeId = false)
258
  $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
259
  return $pakjeGemakProductCodes->getAvailableOptions($storeId, true);
260
  }
261
+
262
+ /**
263
+ * Get an array of PakjeGemak Express product codes.
264
+ *
265
+ * @param bool $storeId
266
+ *
267
+ * @return array
268
+ */
269
+ public function getPgeProductCodes($storeId = false)
270
+ {
271
+ $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
272
+ return $pakjeGemakProductCodes->getAvailablePgeOptions($storeId, true);
273
+ }
274
+
275
+ /**
276
+ * Get an array of pakketautomaat product codes
277
+ *
278
+ * @param bool $storeId
279
+ *
280
+ * @return array
281
+ */
282
+ public function getPakketautomaatProductCodes($storeId = false)
283
+ {
284
+ $pakketautomaatProductCodes = Mage::getSingleton(
285
+ 'postnl_core/system_config_source_pakketautomaatProductOptions'
286
+ );
287
+ return $pakketautomaatProductCodes->getAvailableOptions($storeId, true);
288
+ }
289
+
290
  /**
291
  * Get an array of eu product codes
292
+ *
293
+ * @param bool $storeId
294
+ *
295
  * @return array
296
  */
297
  public function getEuProductCodes($storeId = false)
299
  $euProductCodes = Mage::getSingleton('postnl_core/system_config_source_euProductOptions');
300
  return $euProductCodes->getAvailableOptions($storeId, true);
301
  }
302
+
303
  /**
304
  * Get an array of global product codes
305
+ *
306
+ * @param bool $storeId
307
+ *
308
  * @return array
309
  */
310
  public function getGlobalProductCodes($storeId = false)
312
  $globalProductCodes = Mage::getSingleton('postnl_core/system_config_source_globalProductOptions');
313
  return $globalProductCodes->getAvailableOptions($storeId, true);
314
  }
315
+
316
  /**
317
  * Get an array of possible shipment types
318
+ *
319
  * @return array
320
  */
321
  public function getShipmentTypes()
322
  {
323
  return $this->_shipmentTypes;
324
  }
325
+
326
+ /**
327
+ * Get an array of numeric shipment types
328
+ *
329
+ * @return array
330
+ */
331
+ public function getNumericShipmentTypes()
332
+ {
333
+ return $this->_numericShipmentTypes;
334
+ }
335
+
336
  /**
337
  * Get an array of possible shipping phases
338
+ *
339
  * @return array
340
  */
341
  public function getShippingPhases()
342
  {
343
  $shippingPhases = $this->_shippingPhases;
344
+ foreach ($shippingPhases as &$value) {
345
  $value = $this->__($value);
346
  }
347
+
348
  return $shippingPhases;
349
  }
350
+
351
+ /**
352
+ * Get country IDs that allow fullstreet usage
353
+ *
354
+ * @return array
355
+ */
356
+ public function getAllowedFullStreetCountries()
357
+ {
358
+ return $this->_allowedFullStreetCountries;
359
+ }
360
+
361
+ /**
362
+ * Get EPS combilabel codes.
363
+ *
364
+ * @return array
365
+ */
366
+ public function getCombiLabelProductCodes()
367
+ {
368
+ return $this->_combiLabelProductCodes;
369
+ }
370
+
371
  /**
372
  * Checks if infinite label printing is enabled in the module configuration.
373
+ *
374
  * @return boolean
375
  */
376
  public function allowInfinitePrinting()
377
  {
378
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
379
  $enabled = Mage::getStoreConfigFlag(self::XML_PATH_INFINITE_LABEL_PRINTING, $storeId);
380
+
381
  return $enabled;
382
  }
383
  /**
384
  * Checks which barcode type is applicable for this shipment
385
+ *
386
  * Possible return values:
387
  * - NL
388
  * - EU
389
  * - GLOBAL
390
+ *
391
+ * @param TIG_PostNL_Model_Core_Shipment $shipment
392
+ *
393
  * @return string | TIG_PostNL_Helper_Cif
394
+ *
395
  * @throws TIG_PostNL_Exception
396
  */
397
  public function getBarcodeTypeForShipment($shipment)
400
  $barcodeType = self::DUTCH_BARCODE_TYPE;
401
  return $barcodeType;
402
  }
403
+
404
  if ($shipment->isEuShipment()) {
405
  $barcodeType = self::EU_BARCODE_TYPE;
406
  return $barcodeType;
407
  }
408
+
409
  if ($shipment->isGlobalShipment()) {
410
  $barcodeType = self::GLOBAL_BARCODE_TYPE;
411
  return $barcodeType;
412
  }
413
+
414
  throw new TIG_PostNL_Exception(
415
  $this->__('Unable to get valid barcodetype for postnl shipment id #%s', $shipment->getId()),
416
  'POSTNL-0029'
417
  );
 
 
418
  }
419
+
420
  /**
421
  * Get a list of available product options for a specified shipment
422
+ *
423
  * @param Mage_Sales_Model_Order_Shipment $shipment
424
+ *
425
  * @return array | null
426
  */
427
  public function getProductOptionsForShipment($shipment)
432
  if ($this->isPakjeGemakShipment($shipment)) {
433
  $options = Mage::getModel('postnl_core/system_config_source_pakjeGemakProductOptions')
434
  ->getAvailableOptions();
435
+
436
+ return $options;
437
+ }
438
+
439
+ /**
440
+ * Pakketautomaat product options
441
+ */
442
+ if ($this->isPakketautomaatShipment($shipment)) {
443
+ $options = Mage::getModel('postnl_core/system_config_source_pakketautomaatProductOptions')
444
+ ->getAvailableOptions();
445
+
446
  return $options;
447
  }
448
+
449
  /**
450
  * Dutch product options
451
  */
452
  if ($this->isDutchShipment($shipment)) {
453
  $options = Mage::getModel('postnl_core/system_config_source_standardProductOptions')
454
  ->getAvailableOptions();
455
+
456
  return $options;
457
  }
458
+
459
  /**
460
  * EU product options
461
  */
462
  if ($this->isEuShipment($shipment)) {
463
  $options = Mage::getModel('postnl_core/system_config_source_euProductOptions')
464
  ->getAvailableOptions();
465
+
466
  return $options;
467
  }
468
+
469
  /**
470
  * Global product options
471
  */
472
  if ($this->isGlobalShipment($shipment)) {
473
  $options = Mage::getModel('postnl_core/system_config_source_globalProductOptions')
474
  ->getAvailableOptions();
475
+
476
  return $options;
477
  }
478
+
479
  return null;
480
  }
481
+
482
  /**
483
  * Check if a given shipment is PakjeGemak
484
+ *
485
+ * @param TIG_PostNL_Model_Core_Shipment|Mage_Sales_Model_Order_Shipment $shipment
486
+ *
487
  * @return boolean
488
+ *
489
+ * @see TIG_PostNL_Model_Core_Shipment->isPakjeGemakShipment();
490
  */
491
  public function isPakjeGemakShipment($shipment)
492
  {
493
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
494
  if ($shipment instanceof $postnlShipmentClass) {
495
+ /**
496
+ * @var TIG_PostNL_Model_Core_Shipment $shipment
497
+ */
498
  return $shipment->isPakjeGemakShipment();
499
  }
500
+
501
  $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
502
  $tempPostnlShipment->setShipment($shipment);
503
+
504
  return $tempPostnlShipment->isPakjeGemakShipment();
505
  }
506
+
507
+ /**
508
+ * Check if a given shipment is a pakketautomaat shipment.
509
+ *
510
+ * @param TIG_PostNL_Model_Core_Shipment|Mage_Sales_Model_Order_Shipment $shipment
511
+ *
512
+ * @return boolean
513
+ *
514
+ * @see TIG_PostNL_Model_Core_Shipment->isDutchShipment();
515
+ */
516
+ public function isPakketautomaatShipment($shipment)
517
+ {
518
+ $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
519
+ if ($shipment instanceof $postnlShipmentClass) {
520
+ /**
521
+ * @var TIG_PostNL_Model_Core_Shipment $shipment
522
+ */
523
+ return $shipment->isPakketautomaatShipment();
524
+ }
525
+
526
+ $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
527
+ $tempPostnlShipment->setShipment($shipment);
528
+
529
+ return $tempPostnlShipment->isPakketautomaatShipment();
530
+ }
531
+
532
  /**
533
  * Check if a given shipment is dutch
534
+ *
535
  * @param TIG_PostNL_Model_Core_Shipment | Mage_Sales_Model_Order_Shipment $shipment
536
+ *
537
  * @return boolean
538
+ *
539
  * @see TIG_PostNL_Model_Core_Shipment->isDutchSHipment();
540
  */
541
  public function isDutchShipment($shipment)
542
  {
543
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
544
  if ($shipment instanceof $postnlShipmentClass) {
545
+ /**
546
+ * @var TIG_PostNL_Model_Core_Shipment $shipment
547
+ */
548
  return $shipment->isDutchShipment();
549
  }
550
+
551
  $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
552
  $tempPostnlShipment->setShipment($shipment);
553
+
554
  return $tempPostnlShipment->isDutchShipment();
555
  }
556
+
557
  /**
558
  * Check if a given shipment has an EU destination
559
+ *
560
  * @param TIG_PostNL_Model_Core_Shipment | Mage_Sales_Model_Order_Shipment $shipment
561
+ *
562
  * @return boolean
563
+ *
564
+ * @see TIG_PostNL_Model_Core_Shipment->isEuShipment();
565
  */
566
  public function isEuShipment($shipment)
567
  {
568
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
569
  if ($shipment instanceof $postnlShipmentClass) {
570
+ /**
571
+ * @var TIG_PostNL_Model_Core_Shipment $shipment
572
+ */
573
  return $shipment->isEuShipment();
574
  }
575
+
576
  $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
577
  $tempPostnlShipment->setShipment($shipment);
578
+
579
  return $tempPostnlShipment->isEuShipment();
580
  }
581
+
582
  /**
583
  * Check if a given shipment has a global destination
584
+ *
585
+ * @param TIG_PostNL_Model_Core_Shipment|Mage_Sales_Model_Order_Shipment $shipment
586
+ *
587
  * @return boolean
588
+ *
589
+ * @see TIG_PostNL_Model_Core_Shipment->isGlobalShipment();
590
  */
591
  public function isGlobalShipment($shipment)
592
  {
593
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
594
  if ($shipment instanceof $postnlShipmentClass) {
595
+ /**
596
+ * @var TIG_PostNL_Model_Core_Shipment $shipment
597
+ */
598
  return $shipment->isGlobalShipment();
599
  }
600
+
601
  $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
602
  $tempPostnlShipment->setShipment($shipment);
603
+
604
  return $tempPostnlShipment->isGlobalShipment();
605
  }
606
+
607
  /**
608
  * Gets the default product option for a shipment
609
+ *
610
  * @param Mage_Sales_Model_Order_Shipment
611
+ *
612
  * @return string
613
  */
614
  public function getDefaultProductOptionForShipment($shipment)
615
  {
616
  $postnlShipment = Mage::getModel('postnl_core/shipment');
617
  $postnlShipment->setShipment($shipment);
618
+
619
  $productOption = $postnlShipment->getDefaultProductCode();
620
+
621
  return $productOption;
622
  }
623
+
624
  /**
625
  * Get an array of all default product options. This is a simple method to quickly get a list of default options based on
626
  * the current storeview.
627
+ *
628
  * This does not take into account the possible use of an alternative default for dutch shipments. For that you need to use
629
  * TIG_PostNL_Model_Core_Shipment::getDefaultProductCode() which is more precise.
630
+ *
631
  * @return array
632
  */
633
  public function getDefaultProductOptions()
634
  {
635
  $storeId = Mage::app()->getStore()->getId();
636
+
637
+ $defaultDutchOption = Mage::getStoreConfig(self::XML_PATH_DEFAULT_STANDARD_PRODUCT_OPTION, $storeId);
638
+ $defaultEuOption = Mage::getStoreConfig(self::XML_PATH_DEFAULT_EU_PRODUCT_OPTION, $storeId);
639
+ $defaultGlobalOption = Mage::getStoreConfig(self::XML_PATH_DEFAULT_GLOBAL_PRODUCT_OPTION, $storeId);
640
+ $defaultPakketautomaatOption = Mage::getStoreConfig(
641
+ self::XML_PATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION,
642
+ $storeId
643
+ );
644
+
645
  $defaultOptions = array(
646
+ 'dutch' => $defaultDutchOption,
647
+ 'eu' => $defaultEuOption,
648
+ 'global' => $defaultGlobalOption,
649
+ 'pakketautomaat' => $defaultPakketautomaatOption,
650
  );
651
+
652
  return $defaultOptions;
653
  }
654
+
655
  /**
656
  * Gets the number of parcels in this shipment based on it's weight
657
+ *
658
  * @param Mage_Sales_Model_Order_Shipment $shipment
659
+ *
660
  * @return int
661
  */
662
  public function getParcelCount($shipment)
663
  {
664
  $postnlShipment = Mage::getModel('postnl_core/shipment');
665
  $postnlShipment->setShipment($shipment);
666
+
667
  /**
668
  * Only NL shipments support multi-colli shipments
669
  */
670
  if (!$postnlShipment->isDutchShipment()) {
671
  return 1;
672
  }
673
+
674
  /**
675
  * get this shipment's total weight
676
  */
677
  $weight = $postnlShipment->getTotalWeight(true);
678
+
679
  /**
680
  * get the weight per parcel
681
  */
682
  $weightPerParcel = Mage::getStoreConfig(self::XML_PATH_WEIGHT_PER_PARCEL, $shipment->getStoreId());
683
  $weightPerParcel = $this->standardizeWeight($weightPerParcel, $shipment->getStoreId());
684
+
685
  /**
686
  * calculate the number of parcels needed to ship the total weight of this shipment
687
  */
688
  $parcelCount = ceil($weight / $weightPerParcel);
689
+
690
  return $parcelCount;
691
  }
692
+
693
  /**
694
  * Checks if a given postnl shipment exists using Zend_Validate_Db_RecordExists.
695
+ *
696
  * @param string $shipmentId
697
+ *
698
  * @return boolean
699
+ *
700
  * @see Zend_Validate_Db_RecordExists
701
+ *
702
  * @link http://framework.zend.com/manual/1.12/en/zend.validate.set.html#zend.validate.Db
703
  */
704
  public function postnlShipmentExists($shipmentId)
705
  {
706
  $coreResource = Mage::getSingleton('core/resource');
707
  $readAdapter = $coreResource->getConnection('core_read');
708
+
709
+ $validator = new Zend_Validate_Db_RecordExists(
710
  array(
711
  'table' => $coreResource->getTableName('postnl_core/shipment'),
712
  'field' => 'shipment_id',
713
  'adapter' => $readAdapter,
714
  )
715
  );
716
+
717
  $postnlShipmentExists = $validator->isValid($shipmentId);
718
+
719
  if ($postnlShipmentExists) {
720
  return true;
721
  }
722
+
723
  return false;
724
  }
725
+
726
  /**
727
  * Checks if a given barcode exists using Zend_Validate_Db_RecordExists.
728
+ *
729
  * @param string $barcode
730
+ *
731
  * @return boolean
732
+ *
733
  * @see Zend_Validate_Db_RecordExists
734
+ *
735
  * @link http://framework.zend.com/manual/1.12/en/zend.validate.set.html#zend.validate.Db
736
  */
737
  public function barcodeExists($barcode)
738
  {
739
  $coreResource = Mage::getSingleton('core/resource');
740
  $readAdapter = $coreResource->getConnection('core_read');
741
+
742
  /**
743
  * Check if the barcode exists as a main barcode
744
  */
745
+ $validator = new Zend_Validate_Db_RecordExists(
746
  array(
747
  'table' => $coreResource->getTableName('postnl_core/shipment'),
748
  'field' => 'main_barcode',
749
  'adapter' => $readAdapter,
750
  )
751
  );
752
+
753
  $barcodeExists = $validator->isValid($barcode);
754
+
755
  if ($barcodeExists) {
756
  return true;
757
  }
758
+
759
  /**
760
  * Check if the barcode exists as a secondary barcode
761
  */
762
+ $validator = new Zend_Validate_Db_RecordExists(
763
  array(
764
  'table' => $coreResource->getTableName('postnl_core/shipment_barcode'),
765
  'field' => 'barcode',
766
  'adapter' => $readAdapter,
767
  )
768
  );
769
+
770
  $barcodeExists = $validator->isValid($barcode);
771
+
772
  if ($barcodeExists) {
773
  return true;
774
  }
775
+
776
  return false;
777
  }
778
+
779
  /**
780
  * Convert a given weight to kilogram or gram
781
+ *
782
  * @param float $weight The weight to be converted
783
  * @param int | null $storeId Store Id used to determine the weight unit that was originally used
784
  * @param boolean $toGram Optional parameter to convert to gram instead of kilogram
785
+ *
786
  * @return float
787
  */
788
  public function standardizeWeight($weight, $storeId = null, $toGram = false)
790
  if (is_null($storeId)) {
791
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
792
  }
793
+
794
  $unitUsed = Mage::getStoreConfig(self::XML_PATH_WEIGHT_UNIT, $storeId);
795
+
 
796
  switch ($unitUsed) {
797
  case 'tonne':
798
  $returnWeight = $weight * 1000;
833
  case 'pound':
834
  $returnWeight = $weight * 0.45359237;
835
  break;
 
 
 
836
  case 'ounce':
837
  $returnWeight = $weight * 0.028349523125;
838
  break;
863
  if ($toGram === true) {
864
  $returnWeight *= 1000;
865
  }
866
+
867
  return $returnWeight;
868
  }
869
+
870
+ /**
871
+ * Retrieves streetname, housenumber and housenumber extension from the shipping address.
872
+ * The shipping address may be in multiple streetlines configuration or single line
873
+ * configuration. In the case of multi-line, each part of the street data will be in a seperate
874
+ * field. In the single line configuration, each part will be in the same field and will have
875
+ * to be split using PREG.
876
+ *
877
+ * PREG cannot be relied on as it is impossible to create a regex that can filter all
878
+ * possible street syntaxes. Therefore we strongly recommend to use multiple street lines. This
879
+ * can be enabled in Magento community in system > config > customer configuration. Or if you
880
+ * use Enterprise, in customers > attributes > manage customer address attributes.
881
+ *
882
+ * @param int $storeId
883
+ * @param Mage_Customer_Model_Address_Abstract $address
884
+ * @param boolean $allowFullStreet
885
+ *
886
+ * @return array
887
+ */
888
+ public function getStreetData($storeId, $address, $allowFullStreet = true)
889
+ {
890
+ if (!$storeId) {
891
+ $storeId = Mage::app()->getStore()->getId();
892
+ }
893
+
894
+ $splitStreet = Mage::helper('postnl/addressValidation')->useSplitStreet($storeId);
895
+
896
+ /**
897
+ * Website uses multi-line address mode
898
+ */
899
+ if ($splitStreet) {
900
+ $streetData = $this->_getMultiLineStreetData($storeId, $address);
901
+
902
+ /**
903
+ * If $streetData is false it means a required field was missing. In this
904
+ * case the alternative methods are used to obtain the address data.
905
+ */
906
+ if ($streetData !== false) {
907
+ return $streetData;
908
+ }
909
+ }
910
+
911
+ /**
912
+ * Website uses single-line address mode
913
+ */
914
+ $allowedFullStreetCountries = $this->getAllowedFullStreetCountries();
915
+ $fullStreet = $address->getStreetFull();
916
+
917
+ /**
918
+ * Select countries don't have to split their street values into seperate part
919
+ */
920
+ if ($allowFullStreet === true
921
+ && in_array($address->getCountry(), $allowedFullStreetCountries)
922
+ ) {
923
+ $streetData = array(
924
+ 'streetname' => '',
925
+ 'housenumber' => '',
926
+ 'housenumberExtension' => '',
927
+ 'fullStreet' => $fullStreet,
928
+ );
929
+ return $streetData;
930
+ }
931
+
932
+ /**
933
+ * All other countries must split them using PREG
934
+ */
935
+ $streetData = $this->_getSplitStreetData($fullStreet);
936
+
937
+ return $streetData;
938
+ }
939
+
940
+ /**
941
+ * Retrieves streetname, housenumber and housenumber extension from the shipping address in the multiple streetlines
942
+ * configuration.
943
+ *
944
+ * @param int $storeId
945
+ * @param Mage_Sales_Model_Order_Address $address
946
+ *
947
+ * @return array
948
+ */
949
+ protected function _getMultiLineStreetData($storeId, $address)
950
+ {
951
+ $addressHelper = Mage::helper('postnl/addressValidation');
952
+
953
+ $streetnameField = $addressHelper->getStreetnameField($storeId);;
954
+ $housenumberField = $addressHelper->getHousenumberField($storeId);;
955
+
956
+ $streetname = $address->getStreet($streetnameField);
957
+ $housenumber = $address->getStreet($housenumberField);
958
+ $housenumber = trim($housenumber);
959
+
960
+ /**
961
+ * If street or housenr fields are empty, use alternative options to obtain the address data
962
+ */
963
+ if (empty($streetname) || empty($housenumber)) {
964
+ return false;
965
+ }
966
+
967
+ /**
968
+ * Split the housenumber into a number and an extension
969
+ */
970
+ $splitHouseNumber = $addressHelper->useSplitHousenumber();
971
+ if ($splitHouseNumber) {
972
+ $housenumberExtensionField = $addressHelper->getHousenumberExtensionField();
973
+ $housenumberExtension = $address->getStreet($housenumberExtensionField);
974
+
975
+ /**
976
+ * Make sure the housenumber is actually split.
977
+ */
978
+ if (!$housenumberExtension && !is_numeric($housenumber)) {
979
+ $housenumberParts = $this->_splitHousenumber($housenumber);
980
+ $housenumber = $housenumberParts['number'];
981
+ $housenumberExtension = $housenumberParts['extension'];
982
+ }
983
+ } else {
984
+ $housenumberParts = $this->_splitHousenumber($housenumber);
985
+ $housenumber = $housenumberParts['number'];
986
+ $housenumberExtension = $housenumberParts['extension'];
987
+ }
988
+
989
+ if (empty($housenumber)) {
990
+ return false;
991
+ }
992
+
993
+ $streetData = array(
994
+ 'streetname' => $streetname,
995
+ 'housenumber' => $housenumber,
996
+ 'housenumberExtension' => $housenumberExtension,
997
+ 'fullStreet' => '',
998
+ );
999
+
1000
+ return $streetData;
1001
+ }
1002
+
1003
+ /**
1004
+ * Splits street data into seperate parts for streetname, housenumber and extension.
1005
+ *
1006
+ * @param string $fullStreet The full streetname including all parts
1007
+ *
1008
+ * @return array
1009
+ *
1010
+ * @throws TIG_PostNL_Exception
1011
+ */
1012
+ protected function _getSplitStreetData($fullStreet)
1013
+ {
1014
+ $result = preg_match(self::SPLIT_STREET_REGEX, $fullStreet, $matches);
1015
+ if (!$result || !is_array($matches)) {
1016
+ throw new TIG_PostNL_Exception(
1017
+ Mage::helper('postnl')->__('Invalid full street supplied: %s', $fullStreet),
1018
+ 'POSTNL-0060'
1019
+ );
1020
+ }
1021
+
1022
+ $streetname = '';
1023
+ $housenumber = '';
1024
+ if (isset($matches[1])) {
1025
+ $streetname = $matches[1];
1026
+ }
1027
+
1028
+ if (isset($matches[2])) {
1029
+ $housenumber = $matches[2];
1030
+ }
1031
+
1032
+ $housenumberParts = $this->_splitHousenumber($housenumber);
1033
+ $housenumber = $housenumberParts['number'];
1034
+ $housenumberExtension = $housenumberParts['extension'];
1035
+
1036
+ $streetData = array(
1037
+ 'streetname' => $streetname,
1038
+ 'housenumber' => $housenumber,
1039
+ 'housenumberExtension' => $housenumberExtension,
1040
+ 'fullStreet' => '',
1041
+ );
1042
+
1043
+ return $streetData;
1044
+ }
1045
+
1046
+ /**
1047
+ * Splits a supplier housenumber into a number and an extension.
1048
+ *
1049
+ * @param string $housenumber
1050
+ *
1051
+ * @return array
1052
+ *
1053
+ * @throws TIG_PostNL_Exception
1054
+ */
1055
+ protected function _splitHousenumber($housenumber)
1056
+ {
1057
+ $housenumber = trim($housenumber);
1058
+ $result = preg_match(self::SPLIT_HOUSENUMBER_REGEX, $housenumber, $matches);
1059
+ if (!$result || !is_array($matches)) {
1060
+ throw new TIG_PostNL_Exception(
1061
+ Mage::helper('postnl')->__('Invalid housnumber supplied: %s', $housenumber),
1062
+ 'POSTNL-0059'
1063
+ );
1064
+ }
1065
+
1066
+ $extension = '';
1067
+ $number = '';
1068
+ if (isset($matches[1])) {
1069
+ $number = $matches[1];
1070
+ }
1071
+
1072
+ if (isset($matches[2])) {
1073
+ $extension = trim($matches[2]);
1074
+ }
1075
+
1076
+ $housenumberParts = array(
1077
+ 'number' => $number,
1078
+ 'extension' => $extension,
1079
+ );
1080
+
1081
+ return $housenumberParts;
1082
+ }
1083
+
1084
  /**
1085
  * Logs a CIF request and response for debug purposes.
1086
+ *
1087
  * N.B.: if file logging is enabled, the log will be forced
1088
+ *
1089
+ * @param Zend_Soap_Client $client
1090
+ *
1091
  * @return TIG_PostNL_Helper_Cif
1092
+ *
1093
  * @see Mage::log()
1094
+ *
 
 
1095
  */
1096
  public function logCifCall($client)
1097
  {
1098
+ if (!$this->isLoggingEnabled()) {
1099
  return $this;
1100
  }
1101
+
1102
  $requestXml = $this->formatXml($client->getLastRequest());
1103
  $responseXML = $this->formatXml($client->getLastResponse());
1104
+
1105
  $logMessage = "Request sent:\n"
1106
  . $requestXml
1107
  . "\nResponse received:\n"
1108
  . $responseXML;
1109
+
1110
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::CIF_DEBUG_LOG_FILE;
1111
  $this->log($logMessage, Zend_Log::DEBUG, $file);
1112
+
1113
  return $this;
1114
  }
1115
+
1116
  /**
1117
+ * Logs a CIF exception in the database and/or a log file.
1118
+ *
 
 
1119
  * @param Mage_Core_Exception | TIG_PostNL_Model_Core_Cif_Exception $exception
1120
+ *
1121
  * @return TIG_PostNL_Helper_Cif
1122
+ *
1123
  * @see Mage::logException()
 
 
1124
  */
1125
  public function logCifException($exception)
1126
  {
1127
  if (!$this->isExceptionLoggingEnabled()) {
1128
  return $this;
1129
  }
1130
+
1131
  if ($exception instanceof TIG_PostNL_Model_Core_Cif_Exception) {
1132
  $requestXml = $this->formatXml($exception->getRequestXml());
1133
  $responseXML = $this->formatXml($exception->getResponseXml());
1134
+
1135
  $logMessage = '';
1136
+
1137
  $errorNumbers = $exception->getErrorNumbers();
1138
  if (!empty($errorNumbers)) {
1139
  $errorNumbers = implode(', ', $errorNumbers);
1140
  $logMessage .= "Error numbers received: {$errorNumbers}\n";
1141
  }
1142
+
1143
  $logMessage .= "<<< REQUEST SENT >>>\n"
1144
  . $requestXml
1145
  . "\n<<< RESPONSE RECEIVED >>>\n"
1147
  } else {
1148
  $logMessage = "\n" . $exception->__toString();
1149
  }
1150
+
1151
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::CIF_EXCEPTION_LOG_FILE;
1152
  $this->log($logMessage, Zend_Log::ERR, $file, false, true);
1153
+
1154
  return $this;
1155
  }
1156
  }
app/code/community/TIG/PostNL/Helper/Data.php CHANGED
@@ -33,68 +33,68 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
40
  {
41
  /**
42
- * Log filename to log all non-specific PostNL exceptions
43
  */
44
  const POSTNL_EXCEPTION_LOG_FILE = 'TIG_PostNL_Exception.log';
45
 
46
  /**
47
- * Log filename to log all non-specific PostNL debug messages
48
  */
49
  const POSTNL_DEBUG_LOG_FILE = 'TIG_PostNL_Debug.log';
50
 
51
  /**
52
- * Directory inside var/log where PostNL log files will be logged
53
  */
54
  const POSTNL_LOG_DIRECTORY = 'TIG_PostNL';
55
 
56
  /**
57
- * Log filename to log all cron log messages
58
  */
59
  const POSTNL_CRON_DEBUG_LOG_FILE = 'TIG_PostNL_Cron_Debug.log';
60
 
61
  /**
62
- * XML path to postnl general active/inactive setting
63
  */
64
  const XML_PATH_EXTENSION_ACTIVE = 'postnl/general/active';
65
 
66
  /**
67
- * XML path to postnl carier active/inactive setting
68
  */
69
  const XML_PATH_CARRIER_ACTIVE = 'carriers/postnl/active';
70
 
71
  /**
72
- * XML path to test/live mode config option
73
  */
74
- const XML_PATH_TEST_MODE = 'postnl/cif_labels_and_confirming/mode';
75
 
76
  /**
77
- * XML path to the test mode allowed config option
78
  */
79
  const XML_PATH_TEST_MODE_ALLOWED = 'postnl/advanced/allow_test_mode';
80
 
81
  /**
82
- * XML path to debug mode config option
83
  */
84
  const XML_PATH_DEBUG_MODE = 'postnl/advanced/debug_mode';
85
 
86
  /**
87
- * XML path to 'is_activated' flag
88
  */
89
  const XML_PATH_IS_ACTIVATED = 'postnl/general/is_activated';
90
 
91
  /**
92
- * XML path to 'show_error_details_in_frontend' flag
93
  */
94
  const XML_PATH_SHOW_ERROR_DETAILS_IN_FRONTEND = 'postnl/advanced/show_error_details_in_frontend';
95
 
96
  /**
97
- * XML path to use_globalpack settings
98
  */
99
  const XML_PATH_USE_GLOBALPACK = 'postnl/cif/use_globalpack';
100
 
@@ -104,7 +104,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
104
  const XPATH_ALLOW_EPS_BE_ONLY_OPTION = 'postnl/cif_product_options/allow_eps_be_only_options';
105
 
106
  /**
107
- * Required configuration fields
108
  *
109
  * @var array
110
  */
@@ -122,7 +122,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
122
  );
123
 
124
  /**
125
- * Required configuration fields for live mode
126
  *
127
  * @var array
128
  */
@@ -132,7 +132,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
132
  );
133
 
134
  /**
135
- * Required configuration fields for test mode
136
  *
137
  * @var array
138
  */
@@ -142,7 +142,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
142
  );
143
 
144
  /**
145
- * Required configuration fields when using global shipments
146
  *
147
  * @var array
148
  */
@@ -156,7 +156,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
156
  );
157
 
158
  /**
159
- * Get required fields array
160
  *
161
  * @return array
162
  */
@@ -166,7 +166,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
166
  }
167
 
168
  /**
169
- * Get required fields for live mode array
170
  *
171
  * @return array
172
  */
@@ -176,7 +176,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
176
  }
177
 
178
  /**
179
- * Get required fields for test mode array
180
  *
181
  * @return array
182
  */
@@ -186,7 +186,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
186
  }
187
 
188
  /**
189
- * Get required fields for global shipments array
190
  *
191
  * @return array
192
  */
@@ -196,7 +196,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
196
  }
197
 
198
  /**
199
- * Get debug mode config setting
200
  *
201
  * @return int
202
  */
@@ -213,7 +213,57 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
213
  }
214
 
215
  /**
216
- * Checks to see if the module may ship to the Netherlands using PostNL standard shipments
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  *
218
  * @param boolean|int $storeId
219
  *
@@ -235,7 +285,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
235
  }
236
 
237
  /**
238
- * Checks to see if the module may ship using PakjeGemak
239
  *
240
  * @param boolean|int $storeId
241
  *
@@ -336,6 +386,9 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
336
  */
337
  public function saveConfigState($configState = array())
338
  {
 
 
 
339
  $adminUser = Mage::getSingleton('admin/session')->getUser();
340
  if (!$adminUser) {
341
  return false;
@@ -364,6 +417,87 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
364
  return true;
365
  }
366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  /**
368
  * Checks if GlobalPack may be used.
369
  *
@@ -403,7 +537,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
403
  /**
404
  * Checks if test mode is currently allowed
405
  *
406
- * @deprecated v1.1.4 Will now always return true.
 
407
  *
408
  * @return boolean
409
  */
@@ -415,8 +550,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
415
  /**
416
  * Alias for isEnabled()
417
  *
418
- * @param int | bool $storeId
419
- * @param boolean $checkGlobal
420
  * @param null|boolean $forceTestMode
421
  *
422
  * @return boolean
@@ -479,6 +614,15 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
479
  return false;
480
  }
481
 
 
 
 
 
 
 
 
 
 
482
  /**
483
  * Check if the module's required configuration options have been filled
484
  */
@@ -504,8 +648,13 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
504
  );
505
 
506
  $errorMessage = $this->__(
507
- 'The PostNL shipping method has not been enabled. You can enable the PostNL shipping method under %sSystem > Config > Shipping Methods%s.',
508
- '<a href="' . $shippingMethodSectionurl . '" target="_blank" title="' . $this->__('Shipping Methods') . '">',
 
 
 
 
 
509
  '</a>'
510
  );
511
 
@@ -540,6 +689,58 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
540
  return true;
541
  }
542
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  /**
544
  * Check if the modules has been confgured.
545
  * The required fields will only be checked to see if they're not empty. The values entered will not be validated
@@ -549,8 +750,6 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
549
  * @param null|boolean $forceTestMode
550
  *
551
  * @return boolean
552
- *
553
- * @todo properly implement global check
554
  */
555
  public function isConfigured($storeId = false, $checkGlobal = false, $forceTestMode = null)
556
  {
@@ -613,8 +812,10 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
613
  }
614
 
615
  /**
616
- * Check if each required field is filled. If not add the field's label to an array of missing fields so we can later
617
- * inform the merchant which fields exactly are missing.
 
 
618
  */
619
  $configFields = Mage::getSingleton('adminhtml/config');
620
  $sections = $configFields->getSections('postnl');
@@ -622,22 +823,29 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
622
  foreach ($requiredFields as $requiredField) {
623
  $value = Mage::getStoreConfig($requiredField, $storeId);
624
 
625
- if ($value === null || $value === '') {
626
- $fieldParts = explode('/', $requiredField);
627
- $field = $fieldParts[2];
628
- $group = $fieldParts[1];
629
 
630
- $label = (string) $section->groups->$group->fields->$field->label;
631
- $groupLabel = (string) $section->groups->$group->label;
632
- $groupName = $section->groups->$group->getName();
633
 
634
- $errors[] = array(
635
- 'code' => 'POSTNL-0034',
636
- 'message' => $this->__('%s > %s is required.', $this->__($groupLabel), $this->__($label)),
637
- );
638
 
639
- $this->saveConfigState(array('postnl_' . $groupName => 1));
640
- }
 
 
 
 
 
 
 
 
641
  }
642
 
643
  /**
@@ -689,17 +897,21 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
689
  * Based on Mage_Core_Model_Config::getModuleDir()
690
  *
691
  * @param string $dir The directory in question
692
- * @param string $module The module for which the directory is needed
693
  *
694
  * @return string
695
  *
696
- * @see Mage_Core_Model_Config::getModuleDir()
697
  */
698
  public function getModuleDir($dir, $moduleName = 'TIG_PostNL')
699
  {
700
  $config = Mage::app()->getConfig();
701
 
702
- $codePool = (string)$config->getModuleConfig($moduleName)->codePool;
 
 
 
 
703
  $path = $config->getOptions()->getCodeDir()
704
  . DS
705
  . $codePool
@@ -735,13 +947,13 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
735
  }
736
 
737
  /**
738
- * Logs a debug message. Based on Mage::log
739
  *
740
- * @param string $message
741
- * @param int | null $level
742
- * @param string | null $file
743
- * @param boolean $forced
744
- * @param boolean $isError
745
  *
746
  * @return TIG_PostNL_Helper_Data
747
  *
@@ -774,7 +986,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
774
  * Logs a cron debug messageto a seperate file in order to differentiate it from other debug messages
775
  *
776
  * @param string $message
777
- * @param int | int $level
778
  *
779
  * @return TIG_PostNL_Helper_Data
780
  *
@@ -818,7 +1030,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
818
  }
819
 
820
  /**
821
- * Checks if the current edition of Magento is enterprise. Uses Mage::getEdition if available or version_compare if it is not
 
822
  *
823
  * @return boolean
824
  *
@@ -827,7 +1040,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
827
  public function isEnterprise()
828
  {
829
  /**
830
- * Use Mage::getEdition, which is available since CE 1.7 and EE 1.12
831
  */
832
  if (method_exists('Mage', 'getEdition')) {
833
  $edition = Mage::getEdition();
@@ -840,7 +1053,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
840
  }
841
 
842
  /**
843
- * If the edition is not community or enterprise, it is not supported
844
  */
845
  throw new TIG_PostNL_Exception(
846
  $this->__('Invalid Magento edition detected: %s', $edition),
@@ -849,10 +1062,17 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
849
  }
850
 
851
  /**
852
- * Do a version check instead
 
 
 
 
 
 
 
853
  */
854
  $version = Mage::getVersion();
855
- if (version_compare($version, '1.9.0.0', '>=')) { //1.9.0.0 was the first Magento Enterprise version
856
  return true;
857
  }
858
 
@@ -871,7 +1091,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
871
  }
872
 
873
  /**
874
- * Fallback check in case the previous check returns a false positive
875
  */
876
  if (Mage::getDesign()->getArea() == 'adminhtml') {
877
  return true;
@@ -898,8 +1118,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
898
  }
899
 
900
  /**
901
- * Gets the knowledge base URL for a specified error code. First we check to see if we have an entry in config.xml for this
902
- * error code and if so, if it has an associated URL.
903
  *
904
  * @param string $errorCode The error code (for example: POSTNL-0001)
905
  *
@@ -916,8 +1136,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
916
  }
917
 
918
  /**
919
- * Adds an error message to the specified session based on an exception. The exception should contain a valid error code
920
- * in order to properly process the error. Exceptions without a (valid) error code will behave like a regular
921
  * $session->addError() call.
922
  *
923
  * @param string|Mage_Core_Model_Session_Abstract $session The session to which the messages will be added.
@@ -977,8 +1197,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
977
 
978
  /**
979
  * Add a message to the specified session. Message can be an error, a success message, an info message or a warning.
980
- * If a valid error code is supplied, the message will be prepended with the error code and a link to a knowledgebase article
981
- * will be appended.
982
  *
983
  * If no $code is specified, $messageType and $message will be required
984
  *
@@ -996,9 +1216,9 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
996
  */
997
  public function addSessionMessage($session, $code = null, $messageType = null, $message = null)
998
  {
999
- /************************************************************************************************************************
1000
  * Check that the required arguments are available and valid
1001
- ***********************************************************************************************************************/
1002
 
1003
  /**
1004
  * If $code is null or 0, $messageType and $message are required
@@ -1015,8 +1235,10 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1015
  /**
1016
  * If the session is a string, treat it as a class name and instantiate it
1017
  */
1018
- if (is_string($session)) {
1019
  $session = Mage::getSingleton($session);
 
 
1020
  }
1021
 
1022
  /**
@@ -1032,9 +1254,9 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1032
  );
1033
  }
1034
 
1035
- /************************************************************************************************************************
1036
  * Get the actual error from config.xml if it's available
1037
- ***********************************************************************************************************************/
1038
 
1039
  $error = false;
1040
  $link = false;
@@ -1049,10 +1271,10 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1049
  }
1050
  }
1051
 
1052
- /************************************************************************************************************************
1053
- * Check that the required 'message' and 'messageType' components are available. If they are not yet available, we'll try
1054
- * to read them from the error itself.
1055
- ***********************************************************************************************************************/
1056
 
1057
  /**
1058
  * If the specified error was found and no message was supplied, get the error's default message
@@ -1089,10 +1311,10 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1089
  );
1090
  }
1091
 
1092
- /************************************************************************************************************************
1093
- * Build the actual message we're going to add. The message will consist of the error code, followed by the actual
1094
- * message and finally a link to the knowledge base. Only the message part is required.
1095
- ***********************************************************************************************************************/
1096
 
1097
  /**
1098
  * Flag that determines whether the error code and knowledgebase link will be included in the error message
@@ -1114,22 +1336,22 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1114
  /**
1115
  * Add the actual message. This is the only required part. The code and link are optional
1116
  */
1117
- $errorMessage .= $this->__($message);
1118
 
1119
  /**
1120
  * Add the link to the knowledgebase if we have one
1121
  */
1122
  if ($canShowErrorDetails && $link) {
1123
  $errorMessage .= ' <a href="'
1124
- . $link
1125
  . '" target="_blank" class="postnl-message">'
1126
  . $this->__('Click here for more information from the TiG knowledgebase.')
1127
  . '</a>';
1128
  }
1129
 
1130
- /************************************************************************************************************************
1131
  * Finally, let's add the error to the session
1132
- ***********************************************************************************************************************/
1133
 
1134
  /**
1135
  * The method we'll use to add the message to the session has to be built first
@@ -1155,7 +1377,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1155
  }
1156
 
1157
  /**
1158
- * Checks to see if we can show error details (error code and knowledgebase link) in the frontend when an error occurs.
 
1159
  *
1160
  * @return boolean
1161
  */
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
40
  {
41
  /**
42
+ * Log filename to log all non-specific PostNL exceptions.
43
  */
44
  const POSTNL_EXCEPTION_LOG_FILE = 'TIG_PostNL_Exception.log';
45
 
46
  /**
47
+ * Log filename to log all non-specific PostNL debug messages.
48
  */
49
  const POSTNL_DEBUG_LOG_FILE = 'TIG_PostNL_Debug.log';
50
 
51
  /**
52
+ * Directory inside var/log where PostNL log files will be logged.
53
  */
54
  const POSTNL_LOG_DIRECTORY = 'TIG_PostNL';
55
 
56
  /**
57
+ * Log filename to log all cron log messages.
58
  */
59
  const POSTNL_CRON_DEBUG_LOG_FILE = 'TIG_PostNL_Cron_Debug.log';
60
 
61
  /**
62
+ * XML path to postnl general active/inactive setting.
63
  */
64
  const XML_PATH_EXTENSION_ACTIVE = 'postnl/general/active';
65
 
66
  /**
67
+ * XML path to postnl carier active/inactive setting.
68
  */
69
  const XML_PATH_CARRIER_ACTIVE = 'carriers/postnl/active';
70
 
71
  /**
72
+ * XML path to test/live mode config option.
73
  */
74
+ const XML_PATH_TEST_MODE = 'postnl/cif/mode';
75
 
76
  /**
77
+ * XML path to the test mode allowed config option.
78
  */
79
  const XML_PATH_TEST_MODE_ALLOWED = 'postnl/advanced/allow_test_mode';
80
 
81
  /**
82
+ * XML path to debug mode config option.
83
  */
84
  const XML_PATH_DEBUG_MODE = 'postnl/advanced/debug_mode';
85
 
86
  /**
87
+ * XML path to 'is_activated' flag.
88
  */
89
  const XML_PATH_IS_ACTIVATED = 'postnl/general/is_activated';
90
 
91
  /**
92
+ * XML path to 'show_error_details_in_frontend' flag.
93
  */
94
  const XML_PATH_SHOW_ERROR_DETAILS_IN_FRONTEND = 'postnl/advanced/show_error_details_in_frontend';
95
 
96
  /**
97
+ * XML path to use_globalpack settings.
98
  */
99
  const XML_PATH_USE_GLOBALPACK = 'postnl/cif/use_globalpack';
100
 
104
  const XPATH_ALLOW_EPS_BE_ONLY_OPTION = 'postnl/cif_product_options/allow_eps_be_only_options';
105
 
106
  /**
107
+ * Required configuration fields.
108
  *
109
  * @var array
110
  */
122
  );
123
 
124
  /**
125
+ * Required configuration fields for live mode.
126
  *
127
  * @var array
128
  */
132
  );
133
 
134
  /**
135
+ * Required configuration fields for test mode.
136
  *
137
  * @var array
138
  */
142
  );
143
 
144
  /**
145
+ * Required configuration fields when using global shipments.
146
  *
147
  * @var array
148
  */
156
  );
157
 
158
  /**
159
+ * Get required fields array.
160
  *
161
  * @return array
162
  */
166
  }
167
 
168
  /**
169
+ * Get required fields for live mode array.
170
  *
171
  * @return array
172
  */
176
  }
177
 
178
  /**
179
+ * Get required fields for test mode array.
180
  *
181
  * @return array
182
  */
186
  }
187
 
188
  /**
189
+ * Get required fields for global shipments array.
190
  *
191
  * @return array
192
  */
196
  }
197
 
198
  /**
199
+ * Get debug mode config setting.
200
  *
201
  * @return int
202
  */
213
  }
214
 
215
  /**
216
+ * Gets a shipment's PakjeGemak address if available.
217
+ *
218
+ * @param Mage_Sales_Model_Order_Shipment $shipment
219
+ *
220
+ * @return bool|Mage_Sales_Model_Order_Address
221
+ */
222
+ public function getPakjeGemakAddressForShipment(Mage_Sales_Model_Order_Shipment $shipment)
223
+ {
224
+ $order = $shipment->getOrder();
225
+
226
+ return $this->getPakjeGemakAddressForOrder($order);
227
+ }
228
+
229
+ /**
230
+ * Gets an order's PakjeGemak address if available.
231
+ *
232
+ * @param Mage_Sales_Model_Order $order
233
+ *
234
+ * @return bool|Mage_Sales_Model_Order_Address
235
+ */
236
+ public function getPakjeGemakAddressForOrder(Mage_Sales_Model_Order $order)
237
+ {
238
+ /**
239
+ * Check if this order was placed using PostNL.
240
+ */
241
+ $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
242
+ $shippingMethod = $order->getShippingMethod();
243
+
244
+ /**
245
+ * If this shipment's order was not placed with PostNL, we need to ignore any PakjeGemak addresses that may have
246
+ * been saved.
247
+ */
248
+ if (!in_array($shippingMethod, $postnlShippingMethods)) {
249
+ return false;
250
+ }
251
+
252
+ /**
253
+ * @var Mage_Sales_Model_Order_Address $address
254
+ */
255
+ $addressCollection = $order->getAddressesCollection();
256
+ foreach ($addressCollection as $address) {
257
+ if ($address->getAddressType() == 'pakje_gemak') {
258
+ return $address;
259
+ }
260
+ }
261
+
262
+ return false;
263
+ }
264
+
265
+ /**
266
+ * Checks to see if the module may ship to the Netherlands using PostNL standard shipments.
267
  *
268
  * @param boolean|int $storeId
269
  *
285
  }
286
 
287
  /**
288
+ * Checks to see if the module may ship using PakjeGemak.
289
  *
290
  * @param boolean|int $storeId
291
  *
386
  */
387
  public function saveConfigState($configState = array())
388
  {
389
+ /**
390
+ * @var Mage_Admin_Model_User $adminUser
391
+ */
392
  $adminUser = Mage::getSingleton('admin/session')->getUser();
393
  if (!$adminUser) {
394
  return false;
417
  return true;
418
  }
419
 
420
+ /**
421
+ * Checks if the current admin user is allowed for the specified actions.
422
+ *
423
+ * @param array|string $actions
424
+ * @param boolean $throwException
425
+ *
426
+ * @throws TIG_PostNL_Exception
427
+ *
428
+ * @return bool
429
+ */
430
+ public function checkIsPostnlActionAllowed($actions = array(), $throwException = false)
431
+ {
432
+ if (!is_array($actions)) {
433
+ $actions = array($actions);
434
+ }
435
+
436
+ foreach ($actions as $action) {
437
+ if ($this->_isActionAllowed($action)) {
438
+ continue;
439
+ }
440
+
441
+ if ($throwException) {
442
+ throw new TIG_PostNL_Exception(
443
+ $this->__('The current user is not allowed to perform this action.'),
444
+ 'POSTNL-0155'
445
+ );
446
+ } else {
447
+ return false;
448
+ }
449
+ }
450
+
451
+ return true;
452
+ }
453
+
454
+ /**
455
+ * Checks if a specified action is allowed for the current admin user.
456
+ *
457
+ * @param string $action
458
+ *
459
+ * @return bool
460
+ */
461
+ protected function _isActionAllowed($action)
462
+ {
463
+ switch ($action) {
464
+ case 'create_shipment':
465
+ $aclPath = 'sales/order/actions/ship';
466
+ break;
467
+ case 'confirm':
468
+ $aclPath = 'postnl/shipment/actions/confirm';
469
+ break;
470
+ case 'print_label':
471
+ $aclPath = 'postnl/shipment/actions/print_label';
472
+ break;
473
+ case 'view_complete_status':
474
+ $aclPath = 'postnl/shipment/complete_status';
475
+ break;
476
+ case 'reset_confirmation':
477
+ $aclPath = 'postnl/shipment/actions/reset_confirmation';
478
+ break;
479
+ case 'delete_labels':
480
+ $aclPath = 'postnl/shipment/actions/delete_labels';
481
+ break;
482
+ case 'create_parcelware_export':
483
+ $aclPath = 'postnl/shipment/actions/create_parcelware_export';
484
+ break;
485
+ case 'send_track_and_trace':
486
+ $aclPath = 'postnl/shipment/actions/send_track_and_trace';
487
+ break;
488
+ default:
489
+ $aclPath = false;
490
+ break;
491
+ }
492
+
493
+ if (!$aclPath) {
494
+ return false;
495
+ }
496
+
497
+ $isAllowed = Mage::getSingleton('admin/session')->isAllowed($aclPath);
498
+ return $isAllowed;
499
+ }
500
+
501
  /**
502
  * Checks if GlobalPack may be used.
503
  *
537
  /**
538
  * Checks if test mode is currently allowed
539
  *
540
+ * @deprecated 1.2.0 Test mode is now always allowed, regardless of configuration. This method should therefore not
541
+ * be used anymore and may be removed in the future.
542
  *
543
  * @return boolean
544
  */
550
  /**
551
  * Alias for isEnabled()
552
  *
553
+ * @param int|boolean $storeId
554
+ * @param boolean $checkGlobal
555
  * @param null|boolean $forceTestMode
556
  *
557
  * @return boolean
614
  return false;
615
  }
616
 
617
+ /**
618
+ * Make sure that the required PHP extensions are loaded.
619
+ */
620
+ $phpExtensionsLoaded = $this->areRequiredPHPExtensionsLoaded($registryKey);
621
+ if ($phpExtensionsLoaded === false) {
622
+ Mage::register($registryKey, false);
623
+ return false;
624
+ }
625
+
626
  /**
627
  * Check if the module's required configuration options have been filled
628
  */
648
  );
649
 
650
  $errorMessage = $this->__(
651
+ 'The PostNL shipping method has not been enabled. You can enable the PostNL shipping method under '
652
+ . '%sSystem > Config > Shipping Methods%s.',
653
+ '<a href="'
654
+ . $shippingMethodSectionurl
655
+ . '" target="_blank" title="'
656
+ . $this->__('Shipping Methods')
657
+ . '">',
658
  '</a>'
659
  );
660
 
689
  return true;
690
  }
691
 
692
+ /**
693
+ * Check if the required SOAP, OpenSSL and MCrypt PHP extensions are loaded.
694
+ *
695
+ * @param string $registryKey
696
+ *
697
+ * @return bool
698
+ */
699
+ public function areRequiredPHPExtensionsLoaded($registryKey)
700
+ {
701
+ $errors = array();
702
+ if (!extension_loaded('soap')) {
703
+ $errors[] = array(
704
+ 'code' => 'POSTNL-0134',
705
+ 'message' => $this->__(
706
+ 'The SOAP extension is not installed. PostNL requires the SOAP extension to communicate with '
707
+ . 'PostNL.'
708
+ ),
709
+ );
710
+ }
711
+
712
+ if (!extension_loaded('openssl')) {
713
+ $errors[] = array(
714
+ 'code' => 'POSTNL-0135',
715
+ 'message' => $this->__(
716
+ 'The OpenSSL extension is not installed. The PostNL extension requires the OpenSSL extension to '
717
+ . 'secure the communications with the PostNL servers.'
718
+ ),
719
+ );
720
+ }
721
+
722
+ if (!extension_loaded('mcrypt')) {
723
+ $errors[] = array(
724
+ 'code' => 'POSTNL-0137',
725
+ 'message' => $this->__(
726
+ 'The MCrypt extension is not installed. The PostNL extension requires the MCrypt extension to '
727
+ . 'secure the communications with the PostNL servers.'
728
+ ),
729
+ );
730
+ }
731
+
732
+ /**
733
+ * Register any errors that may have ocurred and return false.
734
+ */
735
+ if (!empty($errors)) {
736
+ Mage::register($registryKey . '_errors', $errors);
737
+
738
+ return false;
739
+ }
740
+
741
+ return true;
742
+ }
743
+
744
  /**
745
  * Check if the modules has been confgured.
746
  * The required fields will only be checked to see if they're not empty. The values entered will not be validated
750
  * @param null|boolean $forceTestMode
751
  *
752
  * @return boolean
 
 
753
  */
754
  public function isConfigured($storeId = false, $checkGlobal = false, $forceTestMode = null)
755
  {
812
  }
813
 
814
  /**
815
+ * Check if each required field is filled. If not add the field's label to an array of missing fields so we can
816
+ * later inform the merchant which fields exactly are missing.
817
+ *
818
+ * @var Varien_Simplexml_Element $section
819
  */
820
  $configFields = Mage::getSingleton('adminhtml/config');
821
  $sections = $configFields->getSections('postnl');
823
  foreach ($requiredFields as $requiredField) {
824
  $value = Mage::getStoreConfig($requiredField, $storeId);
825
 
826
+ if ($value !== null && $value !== '') {
827
+ continue;
828
+ }
 
829
 
830
+ $fieldParts = explode('/', $requiredField);
831
+ $field = $fieldParts[2];
832
+ $group = $fieldParts[1];
833
 
834
+ /**
835
+ * @var Varien_Simplexml_Element $sectionGroup
836
+ */
837
+ $sectionGroup = $section->groups->$group;
838
 
839
+ $label = (string) $sectionGroup->fields->$field->label;
840
+ $groupLabel = (string) $sectionGroup->label;
841
+ $groupName = $sectionGroup->getName();
842
+
843
+ $errors[] = array(
844
+ 'code' => 'POSTNL-0034',
845
+ 'message' => $this->__('%s > %s is required.', $this->__($groupLabel), $this->__($label)),
846
+ );
847
+
848
+ $this->saveConfigState(array('postnl_' . $groupName => 1));
849
  }
850
 
851
  /**
897
  * Based on Mage_Core_Model_Config::getModuleDir()
898
  *
899
  * @param string $dir The directory in question
900
+ * @param string $moduleName
901
  *
902
  * @return string
903
  *
904
+ * @see Mage_Core_Model_Config::getModuleDir()
905
  */
906
  public function getModuleDir($dir, $moduleName = 'TIG_PostNL')
907
  {
908
  $config = Mage::app()->getConfig();
909
 
910
+ /**
911
+ * @var Varien_Simplexml_Element $moduleConfig
912
+ */
913
+ $moduleConfig = $config->getModuleConfig($moduleName);
914
+ $codePool = (string) $moduleConfig->codePool;
915
  $path = $config->getOptions()->getCodeDir()
916
  . DS
917
  . $codePool
947
  }
948
 
949
  /**
950
+ * Logs a debug message. Based on Mage::log.
951
  *
952
+ * @param string $message
953
+ * @param int|null $level
954
+ * @param string|null $file
955
+ * @param boolean $forced
956
+ * @param boolean $isError
957
  *
958
  * @return TIG_PostNL_Helper_Data
959
  *
986
  * Logs a cron debug messageto a seperate file in order to differentiate it from other debug messages
987
  *
988
  * @param string $message
989
+ * @param int $level
990
  *
991
  * @return TIG_PostNL_Helper_Data
992
  *
1030
  }
1031
 
1032
  /**
1033
+ * Checks if the current edition of Magento is enterprise. Uses Mage::getEdition if available. If not, look for the
1034
+ * Enterprise_Enterprise extension. Finally, check the version number.
1035
  *
1036
  * @return boolean
1037
  *
1040
  public function isEnterprise()
1041
  {
1042
  /**
1043
+ * Use Mage::getEdition, which is available since CE 1.7 and EE 1.12.
1044
  */
1045
  if (method_exists('Mage', 'getEdition')) {
1046
  $edition = Mage::getEdition();
1053
  }
1054
 
1055
  /**
1056
+ * If the edition is not community or enterprise, it is not supported.
1057
  */
1058
  throw new TIG_PostNL_Exception(
1059
  $this->__('Invalid Magento edition detected: %s', $edition),
1062
  }
1063
 
1064
  /**
1065
+ * Check if the Enterprise_Enterprise extension is installed.
1066
+ */
1067
+ if (Mage::getConfig()->getNode('modules')->Enterprise_Enterprise) {
1068
+ return true;
1069
+ }
1070
+
1071
+ /**
1072
+ * Do a version check instead.
1073
  */
1074
  $version = Mage::getVersion();
1075
+ if (version_compare($version, '1.9.0.0', '>=')) {
1076
  return true;
1077
  }
1078
 
1091
  }
1092
 
1093
  /**
1094
+ * Fallback check in case the previous check returns a false negative.
1095
  */
1096
  if (Mage::getDesign()->getArea() == 'adminhtml') {
1097
  return true;
1118
  }
1119
 
1120
  /**
1121
+ * Gets the knowledge base URL for a specified error code. First we check to see if we have an entry in config.xml
1122
+ * for this error code and if so, if it has an associated URL.
1123
  *
1124
  * @param string $errorCode The error code (for example: POSTNL-0001)
1125
  *
1136
  }
1137
 
1138
  /**
1139
+ * Adds an error message to the specified session based on an exception. The exception should contain a valid error
1140
+ * code in order to properly process the error. Exceptions without a (valid) error code will behave like a regular
1141
  * $session->addError() call.
1142
  *
1143
  * @param string|Mage_Core_Model_Session_Abstract $session The session to which the messages will be added.
1197
 
1198
  /**
1199
  * Add a message to the specified session. Message can be an error, a success message, an info message or a warning.
1200
+ * If a valid error code is supplied, the message will be prepended with the error code and a link to a
1201
+ * knowledgebase article will be appended.
1202
  *
1203
  * If no $code is specified, $messageType and $message will be required
1204
  *
1216
  */
1217
  public function addSessionMessage($session, $code = null, $messageType = null, $message = null)
1218
  {
1219
+ /***************************************************************************************************************
1220
  * Check that the required arguments are available and valid
1221
+ **************************************************************************************************************/
1222
 
1223
  /**
1224
  * If $code is null or 0, $messageType and $message are required
1235
  /**
1236
  * If the session is a string, treat it as a class name and instantiate it
1237
  */
1238
+ if (is_string($session) && strpos($session, '/') !== false) {
1239
  $session = Mage::getSingleton($session);
1240
+ } elseif (is_string($session)) {
1241
+ $session = Mage::getSingleton($session . '/session');
1242
  }
1243
 
1244
  /**
1254
  );
1255
  }
1256
 
1257
+ /***************************************************************************************************************
1258
  * Get the actual error from config.xml if it's available
1259
+ **************************************************************************************************************/
1260
 
1261
  $error = false;
1262
  $link = false;
1271
  }
1272
  }
1273
 
1274
+ /***************************************************************************************************************
1275
+ * Check that the required 'message' and 'messageType' components are available. If they are not yet available,
1276
+ * we'll try to read them from the error itself.
1277
+ **************************************************************************************************************/
1278
 
1279
  /**
1280
  * If the specified error was found and no message was supplied, get the error's default message
1311
  );
1312
  }
1313
 
1314
+ /***************************************************************************************************************
1315
+ * Build the actual message we're going to add. The message will consist of the error code, followed by the
1316
+ * actual message and finally a link to the knowledge base. Only the message part is required.
1317
+ **************************************************************************************************************/
1318
 
1319
  /**
1320
  * Flag that determines whether the error code and knowledgebase link will be included in the error message
1336
  /**
1337
  * Add the actual message. This is the only required part. The code and link are optional
1338
  */
1339
+ $errorMessage .= $this->escapeHtml($this->__($message));
1340
 
1341
  /**
1342
  * Add the link to the knowledgebase if we have one
1343
  */
1344
  if ($canShowErrorDetails && $link) {
1345
  $errorMessage .= ' <a href="'
1346
+ . $this->escapeHtml($link)
1347
  . '" target="_blank" class="postnl-message">'
1348
  . $this->__('Click here for more information from the TiG knowledgebase.')
1349
  . '</a>';
1350
  }
1351
 
1352
+ /***************************************************************************************************************
1353
  * Finally, let's add the error to the session
1354
+ **************************************************************************************************************/
1355
 
1356
  /**
1357
  * The method we'll use to add the message to the session has to be built first
1377
  }
1378
 
1379
  /**
1380
+ * Checks to see if we can show error details (error code and knowledgebase link) in the frontend when an error
1381
+ * occurs.
1382
  *
1383
  * @return boolean
1384
  */
app/code/community/TIG/PostNL/Helper/DeliveryOptions.php ADDED
@@ -0,0 +1,739 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
40
+ {
41
+ /**
42
+ * Xpath to delivery options enabled config setting.
43
+ */
44
+ const XPATH_DELIVERY_OPTIONS_ACTIVE = 'postnl/delivery_options/delivery_options_active';
45
+
46
+ /**
47
+ * Xpaths to various possible delivery option settings.
48
+ */
49
+ const XPATH_ENABLE_PAKJEGEMAK = 'postnl/delivery_options/enable_pakjegemak';
50
+ const XPATH_ENABLE_PAKJEGEMAK_EXPRESS = 'postnl/delivery_options/enable_pakjegemak_express';
51
+ const XPATH_ENABLE_PAKKETAUTOMAAT_LOCATIONS = 'postnl/delivery_options/enable_pakketautomaat_locations';
52
+ const XPATH_ENABLE_TIMEFRAMES = 'postnl/delivery_options/enable_timeframes';
53
+ const XPATH_ENABLE_EVENING_TIMEFRAMES = 'postnl/delivery_options/enable_evening_timeframes';
54
+
55
+ /**
56
+ * Xpaths to various business rule settings.
57
+ */
58
+ const XPATH_SHOW_OPTIONS_FOR_LETTER = 'postnl/delivery_options/show_options_for_letter';
59
+ const XPATH_SHOW_OPTIONS_FOR_BACKORDERS = 'postnl/delivery_options/show_options_for_backorders';
60
+ const XPATH_ALLOW_SUNDAY_SORTING = 'postnl/delivery_options/allow_sunday_sorting';
61
+
62
+ /**
63
+ * Xpaths to extra fee config settings.
64
+ */
65
+ const XPATH_EVENING_TIMEFRAME_FEE = 'postnl/delivery_options/evening_timeframe_fee';
66
+ const XPATH_PAKJEGEMAK_EXPRESS_FEE = 'postnl/delivery_options/pakjegemak_express_fee';
67
+ /**
68
+ * Xpath for shipping duration setting.
69
+ */
70
+ const XPATH_SHIPPING_DURATION = 'postnl/delivery_options/shipping_duration';
71
+
72
+ /**
73
+ * The time (as H * 100 + i) we consider to be the start of the evening.
74
+ */
75
+ const EVENING_TIME = 1900;
76
+
77
+ /**
78
+ * @var array
79
+ */
80
+ protected $_validTypes = array(
81
+ 'Overdag',
82
+ 'Avond',
83
+ 'PG',
84
+ 'PGE',
85
+ 'PA',
86
+ );
87
+
88
+ /**
89
+ * @var Mage_Sales_Model_Quote
90
+ */
91
+ protected $_quote;
92
+
93
+ /**
94
+ * @return array
95
+ */
96
+ public function getValidTypes()
97
+ {
98
+ return $this->_validTypes;
99
+ }
100
+
101
+ /**
102
+ * @return Mage_Sales_Model_Quote
103
+ */
104
+ public function getQuote()
105
+ {
106
+ if ($this->_quote) {
107
+ return $this->_quote;
108
+ }
109
+
110
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
111
+
112
+ $this->_quote = $quote;
113
+ return $quote;
114
+ }
115
+
116
+ /**
117
+ * Get the fee charged for evening timeframes.
118
+ *
119
+ * @param boolean $formatted
120
+ * @param boolean $includingTax
121
+ *
122
+ * @return float
123
+ */
124
+ public function getEveningFee($formatted = false, $includingTax = true)
125
+ {
126
+ $storeId = Mage::app()->getStore()->getId();
127
+
128
+ $eveningFee = (float) Mage::getStoreConfig(self::XPATH_EVENING_TIMEFRAME_FEE, $storeId);
129
+
130
+ $price = $this->getPriceWithTax($eveningFee, $includingTax, $formatted);
131
+
132
+ return $price;
133
+ }
134
+
135
+ /**
136
+ * Get the fee charged for PakjeGemak Express.
137
+ *
138
+ * @param boolean $formatted
139
+ * @param boolean $includingTax
140
+ *
141
+ * @return float
142
+ */
143
+ public function getExpressFee($formatted = false, $includingTax = true)
144
+ {
145
+ $storeId = Mage::app()->getStore()->getId();
146
+
147
+ $expressFee = (float) Mage::getStoreConfig(self::XPATH_PAKJEGEMAK_EXPRESS_FEE, $storeId);
148
+
149
+ $price = $this->getPriceWithTax($expressFee, $includingTax, $formatted);
150
+
151
+ return $price;
152
+ }
153
+
154
+ /**
155
+ * Get the Shipping date for a specified order date.
156
+ *
157
+ * @param null|string $orderDate
158
+ * @param null|int $storeId
159
+ *
160
+ * @return bool|string
161
+ */
162
+ public function getShippingDate($orderDate = null, $storeId = null)
163
+ {
164
+ if ($orderDate === null) {
165
+ $orderDate = date('Y-m-d');
166
+ }
167
+
168
+ if ($storeId === null) {
169
+ $storeId = Mage::app()->getStore()->getId();
170
+ }
171
+
172
+ $shippingDuration = Mage::getStoreConfig(self::XPATH_SHIPPING_DURATION, $storeId);
173
+ $deliveryTime = strtotime("+{$shippingDuration} days", strtotime($orderDate));
174
+ $deliveryDay = date('N', $deliveryTime);
175
+
176
+ if ($deliveryDay == 1 && !Mage::helper('postnl/deliveryOptions')->canUseSundaySorting()) {
177
+ $deliveryTime = strtotime('+1 day', $deliveryTime);
178
+ }
179
+
180
+ $deliveryDate = date('Y-m-d', $deliveryTime);
181
+ return $deliveryDate;
182
+ }
183
+
184
+ /**
185
+ * Gets the shipping duration for the specified quote.
186
+ *
187
+ * @param Mage_Sales_Model_Quote $quote
188
+ *
189
+ * @return int
190
+ *
191
+ * @throws TIG_PostNL_Exception
192
+ */
193
+ public function getShippingDuration(Mage_Sales_Model_Quote $quote)
194
+ {
195
+ $storeId = $quote->getStoreId();
196
+
197
+ /**
198
+ * Get the default config duration.
199
+ */
200
+ $configDuration = (int) Mage::getStoreConfig(self::XPATH_SHIPPING_DURATION, $storeId);
201
+ $durationArray = array($configDuration);
202
+
203
+ /**
204
+ * Loop through all products in the quote.
205
+ *
206
+ * @var Mage_Sales_Model_Quote_Item $item
207
+ */
208
+ foreach ($quote->getAllVisibleItems() as $item) {
209
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
210
+
211
+ /**
212
+ * If the product has a specific shipping duration, add it to the array of durations.
213
+ */
214
+ if ($product->hasPostnlShippingDuration() && $product->getPostnlShippingDuration() !== '') {
215
+ $durationArray[] = (int) $product->getPostnlShippingDuration();
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Sort the array and get it's last item. This will be the highest value.
221
+ */
222
+ natsort($durationArray);
223
+ $shippingDuration = end($durationArray);
224
+
225
+ /**
226
+ * Make sure the value is between 1 and 14 days.
227
+ */
228
+ if ($shippingDuration > 14 || $shippingDuration < 1) {
229
+ throw new TIG_PostNL_Exception(
230
+ Mage::helper('postnl')->__(
231
+ 'Invalid shipping duration: %s. Shipping duration must be between 1 and 14 days.',
232
+ $shippingDuration
233
+ ),
234
+ 'POSTNL-0127'
235
+ );
236
+ }
237
+
238
+ return $shippingDuration;
239
+ }
240
+
241
+ /**
242
+ * Convert a value to a formatted price.
243
+ *
244
+ * @param float $price
245
+ * @param boolean $includingTax
246
+ * @param boolean $formatted
247
+ *
248
+ * @return float
249
+ *
250
+ * @see Mage_Checkout_Block_Onepage_Shipping_Method_Available::getShippingPrice()
251
+ */
252
+ public function getPriceWithTax($price, $includingTax, $formatted = false)
253
+ {
254
+ $quote = $this->getQuote();
255
+ $store = $quote->getStore();
256
+
257
+ $shippingPrice = Mage::helper('tax')->getShippingPrice($price, $includingTax, $quote->getShippingAddress());
258
+ $convertedPrice = $store->convertPrice($shippingPrice, $formatted, false);
259
+
260
+ return $convertedPrice;
261
+ }
262
+
263
+ /**
264
+ * Mark a set of location results with the 'isEvening' parameter. This will allow the google maps api to easily
265
+ * identify which locations may be filtered out later.
266
+ *
267
+ * @param array $locations An array of PostNL location objects
268
+ * @param string $deliveryDate The date on which the package should be delivered.
269
+ *
270
+ * @return array
271
+ */
272
+ public function markEveningLocations($locations, $deliveryDate)
273
+ {
274
+ /**
275
+ * Get the day of the week on which the package should be delivered.
276
+ *
277
+ * date('l') returns the full textual representation of the day of the week (Sunday through Saturday).
278
+ */
279
+ $weekDay = date('l', strtotime($deliveryDate));
280
+
281
+ foreach ($locations as &$location) {
282
+ /**
283
+ * if we don't have any business hours specified for this date, the location is closed.
284
+ */
285
+ if (!isset($location->OpeningHours->$weekDay->string)) {
286
+ $location->isEvening = false;
287
+
288
+ continue;
289
+ }
290
+
291
+ /**
292
+ * Check if the location is open in the evening and mark it accordingly.
293
+ */
294
+ $businessHours = $location->OpeningHours->$weekDay->string;
295
+ if ($this->_businessHoursIsEvening($businessHours)) {
296
+ $location->isEvening = true;
297
+
298
+ continue;
299
+ }
300
+
301
+ $location->isEvening = false;
302
+
303
+ continue;
304
+ }
305
+
306
+ return $locations;
307
+ }
308
+
309
+ /**
310
+ * Check if an array of business hours contains a timespan that is condiered to be in the evening.
311
+ *
312
+ * @param array $businessHours
313
+ *
314
+ * @return bool
315
+ */
316
+ protected function _businessHoursIsEvening($businessHours)
317
+ {
318
+ foreach ($businessHours as $businessHour) {
319
+ if ($this->_isEvening($businessHour)) {
320
+ return true;
321
+ }
322
+ }
323
+
324
+ return false;
325
+ }
326
+
327
+ /**
328
+ * Check if a specified opening time is considered to be in the evening. Opening times must be formatted as
329
+ * H:i-H:i. The second part of the time (the closing time) will be compared to the self::EVENING_TIME constant to
330
+ * find out if it's in the evening.
331
+ *
332
+ * @param $time
333
+ *
334
+ * @return bool
335
+ */
336
+ protected function _isEvening($time)
337
+ {
338
+ $timeParts = explode('-', $time);
339
+
340
+ if (!isset($timeParts[1])) {
341
+ return false;
342
+ }
343
+
344
+ $closingTime = str_replace(':', '', $timeParts[1]);
345
+
346
+ if ($closingTime >= self::EVENING_TIME) {
347
+ return true;
348
+ }
349
+
350
+ return false;
351
+ }
352
+
353
+ /**
354
+ * Checks if PakjeGemak is available.
355
+ *
356
+ * @param int|boolean $storeId
357
+ *
358
+ * @return boolean
359
+ */
360
+ public function canUsePakjeGemak($storeId = false)
361
+ {
362
+ if ($storeId === false) {
363
+ $storeId = Mage::app()->getStore()->getId();
364
+ }
365
+
366
+ $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_PAKJEGEMAK, $storeId);
367
+ if (!$enabled) {
368
+ return false;
369
+ }
370
+
371
+ $canUsePakjeGemak = parent::canUsePakjeGemak($storeId);
372
+
373
+ return $canUsePakjeGemak;
374
+ }
375
+
376
+ /**
377
+ * Checks if PakjeGemak Express is available.
378
+ *
379
+ * @param int|boolean $storeId
380
+ *
381
+ * @return boolean
382
+ */
383
+ public function canUsePakjeGemakExpress($storeId = false)
384
+ {
385
+ if ($storeId === false) {
386
+ $storeId = Mage::app()->getStore()->getId();
387
+ }
388
+
389
+ if (!$this->canUsePakjeGemak($storeId)) {
390
+ return false;
391
+ }
392
+
393
+ $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_PAKJEGEMAK_EXPRESS, $storeId);
394
+ if (!$enabled) {
395
+ return false;
396
+ }
397
+
398
+ $pgeOptions = Mage::getModel('postnl_core/system_config_source_pakjeGemakProductOptions')
399
+ ->getAvailablePgeOptions($storeId);
400
+
401
+ if (empty($pgeOptions)) {
402
+ return false;
403
+ }
404
+
405
+ return true;
406
+ }
407
+
408
+ /**
409
+ * Checks if 'pakket automaat' is available.
410
+ *
411
+ * @param int|boolean $storeId
412
+ *
413
+ * @return boolean
414
+ */
415
+ public function canUsePakketAutomaat($storeId = false)
416
+ {
417
+ if ($storeId === false) {
418
+ $storeId = Mage::app()->getStore()->getId();
419
+ }
420
+
421
+ $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_PAKKETAUTOMAAT_LOCATIONS, $storeId);
422
+ if (!$enabled) {
423
+ return false;
424
+ }
425
+
426
+ $pakketautomaatOptions = Mage::getModel('postnl_core/system_config_source_pakketautomaatProductOptions')
427
+ ->getAvailableOptions($storeId);
428
+
429
+ if (empty($pakketautomaatOptions)) {
430
+ return false;
431
+ }
432
+
433
+ return true;
434
+ }
435
+
436
+ /**
437
+ * Checks if timeframes are available.
438
+ *
439
+ * @param int|boolean $storeId
440
+ *
441
+ * @return boolean
442
+ */
443
+ public function canUseTimeframes($storeId = false)
444
+ {
445
+ if ($storeId === false) {
446
+ $storeId = Mage::app()->getStore()->getId();
447
+ }
448
+
449
+ $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_TIMEFRAMES, $storeId);
450
+
451
+ return $enabled;
452
+ }
453
+
454
+ /**
455
+ * Checks if evening timeframes are available.
456
+ *
457
+ * @param int|boolean $storeId
458
+ *
459
+ * @return boolean
460
+ */
461
+ public function canUseEveningTimeframes($storeId = false)
462
+ {
463
+ if ($storeId === false) {
464
+ $storeId = Mage::app()->getStore()->getId();
465
+ }
466
+
467
+ if (!$this->canUseTimeframes($storeId)) {
468
+ return false;
469
+ }
470
+
471
+ $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_EVENING_TIMEFRAMES, $storeId);
472
+ if (!$enabled) {
473
+ return false;
474
+ }
475
+
476
+ $eveningOptions = Mage::getModel('postnl_core/system_config_source_standardProductOptions')
477
+ ->getAvailableAvondOptions($storeId);
478
+
479
+ if (empty($eveningOptions)) {
480
+ return false;
481
+ }
482
+
483
+ return true;
484
+ }
485
+
486
+ /**
487
+ * Checks if sunday sorting is allowed.
488
+ *
489
+ * @param bool $storeId
490
+ *
491
+ * @return bool
492
+ */
493
+ public function canUseSundaySorting($storeId = false)
494
+ {
495
+ if ($storeId === false) {
496
+ $storeId = Mage::app()->getStore()->getId();
497
+ }
498
+
499
+ $allowed = Mage::getStoreConfigFlag(self::XPATH_ALLOW_SUNDAY_SORTING, $storeId);
500
+
501
+ return $allowed;
502
+ }
503
+
504
+ /**
505
+ * Check if PostNL delivery options may be used based on a quote.
506
+ *
507
+ * @param Mage_Sales_Model_Quote|boolean $quote
508
+ * @param boolean $checkCountry
509
+ *
510
+ * @return boolean
511
+ */
512
+ public function canUseDeliveryOptions($quote = false, $checkCountry = true)
513
+ {
514
+ $registryKey = 'can_use_delivery_options';
515
+ if ($quote) {
516
+ $registryKey .= '_quote_id_' . $quote->getId();
517
+ }
518
+
519
+ if ($checkCountry) {
520
+ $registryKey .= '_check_country';
521
+ }
522
+
523
+ if (Mage::registry($registryKey) !== null) {
524
+ return Mage::registry($registryKey);
525
+ }
526
+
527
+ Mage::unregister('postnl_enabled_delivery_options_errors');
528
+
529
+ $deliveryOptionsEnabled = $this->isDeliveryOptionsEnabled();
530
+ if (!$deliveryOptionsEnabled) {
531
+ Mage::register($registryKey, false);
532
+ return false;
533
+ }
534
+
535
+ /**
536
+ * PostNL delivery options cannot be used for virtual orders
537
+ */
538
+ if ($quote && $quote->isVirtual()) {
539
+ $errors = array(
540
+ array(
541
+ 'code' => 'POSTNL-0104',
542
+ 'message' => $this->__('The quote is virtual.'),
543
+ )
544
+ );
545
+ Mage::register('postnl_enabled_delivery_options_errors', $errors);
546
+ Mage::register($registryKey, false);
547
+ return false;
548
+ }
549
+
550
+ /**
551
+ * Check if the quote has a valid minimum amount
552
+ */
553
+ if ($quote && !$quote->validateMinimumAmount()) {
554
+ $errors = array(
555
+ array(
556
+ 'code' => 'POSTNL-0105',
557
+ 'message' => $this->__("The quote's grand total is below the minimum amount required."),
558
+ )
559
+ );
560
+ Mage::register('postnl_enabled_delivery_options_errors', $errors);
561
+ Mage::register($registryKey, false);
562
+ return false;
563
+ }
564
+
565
+ /**
566
+ * Check that dutch addresses are allowed
567
+ */
568
+ if (!$this->canUseStandard()) {
569
+ $errors = array(
570
+ array(
571
+ 'code' => 'POSTNL-0106',
572
+ 'message' => $this->__(
573
+ 'No standard product options are enabled. At least 1 option must be active.'
574
+ ),
575
+ )
576
+ );
577
+ Mage::register('postnl_enabled_delivery_options_errors', $errors);
578
+ Mage::register($registryKey, false);
579
+ return false;
580
+ }
581
+
582
+ if ($quote && $checkCountry) {
583
+ $shippingAddress = $quote->getShippingAddress();
584
+ if ($shippingAddress->getCountry() != 'NL') {
585
+ $errors = array(
586
+ array(
587
+ 'code' => 'POSTNL-0132',
588
+ 'message' => $this->__(
589
+ 'PostNL delivery options are only available for Dutch shipping addresses.'
590
+ ),
591
+ )
592
+ );
593
+ Mage::register('postnl_enabled_delivery_options_errors', $errors);
594
+ Mage::register($registryKey, false);
595
+ return false;
596
+ }
597
+ }
598
+
599
+ /**
600
+ * If we have no quote, we have no further checks to perform.
601
+ */
602
+ if (!$quote) {
603
+ Mage::register($registryKey, true);
604
+ return true;
605
+ }
606
+
607
+ $storeId = $quote->getStoreId();
608
+
609
+ /**
610
+ * Check if PostNL delivery options may be used for 'letter' orders and if not, if the quote could fit in an
611
+ * envelope.
612
+ */
613
+ $showDeliveryOptionsForLetters = Mage::getStoreConfigFlag(self::XPATH_SHOW_OPTIONS_FOR_LETTER, $storeId);
614
+ if (!$showDeliveryOptionsForLetters) {
615
+ $isLetterQuote = $this->quoteIsLetter($quote, $storeId);
616
+ if ($isLetterQuote) {
617
+ $errors = array(
618
+ array(
619
+ 'code' => 'POSTNL-0150',
620
+ 'message' => $this->__(
621
+ "The quote's total weight is below the miniumum required to use PostNL delivery options."
622
+ ),
623
+ )
624
+ );
625
+ Mage::register('postnl_enabled_delivery_options_errors', $errors);
626
+ Mage::register($registryKey, false);
627
+ return false;
628
+ }
629
+ }
630
+
631
+ /**
632
+ * Check if PostNL delivery options may be used for out-og-stock orders and if not, whether the quote has any
633
+ * such products.
634
+ */
635
+ $showDeliveryOptionsForBackorders = Mage::getStoreConfigFlag(self::XPATH_SHOW_OPTIONS_FOR_BACKORDERS, $storeId);
636
+ if (!$showDeliveryOptionsForBackorders) {
637
+ $containsOutOfStockItems = $this->quoteHasOutOfStockItems($quote);
638
+ if ($containsOutOfStockItems) {
639
+ $errors = array(
640
+ array(
641
+ 'code' => 'POSTNL-0102',
642
+ 'message' => $this->__('One or more items in the cart are out of stock.'),
643
+ )
644
+ );
645
+ Mage::register('postnl_enabled_delivery_options_errors', $errors);
646
+ Mage::register($registryKey, false);
647
+ return false;
648
+ }
649
+ }
650
+
651
+ Mage::register($registryKey, true);
652
+ return true;
653
+ }
654
+
655
+ /**
656
+ * Check if the module is set to test mode
657
+ *
658
+ * @param bool $storeId
659
+ *
660
+ * @return boolean
661
+ */
662
+ public function isTestMode($storeId = false)
663
+ {
664
+ if (Mage::registry('delivery_options_test_mode') !== null) {
665
+ return Mage::registry('delivery_options_test_mode');
666
+ }
667
+
668
+ if ($storeId === false) {
669
+ $storeId = Mage::app()->getStore()->getId();
670
+ }
671
+
672
+ $testMode = Mage::getStoreConfigFlag(self::XML_PATH_TEST_MODE, $storeId);
673
+
674
+ Mage::register('delivery_options_test_mode', $testMode);
675
+ return $testMode;
676
+ }
677
+
678
+ /**
679
+ * Checks if PostNL delivery options are enabled.
680
+ *
681
+ * @param null|int $storeId
682
+ *
683
+ * @return boolean
684
+ */
685
+ public function isDeliveryOptionsEnabled($storeId = null)
686
+ {
687
+ if (is_null($storeId)) {
688
+ $storeId = Mage::app()->getStore()->getId();
689
+ }
690
+
691
+ if (Mage::registry('postnl_enabled_delivery_options_errors')) {
692
+ Mage::unregister('postnl_enabled_delivery_options_errors');
693
+ }
694
+
695
+ $isPostnlEnabled = $this->isEnabled($storeId, false, $this->isTestMode());
696
+ if ($isPostnlEnabled === false) {
697
+ $errors = array(
698
+ array(
699
+ 'code' => 'POSTNL-0107',
700
+ 'message' => $this->__('You have not yet enabled the PostNL extension.'),
701
+ )
702
+ );
703
+ Mage::register('postnl_enabled_delivery_options_errors', $errors);
704
+ return false;
705
+ }
706
+
707
+ $isDeliveryOptionsActive = $this->isDeliveryOptionsActive($storeId);
708
+ if (!$isDeliveryOptionsActive) {
709
+ $errors = array(
710
+ array(
711
+ 'code' => 'POSTNL-0133',
712
+ 'message' => $this->__('You have not yet enabled PostNL delivery options.'),
713
+ )
714
+ );
715
+ Mage::register('postnl_enabled_delivery_options_errors', $errors);
716
+ return false;
717
+ }
718
+
719
+ return true;
720
+ }
721
+
722
+ /**
723
+ * Checks if PostNL delivery options is active.
724
+ *
725
+ * @param null|int $storeId
726
+ *
727
+ * @return boolean
728
+ */
729
+ public function isDeliveryOptionsActive($storeId = null)
730
+ {
731
+ if (is_null($storeId)) {
732
+ $storeId = Mage::app()->getStore()->getId();
733
+ }
734
+
735
+ $isActive = Mage::getStoreConfigFlag(self::XPATH_DELIVERY_OPTIONS_ACTIVE, $storeId);
736
+
737
+ return $isActive;
738
+ }
739
+ }
app/code/community/TIG/PostNL/Helper/Mijnpakket.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Helper_Mijnpakket extends TIG_PostNL_Helper_Data
40
+ {
41
+ /**
42
+ * Xpath to 'mijnpakket_login_active' setting.
43
+ */
44
+ const XPATH_MIJNPAKKET_LOGIN_ACTIVE = 'postnl/delivery_options/mijnpakket_login_active';
45
+
46
+ /**
47
+ * Log filename to log all non-specific PostNL debug messages.
48
+ */
49
+ const POSTNL_DEBUG_LOG_FILE = 'TIG_PostNL_MijnPakket_Debug.log';
50
+
51
+ /**
52
+ * Check whether MijnPakket login is active.
53
+ *
54
+ * @return bool
55
+ */
56
+ public function isMijnpakketLoginActive()
57
+ {
58
+ $storeId = Mage::app()->getStore()->getId();
59
+
60
+ $isActive = Mage::getStoreConfigFlag(self::XPATH_MIJNPAKKET_LOGIN_ACTIVE, $storeId);
61
+
62
+ return $isActive;
63
+ }
64
+
65
+ /**
66
+ * Checks whether MijnPakket login is currently available for use.
67
+ *
68
+ * @return boolean
69
+ */
70
+ public function canLoginWithMijnpakket()
71
+ {
72
+ /**
73
+ * MijnPakket login is only available if delivery options are enabled.
74
+ */
75
+ if (!Mage::helper('postnl/deliveryOptions')->isDeliveryOptionsEnabled()) {
76
+ return false;
77
+ }
78
+
79
+ if (!$this->isMijnpakketLoginActive()) {
80
+ return false;
81
+ }
82
+
83
+ return true;
84
+ }
85
+
86
+ /**
87
+ * Get initials based on a firstname.
88
+ *
89
+ * @param string $firstName
90
+ *
91
+ * @return string
92
+ */
93
+ public function getInitials($firstName)
94
+ {
95
+ $nameParts = preg_split("/\s+/", $firstName);
96
+
97
+ $initials = '';
98
+ foreach ($nameParts as $name) {
99
+ $initials .= substr($name, 0, 1) . '.';
100
+ }
101
+
102
+ $initials = strtoupper($initials);
103
+ return $initials;
104
+ }
105
+ }
app/code/community/TIG/PostNL/Helper/Parcelware.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Helper_Parcelware extends TIG_PostNL_Helper_Data
40
+ {
41
+ /**
42
+ * XML path to auto confirm setting
43
+ */
44
+ const XML_PATH_AUTO_CONFIRM = 'postnl/parcelware_export/auto_confirm';
45
+
46
+ /**
47
+ * XML path to the active/inactive setting
48
+ */
49
+ const XML_PATH_ACTIVE = 'postnl/parcelware_export/active';
50
+
51
+ /**
52
+ * XML path to the customer code setting.
53
+ */
54
+ const XML_PATH_CUSTOMER_CODE = 'postnl/cif/customer_code';
55
+
56
+ /**
57
+ * AutoConfirmEnabled flag
58
+ *
59
+ * @var boolean|null $_autoConfirmEnabled
60
+ */
61
+ protected $_autoConfirmEnabled = null;
62
+
63
+ /**
64
+ * Gets the autoConfirmEnabled flag
65
+ *
66
+ * @return boolean|null
67
+ */
68
+ public function getAutoConfirmEnabled()
69
+ {
70
+ return $this->_autoConfirmEnabled;
71
+ }
72
+
73
+ /**
74
+ * Sets the autoConfirmEnabled flag
75
+ *
76
+ * @param boolean $autoConfirmEnabled
77
+ *
78
+ * @return TIG_PostNL_Helper_Parcelware
79
+ */
80
+ public function setAutoConfirmEnabled($autoConfirmEnabled)
81
+ {
82
+ $this->_autoConfirmEnabled = $autoConfirmEnabled;
83
+
84
+ return $this;
85
+ }
86
+
87
+ /**
88
+ * Splits a barcode into its component parts.
89
+ *
90
+ * @param string $barcode
91
+ * @param int|bool $storeId
92
+ *
93
+ * @return array
94
+ */
95
+ public function splitBarcode($barcode, $storeId = false)
96
+ {
97
+ if ($storeId === false) {
98
+ $storeId = Mage::app()->getStore()->getId();
99
+ }
100
+
101
+ $type = substr($barcode, 0, 2);
102
+
103
+ $customerCode = (string) Mage::getStoreConfig(self::XML_PATH_CUSTOMER_CODE, $storeId);
104
+
105
+ $number = substr($barcode, 2 + strlen($customerCode));
106
+
107
+ $barcodeComponents = array(
108
+ 'type' => $type,
109
+ 'range' => $customerCode,
110
+ 'number' => $number,
111
+ );
112
+
113
+ return $barcodeComponents;
114
+ }
115
+
116
+ /**
117
+ * Check to see if Parcelware export functionality is enabled.
118
+ */
119
+ public function isParcelwareExportEnabled($storeId = null)
120
+ {
121
+ if ($storeId === null) {
122
+ $storeId = Mage::app()->getStore()->getId();
123
+ }
124
+
125
+ $active = Mage::getStoreConfigFlag(self::XML_PATH_ACTIVE, $storeId);
126
+
127
+ return $active;
128
+ }
129
+
130
+ /**
131
+ * Checks if auto confirm is enabled
132
+ *
133
+ * @return boolean
134
+ */
135
+ public function isAutoConfirmEnabled()
136
+ {
137
+ if ($this->getAutoConfirmEnabled() !== null) {
138
+ return $this->getAutoConfirmEnabled();
139
+ }
140
+
141
+ $autoConfirmEnabled = Mage::getStoreConfigFlag(self::XML_PATH_AUTO_CONFIRM, Mage_Core_Model_App::ADMIN_STORE_ID);
142
+
143
+ $this->setAutoConfirmEnabled($autoConfirmEnabled);
144
+ return $autoConfirmEnabled;
145
+ }
146
+ }
app/code/community/TIG/PostNL/Helper/Webservices.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,10 +33,10 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
-
40
  /**
41
  * Helper class for CIF operations
42
  */
@@ -47,39 +47,39 @@ class TIG_PostNL_Helper_Webservices extends TIG_PostNL_Helper_Data
47
  */
48
  const XML_PATH_EXTENSIONCONTROL_UNIQUE_KEY = 'postnl/general/unique_key';
49
  const XML_PATH_EXTENSIONCONTROL_PRIVATE_KEY = 'postnl/general/private_key';
50
-
51
  /**
52
  * XML path to updateStatistics on/off switch
53
  */
54
  const XML_PATH_SEND_STATISTICS = 'postnl/advanced/send_statistics';
55
-
56
  /**
57
  * XML path to receiveUpdates on/off switch
58
  */
59
  const XML_PATH_RECEIVE_UPDATES = 'postnl/advanced/receive_updates';
60
-
61
  /**
62
  * Log filename to log all webservices exceptions
63
  */
64
  const WEBSERVICES_EXCEPTION_LOG_FILE = 'TIG_PostNL_Webservices_Exception.log';
65
-
66
  /**
67
- * Log filename to webservices CIF calls
68
  */
69
  const WEBSERVICES_DEBUG_LOG_FILE = 'TIG_PostNL_Webservices_Debug.log';
70
-
71
  /**
72
  * Check if the extension has been activated with the extension control system by checking if the unique ket and private key
73
  * have been entered.
74
- *
75
  * @param Mage_Core_Model_Website | null $website
76
- *
77
  * @return boolean
78
  */
79
  public function canSendStatistics($website = null)
80
  {
81
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
82
-
83
  /**
84
  * First check if sending statistics is enabled
85
  */
@@ -94,135 +94,108 @@ class TIG_PostNL_Helper_Webservices extends TIG_PostNL_Helper_Data
94
  */
95
  $sendStatistics = Mage::getStoreConfigFlag(self::XML_PATH_SEND_STATISTICS, $storeId);
96
  }
97
-
98
  if (!$sendStatistics) {
99
  return false;
100
  }
101
-
102
  /**
103
  * Check if the security keys have been entered.
104
  */
105
  $privateKey = Mage::getStoreConfig(self::XML_PATH_EXTENSIONCONTROL_PRIVATE_KEY, $storeId);
106
  $uniqueKey = Mage::getStoreConfig(self::XML_PATH_EXTENSIONCONTROL_UNIQUE_KEY, $storeId);
107
-
108
  if (empty($privateKey) || empty($uniqueKey)) {
109
  return false;
110
  }
111
-
112
  return true;
113
  }
114
-
115
  /**
116
  * Checks whether the module may automatically receive updates regarding the module or promotions
117
- *
118
  * @return boolean
119
  */
120
  public function canReceiveUpdates()
121
  {
122
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
123
-
124
- $receiveUpdates = Mage::getStoreConfigFlag(self::XML_PATH_RECEIVE_UPDATES);
125
  if (!$receiveUpdates) {
126
  return false;
127
  }
128
-
129
  return true;
130
  }
131
-
132
  /**
133
  * Encrypts a value
134
- *
135
  * @param string $value
136
- *
137
  * @return string
138
  */
139
  public function encryptValue($value)
140
  {
141
  $value = (string) $value;
142
-
143
  $encrypted = Mage::helper('core')->encrypt($value);
144
-
145
  return $encrypted;
146
  }
147
-
148
  /**
149
  * Logs a webservice request and response for debug purposes.
150
- *
151
- * N.B.: if file logging is enabled, the log will be forced
152
- *
153
- * @param SoapClient $client
154
- *
155
  * @return TIG_PostNL_Helper_Webservices
156
- *
157
  * @see Mage::log()
158
- *
159
- * @todo add additional debug options
160
- *
161
  */
162
  public function logWebserviceCall($client)
163
  {
164
- if (!$this->isLoggingEnabled()) {
165
  return $this;
166
  }
167
-
168
  $this->createLogDir();
169
-
170
  $requestXml = $this->formatXml($client->getLastRequest());
171
  $responseXML = $this->formatXml($client->getLastResponse());
172
-
173
  $logMessage = "Request sent:\n"
174
  . $requestXml
175
  . "\nResponse received:\n"
176
  . $responseXML;
177
-
178
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::WEBSERVICES_DEBUG_LOG_FILE;
179
  $this->log($logMessage, Zend_Log::DEBUG, $file);
180
-
181
  return $this;
182
  }
183
-
184
  /**
185
  * Logs a webservice exception in the database and/or a log file
186
- *
187
- * N.B.: if file logging is enabled, the log will be forced
188
- *
189
- * @param Mage_Core_Exception | TIG_PostNL_Model_Core_Webservices_Exception $exception
190
- *
191
  * @return TIG_PostNL_Helper_Webservices
192
- *
193
  * @see Mage::logException()
194
- *
195
- * @todo add additional debug options
196
  */
197
  public function logWebserviceException($exception)
198
  {
199
  if (!$this->isExceptionLoggingEnabled()) {
200
  return $this;
201
  }
202
-
203
- if ($exception instanceof TIG_PostNL_Model_Core_Webservices_Exception) {
204
- $requestXml = $this->formatXml($exception->getRequestXml());
205
- $responseXML = $this->formatXml($exception->getResponseXml());
206
-
207
- $logMessage = '';
208
-
209
- $errorNumbers = $exception->getErrorNumbers();
210
- if (!empty($errorNumbers)) {
211
- $errorNumbers = implode(', ', $errorNumbers);
212
- $logMessage .= "Error numbers received: {$errorNumbers}\n";
213
- }
214
-
215
- $logMessage .= "<<< REQUEST SENT >>>\n"
216
- . $requestXml
217
- . "\n<<< RESPONSE RECEIVED >>>\n"
218
- . $responseXML;
219
- } else {
220
- $logMessage = "\n" . $exception->__toString();
221
- }
222
-
223
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::WEBSERVICES_EXCEPTION_LOG_FILE;
224
  $this->log($logMessage, Zend_Log::ERR, $file, false, true);
225
-
226
  return $this;
227
  }
228
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+
40
  /**
41
  * Helper class for CIF operations
42
  */
47
  */
48
  const XML_PATH_EXTENSIONCONTROL_UNIQUE_KEY = 'postnl/general/unique_key';
49
  const XML_PATH_EXTENSIONCONTROL_PRIVATE_KEY = 'postnl/general/private_key';
50
+
51
  /**
52
  * XML path to updateStatistics on/off switch
53
  */
54
  const XML_PATH_SEND_STATISTICS = 'postnl/advanced/send_statistics';
55
+
56
  /**
57
  * XML path to receiveUpdates on/off switch
58
  */
59
  const XML_PATH_RECEIVE_UPDATES = 'postnl/advanced/receive_updates';
60
+
61
  /**
62
  * Log filename to log all webservices exceptions
63
  */
64
  const WEBSERVICES_EXCEPTION_LOG_FILE = 'TIG_PostNL_Webservices_Exception.log';
65
+
66
  /**
67
+ * Log filename to log webservices calls
68
  */
69
  const WEBSERVICES_DEBUG_LOG_FILE = 'TIG_PostNL_Webservices_Debug.log';
70
+
71
  /**
72
  * Check if the extension has been activated with the extension control system by checking if the unique ket and private key
73
  * have been entered.
74
+ *
75
  * @param Mage_Core_Model_Website | null $website
76
+ *
77
  * @return boolean
78
  */
79
  public function canSendStatistics($website = null)
80
  {
81
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
82
+
83
  /**
84
  * First check if sending statistics is enabled
85
  */
94
  */
95
  $sendStatistics = Mage::getStoreConfigFlag(self::XML_PATH_SEND_STATISTICS, $storeId);
96
  }
97
+
98
  if (!$sendStatistics) {
99
  return false;
100
  }
101
+
102
  /**
103
  * Check if the security keys have been entered.
104
  */
105
  $privateKey = Mage::getStoreConfig(self::XML_PATH_EXTENSIONCONTROL_PRIVATE_KEY, $storeId);
106
  $uniqueKey = Mage::getStoreConfig(self::XML_PATH_EXTENSIONCONTROL_UNIQUE_KEY, $storeId);
107
+
108
  if (empty($privateKey) || empty($uniqueKey)) {
109
  return false;
110
  }
111
+
112
  return true;
113
  }
114
+
115
  /**
116
  * Checks whether the module may automatically receive updates regarding the module or promotions
117
+ *
118
  * @return boolean
119
  */
120
  public function canReceiveUpdates()
121
  {
122
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
123
+
124
+ $receiveUpdates = Mage::getStoreConfigFlag(self::XML_PATH_RECEIVE_UPDATES, $storeId);
125
  if (!$receiveUpdates) {
126
  return false;
127
  }
128
+
129
  return true;
130
  }
131
+
132
  /**
133
  * Encrypts a value
134
+ *
135
  * @param string $value
136
+ *
137
  * @return string
138
  */
139
  public function encryptValue($value)
140
  {
141
  $value = (string) $value;
142
+
143
  $encrypted = Mage::helper('core')->encrypt($value);
144
+
145
  return $encrypted;
146
  }
147
+
148
  /**
149
  * Logs a webservice request and response for debug purposes.
150
+ *
151
+ * @param Zend_Soap_Client $client
152
+ *
 
 
153
  * @return TIG_PostNL_Helper_Webservices
154
+ *
155
  * @see Mage::log()
 
 
 
156
  */
157
  public function logWebserviceCall($client)
158
  {
159
+ if (!$this->isLoggingEnabled()) {
160
  return $this;
161
  }
162
+
163
  $this->createLogDir();
164
+
165
  $requestXml = $this->formatXml($client->getLastRequest());
166
  $responseXML = $this->formatXml($client->getLastResponse());
167
+
168
  $logMessage = "Request sent:\n"
169
  . $requestXml
170
  . "\nResponse received:\n"
171
  . $responseXML;
172
+
173
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::WEBSERVICES_DEBUG_LOG_FILE;
174
  $this->log($logMessage, Zend_Log::DEBUG, $file);
175
+
176
  return $this;
177
  }
178
+
179
  /**
180
  * Logs a webservice exception in the database and/or a log file
181
+ *
182
+ * @param Mage_Core_Exception|TIG_PostNL_Exception|SoapFault $exception
183
+ *
 
 
184
  * @return TIG_PostNL_Helper_Webservices
185
+ *
186
  * @see Mage::logException()
 
 
187
  */
188
  public function logWebserviceException($exception)
189
  {
190
  if (!$this->isExceptionLoggingEnabled()) {
191
  return $this;
192
  }
193
+
194
+ $logMessage = "\n" . $exception->__toString();
195
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::WEBSERVICES_EXCEPTION_LOG_FILE;
197
  $this->log($logMessage, Zend_Log::ERR, $file, false, true);
198
+
199
  return $this;
200
  }
201
  }
app/code/community/TIG/PostNL/Model/AddressValidation/Cendris.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_AddressValidation_Cendris extends TIG_PostNL_Model_AddressValidation_Cendris_Abstract
40
+ {
41
+ /**
42
+ * Xpaths to cendris username and password.
43
+ */
44
+ const XPATH_USERNAME = 'postnl/cendris/username';
45
+ const XPATH_PASSWORD = 'postnl/cendris/password';
46
+
47
+ /**
48
+ * Validates and enriches the postcode and housenumber with a city and streetname
49
+ *
50
+ * @param string $postcode
51
+ * @param string $housenumber
52
+ *
53
+ * @return StdClass
54
+ */
55
+ public function getAdresxpressPostcode($postcode, $housenumber)
56
+ {
57
+ $username = $this->_getUsername();
58
+ $password = $this->_getPassword();
59
+
60
+ $soapParams = array(
61
+ 'gebruikersnaam' => $username,
62
+ 'wachtwoord' => $password,
63
+ 'postcode' => $postcode,
64
+ 'huisnummer' => $housenumber,
65
+ );
66
+
67
+ $result = $this->call('getAdresxpressPostcode', $soapParams);
68
+
69
+ if (is_array($result)) {
70
+ $result = current($result);
71
+ }
72
+
73
+ return $result;
74
+ }
75
+
76
+ /**
77
+ * Get the Cendris username.
78
+ *
79
+ * @return string
80
+ */
81
+ protected function _getUsername()
82
+ {
83
+ $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
84
+ $username = Mage::getStoreConfig(self::XPATH_USERNAME, $storeId);
85
+
86
+ return $username;
87
+ }
88
+
89
+ /**
90
+ * Get the Cendris password.
91
+ *
92
+ * @return string
93
+ */
94
+ protected function _getPassword()
95
+ {
96
+ $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
97
+ $password = Mage::getStoreConfig(self::XPATH_PASSWORD, $storeId);
98
+
99
+ return $password;
100
+ }
101
+ }
app/code/community/TIG/PostNL/Model/AddressValidation/Cendris/Abstract.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ advanced * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_AddressValidation_Cendris_Abstract extends Varien_Object
40
+ {
41
+ /**
42
+ * Wsdl location
43
+ */
44
+ const WEBSERVICE_WSDL_URL = 'http://www.cendris.nl/webservices/services/soap_rpcenc?wsdl';
45
+
46
+ /**
47
+ * Calls a webservice method
48
+ *
49
+ * @param string $method The method that will be called
50
+ * @param array $soapParams An array of parameters to be sent
51
+ *
52
+ * @throws Exception
53
+ * @throws SoapFault
54
+ *
55
+ * @return object
56
+ */
57
+ public function call($method, $soapParams)
58
+ {
59
+ try {
60
+ $wsdl = self::WEBSERVICE_WSDL_URL;
61
+
62
+ /**
63
+ * Array of soap options used when connecting to the webservice
64
+ */
65
+ $soapOptions = array(
66
+ 'soap_version' => SOAP_1_1,
67
+ 'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
68
+ );
69
+
70
+ /**
71
+ * try to create a new Zend_Soap_Client instance based on the supplied wsdl. if it fails, try again without using the
72
+ * wsdl cache.
73
+ */
74
+ try {
75
+ $client = new Zend_Soap_Client(
76
+ $wsdl,
77
+ $soapOptions
78
+ );
79
+ } catch (Exception $e) {
80
+ /**
81
+ * Disable wsdl cache and try again
82
+ */
83
+ $soapOptions['cache_wsdl'] = WSDL_CACHE_NONE;
84
+
85
+ $client = new Zend_Soap_Client(
86
+ $wsdl,
87
+ $soapOptions
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Call the SOAP method
93
+ */
94
+ $response = $client->__call(
95
+ $method,
96
+ $soapParams
97
+ );
98
+
99
+ Mage::helper('postnl/addressValidation')->logCendrisCall($client);
100
+ return $response;
101
+ } catch(SoapFault $e) {
102
+ /**
103
+ * Log a possible SoapFault exception.
104
+ */
105
+ if (!isset($client)) {
106
+ $client = false;
107
+ }
108
+ Mage::helper('postnl/addressValidation')->logCendrisException($e, $client);
109
+
110
+ throw $e;
111
+ }
112
+ }
113
+ }
app/code/community/TIG/PostNL/Model/AddressValidation/Observer/AddressBook.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasAddressBlockClass()
40
+ * @method TIG_PostNL_Model_AddressValidation_Observer_AddressBook setAddressBlockClass(string $value)
41
+ */
42
+ class TIG_PostNL_Model_AddressValidation_Observer_AddressBook extends Varien_Object
43
+ {
44
+ /**
45
+ * The block class that we want to edit
46
+ */
47
+ const ADDRESS_COMMUNITY_BLOCK_NAME = 'customer/address_edit';
48
+
49
+ /**
50
+ * Current environment for the postcode check
51
+ */
52
+ const POSTCODECHECK_ENV = 'addressbook';
53
+
54
+ /**
55
+ * Gets the classname for the addressbook block that we want to edit.
56
+ *
57
+ * @return string
58
+ */
59
+ public function getAddressBlockClass()
60
+ {
61
+ if ($this->hasAddressBlockClass()) {
62
+ return $this->_getData('address_block_class');
63
+ }
64
+
65
+ $blockClass = Mage::getConfig()->getBlockClassName(self::ADDRESS_COMMUNITY_BLOCK_NAME);
66
+
67
+ $this->setAddressBlockClass($blockClass);
68
+ return $blockClass;
69
+ }
70
+
71
+ /**
72
+ * Alters the template of the onepage checkout billing address block if the postcode check functionality is active.
73
+ *
74
+ * @param Varien_Event_Observer $observer
75
+ *
76
+ * @return TIG_PostNL_Model_AddressValidation_Observer_AddressBook
77
+ *
78
+ * @event core_block_abstract_to_html_before
79
+ *
80
+ * @observer checkout_onepage_billing_postcodecheck
81
+ *
82
+ */
83
+ public function addressBookPostcodeCheck(Varien_Event_Observer $observer)
84
+ {
85
+ /**
86
+ * Check if the extension is active
87
+ */
88
+ if (!Mage::helper('postnl/addressValidation')->isPostcodeCheckEnabled(null, self::POSTCODECHECK_ENV)) {
89
+ return $this;
90
+ }
91
+
92
+ /**
93
+ * Checks if the current block is the one we want to edit.
94
+ *
95
+ * Unfortunately there is no unique event for this block.
96
+ *
97
+ * @var Mage_Customer_Block_Address_Edit $block
98
+ */
99
+ $block = $observer->getBlock();
100
+ $blockClass = $this->getAddressBlockClass();
101
+
102
+ if (get_class($block) !== $blockClass) {
103
+ return $this;
104
+ }
105
+
106
+ $block->setTemplate('TIG/PostNL/address_validation/customer/address/edit.phtml');
107
+
108
+ return $this;
109
+ }
110
+ }
app/code/community/TIG/PostNL/Model/AddressValidation/Observer/OneStepCheckout.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasAddressBlockClass()
40
+ * @method TIG_PostNL_Model_AddressValidation_Observer_OneStepCheckout setAddressBlockClass(string $value)
41
+ */
42
+ class TIG_PostNL_Model_AddressValidation_Observer_OneStepCheckout extends Varien_Object
43
+ {
44
+ /**
45
+ * The block class that we want to edit
46
+ */
47
+ const ADDRESS_BLOCK_NAME = 'onestepcheckout/fields';
48
+
49
+ /**
50
+ * Block aliases used by OneStepCheckout.
51
+ *
52
+ * We use these to determine whether the block is for the billing or shipping address.
53
+ */
54
+ const BILLING_ADDRESS_BLOCK_ALIAS = 'billing_address';
55
+ const SHIPPING_ADDRESS_BLOCK_ALIAS = 'shipping_address';
56
+
57
+ /**
58
+ * Current environment for the postcode check
59
+ */
60
+ const POSTCODECHECK_ENV = 'checkout';
61
+
62
+ /**
63
+ * Gets the classname for the address block that we want to edit
64
+ *
65
+ * @return string
66
+ */
67
+ public function getAddressBlockClass()
68
+ {
69
+ if ($this->hasAddressBlockClass()) {
70
+ return $this->_getData('address_block_class');
71
+ }
72
+
73
+ $blockClass = Mage::getConfig()->getBlockClassName(self::ADDRESS_BLOCK_NAME);
74
+
75
+ $this->setAddressBlockClass($blockClass);
76
+ return $blockClass;
77
+ }
78
+
79
+ /**
80
+ * Alters the template of the OneStepCheckout address block if the postcode check functionality is active.
81
+ *
82
+ * @param Varien_Event_Observer $observer
83
+ *
84
+ * @return TIG_PostNL_Model_AddressValidation_Observer_OneStepCheckout
85
+ *
86
+ * @event core_block_abstract_to_html_before
87
+ *
88
+ * @observer customer_address_edit_postcodecheck
89
+ */
90
+ public function addressPostcodeCheck(Varien_Event_Observer $observer)
91
+ {
92
+ /**
93
+ * Check if the extension is active
94
+ */
95
+ if (!Mage::helper('postnl/addressValidation')->isPostcodeCheckEnabled(null, self::POSTCODECHECK_ENV)) {
96
+ return $this;
97
+ }
98
+
99
+ /**
100
+ * Checks if the current block is the one we want to edit.
101
+ *
102
+ * Unfortunately there is no unique event for this block.
103
+ *
104
+ * @var Idev_OneStepCheckout_Block_Fields $block
105
+ */
106
+ $block = $observer->getBlock();
107
+ $blockClass = $this->getAddressBlockClass();
108
+
109
+ if (get_class($block) !== $blockClass) {
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * Get the blocks alias and alter it's template based on this
115
+ */
116
+ $blockAlias = $block->getBlockAlias();
117
+ switch ($blockAlias) {
118
+ case self::BILLING_ADDRESS_BLOCK_ALIAS:
119
+ $block->setTemplate('TIG/PostNL/address_validation/onestepcheckout/billing_fields.phtml');
120
+ break;
121
+ case self::SHIPPING_ADDRESS_BLOCK_ALIAS:
122
+ $block->setTemplate('TIG/PostNL/address_validation/onestepcheckout/shipping_fields.phtml');
123
+ break;
124
+ //no default
125
+ }
126
+
127
+ return $this;
128
+ }
129
+ }
app/code/community/TIG/PostNL/Model/AddressValidation/Observer/Onepage.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasBillingAddressBlockClass()
40
+ * @method TIG_PostNL_Model_AddressValidation_Observer_Onepage setBillingAddressBlockClass(string $value)
41
+ * @method boolean hasShippingAddressBlockClass()
42
+ * @method TIG_PostNL_Model_AddressValidation_Observer_Onepage setShippingAddressBlockClass(string $value)
43
+ */
44
+ class TIG_PostNL_Model_AddressValidation_Observer_Onepage extends Varien_Object
45
+ {
46
+ /**
47
+ * The block classes that we want to edit
48
+ */
49
+ const BILLING_ADDRESS_BLOCK_NAME = 'checkout/onepage_billing';
50
+ const SHIPPING_ADDRESS_BLOCK_NAME = 'checkout/onepage_shipping';
51
+
52
+ /**
53
+ * Current environment for the postcode check
54
+ */
55
+ const POSTCODECHECK_ENV = 'checkout';
56
+
57
+ /**
58
+ * Gets the classname for the onepage checkout billing address block that we want to alter
59
+ *
60
+ * @return string
61
+ */
62
+ public function getBillingAddressBlockClass()
63
+ {
64
+ if ($this->hasBillingAddressBlockClass()) {
65
+ return $this->_getData('billing_address_block_class');
66
+ }
67
+
68
+ $blockClass = Mage::getConfig()->getBlockClassName(self::BILLING_ADDRESS_BLOCK_NAME);
69
+
70
+ $this->setBillingAddressBlockClass($blockClass);
71
+ return $blockClass;
72
+ }
73
+
74
+ /**
75
+ * Gets the classname for the onepage checkout shipping address block that we want to alter
76
+ *
77
+ * @return string
78
+ */
79
+ public function getShippingAddressBlockClass()
80
+ {
81
+ if ($this->hasShippingAddressBlockClass()) {
82
+ return $this->_getData('shipping_address_block_class');
83
+ }
84
+
85
+ $blockClass = Mage::getConfig()->getBlockClassName(self::SHIPPING_ADDRESS_BLOCK_NAME);
86
+
87
+ $this->setShippingAddressBlockClass($blockClass);
88
+ return $blockClass;
89
+ }
90
+
91
+ /**
92
+ * Alters the template of the onepage checkout billing address block if the postcode check functionality is active.
93
+ *
94
+ * @param Varien_Event_Observer $observer
95
+ *
96
+ * @return TIG_PostNL_Model_AddressValidation_Observer_Onepage
97
+ *
98
+ * @event core_block_abstract_to_html_before
99
+ *
100
+ * @observer checkout_onepage_billing_postcodecheck
101
+ *
102
+ */
103
+ public function billingAddressPostcodeCheck(Varien_Event_Observer $observer)
104
+ {
105
+ /**
106
+ * Check if the extension is active
107
+ */
108
+ if (!Mage::helper('postnl/addressValidation')->isPostcodeCheckEnabled(null, self::POSTCODECHECK_ENV)) {
109
+ return $this;
110
+ }
111
+
112
+ /**
113
+ * Checks if the current block is the one we want to edit.
114
+ *
115
+ * Unfortunately there is no unique event for this block.
116
+ *
117
+ * @var Mage_Checkout_Block_Onepage_Billing $block
118
+ */
119
+ $block = $observer->getBlock();
120
+ $blockClass = $this->getBillingAddressBlockClass();
121
+
122
+ if (get_class($block) !== $blockClass) {
123
+ return $this;
124
+ }
125
+
126
+ $block->setTemplate('TIG/PostNL/address_validation/checkout/onepage/billing.phtml');
127
+
128
+ return $this;
129
+ }
130
+
131
+ /**
132
+ * Alters the template of the onepage checkout shipping address block if the postcode check functionality is active.
133
+ *
134
+ * @param Varien_Event_Observer $observer
135
+ *
136
+ * @return TIG_PostNL_Model_AddressValidation_Observer_Onepage
137
+ *
138
+ * @event core_block_abstract_to_html_before
139
+ *
140
+ * @observer checkout_onepage_shipping_postcodecheck
141
+ *
142
+ */
143
+ public function shippingAddressPostcodeCheck(Varien_Event_Observer $observer)
144
+ {
145
+ /**
146
+ * Check if the extension is active
147
+ */
148
+ if (!Mage::helper('postnl/addressValidation')->isPostcodeCheckEnabled(null, self::POSTCODECHECK_ENV)) {
149
+ return $this;
150
+ }
151
+
152
+ /**
153
+ * Checks if the current block is the one we want to edit.
154
+ *
155
+ * Unfortunately there is no unique event for this block.
156
+ *
157
+ * @var Mage_Checkout_Block_Onepage_Shipping $block
158
+ */
159
+ $block = $observer->getBlock();
160
+ $blockClass = $this->getShippingAddressBlockClass();
161
+
162
+ if (get_class($block) !== $blockClass) {
163
+ return $this;
164
+ }
165
+
166
+ $block->setTemplate('TIG/PostNL/address_validation/checkout/onepage/shipping.phtml');
167
+
168
+ return $this;
169
+ }
170
+ }
app/code/community/TIG/PostNL/Model/AddressValidation/System/Config/Backend/ValidateAccount.php ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_AddressValidation_System_Config_Backend_ValidateAccount extends Mage_Core_Model_Config_Data
40
+ {
41
+ /**
42
+ * Xpaths used to get PostNL account credentials.
43
+ */
44
+ const XPATH_MODE = 'postnl/cif/mode';
45
+ const XPATH_LIVE_USERNAME = 'postnl/cif/live_username';
46
+ const XPATH_LIVE_PASSWORD = 'postnl/cif/live_password';
47
+ const XPATH_TEST_USERNAME = 'postnl/cif/test_username';
48
+ const XPATH_TEST_PASSWORD = 'postnl/cif/test_password';
49
+ const XPATH_CUSTOMER_NUMBER = 'postnl/cif/customer_number';
50
+ const XPATH_CUSTOMER_CODE = 'postnl/cif/customer_code';
51
+ const XPATH_COLLECTION_LOCATION = 'postnl/cif/collection_location';
52
+
53
+ /**
54
+ * Gets the store ID based on the current store scope.
55
+ *
56
+ * @return int
57
+ */
58
+ public function getStoreId()
59
+ {
60
+ if ($this->hasStoreId()) {
61
+ return $this->getData('store_id');
62
+ }
63
+
64
+ $storeCode = $this->getStoreCode();
65
+ $storeId = Mage::getModel('core/store')->load($storeCode, 'code')->getId();
66
+
67
+ $this->setStoreId($storeId);
68
+ return $storeId;
69
+ }
70
+
71
+ /**
72
+ * Gets an instance of the current website scope.
73
+ *
74
+ * @return Mage_Core_Model_Website
75
+ */
76
+ public function getWebsite()
77
+ {
78
+ if ($this->hasWebsite()) {
79
+ return $this->getData('website');
80
+ }
81
+
82
+ $websiteCode = $this->getWebsiteCode();
83
+ $website = Mage::getModel('core/website')->load($websiteCode, 'code');
84
+
85
+ $this->setWebsite($website);
86
+ return $website;
87
+ }
88
+
89
+ /**
90
+ * Check that PostNL account settings have been entered and are valid before saving this field.
91
+ *
92
+ * @throws TIG_PostNL_Exception
93
+ *
94
+ * @return Mage_Core_Model_Abstract
95
+ *
96
+ * @see Mage_Core_Model_Abstract::_beforeSave()
97
+ */
98
+ protected function _beforeSave()
99
+ {
100
+ /**
101
+ * If the value has not changed, we don't have to do anything.
102
+ */
103
+ if (!$this->isValueChanged()) {
104
+ return parent::_beforeSave();
105
+ }
106
+
107
+ /**
108
+ * If the setting has been disabled we also don't have to do anything.
109
+ */
110
+ if (!$this->getValue()) {
111
+ return parent::_beforeSave();
112
+ }
113
+
114
+ /**
115
+ * Check whether the extension is set to test mode and get the username and password for that mode.
116
+ */
117
+ $testMode = $this->_getIsTestMode();
118
+ if ($testMode) {
119
+ $username = $this->_getConfigValue(self::XPATH_TEST_USERNAME);
120
+ $password = $this->_getConfigValue(self::XPATH_TEST_PASSWORD);
121
+ } else {
122
+ $username = $this->_getConfigValue(self::XPATH_LIVE_USERNAME);
123
+ $password = $this->_getConfigValue(self::XPATH_LIVE_PASSWORD);
124
+ }
125
+
126
+ /**
127
+ * Get other PostNL account settings.
128
+ */
129
+ $customerNumber = $this->_getConfigValue(self::XPATH_CUSTOMER_NUMBER);
130
+ $customerCode = $this->_getConfigValue(self::XPATH_CUSTOMER_CODE);
131
+ $locationCode = $this->_getConfigValue(self::XPATH_COLLECTION_LOCATION);
132
+
133
+ /**
134
+ * Decrypt and then hash the password.
135
+ */
136
+ $password = trim($password);
137
+ $password = sha1(Mage::helper('core')->decrypt($password));
138
+
139
+ /**
140
+ * Put all credentials into an array.
141
+ */
142
+ $data = array(
143
+ 'password' => $password,
144
+ 'username' => $username,
145
+ 'customerNumber' => $customerNumber,
146
+ 'customerCode' => $customerCode,
147
+ 'locationCode' => $locationCode,
148
+ );
149
+
150
+ /**
151
+ * Load the CIF model and set to test mode to false
152
+ */
153
+ $cif = Mage::getModel('postnl_core/cif')
154
+ ->setTestMode($testMode);
155
+
156
+ /**
157
+ * Attempt to generate a barcode to test the account settings. This will result in an exception if the settings
158
+ * are invalid.
159
+ */
160
+ try {
161
+ $response = $cif->generateBarcodePing($data);
162
+ } catch (Exception $e) {
163
+ $errorMessage = $this->_getErrorMessage();
164
+
165
+ throw new TIG_PostNL_Exception($errorMessage, 'POSTNL-0114');
166
+ }
167
+
168
+ /**
169
+ * The result should be a barcode.
170
+ */
171
+ if (!is_string($response)) {
172
+ $errorMessage = $this->_getErrorMessage();
173
+
174
+ throw new TIG_PostNL_Exception($errorMessage, 'POSTNL-0114');
175
+ }
176
+
177
+ return parent::_beforeSave();
178
+ }
179
+
180
+ /**
181
+ * gets whether the extension is set to test mode.
182
+ *
183
+ * @return boolean
184
+ */
185
+ protected function _getIsTestMode()
186
+ {
187
+ $cifTestMode = (bool) $this->_getConfigValue(self::XPATH_MODE);
188
+
189
+ return $cifTestMode;
190
+ }
191
+
192
+ /**
193
+ * Gets a config value. First we try to get the value from the fields we are currently trying to save. if the path
194
+ * is not among the fields we're saving, get it from the database for the current scope.
195
+ *
196
+ * @param string $path An xpath to the setting we're trying to retreive
197
+ *
198
+ * @return string|null
199
+ *
200
+ * @throws InvalidArgumentException
201
+ */
202
+ protected function _getConfigValue($path)
203
+ {
204
+ $groups = $this->getGroups();
205
+ $pathParts = explode('/', $path);
206
+ if (count($pathParts) !== 3) {
207
+ throw new InvalidArgumentException(
208
+ 'Invalid argument: $path should be a valid xpath.'
209
+ );
210
+ }
211
+
212
+ /**
213
+ * Check if the value is among the fields we're currently saving.
214
+ *
215
+ * In the case of password fields, the value '******' might be used. This is not a valid value and should be
216
+ * ignored.
217
+ */
218
+ if (isset($groups[$pathParts[1]]['fields'][$pathParts[2]]['value'])
219
+ && $groups[$pathParts[1]]['fields'][$pathParts[2]]['value'] != '******'
220
+ ) {
221
+ return $groups[$pathParts[1]]['fields'][$pathParts[2]]['value'];
222
+ }
223
+
224
+ /**
225
+ * Get the value based on the current scope.
226
+ */
227
+ $scope = $this->getScope();
228
+ switch ($scope) {
229
+ case 'stores':
230
+ $storeId = $this->getStoreId();
231
+ $value = Mage::getStoreConfig($path, $storeId);
232
+ break;
233
+ case 'websites':
234
+ $website = $this->getWebsite();
235
+ $value = $website->getConfig($path);
236
+ break;
237
+ default:
238
+ $value = Mage::getStoreConfig($path, Mage_Core_Model_App::ADMIN_STORE_ID);
239
+ break;
240
+ }
241
+
242
+ return $value;
243
+ }
244
+
245
+ /**
246
+ * Get the error message in case the PostNL account credentials could not be validated. Normally the controller
247
+ * would catch an exception and parse it to create this message, however we have no control over the system_config
248
+ * controller, so we need to format the message in advance.
249
+ *
250
+ * @return string
251
+ */
252
+ protected function _getErrorMessage()
253
+ {
254
+ $helper = Mage::helper('postnl');
255
+
256
+ /**
257
+ * Get the error from the extension's config.xml
258
+ */
259
+ $error = Mage::getConfig()->getNode('tig/errors/POSTNL-0114');
260
+ $link = (string) $error->url;
261
+
262
+ /**
263
+ * Form the base error message.
264
+ */
265
+ $errorMessage = '[PostNL-0114] ';
266
+ $errorMessage .= $helper->__(
267
+ 'Your PostNL account credentials could not be validated.'
268
+ . ' Please enter valid PostNL account credentials before activating the postcode check functionality.'
269
+ );
270
+
271
+ /**
272
+ * Append a link to the TiG knowledgebase if available.
273
+ */
274
+ if ($link) {
275
+ $errorMessage .= ' <a href="'
276
+ . $link
277
+ . '" target="_blank" class="postnl-message">'
278
+ . $helper->__('Click here for more information from the TiG knowledgebase.')
279
+ . '</a>';
280
+ }
281
+
282
+ return $errorMessage;
283
+ }
284
+ }
app/code/community/TIG/PostNL/Model/Admin/Logging/Handler/Postnl.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_Admin_Logging_Handler_Postnl extends Enterprise_Logging_Model_Handler_Controllers
40
+ {
41
+ /**
42
+ * PostNL mass action postDispatch handler.
43
+ *
44
+ * @param Varien_Simplexml_Element $config
45
+ * @param Enterprise_Logging_Model_Event $eventModel
46
+ *
47
+ * @return boolean
48
+ */
49
+ public function postDispatchSaveMassAction($config, $eventModel)
50
+ {
51
+ $request = Mage::app()->getRequest();
52
+ if ($request->getParam('shipment_ids')) {
53
+ $eventModel->setInfo($request->getParam('shipment_ids'));
54
+
55
+ return true;
56
+ }
57
+
58
+ if ($request->getParam('order_ids')) {
59
+ $eventModel->setInfo($request->getParam('order_ids'));
60
+
61
+ return true;
62
+ }
63
+
64
+ return true;
65
+ }
66
+ }
app/code/community/TIG/PostNL/Model/Admin/Logging/Observer.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_Admin_Logging_Observer
40
+ {
41
+ /**
42
+ * Check if the Enterprise Logging extension is present and if so, call it's observer method. This prevents errors
43
+ * in Magento community edition.
44
+ *
45
+ * @param Varien_Event_Observer $observer
46
+ *
47
+ * @return $this
48
+ *
49
+ * @see Enterprise_Logging_Model_Observer::controllerPostdispatch()
50
+ */
51
+ public function controllerPostdispatch(Varien_Event_Observer $observer)
52
+ {
53
+ $loggingObserverClassName = Mage::getConfig()->getModelClassName('enterprise_logging/observer');
54
+ $found = mageFindClassFile($loggingObserverClassName);
55
+
56
+ /**
57
+ * If we can't find the model, there's nothing that can be logged.
58
+ */
59
+ if ($found === false) {
60
+ return $this;
61
+ }
62
+
63
+ Mage::getModel('enterprise_logging/observer')->controllerPostdispatch($observer);
64
+
65
+ return $this;
66
+ }
67
+ }
app/code/community/TIG/PostNL/Model/Adminhtml/Observer/OrderGrid.php CHANGED
@@ -33,15 +33,15 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  *
39
  * Observer to edit the sales > order grid
40
  *
41
- * @method TIG_PostNL_Model_Adminhtml_Observer_OrderGrid setCollection(Varien_Data_Collection $value)
42
- * @method Varien_Data_Collection getCollection()
43
- * @method TIG_PostNL_Model_Adminhtml_Observer_OrderGrid setBlock(Mage_Core_Block_Abstract $value)
44
- * @method Mage_Core_Block_Abstract getBlock()
45
  */
46
  class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
47
  {
@@ -177,10 +177,12 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
177
  * Join tig_postnl_order table
178
  */
179
  $select->joinLeft(
180
- array('postnl_order' => $resource->getTableName('postnl_checkout/order')),
181
  '`main_table`.`entity_id`=`postnl_order`.`order_id`',
182
  array(
183
- 'is_pakje_gemak' => 'postnl_order.is_pakje_gemak',
 
 
184
  )
185
  );
186
 
@@ -264,14 +266,17 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
264
  'index' => 'country_id',
265
  'type' => 'options',
266
  'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_shipmentType',
267
- 'width' => '0px',
268
  'filter_condition_callback' => array($this, '_filterShipmentType'),
269
  'sortable' => false,
270
  'options' => array(
271
- 'nl' => $helper->__('Domestic'),
272
- 'pakje_gemak' => $helper->__('Post Office'),
273
- 'eu' => $helper->__('EPS'),
274
- 'global' => $helper->__('GlobalPack'),
 
 
 
275
  ),
276
  );
277
 
@@ -309,12 +314,21 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
309
  */
310
  protected function _addMassaction($block)
311
  {
 
 
 
 
 
 
 
 
 
312
  /**
313
  * Build an array of options for the massaction item
314
  */
315
  $massActionData = array(
316
- 'label'=> Mage::helper('postnl')->__('PostNL - Create Shipments'),
317
- 'url' => Mage::helper('adminhtml')->getUrl('postnl/adminhtml_shipment/massCreateShipments'),
318
  );
319
 
320
  $showOptions = Mage::getStoreConfig(self::XML_PATH_SHOW_OPTIONS, Mage_Core_Model_App::ADMIN_STORE_ID);
@@ -328,9 +342,9 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
328
  'name' => 'product_options',
329
  'type' => 'select',
330
  'class' => 'required-entry',
331
- 'label' => Mage::helper('postnl')->__('Product options'),
332
  'values' => Mage::getModel('postnl_core/system_config_source_allProductOptions')
333
- ->getAvailableOptions(true, true),
334
  ),
335
  );
336
  }
@@ -350,7 +364,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
350
  /**
351
  * Applies sorting and filtering to the collection
352
  *
353
- * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
354
  *
355
  * @return $this
356
  */
@@ -417,20 +431,78 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
417
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
418
  $collection->addFieldToFilter('order.shipping_method', array('in' => $postnlShippingMethods));
419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  /**
421
  * If the filter condition is PakjeGemak, filter out all non-PakjeGemak orders
422
  */
423
  if ($filterCond == 'pakje_gemak') {
424
  $collection->addFieldToFilter('is_pakje_gemak', array('eq' => 1));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
 
426
  return $this;
427
  }
428
 
429
  /**
430
- * If the filter condition is NL, filter out all orders not being shipped to the Netherlands
 
 
431
  */
432
  if ($filterCond == 'nl') {
433
  $collection->addFieldToFilter('country_id', $cond);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
 
435
  return $this;
436
  }
@@ -480,7 +552,11 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
480
 
481
  $cond = $column->getFilter()->getCondition();
482
  if ($field && isset($cond)) {
483
- $this->getCollection()->addFieldToFilter($field , $cond);
 
 
 
 
484
  }
485
 
486
  return $this;
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  *
39
  * Observer to edit the sales > order grid
40
  *
41
+ * @method TIG_PostNL_Model_Adminhtml_Observer_OrderGrid setCollection(TIG_PostNL_Model_Resource_Order_Grid_Collection $value)
42
+ * @method TIG_PostNL_Model_Resource_Order_Grid_Collection getCollection()
43
+ * @method TIG_PostNL_Model_Adminhtml_Observer_OrderGrid setBlock(Mage_Adminhtml_Block_Sales_Order_Grid $value)
44
+ * @method Mage_Adminhtml_Block_Sales_Order_Grid getBlock()
45
  */
46
  class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
47
  {
177
  * Join tig_postnl_order table
178
  */
179
  $select->joinLeft(
180
+ array('postnl_order' => $resource->getTableName('postnl_core/order')),
181
  '`main_table`.`entity_id`=`postnl_order`.`order_id`',
182
  array(
183
+ 'is_pakje_gemak' => 'postnl_order.is_pakje_gemak',
184
+ 'is_pakketautomaat' => 'postnl_order.is_pakketautomaat',
185
+ 'delivery_option_type' => 'postnl_order.type',
186
  )
187
  );
188
 
266
  'index' => 'country_id',
267
  'type' => 'options',
268
  'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_shipmentType',
269
+ 'width' => '110px',
270
  'filter_condition_callback' => array($this, '_filterShipmentType'),
271
  'sortable' => false,
272
  'options' => array(
273
+ 'nl' => $helper->__('Domestic'),
274
+ 'pakje_gemak' => $helper->__('Post Office'),
275
+ 'eu' => $helper->__('EPS'),
276
+ 'global' => $helper->__('GlobalPack'),
277
+ 'pakketautomaat' => $helper->__('Parcel Dispenser'),
278
+ 'avond' => $helper->__('Evening Delivery'),
279
+ 'pakje_gemak_express' => $helper->__('Early Pickup'),
280
  ),
281
  );
282
 
314
  */
315
  protected function _addMassaction($block)
316
  {
317
+ $helper = Mage::helper('postnl');
318
+
319
+ /**
320
+ * Make sure the admin is allowed ship orders.
321
+ */
322
+ if (!$helper->checkIsPostnlActionAllowed('create_shipment')) {
323
+ return $this;
324
+ }
325
+
326
  /**
327
  * Build an array of options for the massaction item
328
  */
329
  $massActionData = array(
330
+ 'label'=> $helper->__('PostNL - Create Shipments'),
331
+ 'url' => Mage::helper('adminhtml')->getUrl('postnl_admin/adminhtml_shipment/massCreateShipments'),
332
  );
333
 
334
  $showOptions = Mage::getStoreConfig(self::XML_PATH_SHOW_OPTIONS, Mage_Core_Model_App::ADMIN_STORE_ID);
342
  'name' => 'product_options',
343
  'type' => 'select',
344
  'class' => 'required-entry',
345
+ 'label' => $helper->__('Product options'),
346
  'values' => Mage::getModel('postnl_core/system_config_source_allProductOptions')
347
+ ->getAvailableOptions(true, true, false, false, false, true, true),
348
  ),
349
  );
350
  }
364
  /**
365
  * Applies sorting and filtering to the collection
366
  *
367
+ * @param TIG_PostNL_Model_Resource_Order_Grid_Collection $collection
368
  *
369
  * @return $this
370
  */
431
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
432
  $collection->addFieldToFilter('order.shipping_method', array('in' => $postnlShippingMethods));
433
 
434
+ /**
435
+ * If the filter condition is PakjeGemak Express, filter out all non-PakjeGemak Express orders
436
+ */
437
+ if ($filterCond == 'pakje_gemak_express') {
438
+ $collection->addFieldToFilter('postnl_order.type', array('eq' => 'PGE'));
439
+
440
+ return $this;
441
+ }
442
+
443
+ /**
444
+ * If the filter condition is evening delivery, filter out all other orders
445
+ */
446
+ if ($filterCond == 'avond') {
447
+ $collection->addFieldToFilter('postnl_order.type', array('eq' => 'Avond'));
448
+
449
+ return $this;
450
+ }
451
+
452
  /**
453
  * If the filter condition is PakjeGemak, filter out all non-PakjeGemak orders
454
  */
455
  if ($filterCond == 'pakje_gemak') {
456
  $collection->addFieldToFilter('is_pakje_gemak', array('eq' => 1));
457
+ $collection->addFieldToFilter('postnl_order.type', array(array('eq' => 'PG'), array('null' => true)));
458
+
459
+ return $this;
460
+ }
461
+
462
+ /**
463
+ * If the filter condition is Pakket Automaat, filter out all non-Pakket Automaat orders
464
+ */
465
+ if ($filterCond == 'pakketautomaat') {
466
+ $collection->addFieldToFilter('is_pakketautomaat', array('eq' => 1));
467
+ $collection->addFieldToFilter(
468
+ 'postnl_order.type',
469
+ array(
470
+ array('eq' => 'PA'),
471
+ array('null' => true)
472
+ )
473
+ );
474
 
475
  return $this;
476
  }
477
 
478
  /**
479
+ * If the filter condition is NL, filter out all orders not being shipped to the Netherlands. PakjeGemak,
480
+ * PakjeGmak Express, evening delivery and pakketautomaat shipments are also shipped to the Netherlands so we
481
+ * need to explicitely filter those as well.
482
  */
483
  if ($filterCond == 'nl') {
484
  $collection->addFieldToFilter('country_id', $cond);
485
+ $collection->addFieldToFilter(
486
+ 'postnl_order.type',
487
+ array(
488
+ array('eq' => 'Overdag'),
489
+ array('null' => true)
490
+ )
491
+ );
492
+ $collection->addFieldToFilter(
493
+ 'is_pakje_gemak',
494
+ array(
495
+ array('eq' => 0),
496
+ array('null' => true)
497
+ )
498
+ );
499
+ $collection->addFieldToFilter(
500
+ 'is_pakketautomaat',
501
+ array(
502
+ array('eq' => 0),
503
+ array('null' => true)
504
+ )
505
+ );
506
 
507
  return $this;
508
  }
552
 
553
  $cond = $column->getFilter()->getCondition();
554
  if ($field && isset($cond)) {
555
+ /**
556
+ * @var TIG_PostNL_Model_Resource_Order_Grid_Collection $collection
557
+ */
558
+ $collection = $this->getCollection();
559
+ $collection->addFieldToFilter($field , $cond);
560
  }
561
 
562
  return $this;
app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentGrid.php CHANGED
@@ -33,10 +33,17 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  *
39
  * Observer to edit the sales > shipments grid
 
 
 
 
 
 
 
40
  */
41
  class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
42
  {
@@ -70,10 +77,15 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
70
  */
71
  const XML_PATH_SHIPPING_GRID_MASSACTION_DEFAULT = 'postnl/cif_labels_and_confirming/shipping_grid_massaction_default';
72
 
 
 
 
 
 
73
  /**
74
  * Gets an array of optional columns to display
75
  *
76
- * @return boolean
77
  */
78
  public function getOptionalColumnsToDisplay()
79
  {
@@ -85,6 +97,23 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
85
  return $columnsToDisplay;
86
  }
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  /**
89
  * Observer that adds columns to the grid and allows these to be sorted and filtered properly
90
  *
@@ -115,18 +144,20 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
115
  $block = $observer->getBlock();
116
  $shipmentGridClass = Mage::getConfig()->getBlockClassName(self::SHIPMENT_GRID_BLOCK_NAME);
117
 
118
- if (get_class($block) !== $shipmentGridClass) {
119
  return $this;
120
  }
121
 
 
 
 
 
122
  $currentCollection = $block->getCollection();
123
  $select = $currentCollection->getSelect()->reset(Zend_Db_Select::WHERE);
124
 
125
  /**
126
  * replace the collection as the default collection has a bug preventing it from being reset.
127
- * Without being able to reset it, we can't edit it. Therefore we are forced to replace it altogether
128
- *
129
- * TODO see if this can be avoided in any way
130
  */
131
  $collection = Mage::getResourceModel('postnl/order_shipment_grid_collection');
132
  $collection->setSelect($select)
@@ -190,12 +221,15 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
190
  array('postnl_shipment' => $resource->getTableName('postnl_core/shipment')),
191
  '`main_table`.`entity_id`=`postnl_shipment`.`shipment_id`',
192
  array(
193
- 'confirm_date' => 'postnl_shipment.confirm_date',
194
- 'main_barcode' => 'postnl_shipment.main_barcode',
195
- 'confirm_status' => 'postnl_shipment.confirm_status',
196
- 'labels_printed' => 'postnl_shipment.labels_printed',
197
- 'shipping_phase' => 'postnl_shipment.shipping_phase',
198
- 'parcel_count' => 'postnl_shipment.parcel_count',
 
 
 
199
  )
200
  );
201
 
@@ -203,10 +237,13 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
203
  * Join tig_postnl_order table
204
  */
205
  $select->joinLeft(
206
- array('postnl_order' => $resource->getTableName('postnl_checkout/order')),
207
  '`main_table`.`order_id`=`postnl_order`.`order_id`',
208
  array(
209
- 'is_pakje_gemak' => 'postnl_order.is_pakje_gemak',
 
 
 
210
  )
211
  );
212
 
@@ -276,9 +313,13 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
276
  $block->addColumnAfter(
277
  'shipping_description',
278
  array(
279
- 'header' => $helper->__('Shipping Method'),
280
- 'align' => 'left',
281
- 'index' => 'shipping_description',
 
 
 
 
282
  ),
283
  $after
284
  );
@@ -299,10 +340,13 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
299
  'filter_condition_callback' => array($this, '_filterShipmentType'),
300
  'sortable' => false,
301
  'options' => array(
302
- 'nl' => $helper->__('Domestic'),
303
- 'pakje_gemak' => $helper->__('PakjeGemak'),
304
- 'eu' => $helper->__('EPS'),
305
- 'global' => $helper->__('GlobalPack'),
 
 
 
306
  ),
307
  ),
308
  $after
@@ -311,6 +355,40 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
311
  $after = 'shipment_type';
312
  }
313
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  if (in_array('confirm_date', $columnsToDisplay)) {
315
  $block->addColumnAfter(
316
  'confirm_date',
@@ -329,7 +407,28 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
329
  $after = 'confirm_date';
330
  }
331
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  if (in_array('confirm_status', $columnsToDisplay)) {
 
 
 
333
  $postnlShipmentClass = Mage::app()->getConfig()->getModelClassName('postnl_core/shipment');
334
 
335
  $block->addColumnAfter(
@@ -356,11 +455,11 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
356
  $block->addColumnAfter(
357
  'labels_printed',
358
  array(
359
- 'header' => $helper->__('Labels printed'),
360
  'type' => 'options',
361
  'index' => 'labels_printed',
362
  'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_yesNo',
363
- 'frame_callback' => array($this, 'decorateLabelsPrinted'),
364
  'options' => array(
365
  1 => $helper->__('Yes'),
366
  0 => $helper->__('No'),
@@ -372,6 +471,27 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
372
  $after = 'labels_printed';
373
  }
374
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  if (in_array('barcode', $columnsToDisplay)) {
376
  $block->addColumnAfter(
377
  'barcode',
@@ -408,19 +528,24 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
408
  $actionColumn = $block->getColumn('action');
409
  $actions = $actionColumn->getActions();
410
 
411
- $actions[] = array(
412
- 'caption' => $helper->__('Print label'),
413
- 'url' => array('base' => 'postnl/adminhtml_shipment/printLabel'),
414
- 'field' => 'shipment_id',
415
- 'is_postnl' => true, //custom flag for renderer
416
- );
 
 
417
 
418
- $actions[] = array(
419
- 'caption' => $helper->__('Confirm'),
420
- 'url' => array('base' => 'postnl/adminhtml_shipment/confirm'),
421
- 'field' => 'shipment_id',
422
- 'is_postnl' => true, //custom flag for renderer
423
- );
 
 
 
424
 
425
  $actionColumn->setActions($actions)
426
  ->setWidth('150px')
@@ -434,10 +559,10 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
434
  /**
435
  * Decorates the confirm_sate column
436
  *
437
- * @param string | null $value
438
- * @param Mage_Sales_Model_Order_Shipment $row
439
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
440
- * @param boolean $isExport
441
  *
442
  * @return string
443
  */
@@ -447,32 +572,54 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
447
  return $value;
448
  }
449
 
450
- $origValue = $row->getData($column->getIndex());
 
 
 
451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
453
 
454
- $class = '';
 
 
455
  if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
456
- $class = 'grid-severity-notice';
457
  }
458
 
459
  if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_CONFIRM_EXPIRED) {
460
- $class = 'grid-severity-critical';
461
  }
462
 
463
  if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED
464
- && date('Ymd', Mage::getModel('core/date')->gmtTimestamp()) == date('Ymd', strtotime($origValue))
465
  ) {
466
- $class = 'grid-severity-major';
467
- } elseif ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED
468
- && Mage::getModel('core/date')->gmtTimestamp() > strtotime($origValue)
 
 
469
  ) {
470
- $class = 'grid-severity-critical';
471
- } elseif ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED) {
472
- $class = 'grid-severity-minor';
473
  }
474
 
475
- return '<span class="'.$class.'"><span>'.$value.'</span></span>';
 
 
 
 
476
  }
477
 
478
  /**
@@ -491,6 +638,9 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
491
  return $value;
492
  }
493
 
 
 
 
494
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
495
  switch ($row->getData($column->getIndex())) {
496
  case null: //rows with no value (non-PostNL shipments)
@@ -520,7 +670,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
520
  *
521
  * @return string
522
  */
523
- public function decorateLabelsPrinted($value, $row, $column, $isExport)
524
  {
525
  if ($isExport) {
526
  return $value;
@@ -559,9 +709,11 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
559
  return $value;
560
  }
561
 
 
 
 
562
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
563
 
564
- $class = '';
565
  switch ($row->getData($column->getIndex())) {
566
  case null: //rows with no value (non-PostNL shipments) or unconfirmed shipments
567
  $class = '';
@@ -593,26 +745,58 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
593
  */
594
  protected function _addMassaction($block)
595
  {
 
 
 
596
  $massactionBlock = $block->getMassactionBlock();
597
 
598
  /**
599
  * Build all the mass action option arrays
600
  */
601
  $printAndConfirmOptions = array(
602
- 'label'=> Mage::helper('postnl')->__('PostNL - Print shipping labels & confirm shipment'),
603
- 'url' => Mage::helper('adminhtml')->getUrl('postnl/adminhtml_shipment/massPrintLabelsAndConfirm'),
604
  );
605
 
606
  $printOptions = array(
607
- 'label'=> Mage::helper('postnl')->__('PostNL - Print shipping labels'),
608
- 'url' => Mage::helper('adminhtml')->getUrl('postnl/adminhtml_shipment/massPrintLabels'),
609
  );
610
 
611
  $confirmOptions = array(
612
- 'label'=> Mage::helper('postnl')->__('PostNL - Confirm shipments'),
613
- 'url' => Mage::helper('adminhtml')->getUrl('postnl/adminhtml_shipment/massConfirm'),
 
 
 
 
 
614
  );
615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
  /**
617
  * Check which mass action should be selected by default
618
  */
@@ -634,26 +818,47 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
634
  case 'postnl_confirm_shipments':
635
  $confirmOptions['selected'] = true;
636
  break;
 
 
 
637
  // no default
638
  }
639
 
 
 
 
 
640
  /**
641
- * Add the mass actions to the grid
642
  */
643
- $massactionBlock->addItem(
644
- 'postnl_print_labels_and_confirm',
645
- $printAndConfirmOptions
646
- );
 
 
647
 
648
- $massactionBlock->addItem(
649
- 'postnl_print_labels',
650
- $printOptions
651
- );
 
 
652
 
653
- $massactionBlock->addItem(
654
- 'postnl_confirm_shipments',
655
- $confirmOptions
656
- );
 
 
 
 
 
 
 
 
 
 
657
 
658
  return $this;
659
  }
@@ -718,7 +923,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
718
  * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
719
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
720
  *
721
- * @return TIG_PostNL_Model_Adminhtml_Observer_OrderGrid
722
  */
723
  protected function _filterShipmentType($collection, $column)
724
  {
@@ -731,20 +936,78 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
731
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
732
  $collection->addFieldToFilter('order.shipping_method', array('in' => $postnlShippingMethods));
733
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
734
  /**
735
  * If the filter condition is PakjeGemak, filter out all non-PakjeGemak orders
736
  */
737
  if ($filterCond == 'pakje_gemak') {
738
- $collection->addFieldToFilter('postnl_shipment.is_pakje_gemak', array('eq' => 1));
 
739
 
740
  return $this;
741
  }
742
 
743
  /**
744
- * If the filter condition is NL, filter out all orders not being shipped to the Netherlands
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
745
  */
746
  if ($filterCond == 'nl') {
747
  $collection->addFieldToFilter('country_id', $cond);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
 
749
  return $this;
750
  }
@@ -762,7 +1025,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
762
  }
763
 
764
  /**
765
- * Lastly, filter out all orders that are being shipped to the Netherlands or other EU countries
766
  */
767
  $collection->addFieldToFilter('country_id', array('neq' => 'NL'));
768
  $collection->addFieldToFilter('country_id', array('nin' => $euCountries));
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  *
39
  * Observer to edit the sales > shipments grid
40
+ *
41
+ * @method TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid setCollection(Mage_Sales_Model_Resource_Order_Shipment_Collection $value)
42
+ * @method Mage_Sales_Model_Resource_Order_Shipment_Collection getCollection()
43
+ * @method TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid setBlock(Mage_Adminhtml_Block_Sales_Shipment_Grid $value)
44
+ * @method Mage_Adminhtml_Block_Sales_Shipment_Grid getBlock()
45
+ * @method TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid setLabelSize(string $value)
46
+ * @method boolean hasLabelSize()
47
  */
48
  class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
49
  {
77
  */
78
  const XML_PATH_SHIPPING_GRID_MASSACTION_DEFAULT = 'postnl/cif_labels_and_confirming/shipping_grid_massaction_default';
79
 
80
+ /**
81
+ * Xpath to label size setting.
82
+ */
83
+ const XPATH_LABEL_SIZE = 'postnl/cif_labels_and_confirming/label_size';
84
+
85
  /**
86
  * Gets an array of optional columns to display
87
  *
88
+ * @return array
89
  */
90
  public function getOptionalColumnsToDisplay()
91
  {
97
  return $columnsToDisplay;
98
  }
99
 
100
+ /**
101
+ * Get the configured label size.
102
+ *
103
+ * @return string
104
+ */
105
+ public function getLabelSize()
106
+ {
107
+ if ($this->hasLabelSize()) {
108
+ return $this->_getData('label_size');
109
+ }
110
+
111
+ $labelSize = Mage::getStoreConfig(self::XPATH_LABEL_SIZE, Mage_Core_Model_App::ADMIN_STORE_ID);
112
+
113
+ $this->setLabelSize($labelSize);
114
+ return $labelSize;
115
+ }
116
+
117
  /**
118
  * Observer that adds columns to the grid and allows these to be sorted and filtered properly
119
  *
144
  $block = $observer->getBlock();
145
  $shipmentGridClass = Mage::getConfig()->getBlockClassName(self::SHIPMENT_GRID_BLOCK_NAME);
146
 
147
+ if (!($block instanceof $shipmentGridClass)) {
148
  return $this;
149
  }
150
 
151
+ /**
152
+ * @var Mage_Adminhtml_Block_Sales_Shipment_Grid $block
153
+ * @var Mage_Sales_Model_Resource_Order_Shipment_Collection $currentCollection
154
+ */
155
  $currentCollection = $block->getCollection();
156
  $select = $currentCollection->getSelect()->reset(Zend_Db_Select::WHERE);
157
 
158
  /**
159
  * replace the collection as the default collection has a bug preventing it from being reset.
160
+ * Without being able to reset it, we can't edit it. Therefore we are forced to replace it altogether.
 
 
161
  */
162
  $collection = Mage::getResourceModel('postnl/order_shipment_grid_collection');
163
  $collection->setSelect($select)
221
  array('postnl_shipment' => $resource->getTableName('postnl_core/shipment')),
222
  '`main_table`.`entity_id`=`postnl_shipment`.`shipment_id`',
223
  array(
224
+ 'confirm_date' => 'postnl_shipment.confirm_date',
225
+ 'main_barcode' => 'postnl_shipment.main_barcode',
226
+ 'confirm_status' => 'postnl_shipment.confirm_status',
227
+ 'labels_printed' => 'postnl_shipment.labels_printed',
228
+ 'shipping_phase' => 'postnl_shipment.shipping_phase',
229
+ 'parcel_count' => 'postnl_shipment.parcel_count',
230
+ 'is_parcelware_exported' => 'postnl_shipment.is_parcelware_exported',
231
+ 'product_code' => 'postnl_shipment.product_code',
232
+ 'extra_cover_amount' => 'postnl_shipment.extra_cover_amount',
233
  )
234
  );
235
 
237
  * Join tig_postnl_order table
238
  */
239
  $select->joinLeft(
240
+ array('postnl_order' => $resource->getTableName('postnl_core/order')),
241
  '`main_table`.`order_id`=`postnl_order`.`order_id`',
242
  array(
243
+ 'is_pakje_gemak' => 'postnl_order.is_pakje_gemak',
244
+ 'delivery_date' => 'postnl_order.delivery_date',
245
+ 'is_pakketautomaat' => 'postnl_order.is_pakketautomaat',
246
+ 'delivery_option_type' => 'postnl_order.type',
247
  )
248
  );
249
 
313
  $block->addColumnAfter(
314
  'shipping_description',
315
  array(
316
+ 'header' => $helper->__('Shipping Method'),
317
+ 'align' => 'left',
318
+ 'index' => 'shipping_description',
319
+ 'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_shippingDescription',
320
+ 'column_css_class' => 'nobr',
321
+ 'options' => Mage::getModel('postnl_core/system_config_source_allProductOptions')
322
+ ->getAvailableOptions(false, true, false, false, true, false),
323
  ),
324
  $after
325
  );
340
  'filter_condition_callback' => array($this, '_filterShipmentType'),
341
  'sortable' => false,
342
  'options' => array(
343
+ 'nl' => $helper->__('Domestic'),
344
+ 'pakje_gemak' => $helper->__('PakjeGemak'),
345
+ 'eu' => $helper->__('EPS'),
346
+ 'global' => $helper->__('GlobalPack'),
347
+ 'pakketautomaat' => $helper->__('Parcel Dispenser'),
348
+ 'avond' => $helper->__('Evening Delivery'),
349
+ 'pakje_gemak_express' => $helper->__('Early Pickup'),
350
  ),
351
  ),
352
  $after
355
  $after = 'shipment_type';
356
  }
357
 
358
+ if (in_array('product_code', $columnsToDisplay)) {
359
+ $block->addColumnAfter(
360
+ 'product_code',
361
+ array(
362
+ 'header' => $helper->__('Shipping Product'),
363
+ 'align' => 'left',
364
+ 'index' => 'product_code',
365
+ 'type' => 'options',
366
+ 'column_css_class' => 'nobr',
367
+ 'options' => Mage::getModel('postnl_core/system_config_source_allProductOptions')
368
+ ->getAvailableOptions(false, true, false, false, true, false),
369
+ ),
370
+ $after
371
+ );
372
+
373
+ $after = 'product_code';
374
+ }
375
+
376
+ if (in_array('extra_cover_amount', $columnsToDisplay)) {
377
+ $block->addColumnAfter(
378
+ 'extra_cover_amount',
379
+ array(
380
+ 'header' => $helper->__('Extra Cover'),
381
+ 'align' => 'left',
382
+ 'index' => 'extra_cover_amount',
383
+ 'type' => 'currency',
384
+ 'currency_code' => Mage::app()->getStore()->getBaseCurrencyCode(), //returns the base currency code for the admin store
385
+ ),
386
+ $after
387
+ );
388
+
389
+ $after = 'extra_cover_amount';
390
+ }
391
+
392
  if (in_array('confirm_date', $columnsToDisplay)) {
393
  $block->addColumnAfter(
394
  'confirm_date',
407
  $after = 'confirm_date';
408
  }
409
 
410
+ if (in_array('delivery_date', $columnsToDisplay)) {
411
+ $block->addColumnAfter(
412
+ 'delivery_date',
413
+ array(
414
+ 'type' => 'date',
415
+ 'header' => $helper->__('Delivery Date'),
416
+ 'index' => 'delivery_date',
417
+ 'filter_index' => 'postnl_order.delivery_date',
418
+ 'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_deliveryDate',
419
+ 'width' => '100px',
420
+ 'filter' => false,
421
+ ),
422
+ $after
423
+ );
424
+
425
+ $after = 'delivery_date';
426
+ }
427
+
428
  if (in_array('confirm_status', $columnsToDisplay)) {
429
+ /**
430
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipmentClass
431
+ */
432
  $postnlShipmentClass = Mage::app()->getConfig()->getModelClassName('postnl_core/shipment');
433
 
434
  $block->addColumnAfter(
455
  $block->addColumnAfter(
456
  'labels_printed',
457
  array(
458
+ 'header' => $helper->__('Labels Printed'),
459
  'type' => 'options',
460
  'index' => 'labels_printed',
461
  'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_yesNo',
462
+ 'frame_callback' => array($this, 'decorateYesNo'),
463
  'options' => array(
464
  1 => $helper->__('Yes'),
465
  0 => $helper->__('No'),
471
  $after = 'labels_printed';
472
  }
473
 
474
+ if (in_array('is_parcelware_exported', $columnsToDisplay)) {
475
+ $block->addColumnAfter(
476
+ 'is_parcelware_exported',
477
+ array(
478
+ 'header' => $helper->__('Exported to Parcelware'),
479
+ 'align' => 'left',
480
+ 'type' => 'options',
481
+ 'index' => 'is_parcelware_exported',
482
+ 'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_yesNo',
483
+ 'frame_callback' => array($this, 'decorateYesNo'),
484
+ 'options' => array(
485
+ 1 => $helper->__('Yes'),
486
+ 0 => $helper->__('No'),
487
+ ),
488
+ ),
489
+ $after
490
+ );
491
+
492
+ $after = 'is_parcelware_exported';
493
+ }
494
+
495
  if (in_array('barcode', $columnsToDisplay)) {
496
  $block->addColumnAfter(
497
  'barcode',
528
  $actionColumn = $block->getColumn('action');
529
  $actions = $actionColumn->getActions();
530
 
531
+ if ($helper->checkIsPostnlActionAllowed('print_label')) {
532
+ $actions[] = array(
533
+ 'caption' => $helper->__('Print label'),
534
+ 'style' => 'cursor:pointer;',
535
+ 'is_postnl' => true, //custom flag for renderer
536
+ 'code' => 'postnl_print_label',
537
+ );
538
+ }
539
 
540
+ if ($helper->checkIsPostnlActionAllowed('confirm')) {
541
+ $actions[] = array(
542
+ 'caption' => $helper->__('Confirm'),
543
+ 'url' => array('base' => 'postnl/adminhtml_shipment/confirm'),
544
+ 'field' => 'shipment_id',
545
+ 'is_postnl' => true, //custom flag for renderer
546
+ 'code' => 'postnl_confirm',
547
+ );
548
+ }
549
 
550
  $actionColumn->setActions($actions)
551
  ->setWidth('150px')
559
  /**
560
  * Decorates the confirm_sate column
561
  *
562
+ * @param string|null $value
563
+ * @param Mage_Sales_Model_Order_Shipment $row
564
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
565
+ * @param boolean $isExport
566
  *
567
  * @return string
568
  */
572
  return $value;
573
  }
574
 
575
+ $class = $this->_getConfirmDateClass($row, $column);
576
+
577
+ return '<span class="'.$class.'"><span>'.$value.'</span></span>';
578
+ }
579
 
580
+ /**
581
+ * Gets classname for the confirmDate column of the current row.
582
+ *
583
+ * @param Mage_Sales_Model_Order_Shipment $row
584
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
585
+ *
586
+ * @return string
587
+ */
588
+ protected function _getConfirmDateClass($row, $column)
589
+ {
590
+ /**
591
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipmentClass
592
+ */
593
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
594
 
595
+ $origValue = $row->getData($column->getIndex());
596
+ $dateModel = Mage::getModel('core/date');
597
+
598
  if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
599
+ return 'grid-severity-notice';
600
  }
601
 
602
  if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_CONFIRM_EXPIRED) {
603
+ return 'grid-severity-critical';
604
  }
605
 
606
  if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED
607
+ && date('Ymd', $dateModel->gmtTimestamp()) == date('Ymd', strtotime($origValue))
608
  ) {
609
+ return 'grid-severity-major';
610
+ }
611
+
612
+ if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED
613
+ && $dateModel->gmtTimestamp() > strtotime($origValue)
614
  ) {
615
+ return 'grid-severity-critical';
 
 
616
  }
617
 
618
+ if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED) {
619
+ return 'grid-severity-minor';
620
+ }
621
+
622
+ return '';
623
  }
624
 
625
  /**
638
  return $value;
639
  }
640
 
641
+ /**
642
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipmentClass
643
+ */
644
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
645
  switch ($row->getData($column->getIndex())) {
646
  case null: //rows with no value (non-PostNL shipments)
670
  *
671
  * @return string
672
  */
673
+ public function decorateYesNo($value, $row, $column, $isExport)
674
  {
675
  if ($isExport) {
676
  return $value;
709
  return $value;
710
  }
711
 
712
+ /**
713
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipmentClass
714
+ */
715
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
716
 
 
717
  switch ($row->getData($column->getIndex())) {
718
  case null: //rows with no value (non-PostNL shipments) or unconfirmed shipments
719
  $class = '';
745
  */
746
  protected function _addMassaction($block)
747
  {
748
+ $helper = Mage::helper('postnl/parcelware');
749
+ $adminhtmlHelper = Mage::helper('adminhtml');
750
+
751
  $massactionBlock = $block->getMassactionBlock();
752
 
753
  /**
754
  * Build all the mass action option arrays
755
  */
756
  $printAndConfirmOptions = array(
757
+ 'label' => $helper->__('PostNL - Print shipping labels & confirm shipment'),
758
+ 'url' => $adminhtmlHelper->getUrl('postnl_admin/adminhtml_shipment/massPrintLabelsAndConfirm'),
759
  );
760
 
761
  $printOptions = array(
762
+ 'label' => $helper->__('PostNL - Print shipping labels'),
763
+ 'url' => $adminhtmlHelper->getUrl('postnl_admin/adminhtml_shipment/massPrintLabels'),
764
  );
765
 
766
  $confirmOptions = array(
767
+ 'label' => $helper->__('PostNL - Confirm shipments'),
768
+ 'url' => $adminhtmlHelper->getUrl('postnl_admin/adminhtml_shipment/massConfirm'),
769
+ );
770
+
771
+ $parcelWareOptions = array(
772
+ 'label' => $helper->__('PostNL - Create Parcelware export'),
773
+ 'url' => $adminhtmlHelper->getUrl('postnl_admin/adminhtml_shipment/massCreateParcelwareExport')
774
  );
775
 
776
+ /**
777
+ * Add an additional option to the 'label printing' mass actions if the configured label size is A4.
778
+ */
779
+ if ($this->getLabelSize() == 'A4') {
780
+ /**
781
+ * Get the additional options block for 'label printing' mass actions.
782
+ */
783
+ $printAdditional = Mage::app()->getLayout()
784
+ ->createBlock('postnl_adminhtml/widget_grid_massaction_labelStartPos');
785
+
786
+ $printAdditional->setData(
787
+ array(
788
+ 'name' => 'print_start_pos',
789
+ 'label' => $helper->__('Choose printing start position'),
790
+ )
791
+ );
792
+
793
+ /**
794
+ * Add the additional option block.
795
+ */
796
+ $printAndConfirmOptions['additional'] = $printAdditional;
797
+ $printOptions['additional'] = $printAdditional;
798
+ }
799
+
800
  /**
801
  * Check which mass action should be selected by default
802
  */
818
  case 'postnl_confirm_shipments':
819
  $confirmOptions['selected'] = true;
820
  break;
821
+ case 'postnl_parcelware_export':
822
+ $parcelWareOptions['selected'] = true;
823
+ break;
824
  // no default
825
  }
826
 
827
+ $printAllowed = $helper->checkIsPostnlActionAllowed('print_label');
828
+ $confirmAllowed = $helper->checkIsPostnlActionAllowed('confirm');
829
+ $exportAllowed = $helper->checkIsPostnlActionAllowed('create_parcelware_export');
830
+
831
  /**
832
+ * Add the mass actions to the grid if the current admin user is allowed to use them.
833
  */
834
+ if ($printAllowed && $confirmAllowed) {
835
+ $massactionBlock->addItem(
836
+ 'postnl_print_labels_and_confirm',
837
+ $printAndConfirmOptions
838
+ );
839
+ }
840
 
841
+ if ($printAllowed) {
842
+ $massactionBlock->addItem(
843
+ 'postnl_print_labels',
844
+ $printOptions
845
+ );
846
+ }
847
 
848
+ if ($confirmAllowed) {
849
+ $massactionBlock->addItem(
850
+ 'postnl_confirm_shipments',
851
+ $confirmOptions
852
+ );
853
+ }
854
+
855
+ $parcelwareExportEnabled = $helper->isParcelwareExportEnabled();
856
+ if ($parcelwareExportEnabled && $exportAllowed) {
857
+ $massactionBlock->addItem(
858
+ 'postnl_parcelware_export',
859
+ $parcelWareOptions
860
+ );
861
+ }
862
 
863
  return $this;
864
  }
923
  * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
924
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
925
  *
926
+ * @return $this
927
  */
928
  protected function _filterShipmentType($collection, $column)
929
  {
936
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
937
  $collection->addFieldToFilter('order.shipping_method', array('in' => $postnlShippingMethods));
938
 
939
+ /**
940
+ * If the filter condition is PakjeGemak Express, filter out all non-PakjeGemak Express orders
941
+ */
942
+ if ($filterCond == 'pakje_gemak_express') {
943
+ $collection->addFieldToFilter('postnl_order.type', array('eq' => 'PGE'));
944
+
945
+ return $this;
946
+ }
947
+
948
+ /**
949
+ * If the filter condition is evening delivery, filter out all other orders
950
+ */
951
+ if ($filterCond == 'avond') {
952
+ $collection->addFieldToFilter('postnl_order.type', array('eq' => 'Avond'));
953
+
954
+ return $this;
955
+ }
956
+
957
  /**
958
  * If the filter condition is PakjeGemak, filter out all non-PakjeGemak orders
959
  */
960
  if ($filterCond == 'pakje_gemak') {
961
+ $collection->addFieldToFilter('is_pakje_gemak', array('eq' => 1));
962
+ $collection->addFieldToFilter('postnl_order.type', array(array('eq' => 'PG'), array('null' => true)));
963
 
964
  return $this;
965
  }
966
 
967
  /**
968
+ * If the filter condition is Pakket Automaat, filter out all non-Pakket Automaat orders
969
+ */
970
+ if ($filterCond == 'pakketautomaat') {
971
+ $collection->addFieldToFilter('is_pakketautomaat', array('eq' => 1));
972
+ $collection->addFieldToFilter(
973
+ 'postnl_order.type',
974
+ array(
975
+ array('eq' => 'PA'),
976
+ array('null' => true)
977
+ )
978
+ );
979
+
980
+ return $this;
981
+ }
982
+
983
+ /**
984
+ * If the filter condition is NL, filter out all orders not being shipped to the Netherlands. PakjeGemak,
985
+ * PakjeGmak Express, evening delivery and pakketautomaat shipments are also shipped to the Netherlands so we
986
+ * need to explicitely filter those as well.
987
  */
988
  if ($filterCond == 'nl') {
989
  $collection->addFieldToFilter('country_id', $cond);
990
+ $collection->addFieldToFilter(
991
+ 'postnl_order.type',
992
+ array(
993
+ array('eq' => 'Overdag'),
994
+ array('null' => true)
995
+ )
996
+ );
997
+ $collection->addFieldToFilter(
998
+ 'is_pakje_gemak',
999
+ array(
1000
+ array('eq' => 0),
1001
+ array('null' => true)
1002
+ )
1003
+ );
1004
+ $collection->addFieldToFilter(
1005
+ 'is_pakketautomaat',
1006
+ array(
1007
+ array('eq' => 0),
1008
+ array('null' => true)
1009
+ )
1010
+ );
1011
 
1012
  return $this;
1013
  }
1025
  }
1026
 
1027
  /**
1028
+ * Lastly, filter out all orders who are being shipped to the Netherlands or other EU countries
1029
  */
1030
  $collection->addFieldToFilter('country_id', array('neq' => 'NL'));
1031
  $collection->addFieldToFilter('country_id', array('nin' => $euCountries));
app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentView.php CHANGED
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  *
39
  * Observer to edit the shipment view
@@ -41,12 +41,12 @@
41
  class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
42
  {
43
  /**
44
- * The block we want to edit
45
  */
46
  const SHIPMENT_VIEW_BLOCK_NAME = 'adminhtml/sales_order_shipment_view';
47
 
48
  /**
49
- * Observer that adds a print label button to the shipment view page
50
  *
51
  * @param Varien_Event_Observer $observer
52
  *
@@ -70,7 +70,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
70
  /**
71
  * Checks if the current block is the one we want to edit.
72
  *
73
- * Unfortunately there is no unique event for this block
74
  */
75
  $block = $observer->getBlock();
76
  $shipmentViewClass = Mage::getConfig()->getBlockClassName(self::SHIPMENT_VIEW_BLOCK_NAME);
@@ -91,25 +91,55 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
91
  return $this;
92
  }
93
 
94
- /**
95
- * Add a button to print this shipment's shipping labels
96
- */
97
- $printShippingLabelUrl = $this->getPrintShippingLabelUrl($shipment->getId());
98
- $block->addButton('print_shipping_label', array(
99
- 'label' => $helper->__('PostNL - Print Shipping Label'),
100
- 'onclick' => "setLocation('{$printShippingLabelUrl}')",
101
- 'class' => 'download',
102
- ));
 
 
 
 
 
 
 
 
103
 
104
  /**
105
  * @var TIG_PostNL_Model_Core_Shipment $postnlShipment
106
  */
107
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  /**
110
  * Add a button to reset the shipment's confirmation status
111
  */
112
- if ($postnlShipment->canResetConfirmation()) {
113
  $resetConfirmationUrl = $this->getResetConfirmationUrl($shipment->getId());
114
  $resetWarningMessage = $helper->__(
115
  'Are you sure that you wish to reset the confirmation status of this shipment? You will need to '
@@ -120,10 +150,10 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
120
  $block->addButton('reset_confirmation', array(
121
  'label' => $helper->__('PostNL - Change Confirmation'),
122
  'onclick' => "deleteConfirm('"
123
- . $resetWarningMessage
124
- . "', '"
125
- . $resetConfirmationUrl
126
- . "')",
127
  'class' => 'delete',
128
  ));
129
  }
@@ -131,20 +161,21 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
131
  /**
132
  * Update the send tracking info button so that it sends our info, instead of the default
133
  */
134
- if ($postnlShipment->isConfirmed()) {
135
  $resendTrackAndTraceUrl = $this->getResendTrackAndTraceUrl($shipment->getId());
 
136
  $block->updateButton('save', 'label', $helper->__('PostNL - Send Tracking Information'));
137
  $block->updateButton('save', 'onclick',
138
  "deleteConfirm('"
139
- . $helper->__('Are you sure you want to send PostNL tracking information to the customer?')
140
- . "', '" . $resendTrackAndTraceUrl . "')"
141
  );
142
  }
143
 
144
  /**
145
  * Add a button to remove any stored shipping labels for this shipment.
146
  */
147
- if ($postnlShipment->hasLabels() && !$postnlShipment->isConfirmed()) {
148
  $removeLabelsUrl = $this->getRemoveLabelsUrl($shipment->getId());
149
  $removeLabelsWarningMessage = $helper->__(
150
  "Are you sure that you wish to remove this shipment\'s shipping label? You will need to print a new "
@@ -162,6 +193,19 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
162
  ));
163
  }
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  return $this;
166
  }
167
 
@@ -175,7 +219,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
175
  public function getPrintShippingLabelUrl($shipmentId)
176
  {
177
  $url = Mage::helper('adminhtml')->getUrl(
178
- 'postnl/adminhtml_shipment/printLabel',
179
  array('shipment_id' => $shipmentId)
180
  );
181
 
@@ -192,7 +236,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
192
  public function getResetConfirmationUrl($shipmentId)
193
  {
194
  $url = Mage::helper('adminhtml')->getUrl(
195
- 'postnl/adminhtml_shipment/resetConfirmation',
196
  array('shipment_id' => $shipmentId)
197
  );
198
 
@@ -209,7 +253,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
209
  public function getRemoveLabelsUrl($shipmentId)
210
  {
211
  $url = Mage::helper('adminhtml')->getUrl(
212
- 'postnl/adminhtml_shipment/removeLabels',
213
  array('shipment_id' => $shipmentId)
214
  );
215
 
@@ -226,10 +270,30 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
226
  public function getResendTrackAndTraceUrl($shipmentId)
227
  {
228
  $url = Mage::helper('adminhtml')->getUrl(
229
- 'postnl/adminhtml_shipment/sendTrackAndTrace',
230
  array('shipment_id' => $shipmentId)
231
  );
232
 
233
  return $url;
234
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  }
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  *
39
  * Observer to edit the shipment view
41
  class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
42
  {
43
  /**
44
+ * The block we want to edit.
45
  */
46
  const SHIPMENT_VIEW_BLOCK_NAME = 'adminhtml/sales_order_shipment_view';
47
 
48
  /**
49
+ * Observer that adds a print label button to the shipment view page.
50
  *
51
  * @param Varien_Event_Observer $observer
52
  *
70
  /**
71
  * Checks if the current block is the one we want to edit.
72
  *
73
+ * Unfortunately there is no unique event for this block.
74
  */
75
  $block = $observer->getBlock();
76
  $shipmentViewClass = Mage::getConfig()->getBlockClassName(self::SHIPMENT_VIEW_BLOCK_NAME);
91
  return $this;
92
  }
93
 
94
+ $this->addPostnlButtons($block, $shipment);
95
+
96
+ return $this;
97
+ }
98
+
99
+ /**
100
+ * Add new PostNL buttons to the page.
101
+ *
102
+ * @param Mage_Adminhtml_BLock_Sales_Order_Shipment_View $block
103
+ * @param Mage_Sales_Model_Order_Shipment $shipment
104
+ *
105
+ * @return $this
106
+ */
107
+ public function addPostnlButtons(Mage_Adminhtml_BLock_Sales_Order_Shipment_View $block,
108
+ Mage_Sales_Model_Order_Shipment $shipment)
109
+ {
110
+ $helper = Mage::helper('postnl');
111
 
112
  /**
113
  * @var TIG_PostNL_Model_Core_Shipment $postnlShipment
114
  */
115
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
116
 
117
+ /**
118
+ * Check which actions are allowed.
119
+ */
120
+ $confirmAllowed = $helper->checkIsPostnlActionAllowed('confirm');
121
+ $printAllowed = $helper->checkIsPostnlActionAllowed('print_label');
122
+ $deleteLabelsAllowed = $helper->checkIsPostnlActionAllowed('delete_labels');
123
+ $resetConfirmAllowed = $helper->checkIsPostnlActionAllowed(array('reset_confirmation', 'delete_labels'));
124
+ $sendTrackAndTraceAllowed = $helper->checkIsPostnlActionAllowed('send_track_and_trace');
125
+
126
+ /**
127
+ * Add a button to print this shipment's shipping labels
128
+ */
129
+ if ($printAllowed) {
130
+ $printShippingLabelUrl = $this->getPrintShippingLabelUrl($shipment->getId());
131
+
132
+ $block->addButton('print_shipping_label', array(
133
+ 'label' => $helper->__('PostNL - Print Shipping Label'),
134
+ 'onclick' => "printLabel('{$printShippingLabelUrl}')",
135
+ 'class' => 'download',
136
+ ));
137
+ }
138
+
139
  /**
140
  * Add a button to reset the shipment's confirmation status
141
  */
142
+ if ($postnlShipment->canResetConfirmation() && $resetConfirmAllowed) {
143
  $resetConfirmationUrl = $this->getResetConfirmationUrl($shipment->getId());
144
  $resetWarningMessage = $helper->__(
145
  'Are you sure that you wish to reset the confirmation status of this shipment? You will need to '
150
  $block->addButton('reset_confirmation', array(
151
  'label' => $helper->__('PostNL - Change Confirmation'),
152
  'onclick' => "deleteConfirm('"
153
+ . $resetWarningMessage
154
+ . "', '"
155
+ . $resetConfirmationUrl
156
+ . "')",
157
  'class' => 'delete',
158
  ));
159
  }
161
  /**
162
  * Update the send tracking info button so that it sends our info, instead of the default
163
  */
164
+ if ($postnlShipment->isConfirmed() && $sendTrackAndTraceAllowed) {
165
  $resendTrackAndTraceUrl = $this->getResendTrackAndTraceUrl($shipment->getId());
166
+
167
  $block->updateButton('save', 'label', $helper->__('PostNL - Send Tracking Information'));
168
  $block->updateButton('save', 'onclick',
169
  "deleteConfirm('"
170
+ . $helper->__('Are you sure you want to send PostNL tracking information to the customer?')
171
+ . "', '" . $resendTrackAndTraceUrl . "')"
172
  );
173
  }
174
 
175
  /**
176
  * Add a button to remove any stored shipping labels for this shipment.
177
  */
178
+ if ($postnlShipment->hasLabels() && !$postnlShipment->isConfirmed() && $deleteLabelsAllowed) {
179
  $removeLabelsUrl = $this->getRemoveLabelsUrl($shipment->getId());
180
  $removeLabelsWarningMessage = $helper->__(
181
  "Are you sure that you wish to remove this shipment\'s shipping label? You will need to print a new "
193
  ));
194
  }
195
 
196
+ /**
197
+ * Add a button to confirm this shipment.
198
+ */
199
+ if (!$postnlShipment->isConfirmed() && $confirmAllowed) {
200
+ $confirmUrl = $this->getConfirmUrl($shipment->getId());
201
+
202
+ $block->addButton('confirm_shipment', array(
203
+ 'label' => $helper->__('PostNL - Confirm Shipment'),
204
+ 'onclick' => "setLocation('{$confirmUrl}')",
205
+ 'class' => 'save',
206
+ ));
207
+ }
208
+
209
  return $this;
210
  }
211
 
219
  public function getPrintShippingLabelUrl($shipmentId)
220
  {
221
  $url = Mage::helper('adminhtml')->getUrl(
222
+ 'postnl_admin/adminhtml_shipment/printLabel',
223
  array('shipment_id' => $shipmentId)
224
  );
225
 
236
  public function getResetConfirmationUrl($shipmentId)
237
  {
238
  $url = Mage::helper('adminhtml')->getUrl(
239
+ 'postnl_admin/adminhtml_shipment/resetConfirmation',
240
  array('shipment_id' => $shipmentId)
241
  );
242
 
253
  public function getRemoveLabelsUrl($shipmentId)
254
  {
255
  $url = Mage::helper('adminhtml')->getUrl(
256
+ 'postnl_admin/adminhtml_shipment/removeLabels',
257
  array('shipment_id' => $shipmentId)
258
  );
259
 
270
  public function getResendTrackAndTraceUrl($shipmentId)
271
  {
272
  $url = Mage::helper('adminhtml')->getUrl(
273
+ 'postnl_admin/adminhtml_shipment/sendTrackAndTrace',
274
  array('shipment_id' => $shipmentId)
275
  );
276
 
277
  return $url;
278
  }
279
+
280
+ /**
281
+ * Get adminhtml url for PostNL confirm shipment action
282
+ *
283
+ * @param int $shipmentId The ID of the current shipment
284
+ *
285
+ * @return string
286
+ */
287
+ public function getConfirmUrl($shipmentId)
288
+ {
289
+ $url = Mage::helper('adminhtml')->getUrl(
290
+ 'postnl_admin/adminhtml_shipment/confirm',
291
+ array(
292
+ 'shipment_id' => $shipmentId,
293
+ 'return_to_view' => true,
294
+ )
295
+ );
296
+
297
+ return $url;
298
+ }
299
  }
app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/ShipmentGridColumns.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,14 +33,14 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Adminhtml_System_Config_Source_ShipmentGridColumns
40
  {
41
  /**
42
  * Returns an option array for optional shipment grid columns
43
- *
44
  * @return array
45
  */
46
  public function toOptionArray()
@@ -59,10 +59,22 @@ class TIG_PostNL_Model_Adminhtml_System_Config_Source_ShipmentGridColumns
59
  'value' => 'shipment_type',
60
  'label' => $helper->__('Shipment Type')
61
  ),
 
 
 
 
 
 
 
 
62
  array(
63
  'value' => 'confirm_date',
64
  'label' => $helper->__('Send Date')
65
  ),
 
 
 
 
66
  array(
67
  'value' => 'confirm_status',
68
  'label' => $helper->__('Confirm Status')
@@ -71,6 +83,10 @@ class TIG_PostNL_Model_Adminhtml_System_Config_Source_ShipmentGridColumns
71
  'value' => 'labels_printed',
72
  'label' => $helper->__('Labels Printed')
73
  ),
 
 
 
 
74
  array(
75
  'value' => 'barcode',
76
  'label' => $helper->__('Barcode')
@@ -80,7 +96,7 @@ class TIG_PostNL_Model_Adminhtml_System_Config_Source_ShipmentGridColumns
80
  'label' => $helper->__('Shipping Phase')
81
  ),
82
  );
83
-
84
  return $columns;
85
  }
86
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Adminhtml_System_Config_Source_ShipmentGridColumns
40
  {
41
  /**
42
  * Returns an option array for optional shipment grid columns
43
+ *
44
  * @return array
45
  */
46
  public function toOptionArray()
59
  'value' => 'shipment_type',
60
  'label' => $helper->__('Shipment Type')
61
  ),
62
+ array(
63
+ 'value' => 'product_code',
64
+ 'label' => $helper->__('Shipping Product')
65
+ ),
66
+ array(
67
+ 'value' => 'extra_cover_amount',
68
+ 'label' => $helper->__('Extra Cover')
69
+ ),
70
  array(
71
  'value' => 'confirm_date',
72
  'label' => $helper->__('Send Date')
73
  ),
74
+ array(
75
+ 'value' => 'delivery_date',
76
+ 'label' => $helper->__('Delivery Date')
77
+ ),
78
  array(
79
  'value' => 'confirm_status',
80
  'label' => $helper->__('Confirm Status')
83
  'value' => 'labels_printed',
84
  'label' => $helper->__('Labels Printed')
85
  ),
86
+ array(
87
+ 'value' => 'is_parcelware_exported',
88
+ 'label' => $helper->__('Exported to Parcelware')
89
+ ),
90
  array(
91
  'value' => 'barcode',
92
  'label' => $helper->__('Barcode')
96
  'label' => $helper->__('Shipping Phase')
97
  ),
98
  );
99
+
100
  return $columns;
101
  }
102
  }
app/code/community/TIG/PostNL/Model/{Core → Adminhtml}/System/Config/Source/ShipmentGridMassaction.php RENAMED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,14 +33,14 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Model_Core_System_Config_Source_ShipmentGridMassAction
40
  {
41
  /**
42
  * Returns an option array for available shipment grid mass actions
43
- *
44
  * @return array
45
  */
46
  public function toOptionArray()
@@ -59,8 +59,12 @@ class TIG_PostNL_Model_Core_System_Config_Source_ShipmentGridMassAction
59
  'value' => 'postnl_confirm_shipments',
60
  'label' => $helper->__('Confirm shipments'),
61
  ),
 
 
 
 
62
  );
63
-
64
  return $options;
65
  }
66
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Model_Adminhtml_System_Config_Source_ShipmentGridMassAction
40
  {
41
  /**
42
  * Returns an option array for available shipment grid mass actions
43
+ *
44
  * @return array
45
  */
46
  public function toOptionArray()
59
  'value' => 'postnl_confirm_shipments',
60
  'label' => $helper->__('Confirm shipments'),
61
  ),
62
+ array(
63
+ 'value' => 'postnl_parcelware_export',
64
+ 'label' => $helper->__('Parcelware export'),
65
+ ),
66
  );
67
+
68
  return $options;
69
  }
70
  }
app/code/community/TIG/PostNL/Model/Carrier/Postnl.php CHANGED
@@ -33,21 +33,31 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
- */
39
-
40
- /**
41
  * PostNL shipping method model
42
  *
43
- * @todo check code for inconsistency and conventions. Copied from flat_rate method
 
 
 
 
 
44
  */
45
- class TIG_PostNL_Model_Carrier_Postnl
46
- extends Mage_Shipping_Model_Carrier_Abstract
47
  implements Mage_Shipping_Model_Carrier_Interface
48
  {
 
 
 
49
  const XML_PATH_RATE_TYPE = 'carriers/postnl/rate_type';
50
 
 
 
 
 
 
51
  /**
52
  * PostNL carrier code
53
  *
@@ -61,18 +71,63 @@ class TIG_PostNL_Model_Carrier_Postnl
61
  * @var boolean
62
  */
63
  protected $_isFixed = true;
 
 
 
 
64
  protected $_default_condition_name = 'package_weight';
65
 
 
 
 
66
  protected $_conditionNames = array();
67
 
 
 
 
68
  public function __construct()
69
  {
70
  parent::__construct();
71
- foreach ($this->getCode('condition_name') as $k=>$v) {
72
  $this->_conditionNames[] = $k;
73
  }
74
  }
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  /**
77
  * get PostNL Carrier helper
78
  *
@@ -80,7 +135,7 @@ class TIG_PostNL_Model_Carrier_Postnl
80
  */
81
  public function getHelper()
82
  {
83
- if ($this->getData('helper')) {
84
  return $this->getData('helper');
85
  }
86
 
@@ -103,8 +158,9 @@ class TIG_PostNL_Model_Carrier_Postnl
103
  /**
104
  * Collect shipping rate
105
  *
106
- * @param Mage_Shipping_Model_Rate_Request $data
107
  *
 
108
  * @return Mage_Shipping_Model_Rate_Result|void
109
  */
110
  public function collectRates(Mage_Shipping_Model_Rate_Request $request)
@@ -141,25 +197,31 @@ class TIG_PostNL_Model_Carrier_Postnl
141
  }
142
  }
143
 
144
-
145
  $rateType = Mage::getStoreConfig(self::XML_PATH_RATE_TYPE, Mage::app()->getStore()->getId());
146
 
147
  if ($rateType == 'flat') {
148
  $result = $this->_getFlatRate($request);
149
- return $result;
150
  }
151
 
152
  if ($rateType == 'table') {
153
  $result = $this->_getTableRate($request);
154
- return $result;
155
  }
156
 
157
- throw new TIG_PostNL_Exception(
158
- $helper->__('Invalid rate type requested: %s', $rateType),
159
- 'POSTNL-0036'
160
- );
 
 
 
 
161
  }
162
 
 
 
 
 
 
163
  protected function _getFlatRate($request)
164
  {
165
  $freeBoxes = 0;
@@ -187,7 +249,8 @@ class TIG_PostNL_Model_Carrier_Postnl
187
  if ($this->getConfigData('type') == 'O') { // per order
188
  $shippingPrice = $this->getConfigData('price');
189
  } elseif ($this->getConfigData('type') == 'I') { // per item
190
- $shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
 
191
  } else {
192
  $shippingPrice = false;
193
  }
@@ -207,6 +270,7 @@ class TIG_PostNL_Model_Carrier_Postnl
207
  $shippingPrice = '0.00';
208
  }
209
 
 
210
 
211
  $method->setPrice($shippingPrice);
212
  $method->setCost($shippingPrice);
@@ -217,7 +281,12 @@ class TIG_PostNL_Model_Carrier_Postnl
217
  return $result;
218
  }
219
 
220
- public function _getTableRate(Mage_Shipping_Model_Rate_Request $request)
 
 
 
 
 
221
  {
222
  // exclude Virtual products price from Package value if pre-configured
223
  if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) {
@@ -239,6 +308,7 @@ class TIG_PostNL_Model_Carrier_Postnl
239
 
240
  // Free shipping by qty
241
  $freeQty = 0;
 
242
  if ($request->getAllItems()) {
243
  $freePackageValue = 0;
244
  foreach ($request->getAllItems() as $item) {
@@ -266,7 +336,7 @@ class TIG_PostNL_Model_Carrier_Postnl
266
  if ($freePackageValue) {
267
  $request->setPackageValue($request->getPackageValue() - $freePackageValue);
268
  }
269
-
270
  $conditionName = $this->getConfigData('condition_name');
271
  $request->setConditionName($conditionName ? $conditionName : $this->_default_condition_name);
272
 
@@ -283,25 +353,18 @@ class TIG_PostNL_Model_Carrier_Postnl
283
  $request->setPackageWeight($oldWeight);
284
  $request->setPackageQty($oldQty);
285
 
 
286
  if (!empty($rate) && $rate['price'] >= 0) {
287
- $method = Mage::getModel('shipping/rate_result_method');
288
-
289
- $method->setCarrier('postnl');
290
- $method->setCarrierTitle($this->getConfigData('title'));
291
-
292
- $method->setMethod('tablerate');
293
- $method->setMethodTitle($this->getConfigData('name'));
294
-
295
  if ($request->getFreeShipping() === true || ($request->getPackageQty() == $freeQty)) {
296
  $shippingPrice = 0;
297
  } else {
298
  $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
299
  }
300
 
301
- $method->setPrice($shippingPrice);
302
- $method->setCost($rate['cost']);
303
 
304
- $result->append($method);
 
305
  } elseif (empty($rate) && $request->getFreeShipping() === true) {
306
  /**
307
  * was applied promotion rule for whole cart
@@ -314,34 +377,90 @@ class TIG_PostNL_Model_Carrier_Postnl
314
  $rate = $this->getRate($request);
315
  if (!empty($rate) && $rate['price'] >= 0) {
316
  $method = Mage::getModel('shipping/rate_result_method');
317
-
318
- $method->setCarrier('postnl');
319
- $method->setCarrierTitle($this->getConfigData('title'));
320
-
321
- $method->setMethod('tablerate');
322
- $method->setMethodTitle($this->getConfigData('name'));
323
-
324
- $method->setPrice(0);
325
- $method->setCost(0);
326
-
327
- $result->append($method);
328
  }
 
 
 
329
  } else {
330
  $error = Mage::getModel('shipping/rate_result_error');
331
  $error->setCarrier('tablerate');
332
  $error->setCarrierTitle($this->getConfigData('title'));
333
  $error->setErrorMessage($this->getConfigData('specificerrmsg'));
334
  $result->append($error);
 
 
335
  }
336
 
 
 
 
 
 
 
 
 
 
 
 
337
  return $result;
338
  }
339
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  public function getRate(Mage_Shipping_Model_Rate_Request $request)
341
  {
342
- return Mage::getResourceModel('shipping/carrier_tablerate')->getRate($request);
 
 
 
 
 
 
 
 
 
 
343
  }
344
 
 
 
 
 
 
 
 
345
  public function getCode($type, $code='')
346
  {
347
  $codes = array(
@@ -394,8 +513,6 @@ class TIG_PostNL_Model_Carrier_Postnl
394
  * @param string $tracking
395
  *
396
  * @return Mage_Shipping_Model_Tracking_Result_Status
397
- *
398
- * @todo check code and docblock
399
  */
400
  public function getTrackingInfo($tracking)
401
  {
@@ -423,8 +540,6 @@ class TIG_PostNL_Model_Carrier_Postnl
423
  * @param string $number
424
  *
425
  * @return Mage_Sales_Model_Order_Shipment_Track
426
- *
427
- * @todo check code and docblock
428
  */
429
  protected function _getTrackByNumber($number)
430
  {
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
 
 
39
  * PostNL shipping method model
40
  *
41
+ * @method boolean hasQuote()
42
+ * @method TIG_PostNL_Model_Carrier_Postnl setQuote(Mage_Sales_Model_Quote $value)
43
+ * @method boolean hasPostnlOrder()
44
+ * @method TIG_PostNL_Model_Carrier_Postnl setPostnlOrder(TIG_PostNL_Model_Core_Order $value)
45
+ * @method boolean hasHelper()
46
+ * @method TIG_PostNL_Model_Carrier_Postnl setHelper(TIG_PostNL_Helper_Carrier $value)
47
  */
48
+ class TIG_PostNL_Model_Carrier_Postnl extends Mage_Shipping_Model_Carrier_Abstract
 
49
  implements Mage_Shipping_Model_Carrier_Interface
50
  {
51
+ /**
52
+ * Rate type (tablerate or flatrate).
53
+ */
54
  const XML_PATH_RATE_TYPE = 'carriers/postnl/rate_type';
55
 
56
+ /**
57
+ * Whether to use Magento's tabelrates or PostNL's.
58
+ */
59
+ const XPATH_RATE_SOURCE = 'carriers/postnl/rate_source';
60
+
61
  /**
62
  * PostNL carrier code
63
  *
71
  * @var boolean
72
  */
73
  protected $_isFixed = true;
74
+
75
+ /**
76
+ * @var string
77
+ */
78
  protected $_default_condition_name = 'package_weight';
79
 
80
+ /**
81
+ * @var array
82
+ */
83
  protected $_conditionNames = array();
84
 
85
+ /**
86
+ * Class constructor.
87
+ */
88
  public function __construct()
89
  {
90
  parent::__construct();
91
+ foreach (array_keys($this->getCode('condition_name')) as $k) {
92
  $this->_conditionNames[] = $k;
93
  }
94
  }
95
 
96
+ /**
97
+ * @return Mage_Sales_Model_Quote
98
+ */
99
+ public function getQuote()
100
+ {
101
+ if ($this->hasQuote()) {
102
+ return $this->getData('quote');
103
+ }
104
+
105
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
106
+ $this->setQuote($quote);
107
+
108
+ return $quote;
109
+ }
110
+
111
+ /**
112
+ * @return TIG_PostNL_Model_Core_Order
113
+ */
114
+ public function getPostnlOrder()
115
+ {
116
+ if ($this->hasPostnlOrder()) {
117
+ return $this->getData('postnl_order');
118
+ }
119
+
120
+ $quote = $this->getQuote();
121
+ $postnlOrder = Mage::getModel('postnl_core/order');
122
+
123
+ if ($quote->getId()) {
124
+ $postnlOrder->load($quote->getId(), 'quote_id');
125
+ }
126
+
127
+ $this->setPostnlOrder($postnlOrder);
128
+ return $postnlOrder;
129
+ }
130
+
131
  /**
132
  * get PostNL Carrier helper
133
  *
135
  */
136
  public function getHelper()
137
  {
138
+ if ($this->hasHelper()) {
139
  return $this->getData('helper');
140
  }
141
 
158
  /**
159
  * Collect shipping rate
160
  *
161
+ * @param Mage_Shipping_Model_Rate_Request $request
162
  *
163
+ * @throws TIG_PostNL_Exception
164
  * @return Mage_Shipping_Model_Rate_Result|void
165
  */
166
  public function collectRates(Mage_Shipping_Model_Rate_Request $request)
197
  }
198
  }
199
 
 
200
  $rateType = Mage::getStoreConfig(self::XML_PATH_RATE_TYPE, Mage::app()->getStore()->getId());
201
 
202
  if ($rateType == 'flat') {
203
  $result = $this->_getFlatRate($request);
 
204
  }
205
 
206
  if ($rateType == 'table') {
207
  $result = $this->_getTableRate($request);
 
208
  }
209
 
210
+ if (!isset($result)) {
211
+ throw new TIG_PostNL_Exception(
212
+ $helper->__('Invalid rate type requested: %s', $rateType),
213
+ 'POSTNL-0036'
214
+ );
215
+ }
216
+
217
+ return $result;
218
  }
219
 
220
+ /**
221
+ * @param Mage_Shipping_Model_Rate_Request $request
222
+ *
223
+ * @return Mage_Shipping_Model_Rate_Result
224
+ */
225
  protected function _getFlatRate($request)
226
  {
227
  $freeBoxes = 0;
249
  if ($this->getConfigData('type') == 'O') { // per order
250
  $shippingPrice = $this->getConfigData('price');
251
  } elseif ($this->getConfigData('type') == 'I') { // per item
252
+ $shippingPrice = ($request->getPackageQty() * $this->getConfigData('price'))
253
+ - ($this->getFreeBoxes() * $this->getConfigData('price'));
254
  } else {
255
  $shippingPrice = false;
256
  }
270
  $shippingPrice = '0.00';
271
  }
272
 
273
+ $shippingPrice += $this->getPostnlFee();
274
 
275
  $method->setPrice($shippingPrice);
276
  $method->setCost($shippingPrice);
281
  return $result;
282
  }
283
 
284
+ /**
285
+ * @param Mage_Shipping_Model_Rate_Request $request
286
+ *
287
+ * @return Mage_Shipping_Model_Rate_Result
288
+ */
289
+ protected function _getTableRate(Mage_Shipping_Model_Rate_Request $request)
290
  {
291
  // exclude Virtual products price from Package value if pre-configured
292
  if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) {
308
 
309
  // Free shipping by qty
310
  $freeQty = 0;
311
+ $freePackageValue = false;
312
  if ($request->getAllItems()) {
313
  $freePackageValue = 0;
314
  foreach ($request->getAllItems() as $item) {
336
  if ($freePackageValue) {
337
  $request->setPackageValue($request->getPackageValue() - $freePackageValue);
338
  }
339
+
340
  $conditionName = $this->getConfigData('condition_name');
341
  $request->setConditionName($conditionName ? $conditionName : $this->_default_condition_name);
342
 
353
  $request->setPackageWeight($oldWeight);
354
  $request->setPackageQty($oldQty);
355
 
356
+ $method = Mage::getModel('shipping/rate_result_method');
357
  if (!empty($rate) && $rate['price'] >= 0) {
 
 
 
 
 
 
 
 
358
  if ($request->getFreeShipping() === true || ($request->getPackageQty() == $freeQty)) {
359
  $shippingPrice = 0;
360
  } else {
361
  $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
362
  }
363
 
364
+ $shippingPrice += $this->getPostnlFee();
 
365
 
366
+ $price = $shippingPrice;
367
+ $cost = $rate['cost'];
368
  } elseif (empty($rate) && $request->getFreeShipping() === true) {
369
  /**
370
  * was applied promotion rule for whole cart
377
  $rate = $this->getRate($request);
378
  if (!empty($rate) && $rate['price'] >= 0) {
379
  $method = Mage::getModel('shipping/rate_result_method');
 
 
 
 
 
 
 
 
 
 
 
380
  }
381
+
382
+ $price = 0;
383
+ $cost = 0;
384
  } else {
385
  $error = Mage::getModel('shipping/rate_result_error');
386
  $error->setCarrier('tablerate');
387
  $error->setCarrierTitle($this->getConfigData('title'));
388
  $error->setErrorMessage($this->getConfigData('specificerrmsg'));
389
  $result->append($error);
390
+
391
+ return $result;
392
  }
393
 
394
+ $method->setCarrier('postnl');
395
+ $method->setCarrierTitle($this->getConfigData('title'));
396
+
397
+ $method->setMethod('tablerate');
398
+ $method->setMethodTitle($this->getConfigData('name'));
399
+
400
+ $method->setPrice($price);
401
+ $method->setCost($cost);
402
+
403
+ $result->append($method);
404
+
405
  return $result;
406
  }
407
 
408
+ /**
409
+ * @return float|int
410
+ */
411
+ public function getPostnlFee()
412
+ {
413
+ $fee = 0;
414
+ $type = null;
415
+ $includingTax = false;
416
+
417
+ $postnlOrder = $this->getPostnlOrder();
418
+ if ($postnlOrder->getId() && $postnlOrder->getIsActive()) {
419
+ $type = $postnlOrder->getType();
420
+ } else {
421
+ return $fee;
422
+ }
423
+
424
+ if (Mage::getSingleton('tax/config')->shippingPriceIncludesTax()) {
425
+ $includingTax = true;
426
+ }
427
+
428
+ if ($type == 'PGE') {
429
+ $fee = Mage::helper('postnl/deliveryOptions')->getExpressFee(false, $includingTax);
430
+ } else if ($type == 'Avond' ) {
431
+ $fee = Mage::helper('postnl/deliveryOptions')->getEveningFee(false, $includingTax);
432
+ }
433
+
434
+ return $fee;
435
+ }
436
+
437
+ /**
438
+ * @param Mage_Shipping_Model_Rate_Request $request
439
+ *
440
+ * @return array|bool
441
+ */
442
  public function getRate(Mage_Shipping_Model_Rate_Request $request)
443
  {
444
+ $websiteId = $request->getWebsiteId();
445
+ $website = Mage::getModel('core/website')->load($websiteId);
446
+
447
+ $rateSource = $website->getConfig(self::XPATH_RATE_SOURCE);
448
+ if ($rateSource == 'shipping_tablerate') {
449
+ $rate = Mage::getResourceModel('shipping/carrier_tablerate')->getRate($request);
450
+ } else {
451
+ $rate = Mage::getResourceModel('postnl_carrier/tablerate')->getRate($request);
452
+ }
453
+
454
+ return $rate;
455
  }
456
 
457
+ /**
458
+ * @param $type
459
+ * @param string $code
460
+ *
461
+ * @return mixed
462
+ * @throws Mage_Core_Exception
463
+ */
464
  public function getCode($type, $code='')
465
  {
466
  $codes = array(
513
  * @param string $tracking
514
  *
515
  * @return Mage_Shipping_Model_Tracking_Result_Status
 
 
516
  */
517
  public function getTrackingInfo($tracking)
518
  {
540
  * @param string $number
541
  *
542
  * @return Mage_Sales_Model_Order_Shipment_Track
 
 
543
  */
544
  protected function _getTrackByNumber($number)
545
  {
app/code/community/TIG/PostNL/Model/Carrier/Resource/Tablerate.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_Carrier_Resource_Tablerate extends Mage_Shipping_Model_Resource_Carrier_Tablerate
40
+ {
41
+ /**
42
+ * Define main table and id field name.
43
+ *
44
+ * @return void
45
+ */
46
+ protected function _construct()
47
+ {
48
+ $this->_init('postnl_carrier/tablerate', 'pk');
49
+ }
50
+
51
+ /**
52
+ * Upload table rate file and import data from it
53
+ *
54
+ * @param Varien_Object $object
55
+ *
56
+ * @throws Mage_Core_Exception
57
+ *
58
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate
59
+ */
60
+ public function uploadAndImport(Varien_Object $object)
61
+ {
62
+ if (empty($_FILES['groups']['tmp_name']['postnl']['fields']['import']['value'])) {
63
+ return $this;
64
+ }
65
+
66
+ $csvFile = $_FILES['groups']['tmp_name']['postnl']['fields']['import']['value'];
67
+ $website = Mage::app()->getWebsite($object->getScopeId());
68
+
69
+ $this->_importWebsiteId = (int)$website->getId();
70
+ $this->_importUniqueHash = array();
71
+ $this->_importErrors = array();
72
+ $this->_importedRows = 0;
73
+
74
+ $io = new Varien_Io_File();
75
+ $info = pathinfo($csvFile);
76
+ $io->open(array('path' => $info['dirname']));
77
+ $io->streamOpen($info['basename'], 'r');
78
+
79
+ // check and skip headers
80
+ $headers = $io->streamReadCsv();
81
+ if ($headers === false || count($headers) < 5) {
82
+ $io->streamClose();
83
+ Mage::throwException(Mage::helper('shipping')->__('Invalid Table Rates File Format'));
84
+ }
85
+
86
+ if ($object->getData('groups/postnl/fields/condition_name/inherit') == '1') {
87
+ $conditionName = (string)Mage::getConfig()->getNode('default/carriers/postnl/condition_name');
88
+ } else {
89
+ $conditionName = $object->getData('groups/postnl/fields/condition_name/value');
90
+ }
91
+ $this->_importConditionName = $conditionName;
92
+
93
+ $adapter = $this->_getWriteAdapter();
94
+ $adapter->beginTransaction();
95
+
96
+ try {
97
+ $rowNumber = 1;
98
+ $importData = array();
99
+
100
+ $this->_loadDirectoryCountries();
101
+ $this->_loadDirectoryRegions();
102
+
103
+ // delete old data by website and condition name
104
+ $condition = array(
105
+ 'website_id = ?' => $this->_importWebsiteId,
106
+ 'condition_name = ?' => $this->_importConditionName
107
+ );
108
+ $adapter->delete($this->getMainTable(), $condition);
109
+
110
+ while (false !== ($csvLine = $io->streamReadCsv())) {
111
+ $rowNumber ++;
112
+
113
+ if (empty($csvLine)) {
114
+ continue;
115
+ }
116
+
117
+ $row = $this->_getImportRow($csvLine, $rowNumber);
118
+ if ($row !== false) {
119
+ $importData[] = $row;
120
+ }
121
+
122
+ if (count($importData) == 5000) {
123
+ $this->_saveImportData($importData);
124
+ $importData = array();
125
+ }
126
+ }
127
+ $this->_saveImportData($importData);
128
+ $io->streamClose();
129
+ } catch (Mage_Core_Exception $e) {
130
+ $adapter->rollback();
131
+ $io->streamClose();
132
+ Mage::throwException($e->getMessage());
133
+ } catch (Exception $e) {
134
+ $adapter->rollback();
135
+ $io->streamClose();
136
+ Mage::logException($e);
137
+ Mage::throwException(Mage::helper('shipping')->__('An error occurred while import table rates.'));
138
+ }
139
+
140
+ $adapter->commit();
141
+
142
+ if ($this->_importErrors) {
143
+ $error = Mage::helper('shipping')->__(
144
+ 'File has not been imported. See the following list of errors: %s',
145
+ implode(" \n", $this->_importErrors)
146
+ );
147
+ Mage::throwException($error);
148
+ }
149
+
150
+ return $this;
151
+ }
152
+ }
app/code/community/TIG/PostNL/Model/Carrier/Resource/Tablerate/Collection.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_Carrier_Resource_Tablerate_Collection
40
+ extends Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
41
+ {
42
+ /**
43
+ * Define resource model and item
44
+ *
45
+ */
46
+ protected function _construct()
47
+ {
48
+ $this->_init('postnl_carrier/tablerate');
49
+ $this->_shipTable = $this->getMainTable();
50
+ $this->_countryTable = $this->getTable('directory/country');
51
+ $this->_regionTable = $this->getTable('directory/country_region');
52
+ }
53
+ }
app/code/community/TIG/PostNL/Model/Carrier/System/Config/Backend/Tablerate.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_Carrier_System_Config_Backend_Tablerate extends Mage_Core_Model_Config_Data
40
+ {
41
+ /**
42
+ * Upload a new csv file.
43
+ *
44
+ * @return void
45
+ */
46
+ public function _afterSave()
47
+ {
48
+ Mage::getResourceModel('postnl_carrier/tablerate')->uploadAndImport($this);
49
+ }
50
+ }
app/code/community/TIG/PostNL/Model/Carrier/System/Config/Source/RateType.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,14 +33,14 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Carrier_System_Config_Source_RateType
40
  {
41
  /**
42
  * Returns an option array for rate type options
43
- *
44
  * @return array
45
  */
46
  public function toOptionArray()
@@ -56,7 +56,7 @@ class TIG_PostNL_Model_Carrier_System_Config_Source_RateType
56
  'label' => $helper->__('Table'),
57
  ),
58
  );
59
-
60
  return $options;
61
  }
62
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Carrier_System_Config_Source_RateType
40
  {
41
  /**
42
  * Returns an option array for rate type options
43
+ *
44
  * @return array
45
  */
46
  public function toOptionArray()
56
  'label' => $helper->__('Table'),
57
  ),
58
  );
59
+
60
  return $options;
61
  }
62
  }
app/code/community/TIG/PostNL/Model/Carrier/System/Config/Source/TablerateSource.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_Carrier_System_Config_Source_TablerateSource
40
+ {
41
+ /**
42
+ * Returns an option array for rate source options.
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
+ {
48
+ $helper = Mage::helper('postnl');
49
+ $options = array(
50
+ array(
51
+ 'value' => 'shipping_tablerate',
52
+ 'label' => $helper->__("Use Magento's Table Rates"),
53
+ ),
54
+ array(
55
+ 'value' => 'postnl_tablerate',
56
+ 'label' => $helper->__('Use seperate table rates for PostNL'),
57
+ ),
58
+ );
59
+
60
+ return $options;
61
+ }
62
+ }
app/code/community/TIG/PostNL/Model/Carrier/Tablerate.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * This is a dummy class for the tablerate export/import functionality.
40
+ */
41
+ class TIG_PostNL_Model_Carrier_Tablerate extends Mage_Core_Model_Abstract
42
+ {
43
+ /**
44
+ * Prefix of model events names
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_eventPrefix = 'postnl_carrier_tablerate';
49
+
50
+ public function _construct()
51
+ {
52
+ $this->_init('postnl_carrier/tablerate');
53
+ }
54
+ }
app/code/community/TIG/PostNL/Model/Checkout/Cif.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,8 +33,10 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
38
  */
39
  class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
40
  {
@@ -42,7 +44,7 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
42
  * Webshop ID config option path
43
  */
44
  const XML_PATH_WEBSHOP_ID = 'postnl/cif/webshop_id';
45
-
46
  /**
47
  * XML paths for various options
48
  */
@@ -56,65 +58,71 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
56
  const XML_PATH_SERVICE_URL = 'postnl/checkout/service_url';
57
  const XML_PATH_USE_MOBILE = 'postnl/checkout/use_mobile';
58
  const XML_PATH_USE_DOB = 'postnl/checkout/use_dob';
59
-
60
  /**
61
  * XML path to available payment methods.
62
- * N.B. missing last part os it will return an array of settings
63
  */
64
  const XML_PATH_CHECKOUT_PAYMENT_METHODS = 'postnl/checkout_payment_methods';
65
-
66
  /**
67
  * XML paths for shipment reference info
68
  */
69
  const XML_PATH_SHIPMENT_REFERENCE_TYPE = 'postnl/cif_labels_and_confirming/shipment_reference_type';
70
  const XML_PATH_CUSTOM_SHIPMENT_REFERENCE = 'postnl/cif_labels_and_confirming/custom_shipment_reference';
71
-
72
  /**
73
  * Check if the module is set to test mode
74
- *
75
  * @see TIG_PostNL_Helper_Checkout::isTestMode()
76
- *
 
 
77
  * @return boolean
78
  */
79
  public function isTestMode($storeId = false)
80
  {
 
 
 
 
81
  $testMode = Mage::helper('postnl/checkout')->isTestMode($storeId);
82
-
83
  return $testMode;
84
  }
85
-
86
  /**
87
  * Gets the current store Id
88
- *
89
  * @return integer
90
  */
91
  public function getStoreId()
92
  {
93
- if ($this->getData('store_id')) {
94
  return $this->getData('store_id');
95
  }
96
-
97
  $storeId = Mage::app()->getStore()->getId();
98
-
99
  $this->setStoreId($storeId);
100
  return $storeId;
101
  }
102
-
103
  /**
104
  * Checks if the PostNL service is available
105
- *
106
  * @return string
107
- *
108
  * @throws TIG_PostNL_Exception
109
  */
110
  public function ping()
111
- {
112
  $response = $this->call(
113
- 'checkout',
114
  'PingStatus'
115
  );
116
-
117
- if (!is_object($response)
118
  || !isset($response->Status)
119
  ) {
120
  throw new TIG_PostNL_Exception(
@@ -122,17 +130,17 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
122
  'POSTNL-0038'
123
  );
124
  }
125
-
126
  return $response->Status;
127
  }
128
 
129
  /**
130
  * Prepares a new PostNL checkout order
131
- *
132
  * @param null|Mage_Sales_Model_Quote $quote
133
- *
134
  * @return string
135
- *
136
  * @throws TIG_PostNL_Exception
137
  */
138
  public function prepareOrder($quote = null)
@@ -140,16 +148,16 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
140
  if (is_null($quote)) {
141
  $quote = Mage::getSingleton('checkout/session')->getQuote();
142
  }
143
-
144
  if (!$quote) {
145
  throw new TIG_PostNL_Exception(
146
  Mage::helper('postnl')->__('No quote available to initiate PostNL Checkout.'),
147
  'POSTNL-0039'
148
  );
149
  }
150
-
151
  $this->setStoreId($quote->getStoreId());
152
-
153
  /**
154
  * Get all data required to form the SOAP request
155
  */
@@ -162,50 +170,50 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
162
  $order = $this->_getOrder($quote);
163
  $restrictions = $this->_getRestrictions();
164
  $webshop = $this->_getWebshop();
165
-
166
  $soapParams = array(
167
  'Order' => $order,
168
  'Webshop' => $webshop,
169
  );
170
-
171
  if (!empty($paymentMethods)) {
172
  $soapParams['AangebodenBetaalMethoden'] = $paymentMethods;
173
  }
174
-
175
  if (!empty($communictionOptions)) {
176
  $soapParams['AangebodenCommunicatieOpties'] = $communictionOptions;
177
  }
178
-
179
  if (!empty($restrictions)) {
180
  $soapParams['Restrictions'] = $restrictions;
181
  }
182
-
183
  if ($customer) {
184
  $soapParams['Consument'] = $customer;
185
  }
186
-
187
  if (!empty($optional)) {
188
  $soapParams['Optional'] = $optional;
189
  }
190
-
191
  if ($contact) {
192
  $soapParams['Contact'] = $contact;
193
  }
194
-
195
  if ($service) {
196
  $soapParams['Service'] = $service;
197
  }
198
-
199
  /**
200
  * Send the SOAP request
201
  */
202
  $response = $this->call(
203
- 'checkout',
204
  'PrepareOrder',
205
  $soapParams
206
  );
207
-
208
- if (!is_object($response)
209
  || !isset($response->Checkout)
210
  || !is_object($response->Checkout)
211
  || !isset($response->Checkout->OrderToken)
@@ -215,15 +223,17 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
215
  'POSTNL-0040'
216
  );
217
  }
218
-
219
  return $response;
220
  }
221
 
222
  /**
223
  * Retrieves the data the customer entered for this quote
224
- *
225
  * @param Mage_Sales_Model_Quote $quote
226
- *
 
 
227
  * @return StdClass
228
  */
229
  public function readOrder($quote = null)
@@ -231,48 +241,50 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
231
  if (is_null($quote)) {
232
  $quote = Mage::getSingleton('checkout/session')->getQuote();
233
  }
234
-
235
  if (!$quote) {
236
  throw new TIG_PostNL_Exception(
237
  Mage::helper('postnl')->__('No quote available to initiate PostNL Checkout.'),
238
  'POSTNL-0039'
239
  );
240
  }
241
-
242
  $this->setStoreId($quote->getStoreId());
243
-
244
  $checkout = $this->_getCheckout($quote);
245
  $webshop = $this->_getWebshop();
246
-
247
  $soapParams = array(
248
  'Checkout' => $checkout,
249
  'Webshop' => $webshop,
250
  );
251
-
252
  /**
253
  * Send the SOAP request
254
  */
255
  $response = $this->call(
256
- 'checkout',
257
  'ReadOrder',
258
  $soapParams
259
  );
260
-
261
  if (!is_object($response)) {
262
  throw new TIG_PostNL_Exception(
263
  Mage::helper('postnl')->__('Invalid ReadOrder response: %s', "\n" . var_export($response, true)),
264
  'POSTNL-0041'
265
  );
266
  }
267
-
268
  return $response;
269
  }
270
-
271
  /**
272
  * Confirms the PostNL order.
273
- *
274
- * @param TIG_PostNL_Model_Checkout_Order $postnlOrder
275
- *
 
 
276
  * @return StdClass
277
  */
278
  public function confirmOrder($postnlOrder)
@@ -280,136 +292,138 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
280
  $checkout = $this->_getCheckout($postnlOrder);
281
  $order = $this->_getConfirmOrder($postnlOrder);
282
  $webshop = $this->_getWebshop();
283
-
284
  $soapParams = array(
285
  'Checkout' => $checkout,
286
  'Order' => $order,
287
  'Webshop' => $webshop,
288
  );
289
-
290
  /**
291
  * Send the SOAP request
292
  */
293
  $response = $this->call(
294
- 'checkout',
295
  'ConfirmOrder',
296
  $soapParams
297
  );
298
-
299
  if (!is_object($response)) {
300
  throw new TIG_PostNL_Exception(
301
  Mage::helper('postnl')->__('Invalid ConfirmOrder response: %s', "\n" . var_export($response, true)),
302
  'POSTNL-0042'
303
  );
304
  }
305
-
306
  return $response;
307
  }
308
-
309
  /**
310
  * Updates an order with CIF once a shipment has been confirmed in order to link the shipment to the PostNL CHeckout order
311
- *
312
- * @param TIG_PostNL_Model_Checkout_Order $postnlOrder
313
  * @param boolean $cancel
314
- *
315
  * @return StdClass
316
- *
317
  * @throws TIG_PostNL_Exception
318
  */
319
  public function updateOrder($postnlOrder, $cancel = false)
320
  {
 
 
321
  $order = $this->_getUpdateOrder($postnlOrder, $cancel);
322
  $webshop = $this->_getWebshop();
323
-
324
  $soapParams = array(
325
  'Order' => $order,
326
  'Webshop' => $webshop,
327
  );
328
-
329
  /**
330
  * Send the SOAP request
331
  */
332
  $response = $this->call(
333
- 'checkout',
334
  'UpdateOrder',
335
  $soapParams
336
  );
337
-
338
  if (!is_object($response)) {
339
  throw new TIG_PostNL_Exception(
340
  Mage::helper('postnl')->__('Invalid UpdateOrder response: %s', var_export($response, true)),
341
  'POSTNL-0097'
342
  );
343
  }
344
-
345
  return $response;
346
  }
347
-
348
  /**
349
  * Gets a list of allowed payment methods
350
- *
351
  * @return array
352
  */
353
  protected function _getPaymentMethods()
354
  {
355
  $storeId = $this->getStoreId();
356
-
357
  /**
358
  * Get all payment method configuration options as well as an array of all payment method supported by PostNL
359
  */
360
  $paymentMethods = Mage::getStoreConfig(self::XML_PATH_CHECKOUT_PAYMENT_METHODS, $storeId);
361
  $postnlPaymentMethods = Mage::helper('postnl/checkout')->getCheckoutPaymentMethods();
362
-
363
  $allowedMethods = array();
364
  foreach ($paymentMethods as $method => $value) {
365
  /**
366
- * The $postnlPaymentMethods array uses the configuration option names as keys. So if $method exists as a key in
367
  * $postnlPaymentMethods it's a valid payment method. We then check if it's enabled by checking $value.
368
  */
369
  if (!array_key_exists($method, $postnlPaymentMethods) || !$value) {
370
  continue;
371
  }
372
-
373
  $allowedMethods[] = array(
374
  'Code' => $postnlPaymentMethods[$method],
375
  'Prijs' => '0.00', //additional fees are not supported
376
  );
377
  }
378
-
379
  return $allowedMethods;
380
  }
381
-
382
  /**
383
  * Gets a list of allowed communication options
384
- *
385
  * @return array
386
  */
387
  protected function _getCommunicationOptions()
388
  {
389
  $storeId = $this->getStoreId();
390
-
391
  $communicationOptions = array();
392
-
393
  $newsletterSubscription = Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_SUBSCRIPTION, $storeId);
394
  if ($newsletterSubscription) {
395
  $communicationOptions[] = array(
396
  'Code' => 'NEWS',
397
  );
398
  }
399
-
400
  $remark = Mage::getStoreConfigFlag(self::XML_PATH_REMARK, $storeId);
401
  if ($remark) {
402
  $communicationOptions[] = array(
403
  'Code' => 'REMARK',
404
  );
405
  }
406
-
407
  return $communicationOptions;
408
  }
409
-
410
  /**
411
  * Gets the customer ID if the customer is logged in
412
- *
413
  * @return boolean | array
414
  */
415
  protected function _getCustomer()
@@ -418,83 +432,96 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
418
  if (!$session->isLoggedIn()) {
419
  return false;
420
  }
421
-
422
  $customerId = $session->getCustomerId();
423
  $customer = array(
424
  'ExtRef' => $customerId,
425
  );
426
-
427
  return $customer;
428
  }
429
-
430
  /**
431
  * Gets two optional fields. Both default to false.
432
- *
433
  * @return array
434
  */
435
  protected function _getOptional()
436
  {
437
  $storeId = $this->getStoreId();
438
-
439
- $optional =
440
  array(
441
  'MobileNumber' => 'False',
442
  'BirthDate' => 'False',
443
  );
444
-
445
  $useMobile = Mage::getStoreConfigFlag(self::XML_PATH_USE_MOBILE, $storeId);
446
  if ($useMobile) {
447
  $optional['MobileNumber'] = 'True';
448
  }
449
-
450
  $useDob = Mage::getStoreConfigFlag(self::XML_PATH_USE_DOB, $storeId);
451
  if ($useDob) {
452
  $optional['BirthDate'] = 'True';
453
  }
454
-
455
  return $optional;
456
  }
457
-
458
  /**
459
  * Gets an optional URL of a page where customers can find contact info for this webshop
460
- *
461
  * @return boolean | array
462
  */
463
  protected function _getContact()
464
  {
465
  $storeId = $this->getStoreId();
466
-
467
  $contactUrl = Mage::getStoreConfig(self::XML_PATH_CONTACT_URL, $storeId);
468
  if (!$contactUrl) {
469
  return false;
470
  }
471
-
472
  $contact = array(
473
  'Url' => $contactUrl,
474
  );
475
-
476
  return $contact;
477
  }
478
-
479
  /**
480
  * Builds the Order soap object based on the current quote.
481
- *
482
  * @param Mage_Sales_Model_Quote $quote
483
- *
484
  * @return array
485
- *
486
- * @todo figure out why base_shipping_incl_tax is sometimes empty when shipping_incl_tax is not
487
  */
488
  protected function _getOrder(Mage_Sales_Model_Quote $quote)
489
  {
 
 
 
490
  $shippingAddress = $quote->getShippingAddress();
491
-
 
 
 
 
 
 
 
 
 
 
 
 
492
  $extRef = $quote->getId();
493
  $orderDate = date('d-m-Y H:i:s', Mage::getModel('core/date')->timestamp());
494
- $subtotal = round($shippingAddress->getBaseSubtotalInclTax(), 2);
495
- $shippingDate = $orderDate; //TODO change this to the actual (predicted) shipping date
496
- $shippingCosts = round($shippingAddress->getShippingInclTax() * $quote->getBaseToGlobalRate(), 2); //TODO why is base_shipping_incl_tax sometimes empty?
497
-
498
  $order = array(
499
  'ExtRef' => $extRef,
500
  'OrderDatum' => $orderDate,
@@ -502,76 +529,76 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
502
  'VerzendDatum' => $shippingDate,
503
  'VerzendKosten' => number_format($shippingCosts, 2, '.', ''),
504
  );
505
-
506
  return $order;
507
  }
508
-
509
  /**
510
  * Builds the confirmOrder Order soap object based on the current postnl order.
511
- *
512
- * @param TIG_PostNL_Model_Checkout_Order $postnlOrder
513
- *
514
  * @return array
515
  */
516
  protected function _getConfirmOrder($postnlOrder)
517
  {
518
  $order = $postnlOrder->getOrder();
519
-
520
  $paymentTotal = round($order->getBaseGrandTotal());
521
  $extRef = $order->getIncrementId();
522
  $paymentMethodName = $order->getPayment()->getMethodInstance()->getTitle();
523
-
524
  $confirmOrder = array(
525
  'PaymentTotal' => number_format($paymentTotal, 2, '.', ''),
526
  'ExtRef' => $extRef,
527
  'PaymentMethodName' => $paymentMethodName,
528
  );
529
-
530
  return $confirmOrder;
531
  }
532
-
533
  /**
534
  * Builds the updateOrder Order soap object based on the current postnl order.
535
- *
536
- * @param TIG_PostNL_Model_Checkout_Order $postnlOrder
537
  * @param boolean $cancel
538
- *
539
  * @return array
540
  */
541
  protected function _getUpdateOrder($postnlOrder, $cancel = false)
542
  {
543
  $order = $postnlOrder->getOrder();
544
-
545
  $extRef = $order->getIncrementId();
546
  $shipment = $this->_getShipments($postnlOrder);
547
-
548
  $updateOrder = array(
549
  'ExtRef' => $extRef,
550
  );
551
-
552
  if (!empty($shipment)) {
553
  $updateOrder['Zending'] = $shipment;
554
  }
555
-
556
  if ($cancel) {
557
  $updateOrder['Geannuleerd'] = 'true';
558
  }
559
-
560
  return $updateOrder;
561
  }
562
-
563
  /**
564
  * Gets a list of shipments associated with a PostNL order
565
- *
566
- * @param TIG_PostNL_Model_Checkout_Order $postnlOrder
567
- *
568
  * @return array
569
  */
570
  protected function _getShipments($postnlOrder)
571
  {
572
  $order = $postnlOrder->getOrder();
573
  $shipments = $order->getShipmentsCollection();
574
-
575
  $shipmentData = array();
576
  foreach ($shipments as $shipment) {
577
  $shipmentData[] = array(
@@ -579,27 +606,26 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
579
  'Pakket' => $this->_getParcels($shipment),
580
  );
581
  }
582
-
583
  return $shipmentData;
584
  }
585
-
586
  /**
587
  * Get a shipment's reference. By default this will be the shipment's increment ID
588
- *
589
- * @param Mage_Sales_Model_Order_Shipment
590
- *
591
  * @return string
592
- *
593
  * @throws TIG_PostNL_Exception
594
- *
595
- * @todo shouldn't we save this with the shipment in case the value changes later?
596
  * @todo merge this with TIG_PostNL_Model_Core_Cif::_getReference()
597
  */
598
  protected function _getReference($shipment)
599
  {
600
  $storeId = $this->getStoreId();
601
  $referenceType = Mage::getStoreConfig(self::XML_PATH_SHIPMENT_REFERENCE_TYPE, $storeId);
602
-
603
  /**
604
  * Parse the reference type
605
  */
@@ -623,33 +649,36 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
623
  'POSTNL-0043'
624
  );
625
  }
626
-
627
  /**
628
  * For custom references we need to replace several optional variables
629
  */
630
  if ($referenceType == 'custom') {
631
  $reference = str_replace('{{var shipment_increment_id}}', $shipment->getIncrementId(), $reference);
632
  $reference = str_replace('{{var order_increment_id}}', $shipment->getOrder()->getIncrementId(), $reference);
633
-
634
  $store = Mage::getModel('core/store')->load($storeId);
635
  $reference = str_replace('{{var store_frontend_name}}', $store->getFrontendName(), $reference);
636
  }
637
-
638
  return $reference;
639
  }
640
-
641
  /**
642
  * Gets a list of parcels associated with a shipment
643
- *
644
- * @param Mage_Sales_Model_Order_Shipment
645
- *
646
  * @return array
647
  */
648
  protected function _getParcels($shipment)
649
  {
 
 
 
650
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getid(), 'shipment_id');
651
  $parcelCount = $postnlShipment->getParcelCount();
652
-
653
  $parcelData = array();
654
  $postcode = $shipment->getShippingAddress()->getPostcode();
655
  for ($i = 0; $i < $parcelCount; $i++) {
@@ -661,23 +690,23 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
661
 
662
  return $parcelData;
663
  }
664
-
665
  /**
666
  * Builds the Restrictions soap object based on cofig settings
667
- *
668
  * @return array
669
  */
670
  protected function _getRestrictions()
671
  {
672
  $storeId = $this->getStoreId();
673
-
674
  $restrictions = array();
675
-
676
  $retailLocation = Mage::getStoreConfigFlag(self::XML_PATH_ALLOW_RETAIL_LOCATION, $storeId);
677
  $foreignAddress = Mage::getStoreConfigFlag(self::XML_PATH_ALLOW_FOREIGN_ADDRESS, $storeId);
678
  $priceOverview = Mage::getStoreConfigFlag(self::XML_PATH_ALLOW_PRICE_OVERVIEW, $storeId);
679
  $agreeConditions = Mage::getStoreConfigFlag(self::XML_PATH_AGREE_CONDITIONS, $storeId);
680
-
681
  /**
682
  * If the module cannot use PakjeGemak, retail locations are not allowed in PostNL Checkout
683
  */
@@ -711,45 +740,45 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
711
  } else {
712
  $restrictions['NoAgreeConditions'] = 'false';
713
  }
714
-
715
  return $restrictions;
716
  }
717
-
718
  /**
719
  * Gets an URL linking to the webshop's service info
720
- *
721
- * @return boolean | array
722
  */
723
  protected function _getService()
724
  {
725
  $storeId = $this->getStoreId();
726
-
727
  $serviceUrl = Mage::getStoreConfig(self::XML_PATH_SERVICE_URL, $storeId);
728
  if (!$serviceUrl) {
729
  return false;
730
  }
731
-
732
  $service = array(
733
  'Url' => $serviceUrl,
734
  );
735
-
736
  return $service;
737
  }
738
-
739
  /**
740
  * Gets the order token used to identify a PostNL order
741
- *
742
- * @param Mage_Sales_Model_Quote | TIG_PostNL_Model_Checkout_Order $object
743
- *
744
  * @return array
745
- *
746
  * @throws TIG_PostNL_Exception
747
  */
748
  protected function _getCheckout($object)
749
  {
750
  if ($object instanceof Mage_Sales_Model_Quote) {
751
- $postnlOrder = Mage::getModel('postnl_checkout/order')->load($object->getId(), 'quote_id');
752
- } elseif ($object instanceof TIG_PostNL_Model_Checkout_Order) {
753
  $postnlOrder = $object;
754
  } else {
755
  throw new TIG_PostNL_Exception(
@@ -757,7 +786,7 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
757
  'POSTNL-0044'
758
  );
759
  }
760
-
761
  $orderToken = $postnlOrder->getToken();
762
  if (!$orderToken) {
763
  throw new TIG_PostNL_Exception(
@@ -765,30 +794,30 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
765
  'POSTNL-0045'
766
  );
767
  }
768
-
769
  $checkout = array(
770
  'OrderToken' => $orderToken,
771
  );
772
-
773
  return $checkout;
774
  }
775
-
776
  /**
777
  * Gets the webshop ID for the current store
778
- *
779
  * @return array
780
  */
781
  protected function _getWebshop()
782
  {
783
  $storeId = $this->getStoreId();
784
-
785
  $webshopId = Mage::getStoreConfig(self::XML_PATH_WEBSHOP_ID, $storeId);
786
  $webshopId = Mage::helper('core')->decrypt($webshopId);
787
-
788
  $webshop = array(
789
  'IntRef' => $webshopId,
790
  );
791
-
792
  return $webshop;
793
  }
794
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method TIG_PostNL_Model_Checkout_Cif setStoreId(int $value)
40
  */
41
  class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
42
  {
44
  * Webshop ID config option path
45
  */
46
  const XML_PATH_WEBSHOP_ID = 'postnl/cif/webshop_id';
47
+
48
  /**
49
  * XML paths for various options
50
  */
58
  const XML_PATH_SERVICE_URL = 'postnl/checkout/service_url';
59
  const XML_PATH_USE_MOBILE = 'postnl/checkout/use_mobile';
60
  const XML_PATH_USE_DOB = 'postnl/checkout/use_dob';
61
+
62
  /**
63
  * XML path to available payment methods.
64
+ * N.B. missing last part so it will return an array of settings.
65
  */
66
  const XML_PATH_CHECKOUT_PAYMENT_METHODS = 'postnl/checkout_payment_methods';
67
+
68
  /**
69
  * XML paths for shipment reference info
70
  */
71
  const XML_PATH_SHIPMENT_REFERENCE_TYPE = 'postnl/cif_labels_and_confirming/shipment_reference_type';
72
  const XML_PATH_CUSTOM_SHIPMENT_REFERENCE = 'postnl/cif_labels_and_confirming/custom_shipment_reference';
73
+
74
  /**
75
  * Check if the module is set to test mode
76
+ *
77
  * @see TIG_PostNL_Helper_Checkout::isTestMode()
78
+ *
79
+ * @param bool $storeId
80
+ *
81
  * @return boolean
82
  */
83
  public function isTestMode($storeId = false)
84
  {
85
+ if ($storeId === false) {
86
+ $storeId = $this->getStoreId();
87
+ }
88
+
89
  $testMode = Mage::helper('postnl/checkout')->isTestMode($storeId);
90
+
91
  return $testMode;
92
  }
93
+
94
  /**
95
  * Gets the current store Id
96
+ *
97
  * @return integer
98
  */
99
  public function getStoreId()
100
  {
101
+ if ($this->hasStoreId()) {
102
  return $this->getData('store_id');
103
  }
104
+
105
  $storeId = Mage::app()->getStore()->getId();
106
+
107
  $this->setStoreId($storeId);
108
  return $storeId;
109
  }
110
+
111
  /**
112
  * Checks if the PostNL service is available
113
+ *
114
  * @return string
115
+ *
116
  * @throws TIG_PostNL_Exception
117
  */
118
  public function ping()
119
+ {
120
  $response = $this->call(
121
+ 'checkout',
122
  'PingStatus'
123
  );
124
+
125
+ if (!is_object($response)
126
  || !isset($response->Status)
127
  ) {
128
  throw new TIG_PostNL_Exception(
130
  'POSTNL-0038'
131
  );
132
  }
133
+
134
  return $response->Status;
135
  }
136
 
137
  /**
138
  * Prepares a new PostNL checkout order
139
+ *
140
  * @param null|Mage_Sales_Model_Quote $quote
141
+ *
142
  * @return string
143
+ *
144
  * @throws TIG_PostNL_Exception
145
  */
146
  public function prepareOrder($quote = null)
148
  if (is_null($quote)) {
149
  $quote = Mage::getSingleton('checkout/session')->getQuote();
150
  }
151
+
152
  if (!$quote) {
153
  throw new TIG_PostNL_Exception(
154
  Mage::helper('postnl')->__('No quote available to initiate PostNL Checkout.'),
155
  'POSTNL-0039'
156
  );
157
  }
158
+
159
  $this->setStoreId($quote->getStoreId());
160
+
161
  /**
162
  * Get all data required to form the SOAP request
163
  */
170
  $order = $this->_getOrder($quote);
171
  $restrictions = $this->_getRestrictions();
172
  $webshop = $this->_getWebshop();
173
+
174
  $soapParams = array(
175
  'Order' => $order,
176
  'Webshop' => $webshop,
177
  );
178
+
179
  if (!empty($paymentMethods)) {
180
  $soapParams['AangebodenBetaalMethoden'] = $paymentMethods;
181
  }
182
+
183
  if (!empty($communictionOptions)) {
184
  $soapParams['AangebodenCommunicatieOpties'] = $communictionOptions;
185
  }
186
+
187
  if (!empty($restrictions)) {
188
  $soapParams['Restrictions'] = $restrictions;
189
  }
190
+
191
  if ($customer) {
192
  $soapParams['Consument'] = $customer;
193
  }
194
+
195
  if (!empty($optional)) {
196
  $soapParams['Optional'] = $optional;
197
  }
198
+
199
  if ($contact) {
200
  $soapParams['Contact'] = $contact;
201
  }
202
+
203
  if ($service) {
204
  $soapParams['Service'] = $service;
205
  }
206
+
207
  /**
208
  * Send the SOAP request
209
  */
210
  $response = $this->call(
211
+ 'checkout',
212
  'PrepareOrder',
213
  $soapParams
214
  );
215
+
216
+ if (!is_object($response)
217
  || !isset($response->Checkout)
218
  || !is_object($response->Checkout)
219
  || !isset($response->Checkout->OrderToken)
223
  'POSTNL-0040'
224
  );
225
  }
226
+
227
  return $response;
228
  }
229
 
230
  /**
231
  * Retrieves the data the customer entered for this quote
232
+ *
233
  * @param Mage_Sales_Model_Quote $quote
234
+ *
235
+ * @throws TIG_PostNL_Exception
236
+ *
237
  * @return StdClass
238
  */
239
  public function readOrder($quote = null)
241
  if (is_null($quote)) {
242
  $quote = Mage::getSingleton('checkout/session')->getQuote();
243
  }
244
+
245
  if (!$quote) {
246
  throw new TIG_PostNL_Exception(
247
  Mage::helper('postnl')->__('No quote available to initiate PostNL Checkout.'),
248
  'POSTNL-0039'
249
  );
250
  }
251
+
252
  $this->setStoreId($quote->getStoreId());
253
+
254
  $checkout = $this->_getCheckout($quote);
255
  $webshop = $this->_getWebshop();
256
+
257
  $soapParams = array(
258
  'Checkout' => $checkout,
259
  'Webshop' => $webshop,
260
  );
261
+
262
  /**
263
  * Send the SOAP request
264
  */
265
  $response = $this->call(
266
+ 'checkout',
267
  'ReadOrder',
268
  $soapParams
269
  );
270
+
271
  if (!is_object($response)) {
272
  throw new TIG_PostNL_Exception(
273
  Mage::helper('postnl')->__('Invalid ReadOrder response: %s', "\n" . var_export($response, true)),
274
  'POSTNL-0041'
275
  );
276
  }
277
+
278
  return $response;
279
  }
280
+
281
  /**
282
  * Confirms the PostNL order.
283
+ *
284
+ * @param TIG_PostNL_Model_Core_Order $postnlOrder
285
+ *
286
+ * @throws TIG_PostNL_Exception
287
+ *
288
  * @return StdClass
289
  */
290
  public function confirmOrder($postnlOrder)
292
  $checkout = $this->_getCheckout($postnlOrder);
293
  $order = $this->_getConfirmOrder($postnlOrder);
294
  $webshop = $this->_getWebshop();
295
+
296
  $soapParams = array(
297
  'Checkout' => $checkout,
298
  'Order' => $order,
299
  'Webshop' => $webshop,
300
  );
301
+
302
  /**
303
  * Send the SOAP request
304
  */
305
  $response = $this->call(
306
+ 'checkout',
307
  'ConfirmOrder',
308
  $soapParams
309
  );
310
+
311
  if (!is_object($response)) {
312
  throw new TIG_PostNL_Exception(
313
  Mage::helper('postnl')->__('Invalid ConfirmOrder response: %s', "\n" . var_export($response, true)),
314
  'POSTNL-0042'
315
  );
316
  }
317
+
318
  return $response;
319
  }
320
+
321
  /**
322
  * Updates an order with CIF once a shipment has been confirmed in order to link the shipment to the PostNL CHeckout order
323
+ *
324
+ * @param TIG_PostNL_Model_Core_Order $postnlOrder
325
  * @param boolean $cancel
326
+ *
327
  * @return StdClass
328
+ *
329
  * @throws TIG_PostNL_Exception
330
  */
331
  public function updateOrder($postnlOrder, $cancel = false)
332
  {
333
+ $this->setStoreId($postnlOrder->getOrder()->getStoreId());
334
+
335
  $order = $this->_getUpdateOrder($postnlOrder, $cancel);
336
  $webshop = $this->_getWebshop();
337
+
338
  $soapParams = array(
339
  'Order' => $order,
340
  'Webshop' => $webshop,
341
  );
342
+
343
  /**
344
  * Send the SOAP request
345
  */
346
  $response = $this->call(
347
+ 'checkout',
348
  'UpdateOrder',
349
  $soapParams
350
  );
351
+
352
  if (!is_object($response)) {
353
  throw new TIG_PostNL_Exception(
354
  Mage::helper('postnl')->__('Invalid UpdateOrder response: %s', var_export($response, true)),
355
  'POSTNL-0097'
356
  );
357
  }
358
+
359
  return $response;
360
  }
361
+
362
  /**
363
  * Gets a list of allowed payment methods
364
+ *
365
  * @return array
366
  */
367
  protected function _getPaymentMethods()
368
  {
369
  $storeId = $this->getStoreId();
370
+
371
  /**
372
  * Get all payment method configuration options as well as an array of all payment method supported by PostNL
373
  */
374
  $paymentMethods = Mage::getStoreConfig(self::XML_PATH_CHECKOUT_PAYMENT_METHODS, $storeId);
375
  $postnlPaymentMethods = Mage::helper('postnl/checkout')->getCheckoutPaymentMethods();
376
+
377
  $allowedMethods = array();
378
  foreach ($paymentMethods as $method => $value) {
379
  /**
380
+ * The $postnlPaymentMethods array uses the configuration option names as keys. So if $method exists as a key in
381
  * $postnlPaymentMethods it's a valid payment method. We then check if it's enabled by checking $value.
382
  */
383
  if (!array_key_exists($method, $postnlPaymentMethods) || !$value) {
384
  continue;
385
  }
386
+
387
  $allowedMethods[] = array(
388
  'Code' => $postnlPaymentMethods[$method],
389
  'Prijs' => '0.00', //additional fees are not supported
390
  );
391
  }
392
+
393
  return $allowedMethods;
394
  }
395
+
396
  /**
397
  * Gets a list of allowed communication options
398
+ *
399
  * @return array
400
  */
401
  protected function _getCommunicationOptions()
402
  {
403
  $storeId = $this->getStoreId();
404
+
405
  $communicationOptions = array();
406
+
407
  $newsletterSubscription = Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_SUBSCRIPTION, $storeId);
408
  if ($newsletterSubscription) {
409
  $communicationOptions[] = array(
410
  'Code' => 'NEWS',
411
  );
412
  }
413
+
414
  $remark = Mage::getStoreConfigFlag(self::XML_PATH_REMARK, $storeId);
415
  if ($remark) {
416
  $communicationOptions[] = array(
417
  'Code' => 'REMARK',
418
  );
419
  }
420
+
421
  return $communicationOptions;
422
  }
423
+
424
  /**
425
  * Gets the customer ID if the customer is logged in
426
+ *
427
  * @return boolean | array
428
  */
429
  protected function _getCustomer()
432
  if (!$session->isLoggedIn()) {
433
  return false;
434
  }
435
+
436
  $customerId = $session->getCustomerId();
437
  $customer = array(
438
  'ExtRef' => $customerId,
439
  );
440
+
441
  return $customer;
442
  }
443
+
444
  /**
445
  * Gets two optional fields. Both default to false.
446
+ *
447
  * @return array
448
  */
449
  protected function _getOptional()
450
  {
451
  $storeId = $this->getStoreId();
452
+
453
+ $optional =
454
  array(
455
  'MobileNumber' => 'False',
456
  'BirthDate' => 'False',
457
  );
458
+
459
  $useMobile = Mage::getStoreConfigFlag(self::XML_PATH_USE_MOBILE, $storeId);
460
  if ($useMobile) {
461
  $optional['MobileNumber'] = 'True';
462
  }
463
+
464
  $useDob = Mage::getStoreConfigFlag(self::XML_PATH_USE_DOB, $storeId);
465
  if ($useDob) {
466
  $optional['BirthDate'] = 'True';
467
  }
468
+
469
  return $optional;
470
  }
471
+
472
  /**
473
  * Gets an optional URL of a page where customers can find contact info for this webshop
474
+ *
475
  * @return boolean | array
476
  */
477
  protected function _getContact()
478
  {
479
  $storeId = $this->getStoreId();
480
+
481
  $contactUrl = Mage::getStoreConfig(self::XML_PATH_CONTACT_URL, $storeId);
482
  if (!$contactUrl) {
483
  return false;
484
  }
485
+
486
  $contact = array(
487
  'Url' => $contactUrl,
488
  );
489
+
490
  return $contact;
491
  }
492
+
493
  /**
494
  * Builds the Order soap object based on the current quote.
495
+ *
496
  * @param Mage_Sales_Model_Quote $quote
497
+ *
498
  * @return array
 
 
499
  */
500
  protected function _getOrder(Mage_Sales_Model_Quote $quote)
501
  {
502
+ /**
503
+ * @var Mage_Sales_Model_Quote_Address $shippingAddress
504
+ */
505
  $shippingAddress = $quote->getShippingAddress();
506
+ $baseSubtotalIncltax = $shippingAddress->getBaseSubtotalTotalInclTax();
507
+ if ($baseSubtotalIncltax === null) {
508
+ $baseSubtotalIncltax = $shippingAddress->getBaseSubtotalWithDiscount()
509
+ + $shippingAddress->getBaseTaxAmount()
510
+ - $shippingAddress->getBaseShippingTaxAmount();
511
+ }
512
+
513
+ $baseShippingAmount = $shippingAddress->getBaseShippingInclTax();
514
+ if ($baseShippingAmount === null) {
515
+ $baseShippingAmount = $shippingAddress->getBaseShippingAmount()
516
+ + $shippingAddress->getBaseShippingTaxAmount();
517
+ }
518
+
519
  $extRef = $quote->getId();
520
  $orderDate = date('d-m-Y H:i:s', Mage::getModel('core/date')->timestamp());
521
+ $subtotal = round($baseSubtotalIncltax, 2);
522
+ $shippingDate = $orderDate;
523
+ $shippingCosts = round($baseShippingAmount, 2);
524
+
525
  $order = array(
526
  'ExtRef' => $extRef,
527
  'OrderDatum' => $orderDate,
529
  'VerzendDatum' => $shippingDate,
530
  'VerzendKosten' => number_format($shippingCosts, 2, '.', ''),
531
  );
532
+
533
  return $order;
534
  }
535
+
536
  /**
537
  * Builds the confirmOrder Order soap object based on the current postnl order.
538
+ *
539
+ * @param TIG_PostNL_Model_Core_Order $postnlOrder
540
+ *
541
  * @return array
542
  */
543
  protected function _getConfirmOrder($postnlOrder)
544
  {
545
  $order = $postnlOrder->getOrder();
546
+
547
  $paymentTotal = round($order->getBaseGrandTotal());
548
  $extRef = $order->getIncrementId();
549
  $paymentMethodName = $order->getPayment()->getMethodInstance()->getTitle();
550
+
551
  $confirmOrder = array(
552
  'PaymentTotal' => number_format($paymentTotal, 2, '.', ''),
553
  'ExtRef' => $extRef,
554
  'PaymentMethodName' => $paymentMethodName,
555
  );
556
+
557
  return $confirmOrder;
558
  }
559
+
560
  /**
561
  * Builds the updateOrder Order soap object based on the current postnl order.
562
+ *
563
+ * @param TIG_PostNL_Model_Core_Order $postnlOrder
564
  * @param boolean $cancel
565
+ *
566
  * @return array
567
  */
568
  protected function _getUpdateOrder($postnlOrder, $cancel = false)
569
  {
570
  $order = $postnlOrder->getOrder();
571
+
572
  $extRef = $order->getIncrementId();
573
  $shipment = $this->_getShipments($postnlOrder);
574
+
575
  $updateOrder = array(
576
  'ExtRef' => $extRef,
577
  );
578
+
579
  if (!empty($shipment)) {
580
  $updateOrder['Zending'] = $shipment;
581
  }
582
+
583
  if ($cancel) {
584
  $updateOrder['Geannuleerd'] = 'true';
585
  }
586
+
587
  return $updateOrder;
588
  }
589
+
590
  /**
591
  * Gets a list of shipments associated with a PostNL order
592
+ *
593
+ * @param TIG_PostNL_Model_Core_Order $postnlOrder
594
+ *
595
  * @return array
596
  */
597
  protected function _getShipments($postnlOrder)
598
  {
599
  $order = $postnlOrder->getOrder();
600
  $shipments = $order->getShipmentsCollection();
601
+
602
  $shipmentData = array();
603
  foreach ($shipments as $shipment) {
604
  $shipmentData[] = array(
606
  'Pakket' => $this->_getParcels($shipment),
607
  );
608
  }
609
+
610
  return $shipmentData;
611
  }
612
+
613
  /**
614
  * Get a shipment's reference. By default this will be the shipment's increment ID
615
+ *
616
+ * @param Mage_Sales_Model_Order_Shipment $shipment
617
+ *
618
  * @return string
619
+ *
620
  * @throws TIG_PostNL_Exception
621
+ *
 
622
  * @todo merge this with TIG_PostNL_Model_Core_Cif::_getReference()
623
  */
624
  protected function _getReference($shipment)
625
  {
626
  $storeId = $this->getStoreId();
627
  $referenceType = Mage::getStoreConfig(self::XML_PATH_SHIPMENT_REFERENCE_TYPE, $storeId);
628
+
629
  /**
630
  * Parse the reference type
631
  */
649
  'POSTNL-0043'
650
  );
651
  }
652
+
653
  /**
654
  * For custom references we need to replace several optional variables
655
  */
656
  if ($referenceType == 'custom') {
657
  $reference = str_replace('{{var shipment_increment_id}}', $shipment->getIncrementId(), $reference);
658
  $reference = str_replace('{{var order_increment_id}}', $shipment->getOrder()->getIncrementId(), $reference);
659
+
660
  $store = Mage::getModel('core/store')->load($storeId);
661
  $reference = str_replace('{{var store_frontend_name}}', $store->getFrontendName(), $reference);
662
  }
663
+
664
  return $reference;
665
  }
666
+
667
  /**
668
  * Gets a list of parcels associated with a shipment
669
+ *
670
+ * @param Mage_Sales_Model_Order_Shipment $shipment
671
+ *
672
  * @return array
673
  */
674
  protected function _getParcels($shipment)
675
  {
676
+ /**
677
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipment
678
+ */
679
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getid(), 'shipment_id');
680
  $parcelCount = $postnlShipment->getParcelCount();
681
+
682
  $parcelData = array();
683
  $postcode = $shipment->getShippingAddress()->getPostcode();
684
  for ($i = 0; $i < $parcelCount; $i++) {
690
 
691
  return $parcelData;
692
  }
693
+
694
  /**
695
  * Builds the Restrictions soap object based on cofig settings
696
+ *
697
  * @return array
698
  */
699
  protected function _getRestrictions()
700
  {
701
  $storeId = $this->getStoreId();
702
+
703
  $restrictions = array();
704
+
705
  $retailLocation = Mage::getStoreConfigFlag(self::XML_PATH_ALLOW_RETAIL_LOCATION, $storeId);
706
  $foreignAddress = Mage::getStoreConfigFlag(self::XML_PATH_ALLOW_FOREIGN_ADDRESS, $storeId);
707
  $priceOverview = Mage::getStoreConfigFlag(self::XML_PATH_ALLOW_PRICE_OVERVIEW, $storeId);
708
  $agreeConditions = Mage::getStoreConfigFlag(self::XML_PATH_AGREE_CONDITIONS, $storeId);
709
+
710
  /**
711
  * If the module cannot use PakjeGemak, retail locations are not allowed in PostNL Checkout
712
  */
740
  } else {
741
  $restrictions['NoAgreeConditions'] = 'false';
742
  }
743
+
744
  return $restrictions;
745
  }
746
+
747
  /**
748
  * Gets an URL linking to the webshop's service info
749
+ *
750
+ * @return boolean|array
751
  */
752
  protected function _getService()
753
  {
754
  $storeId = $this->getStoreId();
755
+
756
  $serviceUrl = Mage::getStoreConfig(self::XML_PATH_SERVICE_URL, $storeId);
757
  if (!$serviceUrl) {
758
  return false;
759
  }
760
+
761
  $service = array(
762
  'Url' => $serviceUrl,
763
  );
764
+
765
  return $service;
766
  }
767
+
768
  /**
769
  * Gets the order token used to identify a PostNL order
770
+ *
771
+ * @param Mage_Sales_Model_Quote|TIG_PostNL_Model_Core_Order $object
772
+ *
773
  * @return array
774
+ *
775
  * @throws TIG_PostNL_Exception
776
  */
777
  protected function _getCheckout($object)
778
  {
779
  if ($object instanceof Mage_Sales_Model_Quote) {
780
+ $postnlOrder = Mage::getModel('postnl_core/order')->load($object->getId(), 'quote_id');
781
+ } elseif ($object instanceof TIG_PostNL_Model_Core_Order) {
782
  $postnlOrder = $object;
783
  } else {
784
  throw new TIG_PostNL_Exception(
786
  'POSTNL-0044'
787
  );
788
  }
789
+
790
  $orderToken = $postnlOrder->getToken();
791
  if (!$orderToken) {
792
  throw new TIG_PostNL_Exception(
794
  'POSTNL-0045'
795
  );
796
  }
797
+
798
  $checkout = array(
799
  'OrderToken' => $orderToken,
800
  );
801
+
802
  return $checkout;
803
  }
804
+
805
  /**
806
  * Gets the webshop ID for the current store
807
+ *
808
  * @return array
809
  */
810
  protected function _getWebshop()
811
  {
812
  $storeId = $this->getStoreId();
813
+
814
  $webshopId = Mage::getStoreConfig(self::XML_PATH_WEBSHOP_ID, $storeId);
815
  $webshopId = Mage::helper('core')->decrypt($webshopId);
816
+
817
  $webshop = array(
818
  'IntRef' => $webshopId,
819
  );
820
+
821
  return $webshop;
822
  }
823
  }
app/code/community/TIG/PostNL/Model/Checkout/Observer/Order.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,38 +33,42 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Checkout_Observer_Order
40
  {
41
  /**
42
- * Cancels a PostNL Checkout order
43
- *
44
  * @param Varien_Event_Observer $observer
45
- *
46
  * @return TIG_PostNL_Model_Checkout_Observer_Order
47
- *
48
  * @event order_cancel_after
49
- *
50
  * @observer postnl_cancel_checkout_order
51
  */
52
  public function cancelOrder(Varien_Event_Observer $observer)
53
  {
 
 
 
 
54
  $order = $observer->getOrder();
55
- $postnlOrder = Mage::getModel('postnl_checkout/order')->load($order->getId(), 'order_id');
56
-
57
- if (!$postnlOrder->getId()) {
58
  return $this;
59
  }
60
-
61
  try {
62
  $postnlOrder->cancel()
63
  ->save();
64
  } catch (Exception $e) {
65
  Mage::helper('postnl/checkout')->logException($e);
66
  }
67
-
68
  return $this;
69
  }
70
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Checkout_Observer_Order
40
  {
41
  /**
42
+ * Cancels a PostNL Checkout order after it's Magento order has been cancelled.
43
+ *
44
  * @param Varien_Event_Observer $observer
45
+ *
46
  * @return TIG_PostNL_Model_Checkout_Observer_Order
47
+ *
48
  * @event order_cancel_after
49
+ *
50
  * @observer postnl_cancel_checkout_order
51
  */
52
  public function cancelOrder(Varien_Event_Observer $observer)
53
  {
54
+ /**
55
+ * @var Mage_Sales_Model_Order $order
56
+ * @var TIG_PostNL_Model_Core_Order $postnlOrder
57
+ */
58
  $order = $observer->getOrder();
59
+ $postnlOrder = Mage::getModel('postnl_core/order')->load($order->getId(), 'order_id');
60
+
61
+ if (!$postnlOrder->getId() || !$postnlOrder->getToken()) {
62
  return $this;
63
  }
64
+
65
  try {
66
  $postnlOrder->cancel()
67
  ->save();
68
  } catch (Exception $e) {
69
  Mage::helper('postnl/checkout')->logException($e);
70
  }
71
+
72
  return $this;
73
  }
74
  }
app/code/community/TIG/PostNL/Model/Checkout/Observer/Shipment.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Checkout_Observer_Shipment
@@ -42,42 +42,45 @@ class TIG_PostNL_Model_Checkout_Observer_Shipment
42
  * Updates a PostNL Checkout order with CIF. This has to occur after a shipment is confirmed. If an order has multiple
43
  * shipments, this has to happen every time a shipment is confirmed. Each time the request will contain and additional
44
  * shipment each having 1 or more parcels.
45
- *
46
  * @param Varien_Event_Observer $observer
47
- *
48
  * @return TIG_PostNL_Model_Core_Observer_Barcode
49
- *
50
  * @event postnl_shipment_confirm_after
51
- *
52
  * @observer postnl_checkout_update_order
53
- *
54
  * @throws TIG_PostNL_Exception
55
  */
56
  public function updateOrder(Varien_Event_Observer $observer)
57
  {
 
 
 
58
  $postnlShipment = $observer->getShipment();
59
-
60
  $orderId = $postnlShipment->getOrderId();
61
- $postnlOrder = Mage::getModel('postnl_checkout/order');
62
  $postnlOrder->load($orderId, 'order_id');
63
- if (!$postnlOrder->getId()) {
64
  return $this;
65
  }
66
-
67
  try {
68
  $cif = Mage::getModel('postnl_checkout/cif');
69
  $result = $cif->updateOrder($postnlOrder);
70
-
71
  if (!isset($result->Succes) || $result->Succes != 'true') {
72
  throw new TIG_PostNL_Exception(
73
  Mage::helper('postnl')->__('Invalid UpdateOrder response received!'),
74
  'POSTNL-0037'
75
  );
76
  }
77
- } catch (TIG_PostNL_CIF_Exception $e) {
78
  $helper = Mage::helper('postnl');
79
  $helper->addSessionMessage(
80
- 'adminhtml/session',
81
  'POSTNL-0113',
82
  'notice',
83
  $helper->__('An error occurred while updating the PostNL Checkout order: %s', $e->getMessage())
@@ -86,14 +89,14 @@ class TIG_PostNL_Model_Checkout_Observer_Shipment
86
  } catch (Exception $e) {
87
  $helper = Mage::helper('postnl');
88
  $helper->addSessionMessage(
89
- 'adminhtml/session',
90
  'POSTNL-0113',
91
  'notice',
92
  $helper->__('An error occurred while updating the PostNL Checkout order.')
93
  );
94
  return $this;
95
  }
96
-
97
  return $this;
98
  }
99
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Checkout_Observer_Shipment
42
  * Updates a PostNL Checkout order with CIF. This has to occur after a shipment is confirmed. If an order has multiple
43
  * shipments, this has to happen every time a shipment is confirmed. Each time the request will contain and additional
44
  * shipment each having 1 or more parcels.
45
+ *
46
  * @param Varien_Event_Observer $observer
47
+ *
48
  * @return TIG_PostNL_Model_Core_Observer_Barcode
49
+ *
50
  * @event postnl_shipment_confirm_after
51
+ *
52
  * @observer postnl_checkout_update_order
53
+ *
54
  * @throws TIG_PostNL_Exception
55
  */
56
  public function updateOrder(Varien_Event_Observer $observer)
57
  {
58
+ /**
59
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipment
60
+ */
61
  $postnlShipment = $observer->getShipment();
62
+
63
  $orderId = $postnlShipment->getOrderId();
64
+ $postnlOrder = Mage::getModel('postnl_core/order');
65
  $postnlOrder->load($orderId, 'order_id');
66
+ if (!$postnlOrder->getId() || !$postnlOrder->getToken()) {
67
  return $this;
68
  }
69
+
70
  try {
71
  $cif = Mage::getModel('postnl_checkout/cif');
72
  $result = $cif->updateOrder($postnlOrder);
73
+
74
  if (!isset($result->Succes) || $result->Succes != 'true') {
75
  throw new TIG_PostNL_Exception(
76
  Mage::helper('postnl')->__('Invalid UpdateOrder response received!'),
77
  'POSTNL-0037'
78
  );
79
  }
80
+ } catch (TIG_PostNL_Exception $e) {
81
  $helper = Mage::helper('postnl');
82
  $helper->addSessionMessage(
83
+ 'adminhtml/session',
84
  'POSTNL-0113',
85
  'notice',
86
  $helper->__('An error occurred while updating the PostNL Checkout order: %s', $e->getMessage())
89
  } catch (Exception $e) {
90
  $helper = Mage::helper('postnl');
91
  $helper->addSessionMessage(
92
+ 'adminhtml/session',
93
  'POSTNL-0113',
94
  'notice',
95
  $helper->__('An error occurred while updating the PostNL Checkout order.')
96
  );
97
  return $this;
98
  }
99
+
100
  return $this;
101
  }
102
  }
app/code/community/TIG/PostNL/Model/Checkout/Order.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,128 +33,13 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
38
  */
39
- class TIG_PostNL_Model_Checkout_Order extends Mage_Core_Model_Abstract
40
  {
41
- /**
42
- * Prefix of model events names
43
- *
44
- * @var string
45
- */
46
- protected $_eventPrefix = 'postnl_order';
47
-
48
- public function _construct()
49
- {
50
- $this->_init('postnl_checkout/order');
51
- }
52
-
53
- /**
54
- * Gets the order associated with this PostNL Checkout Order
55
- *
56
- * @return Mage_Sales_Model_Order | null
57
- */
58
- public function getOrder()
59
- {
60
- if ($this->getData('order')) {
61
- return $this->getData('order');
62
- }
63
-
64
- if (!$this->getOrderId()) {
65
- return null;
66
- }
67
-
68
- $order = Mage::getModel('sales/order')->load($this->getOrderId());
69
-
70
- $this->setOrder($order);
71
- return $order;
72
- }
73
-
74
- /**
75
- * Gets the quote associated with this PostNL Checkout Order
76
- *
77
- * @return Mage_Sales_Model_Quote | null
78
- */
79
- public function getQuote()
80
- {
81
- if ($this->getData('quote')) {
82
- return $this->getData('quote');
83
- }
84
-
85
- if (!$this-getQuoteId()) {
86
- return null;
87
- }
88
-
89
- $order = Mage::getModel('sales/quote')->load($this->getQuoteId());
90
-
91
- $this->setQuote($order);
92
- return $order;
93
- }
94
-
95
- /**
96
- * Alias for magic getToken()
97
- *
98
- * @return string
99
- */
100
- public function getOrderToken()
101
- {
102
- return $this->getToken();
103
- }
104
-
105
- /**
106
- * Alias for magic getQuoteId()
107
- *
108
- * @return int
109
- */
110
- public function getExtRef()
111
- {
112
- return $this->getQuoteId();
113
- }
114
-
115
- /**
116
- * Cancels the PostNL order
117
- *
118
- * @return TIG_PostNL_Model_Checkout_Order
119
- *
120
- * @throws TIG_PostNL_Exception
121
- */
122
- public function cancel()
123
- {
124
- $helper = Mage::helper('postnl');
125
- if (!$this->getOrderId()) {
126
- throw new TIG_PostNL_Exception(
127
- $helper->__('This PostNL Checkout order cannot be cancelled: it has no associated magento order.'),
128
- 'POSTNL-0046'
129
- );
130
- }
131
 
132
- if ($this->getIsCanceled()) {
133
- throw new TIG_PostNL_Exception(
134
- $helper->__('This PostNL Checkout order cannot be cancelled: it has already been canceled.'),
135
- 'POSTNL-0047'
136
- );
137
- }
138
-
139
- $cif = Mage::getModel('postnl_checkout/cif');
140
- $cif->updateOrder($this, true);
141
-
142
- $this->setIsCanceled(true);
143
-
144
- return $this;
145
- }
146
-
147
- /**
148
- * Sets new PostNL Orders to active before saving
149
- *
150
- * @return Mage_Core_Model_Abstract::_beforeSave();
151
- */
152
- protected function _beforeSave()
153
- {
154
- if ($this->isObjectNew()) {
155
- $this->setIsActive(1);
156
- }
157
-
158
- return parent::_beforeSave();
159
- }
160
- }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @deprecated 1.2.0 This class has been moved to TIG_PostNL_Model_Core_Order. A dummy class has been left behind to
40
+ * provide backwards compatibility. This class may be removed in the future without further notice.
41
  */
42
+ class TIG_PostNL_Model_Checkout_Order extends TIG_PostNL_Model_Core_Order
43
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/TIG/PostNL/Model/Checkout/Service.php CHANGED
@@ -1,868 +1,972 @@
1
- <?php
2
- /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
- * | | / _ \\ __\\__ \ | |
6
- * | | | |_| || | / __ \_| |__
7
- * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
- * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
- * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
- *
22
- * NOTICE OF LICENSE
23
- *
24
- * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
- * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
- * If you are unable to obtain it through the world-wide-web, please send an email
28
- * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
- *
30
- * DISCLAIMER
31
- *
32
- * Do not edit or add to this file if you wish to upgrade this module to newer
33
- * versions in the future. If you wish to customize this module for your
34
- * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
- *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
- * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
- */
39
- class TIG_PostNL_Model_Checkout_Service extends Varien_Object
40
- {
41
- /**
42
- * XML path to public webshop ID setting
43
- */
44
- const XML_PATH_WEBSHOP_ID = 'postnl/cif/webshop_id';
45
-
46
- /**
47
- * Constants containing XML paths to cif address configuration options
48
- */
49
- const XML_PATH_SPLIT_STREET = 'postnl/cif_address/split_street';
50
- const XML_PATH_STREETNAME_FIELD = 'postnl/cif_address/streetname_field';
51
- const XML_PATH_HOUSENUMBER_FIELD = 'postnl/cif_address/housenr_field';
52
- const XML_PATH_SPLIT_HOUSENUMBER = 'postnl/cif_address/split_housenr';
53
- const XML_PATH_HOUSENUMBER_EXTENSION_FIELD = 'postnl/cif_address/housenr_extension_field';
54
- const XML_PATH_AREA_FIELD = 'postnl/cif_address/area_field';
55
- const XML_PATH_BUILDING_NAME_FIELD = 'postnl/cif_address/building_name_field';
56
- const XML_PATH_DEPARTMENT_FIELD = 'postnl/cif_address/department_field';
57
- const XML_PATH_DOORCODE_FIELD = 'postnl/cif_address/doorcode_field';
58
- const XML_PATH_FLOOR_FIELD = 'postnl/cif_address/floor_field';
59
- const XML_PATH_REMARK_FIELD = 'postnl/cif_address/remark_field';
60
-
61
- /**
62
- * XML path to all PostNL Checkout payment settings
63
- * N.B. missing last part os it will return an array of settings
64
- */
65
- const XML_PATH_PAYMENT_METHODS = 'postnl/checkout_payment_methods';
66
-
67
- /**
68
- * Newly added 'pakje_gemak' address type
69
- */
70
- const ADDRESS_TYPE_PAKJEGEMAK = 'pakje_gemak';
71
-
72
- /**
73
- * Gets the currently used quote object
74
- *
75
- * @return Mage_Sales_Model_Quote
76
- */
77
- public function getQuote()
78
- {
79
- if ($this->getData('quote')) {
80
- return $this->getData('quote');
81
- }
82
-
83
- $quote = Mage::getSingleton('checkout/session')->getQuote();
84
-
85
- $this->setQuote($quote);
86
- return $quote;
87
- }
88
-
89
- /**
90
- * Updates a quote with the given PostNL order data. Each part of the data is used to replace the data normally acquired
91
- * during checkout.
92
- *
93
- * @param StdClass $data
94
- * @param Mage_Sales_Model_Quote | null $quote
95
- *
96
- * @return TIG_PostNL_Model_Checkout_Service
97
- *
98
- * @throws TIG_PostNL_Exception
99
- */
100
- public function updateQuoteAddresses($data, $quote = null)
101
- {
102
- /**
103
- * Load the current quote if none was supplied
104
- */
105
- if (is_null($quote)) {
106
- $quote = $this->getQuote();
107
- }
108
-
109
- $this->setStoreId($quote->getStoreId());
110
-
111
- $this->_verifyData($data, $quote);
112
-
113
- /**
114
- * Get consumer data
115
- */
116
- $consumer = $data->Consument;
117
- $email = $consumer->Email;
118
- $phone = $consumer->TelefoonNummer;
119
- if (!$phone) {
120
- $phone = '-';
121
- } else {
122
- $phone = preg_replace("/[^0-9]/", '', $phone);
123
- }
124
-
125
- /**
126
- * Remove all existing addresses, we're going to add new ones
127
- */
128
- $this->_removeAllQuoteAddresses($quote);
129
-
130
- /**
131
- * Parse the shippingaddresses
132
- */
133
- $delivery = $data->Bezorging;
134
- $shippingAddressData = $delivery->Geadresseerde;
135
-
136
- $shippingAddress = Mage::getModel('sales/quote_address');
137
- $shippingAddress->setAddressType($shippingAddress::TYPE_SHIPPING)
138
- ->setEmail($email)
139
- ->setPhone($phone);
140
-
141
- $shippingAddress = $this->_parseAddress($shippingAddress, $shippingAddressData);
142
-
143
- $shippingMethod = Mage::helper('postnl/carrier')->getCurrentPostnlShippingMethod();
144
- if (!$shippingAddress->getShippingMethod()) {
145
- $shippingAddress->setCollectShippingRates(true)
146
- ->setShippingMethod($shippingMethod);
147
- }
148
-
149
- /**
150
- * Parse the billing address
151
- */
152
- $billingAddressData = $data->Facturatie->Adres;
153
- $billingAddress = Mage::getModel('sales/quote_address');
154
- $billingAddress->setAddressType($billingAddress::TYPE_BILLING)
155
- ->setEmail($email)
156
- ->setPhone($phone);
157
-
158
- $billingAddress = $this->_parseAddress($billingAddress, $billingAddressData);
159
-
160
- /**
161
- * If a servicelocation was set, add that as a third address
162
- */
163
- if (isset($delivery->ServicePunt)) {
164
- $serviceLocationData = $delivery->ServicePunt;
165
- $pakjeGemakAddress = Mage::getModel('sales/quote_address');
166
- $pakjeGemakAddress->setAddressType(self::ADDRESS_TYPE_PAKJEGEMAK)
167
- ->setEmail($email)
168
- ->setPhone($phone);
169
-
170
- $pakjeGemakAddress = $this->_parseAddress($pakjeGemakAddress, $serviceLocationData);
171
-
172
- $quote->addAddress($pakjeGemakAddress);
173
-
174
- /**
175
- * Register that this is a PakjeGemak order
176
- */
177
- Mage::register('quote_is_pakje_gemak', 1);
178
- }
179
-
180
- /**
181
- * Update the quote's addresses
182
- */
183
- $quote->setCustomerEmail($email)
184
- ->setShippingAddress($shippingAddress)
185
- ->setBillingAddress($billingAddress)
186
- ->collectTotals()
187
- ->save();
188
-
189
- return $this;
190
- }
191
-
192
- /**
193
- * Updates a quote with the given payment data (from PostNL or magento).
194
- *
195
- * @param mixed $data
196
- * @param boolean $isOrderdetails Flag whether or not the supplied data was sent by PostNL and not by magento
197
- * @param boolean $methodOnly Flag whether or not to only set the payment method. If false, all data will be set for the
198
- * chosen payment method.
199
- * @param Mage_Sales_Model_Quote | null $quote
200
- *
201
- * @return TIG_PostNL_Model_Checkout_Service
202
- */
203
- public function updateQuotePayment($data, $isOrderdetails = true, $methodOnly = false, $quote = null)
204
- {
205
- /**
206
- * Load the current quote if none was supplied
207
- */
208
- if (is_null($quote)) {
209
- $quote = $this->getQuote();
210
- }
211
-
212
- $this->setStoreId($quote->getStoreId());
213
-
214
- /**
215
- * If the payment data is sent by PostNL we need to process it accordingly
216
- */
217
- if ($isOrderdetails) {
218
- $this->_verifyData($data, $quote);
219
- $this->_processPostnlPaymentData($data, $methodOnly, $quote);
220
-
221
- return $this;
222
- }
223
-
224
- /**
225
- * Otherwise, we need to process the data as we would with a regular checkout procedure
226
- */
227
- if ($quote->isVirtual()) {
228
- $quote->getBillingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
229
- } else {
230
- $quote->getShippingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
231
- }
232
-
233
- // shipping totals may be affected by payment method
234
- if (!$quote->isVirtual() && $quote->getShippingAddress()) {
235
- $quote->getShippingAddress()->setCollectShippingRates(true);
236
- }
237
-
238
- /**
239
- * Extra checks used by Magento
240
- *
241
- * @since Magento v1.13
242
- */
243
- $paymentMethodAbstractClass = Mage::getConfig()->getModelClassName('payment/method_abstract');
244
- if (defined($paymentMethodAbstractClass . '::CHECK_USE_CHECKOUT')
245
- && defined($paymentMethodAbstractClass . '::CHECK_USE_FOR_COUNTRY')
246
- && defined($paymentMethodAbstractClass . '::CHECK_USE_FOR_CURRENCY')
247
- && defined($paymentMethodAbstractClass . '::CHECK_ORDER_TOTAL_MIN_MAX')
248
- && defined($paymentMethodAbstractClass . '::CHECK_ZERO_TOTAL')
249
- ) {
250
- $data['checks'] = $paymentMethodAbstractClass::CHECK_USE_CHECKOUT
251
- | $paymentMethodAbstractClass::CHECK_USE_FOR_COUNTRY
252
- | $paymentMethodAbstractClass::CHECK_USE_FOR_CURRENCY
253
- | $paymentMethodAbstractClass::CHECK_ORDER_TOTAL_MIN_MAX
254
- | $paymentMethodAbstractClass::CHECK_ZERO_TOTAL;
255
- }
256
-
257
- $quote->getPayment()->setMethod($data['method'])->importData($data);
258
- $quote->getPayment()->getMethodInstance()->assignData($data);
259
-
260
- $quote->save();
261
-
262
- return $this;
263
- }
264
-
265
- /**
266
- * Processes PostNL payment data
267
- *
268
- * @param StdClass $data
269
- * @param boolean $methodOnly
270
- * @param Mage_Sales_Model_Quote $quote
271
- *
272
- * @return TIG_PostNL_Model_Checkout_Service
273
- *
274
- * @throws TIG_PostNL_Exception
275
- */
276
- protected function _processPostnlPaymentData($data, $methodOnly, $quote)
277
- {
278
- /**
279
- * Get the payment data PostNL supplied
280
- */
281
- $postnlPaymentData = $data->BetaalMethode;
282
-
283
- /**
284
- * Check if the plugin supports the chosen payment method
285
- */
286
- $postnlPaymentMethods = Mage::helper('postnl/checkout')->getCheckoutPaymentMethods();
287
- $methodName = array_search($postnlPaymentData->Code, $postnlPaymentMethods);
288
-
289
- /**
290
- * Check if the payment method chosen is allowed
291
- */
292
- if (!Mage::getStoreConfigFlag(self::XML_PATH_PAYMENT_METHODS . '/' . $methodName, $quote->getStoreId())) {
293
- throw new TIG_PostNL_Exception(
294
- Mage::helper('postnl')->__('Selected payment method %s is not available.', $methodName),
295
- 'POSTNL-0048'
296
- );
297
- }
298
-
299
- /**
300
- * Get the Magento payment method code associated with this method
301
- */
302
- $methodCode = Mage::getStoreConfig(self::XML_PATH_PAYMENT_METHODS . '/' . $methodName . '_method', $quote->getStoreId());
303
- $optionValue = $postnlPaymentData->Optie;
304
-
305
-
306
- /**
307
- * Remove any current payment associtaed with the quote and get a new one
308
- */
309
- $payment = $quote->removePayment()
310
- ->getPayment();
311
-
312
- Mage::register('postnl_payment_data', array('method' => $methodCode, 'option' => $optionValue));
313
-
314
- /**
315
- * if we only need to set the payment method, do so and we'll be finished
316
- */
317
- if ($methodOnly) {
318
- $payment->setMethod($methodCode);
319
- $quote->save();
320
-
321
- return $this;
322
- }
323
-
324
- /**
325
- * Otherwise we need to form the payment data array containing all relevant payment data
326
- */
327
- $paymentData = Mage::app()->getRequest()->getPost('payment', array());
328
-
329
- /**
330
- * Extra checks used by Magento
331
- *
332
- * @since Magento v1.13
333
- */
334
- $paymentMethodAbstractClass = Mage::getConfig()->getModelClassName('payment/method_abstract');
335
- if (defined($paymentMethodAbstractClass . '::CHECK_USE_CHECKOUT')
336
- && defined($paymentMethodAbstractClass . '::CHECK_USE_FOR_COUNTRY')
337
- && defined($paymentMethodAbstractClass . '::CHECK_USE_FOR_CURRENCY')
338
- && defined($paymentMethodAbstractClass . '::CHECK_ORDER_TOTAL_MIN_MAX')
339
- && defined($paymentMethodAbstractClass . '::CHECK_ZERO_TOTAL')
340
- ) {
341
- $paymentData['checks'] = $paymentMethodAbstractClass::CHECK_USE_CHECKOUT
342
- | $paymentMethodAbstractClass::CHECK_USE_FOR_COUNTRY
343
- | $paymentMethodAbstractClass::CHECK_USE_FOR_CURRENCY
344
- | $paymentMethodAbstractClass::CHECK_ORDER_TOTAL_MIN_MAX
345
- | $paymentMethodAbstractClass::CHECK_ZERO_TOTAL;
346
- }
347
-
348
- if ($quote->isVirtual()) {
349
- $quote->getBillingAddress()->setPaymentMethod($methodCode);
350
- } else {
351
- $quote->getShippingAddress()->setPaymentMethod($methodCode);
352
- $quote->getShippingAddress()->setCollectShippingRates(true);
353
- }
354
-
355
- $paymentData['method'] = $methodCode;
356
-
357
- /**
358
- * If the chosen payment method has an optional field (like bank selection for iDEAL) we have to check system / config in
359
- * order to map it to a form field the payment method would expect.
360
- */
361
- if ($optionValue) {
362
- $field = Mage::getStoreConfig(
363
- self::XML_PATH_PAYMENT_METHODS . '/' . $methodName . '_option_field',
364
- $quote->getStoreId()
365
- );
366
-
367
- /**
368
- * If a field name is specified we add the option to the payment data as well as to the super global POST array
369
- */
370
- if ($field) {
371
- $paymentData[$field] = $optionValue;
372
- $_POST[$field] = $optionValue;
373
- }
374
- }
375
-
376
- /**
377
- * Import the payment data, save the payment, and then save the quote
378
- */
379
- $payment->importData($paymentData);
380
-
381
- $quote->save();
382
-
383
- return $this;
384
- }
385
-
386
- /**
387
- * Adds the customer to the quote if a customer is currently logged in. Also updates the customer's DOB if possible.
388
- *
389
- * @param StdClass $data
390
- * @param Mage_Sales_Model_Quote | null $quote
391
- *
392
- * @return TIG_PostNL_Model_Checkout_Service
393
- */
394
- public function updateQuoteCustomer($data, $quote = null)
395
- {
396
- /**
397
- * Load the current quote if none was supplied
398
- */
399
- if (is_null($quote)) {
400
- $quote = $this->getQuote();
401
- }
402
-
403
- /**
404
- * Load the current customer if the user is logged in
405
- */
406
- $customer = Mage::getSingleton('customer/session')->getCustomer();
407
- $customerId = $customer->getId();
408
-
409
- /**
410
- * If there is no customer we don't have to do anything
411
- */
412
- if(!$customerId) {
413
- return $this;
414
- }
415
-
416
- /**
417
- * Add the customer to the quote
418
- */
419
- $quote->setCustomerId($customerId);
420
- $quote->getShippingAddress()->setCustomerId($customerId);
421
- $quote->getBillingAddress()->setCustomerId($customerId);
422
-
423
- /**
424
- * If the customer already has a DOB we're finished
425
- */
426
- if ($customer->getDob()) {
427
- return $this;
428
- }
429
-
430
- /**
431
- * Check if PostNL returned a DOB for the customer
432
- */
433
- if (isset($data->Consument)
434
- && is_object($data->Consument)
435
- && isset($data->Consument->GeboorteDatum)
436
- && !empty($data->Consument->GeboorteDatum)
437
- ) {
438
- $dob = $data->Consument->GeboorteDatum;
439
- }
440
-
441
- if (!isset($dob)) {
442
- return $this;
443
- }
444
-
445
- /**
446
- * Update the customer with the DOB and save
447
- */
448
- $customer->setDob(strtotime($dob))
449
- ->save();
450
-
451
- return $this;
452
- }
453
-
454
- /**
455
- * Updates the PostNL order with the selected options
456
- *
457
- * @param StdClass $orderDetails
458
- *
459
- * @return TIG_PostNL_Model_Checkout_Service
460
- */
461
- public function updatePostnlOrder($data, $quote = null)
462
- {
463
- /**
464
- * Load the current quote if none was supplied
465
- */
466
- if (is_null($quote)) {
467
- $quote = $this->getQuote();
468
- }
469
-
470
- $this->setStoreId($quote->getStoreId());
471
-
472
- $this->_verifyData($data, $quote);
473
-
474
- $postnlOrder = Mage::getModel('postnl_checkout/order');
475
- $postnlOrder->load($quote->getId(), 'quote_id');
476
-
477
- /**
478
- * If a confirm date has been specified, save it with the PostNL Order object so we can reference it later
479
- */
480
- if (isset($data->Voorkeuren)
481
- && is_object($data->Voorkeuren)
482
- && isset($data->Voorkeuren->Bezorging)
483
- && is_object($data->Voorkeuren->Bezorging)
484
- && isset($data->Voorkeuren->Bezorging->VerzendDatum)
485
- && isset($data->Voorkeuren->Bezorging->Datum)
486
- ) {
487
- $delivery = $data->Voorkeuren->Bezorging;
488
- $postnlOrder->setConfirmDate($delivery->VerzendDatum)
489
- ->setDeliveryDate($delivery->Datum);
490
- }
491
-
492
- /**
493
- * If a specific product code is needed to ship this order, save it as well
494
- */
495
- if (isset($data->Bezorging)
496
- && is_object($data->Bezorging)
497
- && isset($data->Bezorging->ProductCode)
498
- ) {
499
- $postnlOrder->setProductCode($data->Bezorging->ProductCode);
500
- }
501
-
502
- /**
503
- * Check if this is a PakjeGemak order. If so, save the PostNL Order as such
504
- */
505
- if (Mage::registry('quote_is_pakje_gemak')) {
506
- $postnlOrder->setIsPakjeGemak(1);
507
-
508
- Mage::unRegister('quote_is_pakje_gemak');
509
- }
510
-
511
- $postnlOrder->save();
512
-
513
- return $this;
514
- }
515
-
516
- /**
517
- * Converts a quote to it's order
518
- *
519
- * @param Mage_Sales_Model_Quote $quote
520
- *
521
- * @return Mage_Sales_Model_Order
522
- *
523
- * @throws TIG_PostNL_Exception
524
- */
525
- public function saveOrder($quote = null)
526
- {
527
- /**
528
- * Load the current quote if none was supplied
529
- */
530
- if (is_null($quote)) {
531
- $quote = $this->getQuote();
532
- }
533
-
534
- Mage::dispatchEvent('postnl_checkout_save_order_before',
535
- array(
536
- 'quote' => $quote
537
- )
538
- );
539
-
540
- $quoteService = Mage::getModel('sales/service_quote', $quote);
541
- $quoteService->submitAll();
542
- $order = $quoteService->getOrder();
543
-
544
- if(empty($order)) {
545
- throw new TIG_PostNL_Exception(
546
- Mage::helper('postnl')->__('Unable to create an order for quote #%s', $quote->getId()),
547
- 'POSTNL-0049'
548
- );
549
- }
550
-
551
- /**
552
- * If a pakje_gemak address is present, add it to the order as well
553
- */
554
- $quoteAddresses = $quote->getAllAddresses();
555
- foreach ($quoteAddresses as $address) {
556
- if ($address->getAddressType() != self::ADDRESS_TYPE_PAKJEGEMAK) {
557
- continue;
558
- }
559
-
560
- $address->load($address->getId());
561
- $orderAddress = Mage::getModel('sales/convert_quote')->addressToOrderAddress($address);
562
-
563
- $order->addAddress($orderAddress);
564
-
565
- $orderAddress->save();
566
- break;
567
- }
568
-
569
- /**
570
- * Save the customer's name
571
- */
572
- $billingAddress = $quote->getBillingAddress();
573
- $order->setCustomerFirstname($billingAddress->getFirstname())
574
- ->setCustomerLastname($billingAddress->getLastname())
575
- ->save();
576
-
577
- Mage::dispatchEvent('checkout_type_onepage_save_order_after',
578
- array(
579
- 'order' => $order,
580
- 'quote' => $quote
581
- )
582
- );
583
-
584
- Mage::dispatchEvent('postnl_checkout_save_order_after',
585
- array(
586
- 'order' => $order,
587
- 'quote' => $quote
588
- )
589
- );
590
-
591
- $quote->setIsActive(false)
592
- ->save();
593
-
594
- $postnlOrder = Mage::getModel('postnl_checkout/order');
595
- $postnlOrder->load($quote->getId(), 'quote_id')
596
- ->setOrderId($order->getId())
597
- ->setIsActive(false)
598
- ->save();
599
-
600
- $checkoutSession = Mage::getSingleton('checkout/session');
601
- $checkoutSession->setLastSuccessQuoteId($order->getQuoteId())
602
- ->setLastRealOrderId($order->getRealOrderId())
603
- ->setLastQuoteId($order->getQuoteId())
604
- ->setLastOrderId($order->getId());
605
-
606
- Mage::dispatchEvent(
607
- 'checkout_submit_all_after',
608
- array(
609
- 'order' => $order,
610
- 'quote' => $quote,
611
- 'recurring_profiles' => null
612
- )
613
- );
614
-
615
- return $order;
616
- }
617
-
618
- /**
619
- * Confirms a PostNL order with PostNL.
620
- *
621
- * @param Mage_Sales_Model_Quote
622
- *
623
- * @return TIG_PostNL_Model_Checkout_Service
624
- */
625
- public function confirmPostnlOrder($quote = null)
626
- {
627
- /**
628
- * Load the current quote if none was supplied
629
- */
630
- if (is_null($quote)) {
631
- $quote = $this->getQuote();
632
- }
633
-
634
- $postnlOrder = Mage::getModel('postnl_checkout/order')
635
- ->load($quote->getId(), 'quote_id');
636
-
637
- $cif = Mage::getModel('postnl_checkout/cif');
638
- $cif->confirmOrder($postnlOrder);
639
-
640
- return $this;
641
- }
642
-
643
- /**
644
- * Parses a PostNL Checkout address into a varien object that can be used by Magento
645
- *
646
- * @param Mage_Sales_Model_Quote_Address $address
647
- * @param StdClass $addressData
648
- *
649
- * @return Mage_Sales_Model_Quote_Address
650
- */
651
- protected function _parseAddress($address, $addressData)
652
- {
653
- $storeId = $this->getStoreId();
654
-
655
- /**
656
- * First parse the street data (streetname, house nr. house nr. ext.)
657
- */
658
- $address = $this->_parseStreetData($address, $addressData);
659
-
660
- /**
661
- * Parse optional address fields
662
- */
663
- $buildingNameField = Mage::getStoreConfig(self::XML_PATH_BUILDING_NAME_FIELD, $storeId);
664
- $departmentField = Mage::getStoreConfig(self::XML_PATH_DEPARTMENT_FIELD, $storeId);
665
- $doorcodeField = Mage::getStoreConfig(self::XML_PATH_DOORCODE_FIELD, $storeId);
666
- $floorField = Mage::getStoreConfig(self::XML_PATH_FLOOR_FIELD, $storeId);
667
- $areaField = Mage::getStoreConfig(self::XML_PATH_AREA_FIELD, $storeId);
668
-
669
- if ($buildingNameField) {
670
- $address->setData('street' . $buildingNameField, $addressData->Gebouw);
671
- }
672
-
673
- if ($departmentField) {
674
- $address->setData('street' . $departmentField, $addressData->Afdeling);
675
- }
676
-
677
- if ($doorcodeField) {
678
- $address->setData('street' . $doorcodeField, $addressData->Deurcode);
679
- }
680
-
681
- if ($floorField) {
682
- $address->setData('street' . $floorField, $addressData->Verdieping);
683
- }
684
-
685
- if ($areaField) {
686
- $address->setData('street' . $areaField, $addressData->Wijk);
687
- }
688
-
689
- /**
690
- * Parse the remaining simple fields that require no additional logic
691
- */
692
- $firstname = $addressData->Voornaam;
693
- $lastname = $addressData->Achternaam;
694
- $middlename = $addressData->Tussenvoegsel;
695
- $country = $addressData->Land;
696
- $city = $addressData->Plaats;
697
- $postcode = $addressData->Postcode;
698
-
699
- $address->setFirstname($firstname)
700
- ->setLastname($lastname)
701
- ->setMiddelname($middlename)
702
- ->setCountryId($country)
703
- ->setCity($city)
704
- ->setPostcode($postcode);
705
-
706
- if (!$address->getCountryId()) {
707
- $address->setCountryId('NL');
708
- }
709
-
710
- $address->setShouldIgnoreValidation(true);
711
-
712
- return $address;
713
- }
714
-
715
- /**
716
- * Add optional service location data to the shipping address. This ovverrides the previously set address data.
717
- * nto a varien object that can be used by Magento
718
- *
719
- * @param Mage_Sales_Model_Quote_Address $address
720
- * @param StdClass $addressData
721
- *
722
- * @return Mage_Sales_Model_Quote_Address
723
- */
724
- protected function _addServiceLocationData($address, $serviceLocationData)
725
- {
726
- $storeId = $this->getStoreId();
727
-
728
- /**
729
- * First parse the street data (streetname, house nr. house nr. ext.)
730
- */
731
- $address = $this->_parseStreetData($address, $serviceLocationData);
732
-
733
- /**
734
- * Remove any company data that may have been set, this could cause confusion when delivering the package to a service
735
- * location with a different company name
736
- */
737
- $address->setCompany(false);
738
-
739
- return $address;
740
- }
741
-
742
- /**
743
- * Parses street data and returns an address object containing properly formatted street lines.
744
- *
745
- * @param Mage_Sales_Model_Quote_Address $address
746
- * @param StdClass $addressData
747
- *
748
- * @return Mage_Sales_Model_Quote_Address
749
- */
750
- protected function _parseStreetData($address, $addressData)
751
- {
752
- $storeId = $this->getStoreId();
753
- $splitStreet = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_STREET, $storeId);
754
-
755
- if (!$splitStreet) {
756
- /**
757
- * If the store uses single line addresses, merge the street fields
758
- */
759
- $streetData = $addressData->Straat . PHP_EOL . $addressData->Huisnummer . PHP_EOL . $addressData->HuisnummerExt;
760
-
761
- $address->setStreet($streetData);
762
- return $address;
763
- }
764
-
765
- $streetData = array();
766
-
767
- /**
768
- * If the store uses multiple address lines, check which part of the address goes where
769
- */
770
- $streetnameField = Mage::getStoreConfig(self::XML_PATH_STREETNAME_FIELD, $storeId);
771
- $housenumberField = Mage::getStoreCOnfig(self::XML_PATH_HOUSENUMBER_FIELD, $storeId);
772
-
773
- /**
774
- * Set the streetname to the appropriate field
775
- */
776
- $streetData[$streetnameField] = $addressData->Straat;
777
-
778
- /**
779
- * Check if the store splits housenumber and housenumber extensions as well. Place them in appriopriate fields
780
- */
781
- $splitHousenumber = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_HOUSENUMBER, $storeId);
782
- if (!$splitHousenumber) {
783
- $housenumber = $addressData->Huisnummer . ' ' . $addressData->HuisnummerExt;
784
- $streetData[$housenumberField] = $housenumber;
785
- } else {
786
- $housenumberExtensionField = Mage::getStoreConfig(self::XML_PATH_HOUSENUMBER_EXTENSION_FIELD, $storeId);
787
- $streetData[$housenumberField] = $addressData->Huisnummer;
788
- $streetData[$housenumberExtensionField] = $addressData->HuisnummerExt;
789
- }
790
-
791
- /**
792
- * Sort the street data according to the field numbers and set it
793
- */
794
- ksort($streetData);
795
- $address->setStreet($streetData);
796
-
797
- return $address;
798
- }
799
-
800
- /**
801
- * Verifies the validity of the supplied data
802
- *
803
- * @param StdClass $data
804
- * @param Mage_Sales_Model_Quote $quote
805
- *
806
- * @return TIG_PostNL_Model_Checkout_Service
807
- *
808
- * @throws TIG_PostNL_Exception
809
- */
810
- protected function _verifyData($data, $quote)
811
- {
812
- /**
813
- * Check if the quote matches the one PostNL expected
814
- */
815
- $quoteId = $data->Order->ExtRef;
816
- if ($quote->getId() != $quoteId) {
817
- throw new TIG_PostNL_Exception(
818
- Mage::helper('postnl')->__('Invalid quote supplied.'),
819
- 'POSTNL-0050'
820
- );
821
- }
822
-
823
- /**
824
- * Verify the webshop ID to make sure this message was not meant for another shop
825
- */
826
- $dataWebshopId = $data->Webshop->IntRef;
827
- $webshopId = Mage::getStoreConfig(self::XML_PATH_WEBSHOP_ID, $this->getStoreId());
828
- $webshopId = Mage::helper('core')->decrypt($webshopId);
829
-
830
- if ($webshopId != $dataWebshopId) {
831
- throw new TIG_PostNL_Exception(
832
- Mage::helper('postnl')->__('Invalid data supplied.'),
833
- 'POSTNL-0051'
834
- );
835
- }
836
-
837
- return $this;
838
- }
839
-
840
- /**
841
- * Removes all addresses associated with a quote. The quote's regular method to remove all addresses (removeAllAddresses())
842
- * effectively resets the addresses rather than removing them (replaces each address by a default one of the same type). We
843
- * specifically want to delete the optional PakjeGemak address as well.
844
- *
845
- * @param Mage_Sales_Model_Quote &$quote
846
- *
847
- * @return TIG_PostNL_Model_Checkout_Service
848
- */
849
- protected function _removeAllQuoteAddresses(&$quote)
850
- {
851
- /**
852
- * Truly delete the PakjeGemak address
853
- */
854
- $addresses = $quote->getAllAddresses();
855
- foreach ($addresses as $address) {
856
- if ($address->getAddressType() == self::ADDRESS_TYPE_PAKJEGEMAK) {
857
- $address->isDeleted(true);
858
- }
859
- }
860
-
861
- /**
862
- * Reset all remaining address types (by default only billing and shipping will remain)
863
- */
864
- $quote->removeAllAddresses();
865
-
866
- return $this;
867
- }
868
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method TIG_PostNL_Model_Checkout_Service setQuote(Mage_Sales_Model_Quote $value)
40
+ * @method TIG_PostNL_Model_Checkout_Service setStoreId(int $value)
41
+ * @method int getStoreId()
42
+ */
43
+ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
44
+ {
45
+ /**
46
+ * XML path to public webshop ID setting
47
+ */
48
+ const XML_PATH_WEBSHOP_ID = 'postnl/cif/webshop_id';
49
+
50
+ /**
51
+ * Constants containing XML paths to cif address configuration options
52
+ */
53
+ const XML_PATH_SPLIT_STREET = 'postnl/cif_address/split_street';
54
+ const XML_PATH_STREETNAME_FIELD = 'postnl/cif_address/streetname_field';
55
+ const XML_PATH_HOUSENUMBER_FIELD = 'postnl/cif_address/housenr_field';
56
+ const XML_PATH_SPLIT_HOUSENUMBER = 'postnl/cif_address/split_housenr';
57
+ const XML_PATH_HOUSENUMBER_EXTENSION_FIELD = 'postnl/cif_address/housenr_extension_field';
58
+ const XML_PATH_AREA_FIELD = 'postnl/cif_address/area_field';
59
+ const XML_PATH_BUILDING_NAME_FIELD = 'postnl/cif_address/building_name_field';
60
+ const XML_PATH_DEPARTMENT_FIELD = 'postnl/cif_address/department_field';
61
+ const XML_PATH_DOORCODE_FIELD = 'postnl/cif_address/doorcode_field';
62
+ const XML_PATH_FLOOR_FIELD = 'postnl/cif_address/floor_field';
63
+ const XML_PATH_REMARK_FIELD = 'postnl/cif_address/remark_field';
64
+
65
+ /**
66
+ * XML path to all PostNL Checkout payment settings
67
+ * N.B. missing last part os it will return an array of settings
68
+ */
69
+ const XML_PATH_PAYMENT_METHODS = 'postnl/checkout_payment_methods';
70
+
71
+ /**
72
+ * Newly added 'pakje_gemak' address type
73
+ */
74
+ const ADDRESS_TYPE_PAKJEGEMAK = 'pakje_gemak';
75
+
76
+ /**
77
+ * Gets the currently used quote object
78
+ *
79
+ * @return Mage_Sales_Model_Quote
80
+ */
81
+ public function getQuote()
82
+ {
83
+ if ($this->getData('quote')) {
84
+ return $this->getData('quote');
85
+ }
86
+
87
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
88
+
89
+ $this->setQuote($quote);
90
+ return $quote;
91
+ }
92
+
93
+ /**
94
+ * Updates a quote with the given PostNL order data. Each part of the data is used to replace the data normally
95
+ * acquired during checkout.
96
+ *
97
+ * @param StdClass $data
98
+ * @param Mage_Sales_Model_Quote | null $quote
99
+ *
100
+ * @return TIG_PostNL_Model_Checkout_Service
101
+ *
102
+ * @throws TIG_PostNL_Exception
103
+ */
104
+ public function updateQuoteAddresses($data, $quote = null)
105
+ {
106
+ /**
107
+ * Load the current quote if none was supplied
108
+ */
109
+ if (is_null($quote)) {
110
+ $quote = $this->getQuote();
111
+ }
112
+
113
+ $this->setStoreId($quote->getStoreId());
114
+
115
+ $this->_verifyData($data, $quote);
116
+
117
+ /**
118
+ * Get consumer data
119
+ */
120
+ $consumer = $data->Consument;
121
+ $email = $consumer->Email;
122
+ $phone = $consumer->TelefoonNummer;
123
+ if (!$phone) {
124
+ $phone = '-';
125
+ } else {
126
+ $phone = preg_replace("/[^0-9]/", '', $phone);
127
+ }
128
+
129
+ /**
130
+ * Remove all existing addresses, we're going to add new ones
131
+ */
132
+ $this->_removeAllQuoteAddresses($quote);
133
+
134
+ /**
135
+ * Parse the shippingaddresses
136
+ */
137
+ $delivery = $data->Bezorging;
138
+ $shippingAddressData = $delivery->Geadresseerde;
139
+
140
+ $shippingAddress = Mage::getModel('sales/quote_address');
141
+ $shippingAddress->setAddressType($shippingAddress::TYPE_SHIPPING)
142
+ ->setEmail($email)
143
+ ->setTelephone($phone);
144
+
145
+ $shippingAddress = $this->_parseAddress($shippingAddress, $shippingAddressData);
146
+
147
+ $shippingMethod = Mage::helper('postnl/carrier')->getCurrentPostnlShippingMethod();
148
+ if (!$shippingAddress->getShippingMethod()) {
149
+ $shippingAddress->setCollectShippingRates(true)
150
+ ->setShippingMethod($shippingMethod);
151
+ }
152
+
153
+ /**
154
+ * Parse the billing address
155
+ */
156
+ $billingAddressData = $data->Facturatie->Adres;
157
+ $billingAddress = Mage::getModel('sales/quote_address');
158
+ $billingAddress->setAddressType($billingAddress::TYPE_BILLING)
159
+ ->setEmail($email)
160
+ ->setTelephone($phone);
161
+
162
+ $billingAddress = $this->_parseAddress($billingAddress, $billingAddressData);
163
+
164
+ /**
165
+ * If a servicelocation was set, add that as a third address
166
+ */
167
+ if (isset($delivery->ServicePunt)) {
168
+ $serviceLocationData = $delivery->ServicePunt;
169
+ $pakjeGemakAddress = Mage::getModel('sales/quote_address');
170
+ $pakjeGemakAddress->setAddressType(self::ADDRESS_TYPE_PAKJEGEMAK)
171
+ ->setEmail($email)
172
+ ->setTelephone($phone);
173
+
174
+ $pakjeGemakAddress = $this->_parseAddress($pakjeGemakAddress, $serviceLocationData);
175
+
176
+ $quote->addAddress($pakjeGemakAddress);
177
+
178
+ /**
179
+ * Register that this is a PakjeGemak order
180
+ */
181
+ Mage::register('quote_is_pakje_gemak', 1);
182
+ }
183
+
184
+ /**
185
+ * Update the quote's addresses
186
+ */
187
+ $quote->setCustomerEmail($email)
188
+ ->setShippingAddress($shippingAddress)
189
+ ->setBillingAddress($billingAddress)
190
+ ->collectTotals()
191
+ ->save();
192
+
193
+ return $this;
194
+ }
195
+
196
+ /**
197
+ * Updates a quote with the given payment data (from PostNL or magento).
198
+ *
199
+ * @param mixed $data
200
+ * @param boolean $isOrderdetails Flag whether or not the supplied data was sent by PostNL and not by magento
201
+ * @param boolean $methodOnly Flag whether or not to only set the payment method. If false, all data will be set
202
+ * for the chosen payment method.
203
+ * @param Mage_Sales_Model_Quote|null $quote
204
+ *
205
+ * @return TIG_PostNL_Model_Checkout_Service
206
+ */
207
+ public function updateQuotePayment($data, $isOrderdetails = true, $methodOnly = false, $quote = null)
208
+ {
209
+ /**
210
+ * Load the current quote if none was supplied
211
+ */
212
+ if (is_null($quote)) {
213
+ $quote = $this->getQuote();
214
+ }
215
+
216
+ $this->setStoreId($quote->getStoreId());
217
+
218
+ /**
219
+ * If the payment data is sent by PostNL we need to process it accordingly
220
+ */
221
+ if ($isOrderdetails) {
222
+ $this->_verifyData($data, $quote);
223
+ $this->_processPostnlPaymentData($data, $methodOnly, $quote);
224
+
225
+ return $this;
226
+ }
227
+
228
+ /**
229
+ * Otherwise, we need to process the data as we would with a regular checkout procedure
230
+ */
231
+ if ($quote->isVirtual()) {
232
+ $quote->getBillingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
233
+ } else {
234
+ $quote->getShippingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
235
+ }
236
+
237
+ /**
238
+ * shipping totals may be affected by payment method
239
+ */
240
+ if (!$quote->isVirtual() && $quote->getShippingAddress()) {
241
+ $quote->getShippingAddress()->setCollectShippingRates(true);
242
+ }
243
+
244
+ /**
245
+ * Extra checks used by Magento
246
+ *
247
+ * @var $paymentMethodAbstractClass Mage_Payment_Model_Method_Abstract
248
+ *
249
+ * @since Magento v1.13
250
+ */
251
+ $paymentMethodAbstractClass = Mage::getConfig()->getModelClassName('payment/method_abstract');
252
+ if (defined($paymentMethodAbstractClass . '::CHECK_USE_CHECKOUT')
253
+ && defined($paymentMethodAbstractClass . '::CHECK_USE_FOR_COUNTRY')
254
+ && defined($paymentMethodAbstractClass . '::CHECK_USE_FOR_CURRENCY')
255
+ && defined($paymentMethodAbstractClass . '::CHECK_ORDER_TOTAL_MIN_MAX')
256
+ && defined($paymentMethodAbstractClass . '::CHECK_ZERO_TOTAL')
257
+ ) {
258
+ $data['checks'] = $paymentMethodAbstractClass::CHECK_USE_CHECKOUT
259
+ | $paymentMethodAbstractClass::CHECK_USE_FOR_COUNTRY
260
+ | $paymentMethodAbstractClass::CHECK_USE_FOR_CURRENCY
261
+ | $paymentMethodAbstractClass::CHECK_ORDER_TOTAL_MIN_MAX
262
+ | $paymentMethodAbstractClass::CHECK_ZERO_TOTAL;
263
+ }
264
+
265
+ $paymentDataObject = new Varien_Object();
266
+ $paymentDataObject->setPaymentData($data);
267
+
268
+ Mage::dispatchEvent(
269
+ 'postnl_checkout_set_payment_before',
270
+ array(
271
+ 'payment' => $quote->getPayment(),
272
+ 'quote' => $quote,
273
+ 'payment_data_object' => $paymentDataObject,
274
+ )
275
+ );
276
+
277
+ $paymentData = $paymentDataObject->getPaymentData();
278
+
279
+ $quote->getPayment()->setMethod($data['method'])->importData($paymentData);
280
+ $quote->getPayment()->getMethodInstance()->assignData($paymentData);
281
+
282
+ Mage::dispatchEvent(
283
+ 'postnl_checkout_set_payment_after',
284
+ array(
285
+ 'payment' => $quote->getPayment(),
286
+ 'quote' => $quote,
287
+ )
288
+ );
289
+
290
+ $quote->save();
291
+
292
+ return $this;
293
+ }
294
+
295
+ /**
296
+ * Processes PostNL payment data
297
+ *
298
+ * @param StdClass $data
299
+ * @param boolean $methodOnly
300
+ * @param Mage_Sales_Model_Quote $quote
301
+ *
302
+ * @return TIG_PostNL_Model_Checkout_Service
303
+ *
304
+ * @throws TIG_PostNL_Exception
305
+ */
306
+ protected function _processPostnlPaymentData($data, $methodOnly, $quote)
307
+ {
308
+ /**
309
+ * Get the payment data PostNL supplied
310
+ */
311
+ $postnlPaymentData = $data->BetaalMethode;
312
+
313
+ /**
314
+ * Check if the plugin supports the chosen payment method
315
+ */
316
+ $postnlPaymentMethods = Mage::helper('postnl/checkout')->getCheckoutPaymentMethods();
317
+ $methodName = array_search($postnlPaymentData->Code, $postnlPaymentMethods);
318
+
319
+ /**
320
+ * Check if the payment method chosen is allowed
321
+ */
322
+ if (!Mage::getStoreConfigFlag(self::XML_PATH_PAYMENT_METHODS . '/' . $methodName, $quote->getStoreId())) {
323
+ throw new TIG_PostNL_Exception(
324
+ Mage::helper('postnl')->__('Selected payment method %s is not available.', $methodName),
325
+ 'POSTNL-0048'
326
+ );
327
+ }
328
+
329
+ if ($methodOnly === true) {
330
+ $this->_processPaymentMethod($methodName, $quote);
331
+ return $this;
332
+ }
333
+
334
+ $this->_processPaymentData($postnlPaymentData, $methodName, $quote);
335
+ return $this;
336
+ }
337
+
338
+ /**
339
+ * Process a chosen payment method
340
+ *
341
+ * @param string $methodName
342
+ * @param Mage_Sales_Model_Quote $quote
343
+ *
344
+ * @return TIG_PostNL_Exception
345
+ */
346
+ protected function _processPaymentMethod($methodName, $quote)
347
+ {
348
+ /**
349
+ * Get the Magento payment method code associated with this method
350
+ */
351
+ $methodCode = Mage::getStoreConfig(
352
+ self::XML_PATH_PAYMENT_METHODS . '/' . $methodName . '_method',
353
+ $quote->getStoreId()
354
+ );
355
+ Mage::register('postnl_payment_data', array('method' => $methodCode));
356
+
357
+ /**
358
+ * Remove any current payment associtaed with the quote and get a new one
359
+ */
360
+ $payment = $quote->removePayment()
361
+ ->getPayment();
362
+
363
+ $payment->setMethod($methodCode);
364
+ $quote->save();
365
+
366
+ return $this;
367
+ }
368
+
369
+ /**
370
+ * Process a chosen payment method with extra payment data
371
+ *
372
+ * @param StdClass $postnlPaymentData
373
+ * @param string $methodName
374
+ * @param Mage_Sales_Model_Quote $quote
375
+ *
376
+ * @return TIG_PostNL_Exception
377
+ */
378
+ protected function _processPaymentData($postnlPaymentData, $methodName, $quote)
379
+ {
380
+ /**
381
+ * Otherwise we need to form the payment data array containing all relevant payment data
382
+ */
383
+ $paymentData = Mage::app()->getRequest()->getPost('payment', array());
384
+
385
+ $optionValue = $postnlPaymentData->Optie;
386
+
387
+ /**
388
+ * Get the payment method code associated with the chosen payment method
389
+ */
390
+ $methodCode = Mage::getStoreConfig(
391
+ self::XML_PATH_PAYMENT_METHODS . '/' . $methodName . '_method',
392
+ $quote->getStoreId()
393
+ );
394
+
395
+ /**
396
+ * Extra checks used by Magento
397
+ *
398
+ * @since Magento CE v1.7
399
+ * @since Magento EE v1.13
400
+ *
401
+ * @var $paymentMethodAbstractClass Mage_Payment_Model_Method_Abstract
402
+ */
403
+ $paymentMethodAbstractClass = Mage::getConfig()->getModelClassName('payment/method_abstract');
404
+ if (defined($paymentMethodAbstractClass . '::CHECK_USE_CHECKOUT')
405
+ && defined($paymentMethodAbstractClass . '::CHECK_USE_FOR_COUNTRY')
406
+ && defined($paymentMethodAbstractClass . '::CHECK_USE_FOR_CURRENCY')
407
+ && defined($paymentMethodAbstractClass . '::CHECK_ORDER_TOTAL_MIN_MAX')
408
+ && defined($paymentMethodAbstractClass . '::CHECK_ZERO_TOTAL')
409
+ ) {
410
+ $paymentData['checks'] = $paymentMethodAbstractClass::CHECK_USE_CHECKOUT
411
+ | $paymentMethodAbstractClass::CHECK_USE_FOR_COUNTRY
412
+ | $paymentMethodAbstractClass::CHECK_USE_FOR_CURRENCY
413
+ | $paymentMethodAbstractClass::CHECK_ORDER_TOTAL_MIN_MAX
414
+ | $paymentMethodAbstractClass::CHECK_ZERO_TOTAL;
415
+ }
416
+
417
+ if ($quote->isVirtual()) {
418
+ $quote->getBillingAddress()->setPaymentMethod($methodCode);
419
+ } else {
420
+ $quote->getShippingAddress()->setPaymentMethod($methodCode);
421
+ $quote->getShippingAddress()->setCollectShippingRates(true);
422
+ }
423
+
424
+ $paymentData['method'] = $methodCode;
425
+
426
+ /**
427
+ * If the chosen payment method has an optional field (like bank selection for iDEAL) we have to check
428
+ * system / config in order to map it to a form field the payment method would expect.
429
+ */
430
+ if ($optionValue) {
431
+ $field = Mage::getStoreConfig(
432
+ self::XML_PATH_PAYMENT_METHODS . '/' . $methodName . '_option_field',
433
+ $quote->getStoreId()
434
+ );
435
+
436
+ /**
437
+ * If a field name is specified we add the option to the payment data as well as to the super global POST
438
+ * array.
439
+ */
440
+ if ($field) {
441
+ $paymentData[$field] = $optionValue;
442
+ $_POST[$field] = $optionValue;
443
+ }
444
+ }
445
+
446
+ $paymentDataObject = new Varien_Object();
447
+ $paymentDataObject->setPaymentData($paymentData);
448
+
449
+ Mage::dispatchEvent(
450
+ 'postnl_checkout_set_payment_before',
451
+ array(
452
+ 'payment' => $quote->getPayment(),
453
+ 'quote' => $quote,
454
+ 'payment_data_object' => $paymentDataObject,
455
+ )
456
+ );
457
+
458
+ $paymentData = $paymentDataObject->getPaymentData();
459
+
460
+ /**
461
+ * Import the payment data, save the payment, and then save the quote
462
+ */
463
+ $quote->getPayment()->importData($paymentData);
464
+
465
+ Mage::dispatchEvent(
466
+ 'postnl_checkout_set_payment_after',
467
+ array(
468
+ 'payment' => $quote->getPayment(),
469
+ 'quote' => $quote,
470
+ )
471
+ );
472
+
473
+ $quote->save();
474
+
475
+ return $this;
476
+ }
477
+
478
+ /**
479
+ * Adds the customer to the quote if a customer is currently logged in. Also updates the customer's DOB if possible.
480
+ *
481
+ * @param StdClass $data
482
+ * @param Mage_Sales_Model_Quote | null $quote
483
+ *
484
+ * @return TIG_PostNL_Model_Checkout_Service
485
+ */
486
+ public function updateQuoteCustomer($data, $quote = null)
487
+ {
488
+ /**
489
+ * Load the current quote if none was supplied
490
+ */
491
+ if (is_null($quote)) {
492
+ $quote = $this->getQuote();
493
+ }
494
+
495
+ /**
496
+ * Load the current customer if the user is logged in
497
+ */
498
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
499
+ $customerId = $customer->getId();
500
+
501
+ /**
502
+ * If there is no customer we don't have to do anything
503
+ */
504
+ if(!$customerId) {
505
+ return $this;
506
+ }
507
+
508
+ /**
509
+ * Add the customer to the quote
510
+ */
511
+ $quote->setCustomerId($customerId);
512
+ $quote->getShippingAddress()->setCustomerId($customerId);
513
+ $quote->getBillingAddress()->setCustomerId($customerId);
514
+
515
+ /**
516
+ * If the customer already has a DOB we're finished
517
+ */
518
+ if ($customer->getDob()) {
519
+ return $this;
520
+ }
521
+
522
+ /**
523
+ * Check if PostNL returned a DOB for the customer
524
+ */
525
+ if (isset($data->Consument)
526
+ && is_object($data->Consument)
527
+ && isset($data->Consument->GeboorteDatum)
528
+ && !empty($data->Consument->GeboorteDatum)
529
+ ) {
530
+ $dob = $data->Consument->GeboorteDatum;
531
+ }
532
+
533
+ if (!isset($dob)) {
534
+ return $this;
535
+ }
536
+
537
+ /**
538
+ * Update the customer with the DOB and save
539
+ */
540
+ $customer->setDob(strtotime($dob))
541
+ ->save();
542
+
543
+ return $this;
544
+ }
545
+
546
+ /**
547
+ * Updates the PostNL order with the selected options
548
+ *
549
+ * @param $data
550
+ * @param null $quote
551
+ *
552
+ * @return TIG_PostNL_Model_Checkout_Service
553
+ */
554
+ public function updatePostnlOrder($data, $quote = null)
555
+ {
556
+ /**
557
+ * Load the current quote if none was supplied
558
+ */
559
+ if (is_null($quote)) {
560
+ $quote = $this->getQuote();
561
+ }
562
+
563
+ $this->setStoreId($quote->getStoreId());
564
+
565
+ $this->_verifyData($data, $quote);
566
+
567
+ $postnlOrder = Mage::getModel('postnl_core/order');
568
+ $postnlOrder->load($quote->getId(), 'quote_id');
569
+
570
+ /**
571
+ * If a confirm date has been specified, save it with the PostNL Order object so we can reference it later
572
+ */
573
+ if (isset($data->Voorkeuren)
574
+ && is_object($data->Voorkeuren)
575
+ && isset($data->Voorkeuren->Bezorging)
576
+ && is_object($data->Voorkeuren->Bezorging)
577
+ && isset($data->Voorkeuren->Bezorging->VerzendDatum)
578
+ && isset($data->Voorkeuren->Bezorging->Datum)
579
+ ) {
580
+ $delivery = $data->Voorkeuren->Bezorging;
581
+ $postnlOrder->setConfirmDate($delivery->VerzendDatum)
582
+ ->setDeliveryDate($delivery->Datum);
583
+ }
584
+
585
+ /**
586
+ * If a specific product code is needed to ship this order, save it as well
587
+ */
588
+ if (isset($data->Bezorging)
589
+ && is_object($data->Bezorging)
590
+ && isset($data->Bezorging->ProductCode)
591
+ ) {
592
+ $postnlOrder->setProductCode($data->Bezorging->ProductCode);
593
+ }
594
+
595
+ /**
596
+ * Check if this is a PakjeGemak order. If so, save the PostNL Order as such
597
+ */
598
+ if (Mage::registry('quote_is_pakje_gemak')) {
599
+ $postnlOrder->setIsPakjeGemak(1);
600
+
601
+ Mage::unRegister('quote_is_pakje_gemak');
602
+ }
603
+
604
+ $postnlOrder->save();
605
+
606
+ return $this;
607
+ }
608
+
609
+ /**
610
+ * Converts a quote to it's order
611
+ *
612
+ * @param Mage_Sales_Model_Quote $quote
613
+ *
614
+ * @return Mage_Sales_Model_Order
615
+ *
616
+ * @throws TIG_PostNL_Exception
617
+ */
618
+ public function saveOrder($quote = null)
619
+ {
620
+ /**
621
+ * Load the current quote if none was supplied
622
+ */
623
+ if (is_null($quote)) {
624
+ $quote = $this->getQuote();
625
+ }
626
+
627
+ Mage::dispatchEvent('postnl_checkout_save_order_before',
628
+ array(
629
+ 'quote' => $quote
630
+ )
631
+ );
632
+
633
+ $quoteService = Mage::getModel('sales/service_quote', $quote);
634
+ $quoteService->submitAll();
635
+ $order = $quoteService->getOrder();
636
+
637
+ if(empty($order)) {
638
+ throw new TIG_PostNL_Exception(
639
+ Mage::helper('postnl')->__('Unable to create an order for quote #%s', $quote->getId()),
640
+ 'POSTNL-0049'
641
+ );
642
+ }
643
+
644
+ /**
645
+ * If a pakje_gemak address is present, add it to the order as well.
646
+ *
647
+ * @var Mage_Sales_Model_Quote_Address $address
648
+ */
649
+ $quoteAddresses = $quote->getAllAddresses();
650
+ foreach ($quoteAddresses as $address) {
651
+ if ($address->getAddressType() != self::ADDRESS_TYPE_PAKJEGEMAK) {
652
+ continue;
653
+ }
654
+
655
+ $address->load($address->getId());
656
+ $orderAddress = Mage::getModel('sales/convert_quote')->addressToOrderAddress($address);
657
+
658
+ $order->addAddress($orderAddress);
659
+
660
+ $orderAddress->save();
661
+ break;
662
+ }
663
+
664
+ /**
665
+ * Save the customer's name
666
+ */
667
+ $billingAddress = $quote->getBillingAddress();
668
+ $order->setCustomerFirstname($billingAddress->getFirstname())
669
+ ->setCustomerLastname($billingAddress->getLastname())
670
+ ->save();
671
+
672
+ Mage::dispatchEvent('checkout_type_onepage_save_order_after',
673
+ array(
674
+ 'order' => $order,
675
+ 'quote' => $quote
676
+ )
677
+ );
678
+
679
+ Mage::dispatchEvent('postnl_checkout_save_order_after',
680
+ array(
681
+ 'order' => $order,
682
+ 'quote' => $quote
683
+ )
684
+ );
685
+
686
+ $quote->setIsActive(false)
687
+ ->save();
688
+
689
+ /**
690
+ * @var TIG_PostNL_Model_Core_Order $postnlOrder
691
+ */
692
+ $postnlOrder = Mage::getModel('postnl_core/order')->load($quote->getId(), 'quote_id');
693
+ $postnlOrder->setOrderId($order->getId())
694
+ ->setIsActive(false)
695
+ ->save();
696
+
697
+ $checkoutSession = Mage::getSingleton('checkout/session');
698
+ $checkoutSession->setLastSuccessQuoteId($order->getQuoteId())
699
+ ->setLastRealOrderId($order->getRealOrderId())
700
+ ->setLastQuoteId($order->getQuoteId())
701
+ ->setLastOrderId($order->getId());
702
+
703
+ Mage::dispatchEvent(
704
+ 'checkout_submit_all_after',
705
+ array(
706
+ 'order' => $order,
707
+ 'quote' => $quote,
708
+ 'recurring_profiles' => null
709
+ )
710
+ );
711
+
712
+ return $order;
713
+ }
714
+
715
+ /**
716
+ * Confirms a PostNL order with PostNL.
717
+ *
718
+ * @param Mage_Sales_Model_Quote
719
+ *
720
+ * @return TIG_PostNL_Model_Checkout_Service
721
+ */
722
+ public function confirmPostnlOrder($quote = null)
723
+ {
724
+ /**
725
+ * Load the current quote if none was supplied
726
+ */
727
+ if (is_null($quote)) {
728
+ $quote = $this->getQuote();
729
+ }
730
+
731
+ /**
732
+ * @var TIG_PostNL_Model_Core_Order $postnlOrder
733
+ */
734
+ $postnlOrder = Mage::getModel('postnl_core/order')
735
+ ->load($quote->getId(), 'quote_id');
736
+
737
+ $cif = Mage::getModel('postnl_checkout/cif');
738
+ $cif->confirmOrder($postnlOrder);
739
+
740
+ return $this;
741
+ }
742
+
743
+ /**
744
+ * Parses a PostNL Checkout address into a varien object that can be used by Magento.
745
+ *
746
+ * @param Mage_Sales_Model_Quote_Address $address
747
+ * @param StdClass $addressData
748
+ *
749
+ * @return Mage_Sales_Model_Quote_Address
750
+ */
751
+ protected function _parseAddress($address, $addressData)
752
+ {
753
+ $storeId = $this->getStoreId();
754
+
755
+ /**
756
+ * First parse the street data (streetname, house nr. house nr. ext.)
757
+ */
758
+ $address = $this->_parseStreetData($address, $addressData);
759
+
760
+ /**
761
+ * Parse optional address fields
762
+ */
763
+ $buildingNameField = Mage::getStoreConfig(self::XML_PATH_BUILDING_NAME_FIELD, $storeId);
764
+ $departmentField = Mage::getStoreConfig(self::XML_PATH_DEPARTMENT_FIELD, $storeId);
765
+ $doorcodeField = Mage::getStoreConfig(self::XML_PATH_DOORCODE_FIELD, $storeId);
766
+ $floorField = Mage::getStoreConfig(self::XML_PATH_FLOOR_FIELD, $storeId);
767
+ $areaField = Mage::getStoreConfig(self::XML_PATH_AREA_FIELD, $storeId);
768
+
769
+ if ($buildingNameField) {
770
+ $address->setData('street' . $buildingNameField, $addressData->Gebouw);
771
+ }
772
+
773
+ if ($departmentField) {
774
+ $address->setData('street' . $departmentField, $addressData->Afdeling);
775
+ }
776
+
777
+ if ($doorcodeField) {
778
+ $address->setData('street' . $doorcodeField, $addressData->Deurcode);
779
+ }
780
+
781
+ if ($floorField) {
782
+ $address->setData('street' . $floorField, $addressData->Verdieping);
783
+ }
784
+
785
+ if ($areaField) {
786
+ $address->setData('street' . $areaField, $addressData->Wijk);
787
+ }
788
+
789
+ /**
790
+ * Parse the remaining simple fields that require no additional logic
791
+ */
792
+ $firstname = $addressData->Voornaam;
793
+ $lastname = $addressData->Achternaam;
794
+ $middlename = $addressData->Tussenvoegsel;
795
+ $country = $addressData->Land;
796
+ $city = $addressData->Plaats;
797
+ $postcode = $addressData->Postcode;
798
+
799
+ $address->setFirstname($firstname)
800
+ ->setLastname($lastname)
801
+ ->setMiddlename($middlename)
802
+ ->setCountryId($country)
803
+ ->setCity($city)
804
+ ->setPostcode($postcode);
805
+
806
+ if (!$address->getCountryId()) {
807
+ $address->setCountryId('NL');
808
+ }
809
+
810
+ $address->setShouldIgnoreValidation(true);
811
+
812
+ return $address;
813
+ }
814
+
815
+ /**
816
+ * Add optional service location data to the shipping address. This ovverrides the previously set address data.
817
+ * nto a varien object that can be used by Magento
818
+ *
819
+ * @param Mage_Sales_Model_Quote_Address $address
820
+ * @param $serviceLocationData
821
+ *
822
+ * @return Mage_Sales_Model_Quote_Address
823
+ */
824
+ protected function _addServiceLocationData($address, $serviceLocationData)
825
+ {
826
+ /**
827
+ * First parse the street data (streetname, house nr. house nr. ext.)
828
+ */
829
+ $address = $this->_parseStreetData($address, $serviceLocationData);
830
+
831
+ /**
832
+ * Remove any company data that may have been set, this could cause confusion when delivering the package to a
833
+ * service location with a different company name.
834
+ */
835
+ $address->setCompany(false);
836
+
837
+ return $address;
838
+ }
839
+
840
+ /**
841
+ * Parses street data and returns an address object containing properly formatted street lines.
842
+ *
843
+ * @param Mage_Sales_Model_Quote_Address $address
844
+ * @param StdClass $addressData
845
+ *
846
+ * @return Mage_Sales_Model_Quote_Address
847
+ */
848
+ protected function _parseStreetData($address, $addressData)
849
+ {
850
+ $storeId = $this->getStoreId();
851
+ $splitStreet = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_STREET, $storeId);
852
+
853
+ if (!$splitStreet) {
854
+ /**
855
+ * If the store uses single line addresses, merge the street fields
856
+ */
857
+ $streetData = $addressData->Straat
858
+ . PHP_EOL
859
+ . $addressData->Huisnummer
860
+ . PHP_EOL
861
+ . $addressData->HuisnummerExt;
862
+
863
+ $address->setStreet($streetData);
864
+ return $address;
865
+ }
866
+
867
+ $streetData = array();
868
+
869
+ /**
870
+ * If the store uses multiple address lines, check which part of the address goes where
871
+ */
872
+ $streetnameField = Mage::getStoreConfig(self::XML_PATH_STREETNAME_FIELD, $storeId);
873
+ $housenumberField = Mage::getStoreCOnfig(self::XML_PATH_HOUSENUMBER_FIELD, $storeId);
874
+
875
+ /**
876
+ * Set the streetname to the appropriate field
877
+ */
878
+ $streetData[$streetnameField] = $addressData->Straat;
879
+
880
+ /**
881
+ * Check if the store splits housenumber and housenumber extensions as well. Place them in appriopriate fields
882
+ */
883
+ $splitHousenumber = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_HOUSENUMBER, $storeId);
884
+ if (!$splitHousenumber) {
885
+ $housenumber = $addressData->Huisnummer . ' ' . $addressData->HuisnummerExt;
886
+ $streetData[$housenumberField] = $housenumber;
887
+ } else {
888
+ $housenumberExtensionField = Mage::getStoreConfig(self::XML_PATH_HOUSENUMBER_EXTENSION_FIELD, $storeId);
889
+ $streetData[$housenumberField] = $addressData->Huisnummer;
890
+ $streetData[$housenumberExtensionField] = $addressData->HuisnummerExt;
891
+ }
892
+
893
+ /**
894
+ * Sort the street data according to the field numbers and set it
895
+ */
896
+ ksort($streetData);
897
+ $address->setStreet($streetData);
898
+
899
+ return $address;
900
+ }
901
+
902
+ /**
903
+ * Verifies the validity of the supplied data
904
+ *
905
+ * @param StdClass $data
906
+ * @param Mage_Sales_Model_Quote $quote
907
+ *
908
+ * @return TIG_PostNL_Model_Checkout_Service
909
+ *
910
+ * @throws TIG_PostNL_Exception
911
+ */
912
+ protected function _verifyData($data, $quote)
913
+ {
914
+ /**
915
+ * Check if the quote matches the one PostNL expected
916
+ */
917
+ $quoteId = $data->Order->ExtRef;
918
+ if ($quote->getId() != $quoteId) {
919
+ throw new TIG_PostNL_Exception(
920
+ Mage::helper('postnl')->__('Invalid quote supplied.'),
921
+ 'POSTNL-0050'
922
+ );
923
+ }
924
+
925
+ /**
926
+ * Verify the webshop ID to make sure this message was not meant for another shop
927
+ */
928
+ $dataWebshopId = $data->Webshop->IntRef;
929
+ $webshopId = Mage::getStoreConfig(self::XML_PATH_WEBSHOP_ID, $this->getStoreId());
930
+ $webshopId = Mage::helper('core')->decrypt($webshopId);
931
+
932
+ if ($webshopId != $dataWebshopId) {
933
+ throw new TIG_PostNL_Exception(
934
+ Mage::helper('postnl')->__('Invalid data supplied.'),
935
+ 'POSTNL-0051'
936
+ );
937
+ }
938
+
939
+ return $this;
940
+ }
941
+
942
+ /**
943
+ * Removes all addresses associated with a quote. The quote's regular method to remove all addresses
944
+ * (removeAllAddresses()) effectively resets the addresses rather than removing them (replaces each address by a
945
+ * default one of the same type). We specifically want to delete the optional PakjeGemak address as well.
946
+ *
947
+ * @param Mage_Sales_Model_Quote &$quote
948
+ *
949
+ * @return TIG_PostNL_Model_Checkout_Service
950
+ */
951
+ protected function _removeAllQuoteAddresses(&$quote)
952
+ {
953
+ /**
954
+ * Truly delete the PakjeGemak address.
955
+ *
956
+ * @var Mage_Sales_Model_Quote_Address $address
957
+ */
958
+ $addresses = $quote->getAllAddresses();
959
+ foreach ($addresses as $address) {
960
+ if ($address->getAddressType() == self::ADDRESS_TYPE_PAKJEGEMAK) {
961
+ $address->isDeleted(true);
962
+ }
963
+ }
964
+
965
+ /**
966
+ * Reset all remaining address types (by default only billing and shipping will remain)
967
+ */
968
+ $quote->removeAllAddresses();
969
+
970
+ return $this;
971
+ }
972
+ }
app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/ActivePaymentMethods.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -40,28 +40,28 @@ class TIG_PostNL_Model_Checkout_System_Config_Source_ActivePaymentMethods
40
  {
41
  /**
42
  * Gets an array of active payment methods
43
- *
44
  * @return array
45
  */
46
  public function toOptionArray()
47
  {
48
  $paymentMethods = Mage::getSingleton('payment/config')->getActiveMethods();
49
-
50
  $storeId = Mage::app()->getStore()->getId();
51
-
52
  $options = array();
53
  foreach ($paymentMethods as $code => $model) {
54
  $title = Mage::getStoreConfig('payment/' . $code . '/title', $storeId);
55
  if (empty($title)) {
56
- continue;
57
  }
58
-
59
  $options[$code] = array(
60
  'label' => $title,
61
  'value' => $code,
62
  );
63
  }
64
-
65
  return $options;
66
  }
67
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
40
  {
41
  /**
42
  * Gets an array of active payment methods
43
+ *
44
  * @return array
45
  */
46
  public function toOptionArray()
47
  {
48
  $paymentMethods = Mage::getSingleton('payment/config')->getActiveMethods();
49
+
50
  $storeId = Mage::app()->getStore()->getId();
51
+
52
  $options = array();
53
  foreach ($paymentMethods as $code => $model) {
54
  $title = Mage::getStoreConfig('payment/' . $code . '/title', $storeId);
55
  if (empty($title)) {
56
+ $title = $code;
57
  }
58
+
59
  $options[$code] = array(
60
  'label' => $title,
61
  'value' => $code,
62
  );
63
  }
64
+
65
  return $options;
66
  }
67
  }
app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/CmsPage.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -42,34 +42,34 @@ class TIG_PostNL_Model_Checkout_System_Config_Source_CmsPage
42
  * @var array
43
  */
44
  protected $_options;
45
-
46
  /**
47
  * Get the stored options array
48
- *
49
  * @return array
50
  */
51
  public function getOptions()
52
  {
53
  return $this->_options;
54
  }
55
-
56
  /**
57
  * Store the options array
58
- *
59
  * @param array $options
60
- *
61
  * @return TIG_PostNL_Model_Checkout_System_Config_Source_CmsPage
62
  */
63
  public function setOptions($options)
64
  {
65
  $this->_options = $options;
66
-
67
  return $this;
68
  }
69
-
70
  /**
71
  * Checks if an option array has been stored
72
- *
73
  * @return boolean
74
  */
75
  public function hasOptions()
@@ -78,32 +78,35 @@ class TIG_PostNL_Model_Checkout_System_Config_Source_CmsPage
78
  if (empty($options)) {
79
  return false;
80
  }
81
-
82
  return true;
83
  }
84
-
85
  /**
86
  * Get an option array of all CMS pages available
87
- *
88
  * @return array
89
  */
90
  public function toOptionArray()
91
  {
92
  if ($this->hasOptions()) {
93
  return $this->getOptions();
94
-
95
  }
96
-
97
  $options = array(
98
  '' => Mage::helper('postnl')->__('-- none --'),
99
  );
100
-
101
- $pageOptions = Mage::getResourceModel('cms/page_collection')->load()
102
- ->toOptionIdArray();
103
-
 
 
 
104
  $options = array_merge($options, $pageOptions);
105
  $this->setOptions($options);
106
-
107
  return $options;
108
  }
109
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
42
  * @var array
43
  */
44
  protected $_options;
45
+
46
  /**
47
  * Get the stored options array
48
+ *
49
  * @return array
50
  */
51
  public function getOptions()
52
  {
53
  return $this->_options;
54
  }
55
+
56
  /**
57
  * Store the options array
58
+ *
59
  * @param array $options
60
+ *
61
  * @return TIG_PostNL_Model_Checkout_System_Config_Source_CmsPage
62
  */
63
  public function setOptions($options)
64
  {
65
  $this->_options = $options;
66
+
67
  return $this;
68
  }
69
+
70
  /**
71
  * Checks if an option array has been stored
72
+ *
73
  * @return boolean
74
  */
75
  public function hasOptions()
78
  if (empty($options)) {
79
  return false;
80
  }
81
+
82
  return true;
83
  }
84
+
85
  /**
86
  * Get an option array of all CMS pages available
87
+ *
88
  * @return array
89
  */
90
  public function toOptionArray()
91
  {
92
  if ($this->hasOptions()) {
93
  return $this->getOptions();
94
+
95
  }
96
+
97
  $options = array(
98
  '' => Mage::helper('postnl')->__('-- none --'),
99
  );
100
+
101
+ /**
102
+ * @var Mage_Cms_Model_Resource_Page_Collection $pageCollection
103
+ */
104
+ $pageCollection = Mage::getResourceModel('cms/page_collection')->load();
105
+ $pageOptions = $pageCollection->toOptionIdArray();
106
+
107
  $options = array_merge($options, $pageOptions);
108
  $this->setOptions($options);
109
+
110
  return $options;
111
  }
112
  }
app/code/community/TIG/PostNL/Model/Core/Cif.php CHANGED
@@ -33,14 +33,27 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
- */
39
-
40
- /**
41
  * Class containing all default methods used for CIF communication by this extension.
42
  *
43
- * If you wish to add new methods you can etxend this class or create a new class that extends TIG_PostNL_Model_Core_Cif_Abstract
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  */
45
  class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
46
  {
@@ -56,11 +69,6 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
56
  /**
57
  * Constants containing XML paths to cif address configuration options
58
  */
59
- const XML_PATH_SPLIT_STREET = 'postnl/cif_address/split_street';
60
- const XML_PATH_STREETNAME_FIELD = 'postnl/cif_address/streetname_field';
61
- const XML_PATH_HOUSENUMBER_FIELD = 'postnl/cif_address/housenr_field';
62
- const XML_PATH_SPLIT_HOUSENUMBER = 'postnl/cif_address/split_housenr';
63
- const XML_PATH_HOUSENUMBER_EXTENSION_FIELD = 'postnl/cif_address/housenr_extension_field';
64
  const XML_PATH_AREA_FIELD = 'postnl/cif_address/area_field';
65
  const XML_PATH_BUILDING_NAME_FIELD = 'postnl/cif_address/building_name_field';
66
  const XML_PATH_DEPARTMENT_FIELD = 'postnl/cif_address/department_field';
@@ -120,18 +128,6 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
120
  */
121
  const XML_PATH_WEIGHT_PER_PARCEL = 'postnl/cif_labels_and_confirming/weight_per_parcel';
122
 
123
- /**
124
- * Regular expression used to split streetname from housenumber. This regex works well for dutch
125
- * addresses, but may fail for international addresses. We strongly recommend using split address
126
- * lines instead.
127
- */
128
- const SPLIT_STREET_REGEX = '#\A(.*?)\s+(\d+[a-zA-Z]{0,1}\s{0,1}[-]{1}\s{0,1}\d*[a-zA-Z]{0,1}|\d+[a-zA-Z-]{0,1}\d*[a-zA-Z]{0,1})#';
129
-
130
- /**
131
- * Regular expression used to split housenumber and housenumber extension
132
- */
133
- const SPLIT_HOUSENUMBER_REGEX = '#^([\d]+)(.*)#s';
134
-
135
  /**
136
  * array containing possible address types
137
  *
@@ -209,17 +205,6 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
209
  'Zebra|GK420d',
210
  );
211
 
212
- /**
213
- * Array of countires which may send their full street data in a single line,
214
- * rather than having to split them into streetname, housenr and extension parts
215
- *
216
- * @var array
217
- */
218
- protected $_allowedFullStreetCountries = array(
219
- 'NL',
220
- 'BE'
221
- );
222
-
223
  /**
224
  * These shipment types require an invoice in the customs declaration. Other possible shipment types are:
225
  * - Gift
@@ -233,6 +218,22 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
233
  'Returned Goods',
234
  );
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  /**
237
  * Get possible address types
238
  *
@@ -254,23 +255,23 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
254
  }
255
 
256
  /**
257
- * Get country IDs that allow fullstreet usage
258
  *
259
  * @return array
260
  */
261
- public function getAllowedFullStreetCountries()
262
  {
263
- return $this->_allowedFullStreetCountries;
264
  }
265
 
266
  /**
267
- * Get shipment types that require an invoice number
268
  *
269
  * @return array
270
  */
271
- public function getInvoiceRequiredShipmentTypes()
272
  {
273
- return $this->_invoiceRequiredShipmentTypes;
274
  }
275
 
276
  /**
@@ -280,12 +281,12 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
280
  */
281
  public function getStoreId()
282
  {
283
- if ($this->getData('store_id')) {
284
  return $this->getData('store_id');
285
  }
286
 
287
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
288
- $this->setStoreId($storeId);
289
 
290
  return $storeId;
291
  }
@@ -341,9 +342,9 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
341
  }
342
 
343
  /**
344
- * Requests a new barcode from CIF as a ping request. This can be used to validate account settings or to check if the CIF
345
- * service is up and running. This is not meant to be used to generate an actual barcode for a shipment. Use the
346
- * generateBarcode method for that.
347
  *
348
  * The generateBarcode CIF call was chosena s it is the simplest CIF function available.
349
  *
@@ -357,6 +358,9 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
357
  {
358
  $this->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID);
359
 
 
 
 
360
  $barcode = $this->_getBarcodeData('NL');
361
 
362
  $message = $this->_getMessage('');
@@ -383,9 +387,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
383
  $response = $this->call(
384
  'Barcode',
385
  'GenerateBarcode',
386
- $soapParams,
387
- $data['username'],
388
- $data['password']
389
  );
390
 
391
  if (!is_object($response)
@@ -403,16 +405,15 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
403
  /**
404
  * Retrieves the latest shipping status of a shipment from CIF
405
  *
406
- * @param TIG_PostNL_Model_Core_Shipment $shipment
 
 
407
  *
408
  * @return StdClass
409
  *
410
- * @throws TIG_PostNL_Exception
411
  */
412
- public function getShipmentStatus($postnlShipment)
413
  {
414
- $shipment = $postnlShipment->getShipment();
415
-
416
  $barcode = $postnlShipment->getMainBarcode();
417
  $message = $this->_getMessage($barcode);
418
  $customer = $this->_getCustomer();
@@ -449,7 +450,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
449
  $shipment = $shipment[0];
450
  }
451
 
452
- if ($shipment->Barcode === $barcode) { // we need the original shipment, not a related shipment (such as a return shipment)
 
 
 
453
  return $shipment;
454
  }
455
  }
@@ -458,7 +462,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
458
  * no shipment could be matched to the supplied barcode
459
  */
460
  throw new TIG_PostNL_Exception(
461
- Mage::helper('postnl')->__( 'Unable to match barcode to shippingStatus response: %s', var_export($response, true)),
 
 
 
462
  'POSTNL-0063'
463
  );
464
  }
@@ -466,16 +473,15 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
466
  /**
467
  * Retrieves the latest shipping status of a shipment from CIF including full status history
468
  *
469
- * @param TIG_PostNL_Model_Core_Shipment $shipment
 
 
470
  *
471
  * @return StdClass
472
  *
473
- * @throws TIG_PostNL_Exception
474
  */
475
- public function getCompleteShipmentStatus($postnlShipment)
476
  {
477
- $shipment = $postnlShipment->getShipment();
478
-
479
  $barcode = $postnlShipment->getMainBarcode();
480
  $message = $this->_getMessage($barcode);
481
  $customer = $this->_getCustomer();
@@ -488,12 +494,6 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
488
  ),
489
  );
490
 
491
- $response = $this->call(
492
- 'ShippingStatus',
493
- 'CurrentStatus',
494
- $soapParams
495
- );
496
-
497
  $response = $this->call(
498
  'ShippingStatus',
499
  'CompleteStatus',
@@ -512,7 +512,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
512
 
513
  foreach($response->Shipments as $shipment) {
514
  $shipment = $shipment[0];
515
- if ($shipment->Barcode === $barcode) { // we need the original shipment, not a related shipment (such as a return shipment)
 
 
 
516
  return $shipment;
517
  }
518
  }
@@ -521,7 +524,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
521
  * no shipment could be matched to the supplied barcode
522
  */
523
  throw new TIG_PostNL_Exception(
524
- Mage::helper('postnl')->__( 'Unable to match barcode to shippingStatus response: %s', var_export($response, true)),
 
 
 
525
  'POSTNL-0063'
526
  );
527
  }
@@ -529,14 +535,17 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
529
  /**
530
  * Confirms the choen shipment without generating labels
531
  *
532
- * @param Mage_Sales_Model_Order_Shipment $shipment
533
- * @param string $barcode
534
- *
535
- * @return array
536
  *
537
  * @throws TIG_PostNL_Exception
 
 
538
  */
539
- public function confirmShipment($postnlShipment, $barcode, $mainBarcode = false, $shipmentNumber = false)
 
540
  {
541
  $shipment = $postnlShipment->getShipment();
542
 
@@ -592,15 +601,24 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
592
  /**
593
  * Generates shipping labels for the chosen shipment
594
  *
595
- * @param Mage_Sales_Model_Order_Shipment $shipment
 
 
 
596
  * @param string $printerType The printertype used. Currently only 'GraphicFile|PDF' is fully supported
597
  *
 
 
598
  * @return array
599
  *
600
- * @throws TIG_PostNL_Exception
601
  */
602
- public function generateLabels($postnlShipment, $barcode, $mainBarcode = false, $shipmentNumber = false, $printerType = 'GraphicFile|PDF')
603
- {
 
 
 
 
 
604
  $shipment = $postnlShipment->getShipment();
605
 
606
  $availablePrinterTypes = $this->_printerTypes;
@@ -651,15 +669,26 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
651
  /**
652
  * Generates shipping labels for the chosen shipment without confirming it
653
  *
654
- * @param Mage_Sales_Model_Order_Shipment $shipment
655
- * @param string $printerType The printertype used. Currently only 'GraphicFile|PDF' is fully supported
 
 
 
 
656
  *
657
- * @return array
658
  *
659
  * @throws TIG_PostNL_Exception
 
 
 
660
  */
661
- public function generateLabelsWithoutConfirm($postnlShipment, $barcode, $mainBarcode = false, $shipmentNumber = false, $printerType = 'GraphicFile|PDF')
662
- {
 
 
 
 
 
663
  $shipment = $postnlShipment->getShipment();
664
 
665
  $availablePrinterTypes = $this->_printerTypes;
@@ -699,7 +728,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
699
  || !is_object($response->Labels)
700
  ) {
701
  throw new TIG_PostNL_Exception(
702
- Mage::helper('postnl')->__('Invalid generateLabelsWithoutConfirm response: %s', var_export($response, true)),
 
 
 
703
  'POSTNL-0058'
704
  );
705
  }
@@ -710,13 +742,17 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
710
  /**
711
  * Gets the Message parameter
712
  *
 
713
  * @param array $extra An array of additional parameters to add
714
  *
715
  * @return array
716
  */
717
  protected function _getMessage($barcode, $extra = array())
718
  {
719
- $messageIdString = uniqid('postnl_')
 
 
 
720
  . $this->_getCustomerNumber()
721
  . $barcode
722
  . microtime();
@@ -736,7 +772,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
736
  /**
737
  * Gets the customer parameter
738
  *
739
- * @param Mage_Sales_Model_Order_Shipment | boolean $shipment
740
  *
741
  * @return array
742
  */
@@ -762,16 +798,15 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
762
  /**
763
  * Creates the CIF shipment object based on a PostNL shipment
764
  *
765
- * @param TIG_PostNL_Model_Core_Shipment $postnlShipment
766
- * @param string $barcode
767
- * @param bool $mainBarcode
768
- * @param bool $shipmentNumber
769
  *
770
  * @return array
771
- *
772
- * @todo modify to support OVM and PostNL checkout shipments
773
  */
774
- protected function _getShipment($postnlShipment, $barcode, $mainBarcode = false, $shipmentNumber = false)
 
775
  {
776
  $shipment = $postnlShipment->getShipment();
777
  $order = $shipment->getOrder();
@@ -785,8 +820,11 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
785
  * needs to be calculated
786
  */
787
  if ($shipmentNumber !== false) {
 
 
 
788
  $parcelWeight = Mage::getStoreConfig(self::XML_PATH_WEIGHT_PER_PARCEL, $postnlShipment->getStoreId());
789
- $parcelWeight = Mage::helper('postnl/cif')->standardizeWeight($parcelWeight, $shipment->getStoreId(), true); //convert the parcelweight to grams
790
 
791
  /**
792
  * All parcels except for the last one weigh a configured amount. The last parcel weighs the remainder
@@ -805,6 +843,15 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
805
  $shipmentWeight = 1;
806
  }
807
 
 
 
 
 
 
 
 
 
 
808
  $shipmentData = array(
809
  'Barcode' => $barcode,
810
  'CollectionTimeStampEnd' => '',
@@ -812,14 +859,14 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
812
  'DownPartnerBarcode' => '',
813
  'DownPartnerID' => '',
814
  'ProductCodeDelivery' => $postnlShipment->getProductCode(),
815
- 'Reference' => $shipment->getReference(),
816
  'Contacts' => array(
817
- 'Contact' => $this->_getContact($shippingAddress, $order),
818
  ),
819
  'Dimension' => array(
820
  'Weight' => round($shipmentWeight),
821
  ),
822
  'Reference' => $this->_getReference($shipment),
 
823
  );
824
 
825
  /**
@@ -840,23 +887,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
840
  /**
841
  * Add address data
842
  */
843
- $useSenderAddressAsReturn = Mage::getStoreConfig(self::XML_PATH_USE_SENDER_ADDRESS_AS_RETURN, $this->getStoreId());
844
- $pakjeGemakAddress = $postnlShipment->getPakjeGemakAddress();
845
-
846
- $addresses = array(
847
- 'Address' => array(
848
- $this->_getAddress('Receiver', $shippingAddress)
849
- ),
850
- );
851
-
852
- if (!$useSenderAddressAsReturn) {
853
- $addresses['Address'][] = $this->_getAddress('Alternative');
854
- }
855
-
856
- if ($pakjeGemakAddress) {
857
- $addresses['Address'][] =$this->_getAddress('Delivery', $pakjeGemakAddress);
858
- }
859
-
860
  $shipmentData['Addresses'] = $addresses;
861
 
862
  /**
@@ -876,15 +907,78 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
876
  $shipmentData['Customs'] = $this->_getCustoms($postnlShipment);
877
  }
878
 
 
 
 
 
 
879
  return $shipmentData;
880
  }
881
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
882
  /**
883
  * Gets an array containing required address data
884
  *
885
- * @param string $shippingAddress
886
- * @param Mage_Sales_Model_Order_Address $address
887
  *
 
888
  * @return array
889
  */
890
  protected function _getAddress($addressType, $shippingAddress= false)
@@ -924,7 +1018,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
924
  /**
925
  * Check if the return address is the same as the sender address. If so, no address is returned
926
  */
927
- $useSenderAddress = Mage::getStoreConfig(self::XML_PATH_USE_SENDER_ADDRESS_AS_RETURN, $this->getStoreId());
 
 
 
928
  if ($useSenderAddress) {
929
  return false;
930
  }
@@ -960,9 +1057,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
960
 
961
  /**
962
  * Forms an array of address data compatible with CIF
963
- *
964
- * @param Mage_Sales_Model_Order_Address $address
965
- * @param array | boolean $streetData Optional parameter containing streetname, housenr, housenr extension and fullStreet values.
 
966
  *
967
  * @return array
968
  */
@@ -1007,6 +1105,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1007
  */
1008
  protected function _getBarcodeData($barcodeType)
1009
  {
 
 
1010
  switch ($barcodeType) {
1011
  case 'NL':
1012
  $type = '3S';
@@ -1057,13 +1157,11 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1057
  /**
1058
  * Generates the CIF amount object containing the shipment's insured amount (if any)
1059
  *
1060
- * @param TIG_PostNL_Model_Core_Shipment $shipment
1061
  *
1062
  * @return array
1063
- *
1064
- * @todo implement COD
1065
  */
1066
- protected function _getAmount($postnlShipment)
1067
  {
1068
  $amount = array();
1069
  if (!$postnlShipment->hasExtraCover() && !$postnlShipment->isCod()) {
@@ -1074,7 +1172,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1074
  $extraCover = number_format($postnlShipment->getExtraCoverAmount(), 2, '.', '');
1075
  $amount[] = array(
1076
  'AccountName' => '',
1077
- 'AccountNr' => '',
 
1078
  'AmountType' => '02', // 01 = COD, 02 = Insured
1079
  'Currency' => 'EUR',
1080
  'Reference' => '',
@@ -1084,7 +1183,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1084
  }
1085
 
1086
  if ($postnlShipment->isCod()) {
1087
- //TODO implement COD here
1088
  }
1089
 
1090
  return $amount;
@@ -1094,27 +1193,51 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1094
  * Creates the CIF contact object
1095
  *
1096
  * @param Mage_Sales_Model_Order_Address $address
 
1097
  * @param Mage_Sales_Model_Order $order
1098
  *
1099
  * @return array
1100
- *
1101
- * @todo check if SMSNr is required for pakjegemak
1102
  */
1103
- protected function _getContact($address, Mage_Sales_Model_Order $order)
 
1104
  {
 
 
1105
  $contact = array(
1106
  'ContactType' => '01', // Receiver
1107
  'Email' => $order->getCustomerEmail(),
1108
- 'SMSNr' => '', // never sure if clean 06 number - TODO: check needed for PakjeGemak?
1109
  'TelNr' => $address->getTelephone(),
1110
  );
1111
 
1112
  return $contact;
1113
  }
1114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1115
  /**
1116
  * Creates the CIF group object
1117
  *
 
 
 
1118
  * @return array
1119
  */
1120
  protected function _getGroup($groupCount = 1, $mainBarcode = false, $shipmentNumber = false)
@@ -1140,196 +1263,31 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1140
  }
1141
 
1142
  /**
1143
- * Retrieves streetname, housenumber and housenumber extension from the shipping address.
1144
- * The shipping address may be in multiple streetlines configuration or single line
1145
- * configuration. In the case of multi-line, each part of the street data will be in a seperate
1146
- * field. In the single line configuration, each part will be in the same field and will have
1147
- * to be split using PREG.
1148
  *
1149
- * PREG cannot be relied on as it is impossible to create a regex that can filter all
1150
- * possible street syntaxes. Therefore we strongly recommend to use multiple street lines. This
1151
- * can be enabled in Magento community in system > config > customer configuration. Or if you
1152
- * use Enterprise, in customers > attributes > manage customer address attributes.
1153
- *
1154
- * @param Mage_Sales_Model_Order_Address $address
1155
- *
1156
- * @return array
1157
- */
1158
- protected function _getStreetData($address)
1159
- {
1160
- $storeId = $this->getStoreId();
1161
- $splitStreet = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_STREET, $storeId);
1162
-
1163
- /**
1164
- * Website uses multi-line address mode
1165
- */
1166
- if ($splitStreet) {
1167
- $streetData = $this->_getMultiLineStreetData($address);
1168
-
1169
- /**
1170
- * If $streetData is false it means a required field was missing. In this
1171
- * case the alternative methods are used to obtain the address data.
1172
- */
1173
- if ($streetData !== false) {
1174
- return $streetData;
1175
- }
1176
- }
1177
-
1178
- /**
1179
- * Website uses single-line address mode
1180
- */
1181
- $allowedFullStreetCountries = $this->getAllowedFullStreetCountries();
1182
- $fullStreet = $address->getStreetFull();
1183
-
1184
- /**
1185
- * Select countries don't have to split their street values into seperate part
1186
- */
1187
- if (in_array($address->getCountry(), $allowedFullStreetCountries)) {
1188
- $streetData = array(
1189
- 'streetname' => '',
1190
- 'housenumber' => '',
1191
- 'housenumberExtension' => '',
1192
- 'fullStreet' => $fullStreet,
1193
- );
1194
- return $streetData;
1195
- }
1196
-
1197
- /**
1198
- * All other countries must split them using PREG
1199
- */
1200
- $streetData = $this->_getSplitStreetData($fullStreet);
1201
-
1202
- return $streetData;
1203
- }
1204
-
1205
- /**
1206
- * Retrieves streetname, housenumber and housenumber extension from the shipping address in the multiple streetlines configuration.
1207
  *
1208
  * @param Mage_Sales_Model_Order_Address $address
 
1209
  *
1210
  * @return array
1211
  */
1212
- protected function _getMultiLineStreetData($address)
1213
  {
 
1214
  $storeId = $this->getStoreId();
1215
- $streetnameField = (int) Mage::getStoreConfig(self::XML_PATH_STREETNAME_FIELD, $storeId);
1216
- $housenumberField = (int) Mage::getStoreConfig(self::XML_PATH_HOUSENUMBER_FIELD, $storeId);
1217
-
1218
- $streetname = $address->getStreet($streetnameField);
1219
- $housenumber = $address->getStreet($housenumberField);
1220
-
1221
- /**
1222
- * If street or housenr fields are empty, use alternative options to obtain the address data
1223
- */
1224
- if (is_null($streetname) || is_null($housenumber)) {
1225
- return false;
1226
- }
1227
-
1228
- /**
1229
- * Split the housenumber into a number and an extension
1230
- */
1231
- $splitHouseNumber = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_HOUSENUMBER, $storeId);
1232
- if ($splitHouseNumber) {
1233
- $housenumberExtensionField = (int) Mage::getStoreConfig(self::XML_PATH_HOUSENUMBER_EXTENSION_FIELD, $storeId);
1234
- $housenumberExtension = $address->getStreet($housenumberExtensionField);
1235
- } else {
1236
- $housenumberParts = $this->_splitHousenumber($housenumber);
1237
- $housenumber = $housenumberParts['number'];
1238
- $housenumberExtension = $housenumberParts['extension'];
1239
- }
1240
-
1241
- $streetData = array(
1242
- 'streetname' => $streetname,
1243
- 'housenumber' => $housenumber,
1244
- 'housenumberExtension' => $housenumberExtension,
1245
- 'fullStreet' => '',
1246
- );
1247
-
1248
- return $streetData;
1249
- }
1250
 
1251
- /**
1252
- * Splits street data into seperate parts for streetname, housenumber and extension.
1253
- *
1254
- * @param string $fullStreet The full streetname including all parts
1255
- *
1256
- * @return array
1257
- *
1258
- * @throws TIG_PostNL_Exception
1259
- */
1260
- protected function _getSplitStreetData($fullStreet)
1261
- {
1262
- $result = preg_match(self::SPLIT_STREET_REGEX, $fullStreet, $matches);
1263
- if (!$result || !is_array($matches)) {
1264
- throw new TIG_PostNL_Exception(
1265
- Mage::helper('postnl')->__('Invalid full street supplied: %s', $fullStreet),
1266
- 'POSTNL-0060'
1267
- );
1268
- }
1269
-
1270
- $streetname = '';
1271
- $housenumber = '';
1272
- if (isset($matches[1])) {
1273
- $streetname = $matches[1];
1274
- }
1275
-
1276
- if (isset($matches[2])) {
1277
- $housenumber = $matches[2];
1278
- }
1279
-
1280
- $housenumberParts = $this->_splitHousenumber($housenumber);
1281
- $housenumber = $housenumberParts['number'];
1282
- $housenumberExtension = $housenumberParts['extension'];
1283
-
1284
- $streetData = array(
1285
- 'streetname' => $streetname,
1286
- 'housenumber' => $housenumber,
1287
- 'housenumberExtension' => $housenumberExtension,
1288
- 'fullStreet' => '',
1289
- );
1290
 
1291
  return $streetData;
1292
  }
1293
 
1294
- /**
1295
- * Splits a supplier housenumber into a number and an extension
1296
- *
1297
- * @param string $housenumber
1298
- *
1299
- * @return array
1300
- *
1301
- * @throws TIG_PostNL_Exception
1302
- */
1303
- protected function _splitHousenumber($housenumber)
1304
- {
1305
- $housenumber = trim($housenumber);
1306
-
1307
- $result = preg_match(self::SPLIT_HOUSENUMBER_REGEX, $housenumber, $matches);
1308
- if (!$result || !is_array($matches)) {
1309
- throw new TIG_PostNL_Exception(
1310
- Mage::helper('postnl')->__('Invalid housnumber supplied: %s', $housenumber),
1311
- 'POSTNL-0059'
1312
- );
1313
- }
1314
-
1315
- $extension = '';
1316
- $number = '';
1317
- if (isset($matches[1])) {
1318
- $number = $matches[1];
1319
- }
1320
-
1321
- if (isset($matches[2])) {
1322
- $extension = trim($matches[2]);
1323
- }
1324
-
1325
- $housenumberParts = array(
1326
- 'number' => $number,
1327
- 'extension' => $extension,
1328
- );
1329
-
1330
- return $housenumberParts;
1331
- }
1332
-
1333
  /**
1334
  * create Customs CIF object
1335
  *
@@ -1340,10 +1298,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1340
  protected function _getCustoms($postnlShipment)
1341
  {
1342
  $shipment = $postnlShipment->getShipment();
1343
- $shipmentType = $postnlShipment->getShipmentType();
1344
 
1345
  $customs = array(
1346
- 'ShipmentType' => $shipmentType, // Gift / Documents / Commercial Goods / Commercial Sample / Returned Goods
1347
  'HandleAsNonDeliverable' => 'false',
1348
  'Invoice' => 'false',
1349
  'Certificate' => 'false',
@@ -1352,7 +1310,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1352
  );
1353
 
1354
  /**
1355
- * Check if the shipment should be treated as abandoned when it can't be delivered or if it should be returned to the sender
 
1356
  */
1357
  if ($postnlShipment->getTreatAsAbandoned()) {
1358
  $customs['HandleAsNonDeliverable'] = 'true';
@@ -1397,6 +1356,9 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1397
  $content = array();
1398
  $items = $this->_sortCustomsItems($shipment->getAllItems());
1399
 
 
 
 
1400
  foreach ($items as $item) {
1401
  /**
1402
  * A maximum of 5 rows are allowed
@@ -1465,13 +1427,20 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1465
  /**
1466
  * Get the attribute and direction used for sorting
1467
  */
1468
- $sortingAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_PRODUCT_SORTING_ATTRIBUTE, $this->getStoreId());
1469
- $sortingDirection = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_PRODUCT_SORTING_DIRECTION, $this->getStoreId());
 
 
 
 
 
 
1470
 
1471
  /**
1472
  * Place the item's sorting value in a temporary array where the key is the item's ID
 
 
1473
  */
1474
- $sortingValue = array();
1475
  foreach ($items as $item) {
1476
  $product = $item->getOrderItem()->getProduct();
1477
  $sortingAttributeValue = $product->getDataUsingMethod($sortingAttribute);
@@ -1501,11 +1470,11 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1501
  /**
1502
  * Get a shipment item's HS tariff
1503
  *
1504
- * @param Mage_Sales_Model_Order_Shipment_item
1505
  *
1506
  * @return string
1507
  */
1508
- protected function _getHSTariff($shipmentItem)
1509
  {
1510
  $storeId = $this->getStoreId();
1511
 
@@ -1516,7 +1485,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1516
  return '000000';
1517
  }
1518
 
1519
- if ($this->getHSTariffAttribute() !== null) {
1520
  $hsTariffAttribute = $this->getHSTariffAttribute();
1521
  } else {
1522
  $hsTariffAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_HS_TARIFF_ATTRIBUTE, $storeId);
@@ -1537,17 +1506,22 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1537
  /**
1538
  * Get a shipment item's country of origin
1539
  *
1540
- * @param Mage_Sales_Model_Order_Shipment_item
 
 
1541
  *
1542
  * @return string
1543
  */
1544
  protected function _getCountryOfOrigin($shipmentItem)
1545
  {
1546
  $storeId = $this->getStoreId();
1547
- if ($this->getCountryOfOriginAttribute() !== null) {
1548
  $countryOfOriginAttribute = $this->getCountryOfOriginAttribute();
1549
  } else {
1550
- $countryOfOriginAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_COUNTRY_OF_ORIGIN_ATTRIBUTE, $storeId);
 
 
 
1551
  $this->setCountryOfOriginAttribute($countryOfOriginAttribute);
1552
  }
1553
 
@@ -1557,7 +1531,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1557
 
1558
  if (empty($countryOfOrigin)) {
1559
  throw new TIG_PostNL_Exception(
1560
- Mage::helper('postnl')->__('Missing country of origin value for product #%s.', $shipmentItem->getProductId()),
 
 
 
1561
  'POSTNL-0091'
1562
  );
1563
  }
@@ -1568,14 +1545,16 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1568
  /**
1569
  * Get a shipment item's customs value
1570
  *
1571
- * @param Mage_Sales_Model_Order_Shipment_item
 
 
1572
  *
1573
  * @return string
1574
  */
1575
  protected function _getCustomsValue($shipmentItem)
1576
  {
1577
  $storeId = $this->getStoreId();
1578
- if ($this->getCustomsValueAttribute() !== null) {
1579
  $customsValueAttribute = $this->getCustomsValueAttribute();
1580
  } else {
1581
  $customsValueAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_CUSTOMS_VALUE_ATTRIBUTE, $storeId);
@@ -1599,14 +1578,16 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1599
  /**
1600
  * Get a shipment item's customs description
1601
  *
1602
- * @param Mage_Sales_Model_Order_Shipment_item
 
 
1603
  *
1604
  * @return string
1605
  */
1606
  protected function _getCustomsDescription($shipmentItem)
1607
  {
1608
  $storeId = $this->getStoreId();
1609
- if ($this->getCustomsDescriptionAttribute() !== null) {
1610
  $descriptionAttribute = $this->getCustomsDescriptionAttribute();
1611
  } else {
1612
  $descriptionAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_DESCRIPTION_ATTRIBUTE, $storeId);
@@ -1619,7 +1600,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1619
 
1620
  if (empty($description)) {
1621
  throw new TIG_PostNL_Exception(
1622
- Mage::helper('postnl')->__('Missing customs description for product #%s.', $shipmentItem->getProductId()),
 
 
 
1623
  'POSTNL-0093'
1624
  );
1625
  }
@@ -1717,7 +1701,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1717
  protected function _getCustomsCertificate()
1718
  {
1719
  $storeId = $this->getStoreId();
1720
- $customsCertificate = (string) Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_CUSTOMS_CERTIFICATE_NUMBER, $storeId);
 
 
 
1721
 
1722
  if (empty($customsCertificate)) {
1723
  return false;
@@ -1729,6 +1716,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1729
  /**
1730
  * Get the area field from an address if enabled
1731
  *
 
 
1732
  * @return string
1733
  */
1734
  protected function _getArea($address)
@@ -1744,6 +1733,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1744
  /**
1745
  * Attempt to get the area through the magic getter instead
1746
  */
 
1747
  $area = $address->getArea();
1748
 
1749
  return $area;
@@ -1752,6 +1742,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1752
  /**
1753
  * Get the area building name from an address if enabled
1754
  *
 
 
1755
  * @return string
1756
  */
1757
  protected function _getBuildingName($address)
@@ -1767,6 +1759,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1767
  /**
1768
  * Attempt to get the building name through the magic getter instead
1769
  */
 
1770
  $buildingName = $address->getBuildingName();
1771
 
1772
  return $buildingName;
@@ -1775,6 +1768,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1775
  /**
1776
  * Get the department field from an address if enabled
1777
  *
 
 
1778
  * @return string
1779
  */
1780
  protected function _getDepartment($address)
@@ -1790,6 +1785,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1790
  /**
1791
  * Attempt to get department through the magic getter instead
1792
  */
 
1793
  $department = $address->getDepartment();
1794
 
1795
  return $department;
@@ -1798,6 +1794,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1798
  /**
1799
  * Get the doorcode field from an address if enabled
1800
  *
 
 
1801
  * @return string
1802
  */
1803
  protected function _getDoorcode($address)
@@ -1813,6 +1811,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1813
  /**
1814
  * Attempt to get the doorcode through the magic getter instead
1815
  */
 
1816
  $doorcode = $address->getDoorcode();
1817
 
1818
  return $doorcode;
@@ -1821,6 +1820,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1821
  /**
1822
  * Get the floor field from an address if enabled
1823
  *
 
 
1824
  * @return string
1825
  */
1826
  protected function _getFloor($address)
@@ -1836,6 +1837,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1836
  /**
1837
  * Attempt to get the floor through the magic getter instead
1838
  */
 
1839
  $floor = $address->getFloor();
1840
 
1841
  return $floor;
@@ -1844,6 +1846,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1844
  /**
1845
  * Get the remark field from an address if enabled
1846
  *
 
 
1847
  * @return string
1848
  */
1849
  protected function _getRemark($address)
@@ -1859,6 +1863,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1859
  /**
1860
  * Attempt to get the remark through the magic getter instead
1861
  */
 
1862
  $remark = $address->getRemark();
1863
 
1864
  return $remark;
@@ -1867,7 +1872,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1867
  /**
1868
  * Get a shipment's reference. By default this will be the shipment's increment ID
1869
  *
1870
- * @param Mage_Sales_Model_Order_Shipment
1871
  *
1872
  * @return string
1873
  *
@@ -1906,10 +1911,11 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1906
  * For custom references we need to replace several optional variables
1907
  */
1908
  if ($referenceType == 'custom') {
 
 
1909
  $reference = str_replace('{{var shipment_increment_id}}', $shipment->getIncrementId(), $reference);
1910
  $reference = str_replace('{{var order_increment_id}}', $shipment->getOrder()->getIncrementId(), $reference);
1911
 
1912
- $store = Mage::getModel('core/store')->load($storeId);
1913
  $reference = str_replace('{{var store_frontend_name}}', $store->getFrontendName(), $reference);
1914
  }
1915
 
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
 
 
39
  * Class containing all default methods used for CIF communication by this extension.
40
  *
41
+ * If you wish to add new methods you can etxend this class or create a new class that extends
42
+ * TIG_PostNL_Model_Core_Cif_Abstract.
43
+ *
44
+ * @method TIG_PostNL_Model_Core_Cif setStoreId(int $value)
45
+ * @method boolean hasHSTariffAttribute()
46
+ * @method string getHSTariffAttribute()
47
+ * @method TIG_PostNL_Model_Core_Cif setHSTariffAttribute(string $value)
48
+ * @method boolean hasCountryOfOriginAttribute()
49
+ * @method string getCountryOfOriginAttribute()
50
+ * @method TIG_PostNL_Model_Core_Cif setCountryOfOriginAttribute(string $value)
51
+ * @method boolean hasCustomsValueAttribute()
52
+ * @method string getCustomsValueAttribute()
53
+ * @method TIG_PostNL_Model_Core_Cif setCustomsValueAttribute(string $value)
54
+ * @method boolean hasCustomsDescriptionAttribute()
55
+ * @method string getCustomsDescriptionAttribute()
56
+ * @method TIG_PostNL_Model_Core_Cif setCustomsDescriptionAttribute(string $value)
57
  */
58
  class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
59
  {
69
  /**
70
  * Constants containing XML paths to cif address configuration options
71
  */
 
 
 
 
 
72
  const XML_PATH_AREA_FIELD = 'postnl/cif_address/area_field';
73
  const XML_PATH_BUILDING_NAME_FIELD = 'postnl/cif_address/building_name_field';
74
  const XML_PATH_DEPARTMENT_FIELD = 'postnl/cif_address/department_field';
128
  */
129
  const XML_PATH_WEIGHT_PER_PARCEL = 'postnl/cif_labels_and_confirming/weight_per_parcel';
130
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  /**
132
  * array containing possible address types
133
  *
205
  'Zebra|GK420d',
206
  );
207
 
 
 
 
 
 
 
 
 
 
 
 
208
  /**
209
  * These shipment types require an invoice in the customs declaration. Other possible shipment types are:
210
  * - Gift
218
  'Returned Goods',
219
  );
220
 
221
+ /**
222
+ * These shipment types need specific product options.
223
+ *
224
+ * @var array
225
+ */
226
+ protected $_availableProductOptions = array(
227
+ 'PGE' => array(
228
+ 'Characteristic' => '118',
229
+ 'Option' => '002',
230
+ ),
231
+ 'Avond' => array(
232
+ 'Characteristic' => '118',
233
+ 'Option' => '006',
234
+ ),
235
+ );
236
+
237
  /**
238
  * Get possible address types
239
  *
255
  }
256
 
257
  /**
258
+ * Get shipment types that require an invoice number
259
  *
260
  * @return array
261
  */
262
+ public function getInvoiceRequiredShipmentTypes()
263
  {
264
+ return $this->_invoiceRequiredShipmentTypes;
265
  }
266
 
267
  /**
268
+ * Get an array of available product options per type.
269
  *
270
  * @return array
271
  */
272
+ public function getAvailableProductOptions()
273
  {
274
+ return $this->_availableProductOptions;
275
  }
276
 
277
  /**
281
  */
282
  public function getStoreId()
283
  {
284
+ if ($this->hasData('store_id')) {
285
  return $this->getData('store_id');
286
  }
287
 
288
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
289
+ $this->setData('store_id', $storeId);
290
 
291
  return $storeId;
292
  }
342
  }
343
 
344
  /**
345
+ * Requests a new barcode from CIF as a ping request. This can be used to validate account settings or to check if
346
+ * the CIF service is up and running. This is not meant to be used to generate an actual barcode for a shipment.
347
+ * Use the generateBarcode method for that.
348
  *
349
  * The generateBarcode CIF call was chosena s it is the simplest CIF function available.
350
  *
358
  {
359
  $this->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID);
360
 
361
+ $this->setPassword($data['password']);
362
+ $this->setUsername($data['username']);
363
+
364
  $barcode = $this->_getBarcodeData('NL');
365
 
366
  $message = $this->_getMessage('');
387
  $response = $this->call(
388
  'Barcode',
389
  'GenerateBarcode',
390
+ $soapParams
 
 
391
  );
392
 
393
  if (!is_object($response)
405
  /**
406
  * Retrieves the latest shipping status of a shipment from CIF
407
  *
408
+ * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
409
+ *
410
+ * @throws TIG_PostNL_Exception
411
  *
412
  * @return StdClass
413
  *
 
414
  */
415
+ public function getShipmentStatus(TIG_PostnL_Model_Core_Shipment $postnlShipment)
416
  {
 
 
417
  $barcode = $postnlShipment->getMainBarcode();
418
  $message = $this->_getMessage($barcode);
419
  $customer = $this->_getCustomer();
450
  $shipment = $shipment[0];
451
  }
452
 
453
+ /**
454
+ * We need the original shipment, not a related shipment (such as a return shipment).
455
+ */
456
+ if ($shipment->Barcode === $barcode) {
457
  return $shipment;
458
  }
459
  }
462
  * no shipment could be matched to the supplied barcode
463
  */
464
  throw new TIG_PostNL_Exception(
465
+ Mage::helper('postnl')->__(
466
+ 'Unable to match barcode to shippingStatus response: %s',
467
+ var_export($response, true)
468
+ ),
469
  'POSTNL-0063'
470
  );
471
  }
473
  /**
474
  * Retrieves the latest shipping status of a shipment from CIF including full status history
475
  *
476
+ * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
477
+ *
478
+ * @throws TIG_PostNL_Exception
479
  *
480
  * @return StdClass
481
  *
 
482
  */
483
+ public function getCompleteShipmentStatus(TIG_PostnL_Model_Core_Shipment $postnlShipment)
484
  {
 
 
485
  $barcode = $postnlShipment->getMainBarcode();
486
  $message = $this->_getMessage($barcode);
487
  $customer = $this->_getCustomer();
494
  ),
495
  );
496
 
 
 
 
 
 
 
497
  $response = $this->call(
498
  'ShippingStatus',
499
  'CompleteStatus',
512
 
513
  foreach($response->Shipments as $shipment) {
514
  $shipment = $shipment[0];
515
+ /**
516
+ * we need the original shipment, not a related shipment (such as a return shipment).
517
+ */
518
+ if ($shipment->Barcode === $barcode) {
519
  return $shipment;
520
  }
521
  }
524
  * no shipment could be matched to the supplied barcode
525
  */
526
  throw new TIG_PostNL_Exception(
527
+ Mage::helper('postnl')->__(
528
+ 'Unable to match barcode to shippingStatus response: %s',
529
+ var_export($response, true)
530
+ ),
531
  'POSTNL-0063'
532
  );
533
  }
535
  /**
536
  * Confirms the choen shipment without generating labels
537
  *
538
+ * @param TIG_PostNL_Model_Core_Shipment $postnlShipment
539
+ * @param string $barcode
540
+ * @param bool $mainBarcode
541
+ * @param bool $shipmentNumber
542
  *
543
  * @throws TIG_PostNL_Exception
544
+ *
545
+ * @return array
546
  */
547
+ public function confirmShipment(TIG_PostNL_Model_Core_Shipment $postnlShipment, $barcode, $mainBarcode = false,
548
+ $shipmentNumber = false)
549
  {
550
  $shipment = $postnlShipment->getShipment();
551
 
601
  /**
602
  * Generates shipping labels for the chosen shipment
603
  *
604
+ * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
605
+ * @param $barcode
606
+ * @param bool $mainBarcode
607
+ * @param bool $shipmentNumber
608
  * @param string $printerType The printertype used. Currently only 'GraphicFile|PDF' is fully supported
609
  *
610
+ * @throws TIG_PostNL_Exception
611
+ *
612
  * @return array
613
  *
 
614
  */
615
+ public function generateLabels(
616
+ TIG_PostnL_Model_Core_Shipment $postnlShipment,
617
+ $barcode,
618
+ $mainBarcode = false,
619
+ $shipmentNumber = false,
620
+ $printerType = 'GraphicFile|PDF'
621
+ ) {
622
  $shipment = $postnlShipment->getShipment();
623
 
624
  $availablePrinterTypes = $this->_printerTypes;
669
  /**
670
  * Generates shipping labels for the chosen shipment without confirming it
671
  *
672
+ * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
673
+ * @param string $barcode
674
+ * @param boolean|string $mainBarcode
675
+ * @param bool|int $shipmentNumber
676
+ * @param string $printerType The printertype used. Currently only
677
+ * 'GraphicFile|PDF' is fully supported.
678
  *
 
679
  *
680
  * @throws TIG_PostNL_Exception
681
+ *
682
+ * @return array
683
+ *
684
  */
685
+ public function generateLabelsWithoutConfirm(
686
+ TIG_PostnL_Model_Core_Shipment $postnlShipment,
687
+ $barcode,
688
+ $mainBarcode = false,
689
+ $shipmentNumber = false,
690
+ $printerType = 'GraphicFile|PDF'
691
+ ) {
692
  $shipment = $postnlShipment->getShipment();
693
 
694
  $availablePrinterTypes = $this->_printerTypes;
728
  || !is_object($response->Labels)
729
  ) {
730
  throw new TIG_PostNL_Exception(
731
+ Mage::helper('postnl')->__(
732
+ 'Invalid generateLabelsWithoutConfirm response: %s',
733
+ var_export($response, true)
734
+ ),
735
  'POSTNL-0058'
736
  );
737
  }
742
  /**
743
  * Gets the Message parameter
744
  *
745
+ * @param $barcode
746
  * @param array $extra An array of additional parameters to add
747
  *
748
  * @return array
749
  */
750
  protected function _getMessage($barcode, $extra = array())
751
  {
752
+ $messageIdString = uniqid(
753
+ 'postnl_'
754
+ . ip2long(Mage::helper('core/http')->getServerAddr())
755
+ )
756
  . $this->_getCustomerNumber()
757
  . $barcode
758
  . microtime();
772
  /**
773
  * Gets the customer parameter
774
  *
775
+ * @param Mage_Sales_Model_Order_Shipment|boolean $shipment
776
  *
777
  * @return array
778
  */
798
  /**
799
  * Creates the CIF shipment object based on a PostNL shipment
800
  *
801
+ * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
802
+ * @param $barcode
803
+ * @param bool $mainBarcode
804
+ * @param bool $shipmentNumber
805
  *
806
  * @return array
 
 
807
  */
808
+ protected function _getShipment(TIG_PostnL_Model_Core_Shipment $postnlShipment,
809
+ $barcode, $mainBarcode = false, $shipmentNumber = false)
810
  {
811
  $shipment = $postnlShipment->getShipment();
812
  $order = $shipment->getOrder();
820
  * needs to be calculated
821
  */
822
  if ($shipmentNumber !== false) {
823
+ /**
824
+ * Get the parcel weight and then convert it to grams.
825
+ */
826
  $parcelWeight = Mage::getStoreConfig(self::XML_PATH_WEIGHT_PER_PARCEL, $postnlShipment->getStoreId());
827
+ $parcelWeight = Mage::helper('postnl/cif')->standardizeWeight($parcelWeight, $shipment->getStoreId(), true);
828
 
829
  /**
830
  * All parcels except for the last one weigh a configured amount. The last parcel weighs the remainder
843
  $shipmentWeight = 1;
844
  }
845
 
846
+ /**
847
+ * Get and format this shipment's delivery date if available.
848
+ */
849
+ $deliveryDate = $postnlShipment->getDeliveryDate();
850
+ if ($deliveryDate) {
851
+ $deliveryTime = strtotime($deliveryDate);
852
+ $deliveryDate = date('d-m-Y H:i:s', $deliveryTime);
853
+ }
854
+
855
  $shipmentData = array(
856
  'Barcode' => $barcode,
857
  'CollectionTimeStampEnd' => '',
859
  'DownPartnerBarcode' => '',
860
  'DownPartnerID' => '',
861
  'ProductCodeDelivery' => $postnlShipment->getProductCode(),
 
862
  'Contacts' => array(
863
+ 'Contact' => $this->_getContact($shippingAddress, $postnlShipment, $order),
864
  ),
865
  'Dimension' => array(
866
  'Weight' => round($shipmentWeight),
867
  ),
868
  'Reference' => $this->_getReference($shipment),
869
+ 'DeliveryDate' => $deliveryDate,
870
  );
871
 
872
  /**
887
  /**
888
  * Add address data
889
  */
890
+ $addresses = $this->_getShipmentAddresses($postnlShipment, $shippingAddress);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
891
  $shipmentData['Addresses'] = $addresses;
892
 
893
  /**
907
  $shipmentData['Customs'] = $this->_getCustoms($postnlShipment);
908
  }
909
 
910
+ $productOptions = $this->_getProductOptions($postnlShipment);
911
+ if ($productOptions) {
912
+ $shipmentData['ProductOptions'] = $productOptions;
913
+ }
914
+
915
  return $shipmentData;
916
  }
917
 
918
+ /**
919
+ * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
920
+ * @param Mage_Sales_Model_order_Address $shippingAddress
921
+ *
922
+ * @return array
923
+ */
924
+ protected function _getShipmentAddresses(TIG_PostnL_Model_Core_Shipment $postnlShipment, $shippingAddress)
925
+ {
926
+ $useSenderAddressAsReturn = Mage::getStoreConfig(
927
+ self::XML_PATH_USE_SENDER_ADDRESS_AS_RETURN,
928
+ $this->getStoreId()
929
+ );
930
+ $pakjeGemakAddress = $postnlShipment->getPakjeGemakAddress();
931
+
932
+ $addresses = array(
933
+ 'Address' => array(
934
+ $this->_getAddress('Receiver', $shippingAddress)
935
+ ),
936
+ );
937
+
938
+ if (!$useSenderAddressAsReturn) {
939
+ $addresses['Address'][] = $this->_getAddress('Alternative');
940
+ }
941
+
942
+ if ($pakjeGemakAddress) {
943
+ $addresses['Address'][] =$this->_getAddress('Delivery', $pakjeGemakAddress);
944
+ }
945
+
946
+ return $addresses;
947
+ }
948
+
949
+ /**
950
+ * Gets product options based on a specified shipment.
951
+ *
952
+ * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
953
+ *
954
+ * @return array|bool
955
+ */
956
+ protected function _getProductOptions(TIG_PostnL_Model_Core_Shipment $postnlShipment)
957
+ {
958
+ $postnlOrder = $postnlShipment->getPostnlOrder();
959
+ if (!$postnlOrder) {
960
+ return false;
961
+ }
962
+
963
+ $type = $postnlOrder->getType();
964
+ $availableProductOptions = $this->getAvailableProductOptions();
965
+ if (!array_key_exists($type, $availableProductOptions)) {
966
+ return false;
967
+ }
968
+
969
+ $productOptions = array(
970
+ 'ProductOption' => $availableProductOptions[$type]
971
+ );
972
+ return $productOptions;
973
+ }
974
+
975
  /**
976
  * Gets an array containing required address data
977
  *
978
+ * @param $addressType
979
+ * @param bool|string $shippingAddress
980
  *
981
+ * @throws TIG_PostNL_Exception
982
  * @return array
983
  */
984
  protected function _getAddress($addressType, $shippingAddress= false)
1018
  /**
1019
  * Check if the return address is the same as the sender address. If so, no address is returned
1020
  */
1021
+ $useSenderAddress = Mage::getStoreConfig(
1022
+ self::XML_PATH_USE_SENDER_ADDRESS_AS_RETURN,
1023
+ $this->getStoreId()
1024
+ );
1025
  if ($useSenderAddress) {
1026
  return false;
1027
  }
1057
 
1058
  /**
1059
  * Forms an array of address data compatible with CIF
1060
+
1061
+ * @param Mage_Sales_Model_Order_Address|Varien_Object $address
1062
+ * @param array|boolean $streetData Optional parameter containing streetname,
1063
+ * housenr, housenr extension and fullStreet values.
1064
  *
1065
  * @return array
1066
  */
1105
  */
1106
  protected function _getBarcodeData($barcodeType)
1107
  {
1108
+ $barcodeType = strtoupper($barcodeType);
1109
+
1110
  switch ($barcodeType) {
1111
  case 'NL':
1112
  $type = '3S';
1157
  /**
1158
  * Generates the CIF amount object containing the shipment's insured amount (if any)
1159
  *
1160
+ * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
1161
  *
1162
  * @return array
 
 
1163
  */
1164
+ protected function _getAmount(TIG_PostnL_Model_Core_Shipment $postnlShipment)
1165
  {
1166
  $amount = array();
1167
  if (!$postnlShipment->hasExtraCover() && !$postnlShipment->isCod()) {
1172
  $extraCover = number_format($postnlShipment->getExtraCoverAmount(), 2, '.', '');
1173
  $amount[] = array(
1174
  'AccountName' => '',
1175
+ 'BIC' => '',
1176
+ 'IBAN' => '',
1177
  'AmountType' => '02', // 01 = COD, 02 = Insured
1178
  'Currency' => 'EUR',
1179
  'Reference' => '',
1183
  }
1184
 
1185
  if ($postnlShipment->isCod()) {
1186
+ /** @todo implement COD here */
1187
  }
1188
 
1189
  return $amount;
1193
  * Creates the CIF contact object
1194
  *
1195
  * @param Mage_Sales_Model_Order_Address $address
1196
+ * @param TIG_PostNL_Model_Core_Shipment $postnlShipment
1197
  * @param Mage_Sales_Model_Order $order
1198
  *
1199
  * @return array
 
 
1200
  */
1201
+ protected function _getContact($address, TIG_PostNL_Model_Core_Shipment $postnlShipment,
1202
+ Mage_Sales_Model_Order $order)
1203
  {
1204
+ $smsNr = $this->_getMobilePhoneNumber($postnlShipment);
1205
+
1206
  $contact = array(
1207
  'ContactType' => '01', // Receiver
1208
  'Email' => $order->getCustomerEmail(),
1209
+ 'SMSNr' => $smsNr,
1210
  'TelNr' => $address->getTelephone(),
1211
  );
1212
 
1213
  return $contact;
1214
  }
1215
 
1216
+ /**
1217
+ * Gets a mobile phone number for the current shipment.
1218
+ *
1219
+ * @param TIG_PostNL_Model_Core_Shipment $postnlShipment
1220
+ *
1221
+ * @return string
1222
+ */
1223
+ protected function _getMobilePhoneNumber(TIG_PostNL_Model_Core_Shipment $postnlShipment)
1224
+ {
1225
+ $mobilePhoneNumber = '';
1226
+
1227
+ $postnlOrder = $postnlShipment->getPostnlOrder();
1228
+ if ($postnlOrder && $postnlOrder->getMobilePhoneNumber()) {
1229
+ $mobilePhoneNumber = $postnlOrder->getMobilePhoneNumber();
1230
+ }
1231
+
1232
+ return $mobilePhoneNumber;
1233
+ }
1234
+
1235
  /**
1236
  * Creates the CIF group object
1237
  *
1238
+ * @param int $groupCount
1239
+ * @param bool $mainBarcode
1240
+ * @param bool $shipmentNumber
1241
  * @return array
1242
  */
1243
  protected function _getGroup($groupCount = 1, $mainBarcode = false, $shipmentNumber = false)
1263
  }
1264
 
1265
  /**
1266
+ * Retrieves streetname, housenumber and housenumber extension from the shipping address. The shipping address may
1267
+ * be in multiple streetlines configuration or single line configuration. In the case of multi-line, each part of
1268
+ * the street data will be in a seperate field. In the single line configuration, each part will be in the same
1269
+ * field and will have to be split using PREG.
 
1270
  *
1271
+ * PREG cannot be relied on as it is impossible to create a regex that can filter all possible street syntaxes.
1272
+ * Therefore we strongly recommend to use multiple street lines. This can be enabled in Magento community in
1273
+ * system > config > customer configuration. Or if you use Enterprise, in customers > attributes > manage customer
1274
+ * address attributes.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1275
  *
1276
  * @param Mage_Sales_Model_Order_Address $address
1277
+ * @param boolean $allowFullStreet
1278
  *
1279
  * @return array
1280
  */
1281
+ protected function _getStreetData($address, $allowFullStreet = true)
1282
  {
1283
+ $helper = Mage::helper('postnl/cif');
1284
  $storeId = $this->getStoreId();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1285
 
1286
+ $streetData = $helper->getStreetData($storeId, $address, $allowFullStreet);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1287
 
1288
  return $streetData;
1289
  }
1290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1291
  /**
1292
  * create Customs CIF object
1293
  *
1298
  protected function _getCustoms($postnlShipment)
1299
  {
1300
  $shipment = $postnlShipment->getShipment();
1301
+ $shipmentType = $postnlShipment->getGlobalpackShipmentType();
1302
 
1303
  $customs = array(
1304
+ 'ShipmentType' => $shipmentType,
1305
  'HandleAsNonDeliverable' => 'false',
1306
  'Invoice' => 'false',
1307
  'Certificate' => 'false',
1310
  );
1311
 
1312
  /**
1313
+ * Check if the shipment should be treated as abandoned when it can't be delivered or if it should be returned
1314
+ * to the sender.
1315
  */
1316
  if ($postnlShipment->getTreatAsAbandoned()) {
1317
  $customs['HandleAsNonDeliverable'] = 'true';
1356
  $content = array();
1357
  $items = $this->_sortCustomsItems($shipment->getAllItems());
1358
 
1359
+ /**
1360
+ * @var Mage_Sales_Model_Order_Shipment_Item $item
1361
+ */
1362
  foreach ($items as $item) {
1363
  /**
1364
  * A maximum of 5 rows are allowed
1427
  /**
1428
  * Get the attribute and direction used for sorting
1429
  */
1430
+ $sortingAttribute = Mage::getStoreConfig(
1431
+ self::XML_PATH_GLOBALPACK_PRODUCT_SORTING_ATTRIBUTE,
1432
+ $this->getStoreId()
1433
+ );
1434
+ $sortingDirection = Mage::getStoreConfig(
1435
+ self::XML_PATH_GLOBALPACK_PRODUCT_SORTING_DIRECTION,
1436
+ $this->getStoreId()
1437
+ );
1438
 
1439
  /**
1440
  * Place the item's sorting value in a temporary array where the key is the item's ID
1441
+ *
1442
+ * @var Mage_Sales_Model_Order_Shipment_Item $item
1443
  */
 
1444
  foreach ($items as $item) {
1445
  $product = $item->getOrderItem()->getProduct();
1446
  $sortingAttributeValue = $product->getDataUsingMethod($sortingAttribute);
1470
  /**
1471
  * Get a shipment item's HS tariff
1472
  *
1473
+ * @param Mage_Sales_Model_Order_Shipment_Item $shipmentItem
1474
  *
1475
  * @return string
1476
  */
1477
+ protected function _getHSTariff(Mage_Sales_Model_Order_Shipment_Item $shipmentItem)
1478
  {
1479
  $storeId = $this->getStoreId();
1480
 
1485
  return '000000';
1486
  }
1487
 
1488
+ if ($this->hasHSTariffAttribute()) {
1489
  $hsTariffAttribute = $this->getHSTariffAttribute();
1490
  } else {
1491
  $hsTariffAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_HS_TARIFF_ATTRIBUTE, $storeId);
1506
  /**
1507
  * Get a shipment item's country of origin
1508
  *
1509
+ * @param Mage_Sales_Model_Order_Shipment_Item $shipmentItem
1510
+ *
1511
+ * @throws TIG_PostNL_Exception
1512
  *
1513
  * @return string
1514
  */
1515
  protected function _getCountryOfOrigin($shipmentItem)
1516
  {
1517
  $storeId = $this->getStoreId();
1518
+ if ($this->hasCountryOfOriginAttribute()) {
1519
  $countryOfOriginAttribute = $this->getCountryOfOriginAttribute();
1520
  } else {
1521
+ $countryOfOriginAttribute = Mage::getStoreConfig(
1522
+ self::XML_PATH_GLOBALPACK_COUNTRY_OF_ORIGIN_ATTRIBUTE,
1523
+ $storeId
1524
+ );
1525
  $this->setCountryOfOriginAttribute($countryOfOriginAttribute);
1526
  }
1527
 
1531
 
1532
  if (empty($countryOfOrigin)) {
1533
  throw new TIG_PostNL_Exception(
1534
+ Mage::helper('postnl')->__(
1535
+ 'Missing country of origin value for product #%s.',
1536
+ $shipmentItem->getProductId()
1537
+ ),
1538
  'POSTNL-0091'
1539
  );
1540
  }
1545
  /**
1546
  * Get a shipment item's customs value
1547
  *
1548
+ * @param Mage_Sales_Model_Order_Shipment_Item $shipmentItem
1549
+ *
1550
+ * @throws TIG_PostNL_Exception
1551
  *
1552
  * @return string
1553
  */
1554
  protected function _getCustomsValue($shipmentItem)
1555
  {
1556
  $storeId = $this->getStoreId();
1557
+ if ($this->hasCustomsValueAttribute()) {
1558
  $customsValueAttribute = $this->getCustomsValueAttribute();
1559
  } else {
1560
  $customsValueAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_CUSTOMS_VALUE_ATTRIBUTE, $storeId);
1578
  /**
1579
  * Get a shipment item's customs description
1580
  *
1581
+ * @param Mage_Sales_Model_Order_Shipment_Item $shipmentItem
1582
+ *
1583
+ * @throws TIG_PostNL_Exception
1584
  *
1585
  * @return string
1586
  */
1587
  protected function _getCustomsDescription($shipmentItem)
1588
  {
1589
  $storeId = $this->getStoreId();
1590
+ if ($this->hasCustomsDescriptionAttribute()) {
1591
  $descriptionAttribute = $this->getCustomsDescriptionAttribute();
1592
  } else {
1593
  $descriptionAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_DESCRIPTION_ATTRIBUTE, $storeId);
1600
 
1601
  if (empty($description)) {
1602
  throw new TIG_PostNL_Exception(
1603
+ Mage::helper('postnl')->__(
1604
+ 'Missing customs description for product #%s.',
1605
+ $shipmentItem->getProductId()
1606
+ ),
1607
  'POSTNL-0093'
1608
  );
1609
  }
1701
  protected function _getCustomsCertificate()
1702
  {
1703
  $storeId = $this->getStoreId();
1704
+ $customsCertificate = (string) Mage::getStoreConfig(
1705
+ self::XML_PATH_GLOBALPACK_CUSTOMS_CERTIFICATE_NUMBER,
1706
+ $storeId
1707
+ );
1708
 
1709
  if (empty($customsCertificate)) {
1710
  return false;
1716
  /**
1717
  * Get the area field from an address if enabled
1718
  *
1719
+ * @param Mage_Sales_Model_Order_Address $address
1720
+ *
1721
  * @return string
1722
  */
1723
  protected function _getArea($address)
1733
  /**
1734
  * Attempt to get the area through the magic getter instead
1735
  */
1736
+ /** @noinspection PhpUndefinedMethodInspection */
1737
  $area = $address->getArea();
1738
 
1739
  return $area;
1742
  /**
1743
  * Get the area building name from an address if enabled
1744
  *
1745
+ * @param Mage_Sales_Model_Order_Address $address
1746
+ *
1747
  * @return string
1748
  */
1749
  protected function _getBuildingName($address)
1759
  /**
1760
  * Attempt to get the building name through the magic getter instead
1761
  */
1762
+ /** @noinspection PhpUndefinedMethodInspection */
1763
  $buildingName = $address->getBuildingName();
1764
 
1765
  return $buildingName;
1768
  /**
1769
  * Get the department field from an address if enabled
1770
  *
1771
+ * @param Mage_Sales_Model_Order_Address $address
1772
+ *
1773
  * @return string
1774
  */
1775
  protected function _getDepartment($address)
1785
  /**
1786
  * Attempt to get department through the magic getter instead
1787
  */
1788
+ /** @noinspection PhpUndefinedMethodInspection */
1789
  $department = $address->getDepartment();
1790
 
1791
  return $department;
1794
  /**
1795
  * Get the doorcode field from an address if enabled
1796
  *
1797
+ * @param Mage_Sales_Model_Order_Address $address
1798
+ *
1799
  * @return string
1800
  */
1801
  protected function _getDoorcode($address)
1811
  /**
1812
  * Attempt to get the doorcode through the magic getter instead
1813
  */
1814
+ /** @noinspection PhpUndefinedMethodInspection */
1815
  $doorcode = $address->getDoorcode();
1816
 
1817
  return $doorcode;
1820
  /**
1821
  * Get the floor field from an address if enabled
1822
  *
1823
+ * @param Mage_Sales_Model_Order_Address $address
1824
+ *
1825
  * @return string
1826
  */
1827
  protected function _getFloor($address)
1837
  /**
1838
  * Attempt to get the floor through the magic getter instead
1839
  */
1840
+ /** @noinspection PhpUndefinedMethodInspection */
1841
  $floor = $address->getFloor();
1842
 
1843
  return $floor;
1846
  /**
1847
  * Get the remark field from an address if enabled
1848
  *
1849
+ * @param Mage_Sales_Model_Order_Address $address
1850
+ *
1851
  * @return string
1852
  */
1853
  protected function _getRemark($address)
1863
  /**
1864
  * Attempt to get the remark through the magic getter instead
1865
  */
1866
+ /** @noinspection PhpUndefinedMethodInspection */
1867
  $remark = $address->getRemark();
1868
 
1869
  return $remark;
1872
  /**
1873
  * Get a shipment's reference. By default this will be the shipment's increment ID
1874
  *
1875
+ * @param Mage_Sales_Model_Order_Shipment $shipment
1876
  *
1877
  * @return string
1878
  *
1911
  * For custom references we need to replace several optional variables
1912
  */
1913
  if ($referenceType == 'custom') {
1914
+ $store = Mage::getModel('core/store')->load($storeId);
1915
+
1916
  $reference = str_replace('{{var shipment_increment_id}}', $shipment->getIncrementId(), $reference);
1917
  $reference = str_replace('{{var order_increment_id}}', $shipment->getOrder()->getIncrementId(), $reference);
1918
 
 
1919
  $reference = str_replace('{{var store_frontend_name}}', $store->getFrontendName(), $reference);
1920
  }
1921
 
app/code/community/TIG/PostNL/Model/Core/Cif/Abstract.php CHANGED
@@ -1,157 +1,241 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
  *
30
  * DISCLAIMER
31
  *
32
- advanced * Do not edit or add to this file if you wish to upgrade this module to newer
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  */
39
-
40
- /**
41
- * Base CIF model. Contains general code for communicating with the CIF API
42
- */
43
- class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
44
  {
45
  /**
46
  * Base URL of wsdl files
47
  */
48
  const WSDL_BASE_URL = 'https://service.postnl.com/CIF/';
49
-
50
  /**
51
  * Base URL of sandbox wsdl files
52
  */
53
  const TEST_WSDL_BASE_URL = 'https://testservice.postnl.com/CIF_SB/';
54
-
55
  /**
56
- * available wsdl filenames
57
  */
58
- const WSDL_BARCODE_NAME = 'BarcodeWebService';
59
- const WSDL_CONFIRMING_NAME = 'ConfirmingWebService';
60
- const WSDL_LABELLING_NAME = 'LabellingWebService';
61
- const WSDL_SHIPPING_STATUS_NAME = 'ShippingStatusWebService';
62
- const WSDL_CHECKOUT_NAME = 'WebshopCheckoutWebService';
63
-
 
 
 
64
  /**
65
- * header security namespace. Used for constructing the SOAP headers array
66
  */
67
  const HEADER_SECURITY_NAMESPACE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
68
-
69
  /**
70
  * CIF error namespace.
71
  */
72
  const CIF_ERROR_NAMESPACE = 'http://schemas.datacontract.org/2004/07/Tpp.Cif.Services.Services.Exception';
73
-
74
  /**
75
  * XML paths for config options
76
  */
77
- const XML_PATH_LIVE_USERNAME = 'postnl/cif/live_username';
78
- const XML_PATH_LIVE_PASSWORD = 'postnl/cif/live_password';
79
- const XML_PATH_TEST_USERNAME = 'postnl/cif/test_username';
80
- const XML_PATH_TEST_PASSWORD = 'postnl/cif/test_password';
81
- const XML_PATH_CIF_VERSION_BARCODE = 'postnl/advanced/cif_version_barcode';
82
- const XML_PATH_CIF_VERSION_LABELLING = 'postnl/advanced/cif_version_labelling';
83
- const XML_PATH_CIF_VERSION_CONFIRMING = 'postnl/advanced/cif_version_confirming';
84
- const XML_PATH_CIF_VERSION_SHIPPINGSTATUS = 'postnl/advanced/cif_version_shippingstatus';
85
- const XML_PATH_CIF_VERSION_CHECKOUT = 'postnl/advanced/cif_version_checkout';
86
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  /**
88
  * Gets the username from system/config. Test mode determines if live or test username is used.
89
- *
90
  * @param boolean|int $storeId
91
- *
92
  * @return string
93
  */
94
- protected function _getUsername($storeId = false)
95
  {
 
 
 
 
96
  if ($storeId === false) {
97
  $storeId = $this->getStoreId();
98
  }
99
-
100
- if (!$storeId) {
101
- $storeId = Mage::app()->getStore()->getId();
102
- }
103
-
104
  if ($this->isTestMode()) {
105
- $username = Mage::getStoreConfig(self::XML_PATH_TEST_USERNAME, $storeId);
106
- return $username;
 
 
 
 
 
107
  }
108
-
109
- $username = Mage::getStoreConfig(self::XML_PATH_LIVE_USERNAME, $storeId);
110
  return trim($username);
111
  }
112
-
113
  /**
114
  * Gets the password from system/config. Test mode determines if live or test password is used.
115
  * Passwords will be decrypted using Magento's encryption key and then hashed using sha1
116
- *
117
  * @param boolean|int $storeId
118
- *
119
- * @return string
120
  */
121
- protected function _getPassword($storeId = false)
122
  {
 
 
 
 
123
  if ($storeId === false) {
124
  $storeId = $this->getStoreId();
125
  }
126
-
127
- if (!$storeId) {
128
- $storeId = Mage::app()->getStore()->getId();
129
- }
130
-
131
  if ($this->isTestMode()) {
132
- $password = Mage::getStoreConfig(self::XML_PATH_TEST_PASSWORD, $storeId);
133
-
134
- $password = trim($password);
135
- $password = sha1(Mage::helper('core')->decrypt($password));
136
-
137
- return $password;
138
  }
139
-
140
- $password = Mage::getStoreConfig(self::XML_PATH_LIVE_PASSWORD, $storeId);
141
-
142
- $password = trim($password);
143
- $password = sha1(Mage::helper('core')->decrypt($password));
144
-
 
 
 
145
  return $password;
146
  }
147
-
148
  /**
149
  * Check if the module is set to test mode
150
- *
151
  * @param boolean|int $storeId
152
- *
153
  * @return boolean
154
- *
155
  * @see TIG_PostNL_Helper_Data::isTestMode()
156
  */
157
  public function isTestMode($storeId = false)
@@ -160,127 +244,148 @@ class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
160
  $testMode = $this->getTestMode();
161
  return $testMode;
162
  }
163
-
164
  if ($storeId === false) {
165
  $storeId = $this->getStoreId();
166
  }
167
-
168
- if (!$storeId) {
169
  $storeId = Mage::app()->getStore()->getId();
170
  }
171
-
172
- $testMode = Mage::helper('postnl')->isTestMode($storeId);
173
-
174
  return $testMode;
175
  }
176
 
177
  /**
178
- * Calls a CIF method
179
- *
180
- * @param string $wsdlType Which wsdl to use
181
- * @param string $method The method that will be called
182
- * @param array $soapParams An array of parameters to be sent
183
- * @param boolean|string $username
184
- * @param boolean|string $password
185
- *
186
- * @return object
187
- *
188
- * @throws TIG_PostNL_Exception
189
  */
190
- public function call($wsdlType, $method, $soapParams = null, $username = false, $password = false)
191
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  try {
193
- if ($username !== false && $password !== false
194
- && (!$this->_getUserName() || !$this->_getPassword())
195
- ) {
196
- throw new TIG_PostNL_Exception(
197
- Mage::helper('postnl')->__('No username or password set.'),
198
- 'POSTNL-0052'
199
- );
200
- }
201
-
202
- $wsdlFile = $this->_getWsdl($wsdlType);
203
-
204
  /**
205
- * Array of soap options used when connecting to CIF
206
  */
207
- $soapOptions = array(
208
- 'soap_version' => SOAP_1_1,
209
- 'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
 
 
210
  );
211
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  /**
213
- * try to create a new Zend_Soap_Client instance based on the supplied wsdl. if it fails, try again without using the
214
- * wsdl cache.
215
  */
216
- try {
217
- $client = new Zend_Soap_Client(
218
- $wsdlFile,
219
- $soapOptions
220
- );
221
- } catch (Exception $e) {
222
- /**
223
- * Disable wsdl cache and try again
224
- */
225
- $soapOptions['cache_wsdl'] = WSDL_CACHE_NONE;
226
-
227
- $client = new Zend_Soap_Client(
228
- $wsdlFile,
229
- $soapOptions
230
  );
231
  }
232
-
233
  /**
234
  * Add SOAP header
235
  */
236
- $header = $this->_getSoapHeader($username, $password);
237
  $client->addSoapInputHeader($header, true); //permanent header
238
-
239
  /**
240
  * Call the SOAP method
241
  */
242
- $response = $client->__call(
243
- $method,
244
- array(
245
- $method => $soapParams,
246
- )
247
- );
248
-
249
  /**
250
- * Parse any warnings that may have occurred
251
  */
252
  $this->_processWarnings($client);
253
-
254
- Mage::helper('postnl/cif')->logCifCall($client);
255
  return $response;
256
  } catch(SoapFault $e) {
257
  /**
258
  * Only Soap exceptions are caught. Other exceptions must be caught by the caller
 
 
259
  */
260
  $this->_handleCifException($e, $client);
261
  }
 
 
262
  }
263
 
264
  /**
265
- * returns the URL of the chosen wsdl file based on a wsdl type.
266
- *
267
- * available types are:
268
  * - barcode
269
  * - confirming
270
  * - labelling
271
  * - shippingstatus
272
  * - checkout
273
- *
 
 
 
274
  * @param string $wsdlType
275
- *
276
  * @return string
277
- *
278
  * @throws TIG_PostNL_Exception
279
  */
280
  protected function _getWsdl($wsdlType)
281
  {
282
  $adminStoreId = Mage_Core_Model_App::ADMIN_STORE_ID;
283
-
284
  /**
285
  * Check which wsdl file we need for each wsdl type
286
  * Als get the wsdl version to get
@@ -288,38 +393,44 @@ class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
288
  $wsdlType = strtolower($wsdlType);
289
  switch ($wsdlType) {
290
  case 'barcode':
291
- $wsdlversion = Mage::getStoreConfig(self::XML_PATH_CIF_VERSION_BARCODE, $adminStoreId);
292
  $wsdlFileName = self::WSDL_BARCODE_NAME;
293
  break;
294
  case 'confirming':
295
- $wsdlversion = Mage::getStoreConfig(self::XML_PATH_CIF_VERSION_CONFIRMING, $adminStoreId);
296
  $wsdlFileName = self::WSDL_CONFIRMING_NAME;
297
  break;
298
  case 'labelling':
299
- $wsdlversion = Mage::getStoreConfig(self::XML_PATH_CIF_VERSION_LABELLING, $adminStoreId);
300
  $wsdlFileName = self::WSDL_LABELLING_NAME;
301
  break;
302
  case 'shippingstatus':
303
- $wsdlversion = Mage::getStoreConfig(self::XML_PATH_CIF_VERSION_SHIPPINGSTATUS, $adminStoreId);
304
- $wsdlFileName = self::WSDL_SHIPPING_STATUS_NAME;
305
  break;
306
  case 'checkout':
307
- $wsdlversion = Mage::getStoreConfig(self::XML_PATH_CIF_VERSION_CHECKOUT, $adminStoreId);
308
  $wsdlFileName = self::WSDL_CHECKOUT_NAME;
309
  break;
 
 
 
 
 
 
 
 
 
 
 
 
310
  default:
311
  throw new TIG_PostNL_Exception(
312
  Mage::helper('postnl')->__('Chosen wsdl type is not supported: %s', $wsdlType),
313
  'POSTNL-0053'
314
  );
315
  }
316
-
317
- /**
318
- * Wsdl version numbers are formatted using an underscore instead of a period. Since many people would use a period, we
319
- * convert it to CIF specifications.
320
- */
321
- $wsdlversion = str_replace('.', '_', $wsdlversion);
322
-
323
  /**
324
  * Check if we need the live or the sandbox wsdl
325
  */
@@ -328,48 +439,46 @@ class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
328
  } else {
329
  $wsdlUrl = self::WSDL_BASE_URL;
330
  }
331
-
332
  /**
333
  * Format the final wsdl URL
334
  */
335
  $wsdlUrl .= $wsdlFileName
336
- . '/'
337
- . $wsdlversion
338
- . '/?wsdl';
339
-
340
  return $wsdlUrl;
341
  }
342
-
343
  /**
344
- * Builds soap headers array for CIF authentication
345
- *
346
- * @param boolean|string $username
347
- * @param boolean|string $password
348
- *
349
- * @return array
350
  */
351
- protected function _getSoapHeader($username = false, $password = false)
352
  {
353
- if ($username === false || $password === false) {
354
- $username = $this->_getUserName();
355
- $password = $this->_getPassWord();
356
- }
357
-
358
  $namespace = self::HEADER_SECURITY_NAMESPACE;
359
- $node1 = new SoapVar($username, XSD_STRING, null, null, 'Username', $namespace);
360
- $node2 = new SoapVar($password, XSD_STRING, null, null, 'Password', $namespace);
 
361
  $token = new SoapVar(array($node1, $node2), SOAP_ENC_OBJECT, null, null, 'UsernameToken', $namespace);
362
- $security = new SoapVar(array($token), SOAP_ENC_OBJECT, null, null, 'Security', $namespace);
363
- $header = new SOAPHeader($namespace, 'Security', $security, false);
364
-
 
 
365
  return $header;
366
  }
367
-
368
  /**
369
  * Check if warnings occurred while processing the CIF request. If so, parse and register them
370
- *
371
- * @param SoapClient $client
372
- *
373
  * @return TIG_PostNL_Model_Core_Cif_Abstract
374
  */
375
  protected function _processWarnings($client)
@@ -377,18 +486,20 @@ class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
377
  $responseXML = $client->getLastResponse();
378
  $responseDOMDoc = new DOMDocument();
379
  $responseDOMDoc->loadXML($responseXML);
380
-
381
  /**
382
- * Search the CIF response for warnings
383
  */
384
  $warnings = $responseDOMDoc->getElementsByTagName('Warning');
385
-
386
  if (!$warnings || $warnings->length < 1) {
387
  return $this;
388
  }
389
-
390
  /**
391
- * add all warning codes and descriptions to an array
 
 
392
  */
393
  $n = 0;
394
  $responseWarnings = array();
@@ -401,40 +512,44 @@ class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
401
  }
402
  $n++;
403
  }
404
-
405
  /**
406
- * Check if old warnings are still present in the registry. If so, merge these with the new warnings
407
  */
408
  if (Mage::registry('postnl_cif_warnings') !== null) {
409
  $existingWarnings = (array) Mage::registry('postnl_cif_warnings');
410
  $responseWarnings = array_merge($responseWarnings, $existingWarnings);
411
-
412
  /**
413
  * Remove the old warnings from the registry
414
  */
415
- Mage::unRegister('postnl_cif_warnings');
416
  }
417
-
418
  /**
419
  * Register the warnings
420
  */
421
  Mage::register('postnl_cif_warnings', $responseWarnings);
422
-
423
  return $this;
424
  }
425
-
426
  /**
427
- * Handle a SoapFault caused by CIF
428
- *
429
- * @param SoapFault $e
430
- * @param SoapClient $client
431
- *
432
  * @throws TIG_PostNL_Model_Core_Cif_Exception
433
  */
434
- protected function _handleCifException($e, $client = null)
435
  {
436
  $cifHelper = Mage::helper('postnl/cif');
437
-
 
 
 
 
438
  /**
439
  * Get the request and response XML data
440
  */
@@ -442,49 +557,57 @@ class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
442
  $requestXML = $cifHelper->formatXml($client->getLastRequest());
443
  $responseXML = $cifHelper->formatXml($client->getLastResponse());
444
  }
445
-
446
- if ($responseXML) {
 
 
 
447
  /**
448
  * If we received a response, parse it for errors and create an appropriate exception
449
  */
450
  $errorResponse = new DOMDocument();
451
  $errorResponse->loadXML($responseXML);
 
 
 
 
452
  $errors = $errorResponse->getElementsByTagNameNS(self::CIF_ERROR_NAMESPACE, 'ErrorMsg');
453
  if ($errors) {
454
  $message = '';
455
  foreach($errors as $error) {
456
  $message .= $error->nodeValue . PHP_EOL;
457
  }
458
-
459
- $exception = new TIG_PostNL_Model_Core_Cif_Exception($message, null, $e);
 
 
 
460
  }
461
-
 
 
 
462
  $errorNumbers = $errorResponse->getElementsByTagNameNS(self::CIF_ERROR_NAMESPACE, 'ErrorNumber');
463
- if ($exception && $errorNumbers) {
464
  foreach ($errorNumbers as $errorNumber) {
465
  $exception->addErrorNumber($errorNumber->nodeValue);
466
  }
467
  }
468
- } else {
469
- /**
470
- * Create a general exception
471
- */
472
- $exception = new TIG_PostNL_Model_Core_Cif_Exception($e->getMessage(), null, $e);
473
  }
474
-
475
  /**
476
  * Add the response and request data to the exception (to be logged later)
477
  */
478
- if ($client) {
479
  $exception->setRequestXml($requestXML)
480
  ->setResponseXml($responseXML);
481
  }
482
-
483
  /**
484
  * Log the exception and throw it
485
- */
486
  $cifHelper->logCifException($exception);
487
-
488
  throw $exception;
489
  }
490
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
  *
30
  * DISCLAIMER
31
  *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * Base CIF model. Contains general code for communicating with the CIF API
40
+ *
41
+ * @method boolean getTestMode()
42
+ *
43
+ * @method TIG_PostNL_Model_Core_Cif_Abstract setHelper(Mage_Core_Helper_Abstract $value)
44
+ * @method TIG_PostNL_Model_Core_Cif_Abstract setSoapClient(Zend_Soap_Client $value)
45
+ * @method TIG_PostNL_Model_Core_Cif_Abstract setTestMode(boolean $value)
46
+ * @method TIG_PostNL_Model_Core_Cif_Abstract setPassword(string $value)
47
+ * @method TIG_PostNL_Model_Core_Cif_Abstract setUsername(string $value)
48
+ * @method TIG_PostNL_Model_Core_Cif_Abstract setStoreId(int $value)
49
+ *
50
+ * @method boolean hasSoapClient()
51
+ * @method boolean hasHelper()
52
+ * @method boolean hasStoreId()
53
+ * @method boolean hasTestMode()
54
+ * @method boolean hasPassword()
55
+ * @method boolean hasUsername()
56
+ *
57
+ * @method TIG_PostNL_Model_Core_Cif_Abstract unsTestMode()
58
  */
59
+ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
 
 
 
 
60
  {
61
  /**
62
  * Base URL of wsdl files
63
  */
64
  const WSDL_BASE_URL = 'https://service.postnl.com/CIF/';
65
+
66
  /**
67
  * Base URL of sandbox wsdl files
68
  */
69
  const TEST_WSDL_BASE_URL = 'https://testservice.postnl.com/CIF_SB/';
70
+
71
  /**
72
+ * Available wsdl filenames.
73
  */
74
+ const WSDL_BARCODE_NAME = 'BarcodeWebService';
75
+ const WSDL_CONFIRMING_NAME = 'ConfirmingWebService';
76
+ const WSDL_LABELLING_NAME = 'LabellingWebService';
77
+ const WSDL_SHIPPINGSTATUS_NAME = 'ShippingStatusWebService';
78
+ const WSDL_CHECKOUT_NAME = 'WebshopCheckoutWebService';
79
+ const WSDL_DELIVERYDATE_NAME = 'DeliveryDateWebService';
80
+ const WSDL_TIMEFRAME_NAME = 'TimeframeWebService';
81
+ const WSDL_LOCATION_NAME = 'LocationWebService';
82
+
83
  /**
84
+ * Header security namespace. Used for constructing the SOAP headers array.
85
  */
86
  const HEADER_SECURITY_NAMESPACE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
87
+
88
  /**
89
  * CIF error namespace.
90
  */
91
  const CIF_ERROR_NAMESPACE = 'http://schemas.datacontract.org/2004/07/Tpp.Cif.Services.Services.Exception';
92
+
93
  /**
94
  * XML paths for config options
95
  */
96
+ const XPATH_LIVE_USERNAME = 'postnl/cif/live_username';
97
+ const XPATH_LIVE_PASSWORD = 'postnl/cif/live_password';
98
+ const XPATH_TEST_USERNAME = 'postnl/cif/test_username';
99
+ const XPATH_TEST_PASSWORD = 'postnl/cif/test_password';
100
+ const XPATH_CIF_VERSION_BARCODE = 'postnl/advanced/cif_version_barcode';
101
+ const XPATH_CIF_VERSION_LABELLING = 'postnl/advanced/cif_version_labelling';
102
+ const XPATH_CIF_VERSION_CONFIRMING = 'postnl/advanced/cif_version_confirming';
103
+ const XPATH_CIF_VERSION_SHIPPINGSTATUS = 'postnl/advanced/cif_version_shippingstatus';
104
+ const XPATH_CIF_VERSION_CHECKOUT = 'postnl/advanced/cif_version_checkout';
105
+ const XPATH_CIF_VERSION_DELIVERYDATE = 'postnl/advanced/cif_version_deliverydate';
106
+ const XPATH_CIF_VERSION_TIMEFRAME = 'postnl/advanced/cif_version_timeframe';
107
+ const XPATH_CIF_VERSION_LOCATION = 'postnl/advanced/cif_version_location';
108
+
109
+ /**
110
+ * Check if the required PHP extensions are installed.
111
+ *
112
+ * @throws TIG_PostNL_Exception
113
+ */
114
+ protected function _construct()
115
+ {
116
+ if (!extension_loaded('soap')) {
117
+ throw new TIG_PostNL_Exception(
118
+ Mage::helper('postnl')->__('The SOAP extension is not installed. PostNL requires the SOAP extension to '
119
+ . 'communicate with PostNL.'
120
+ ),
121
+ 'POSTNL-0134'
122
+ );
123
+ }
124
+
125
+ if (!extension_loaded('openssl')) {
126
+ throw new TIG_PostNL_Exception(
127
+ Mage::helper('postnl')->__('The OpenSSL extension is not installed. The PostNL extension requires the '
128
+ . 'OpenSSL extension to secure the communications with the PostNL servers.'
129
+ ),
130
+ 'POSTNL-0135'
131
+ );
132
+ }
133
+
134
+ parent::_construct();
135
+ }
136
+
137
+ /**
138
+ * @return int
139
+ */
140
+ public function getStoreId()
141
+ {
142
+ if ($this->hasStoreId()) {
143
+ return $this->_getData('store_id');
144
+ }
145
+
146
+ $storeId = Mage::app()->getStore()->getId();
147
+
148
+ $this->setStoreId($storeId);
149
+ return $storeId;
150
+ }
151
+
152
+ /**
153
+ * @return TIG_PostNL_Helper_Cif
154
+ */
155
+ public function getHelper()
156
+ {
157
+ if ($this->hasHelper()) {
158
+ return $this->getData('helper');
159
+ }
160
+
161
+ $helper = Mage::helper('postnl/cif');
162
+
163
+ $this->setHelper($helper);
164
+ return $helper;
165
+ }
166
+
167
  /**
168
  * Gets the username from system/config. Test mode determines if live or test username is used.
169
+ *
170
  * @param boolean|int $storeId
171
+ *
172
  * @return string
173
  */
174
+ public function getUsername($storeId = false)
175
  {
176
+ if ($this->hasUsername()) {
177
+ return $this->_getData('username');
178
+ }
179
+
180
  if ($storeId === false) {
181
  $storeId = $this->getStoreId();
182
  }
183
+
 
 
 
 
184
  if ($this->isTestMode()) {
185
+ $username = Mage::getStoreConfig(self::XPATH_TEST_USERNAME, $storeId);
186
+ } else {
187
+ $username = Mage::getStoreConfig(self::XPATH_LIVE_USERNAME, $storeId);
188
+ }
189
+
190
+ if (!$username) {
191
+ return false;
192
  }
193
+
 
194
  return trim($username);
195
  }
196
+
197
  /**
198
  * Gets the password from system/config. Test mode determines if live or test password is used.
199
  * Passwords will be decrypted using Magento's encryption key and then hashed using sha1
200
+ *
201
  * @param boolean|int $storeId
202
+ *
203
+ * @return string|boolean
204
  */
205
+ public function getPassword($storeId = false)
206
  {
207
+ if ($this->hasPassword()) {
208
+ return $this->_getData('password');
209
+ }
210
+
211
  if ($storeId === false) {
212
  $storeId = $this->getStoreId();
213
  }
214
+
 
 
 
 
215
  if ($this->isTestMode()) {
216
+ $configPassword = Mage::getStoreConfig(self::XPATH_TEST_PASSWORD, $storeId);
217
+ } else {
218
+ $configPassword = Mage::getStoreConfig(self::XPATH_LIVE_PASSWORD, $storeId);
 
 
 
219
  }
220
+
221
+ if (!$configPassword) {
222
+ return false;
223
+ }
224
+
225
+ $configPassword = trim($configPassword);
226
+ $decryptedPassword = Mage::helper('core')->decrypt($configPassword);
227
+ $password = sha1($decryptedPassword);
228
+
229
  return $password;
230
  }
231
+
232
  /**
233
  * Check if the module is set to test mode
234
+ *
235
  * @param boolean|int $storeId
236
+ *
237
  * @return boolean
238
+ *
239
  * @see TIG_PostNL_Helper_Data::isTestMode()
240
  */
241
  public function isTestMode($storeId = false)
244
  $testMode = $this->getTestMode();
245
  return $testMode;
246
  }
247
+
248
  if ($storeId === false) {
249
  $storeId = $this->getStoreId();
250
  }
251
+
252
+ if (is_null($storeId)) {
253
  $storeId = Mage::app()->getStore()->getId();
254
  }
255
+
256
+ $testMode = $this->getHelper()->isTestMode($storeId);
257
+
258
  return $testMode;
259
  }
260
 
261
  /**
262
+ * Gets a Zend_Soap_Client instance for the specified wsdl type.
263
+ *
264
+ * @param string|null $wsdlType
265
+ *
266
+ * @return Zend_Soap_Client
 
 
 
 
 
 
267
  */
268
+ public function getSoapClient($wsdlType = null)
269
  {
270
+ if ($this->hasSoapClient()) {
271
+ return $this->_getData('soap_client');
272
+ }
273
+
274
+ $wsdlFile = $this->_getWsdl($wsdlType);
275
+
276
+ /**
277
+ * Array of soap options used when connecting to CIF
278
+ */
279
+ $soapOptions = array(
280
+ 'soap_version' => SOAP_1_1,
281
+ 'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
282
+ );
283
+
284
+ /**
285
+ * try to create a new Zend_Soap_Client instance based on the supplied wsdl. if it fails, try again without using the
286
+ * wsdl cache.
287
+ */
288
  try {
289
+ $client = new Zend_Soap_Client(
290
+ $wsdlFile,
291
+ $soapOptions
292
+ );
293
+ } catch (Exception $e) {
 
 
 
 
 
 
294
  /**
295
+ * Disable wsdl cache and try again
296
  */
297
+ $soapOptions['cache_wsdl'] = WSDL_CACHE_NONE;
298
+
299
+ $client = new Zend_Soap_Client(
300
+ $wsdlFile,
301
+ $soapOptions
302
  );
303
+ }
304
+
305
+ $this->setSoapClient($client);
306
+ return $client;
307
+ }
308
+
309
+ /**
310
+ * Calls a CIF method
311
+ *
312
+ * @param string $wsdlType Which wsdl to use
313
+ * @param callable $method The method that will be called
314
+ * @param array $soapParams An array of parameters to be sent
315
+ *
316
+ * @return object|boolean
317
+ *
318
+ * @throws TIG_PostNL_Exception
319
+ */
320
+ public function call($wsdlType, $method, $soapParams = array())
321
+ {
322
+ $client = null;
323
+ try {
324
  /**
325
+ * @var Zend_Soap_Client $client
 
326
  */
327
+ $client = $this->getSoapClient($wsdlType);
328
+
329
+ if (!is_callable(array($client, $method))) {
330
+ throw new TIG_PostNL_Exception(
331
+ Mage::helper('postnl')->__('The specified method "%s" is not callable.', $method),
332
+ 'POSTNL-0136'
 
 
 
 
 
 
 
 
333
  );
334
  }
335
+
336
  /**
337
  * Add SOAP header
338
  */
339
+ $header = $this->_getSoapHeader();
340
  $client->addSoapInputHeader($header, true); //permanent header
341
+
342
  /**
343
  * Call the SOAP method
344
  */
345
+ $response = $client->$method($soapParams);
346
+
 
 
 
 
 
347
  /**
348
+ * Process any warnings that may have occurred
349
  */
350
  $this->_processWarnings($client);
351
+
352
+ $this->getHelper()->logCifCall($client);
353
  return $response;
354
  } catch(SoapFault $e) {
355
  /**
356
  * Only Soap exceptions are caught. Other exceptions must be caught by the caller
357
+ *
358
+ * @throws TIG_PostNL_Exception
359
  */
360
  $this->_handleCifException($e, $client);
361
  }
362
+
363
+ return false;
364
  }
365
 
366
  /**
367
+ * Returns the URL of the chosen wsdl file based on a wsdl type.
368
+ *
369
+ * Available types are:
370
  * - barcode
371
  * - confirming
372
  * - labelling
373
  * - shippingstatus
374
  * - checkout
375
+ * - deliverydate
376
+ * - timeframe
377
+ * - location
378
+ *
379
  * @param string $wsdlType
380
+ *
381
  * @return string
382
+ *
383
  * @throws TIG_PostNL_Exception
384
  */
385
  protected function _getWsdl($wsdlType)
386
  {
387
  $adminStoreId = Mage_Core_Model_App::ADMIN_STORE_ID;
388
+
389
  /**
390
  * Check which wsdl file we need for each wsdl type
391
  * Als get the wsdl version to get
393
  $wsdlType = strtolower($wsdlType);
394
  switch ($wsdlType) {
395
  case 'barcode':
396
+ $wsdlversion = Mage::getStoreConfig(self::XPATH_CIF_VERSION_BARCODE, $adminStoreId);
397
  $wsdlFileName = self::WSDL_BARCODE_NAME;
398
  break;
399
  case 'confirming':
400
+ $wsdlversion = Mage::getStoreConfig(self::XPATH_CIF_VERSION_CONFIRMING, $adminStoreId);
401
  $wsdlFileName = self::WSDL_CONFIRMING_NAME;
402
  break;
403
  case 'labelling':
404
+ $wsdlversion = Mage::getStoreConfig(self::XPATH_CIF_VERSION_LABELLING, $adminStoreId);
405
  $wsdlFileName = self::WSDL_LABELLING_NAME;
406
  break;
407
  case 'shippingstatus':
408
+ $wsdlversion = Mage::getStoreConfig(self::XPATH_CIF_VERSION_SHIPPINGSTATUS, $adminStoreId);
409
+ $wsdlFileName = self::WSDL_SHIPPINGSTATUS_NAME;
410
  break;
411
  case 'checkout':
412
+ $wsdlversion = Mage::getStoreConfig(self::XPATH_CIF_VERSION_CHECKOUT, $adminStoreId);
413
  $wsdlFileName = self::WSDL_CHECKOUT_NAME;
414
  break;
415
+ case 'deliverydate':
416
+ $wsdlversion = Mage::getStoreConfig(self::XPATH_CIF_VERSION_DELIVERYDATE, $adminStoreId);
417
+ $wsdlFileName = self::WSDL_DELIVERYDATE_NAME;
418
+ break;
419
+ case 'timeframe':
420
+ $wsdlversion = Mage::getStoreConfig(self::XPATH_CIF_VERSION_TIMEFRAME, $adminStoreId);
421
+ $wsdlFileName = self::WSDL_TIMEFRAME_NAME;
422
+ break;
423
+ case 'location':
424
+ $wsdlversion = Mage::getStoreConfig(self::XPATH_CIF_VERSION_LOCATION, $adminStoreId);
425
+ $wsdlFileName = self::WSDL_LOCATION_NAME;
426
+ break;
427
  default:
428
  throw new TIG_PostNL_Exception(
429
  Mage::helper('postnl')->__('Chosen wsdl type is not supported: %s', $wsdlType),
430
  'POSTNL-0053'
431
  );
432
  }
433
+
 
 
 
 
 
 
434
  /**
435
  * Check if we need the live or the sandbox wsdl
436
  */
439
  } else {
440
  $wsdlUrl = self::WSDL_BASE_URL;
441
  }
442
+
443
  /**
444
  * Format the final wsdl URL
445
  */
446
  $wsdlUrl .= $wsdlFileName
447
+ . '/'
448
+ . $wsdlversion
449
+ . '/?wsdl';
450
+
451
  return $wsdlUrl;
452
  }
453
+
454
  /**
455
+ * Builds soap headers array for CIF authentication.
456
+ *
457
+ * @return SOAPHeader
 
 
 
458
  */
459
+ protected function _getSoapHeader()
460
  {
461
+ $username = $this->getUserName();
462
+ $password = $this->getPassWord();
463
+
 
 
464
  $namespace = self::HEADER_SECURITY_NAMESPACE;
465
+ $node1 = new SoapVar($username, XSD_STRING, null, null, 'Username', $namespace);
466
+ $node2 = new SoapVar($password, XSD_STRING, null, null, 'Password', $namespace);
467
+
468
  $token = new SoapVar(array($node1, $node2), SOAP_ENC_OBJECT, null, null, 'UsernameToken', $namespace);
469
+
470
+ $security = new SoapVar(array($token), SOAP_ENC_OBJECT, null, null, 'Security', $namespace);
471
+
472
+ $header = new SOAPHeader($namespace, 'Security', $security, false);
473
+
474
  return $header;
475
  }
476
+
477
  /**
478
  * Check if warnings occurred while processing the CIF request. If so, parse and register them
479
+ *
480
+ * @param Zend_Soap_Client $client
481
+ *
482
  * @return TIG_PostNL_Model_Core_Cif_Abstract
483
  */
484
  protected function _processWarnings($client)
486
  $responseXML = $client->getLastResponse();
487
  $responseDOMDoc = new DOMDocument();
488
  $responseDOMDoc->loadXML($responseXML);
489
+
490
  /**
491
+ * Search the CIF response for warnings.
492
  */
493
  $warnings = $responseDOMDoc->getElementsByTagName('Warning');
494
+
495
  if (!$warnings || $warnings->length < 1) {
496
  return $this;
497
  }
498
+
499
  /**
500
+ * Add all warning codes and descriptions to an array.
501
+ *
502
+ * @var DOMDocument $warning
503
  */
504
  $n = 0;
505
  $responseWarnings = array();
512
  }
513
  $n++;
514
  }
515
+
516
  /**
517
+ * Check if old warnings are still present in the registry. If so, merge these with the new warnings.
518
  */
519
  if (Mage::registry('postnl_cif_warnings') !== null) {
520
  $existingWarnings = (array) Mage::registry('postnl_cif_warnings');
521
  $responseWarnings = array_merge($responseWarnings, $existingWarnings);
522
+
523
  /**
524
  * Remove the old warnings from the registry
525
  */
526
+ Mage::unregister('postnl_cif_warnings');
527
  }
528
+
529
  /**
530
  * Register the warnings
531
  */
532
  Mage::register('postnl_cif_warnings', $responseWarnings);
533
+
534
  return $this;
535
  }
536
+
537
  /**
538
+ * Handle a SoapFault thrown by CIF.
539
+ *
540
+ * @param SoapFault $e
541
+ * @param Zend_Soap_Client $client
542
+ *
543
  * @throws TIG_PostNL_Model_Core_Cif_Exception
544
  */
545
+ protected function _handleCifException(SoapFault $e, $client = null)
546
  {
547
  $cifHelper = Mage::helper('postnl/cif');
548
+ $exception = new TIG_PostNL_Model_Core_Cif_Exception($e->getMessage(), null, $e);
549
+
550
+ $requestXML = '';
551
+ $responseXML = '';
552
+
553
  /**
554
  * Get the request and response XML data
555
  */
557
  $requestXML = $cifHelper->formatXml($client->getLastRequest());
558
  $responseXML = $cifHelper->formatXml($client->getLastResponse());
559
  }
560
+
561
+ /**
562
+ * If we got a response, parse it for specific error messages and add these to the exception.
563
+ */
564
+ if (!empty($responseXML)) {
565
  /**
566
  * If we received a response, parse it for errors and create an appropriate exception
567
  */
568
  $errorResponse = new DOMDocument();
569
  $errorResponse->loadXML($responseXML);
570
+
571
+ /**
572
+ * Get all error messages.
573
+ */
574
  $errors = $errorResponse->getElementsByTagNameNS(self::CIF_ERROR_NAMESPACE, 'ErrorMsg');
575
  if ($errors) {
576
  $message = '';
577
  foreach($errors as $error) {
578
  $message .= $error->nodeValue . PHP_EOL;
579
  }
580
+
581
+ /**
582
+ * Update the exception.
583
+ */
584
+ $exception->setMessage($message);
585
  }
586
+
587
+ /**
588
+ * Parse any CIF error numbers we may have received.
589
+ */
590
  $errorNumbers = $errorResponse->getElementsByTagNameNS(self::CIF_ERROR_NAMESPACE, 'ErrorNumber');
591
+ if ($errorNumbers) {
592
  foreach ($errorNumbers as $errorNumber) {
593
  $exception->addErrorNumber($errorNumber->nodeValue);
594
  }
595
  }
 
 
 
 
 
596
  }
597
+
598
  /**
599
  * Add the response and request data to the exception (to be logged later)
600
  */
601
+ if (!empty($requestXML) || !empty($responseXML)) {
602
  $exception->setRequestXml($requestXML)
603
  ->setResponseXml($responseXML);
604
  }
605
+
606
  /**
607
  * Log the exception and throw it
608
+ */
609
  $cifHelper->logCifException($exception);
610
+
611
  throw $exception;
612
  }
613
  }
app/code/community/TIG/PostNL/Model/Core/Cif/Exception.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -36,120 +36,123 @@
36
  * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
-
40
  /**
41
  * Custom Exception class for CIF exceptions
42
- *
43
  * @see TIG_PostNL_Exception
44
  * @see Mage_Core_Exception
45
- *
46
  * @link http://php.net/manual/en/language.exceptions.extending.php
47
  */
48
  class TIG_PostNL_Model_Core_Cif_Exception extends TIG_PostNL_Exception
49
  {
50
  /**
51
  * XML sent to CIF by the extension
52
- *
53
  * @var string The XML string sent to CIF
54
  */
55
  protected $_requestXml;
56
-
57
  /**
58
  * XML received in response
59
- *
60
  * @var string The XML string CIF returned
61
  */
62
  protected $_responseXml;
63
-
64
  /**
65
  * Array of error numbers
66
- *
67
  * @var array
68
  */
69
  protected $_errorNumbers = array();
70
-
71
  /**
72
  * Set $_requestXml to specified value
73
- *
 
 
74
  * @return TIG_PostNL_Model_Core_Cif_Exception
75
  */
76
  public function setRequestXml($xml)
77
  {
78
  $this->_requestXml = $xml;
79
-
80
  return $this;
81
  }
82
-
83
  /**
84
  * Set $_responseXml to specified value
85
- *
 
86
  * @return TIG_PostNL_Model_Core_Cif_Exception
87
  */
88
  public function setResponseXml($xml)
89
  {
90
  $this->_responseXml = $xml;
91
-
92
  return $this;
93
  }
94
-
95
  /**
96
  * Set the error numbers array
97
- *
98
  * @param array $errorNumbers
99
- *
100
  * @return TIG_PostNL_Model_Core_Cif_Exception
101
  */
102
  public function setErrorNumbers($errorNumbers)
103
  {
104
  $this->_errorNumbers = $errorNumbers;
105
-
106
  return $this;
107
  }
108
-
109
  /**
110
  * Get $_requestXml
111
- *
112
  * @return string
113
  */
114
  public function getRequestXml()
115
  {
116
  return $this->_requestXml;
117
  }
118
-
119
  /**
120
  * Get $_responseXml
121
- *
122
  * @return string
123
  */
124
  public function getResponseXml()
125
  {
126
  return $this->_responseXml;
127
  }
128
-
129
  /**
130
  * get the error numbers array
131
- *
132
  * @return array
133
  */
134
  public function getErrorNumbers()
135
  {
136
  return $this->_errorNumbers;
137
  }
138
-
139
  /**
140
  * Add an error number to the error numbers array
141
- *
142
  * @param int $errorNumber
143
- *
144
  * @return TIG_PostNL_Model_Core_Cif_Exception
145
  */
146
  public function addErrorNumber($errorNumber)
147
  {
148
  $errorNumbers = $this->getErrorNumbers();
149
  $errorNumbers[] = $errorNumber;
150
-
151
  $this->setErrorNumbers($errorNumbers);
152
-
153
  return $this;
154
  }
155
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
36
  * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+
40
  /**
41
  * Custom Exception class for CIF exceptions
42
+ *
43
  * @see TIG_PostNL_Exception
44
  * @see Mage_Core_Exception
45
+ *
46
  * @link http://php.net/manual/en/language.exceptions.extending.php
47
  */
48
  class TIG_PostNL_Model_Core_Cif_Exception extends TIG_PostNL_Exception
49
  {
50
  /**
51
  * XML sent to CIF by the extension
52
+ *
53
  * @var string The XML string sent to CIF
54
  */
55
  protected $_requestXml;
56
+
57
  /**
58
  * XML received in response
59
+ *
60
  * @var string The XML string CIF returned
61
  */
62
  protected $_responseXml;
63
+
64
  /**
65
  * Array of error numbers
66
+ *
67
  * @var array
68
  */
69
  protected $_errorNumbers = array();
70
+
71
  /**
72
  * Set $_requestXml to specified value
73
+ *
74
+ * @param $xml
75
+ *
76
  * @return TIG_PostNL_Model_Core_Cif_Exception
77
  */
78
  public function setRequestXml($xml)
79
  {
80
  $this->_requestXml = $xml;
81
+
82
  return $this;
83
  }
84
+
85
  /**
86
  * Set $_responseXml to specified value
87
+ *
88
+ * @param $xml
89
  * @return TIG_PostNL_Model_Core_Cif_Exception
90
  */
91
  public function setResponseXml($xml)
92
  {
93
  $this->_responseXml = $xml;
94
+
95
  return $this;
96
  }
97
+
98
  /**
99
  * Set the error numbers array
100
+ *
101
  * @param array $errorNumbers
102
+ *
103
  * @return TIG_PostNL_Model_Core_Cif_Exception
104
  */
105
  public function setErrorNumbers($errorNumbers)
106
  {
107
  $this->_errorNumbers = $errorNumbers;
108
+
109
  return $this;
110
  }
111
+
112
  /**
113
  * Get $_requestXml
114
+ *
115
  * @return string
116
  */
117
  public function getRequestXml()
118
  {
119
  return $this->_requestXml;
120
  }
121
+
122
  /**
123
  * Get $_responseXml
124
+ *
125
  * @return string
126
  */
127
  public function getResponseXml()
128
  {
129
  return $this->_responseXml;
130
  }
131
+
132
  /**
133
  * get the error numbers array
134
+ *
135
  * @return array
136
  */
137
  public function getErrorNumbers()
138
  {
139
  return $this->_errorNumbers;
140
  }
141
+
142
  /**
143
  * Add an error number to the error numbers array
144
+ *
145
  * @param int $errorNumber
146
+ *
147
  * @return TIG_PostNL_Model_Core_Cif_Exception
148
  */
149
  public function addErrorNumber($errorNumber)
150
  {
151
  $errorNumbers = $this->getErrorNumbers();
152
  $errorNumbers[] = $errorNumber;
153
+
154
  $this->setErrorNumbers($errorNumbers);
155
+
156
  return $this;
157
  }
158
  }
app/code/community/TIG/PostNL/Model/Core/Label.php CHANGED
@@ -33,8 +33,10 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
38
  */
39
  class TIG_PostNL_Model_Core_Label extends Varien_Object
40
  {
@@ -64,6 +66,33 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
64
  */
65
  protected $_labelCounter = null;
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  /**
68
  * Get the array of saved temporary labels
69
  *
@@ -125,7 +154,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
125
 
126
  $labelSize = Mage::getStoreConfig(self::XML_PATH_LABEL_SIZE, Mage_Core_Model_App::ADMIN_STORE_ID);
127
 
128
- $this->setLabelSeize($labelSize);
129
  return $labelSize;
130
  }
131
 
@@ -229,12 +258,13 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
229
  $this->_destroyTempLabels();
230
 
231
  /**
232
- * Output the label as a download response
233
  */
234
- $pdf->Output('PostNL Shipping Labels.pdf', 'D');
235
 
236
  Varien_Profiler::stop('tig::postnl::core::label_createpdf');
237
- return $this;
 
238
  }
239
 
240
  /**
@@ -268,6 +298,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
268
  );
269
  }
270
 
 
271
  $labels = $this->_sortLabels($labels);
272
  foreach ($labels as $label) {
273
  $pdf = $this->_addPdfTemplate($pdf, $label);
@@ -279,9 +310,10 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
279
  /**
280
  * Adds a lebl to the pdf by storing it in a temporary pdf file and then adding it to the master pdf object
281
  *
282
- * @param TIG_PostNL_Fpdi $pdf
283
- * @param string $label
284
- * @param int $labelCounter A counter used to determine the position of the next label to be added.
 
285
  *
286
  * @return TIG_PostNL_Fpdi $pdf
287
  */
@@ -293,6 +325,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
293
  $tempFilename = $this->_saveTempLabel($label->getLabel());
294
 
295
  switch ($label->getLabelType()) {
 
296
  case 'Label-combi':
297
  $this->_convertTempLabelToCombi($tempFilename); //NO BREAK
298
  case 'Label':
@@ -304,34 +337,9 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
304
  ) {
305
  $pdf->addOrientedPage('L', 'A4');
306
  $this->resetLabelCounter();
307
- }
308
-
309
- /**
310
- * If the configured label size is A6, add a new page every label
311
- */
312
- if($this->getLabelSize() == 'A6') {
313
- $this->setLabelCounter(3); //used to calculate the top left position
314
- $pdf->addOrientedPage('L', 'A6');
315
- }
316
-
317
- /**
318
- * Calculate the position of the next label to be printed
319
- */
320
- $position = $this->_getPosition($this->getLabelCounter());
321
- $position['w'] = $this->pix2pt(538);
322
-
323
- $this->increaseLabelCounter();
324
- break;
325
-
326
-
327
- /**
328
- * If the configured label size is A4, add a new page every 4 labels and reset the counter
329
- */
330
- if ($this->getLabelSize() == 'A4'
331
- && (!$this->getLabelCounter() || $this->getLabelCounter() > 4)
332
- ) {
333
  $pdf->addOrientedPage('L', 'A4');
334
- $this->resetLabelCounter();
335
  }
336
 
337
  /**
@@ -426,6 +434,8 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
426
  *
427
  * @param string $label
428
  *
 
 
429
  * @return string
430
  */
431
  protected function _saveTempLabel($label)
@@ -489,8 +499,12 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
489
  protected function _sortLabels($labels)
490
  {
491
  $generalLabels = array();
492
- $globalLabels = array();
493
- $codCards = array();
 
 
 
 
494
  foreach ($labels as $label) {
495
  /**
496
  * Seperate general labels from the rest
@@ -591,11 +605,12 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
591
  * third: bottom left
592
  * fourth: bottom right
593
  *
594
- * @param int $counter
 
 
595
  *
596
  * @return array
597
  *
598
- * @throws TIG_PostNL_Exception
599
  */
600
  protected function _getPosition($counter = false)
601
  {
@@ -631,7 +646,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
631
  /**
632
  * Converts pixels to points. 3.8 pixels is 1 pt in pdfs
633
  *
634
- * @param float $input
635
  *
636
  * @return int
637
  */
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method TIG_PostNL_Model_Core_Label setLabelSize(string $value)
40
  */
41
  class TIG_PostNL_Model_Core_Label extends Varien_Object
42
  {
66
  */
67
  protected $_labelCounter = null;
68
 
69
+ /**
70
+ * Flag if the current label is the first of a set of labels.
71
+ *
72
+ * @var bool
73
+ */
74
+ protected $_isFirstLabel = false;
75
+
76
+ /**
77
+ * @param boolean $isFirstLabel
78
+ *
79
+ * @return TIG_PostNL_Model_Core_Label
80
+ */
81
+ public function setIsFirstLabel($isFirstLabel)
82
+ {
83
+ $this->_isFirstLabel = $isFirstLabel;
84
+
85
+ return $this;
86
+ }
87
+
88
+ /**
89
+ * @return boolean
90
+ */
91
+ public function getIsFirstLabel()
92
+ {
93
+ return $this->_isFirstLabel;
94
+ }
95
+
96
  /**
97
  * Get the array of saved temporary labels
98
  *
154
 
155
  $labelSize = Mage::getStoreConfig(self::XML_PATH_LABEL_SIZE, Mage_Core_Model_App::ADMIN_STORE_ID);
156
 
157
+ $this->setLabelSize($labelSize);
158
  return $labelSize;
159
  }
160
 
258
  $this->_destroyTempLabels();
259
 
260
  /**
261
+ * Get the final label.
262
  */
263
+ $label = $pdf->Output('PostNL Shipping Labels.pdf', 'I');
264
 
265
  Varien_Profiler::stop('tig::postnl::core::label_createpdf');
266
+
267
+ return $label;
268
  }
269
 
270
  /**
298
  );
299
  }
300
 
301
+ $this->setIsFirstLabel(true);
302
  $labels = $this->_sortLabels($labels);
303
  foreach ($labels as $label) {
304
  $pdf = $this->_addPdfTemplate($pdf, $label);
310
  /**
311
  * Adds a lebl to the pdf by storing it in a temporary pdf file and then adding it to the master pdf object
312
  *
313
+ * @param TIG_PostNL_Fpdi $pdf
314
+ * @param TIG_PostNL_Model_Core_Shipment_Label $label
315
+ *
316
+ * @throws TIG_PostNL_Exception
317
  *
318
  * @return TIG_PostNL_Fpdi $pdf
319
  */
325
  $tempFilename = $this->_saveTempLabel($label->getLabel());
326
 
327
  switch ($label->getLabelType()) {
328
+ /** @noinspection PhpMissingBreakStatementInspection */
329
  case 'Label-combi':
330
  $this->_convertTempLabelToCombi($tempFilename); //NO BREAK
331
  case 'Label':
337
  ) {
338
  $pdf->addOrientedPage('L', 'A4');
339
  $this->resetLabelCounter();
340
+ } elseif ($this->getLabelSize() == 'A4' && $this->getIsFirstLabel()) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  $pdf->addOrientedPage('L', 'A4');
342
+ $this->setIsFirstLabel(false);
343
  }
344
 
345
  /**
434
  *
435
  * @param string $label
436
  *
437
+ * @throws TIG_PostNL_Exception
438
+ *
439
  * @return string
440
  */
441
  protected function _saveTempLabel($label)
499
  protected function _sortLabels($labels)
500
  {
501
  $generalLabels = array();
502
+ $globalLabels = array();
503
+ $codCards = array();
504
+
505
+ /**
506
+ * @var TIG_PostNL_Model_Core_Shipment_Label $label
507
+ */
508
  foreach ($labels as $label) {
509
  /**
510
  * Seperate general labels from the rest
605
  * third: bottom left
606
  * fourth: bottom right
607
  *
608
+ * @param bool|int $counter
609
+ *
610
+ * @throws TIG_PostNL_Exception
611
  *
612
  * @return array
613
  *
 
614
  */
615
  protected function _getPosition($counter = false)
616
  {
646
  /**
647
  * Converts pixels to points. 3.8 pixels is 1 pt in pdfs
648
  *
649
+ * @param int $pixels
650
  *
651
  * @return int
652
  */
app/code/community/TIG/PostNL/Model/Core/Observer/Barcode.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,23 +33,21 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Observer_Barcode
40
  {
41
  /**
42
  * Generates a barcode for the shipment if it is new
43
- *
44
  * @param Varien_Event_Observer $observer
45
- *
46
  * @return TIG_PostNL_Model_Core_Observer_Barcode
47
- *
48
  * @event sales_order_shipment_save_after
49
- *
50
  * @observer postnl_shipment_generate_barcode
51
- *
52
- * @todo change confirm date to the correct value, taking into account 'ordered before X, delivered on Y' settings
53
  */
54
  public function generateBarcode(Varien_Event_Observer $observer)
55
  {
@@ -59,56 +57,83 @@ class TIG_PostNL_Model_Core_Observer_Barcode
59
  if (!Mage::helper('postnl')->isEnabled()) {
60
  return $this;
61
  }
62
-
 
 
 
63
  $shipment = $observer->getShipment();
64
-
 
 
 
 
 
 
65
  /**
66
- * Check if a postnl shipment exists for this shipment
 
 
 
 
 
 
 
 
67
  */
68
  if (Mage::helper('postnl/cif')->postnlShipmentExists($shipment->getId())) {
69
  return $this;
70
  }
71
-
72
  /**
73
- * create a new postnl shipment entity
74
  */
75
  $postnlShipment = Mage::getModel('postnl_core/shipment');
76
- $postnlShipment->setShipmentId($shipment->getId())
77
- ->setConfirmDate(Mage::getModel('core/date')->gmtTimestamp());
78
-
79
  /**
80
  * Check if this shipment has an associated PostNL Order. If so, copy it's data.
 
 
81
  */
82
- $postnlOrder = Mage::getModel('postnl_checkout/order')->load($shipment->getOrderId(), 'order_id');
 
83
  if ($postnlOrder->getId()) {
84
  if ($postnlOrder->getConfirmDate()) {
85
  $postnlShipment->setConfirmDate(strtotime($postnlOrder->getConfirmDate()));
86
  }
87
-
 
 
 
 
88
  if ($postnlOrder->getIsPakjeGemak()) {
89
  $postnlShipment->setIsPakjeGemak($postnlOrder->getIsPakjeGemak());
90
  }
 
 
 
 
91
  }
92
-
93
  /**
94
- * We need an ID in order to save the barcodes
95
  */
96
  $postnlShipment->save();
97
-
98
  /**
99
  * Barcode generation needs to be tried seperately. This functionality may throw a valid exception
100
  * in which case it needs to be tried again later without preventing the shipment from being
101
  * created. This may happen when CIF is overburdoned.
102
- */
103
  try {
104
  $postnlShipment->saveAdditionalShippingOptions()
105
  ->generateBarcodes();
106
  } catch (Exception $e) {
107
  Mage::helper('postnl')->logException($e);
108
  }
109
-
110
  $postnlShipment->save();
111
-
112
  return $this;
113
  }
114
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Observer_Barcode
40
  {
41
  /**
42
  * Generates a barcode for the shipment if it is new
43
+ *
44
  * @param Varien_Event_Observer $observer
45
+ *
46
  * @return TIG_PostNL_Model_Core_Observer_Barcode
47
+ *
48
  * @event sales_order_shipment_save_after
49
+ *
50
  * @observer postnl_shipment_generate_barcode
 
 
51
  */
52
  public function generateBarcode(Varien_Event_Observer $observer)
53
  {
57
  if (!Mage::helper('postnl')->isEnabled()) {
58
  return $this;
59
  }
60
+
61
+ /**
62
+ * @var Mage_Sales_Model_Order_Shipment $shipment
63
+ */
64
  $shipment = $observer->getShipment();
65
+
66
+ /**
67
+ * Check if this shipment was placed using PostNL.
68
+ */
69
+ $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
70
+ $shippingMethod = $shipment->getOrder()->getShippingMethod();
71
+
72
  /**
73
+ * If this shipment's order was not placed with PostNL, remove any PakjeGemak addresses that may have been
74
+ * saved.
75
+ */
76
+ if (!in_array($shippingMethod, $postnlShippingMethods)) {
77
+ return $this;
78
+ }
79
+
80
+ /**
81
+ * Check if a postnl shipment exists for this shipment.
82
  */
83
  if (Mage::helper('postnl/cif')->postnlShipmentExists($shipment->getId())) {
84
  return $this;
85
  }
86
+
87
  /**
88
+ * Create a new postnl shipment entity.
89
  */
90
  $postnlShipment = Mage::getModel('postnl_core/shipment');
91
+ $postnlShipment->setShipmentId($shipment->getId());
92
+
 
93
  /**
94
  * Check if this shipment has an associated PostNL Order. If so, copy it's data.
95
+ *
96
+ * @var TIG_PostNL_Model_Core_Order $postnlOrder
97
  */
98
+ $postnlOrder = Mage::getModel('postnl_core/order')->load($shipment->getOrderId(), 'order_id');
99
+
100
  if ($postnlOrder->getId()) {
101
  if ($postnlOrder->getConfirmDate()) {
102
  $postnlShipment->setConfirmDate(strtotime($postnlOrder->getConfirmDate()));
103
  }
104
+
105
+ if ($postnlOrder->getDeliveryDate()) {
106
+ $postnlShipment->setDeliveryDate(strtotime($postnlOrder->getDeliveryDate()));
107
+ }
108
+
109
  if ($postnlOrder->getIsPakjeGemak()) {
110
  $postnlShipment->setIsPakjeGemak($postnlOrder->getIsPakjeGemak());
111
  }
112
+
113
+ if ($postnlOrder->getIsPakketautomaat()) {
114
+ $postnlShipment->setIsPakketautomaat($postnlOrder->getIsPakketautomaat());
115
+ }
116
  }
117
+
118
  /**
119
+ * We need an ID in order to save the barcodes.
120
  */
121
  $postnlShipment->save();
122
+
123
  /**
124
  * Barcode generation needs to be tried seperately. This functionality may throw a valid exception
125
  * in which case it needs to be tried again later without preventing the shipment from being
126
  * created. This may happen when CIF is overburdoned.
127
+ */
128
  try {
129
  $postnlShipment->saveAdditionalShippingOptions()
130
  ->generateBarcodes();
131
  } catch (Exception $e) {
132
  Mage::helper('postnl')->logException($e);
133
  }
134
+
135
  $postnlShipment->save();
136
+
137
  return $this;
138
  }
139
  }
app/code/community/TIG/PostNL/Model/Core/Observer/Cron.php CHANGED
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Observer_Cron
@@ -102,6 +102,8 @@ class TIG_PostNL_Model_Core_Observer_Cron
102
  /**
103
  * Get the temporary label filename constant. This is used to construct the fgilename together with
104
  * an md5 hash of the content and a timestamp.
 
 
105
  */
106
  $labelModel = Mage::app()->getConfig()->getModelClassName('postnl_core/label');
107
  $tempLabelName = $labelModel::TEMP_LABEL_FILENAME;
@@ -200,7 +202,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
200
  if ($files === false) {
201
  $helper->cronLog('Lock storage is unreadable. Exiting cron.');
202
  throw new TIG_PostNL_Exception(
203
- $helper->__('Unable to read directory: %s', $tempLabelsDirectory),
204
  'POSTNL-0096'
205
  );
206
  }
@@ -280,13 +282,13 @@ class TIG_PostNL_Model_Core_Observer_Cron
280
 
281
  $helper->cronLog("Getting barcodes for {$postnlShipmentCollection->getSize()} shipments.");
282
 
283
- $n = 1000;
284
  foreach ($postnlShipmentCollection as $postnlShipment) {
285
  /**
286
  * Process a maximum of 1000 shipments (to prevent Cif from being overburdoned).
287
  * Only successfull requests count towards this number
288
  */
289
- if ($n < 1) {
290
  break;
291
  }
292
 
@@ -298,7 +300,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
298
  $postnlShipment->generateBarcodes()
299
  ->save();
300
 
301
- $n--;
302
  } catch (Exception $e) {
303
  Mage::helper('postnl')->logException($e);
304
  }
@@ -327,6 +329,9 @@ class TIG_PostNL_Model_Core_Observer_Cron
327
 
328
  $helper->cronLog('UpdateShippingStatus cron starting...');
329
 
 
 
 
330
  $postnlShipmentModelClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
331
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
332
  $deliveredStatus = $postnlShipmentModelClass::SHIPPING_PHASE_DELIVERED;
@@ -373,6 +378,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
373
  $helper->cronLog("Updating shipping status for shipment #{$postnlShipment->getShipment()->getId()}");
374
 
375
  if (!$postnlShipment->canUpdateShippingStatus()) {
 
376
  $helper->cronLog("Updating shipment #{$postnlShipment->getShipment()->getId()} is not allowed. Continuing with next shipment.");
377
  continue;
378
  }
@@ -475,6 +481,9 @@ class TIG_PostNL_Model_Core_Observer_Cron
475
 
476
  $helper->cronLog('ExpireConfirmation cron starting...');
477
 
 
 
 
478
  $postnlShipmentModelClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
479
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
480
  $collectionPhase = $postnlShipmentModelClass::SHIPPING_PHASE_COLLECTION;
@@ -563,7 +572,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
563
  * Check each storeview if sending track & trace emails is allowed
564
  */
565
  $allowedStoreIds = array();
566
- foreach (Mage::app()->getStores() as $storeId => $value) {
567
  if (Mage::getStoreConfig(self::XML_PATH_SEND_TRACK_AND_TRACE_EMAIL, $storeId)) {
568
  $allowedStoreIds[] = $storeId;
569
  }
@@ -574,6 +583,9 @@ class TIG_PostNL_Model_Core_Observer_Cron
574
  return $this;
575
  }
576
 
 
 
 
577
  $postnlShipmentModelClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
578
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
579
 
@@ -584,6 +596,29 @@ class TIG_PostNL_Model_Core_Observer_Cron
584
 
585
  /**
586
  * Get all postnl shipments that have been confirmed over 20 minutes ago whose track & trace e-mail has not yet been sent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
587
  */
588
  $postnlShipmentCollection = Mage::getResourceModel('postnl_core/shipment_collection');
589
  $postnlShipmentCollection->addFieldToFilter(
@@ -666,6 +701,8 @@ class TIG_PostNL_Model_Core_Observer_Cron
666
 
667
  /**
668
  * Get the PostNL Shipment classname for later use
 
 
669
  */
670
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
671
 
@@ -731,7 +768,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
731
  */
732
  foreach ($labelsCollection as $label) {
733
  $helper->cronLog("Deleting label #{$label->getId()}.");
734
- $label->delete()->save();
735
  }
736
  $helper->cronLog('RemoveOldLabels cron has finished.');
737
 
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Observer_Cron
102
  /**
103
  * Get the temporary label filename constant. This is used to construct the fgilename together with
104
  * an md5 hash of the content and a timestamp.
105
+ *
106
+ * @var $labelModel TIG_PostNL_Model_Core_Label
107
  */
108
  $labelModel = Mage::app()->getConfig()->getModelClassName('postnl_core/label');
109
  $tempLabelName = $labelModel::TEMP_LABEL_FILENAME;
202
  if ($files === false) {
203
  $helper->cronLog('Lock storage is unreadable. Exiting cron.');
204
  throw new TIG_PostNL_Exception(
205
+ $helper->__('Unable to read directory: %s', $locksDirectory),
206
  'POSTNL-0096'
207
  );
208
  }
282
 
283
  $helper->cronLog("Getting barcodes for {$postnlShipmentCollection->getSize()} shipments.");
284
 
285
+ $counter = 1000;
286
  foreach ($postnlShipmentCollection as $postnlShipment) {
287
  /**
288
  * Process a maximum of 1000 shipments (to prevent Cif from being overburdoned).
289
  * Only successfull requests count towards this number
290
  */
291
+ if ($counter < 1) {
292
  break;
293
  }
294
 
300
  $postnlShipment->generateBarcodes()
301
  ->save();
302
 
303
+ $counter--;
304
  } catch (Exception $e) {
305
  Mage::helper('postnl')->logException($e);
306
  }
329
 
330
  $helper->cronLog('UpdateShippingStatus cron starting...');
331
 
332
+ /**
333
+ * @var $postnlShipmentModelClass TIG_PostNL_Model_Core_Shipment
334
+ */
335
  $postnlShipmentModelClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
336
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
337
  $deliveredStatus = $postnlShipmentModelClass::SHIPPING_PHASE_DELIVERED;
378
  $helper->cronLog("Updating shipping status for shipment #{$postnlShipment->getShipment()->getId()}");
379
 
380
  if (!$postnlShipment->canUpdateShippingStatus()) {
381
+ $postnlShipment->unlock();
382
  $helper->cronLog("Updating shipment #{$postnlShipment->getShipment()->getId()} is not allowed. Continuing with next shipment.");
383
  continue;
384
  }
481
 
482
  $helper->cronLog('ExpireConfirmation cron starting...');
483
 
484
+ /**
485
+ * @var $postnlShipmentModelClass TIG_PostNL_Model_Core_Shipment
486
+ */
487
  $postnlShipmentModelClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
488
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
489
  $collectionPhase = $postnlShipmentModelClass::SHIPPING_PHASE_COLLECTION;
572
  * Check each storeview if sending track & trace emails is allowed
573
  */
574
  $allowedStoreIds = array();
575
+ foreach (array_keys(Mage::app()->getStores()) as $storeId) {
576
  if (Mage::getStoreConfig(self::XML_PATH_SEND_TRACK_AND_TRACE_EMAIL, $storeId)) {
577
  $allowedStoreIds[] = $storeId;
578
  }
583
  return $this;
584
  }
585
 
586
+ /**
587
+ * @var $postnlShipmentModelClass TIG_PostNL_Model_Core_Shipment
588
+ */
589
  $postnlShipmentModelClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
590
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
591
 
596
 
597
  /**
598
  * Get all postnl shipments that have been confirmed over 20 minutes ago whose track & trace e-mail has not yet been sent
599
+ *
600
+ * Resulting SQL:
601
+ * SELECT `main_table` . *
602
+ * FROM `tig_postnl_shipment` AS `main_table`
603
+ * WHERE (
604
+ * confirm_status = '{$confirmedStatus}'
605
+ * )
606
+ * AND (
607
+ * labels_printed =1
608
+ * )
609
+ * AND (
610
+ * confirmed_at <= '{$twentyMinutesAgo}'
611
+ * )
612
+ * AND (
613
+ * (
614
+ * (
615
+ * track_and_trace_email_sent IS NULL
616
+ * )
617
+ * OR (
618
+ * track_and_trace_email_sent = '0'
619
+ * )
620
+ * )
621
+ * )
622
  */
623
  $postnlShipmentCollection = Mage::getResourceModel('postnl_core/shipment_collection');
624
  $postnlShipmentCollection->addFieldToFilter(
701
 
702
  /**
703
  * Get the PostNL Shipment classname for later use
704
+ *
705
+ * @var $postnlShipmentClass TIG_PostNL_Model_Core_Shipment
706
  */
707
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
708
 
768
  */
769
  foreach ($labelsCollection as $label) {
770
  $helper->cronLog("Deleting label #{$label->getId()}.");
771
+ $label->delete();
772
  }
773
  $helper->cronLog('RemoveOldLabels cron has finished.');
774
 
app/code/community/TIG/PostNL/Model/Core/Observer/SaveShipment.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,20 +33,20 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Observer_SaveShipment
40
  {
41
  /**
42
  * Registers a chosen product option
43
- *
44
  * @param Varien_Event_Observer $observer
45
- *
46
- * @return TIG_PostNL_Model_Core_Observer
47
- *
48
  * @event controller_action_predispatch_adminhtml_sales_order_shipment_save
49
- *
50
  * @observer postnl_core_shipment_save
51
  */
52
  public function registerProductOption(Varien_Event_Observer $observer)
@@ -57,22 +57,24 @@ class TIG_PostNL_Model_Core_Observer_SaveShipment
57
  if (!Mage::helper('postnl')->isEnabled()) {
58
  return $this;
59
  }
60
-
61
  /**
62
- * retrieve and register the chosen option, if any
 
 
63
  */
64
  $controller = $observer->getControllerAction();
65
  $productOption = $controller->getRequest()->getParam('postnl');
66
-
67
  if ($productOption && isset($productOption['product_option'])) {
68
  Mage::register('postnl_product_option', $productOption['product_option']);
69
  unset($productOption['product_option']);
70
  }
71
-
72
  if ($productOption && !empty($productOption)) {
73
  Mage::register('postnl_additional_options', $productOption);
74
  }
75
-
76
  return $this;
77
  }
78
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Observer_SaveShipment
40
  {
41
  /**
42
  * Registers a chosen product option
43
+ *
44
  * @param Varien_Event_Observer $observer
45
+ *
46
+ * @return $this
47
+ *
48
  * @event controller_action_predispatch_adminhtml_sales_order_shipment_save
49
+ *
50
  * @observer postnl_core_shipment_save
51
  */
52
  public function registerProductOption(Varien_Event_Observer $observer)
57
  if (!Mage::helper('postnl')->isEnabled()) {
58
  return $this;
59
  }
60
+
61
  /**
62
+ * retrieve and register the chosen option, if any.
63
+ *
64
+ * @var Mage_Core_Controller_Varien_Front $controller
65
  */
66
  $controller = $observer->getControllerAction();
67
  $productOption = $controller->getRequest()->getParam('postnl');
68
+
69
  if ($productOption && isset($productOption['product_option'])) {
70
  Mage::register('postnl_product_option', $productOption['product_option']);
71
  unset($productOption['product_option']);
72
  }
73
+
74
  if ($productOption && !empty($productOption)) {
75
  Mage::register('postnl_additional_options', $productOption);
76
  }
77
+
78
  return $this;
79
  }
80
  }
app/code/community/TIG/PostNL/Model/Core/Order.php ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * Class TIG_PostNL_Model_Core_Order
40
+ *
41
+ * @method string getConfirmDate()
42
+ * @method TIG_PostNL_Model_Core_Order setConfirmDate(string $value)
43
+ * @method int getIsActive()
44
+ * @method TIG_PostNL_Model_Core_Order setIsActive(int $value)
45
+ * @method string getToken()
46
+ * @method TIG_PostNL_Model_Core_Order setToken(string $value)
47
+ * @method string getShipmentCosts()
48
+ * @method TIG_PostNL_Model_Core_Order setShipmentCosts(string $value)
49
+ * @method string getProductCode()
50
+ * @method TIG_PostNL_Model_Core_Order setProductCode(string $value)
51
+ * @method int getIsPakjeGemak()
52
+ * @method TIG_PostNL_Model_Core_Order setIsPakjeGemak(int $value)
53
+ * @method int getIsCanceled()
54
+ * @method TIG_PostNL_Model_Core_Order setIsCanceled(int $value)
55
+ * @method string getDeliveryDate()
56
+ * @method TIG_PostNL_Model_Core_Order setDeliveryDate(string $value)
57
+ * @method int getQuoteId()
58
+ * @method TIG_PostNL_Model_Core_Order setQuoteId(int $value)
59
+ * @method string getType()
60
+ * @method TIG_PostNL_Model_Core_Order setType(string $value)
61
+ * @method int getOrderId()
62
+ * @method TIG_PostNL_Model_Core_Order setOrderId(int $value)
63
+ * @method int getEntityId()
64
+ * @method string getMobilePhoneNumber()
65
+ * @method TIG_PostNL_Model_Core_Order setEntityId(int $value)
66
+ * @method TIG_PostNL_Model_Core_Order setOrder(Mage_Sales_Model_Order $value)
67
+ * @method TIG_PostNL_Model_Core_Order setQuote(Mage_Sales_Model_Quote $value)
68
+ * @method int getIsPakketautomaat()
69
+ * @method TIG_PostNL_Model_Core_Order setIsPakketautomaat(int $value)
70
+ */
71
+ class TIG_PostNL_Model_Core_Order extends Mage_Core_Model_Abstract
72
+ {
73
+ /**
74
+ * Regexes for mobile phone number validation.
75
+ */
76
+ const MOBILE_PHONE_NUMBER_REGEX = '/^(((\+31|0|0031)6){1}[1-9]{1}[0-9]{7})$/i';
77
+ const MOBILE_PHONE_NUMBER_PREFIX_REGEX = '/^(06|00316){1}(.*?)$/i';
78
+ const MOBILE_PHONE_NUMBER_PREFIX_REPLACEMENT = '+316$2';
79
+ const MOBILE_PHONE_NUMBER_CONTENT_REGEX = '/[^0-9+]/';
80
+
81
+ /**
82
+ * Prefix of model events names.
83
+ *
84
+ * @var string
85
+ */
86
+ protected $_eventPrefix = 'postnl_order';
87
+
88
+ public function _construct()
89
+ {
90
+ $this->_init('postnl_core/order');
91
+ }
92
+
93
+ /**
94
+ * Gets the order associated with this PostNL Checkout Order.
95
+ *
96
+ * @return Mage_Sales_Model_Order|null
97
+ */
98
+ public function getOrder()
99
+ {
100
+ if ($this->getData('order')) {
101
+ return $this->getData('order');
102
+ }
103
+
104
+ if (!$this->getOrderId()) {
105
+ return null;
106
+ }
107
+
108
+ /**
109
+ * @var Mage_Sales_Model_Order $order
110
+ */
111
+ $order = Mage::getModel('sales/order')->load($this->getOrderId());
112
+
113
+ $this->setOrder($order);
114
+ return $order;
115
+ }
116
+
117
+ /**
118
+ * Gets the quote associated with this PostNL Checkout Order.
119
+ *
120
+ * @return Mage_Sales_Model_Quote|null
121
+ */
122
+ public function getQuote()
123
+ {
124
+ if ($this->getData('quote')) {
125
+ return $this->getData('quote');
126
+ }
127
+
128
+ if (!$this->getQuoteId()) {
129
+ return null;
130
+ }
131
+
132
+ /**
133
+ * @var Mage_Sales_Model_Quote $quote
134
+ */
135
+ $quote = Mage::getModel('sales/quote')->load($this->getQuoteId());
136
+
137
+ $this->setQuote($quote);
138
+ return $quote;
139
+ }
140
+
141
+ /**
142
+ * Alias for magic getToken().
143
+ *
144
+ * @return string
145
+ */
146
+ public function getOrderToken()
147
+ {
148
+ return $this->getToken();
149
+ }
150
+
151
+ /**
152
+ * Alias for magic getQuoteId().
153
+ *
154
+ * @return int
155
+ */
156
+ public function getExtRef()
157
+ {
158
+ return $this->getQuoteId();
159
+ }
160
+
161
+ /**
162
+ * Set a mobile phone number.
163
+ *
164
+ * @param string $phoneNumber
165
+ * @param boolean $skipValidation
166
+ *
167
+ * @throws TIG_PostNL_Exception
168
+ *
169
+ * @return $this
170
+ */
171
+ public function setMobilePhoneNumber($phoneNumber, $skipValidation = false)
172
+ {
173
+ if ($skipValidation || empty($phoneNumber)) {
174
+ $this->setData('mobile_phone_number', $phoneNumber);
175
+ return $this;
176
+ }
177
+
178
+ /**
179
+ * Parse the number so that it starts with '+316' and remove any invalid characters.
180
+ */
181
+ $parsedPhoneNumber = preg_replace(
182
+ array(self::MOBILE_PHONE_NUMBER_CONTENT_REGEX, self::MOBILE_PHONE_NUMBER_PREFIX_REGEX),
183
+ array('', self::MOBILE_PHONE_NUMBER_PREFIX_REPLACEMENT),
184
+ $phoneNumber
185
+ );
186
+
187
+ /**
188
+ * Validate the phone number. It should be a valid Dutch mobile phone number.
189
+ */
190
+ $validPhoneNumber = preg_match(self::MOBILE_PHONE_NUMBER_REGEX, $parsedPhoneNumber);
191
+ if (!$validPhoneNumber) {
192
+ throw new TIG_PostNL_Exception(
193
+ Mage::helper('postnl')->__('Invalid mobile phone number supplied: %s', $parsedPhoneNumber),
194
+ 'POSTNL-0149'
195
+ );
196
+ }
197
+
198
+ $this->setData('mobile_phone_number', $parsedPhoneNumber);
199
+ return $this;
200
+ }
201
+
202
+ /**
203
+ * Cancels the PostNL order.
204
+ *
205
+ * @return $this
206
+ *
207
+ * @throws TIG_PostNL_Exception
208
+ */
209
+ public function cancel()
210
+ {
211
+ $helper = Mage::helper('postnl');
212
+ if (!$this->getOrderId()) {
213
+ throw new TIG_PostNL_Exception(
214
+ $helper->__('This PostNL Checkout order cannot be cancelled: it has no associated magento order.'),
215
+ 'POSTNL-0046'
216
+ );
217
+ }
218
+
219
+ if ($this->getIsCanceled()) {
220
+ throw new TIG_PostNL_Exception(
221
+ $helper->__('This PostNL Checkout order cannot be cancelled: it has already been canceled.'),
222
+ 'POSTNL-0047'
223
+ );
224
+ }
225
+
226
+ $cif = Mage::getModel('postnl_checkout/cif');
227
+ $cif->updateOrder($this, true);
228
+
229
+ $this->setIsCanceled(true);
230
+
231
+ return $this;
232
+ }
233
+
234
+ /**
235
+ * Sets new PostNL Orders to active before saving
236
+ *
237
+ * @return Mage_Core_Model_Abstract::_beforeSave();
238
+ */
239
+ protected function _beforeSave()
240
+ {
241
+ if ($this->isObjectNew()) {
242
+ $this->setIsActive(1);
243
+ }
244
+
245
+ return parent::_beforeSave();
246
+ }
247
+ }
app/code/community/TIG/PostNL/Model/{Checkout → Core}/Resource/Order.php RENAMED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,13 +33,13 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Model_Checkout_Resource_Order extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
- {
43
- $this->_init('postnl_checkout/order', 'entity_id');
44
  }
45
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Model_Core_Resource_Order extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
+ {
43
+ $this->_init('postnl_core/order', 'entity_id');
44
  }
45
  }
app/code/community/TIG/PostNL/Model/{Checkout → Core}/Resource/Order/Collection.php RENAMED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,10 +33,10 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
- class TIG_PostNL_Model_Checkout_Resource_Order_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
40
  {
41
  /**
42
  * Event prefix
@@ -51,10 +51,10 @@ class TIG_PostNL_Model_Checkout_Resource_Order_Collection extends TIG_PostNL_Mod
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_order_collection';
54
-
55
  public function _construct()
56
- {
57
  parent::_construct();
58
- $this->_init('postnl_checkout/order');
59
  }
60
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
+ class TIG_PostNL_Model_Core_Resource_Order_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
40
  {
41
  /**
42
  * Event prefix
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_order_collection';
54
+
55
  public function _construct()
56
+ {
57
  parent::_construct();
58
+ $this->_init('postnl_core/order');
59
  }
60
  }
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,13 +33,13 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Resource_Shipment extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
- {
43
  $this->_init('postnl_core/shipment', 'entity_id');
44
  }
45
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Resource_Shipment extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
+ {
43
  $this->_init('postnl_core/shipment', 'entity_id');
44
  }
45
  }
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -39,7 +39,7 @@
39
  class TIG_PostNL_Model_Core_Resource_Shipment_Barcode extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
- {
43
  $this->_init('postnl_core/shipment_barcode', 'barcode_id');
44
  }
45
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
39
  class TIG_PostNL_Model_Core_Resource_Shipment_Barcode extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
+ {
43
  $this->_init('postnl_core/shipment_barcode', 'barcode_id');
44
  }
45
  }
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode/Collection.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -51,9 +51,9 @@ class TIG_PostNL_Model_Core_Resource_Shipment_Barcode_Collection extends TIG_Pos
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_shipment_barcode_collection';
54
-
55
  public function _construct()
56
- {
57
  parent::_construct();
58
  $this->_init('postnl_core/shipment_barcode');
59
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_shipment_barcode_collection';
54
+
55
  public function _construct()
56
+ {
57
  parent::_construct();
58
  $this->_init('postnl_core/shipment_barcode');
59
  }
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Collection.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -51,9 +51,9 @@ class TIG_PostNL_Model_Core_Resource_Shipment_Collection extends TIG_PostNL_Mode
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_shipment_collection';
54
-
55
  public function _construct()
56
- {
57
  parent::_construct();
58
  $this->_init('postnl_core/shipment');
59
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_shipment_collection';
54
+
55
  public function _construct()
56
+ {
57
  parent::_construct();
58
  $this->_init('postnl_core/shipment');
59
  }
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -39,7 +39,7 @@
39
  class TIG_PostNL_Model_Core_Resource_Shipment_Label extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
- {
43
  $this->_init('postnl_core/shipment_label', 'label_id');
44
  }
45
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
39
  class TIG_PostNL_Model_Core_Resource_Shipment_Label extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
+ {
43
  $this->_init('postnl_core/shipment_label', 'label_id');
44
  }
45
  }
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label/Collection.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -51,9 +51,9 @@ class TIG_PostNL_Model_Core_Resource_Shipment_Label_Collection extends TIG_PostN
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_shipment_label_collection';
54
-
55
  public function _construct()
56
- {
57
  parent::_construct();
58
  $this->_init('postnl_core/shipment_label');
59
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_shipment_label_collection';
54
+
55
  public function _construct()
56
+ {
57
  parent::_construct();
58
  $this->_init('postnl_core/shipment_label');
59
  }
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Status/History.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,13 +33,13 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Resource_Shipment_Status_History extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
- {
43
  $this->_init('postnl_core/shipment_status_history', 'status_id');
44
  }
45
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Resource_Shipment_Status_History extends Mage_Core_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
+ {
43
  $this->_init('postnl_core/shipment_status_history', 'status_id');
44
  }
45
  }
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Status/History/Collection.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -51,9 +51,9 @@ class TIG_PostNL_Model_Core_Resource_Shipment_Status_History_Collection extends
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_shipment_status_history_collection';
54
-
55
  public function _construct()
56
- {
57
  parent::_construct();
58
  $this->_init('postnl_core/shipment_status_history');
59
  }
1
+ <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
51
  * @var string
52
  */
53
  protected $_eventObject = 'postnl_shipment_status_history_collection';
54
+
55
  public function _construct()
56
+ {
57
  parent::_construct();
58
  $this->_init('postnl_core/shipment_status_history');
59
  }
app/code/community/TIG/PostNL/Model/Core/Shipment.php CHANGED
@@ -33,36 +33,120 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
- * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
- */
39
-
40
- /**
41
- * PostNL Shipment base class. Contains majority of PostNL shipping functionality
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  */
43
  class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
44
  {
45
  /**
46
- * Prefix of model events names
47
  *
48
  * @var string
49
  */
50
  protected $_eventPrefix = 'postnl_shipment';
51
 
52
  /**
53
- * Carrier code used by postnl
54
  */
55
  const POSTNL_CARRIER_CODE = 'postnl';
56
 
57
  /**
58
- * Possible confirm statusses
59
  */
60
  const CONFIRM_STATUS_CONFIRMED = 'confirmed';
61
  const CONFIRM_STATUS_UNCONFIRMED = 'unconfirmed';
62
  const CONFIRM_STATUS_CONFIRM_EXPIRED = 'confirm_expired';
63
 
64
  /**
65
- * Possible shipping phases
66
  */
67
  const SHIPPING_PHASE_COLLECTION = '1';
68
  const SHIPPING_PHASE_SORTING = '2';
@@ -71,48 +155,56 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
71
  const SHIPPING_PHASE_NOT_APPLICABLE = '99';
72
 
73
  /**
74
- * XML paths to default product options settings
75
  */
76
- const XML_PATH_DEFAULT_STANDARD_PRODUCT_OPTION = 'postnl/cif_product_options/default_product_option';
77
- const XML_PATH_DEFAULT_PAKJEGEMAK_PRODUCT_OPTION = 'postnl/cif_product_options/default_pakjegemak_product_option';
78
- const XML_PATH_DEFAULT_EU_PRODUCT_OPTION = 'postnl/cif_product_options/default_eu_product_option';
79
- const XML_PATH_DEFAULT_GLOBAL_PRODUCT_OPTION = 'postnl/cif_product_options/default_global_product_option';
80
- const XML_PATH_USE_ALTERNATIVE_DEFAULT = 'postnl/cif_product_options/use_alternative_default';
81
- const XML_PATH_ALTERNATIVE_DEFAULT_MAX_AMOUNT = 'postnl/cif_product_options/alternative_default_max_amount';
82
- const XML_PATH_ALTERNATIVE_DEFAULT_OPTION = 'postnl/cif_product_options/alternative_default_option';
 
 
 
83
 
84
  /**
85
- * XML path to weight per parcel config setting
86
  */
87
- const XML_PATH_WEIGHT_PER_PARCEL = 'postnl/cif_labels_and_confirming/weight_per_parcel';
88
 
89
  /**
90
- * XML path to setting that determines whether or not to send track and trace emails
91
  */
92
- const XML_PATH_SEND_TRACK_AND_TRACE_EMAIL = 'postnl/cif_labels_and_confirming/send_track_and_trace_email';
93
 
94
  /**
95
- * XML path to track and trace email template setting
96
  */
97
- const XML_PATH_TRACK_AND_TRACE_EMAIL_TEMPLATE = 'postnl/cif_labels_and_confirming/track_and_trace_email_template';
98
 
99
  /**
100
- * XML path to maximum allowed parcel count settings
101
  */
102
- const XML_PATH_MAX_PARCEL_COUNT = 'postnl/advanced/max_parcel_count';
103
 
104
  /**
105
- * CIF warning code returned when an EPS combi label is not available
 
 
 
 
 
106
  */
107
  const EPS_COMBI_LABEL_WARNING_CODE = 'LIRS_0';
108
 
109
  /**
110
- * Newly added 'pakje_gemak' address type
111
  */
112
  const ADDRESS_TYPE_PAKJEGEMAK = 'pakje_gemak';
113
 
114
  /**
115
- * Array of product codes that have extra cover
116
  *
117
  * @var array
118
  */
@@ -136,9 +228,10 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
136
  protected $_labelsToSave = array();
137
 
138
  /**
139
- * Contains an instance of TIG_PostNL_Model_Core_Shipment_Process which locks a shipment and prevents it from being modified
 
140
  *
141
- * @var void | TIG_PostNL_Model_Core_Shipment_Process
142
  */
143
  protected $_process;
144
 
@@ -150,9 +243,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
150
  $this->_init('postnl_core/shipment');
151
  }
152
 
153
- /****************************************************************************************************************************
154
- * GETTER AND SETTER METHODS
155
- ***************************************************************************************************************************/
156
 
157
  /**
158
  * Retrieves a Mage_Sales_Model_Order_Shipment entity linked to the postnl shipment.
@@ -161,8 +254,8 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
161
  */
162
  public function getShipment()
163
  {
164
- if ($this->getData('shipment')) {
165
- return $this->getData('shipment');
166
  }
167
 
168
  $shipmentId = $this->getShipmentId();
@@ -170,6 +263,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
170
  return null;
171
  }
172
 
 
 
 
173
  $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
174
 
175
  $this->setShipment($shipment);
@@ -179,12 +275,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
179
  /**
180
  * Retrieves the linked Shipment's shipping address
181
  *
182
- * @return Mage_Sales_Model_Order_Address | null
183
  */
184
  public function getShippingAddress()
185
  {
186
- if ($this->getData('shipping_address')) {
187
- return $this->getData('shipping_address');
188
  }
189
 
190
  $shipmentId = $this->getShipmentId();
@@ -201,12 +297,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
201
  /**
202
  * Gets an optional address with the pakje_gemak address type
203
  *
204
- * @return boolean | Mage_Sales_Model_Order_Address
205
  */
206
  public function getPakjeGemakAddress()
207
  {
208
- if ($this->getData('pakje_gemak_address')) {
209
- return $this->getData('pakje_gemak_address');
210
  }
211
 
212
  $shipmentId = $this->getShipmentId();
@@ -214,6 +310,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
214
  return null;
215
  }
216
 
 
 
 
217
  $addresses = $this->getShipment()->getOrder()->getAddressesCollection();
218
  foreach ($addresses as $address) {
219
  if ($address->getAddressType() == self::ADDRESS_TYPE_PAKJEGEMAK) {
@@ -234,8 +333,8 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
234
  */
235
  public function getStoreId()
236
  {
237
- if ($this->getData('store_id')) {
238
- return $this->getData('store_id');
239
  }
240
 
241
  if ($this->getShipment()) {
@@ -258,8 +357,8 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
258
  */
259
  public function getOrderId()
260
  {
261
- if ($this->getData('order_id')) {
262
- return $this->getData('order_id');
263
  }
264
 
265
  $shipment = $this->getShipment();
@@ -276,12 +375,16 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
276
  /**
277
  * Gets a PostNL helper object
278
  *
279
- * @return TIG_PostNL_Helper_Data
 
 
 
 
280
  */
281
  public function getHelper($type = 'data')
282
  {
283
- if ($this->getData('helper_' . $type)) {
284
- return $this->getData('helper_' . $type);
285
  }
286
 
287
  $helper = Mage::helper('postnl/' . $type);
@@ -299,34 +402,24 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
299
  {
300
  $process = $this->_process;
301
  if (is_null($process)) {
 
 
 
302
  $process = Mage::getModel('postnl_core/shipment_process')
303
  ->setId($this->getId());
 
304
  $this->setProcess($process);
305
  }
306
 
307
  return $process;
308
  }
309
 
310
- /**
311
- * Sets the process used for locking and unlocking this shipment
312
- *
313
- * @param TIG_PostNL_Model_Core_Shipment_Process
314
- *
315
- * @return TIG_PostNL_Model_Core_Shipment
316
- */
317
- public function setProcess(TIG_PostNL_Model_Core_Shipment_Process $process)
318
- {
319
- $this->_process = $process;
320
-
321
- return $this;
322
- }
323
-
324
  /**
325
  * Get an array of labels that have to be saved together
326
  *
327
  * @return array
328
  */
329
- public function getlabelsToSave()
330
  {
331
  return $this->_labelsToSave;
332
  }
@@ -348,8 +441,8 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
348
  */
349
  public function getProductCode()
350
  {
351
- if ($this->getData('product_code')) {
352
- return $this->getData('product_code');
353
  }
354
 
355
  $productCode = $this->_getProductCode();
@@ -370,7 +463,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
370
 
371
  /**
372
  * If the 'labels_printed' flag is false, yet there are labels present something has gone wrong.
373
- * Delete the labels so the module will generate new ones.
374
  */
375
  if (!$this->getLabelsPrinted() && $labelCollection->getSize() > 0) {
376
  $this->deleteLabels();
@@ -384,12 +477,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
384
  /**
385
  * Get the amount of extra cover this shipment has.
386
  *
387
- * @return int | float
388
  */
389
  public function getExtraCoverAmount()
390
  {
391
- if ($this->hasData('extra_cover_amount')) {
392
- return $this->getData('extra_cover_amount');
393
  }
394
 
395
  return 0;
@@ -401,7 +494,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
401
  * @param boolean $standardize Whether or not to convert the weight to kg
402
  * @param boolean $toGrams whether or not to convert the standardized weight to g
403
  *
404
- * @return float | int
405
  */
406
  public function getTotalWeight($standardize = false, $toGrams = false)
407
  {
@@ -414,6 +507,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
414
  * calculate the total weight
415
  */
416
  $weight = 0;
 
 
 
417
  foreach ($items as $item) {
418
  $weight += ($item->getWeight() * $item->getQty());
419
  }
@@ -423,9 +519,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
423
  }
424
 
425
  /**
426
- * standardize the weight to kg or g
 
 
427
  */
428
- $weight = $this->getHelper('cif')->standardizeWeight(
 
429
  $weight,
430
  $this->getStoreId(),
431
  $toGrams
@@ -437,12 +536,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
437
  /**
438
  * Calculates a shipment's base grand total based on it's shipment items
439
  *
440
- * @return float | null
441
  */
442
  public function getShipmentBaseGrandTotal()
443
  {
444
- if ($this->getData('shipment_base_grand_total')) {
445
- return $this->getData('shipment_base_grand_total');
446
  }
447
 
448
  /**
@@ -458,8 +557,13 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
458
  */
459
  $baseGrandTotal = 0;
460
  $shipmentItems = $shipment->getAllItems();
 
 
 
 
461
  foreach ($shipmentItems as $shipmentItem) {
462
  $qty = $shipmentItem->getQty();
 
463
  /**
464
  * The base price of a shipment item is only available through it's associated order item
465
  */
@@ -488,7 +592,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
488
  public function getBarcodeUrl($forceNl = false)
489
  {
490
  if ($this->hasBarcodeUrl()) {
491
- return $this->getData('barcode_url');
492
  }
493
 
494
  $barcode = $this->getMainBarcode();
@@ -496,6 +600,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
496
  return false;
497
  }
498
 
 
 
 
499
  $helper = $this->getHelper('carrier');
500
 
501
  $locale = Mage::getStoreConfig('general/locale/code', $this->getStoreId());
@@ -508,64 +615,69 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
508
  }
509
 
510
  /**
511
- * Gets the shipment's shipment type for intrnational shipments.
512
- * If no shipment type is defined, use the default 'commercial goods'.
513
  *
514
- * @return string | null
515
  */
516
- public function getShipmentType()
517
  {
518
- if ($this->getData('shipment_type')) {
519
- return $this->getData('shipment_type');
520
  }
521
 
522
  if (!$this->isGlobalShipment()) {
523
  return null;
524
  }
525
 
526
- $shipmentType = 'Commercial Goods';
527
- return $shipmentType;
 
 
 
 
528
  }
529
 
530
  /**
531
  * Gets the default product code for this shipment from the module's configuration
532
  *
533
  * @return string
534
- *
535
- * @todo implement pakjegemak
536
  */
537
  public function getDefaultProductCode()
538
  {
539
  $storeId = $this->getStoreId();
540
 
541
- if ($this->isPakjeGemakShipment()) {
 
 
 
 
 
 
 
 
 
 
 
542
  /**
543
  * PakjeGemak default option
544
  */
545
- $productCode = Mage::getStoreConfig(self::XML_PATH_DEFAULT_PAKJEGEMAK_PRODUCT_OPTION, $storeId);
546
- $this->_checkProductCodeAllowed($productCode);
547
-
548
- return $productCode;
549
- }
550
-
551
- if ($this->isEuShipment()) {
552
  /**
553
  * EU default option
554
  */
555
- $productCode = Mage::getStoreConfig(self::XML_PATH_DEFAULT_EU_PRODUCT_OPTION, $storeId);
556
- $this->_checkProductCodeAllowed($productCode);
557
-
558
- return $productCode;
559
- }
560
-
561
- if ($this->isGlobalShipment()) {
562
  /**
563
  * Global default option
564
  */
565
- $productCode = Mage::getStoreConfig(self::XML_PATH_DEFAULT_GLOBAL_PRODUCT_OPTION, $storeId);
566
- $this->_checkProductCodeAllowed($productCode);
567
-
568
- return $productCode;
569
  }
570
 
571
  /**
@@ -573,29 +685,31 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
573
  */
574
 
575
  /**
576
- * Dutch shipments may use an alternative default option when the shipment's base grandtotal exceeds a specified amount
 
577
  */
578
- $useAlternativeDefault = Mage::getStoreConfig(self::XML_PATH_USE_ALTERNATIVE_DEFAULT, $storeId);
579
- if ($useAlternativeDefault) {
580
  /**
581
  * Alternative default option usage is enabled
582
  */
583
- $maxShipmentAmount = Mage::getStoreConfig(self::XML_PATH_ALTERNATIVE_DEFAULT_MAX_AMOUNT, $storeId);
584
  if ($this->getShipmentBaseGrandTotal() > $maxShipmentAmount) {
585
  /**
586
- * The shipment's base GT exceeds the specified amount; use the alternative default
587
  */
588
- $productCode = Mage::getStoreConfig(self::XML_PATH_ALTERNATIVE_DEFAULT_OPTION, $storeId);
589
- $this->_checkProductCodeAllowed($productCode);
590
-
591
- return $productCode;
592
  }
593
  }
594
 
 
 
 
 
595
  /**
596
  * standard default option
597
  */
598
- $productCode = Mage::getStoreConfig(self::XML_PATH_DEFAULT_STANDARD_PRODUCT_OPTION, $storeId);
599
  $this->_checkProductCodeAllowed($productCode);
600
 
601
  return $productCode;
@@ -604,9 +718,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
604
  /**
605
  * Get a specific barcode for this shipment
606
  *
607
- * @param int | null $barcodeNumber Which barcode to get
608
  *
609
- * @return string | null
610
  */
611
  public function getBarcode($barcodeNumber = null)
612
  {
@@ -615,8 +729,11 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
615
  return $barcode;
616
  }
617
 
618
- $barcode = Mage::getModel('postnl_core/shipment_barcode')
619
- ->loadByParentAndBarcodeNumber($this->getId(), $barcodeNumber);
 
 
 
620
 
621
  return $barcode->getBarcode();
622
  }
@@ -624,7 +741,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
624
  /**
625
  * Get all barcodes associated with this shipment
626
  *
627
- * @param $asObject boolean Optional value to get the barcodes as entities, rather than an array of values
628
  *
629
  * @return array
630
  */
@@ -656,16 +773,151 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
656
  return $barcodeCollection->getItems();
657
  }
658
 
659
- /****************************************************************************************************************************
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  * SETTER METHODS
661
- ***************************************************************************************************************************/
662
 
663
  /**
664
  * Set an array of labels that are to be saved together
665
  *
666
  * @param array $labels
667
  *
668
- * @return TIG_PostNL_Model_Core_Shipment
669
  */
670
  public function setLabelsToSave($labels)
671
  {
@@ -679,7 +931,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
679
  *
680
  * @param int $amount
681
  *
682
- * @return TIG_PostNL_Model_Core_Shipment
683
  */
684
  public function setExtraCoverAmount($amount)
685
  {
@@ -689,7 +941,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
689
  $productCode = $this->getProductCode();
690
  $extraCoverProductCodes = $this->getExtraCoverProductCodes();
691
  if (!in_array($productCode, $extraCoverProductCodes)) {
692
- return $this;
693
  }
694
 
695
  $this->setData('extra_cover_amount', $amount);
@@ -702,9 +954,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
702
  *
703
  * @param string $type
704
  *
705
- * @return TIG_PostNL_Model_Core_Shipment
706
  */
707
- public function setShipmentType($type)
708
  {
709
  /**
710
  * Only global shipments have a shipment type
@@ -719,7 +971,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
719
  $shipmentType = str_replace('_', ' ', $type);
720
  $shipmentType = ucwords($shipmentType);
721
 
722
- $this->setData('shipment_type', $shipmentType);
723
  return $this;
724
  }
725
 
@@ -728,11 +980,13 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
728
  *
729
  * @param int $count
730
  *
731
- * @return TIG_PostNL_Model_Core_Shipment
 
 
732
  */
733
  public function setParcelCount($count)
734
  {
735
- $maxParcelCount = Mage::getStoreConfig(self::XML_PATH_MAX_PARCEL_COUNT, Mage_Core_Model_App::ADMIN_STORE_ID);
736
  if (!$maxParcelCount) {
737
  $this->setData('parcel_count', $count);
738
  return $this;
@@ -753,52 +1007,87 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
753
  return $this;
754
  }
755
 
756
- /****************************************************************************************************************************
757
- * SHIPMENT LOCKING AND UNLOCKING FUNCTIONS
758
- ***************************************************************************************************************************/
759
-
760
  /**
761
- * Lock this shipment to prevent simultaneous execution
 
 
762
  *
763
- * @return TIG_PostNL_Model_Core_Shipment
764
  */
765
- public function lock()
766
  {
767
- $process = $this->getProcess();
768
- $process->lockAndBlock();
769
-
770
- return $this;
771
  }
772
 
773
  /**
774
- * Unlock this shipment
775
  *
776
- * @return TIG_PostNL_Model_Core_Shipment
 
 
777
  */
778
- public function unlock()
779
  {
780
- $process = $this->getProcess();
781
- $process->unlock();
782
 
783
  return $this;
784
  }
785
 
786
  /**
787
- * Check if this shipment is locked
 
 
788
  *
789
- * @return boolean
 
 
790
  */
791
- public function isLocked()
792
  {
793
- $process = $this->getProcess();
794
- $isLocked = $process->isLocked();
 
 
795
 
796
- return $isLocked;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
797
  }
798
 
799
- /****************************************************************************************************************************
800
  * HAS- METHODS
801
- ***************************************************************************************************************************/
802
 
803
  /**
804
  * Check if the shipment has any associated labels
@@ -847,6 +1136,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
847
  */
848
  public function hasLabelType($labelType)
849
  {
 
 
 
850
  $coreResource = Mage::getSingleton('core/resource');
851
  $readConn = $coreResource->getConnection('core/read');
852
 
@@ -864,14 +1156,14 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
864
  return true;
865
  }
866
 
867
- /****************************************************************************************************************************
868
  * IS- AND CAN- METHODS
869
- ***************************************************************************************************************************/
870
 
871
  /**
872
  * Alias for magic getIsPakjeGemak()
873
  *
874
- * Please note the difference between this method and TIG_PostNL_Model_Core_Shipment::isPakjeGemakShipment
875
  *
876
  * @return integer
877
  */
@@ -887,6 +1179,10 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
887
  */
888
  public function isDutchShipment()
889
  {
 
 
 
 
890
  $shippingDestination = $this->getShippingAddress()->getCountryId();
891
 
892
  if ($shippingDestination == 'NL') {
@@ -903,9 +1199,17 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
903
  */
904
  public function isEuShipment()
905
  {
 
 
 
 
906
  $shippingDestination = $this->getShippingAddress()->getCountryId();
907
 
908
- $euCountries = $this->getHelper('cif')->getEuCountries();
 
 
 
 
909
 
910
  if (in_array($shippingDestination, $euCountries)) {
911
  return true;
@@ -921,6 +1225,10 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
921
  */
922
  public function isGlobalShipment()
923
  {
 
 
 
 
924
  if (!$this->isDutchShipment() && !$this->isEuShipment()) {
925
  return true;
926
  }
@@ -928,6 +1236,60 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
928
  return false;
929
  }
930
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
931
  /**
932
  * Check if the currrent shipment is a PakjeGemak shipment.
933
  *
@@ -939,13 +1301,27 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
939
  return true;
940
  }
941
 
942
- $postnlOrder = Mage::getModel('postnl_checkout/order')->load($this->getOrderId(), 'order_id');
943
- if ($postnlOrder->getId() && $postnlOrder->getIsPakjeGemak()) {
 
 
 
 
 
 
 
 
944
  return true;
945
  }
946
 
947
- $pakjeGemakProductCodes = $this->getHelper('cif')->getPakjeGemakProductCodes();
948
- $productCode = $this->getData('product_code');
 
 
 
 
 
 
949
 
950
  if (!$productCode) {
951
  return false;
@@ -959,6 +1335,35 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
959
  return false;
960
  }
961
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
962
  /**
963
  * Checks if this shipment is a COD shipment
964
  *
@@ -968,7 +1373,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
968
  */
969
  public function isCod()
970
  {
971
- return false; //TODO implement this method
972
  }
973
 
974
  /**
@@ -986,6 +1391,28 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
986
  return false;
987
  }
988
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
989
  /**
990
  * Checks if the current entity may generate a barcode.
991
  *
@@ -1003,6 +1430,8 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1003
  /**
1004
  * Checks if the current entity can be confirmed.
1005
  *
 
 
1006
  * @return boolean
1007
  */
1008
  public function canConfirm($skipEuCheck = false)
@@ -1035,7 +1464,8 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1035
 
1036
  /**
1037
  * Checks if the current shipment is eligible for a shipping status update.
1038
- * Unconfirmed shipments, shipments whose labels are not yet printed or shipments that are already delivered are inelligible.
 
1039
  *
1040
  * @return boolean
1041
  */
@@ -1070,7 +1500,8 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1070
 
1071
  /**
1072
  * Checks if the current shipment is eligible for a complete shipping status update.
1073
- * For now the same conditions apply as a regular status update. This may change in a future update of the extension.
 
1074
  *
1075
  * @return boolean
1076
  *
@@ -1085,10 +1516,11 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1085
  * Checks if the current shipment can send a track & trace email to the customer.
1086
  *
1087
  * @param boolean $ignoreAlreadySent Flag to ignore the 'already sent' check
 
1088
  *
1089
  * @return boolean
1090
  */
1091
- public function canSendTrackAndTraceEmail($ignoreAlreadySent = false)
1092
  {
1093
  if ($this->isLocked()) {
1094
  return false;
@@ -1098,10 +1530,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1098
  return false;
1099
  }
1100
 
1101
- $storeId = $this->getStoreId();
1102
- $canSendTrackAndTrace = Mage::getStoreConfig(self::XML_PATH_SEND_TRACK_AND_TRACE_EMAIL, $storeId);
1103
- if (!$canSendTrackAndTrace) {
1104
- return false;
 
 
1105
  }
1106
 
1107
  return true;
@@ -1135,15 +1569,61 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1135
  return true;
1136
  }
1137
 
1138
- /****************************************************************************************************************************
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1139
  * CIF FUNCTIONALITY METHODS
1140
- ***************************************************************************************************************************/
1141
 
1142
  /**
1143
  * Generates barcodes for this postnl shipment.
1144
- * Barcodes are the basis for all CIF functionality and must therefore be generated before any further action is possible.
 
1145
  *
1146
- * @return TIG_PostNL_Model_Core_Shipment
1147
  *
1148
  * @throws TIG_PostNL_Exception
1149
  */
@@ -1172,9 +1652,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1172
  }
1173
 
1174
  /**
1175
- * If this shipment consists of a single parcel or if it's an international shipment we only need the main barcode
1176
  */
1177
- if ($parcelCount < 2 || $this->isGlobalShipment()) {
1178
  Mage::dispatchEvent('postnl_shipment_generatebarcode_after', array('shipment' => $this));
1179
  $this->unlock();
1180
 
@@ -1200,19 +1680,26 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1200
  * @return string
1201
  *
1202
  * @throws TIG_PostNL_Exception
 
1203
  */
1204
  protected function _generateBarcode()
1205
  {
1206
  $shipment = $this->getShipment();
1207
 
 
 
 
 
1208
  $cif = Mage::getModel('postnl_core/cif');
1209
- $barcodeType = $this->getHelper('cif')->getBarcodeTypeForShipment($this);
 
 
1210
 
1211
  $barcode = $cif->generateBarcode($shipment, $barcodeType);
1212
 
1213
  if (!$barcode) {
1214
  throw new TIG_PostNL_Exception(
1215
- Mage::helper('postnl')->__('Unable to generate barcode for this shipment: %s', $shipment->getId()),
1216
  'POSTNL-0070'
1217
  );
1218
  }
@@ -1220,7 +1707,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1220
  /**
1221
  * If the generated barcode already exists a new one needs to be generated.
1222
  */
1223
- if ($this->getHelper('cif')->barcodeExists($barcode)) {
1224
  return $this->_generateBarcode();
1225
  }
1226
 
@@ -1230,7 +1717,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1230
  /**
1231
  * Generates a shipping labels for a shipment without confirming it with PostNL.
1232
  *
1233
- * @return TIG_PostNL_Model_Core_Shipment
1234
  *
1235
  * @throws TIG_PostNL_Exception
1236
  */
@@ -1277,11 +1764,13 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1277
  }
1278
 
1279
  /**
1280
- * Get a shipping label from PostNL for a single parcel or a whole shipment
1281
  *
1282
- * @param boolean $confirm Whether or not to also confirm the shipment
1283
- * @param int | null $barcodeNumber An optional barcode number. If this parameter is null, the main barcode will be used
 
1284
  *
 
1285
  * @return array
1286
  */
1287
  protected function _generateLabel($confirm = false, $barcodeNumber = false)
@@ -1293,25 +1782,31 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1293
  */
1294
  if ($barcodeNumber === false) {
1295
  $barcode = $mainBarcode;
1296
- $mainbarcode = false;
1297
  } else {
1298
  $barcode = $this->getBarcode($barcodeNumber);
1299
  $barcodeNumber++; //while barcode numbers start at 0, shipment numbers start at 1
1300
  }
1301
 
 
 
 
1302
  $cif = Mage::getModel('postnl_core/cif');
 
1303
 
 
 
 
1304
  if ($confirm === false) {
1305
  $result = $cif->generateLabelsWithoutConfirm($this, $barcode, $mainBarcode, $barcodeNumber);
1306
  } else {
1307
  $result = $cif->generateLabels($this, $barcode, $mainBarcode, $barcodeNumber);
1308
  }
1309
 
1310
- if (!isset($result->Labels) || !isset($result->Labels->Label)) {
1311
  throw new TIG_PostNL_Exception(
1312
  Mage::helper('postnl')->__(
1313
  'The confirmAndPrintLabel action returned an invalid response: %s',
1314
- var_export($response, true)
1315
  ),
1316
  'POSTNL-0071'
1317
  );
@@ -1319,7 +1814,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1319
  $labels = $result->Labels->Label;
1320
 
1321
  /**
1322
- * If this is an EU shipment and a non-combi label was returned, the product code needs to be updated
1323
  */
1324
  if ($this->isEuShipment() && !$this->_isCombiLabel()) {
1325
  $this->setProductCode($result->ProductCodeDelivery);
@@ -1328,10 +1823,34 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1328
  return $labels;
1329
  }
1330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1331
  /**
1332
  * Confirm the shipment with PostNL without generating new labels
1333
  *
1334
- * @return TIG_PostNL_Model_Core_Shipment
1335
  *
1336
  * @throws TIG_PostNL_Exception
1337
  */
@@ -1359,8 +1878,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1359
  if ($parcelCount < 2) {
1360
  $this->_confirm();
1361
 
1362
- $this->setConfirmStatus(self::CONFIRM_STATUS_CONFIRMED)
1363
- ->setConfirmedAt(Mage::getModel('core/date')->gmtTimestamp());
1364
 
1365
  Mage::dispatchEvent('postnl_shipment_confirm_after', array('shipment' => $this));
1366
 
@@ -1375,8 +1893,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1375
  $this->_confirm($i);
1376
  }
1377
 
1378
- $this->setConfirmStatus(self::CONFIRM_STATUS_CONFIRMED)
1379
- ->setConfirmedAt(Mage::getModel('core/date')->gmtTimestamp());
1380
 
1381
  Mage::dispatchEvent('postnl_shipment_confirm_after', array('shipment' => $this));
1382
 
@@ -1385,13 +1902,13 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1385
  }
1386
 
1387
  /**
1388
- * Confirms the shipment using CIF
1389
- *
1390
- * @param int | null $barcodeNumber
1391
  *
1392
- * @return TIG_PostNL_Model_Core_Shipment
1393
  *
1394
  * @throws TIG_PostNL_Exception
 
 
1395
  */
1396
  protected function _confirm($barcodeNumber = false)
1397
  {
@@ -1402,20 +1919,24 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1402
  */
1403
  if ($barcodeNumber === false) {
1404
  $barcode = $mainBarcode;
1405
- $mainbarcode = false;
1406
  } else {
1407
  $barcode = $this->getBarcode($barcodeNumber);
1408
  $barcodeNumber++; //while barcode numbers start at 0, shipment numbers start at 1
1409
  }
1410
 
 
 
 
 
1411
  $cif = Mage::getModel('postnl_core/cif');
 
1412
  $result = $cif->confirmShipment($this, $barcode, $mainBarcode, $barcodeNumber);
1413
 
1414
  $responseShipment = $result->ConfirmingResponseShipment;
1415
 
1416
  /**
1417
- * If the ConfirmingResponseShipment is an object, it means only one shipment was confirmed and the returned barcode
1418
- * has to be the shipment's main barcode.
1419
  */
1420
  if (is_object($responseShipment)
1421
  && isset($responseShipment->Barcode)
@@ -1425,11 +1946,11 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1425
  }
1426
 
1427
  /**
1428
- * If the ConfirmingResponseShipment is an array, it may indicate multiple shipments were confirmed. We need to check the
1429
- * first shipment's barcode to see if it matches the main bartcode.
1430
  */
1431
  if (is_array($responseShipment)) {
1432
- $mainResponseShipment = $responseShipment[0];
1433
 
1434
  if (is_object($mainResponseShipment)
1435
  && isset($mainResponseShipment->Barcode)
@@ -1451,7 +1972,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1451
  /**
1452
  * Generates a shipping label and confirms the shipment with postNL.
1453
  *
1454
- * @return TIG_PostNL_Model_Core_Shipment
1455
  *
1456
  * @throws TIG_PostNL_Exception
1457
  */
@@ -1474,6 +1995,11 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1474
  $parcelCount = $this->_calculateParcelCount();
1475
  }
1476
 
 
 
 
 
 
1477
  /**
1478
  * Confirm and generate labels purely for the main shipment
1479
  */
@@ -1482,7 +2008,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1482
  $this->addLabels($labels);
1483
 
1484
  $this->setConfirmStatus(self::CONFIRM_STATUS_CONFIRMED)
1485
- ->setConfirmedAt(Mage::getModel('core/date')->gmtTimestamp());
1486
 
1487
  $this->_saveLabels();
1488
 
@@ -1502,7 +2028,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1502
  }
1503
 
1504
  $this->setConfirmStatus(self::CONFIRM_STATUS_CONFIRMED)
1505
- ->setConfirmedAt(Mage::getModel('core/date')->gmtTimestamp());
1506
 
1507
  $this->_saveLabels();
1508
 
@@ -1516,7 +2042,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1516
  /**
1517
  * Requests a shipping status update for this shipment
1518
  *
1519
- * @return TIG_PostNL_Model_Core_Shipment
1520
  *
1521
  * @throws TIG_PostNL_Exception
1522
  */
@@ -1533,7 +2059,11 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1533
 
1534
  Mage::dispatchEvent('postnl_shipment_updateshippingstatus_before', array('shipment' => $this));
1535
 
 
 
 
1536
  $cif = Mage::getModel('postnl_core/cif');
 
1537
  $result = $cif->getShipmentStatus($this);
1538
 
1539
  $currentPhase = $result->Status->CurrentPhaseCode;
@@ -1553,9 +2083,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1553
  /**
1554
  * Update this shipment's status history
1555
  *
1556
- * @param StdClass $oldStatuses
1557
  *
1558
- * @return TIG_PostNL_Model_Core_Shipment
1559
  */
1560
  public function updateCompleteShippingStatus()
1561
  {
@@ -1570,7 +2100,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1570
 
1571
  Mage::dispatchEvent('postnl_shipment_updatecompleteshippingstatus_before', array('shipment' => $this));
1572
 
 
 
 
 
1573
  $cif = Mage::getModel('postnl_core/cif');
 
1574
  $result = $cif->getCompleteShipmentStatus($this);
1575
 
1576
  /**
@@ -1590,10 +2125,18 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1590
  $completeStatusHistory = $result->Events->CompleteStatusResponseEvent;
1591
  $completeStatusHistory = $this->_sortStatusHistory($completeStatusHistory);
1592
 
 
 
 
 
 
1593
  /**
1594
  * Update the shipments status history
1595
  */
1596
  foreach ($completeStatusHistory as $status) {
 
 
 
1597
  $statusHistory = Mage::getModel('postnl_core/shipment_status_history');
1598
 
1599
  /**
@@ -1604,7 +2147,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1604
  continue;
1605
  }
1606
 
1607
- $timestamp = Mage::getModel('core/date')->gmtTimestamp($status->TimeStamp);
1608
  $statusHistory->setParentId($this->getId())
1609
  ->setCode($status->Code)
1610
  ->setDescription($status->Description)
@@ -1616,7 +2159,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1616
  ->save();
1617
  }
1618
 
1619
- $this->setStatusHistoryUpdatedAt(Mage::getModel('core/date')->gmtTimestamp());
1620
 
1621
  Mage::dispatchEvent('postnl_shipment_updatecompleteshippingstatus_after', array('shipment' => $this));
1622
 
@@ -1625,14 +2168,14 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1625
  return $this;
1626
  }
1627
 
1628
- /****************************************************************************************************************************
1629
  * TRACKING METHODS
1630
- ***************************************************************************************************************************/
1631
 
1632
  /**
1633
  * Adds Magento tracking information to the order containing the previously retrieved barcode
1634
  *
1635
- * @return TIG_PostNL_Model_Core_Shipment
1636
  *
1637
  * @throws TIG_PostNL_Exception
1638
  */
@@ -1657,16 +2200,21 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1657
  'number' => $barcode,
1658
  );
1659
 
 
 
 
1660
  $track = Mage::getModel('sales/order_shipment_track')->addData($data);
1661
  $shipment->addTrack($track);
1662
 
1663
  /**
1664
- * Save the Mage_Sales_Order_Shipment object and the TIG_PostNL_Model_Core_Shipment objects simultaneously
 
 
1665
  */
1666
- $transactionSave = Mage::getModel('core/resource_transaction')
1667
- ->addObject($this)
1668
- ->addObject($shipment)
1669
- ->save();
1670
 
1671
  return $this;
1672
  }
@@ -1675,29 +2223,35 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1675
  * Send a track & trace email to the customer containing a link to the 'mijnpakket' environment where they
1676
  * can track their shipment.
1677
  *
1678
- * @param boolean $ignoreAlreadySent Flag to ignore the 'already sent' check
 
 
 
1679
  *
1680
- * @return TIG_PostNL_Model_Core_Shipment
1681
  */
1682
- public function sendTrackAndTraceEmail($ignoreAlreadySent = false)
1683
  {
1684
- if (!$this->canSendTrackAndTraceEmail($ignoreAlreadySent)) {
1685
  throw new TIG_PostNL_Exception(
1686
  Mage::helper('postnl')->__('The sendTrackAndTraceEmail action is currently unavailable.'),
1687
  'POSTNL-0076'
1688
  );
1689
  }
1690
 
1691
- $oldStoreId = Mage::app()->getStore()->getId();
1692
  $storeId = $this->getStoreId();
1693
 
1694
- $template = Mage::getStoreConfig(self::XML_PATH_TRACK_AND_TRACE_EMAIL_TEMPLATE, $storeId);
 
 
 
 
1695
  $mailTemplate = Mage::getModel('core/email_template');
1696
 
1697
  $shippingAddress = $this->getShippingAddress();
1698
  $recipient = array(
1699
  'email' => $this->getShipment()->getOrder()->getCustomerEmail(),
1700
- 'name' => $shippingAddress->getFirstname() . ' ' . $shippingAddress->getLastname(),
1701
  );
1702
 
1703
  $mailTemplate->setDesignConfig(
@@ -1707,8 +2261,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1707
  )
1708
  );
1709
 
 
 
 
1710
  $shipment = $this->getShipment();
1711
  $order = $shipment->getOrder();
 
1712
  $templateVariables = array(
1713
  'postnlshipment' => $this,
1714
  'barcode' => $this->getMainBarcode(),
@@ -1719,6 +2277,10 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1719
  'quote' => $order->getQuote(),
1720
  );
1721
 
 
 
 
 
1722
  $orderModel = Mage::getConfig()->getModelClassName('sales/order');
1723
  $success = $mailTemplate->sendTransactional(
1724
  $template,
@@ -1730,17 +2292,27 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1730
 
1731
  if ($success === false) {
1732
  throw new TIG_PostNL_Exception(
1733
- Mage::helper('postnl')->__('Unable to send track and trace email for shipment #', $this->getShipmentId()),
 
 
 
1734
  'POSTNL-0077'
1735
  );
1736
  }
1737
 
 
 
 
 
 
 
 
1738
  return $this;
1739
  }
1740
 
1741
- /****************************************************************************************************************************
1742
  * BARCODE PROCESSING METHODS
1743
- ***************************************************************************************************************************/
1744
 
1745
  /**
1746
  * Add a barcode to this shipment's barcode collection
@@ -1748,10 +2320,13 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1748
  * @param string $barcode The barcode to add
1749
  * @param int $barcodeNumber The number of this barcode
1750
  *
1751
- * @return TIG_PostNL_Model_Core_Shipment
1752
  */
1753
  protected function _addBarcode($barcode, $barcodeNumber)
1754
  {
 
 
 
1755
  $barcodeModel = Mage::getModel('postnl_core/shipment_barcode');
1756
  $barcodeModel->setParentId($this->getId())
1757
  ->setBarcode($barcode)
@@ -1761,16 +2336,16 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1761
  return $this;
1762
  }
1763
 
1764
- /****************************************************************************************************************************
1765
  * LABEL PROCESSING METHODS
1766
- ***************************************************************************************************************************/
1767
 
1768
  /**
1769
  * Add labels to this shipment
1770
  *
1771
  * @param mixed $labels An array of labels or a single label object
1772
  *
1773
- * @return TIG_PostNL_Model_Core_Shipment
1774
  */
1775
  public function addLabels($labels)
1776
  {
@@ -1797,7 +2372,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1797
  *
1798
  * @param stdClass $label
1799
  *
1800
- * @return TIG_PostNL_Model_Core_Shipment
1801
  */
1802
  protected function _addLabel($label)
1803
  {
@@ -1807,6 +2382,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1807
  $labelType = 'Label-combi';
1808
  }
1809
 
 
 
 
1810
  $postnlLabel = Mage::getModel('postnl_core/shipment_label');
1811
  $postnlLabel->setParentId($this->getId())
1812
  ->setLabel(base64_encode($label->Content))
@@ -1822,11 +2400,11 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1822
  *
1823
  * @param TIG_PostNL_Model_Core_Shipment_Label $label
1824
  *
1825
- * @return TIG_PostNL_Model_Core_Shipment
1826
  */
1827
  protected function _addLabelToSave($label)
1828
  {
1829
- $labelsToSave = $this->getlabelsToSave();
1830
 
1831
  $labelsToSave[] = $label;
1832
 
@@ -1838,10 +2416,13 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1838
  /**
1839
  * Save all newly added labels at once
1840
  *
1841
- * @return TIG_PostNL_Model_Core_Shipment
1842
  */
1843
  protected function _saveLabels()
1844
  {
 
 
 
1845
  $transactionSave = Mage::getModel('core/resource_transaction');
1846
 
1847
  /**
@@ -1849,7 +2430,10 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1849
  */
1850
  $labelsToSave = $this->getLabelsToSave();
1851
 
1852
- Mage::dispatchEvent('postnl_shipment_savelabels_before', array('shipment' => $this, 'labels' => $labelsToSave));
 
 
 
1853
 
1854
  foreach ($labelsToSave as $label) {
1855
  $transactionSave->addObject($label);
@@ -1860,13 +2444,16 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1860
  */
1861
  $transactionSave->save();
1862
 
1863
- Mage::dispatchEvent('postnl_shipment_savelabels_after', array('shipment' => $this, 'labels' => $labelsToSave));
 
 
 
1864
 
1865
  return $this;
1866
  }
1867
 
1868
  /**
1869
- * Check if the returned label is a combi-label
1870
  *
1871
  * @param TIG_PostNL_Model_Core_Shipment_label
1872
  *
@@ -1899,9 +2486,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1899
  return true;
1900
  }
1901
 
1902
- /****************************************************************************************************************************
1903
  * STATUS PROCESSING METHODS
1904
- ***************************************************************************************************************************/
1905
 
1906
  /**
1907
  * Sort a status history array based on the time the status was assigned
@@ -1934,9 +2521,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1934
  return array_values($sortedHistory);
1935
  }
1936
 
1937
- /****************************************************************************************************************************
1938
  * PRODUCT CODE METHODS
1939
- ***************************************************************************************************************************/
1940
 
1941
  /**
1942
  * Gets the product code for this shipment. If specific options have been selected
@@ -1975,38 +2562,11 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1975
  */
1976
  protected function _checkProductCodeAllowed($productCode)
1977
  {
1978
- $cifHelper = $this->getHelper('cif');
1979
- $allowedProductCodes = array();
1980
-
1981
- /**
1982
- * PakjeGemak shipments are also dutch shipments
1983
- */
1984
- if ($this->isDutchShipment() && $this->isPakjeGemakShipment()) {
1985
- $allowedProductCodes = $cifHelper->getPakjeGemakProductCodes();
1986
- }
1987
-
1988
  /**
1989
- * Here we specifically want shipments that are dutch, but not PakjeGemak
1990
  */
1991
- if ($this->isDutchShipment() && !$this->isPakjeGemakShipment()) {
1992
- $allowedProductCodes = $cifHelper->getStandardProductCodes();
1993
- }
1994
-
1995
- if ($this->isEuShipment()) {
1996
- $allowedProductCodes = $cifHelper->getEuProductCodes();
1997
-
1998
- }
1999
-
2000
- if ($this->isGlobalShipment()) {
2001
- if (!$cifHelper->isGlobalAllowed()) {
2002
- throw new TIG_PostNL_Exception(
2003
- $cifHelper->__('Product code %s is not allowed for this shipment.', $productCode),
2004
- 'POSTNL-0078'
2005
- );
2006
- }
2007
-
2008
- $allowedProductCodes = $cifHelper->getGlobalProductCodes();
2009
- }
2010
 
2011
  /**
2012
  * Check if the product code is allowed
@@ -2043,11 +2603,17 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2043
  /**
2044
  * Checks if a given product code is only allowed for a specific country
2045
  *
 
 
2046
  * @return boolean|array Either false if the code is not restricted, or otherwise an array of allowed country IDs
2047
  */
2048
  protected function _isCodeRestricted($code)
2049
  {
2050
- $countryRestrictedCodes = $this->getHelper('cif')->getCountryRestrictedProductCodes();
 
 
 
 
2051
 
2052
  /**
2053
  * Check if the supplied code is restricted
@@ -2063,14 +2629,14 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2063
  return $allowedCountries;
2064
  }
2065
 
2066
- /****************************************************************************************************************************
2067
  * ADDITIONAL SHIPMENT OPTIONS
2068
- ***************************************************************************************************************************/
2069
 
2070
  /**
2071
  * Public alias for _saveAdditionalShippingOptions()
2072
  *
2073
- * @return TIG_PostNL_Model_Core_Shipment
2074
  *
2075
  * @see TIG_PostNL_Model_Core_Shipment::_saveAdditionalShippingOptions()
2076
  */
@@ -2082,7 +2648,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2082
  /**
2083
  * Stores additionally selected shipping options
2084
  *
2085
- * @return TIG_PostNL_Model_Core_Shipment
2086
  */
2087
  protected function _saveAdditionalShippingOptions()
2088
  {
@@ -2099,7 +2665,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2099
  'postnl_shipment_saveadditionaloptions_after',
2100
  array(
2101
  'shipment' => $this,
2102
- 'options' => $additionalOptions
2103
  )
2104
  );
2105
 
@@ -2128,10 +2694,13 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2128
  $weight = $this->getTotalWeight(true);
2129
 
2130
  /**
2131
- * get the weight per parcel
 
 
2132
  */
2133
- $weightPerParcel = Mage::getStoreConfig(self::XML_PATH_WEIGHT_PER_PARCEL, $this->getStoreId());
2134
- $weightPerParcel = $this->getHelper('cif')->standardizeWeight($weightPerParcel, $this->getStoreId());
 
2135
 
2136
  /**
2137
  * calculate the number of parcels needed to ship the total weight of this shipment
@@ -2141,9 +2710,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2141
  return $parcelCount;
2142
  }
2143
 
2144
- /****************************************************************************************************************************
2145
  * RESET AND DELETE METHODS
2146
- ***************************************************************************************************************************/
2147
 
2148
  /**
2149
  * Resets this shipment to a pre-confirmed state
@@ -2161,13 +2730,15 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2161
  ->deleteBarcodes() //delete all associated barcodes
2162
  ->deleteStatusHistory(); //delete all associated status history items
2163
 
 
2164
  if ($deleteLabels) {
2165
  $this->setlabelsPrinted(false) //labels have not been printed
2166
  ->deleteLabels(); //delete all associated labels
2167
  }
2168
 
2169
  if ($deleteTracks) {
2170
- $this->deleteShipmentTracks(); //delete ale addociated tracks
 
2171
  }
2172
 
2173
  return $this;
@@ -2196,18 +2767,19 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2196
  /**
2197
  * Removes all labels associated with this shipment
2198
  *
2199
- * @return TIG_PostNL_Model_Core_Shipment
2200
  */
2201
  public function deleteLabels()
2202
  {
2203
- $labelCollection = Mage::getResourceModel('postnl_core/shipment_label_collection');
2204
- $labelCollection->addFieldToFilter('parent_id', array('eq' => $this->getid()));
2205
 
2206
  $labels = $labelCollection->getItems();
2207
 
 
 
 
2208
  foreach ($labels as $label) {
2209
- $label->delete()
2210
- ->save();
2211
  }
2212
 
2213
  return $this;
@@ -2216,15 +2788,17 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2216
  /**
2217
  * Removes all barcodes associated with this shipment
2218
  *
2219
- * @return TIG_PostNL_Model_Core_Shipment
2220
  */
2221
  public function deleteBarcodes()
2222
  {
2223
  $barcodes = $this->getBarcodes(true);
2224
 
 
 
 
2225
  foreach ($barcodes as $barcode) {
2226
- $barcode->delete()
2227
- ->save();
2228
  }
2229
 
2230
  $this->setMainBarcode(false);
@@ -2235,24 +2809,26 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2235
  /**
2236
  * Deletes all status history items associated with this shipment
2237
  *
2238
- * @return TIG_PostNL_Model_Core_Shipment
2239
  */
2240
  public function deleteStatusHistory()
2241
  {
2242
  $statusHistoryCollection = Mage::getResourceModel('postnl_core/shipment_status_history_collection');
2243
  $statusHistoryCollection->addFieldToFilter('parent_id', array('eq' => $this->getid()));
2244
 
 
 
 
2245
  foreach ($statusHistoryCollection as $status) {
2246
- $status->delete()
2247
- ->save();
2248
  }
2249
 
2250
  return $this;
2251
  }
2252
 
2253
- /****************************************************************************************************************************
2254
  * BEFORE- AND AFTERSAVE METHODS
2255
- ***************************************************************************************************************************/
2256
 
2257
  /**
2258
  * Updates the shipment's attributes before saving this shipment
@@ -2261,24 +2837,28 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2261
  */
2262
  protected function _beforeSave()
2263
  {
2264
- $currentTimestamp = Mage::getModel('core/date')->gmtTimestamp();
 
 
 
 
2265
 
2266
  /**
2267
- * Store any shipment options that have been saved in the registry
2268
  */
2269
  if (Mage::registry('postnl_additional_options')) {
2270
  $this->_saveAdditionalShippingOptions();
2271
  }
2272
 
2273
  /**
2274
- * Set confirm status
2275
  */
2276
  if ($this->getConfirmStatus() === null) {
2277
  $this->setConfirmStatus(self::CONFIRM_STATUS_UNCONFIRMED);
2278
  }
2279
 
2280
  /**
2281
- * Set confrirmed at
2282
  */
2283
  if ($this->getConfirmedStatus() == self::CONFIRM_STATUS_CONFIRMED
2284
  && $this->getConfirmedAt() === null
@@ -2287,14 +2867,14 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2287
  }
2288
 
2289
  /**
2290
- * Set whether labels have printed or not
2291
  */
2292
  if ($this->getlabelsPrinted() == 0 && $this->hasLabels()) {
2293
  $this->setLabelsPrinted(1);
2294
  }
2295
 
2296
  /**
2297
- * Set a product code
2298
  */
2299
  if (!$this->getProductCode() || Mage::registry('postnl_product_option') !== null) {
2300
  $productCode = $this->_getProductCode();
@@ -2302,7 +2882,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2302
  }
2303
 
2304
  /**
2305
- * Set the parcel count
2306
  */
2307
  if (!$this->getParcelCount()) {
2308
  $parcelCount = $this->_calculateParcelCount();
@@ -2310,21 +2890,21 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2310
  }
2311
 
2312
  /**
2313
- * Set the confirm date
2314
  */
2315
  if (!$this->getConfirmDate()) {
2316
- $this->setConfirmDate($currentTimestamp);
2317
  }
2318
 
2319
  /**
2320
- * If this shipment is new, set it's created at date to the current timestamp
2321
  */
2322
  if (!$this->getId()) {
2323
  $this->setCreatedAt($currentTimestamp);
2324
  }
2325
 
2326
  /**
2327
- * Always update the updated at timestamp to the current timestamp
2328
  */
2329
  $this->setUpdatedAt($currentTimestamp);
2330
 
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ * @package TIG
39
+ * @module PostNL
40
+ * @author Total Internet Group
41
+ *
42
+ * PostNL Shipment base class. Contains the majority of PostNL shipping functionality
43
+ *
44
+ * Supported events:
45
+ * - postnl_shipment_generatebarcode_before
46
+ * - postnl_shipment_generatebarcode_after
47
+ * - postnl_shipment_generatelabel_before
48
+ * - postnl_shipment_generatelabel_after
49
+ * - postnl_shipment_register_confirmation_before
50
+ * - postnl_shipment_register_confirmation_after
51
+ * - postnl_shipment_confirm_before
52
+ * - postnl_shipment_confirm_after
53
+ * - postnl_shipment_confirmandgeneratelabel_before
54
+ * - postnl_shipment_confirmandgeneratelabel_after
55
+ * - postnl_shipment_updateshippingstatus_before
56
+ * - postnl_shipment_updateshippingstatus_after
57
+ * - postnl_shipment_updatecompleteshippingstatus_before
58
+ * - postnl_shipment_updatecompleteshippingstatus_after
59
+ * - postnl_shipment_savelabels_before
60
+ * - postnl_shipment_savelabels_after
61
+ * - postnl_shipment_saveadditionaloptions_after
62
+ *
63
+ * @method bool getIsDutchShipment()
64
+ * @method bool getIsEuShipment()
65
+ * @method bool getIsGlobalShipment()
66
+ * @method int getParcelCount()
67
+ * @method string|null getConfirmedStatus
68
+ * @method string getStatusHistoryUpdatedAt()
69
+ * @method string getConfirmStatus()
70
+ * @method string getMainBarcode()
71
+ * @method string getCreatedAt()
72
+ * @method int getIsPakjeGemak()
73
+ * @method string getConfirmDate()
74
+ * @method string getUpdatedAt()
75
+ * @method string getConfirmedAt()
76
+ * @method int getEntityId()
77
+ * @method int getIsParcelwareExported()
78
+ * @method int getTrackAndTraceEmailSent()
79
+ * @method int getShippingPhase()
80
+ * @method int getTreatAsAbandoned()
81
+ * @method int|null getShipmentId
82
+ * @method int getLabelsPrinted()
83
+ * @method bool|int getIsPakketautomaat()
84
+ *
85
+ * @method TIG_PostNL_Model_Core_Shipment setLabelsPrinted(int $value)
86
+ * @method TIG_PostNL_Model_Core_Shipment setTreatAsAbandoned(int $value)
87
+ * @method TIG_PostNL_Model_Core_Shipment setShippingPhase(int $value)
88
+ * @method TIG_PostNL_Model_Core_Shipment setTrackAndTraceEmailSent(int $value)
89
+ * @method TIG_PostNL_Model_Core_Shipment setIsParcelwareExported(int $value)
90
+ * @method TIG_PostNL_Model_Core_Shipment setEntityId(int $value)
91
+ * @method TIG_PostNL_Model_Core_Shipment setConfirmedAt(string $value)
92
+ * @method TIG_PostNL_Model_Core_Shipment setUpdatedAt(string $value)
93
+ * @method TIG_PostNL_Model_Core_Shipment setProductCode(string $value)
94
+ * @method TIG_PostNL_Model_Core_Shipment setIsPakjeGemak(int $value)
95
+ * @method TIG_PostNL_Model_Core_Shipment setCreatedAt(string $value)
96
+ * @method TIG_PostNL_Model_Core_Shipment setShipmentId(int $value)
97
+ * @method TIG_PostNL_Model_Core_Shipment setMainBarcode(string $value)
98
+ * @method TIG_PostNL_Model_Core_Shipment setConfirmStatus(string $value)
99
+ * @method TIG_PostNL_Model_Core_Shipment setStatusHistoryUpdatedAt(string $value)
100
+ * @method TIG_PostNL_Model_Core_Shipment setShipment(Mage_Sales_Model_Order_Shipment $value)
101
+ * @method TIG_PostNL_Model_Core_Shipment setShippingAddress(Mage_Sales_Model_Order_Address $value)
102
+ * @method TIG_PostNL_Model_Core_Shipment setPakjeGemakAddress(Mage_Sales_Model_Order_Address $value)
103
+ * @method TIG_PostNL_Model_Core_Shipment setStoreId(int $value)
104
+ * @method TIG_PostNL_Model_Core_Shipment setOrderId(int $value)
105
+ * @method TIG_PostNL_Model_Core_Shipment setShipmentBaseGrandTotal(float $value)
106
+ * @method TIG_PostNL_Model_Core_Shipment setBarcodeUrl(string $value)
107
+ * @method TIG_PostNL_Model_Core_Shipment setPostnlOrder(mixed $value)
108
+ * @method TIG_PostNL_Model_Core_Shipment setLabelCollection(TIG_PostNL_Model_Core_Resource_Shipment_LabeL_Collection $value)
109
+ * @method TIG_PostNL_Model_Core_Shipment setDeliveryDate(string $value)
110
+ * @method TIG_PostNL_Model_Core_Shipment setIsPakketautomaat(bool $value)
111
+ *
112
+ * @method bool hasBarcodeUrl()
113
+ * @method bool hasPostnlOrder()
114
+ * @method bool hasShipment()
115
+ * @method bool hasShipmentBaseGrandTotal()
116
+ * @method bool hasGlobalpackShipmentType()
117
+ * @method bool hasProductCode()
118
+ * @method bool hasShippingAddress()
119
+ * @method bool hasPakjeGemakAddress()
120
+ * @method bool hasStoreId()
121
+ * @method bool hasOrderId()
122
+ * @method bool hasExtraCoverAmount()
123
+ * @method bool hasLabelCollection()
124
+ * @method bool hasIsPakketautomaat()
125
+ * @method bool hasDeliveryDate()
126
  */
127
  class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
128
  {
129
  /**
130
+ * Prefix of model events names.
131
  *
132
  * @var string
133
  */
134
  protected $_eventPrefix = 'postnl_shipment';
135
 
136
  /**
137
+ * Carrier code used by postnl.
138
  */
139
  const POSTNL_CARRIER_CODE = 'postnl';
140
 
141
  /**
142
+ * Possible confirm statuses.
143
  */
144
  const CONFIRM_STATUS_CONFIRMED = 'confirmed';
145
  const CONFIRM_STATUS_UNCONFIRMED = 'unconfirmed';
146
  const CONFIRM_STATUS_CONFIRM_EXPIRED = 'confirm_expired';
147
 
148
  /**
149
+ * Possible shipping phases.
150
  */
151
  const SHIPPING_PHASE_COLLECTION = '1';
152
  const SHIPPING_PHASE_SORTING = '2';
155
  const SHIPPING_PHASE_NOT_APPLICABLE = '99';
156
 
157
  /**
158
+ * Xpaths to default product options settings.
159
  */
160
+ const XPATH_DEFAULT_STANDARD_PRODUCT_OPTION = 'postnl/cif_product_options/default_product_option';
161
+ const XPATH_DEFAULT_EVENING_PRODUCT_OPTION = 'postnl/cif_product_options/default_evening_product_option';
162
+ const XPATH_DEFAULT_PAKJEGEMAK_PRODUCT_OPTION = 'postnl/cif_product_options/default_pakjegemak_product_option';
163
+ const XPATH_DEFAULT_PGE_PRODUCT_OPTION = 'postnl/cif_product_options/default_pge_product_option';
164
+ const XPATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION = 'postnl/cif_product_options/default_pakketautomaat_product_option';
165
+ const XPATH_DEFAULT_EU_PRODUCT_OPTION = 'postnl/cif_product_options/default_eu_product_option';
166
+ const XPATH_DEFAULT_GLOBAL_PRODUCT_OPTION = 'postnl/cif_product_options/default_global_product_option';
167
+ const XPATH_USE_ALTERNATIVE_DEFAULT = 'postnl/cif_product_options/use_alternative_default';
168
+ const XPATH_ALTERNATIVE_DEFAULT_MAX_AMOUNT = 'postnl/cif_product_options/alternative_default_max_amount';
169
+ const XPATH_ALTERNATIVE_DEFAULT_OPTION = 'postnl/cif_product_options/alternative_default_option';
170
 
171
  /**
172
+ * Xpath to weight per parcel config setting.
173
  */
174
+ const XPATH_WEIGHT_PER_PARCEL = 'postnl/cif_labels_and_confirming/weight_per_parcel';
175
 
176
  /**
177
+ * Xpath to setting that determines whether or not to send track and trace emails.
178
  */
179
+ const XPATH_SEND_TRACK_AND_TRACE_EMAIL = 'postnl/cif_labels_and_confirming/send_track_and_trace_email';
180
 
181
  /**
182
+ * Xpath to track and trace email template setting.
183
  */
184
+ const XPATH_TRACK_AND_TRACE_EMAIL_TEMPLATE = 'postnl/cif_labels_and_confirming/track_and_trace_email_template';
185
 
186
  /**
187
+ * Xpath to maximum allowed parcel count settings.
188
  */
189
+ const XPATH_MAX_PARCEL_COUNT = 'postnl/advanced/max_parcel_count';
190
 
191
  /**
192
+ * Xpath to default GlobalPack shipment type.
193
+ */
194
+ const XPATH_DEFAULT_SHIPMENT_TYPE = 'postnl/cif_globalpack_settings/default_shipment_type';
195
+
196
+ /**
197
+ * CIF warning code returned when an EPS combi label is not available.
198
  */
199
  const EPS_COMBI_LABEL_WARNING_CODE = 'LIRS_0';
200
 
201
  /**
202
+ * Newly added 'pakje_gemak' address type.
203
  */
204
  const ADDRESS_TYPE_PAKJEGEMAK = 'pakje_gemak';
205
 
206
  /**
207
+ * Array of product codes that have extra cover.
208
  *
209
  * @var array
210
  */
228
  protected $_labelsToSave = array();
229
 
230
  /**
231
+ * Contains an instance of TIG_PostNL_Model_Core_Shipment_Process which locks a shipment and prevents it from being
232
+ * modified.
233
  *
234
+ * @var TIG_PostNL_Model_Core_Shipment_Process
235
  */
236
  protected $_process;
237
 
243
  $this->_init('postnl_core/shipment');
244
  }
245
 
246
+ /*******************************************************************************************************************
247
+ * GETTER METHODS
248
+ ******************************************************************************************************************/
249
 
250
  /**
251
  * Retrieves a Mage_Sales_Model_Order_Shipment entity linked to the postnl shipment.
254
  */
255
  public function getShipment()
256
  {
257
+ if ($this->hasShipment()) {
258
+ return $this->_getData('shipment');
259
  }
260
 
261
  $shipmentId = $this->getShipmentId();
263
  return null;
264
  }
265
 
266
+ /**
267
+ * @var Mage_Sales_Model_Order_Shipment $shipment
268
+ */
269
  $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
270
 
271
  $this->setShipment($shipment);
275
  /**
276
  * Retrieves the linked Shipment's shipping address
277
  *
278
+ * @return Mage_Sales_Model_Order_Address|null
279
  */
280
  public function getShippingAddress()
281
  {
282
+ if ($this->hasShippingAddress()) {
283
+ return $this->_getData('shipping_address');
284
  }
285
 
286
  $shipmentId = $this->getShipmentId();
297
  /**
298
  * Gets an optional address with the pakje_gemak address type
299
  *
300
+ * @return boolean|Mage_Sales_Model_Order_Address
301
  */
302
  public function getPakjeGemakAddress()
303
  {
304
+ if ($this->hasPakjeGemakAddress()) {
305
+ return $this->_getData('pakje_gemak_address');
306
  }
307
 
308
  $shipmentId = $this->getShipmentId();
310
  return null;
311
  }
312
 
313
+ /**
314
+ * @var Mage_Sales_Model_Order_Address $address
315
+ */
316
  $addresses = $this->getShipment()->getOrder()->getAddressesCollection();
317
  foreach ($addresses as $address) {
318
  if ($address->getAddressType() == self::ADDRESS_TYPE_PAKJEGEMAK) {
333
  */
334
  public function getStoreId()
335
  {
336
+ if ($this->hasStoreId()) {
337
+ return $this->_getData('store_id');
338
  }
339
 
340
  if ($this->getShipment()) {
357
  */
358
  public function getOrderId()
359
  {
360
+ if ($this->hasOrderId()) {
361
+ return $this->_getData('order_id');
362
  }
363
 
364
  $shipment = $this->getShipment();
375
  /**
376
  * Gets a PostNL helper object
377
  *
378
+ * @param string $type
379
+ *
380
+ * @return TIG_PostNL_Helper_Data|TIG_PostNL_Helper_Cif|TIG_PostNL_Helper_Carrier|TIG_PostNL_Helper_Checkout
381
+ * |TIG_PostNL_Helper_AddressValidation|TIG_PostNL_Helper_DeliveryOptions|TIG_PostNL_Helper_Parcelware
382
+ * |TIG_PostNL_Helper_Webservices|TIG_PostNL_Helper_Mijnpakket
383
  */
384
  public function getHelper($type = 'data')
385
  {
386
+ if ($this->hasData('helper_' . $type)) {
387
+ return $this->_getData('helper_' . $type);
388
  }
389
 
390
  $helper = Mage::helper('postnl/' . $type);
402
  {
403
  $process = $this->_process;
404
  if (is_null($process)) {
405
+ /**
406
+ * @var TIG_PostNL_Model_Core_Shipment_Process $process
407
+ */
408
  $process = Mage::getModel('postnl_core/shipment_process')
409
  ->setId($this->getId());
410
+
411
  $this->setProcess($process);
412
  }
413
 
414
  return $process;
415
  }
416
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  /**
418
  * Get an array of labels that have to be saved together
419
  *
420
  * @return array
421
  */
422
+ public function getLabelsToSave()
423
  {
424
  return $this->_labelsToSave;
425
  }
441
  */
442
  public function getProductCode()
443
  {
444
+ if ($this->hasProductCode()) {
445
+ return $this->_getData('product_code');
446
  }
447
 
448
  $productCode = $this->_getProductCode();
463
 
464
  /**
465
  * If the 'labels_printed' flag is false, yet there are labels present something has gone wrong.
466
+ * Delete the labels so the extension will generate new ones.
467
  */
468
  if (!$this->getLabelsPrinted() && $labelCollection->getSize() > 0) {
469
  $this->deleteLabels();
477
  /**
478
  * Get the amount of extra cover this shipment has.
479
  *
480
+ * @return int|float
481
  */
482
  public function getExtraCoverAmount()
483
  {
484
+ if ($this->hasExtraCoverAmount()) {
485
+ return $this->_getData('extra_cover_amount');
486
  }
487
 
488
  return 0;
494
  * @param boolean $standardize Whether or not to convert the weight to kg
495
  * @param boolean $toGrams whether or not to convert the standardized weight to g
496
  *
497
+ * @return float|int
498
  */
499
  public function getTotalWeight($standardize = false, $toGrams = false)
500
  {
507
  * calculate the total weight
508
  */
509
  $weight = 0;
510
+ /**
511
+ * @var Mage_Sales_Model_Order_Shipment_Item $item
512
+ */
513
  foreach ($items as $item) {
514
  $weight += ($item->getWeight() * $item->getQty());
515
  }
519
  }
520
 
521
  /**
522
+ * Standardize the weight to kg or g.
523
+ *
524
+ * @var TIG_PostNL_Helper_Cif $helper
525
  */
526
+ $helper = $this->getHelper('cif');
527
+ $weight = $helper->standardizeWeight(
528
  $weight,
529
  $this->getStoreId(),
530
  $toGrams
536
  /**
537
  * Calculates a shipment's base grand total based on it's shipment items
538
  *
539
+ * @return float|null
540
  */
541
  public function getShipmentBaseGrandTotal()
542
  {
543
+ if ($this->hasShipmentBaseGrandTotal()) {
544
+ return $this->_getData('shipment_base_grand_total');
545
  }
546
 
547
  /**
557
  */
558
  $baseGrandTotal = 0;
559
  $shipmentItems = $shipment->getAllItems();
560
+
561
+ /**
562
+ * @var Mage_Sales_Model_Order_Shipment_Item $shipmentItem
563
+ */
564
  foreach ($shipmentItems as $shipmentItem) {
565
  $qty = $shipmentItem->getQty();
566
+
567
  /**
568
  * The base price of a shipment item is only available through it's associated order item
569
  */
592
  public function getBarcodeUrl($forceNl = false)
593
  {
594
  if ($this->hasBarcodeUrl()) {
595
+ return $this->_getData('barcode_url');
596
  }
597
 
598
  $barcode = $this->getMainBarcode();
600
  return false;
601
  }
602
 
603
+ /**
604
+ * @var TIG_PostNL_Helper_Carrier $helper
605
+ */
606
  $helper = $this->getHelper('carrier');
607
 
608
  $locale = Mage::getStoreConfig('general/locale/code', $this->getStoreId());
615
  }
616
 
617
  /**
618
+ * Gets the shipment's shipment type for intrnational shipments. If no shipment type is defined, use the default
619
+ * value. This in turn defaults to 'Commercial Goods' if none is specified.
620
  *
621
+ * @return string|null
622
  */
623
+ public function getGlobalpackShipmentType()
624
  {
625
+ if ($this->hasGlobalpackShipmentType()) {
626
+ return $this->_getData('globalpack_shipment_type');
627
  }
628
 
629
  if (!$this->isGlobalShipment()) {
630
  return null;
631
  }
632
 
633
+ $defaultShipmentType = Mage::getStoreConfig(self::XPATH_DEFAULT_SHIPMENT_TYPE, $this->getStoreId());
634
+ if (!$defaultShipmentType) {
635
+ $defaultShipmentType = 'Commercial Goods';
636
+ }
637
+
638
+ return $defaultShipmentType;
639
  }
640
 
641
  /**
642
  * Gets the default product code for this shipment from the module's configuration
643
  *
644
  * @return string
 
 
645
  */
646
  public function getDefaultProductCode()
647
  {
648
  $storeId = $this->getStoreId();
649
 
650
+ $xpath = false;
651
+ if ($this->isPgeShipment()) {
652
+ /**
653
+ * PakjeGemak Express default option
654
+ */
655
+ $xpath = self::XPATH_DEFAULT_PGE_PRODUCT_OPTION;
656
+ } elseif ($this->isAvondshipment()) {
657
+ /**
658
+ * Evening delivery default option
659
+ */
660
+ $xpath = self::XPATH_DEFAULT_EVENING_PRODUCT_OPTION;
661
+ } elseif ($this->isPakjeGemakShipment()) {
662
  /**
663
  * PakjeGemak default option
664
  */
665
+ $xpath = self::XPATH_DEFAULT_PAKJEGEMAK_PRODUCT_OPTION;
666
+ } elseif ($this->isPakketautomaatShipment()) {
667
+ /**
668
+ * PakjeGemak default option
669
+ */
670
+ $xpath = self::XPATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION;
671
+ } elseif ($this->isEuShipment()) {
672
  /**
673
  * EU default option
674
  */
675
+ $xpath = self::XPATH_DEFAULT_EU_PRODUCT_OPTION;
676
+ } elseif ($this->isGlobalShipment()) {
 
 
 
 
 
677
  /**
678
  * Global default option
679
  */
680
+ $xpath = self::XPATH_DEFAULT_GLOBAL_PRODUCT_OPTION;
 
 
 
681
  }
682
 
683
  /**
685
  */
686
 
687
  /**
688
+ * Dutch shipments may use an alternative default option when the shipment's base grandtotal exceeds a specified
689
+ * amount.
690
  */
691
+ $useAlternativeDefault = Mage::getStoreConfig(self::XPATH_USE_ALTERNATIVE_DEFAULT, $storeId);
692
+ if (!$xpath && $useAlternativeDefault) {
693
  /**
694
  * Alternative default option usage is enabled
695
  */
696
+ $maxShipmentAmount = Mage::getStoreConfig(self::XPATH_ALTERNATIVE_DEFAULT_MAX_AMOUNT, $storeId);
697
  if ($this->getShipmentBaseGrandTotal() > $maxShipmentAmount) {
698
  /**
699
+ * The shipment's base grand total exceeds the specified amount: use the alternative default
700
  */
701
+ $xpath = self::XPATH_ALTERNATIVE_DEFAULT_OPTION;
 
 
 
702
  }
703
  }
704
 
705
+ if (!$xpath) {
706
+ $xpath = self::XPATH_DEFAULT_STANDARD_PRODUCT_OPTION;
707
+ }
708
+
709
  /**
710
  * standard default option
711
  */
712
+ $productCode = Mage::getStoreConfig($xpath, $storeId);
713
  $this->_checkProductCodeAllowed($productCode);
714
 
715
  return $productCode;
718
  /**
719
  * Get a specific barcode for this shipment
720
  *
721
+ * @param int|null $barcodeNumber Which barcode to get
722
  *
723
+ * @return string|null
724
  */
725
  public function getBarcode($barcodeNumber = null)
726
  {
729
  return $barcode;
730
  }
731
 
732
+ /**
733
+ * @var TIG_PostNL_Model_Core_Shipment_Barcode $barcode
734
+ */
735
+ $barcode = Mage::getModel('postnl_core/shipment_barcode');
736
+ $barcode->loadByParentAndBarcodeNumber($this->getId(), $barcodeNumber);
737
 
738
  return $barcode->getBarcode();
739
  }
741
  /**
742
  * Get all barcodes associated with this shipment
743
  *
744
+ * @param boolean $asObject Optional value to get the barcodes as entities, rather than an array of values
745
  *
746
  * @return array
747
  */
773
  return $barcodeCollection->getItems();
774
  }
775
 
776
+ /**
777
+ * Alias for magic getIsParcelwareExported()
778
+ *
779
+ * @return string
780
+ */
781
+ public function getIsExported()
782
+ {
783
+ return $this->getIsParcelwareExported();
784
+ }
785
+
786
+ /**
787
+ * Gets a PostNL order associated with this shipment (if any exist)
788
+ *
789
+ * @return boolean|TIG_PostNL_Model_Core_Order
790
+ */
791
+ public function getPostnlOrder()
792
+ {
793
+ if ($this->hasPostnlOrder()) {
794
+ return $this->_getData('postnl_order');
795
+ }
796
+
797
+ $postnlOrder = Mage::getModel('postnl_core/order')->load($this->getOrderId(), 'order_id');
798
+ if (!$postnlOrder->getId()) {
799
+ $this->setPostnlOrder(false);
800
+
801
+ return false;
802
+ }
803
+
804
+ $this->setPostnlOrder($postnlOrder);
805
+ return $postnlOrder;
806
+ }
807
+
808
+ /**
809
+ * Get collection object for this shipment's labels.
810
+ *
811
+ * @return TIG_PostNL_Model_Core_Resource_Shipment_Label_Collection
812
+ */
813
+ public function getLabelCollection()
814
+ {
815
+ if ($this->hasLabelCollection()) {
816
+ return $this->_getData('label_collection');
817
+ }
818
+
819
+ $labelCollection = Mage::getResourceModel('postnl_core/shipment_label_collection');
820
+ $labelCollection->addFieldToFilter('parent_id', array('eq' => $this->getid()));
821
+
822
+ $this->setLabelCollection($labelCollection);
823
+ return $labelCollection;
824
+ }
825
+
826
+ /**
827
+ * Gets allowed product codes for the current shipment.
828
+ *
829
+ * @return array
830
+ *
831
+ * @throws TIG_PostNL_Exception
832
+ */
833
+ public function getAllowedProductCodes()
834
+ {
835
+ $cifHelper = $this->getHelper('cif');
836
+
837
+ /**
838
+ * Please note the order of these checks as PakjeGemak, PakjeGemak Express, avond and pakketautomaat shipment
839
+ * would all also be considered Dutch shipments.
840
+ */
841
+
842
+ if ($this->isPgeShipment()) {
843
+ $allowedProductCodes = $cifHelper->getPgeProductCodes();
844
+ return $allowedProductCodes;
845
+ }
846
+
847
+ if ($this->isAvondShipment()) {
848
+ $allowedProductCodes = $cifHelper->getAvondProductCodes();
849
+ return $allowedProductCodes;
850
+ }
851
+
852
+ if ($this->isPakjeGemakShipment()) {
853
+ $allowedProductCodes = $cifHelper->getPakjeGemakProductCodes();
854
+ return $allowedProductCodes;
855
+ }
856
+
857
+ if ($this->isPakketautomaatShipment()) {
858
+ $allowedProductCodes = $cifHelper->getPakketautomaatProductCodes();
859
+ return $allowedProductCodes;
860
+ }
861
+
862
+ if ($this->isDutchShipment()) {
863
+ $allowedProductCodes = $cifHelper->getStandardProductCodes();
864
+ return $allowedProductCodes;
865
+ }
866
+
867
+ if ($this->isEuShipment()) {
868
+ $allowedProductCodes = $cifHelper->getEuProductCodes();
869
+ return $allowedProductCodes;
870
+ }
871
+
872
+ if ($this->isGlobalShipment() && $cifHelper->isGlobalAllowed()) {
873
+ $allowedProductCodes = $cifHelper->getGlobalProductCodes();
874
+ return $allowedProductCodes;
875
+ }
876
+
877
+ /**
878
+ * If no matches were found, return an empty array.
879
+ */
880
+ return array();
881
+ }
882
+
883
+ /**
884
+ * Gets the delivery date for this shipment.
885
+ *
886
+ * @return null|string
887
+ */
888
+ public function getDeliveryDate()
889
+ {
890
+ if ($this->hasDeliveryDate()) {
891
+ return $this->_getData('delivery_date');
892
+ }
893
+
894
+ /**
895
+ * Try to get the delivery date fr a PostNL order.
896
+ */
897
+ $postnlOrder = $this->getPostnlOrder();
898
+ if ($postnlOrder && $postnlOrder->getDeliveryDate()) {
899
+ $deliveryDate = $postnlOrder->getDeliveryDate();
900
+
901
+ $this->setDeliveryDate($deliveryDate);
902
+ return $deliveryDate;
903
+ }
904
+
905
+ /**
906
+ * If no delivery date is available, return null.
907
+ */
908
+ return null;
909
+ }
910
+
911
+ /*******************************************************************************************************************
912
  * SETTER METHODS
913
+ ******************************************************************************************************************/
914
 
915
  /**
916
  * Set an array of labels that are to be saved together
917
  *
918
  * @param array $labels
919
  *
920
+ * @return $this
921
  */
922
  public function setLabelsToSave($labels)
923
  {
931
  *
932
  * @param int $amount
933
  *
934
+ * @return boolean|TIG_PostNL_Model_Core_Shipment
935
  */
936
  public function setExtraCoverAmount($amount)
937
  {
941
  $productCode = $this->getProductCode();
942
  $extraCoverProductCodes = $this->getExtraCoverProductCodes();
943
  if (!in_array($productCode, $extraCoverProductCodes)) {
944
+ return false;
945
  }
946
 
947
  $this->setData('extra_cover_amount', $amount);
954
  *
955
  * @param string $type
956
  *
957
+ * @return $this
958
  */
959
+ public function setGlobalpackShipmentType($type)
960
  {
961
  /**
962
  * Only global shipments have a shipment type
971
  $shipmentType = str_replace('_', ' ', $type);
972
  $shipmentType = ucwords($shipmentType);
973
 
974
+ $this->setData('globalpack_shipment_type', $shipmentType);
975
  return $this;
976
  }
977
 
980
  *
981
  * @param int $count
982
  *
983
+ * @throws TIG_PostNL_Exception
984
+ *
985
+ * @return $this
986
  */
987
  public function setParcelCount($count)
988
  {
989
+ $maxParcelCount = Mage::getStoreConfig(self::XPATH_MAX_PARCEL_COUNT, Mage_Core_Model_App::ADMIN_STORE_ID);
990
  if (!$maxParcelCount) {
991
  $this->setData('parcel_count', $count);
992
  return $this;
1007
  return $this;
1008
  }
1009
 
 
 
 
 
1010
  /**
1011
+ * Alias for magic setIsParcelwareExported()
1012
+ *
1013
+ * @param mixed $isExported
1014
  *
1015
+ * @return $this
1016
  */
1017
+ public function setIsExported($isExported)
1018
  {
1019
+ return $this->setIsParcelwareExported($isExported);
 
 
 
1020
  }
1021
 
1022
  /**
1023
+ * Sets the process used for locking and unlocking this shipment
1024
  *
1025
+ * @param TIG_PostNL_Model_Core_Shipment_Process
1026
+ *
1027
+ * @return $this
1028
  */
1029
+ public function setProcess(TIG_PostNL_Model_Core_Shipment_Process $process)
1030
  {
1031
+ $this->_process = $process;
 
1032
 
1033
  return $this;
1034
  }
1035
 
1036
  /**
1037
+ * Sets the confirm date. If no value is supplied, check if this shipment has an associated PostNL order which might
1038
+ * have a confirm date specified. Otherwise calculate the confirm date based on the delivery date or the current
1039
+ * timestamp.
1040
  *
1041
+ * @param boolean|string $date
1042
+ *
1043
+ * @return $this
1044
  */
1045
+ public function setConfirmDate($date = false)
1046
  {
1047
+ if ($date !== false) {
1048
+ $this->setData('confirm_date', $date);
1049
+ return $this;
1050
+ }
1051
 
1052
+ /**
1053
+ * If this shipment has an associated PostNL order with a confirm date, use that.
1054
+ */
1055
+ $postnlOrder = $this->getPostnlOrder();
1056
+ if ($postnlOrder && $postnlOrder->getConfirmDate()) {
1057
+ $confirmDate = strtotime($postnlOrder->getConfirmDate());
1058
+
1059
+ $this->setData('confirm_date', $confirmDate);
1060
+ return $this;
1061
+ }
1062
+
1063
+ /**
1064
+ * Get the requested delivery date for this shipment.
1065
+ */
1066
+ $deliveryDate = $this->getDeliveryDate();
1067
+
1068
+ /**
1069
+ * If no delivery date is available, set the confirm date to today.
1070
+ */
1071
+ if (!$deliveryDate) {
1072
+ $confirmDate = Mage::getModel('core/date')->gmtTimestamp();
1073
+
1074
+ $this->setData('confirm_date', $confirmDate);
1075
+ return $this;
1076
+ }
1077
+
1078
+ /**
1079
+ * Calculate the confirm based on the delivery date.
1080
+ */
1081
+ $deliveryTimeStamp = strtotime($deliveryDate);
1082
+ $confirmDate = strtotime('-1 day', $deliveryTimeStamp);
1083
+
1084
+ $this->setData('confirm_date', $confirmDate);
1085
+ return $this;
1086
  }
1087
 
1088
+ /*******************************************************************************************************************
1089
  * HAS- METHODS
1090
+ ******************************************************************************************************************/
1091
 
1092
  /**
1093
  * Check if the shipment has any associated labels
1136
  */
1137
  public function hasLabelType($labelType)
1138
  {
1139
+ /**
1140
+ * @var Mage_Core_Model_Resource $coreResource
1141
+ */
1142
  $coreResource = Mage::getSingleton('core/resource');
1143
  $readConn = $coreResource->getConnection('core/read');
1144
 
1156
  return true;
1157
  }
1158
 
1159
+ /*******************************************************************************************************************
1160
  * IS- AND CAN- METHODS
1161
+ ******************************************************************************************************************/
1162
 
1163
  /**
1164
  * Alias for magic getIsPakjeGemak()
1165
  *
1166
+ * Please note the difference between this method and TIG_PostNL_Model_Core_Shipment::isPakjeGemakShipment()
1167
  *
1168
  * @return integer
1169
  */
1179
  */
1180
  public function isDutchShipment()
1181
  {
1182
+ if ($this->getIsDutchShipment()) {
1183
+ return true;
1184
+ }
1185
+
1186
  $shippingDestination = $this->getShippingAddress()->getCountryId();
1187
 
1188
  if ($shippingDestination == 'NL') {
1199
  */
1200
  public function isEuShipment()
1201
  {
1202
+ if ($this->getIsEuShipment()) {
1203
+ return true;
1204
+ }
1205
+
1206
  $shippingDestination = $this->getShippingAddress()->getCountryId();
1207
 
1208
+ /**
1209
+ * @var TIG_PostNL_Helper_Cif $helper
1210
+ */
1211
+ $helper = $this->getHelper('cif');
1212
+ $euCountries = $helper->getEuCountries();
1213
 
1214
  if (in_array($shippingDestination, $euCountries)) {
1215
  return true;
1225
  */
1226
  public function isGlobalShipment()
1227
  {
1228
+ if ($this->getIsGlobalShipment()) {
1229
+ return true;
1230
+ }
1231
+
1232
  if (!$this->isDutchShipment() && !$this->isEuShipment()) {
1233
  return true;
1234
  }
1236
  return false;
1237
  }
1238
 
1239
+ /**
1240
+ * Check if this shipment is a PakjeGemak Express shipment.
1241
+ *
1242
+ * @return bool
1243
+ */
1244
+ public function isPgeShipment()
1245
+ {
1246
+ /**
1247
+ * We can check the PostNL order's type to see if it's PakjeGemak Express.
1248
+ *
1249
+ * @var TIG_PostNL_Model_Core_Order $postnlOrder
1250
+ */
1251
+ $postnlOrder = $this->getPostnlOrder();
1252
+ if (!$postnlOrder
1253
+ || !$postnlOrder->getId()
1254
+ ) {
1255
+ return false;
1256
+ }
1257
+
1258
+ $type = $postnlOrder->getType();
1259
+ if ($type != 'PGE') {
1260
+ return false;
1261
+ }
1262
+
1263
+ return true;
1264
+ }
1265
+
1266
+ /**
1267
+ * Check if this shipment is an evening delivery shipment.
1268
+ *
1269
+ * @return bool
1270
+ */
1271
+ public function isAvondShipment()
1272
+ {
1273
+ /**
1274
+ * We can check the PostNL order's type to see if it's evening delivery.
1275
+ *
1276
+ * @var TIG_PostNL_Model_Core_Order $postnlOrder
1277
+ */
1278
+ $postnlOrder = $this->getPostnlOrder();
1279
+ if (!$postnlOrder
1280
+ || !$postnlOrder->getId()
1281
+ ) {
1282
+ return false;
1283
+ }
1284
+
1285
+ $type = $postnlOrder->getType();
1286
+ if ($type != 'Avond') {
1287
+ return false;
1288
+ }
1289
+
1290
+ return true;
1291
+ }
1292
+
1293
  /**
1294
  * Check if the currrent shipment is a PakjeGemak shipment.
1295
  *
1301
  return true;
1302
  }
1303
 
1304
+ /**
1305
+ * If the order was placed using PostNL Checkout, we can check if it was a PakjeGemak order directly.
1306
+ *
1307
+ * @var TIG_PostNL_Model_Core_Order $postnlOrder
1308
+ */
1309
+ $postnlOrder = $this->getPostnlOrder();
1310
+ if ($postnlOrder
1311
+ && $postnlOrder->getId()
1312
+ && $postnlOrder->getIsPakjeGemak()
1313
+ ) {
1314
  return true;
1315
  }
1316
 
1317
+ /**
1318
+ * Otherwise we need to check the product code by comparing it to known PakjeGemak product codes.
1319
+ *
1320
+ * @var TIG_PostNL_Helper_Cif $helper
1321
+ */
1322
+ $helper = $this->getHelper('cif');
1323
+ $pakjeGemakProductCodes = $helper->getPakjeGemakProductCodes();
1324
+ $productCode = $this->_getData('product_code');
1325
 
1326
  if (!$productCode) {
1327
  return false;
1335
  return false;
1336
  }
1337
 
1338
+ /**
1339
+ * Check if this shipment is a pakketautomaat shipment.
1340
+ *
1341
+ * @return boolean
1342
+ */
1343
+ public function isPakketautomaatShipment()
1344
+ {
1345
+ if ($this->hasIsPakketautomaat()) {
1346
+ return $this->getIsPakketautomaat();
1347
+ }
1348
+
1349
+ $postnlOrder = $this->getPostnlOrder();
1350
+ if (!$postnlOrder
1351
+ || !$postnlOrder->getId()
1352
+ || !$postnlOrder->getType()
1353
+ ) {
1354
+ $this->setIsPakketautomaat(false);
1355
+ return false;
1356
+ }
1357
+
1358
+ $type = $postnlOrder->getType();
1359
+ if ($type == 'PA') {
1360
+ $this->setIsPakketautomaat(true);
1361
+ return true;
1362
+ }
1363
+
1364
+ return false;
1365
+ }
1366
+
1367
  /**
1368
  * Checks if this shipment is a COD shipment
1369
  *
1373
  */
1374
  public function isCod()
1375
  {
1376
+ return false;
1377
  }
1378
 
1379
  /**
1391
  return false;
1392
  }
1393
 
1394
+ /**
1395
+ * Alias for isParcelwareExported()
1396
+ *
1397
+ * @return boolean
1398
+ */
1399
+ public function isExported()
1400
+ {
1401
+ return $this->isParcelwareExported();
1402
+ }
1403
+
1404
+ /**
1405
+ * Checks if this shipment has been exported to parcelware
1406
+ *
1407
+ * @return boolean
1408
+ */
1409
+ public function isParcelwareExported()
1410
+ {
1411
+ $isExported = (bool) $this->getIsParcelwareExported();
1412
+
1413
+ return $isExported;
1414
+ }
1415
+
1416
  /**
1417
  * Checks if the current entity may generate a barcode.
1418
  *
1430
  /**
1431
  * Checks if the current entity can be confirmed.
1432
  *
1433
+ * @param bool $skipEuCheck
1434
+ *
1435
  * @return boolean
1436
  */
1437
  public function canConfirm($skipEuCheck = false)
1464
 
1465
  /**
1466
  * Checks if the current shipment is eligible for a shipping status update.
1467
+ * Unconfirmed shipments, shipments whose labels are not yet printed or shipments that are already delivered are
1468
+ * inelligible.
1469
  *
1470
  * @return boolean
1471
  */
1500
 
1501
  /**
1502
  * Checks if the current shipment is eligible for a complete shipping status update.
1503
+ * For now the same conditions apply as a regular status update. This may change in a future update of the
1504
+ * extension.
1505
  *
1506
  * @return boolean
1507
  *
1516
  * Checks if the current shipment can send a track & trace email to the customer.
1517
  *
1518
  * @param boolean $ignoreAlreadySent Flag to ignore the 'already sent' check
1519
+ * @param boolean $ignoreConfig Flag to ignore the 'send_track_and_trace_email' config setting.
1520
  *
1521
  * @return boolean
1522
  */
1523
+ public function canSendTrackAndTraceEmail($ignoreAlreadySent = false, $ignoreConfig = false)
1524
  {
1525
  if ($this->isLocked()) {
1526
  return false;
1530
  return false;
1531
  }
1532
 
1533
+ if ($ignoreConfig !== true) {
1534
+ $storeId = $this->getStoreId();
1535
+ $canSendTrackAndTrace = Mage::getStoreConfig(self::XPATH_SEND_TRACK_AND_TRACE_EMAIL, $storeId);
1536
+ if (!$canSendTrackAndTrace) {
1537
+ return false;
1538
+ }
1539
  }
1540
 
1541
  return true;
1569
  return true;
1570
  }
1571
 
1572
+ /*******************************************************************************************************************
1573
+ * SHIPMENT LOCKING AND UNLOCKING FUNCTIONS
1574
+ ******************************************************************************************************************/
1575
+
1576
+ /**
1577
+ * Lock this shipment to prevent simultaneous execution
1578
+ *
1579
+ * @return $this
1580
+ */
1581
+ public function lock()
1582
+ {
1583
+ $process = $this->getProcess();
1584
+ $process->lockAndBlock();
1585
+
1586
+ $this->isLocked();
1587
+ $this->isLocked();
1588
+ return $this;
1589
+ }
1590
+
1591
+ /**
1592
+ * Unlock this shipment
1593
+ *
1594
+ * @return $this
1595
+ */
1596
+ public function unlock()
1597
+ {
1598
+ $process = $this->getProcess();
1599
+ $process->unlock();
1600
+
1601
+ return $this;
1602
+ }
1603
+
1604
+ /**
1605
+ * Check if this shipment is locked
1606
+ *
1607
+ * @return boolean
1608
+ */
1609
+ public function isLocked()
1610
+ {
1611
+ $process = $this->getProcess();
1612
+ $isLocked = $process->isLocked();
1613
+
1614
+ return $isLocked;
1615
+ }
1616
+
1617
+ /*******************************************************************************************************************
1618
  * CIF FUNCTIONALITY METHODS
1619
+ ******************************************************************************************************************/
1620
 
1621
  /**
1622
  * Generates barcodes for this postnl shipment.
1623
+ * Barcodes are the basis for all CIF functionality and must therefore be generated before any further action is
1624
+ * possible.
1625
  *
1626
+ * @return $this
1627
  *
1628
  * @throws TIG_PostNL_Exception
1629
  */
1652
  }
1653
 
1654
  /**
1655
+ * If this shipment consists of a single parcel we only need the main barcode
1656
  */
1657
+ if ($parcelCount < 2) {
1658
  Mage::dispatchEvent('postnl_shipment_generatebarcode_after', array('shipment' => $this));
1659
  $this->unlock();
1660
 
1680
  * @return string
1681
  *
1682
  * @throws TIG_PostNL_Exception
1683
+ *
1684
  */
1685
  protected function _generateBarcode()
1686
  {
1687
  $shipment = $this->getShipment();
1688
 
1689
+ /**
1690
+ * @var TIG_PostNL_Model_Core_Cif $cif
1691
+ * @var TIG_PostNL_Helper_Cif $helper
1692
+ */
1693
  $cif = Mage::getModel('postnl_core/cif');
1694
+ $cif->setStoreId($this->getStoreId());
1695
+ $helper = $this->getHelper('cif');
1696
+ $barcodeType = $helper->getBarcodeTypeForShipment($this);
1697
 
1698
  $barcode = $cif->generateBarcode($shipment, $barcodeType);
1699
 
1700
  if (!$barcode) {
1701
  throw new TIG_PostNL_Exception(
1702
+ $helper->__('Unable to generate barcode for this shipment: %s', $shipment->getId()),
1703
  'POSTNL-0070'
1704
  );
1705
  }
1707
  /**
1708
  * If the generated barcode already exists a new one needs to be generated.
1709
  */
1710
+ if ($helper->barcodeExists($barcode)) {
1711
  return $this->_generateBarcode();
1712
  }
1713
 
1717
  /**
1718
  * Generates a shipping labels for a shipment without confirming it with PostNL.
1719
  *
1720
+ * @return $this
1721
  *
1722
  * @throws TIG_PostNL_Exception
1723
  */
1764
  }
1765
 
1766
  /**
1767
+ * Get a shipping label from PostNL for a single parcel or a whole shipment.
1768
  *
1769
+ * @param boolean $confirm Whether or not to also confirm the shipment.
1770
+ * @param bool|int|null $barcodeNumber An optional barcode number. If this parameter is null, the main barcode will
1771
+ * be used.
1772
  *
1773
+ * @throws TIG_PostNL_Exception
1774
  * @return array
1775
  */
1776
  protected function _generateLabel($confirm = false, $barcodeNumber = false)
1782
  */
1783
  if ($barcodeNumber === false) {
1784
  $barcode = $mainBarcode;
 
1785
  } else {
1786
  $barcode = $this->getBarcode($barcodeNumber);
1787
  $barcodeNumber++; //while barcode numbers start at 0, shipment numbers start at 1
1788
  }
1789
 
1790
+ /**
1791
+ * @var TIG_PostNL_Model_Core_Cif $cif
1792
+ */
1793
  $cif = Mage::getModel('postnl_core/cif');
1794
+ $cif->setStoreId($this->getStoreId());
1795
 
1796
+ /**
1797
+ * @var StdClass $result
1798
+ */
1799
  if ($confirm === false) {
1800
  $result = $cif->generateLabelsWithoutConfirm($this, $barcode, $mainBarcode, $barcodeNumber);
1801
  } else {
1802
  $result = $cif->generateLabels($this, $barcode, $mainBarcode, $barcodeNumber);
1803
  }
1804
 
1805
+ if (!isset($result->Labels, $result->Labels->Label)) {
1806
  throw new TIG_PostNL_Exception(
1807
  Mage::helper('postnl')->__(
1808
  'The confirmAndPrintLabel action returned an invalid response: %s',
1809
+ var_export($result, true)
1810
  ),
1811
  'POSTNL-0071'
1812
  );
1814
  $labels = $result->Labels->Label;
1815
 
1816
  /**
1817
+ * If this is an EU shipment and a non-combi label was returned, the product code needs to be updated.
1818
  */
1819
  if ($this->isEuShipment() && !$this->_isCombiLabel()) {
1820
  $this->setProductCode($result->ProductCodeDelivery);
1823
  return $labels;
1824
  }
1825
 
1826
+ /**
1827
+ * Manually confirms a shipment without communicating with PostNL. This should be used if you wish to update the
1828
+ * confirmation status in Magento, while actually confirming the shipment through other means, such as Parcelware.
1829
+ *
1830
+ * @return $this
1831
+ *
1832
+ * @throws TIG_PostNL_Exception
1833
+ */
1834
+ public function registerConfirmation()
1835
+ {
1836
+ Mage::dispatchEvent('postnl_shipment_register_confirmation_before', array('shipment' => $this));
1837
+
1838
+ /**
1839
+ * @var Mage_Core_Model_Date $dateModel
1840
+ */
1841
+ $dateModel = Mage::getModel('core/date');
1842
+ $this->setConfirmStatus(self::CONFIRM_STATUS_CONFIRMED)
1843
+ ->setConfirmedAt($dateModel->gmtTimestamp());
1844
+
1845
+ Mage::dispatchEvent('postnl_shipment_register_confirmation_after', array('shipment' => $this));
1846
+
1847
+ return $this;
1848
+ }
1849
+
1850
  /**
1851
  * Confirm the shipment with PostNL without generating new labels
1852
  *
1853
+ * @return $this
1854
  *
1855
  * @throws TIG_PostNL_Exception
1856
  */
1878
  if ($parcelCount < 2) {
1879
  $this->_confirm();
1880
 
1881
+ $this->registerConfirmation();
 
1882
 
1883
  Mage::dispatchEvent('postnl_shipment_confirm_after', array('shipment' => $this));
1884
 
1893
  $this->_confirm($i);
1894
  }
1895
 
1896
+ $this->registerConfirmation();
 
1897
 
1898
  Mage::dispatchEvent('postnl_shipment_confirm_after', array('shipment' => $this));
1899
 
1902
  }
1903
 
1904
  /**
1905
+ * Confirms the shipment using CIF.
 
 
1906
  *
1907
+ * @param bool|int|null $barcodeNumber
1908
  *
1909
  * @throws TIG_PostNL_Exception
1910
+ *
1911
+ * @return $this
1912
  */
1913
  protected function _confirm($barcodeNumber = false)
1914
  {
1919
  */
1920
  if ($barcodeNumber === false) {
1921
  $barcode = $mainBarcode;
 
1922
  } else {
1923
  $barcode = $this->getBarcode($barcodeNumber);
1924
  $barcodeNumber++; //while barcode numbers start at 0, shipment numbers start at 1
1925
  }
1926
 
1927
+ /**
1928
+ * @var TIG_PostNL_Model_Core_Cif $cif
1929
+ * @var StdClass $result
1930
+ */
1931
  $cif = Mage::getModel('postnl_core/cif');
1932
+ $cif->setStoreId($this->getStoreId());
1933
  $result = $cif->confirmShipment($this, $barcode, $mainBarcode, $barcodeNumber);
1934
 
1935
  $responseShipment = $result->ConfirmingResponseShipment;
1936
 
1937
  /**
1938
+ * If the ConfirmingResponseShipment is an object, it means only one shipment was confirmed and the returned
1939
+ * barcode has to be the shipment's main barcode.
1940
  */
1941
  if (is_object($responseShipment)
1942
  && isset($responseShipment->Barcode)
1946
  }
1947
 
1948
  /**
1949
+ * If the ConfirmingResponseShipment is an array, it may indicate multiple shipments were confirmed. We need to
1950
+ * check the first shipment's barcode to see if it matches the main bartcode.
1951
  */
1952
  if (is_array($responseShipment)) {
1953
+ $mainResponseShipment = reset($responseShipment);
1954
 
1955
  if (is_object($mainResponseShipment)
1956
  && isset($mainResponseShipment->Barcode)
1972
  /**
1973
  * Generates a shipping label and confirms the shipment with postNL.
1974
  *
1975
+ * @return $this
1976
  *
1977
  * @throws TIG_PostNL_Exception
1978
  */
1995
  $parcelCount = $this->_calculateParcelCount();
1996
  }
1997
 
1998
+ /**
1999
+ * @var Mage_Core_Model_Date $dateModel
2000
+ */
2001
+ $dateModel = Mage::getModel('core/date');
2002
+
2003
  /**
2004
  * Confirm and generate labels purely for the main shipment
2005
  */
2008
  $this->addLabels($labels);
2009
 
2010
  $this->setConfirmStatus(self::CONFIRM_STATUS_CONFIRMED)
2011
+ ->setConfirmedAt($dateModel->gmtTimestamp());
2012
 
2013
  $this->_saveLabels();
2014
 
2028
  }
2029
 
2030
  $this->setConfirmStatus(self::CONFIRM_STATUS_CONFIRMED)
2031
+ ->setConfirmedAt($dateModel->gmtTimestamp());
2032
 
2033
  $this->_saveLabels();
2034
 
2042
  /**
2043
  * Requests a shipping status update for this shipment
2044
  *
2045
+ * @return $this
2046
  *
2047
  * @throws TIG_PostNL_Exception
2048
  */
2059
 
2060
  Mage::dispatchEvent('postnl_shipment_updateshippingstatus_before', array('shipment' => $this));
2061
 
2062
+ /**
2063
+ * @var TIG_PostNL_Model_Core_Cif $cif
2064
+ */
2065
  $cif = Mage::getModel('postnl_core/cif');
2066
+ $cif->setStoreId($this->getStoreId());
2067
  $result = $cif->getShipmentStatus($this);
2068
 
2069
  $currentPhase = $result->Status->CurrentPhaseCode;
2083
  /**
2084
  * Update this shipment's status history
2085
  *
2086
+ * @throws TIG_PostNL_Exception
2087
  *
2088
+ * @return $this
2089
  */
2090
  public function updateCompleteShippingStatus()
2091
  {
2100
 
2101
  Mage::dispatchEvent('postnl_shipment_updatecompleteshippingstatus_before', array('shipment' => $this));
2102
 
2103
+ /**
2104
+ * @var TIG_PostNL_Model_Core_Cif $cif
2105
+ * @var StdClass $result
2106
+ */
2107
  $cif = Mage::getModel('postnl_core/cif');
2108
+ $cif->setStoreId($this->getStoreId());
2109
  $result = $cif->getCompleteShipmentStatus($this);
2110
 
2111
  /**
2125
  $completeStatusHistory = $result->Events->CompleteStatusResponseEvent;
2126
  $completeStatusHistory = $this->_sortStatusHistory($completeStatusHistory);
2127
 
2128
+ /**
2129
+ * @var MAge_Core_Model_Date $dateModel
2130
+ */
2131
+ $dateModel = Mage::getModel('core/date');
2132
+
2133
  /**
2134
  * Update the shipments status history
2135
  */
2136
  foreach ($completeStatusHistory as $status) {
2137
+ /**
2138
+ * @var TIG_PostNL_Model_Core_Shipment_Status_History $statusHistory
2139
+ */
2140
  $statusHistory = Mage::getModel('postnl_core/shipment_status_history');
2141
 
2142
  /**
2147
  continue;
2148
  }
2149
 
2150
+ $timestamp = $dateModel->gmtTimestamp($status->TimeStamp);
2151
  $statusHistory->setParentId($this->getId())
2152
  ->setCode($status->Code)
2153
  ->setDescription($status->Description)
2159
  ->save();
2160
  }
2161
 
2162
+ $this->setStatusHistoryUpdatedAt($dateModel->gmtTimestamp());
2163
 
2164
  Mage::dispatchEvent('postnl_shipment_updatecompleteshippingstatus_after', array('shipment' => $this));
2165
 
2168
  return $this;
2169
  }
2170
 
2171
+ /*******************************************************************************************************************
2172
  * TRACKING METHODS
2173
+ ******************************************************************************************************************/
2174
 
2175
  /**
2176
  * Adds Magento tracking information to the order containing the previously retrieved barcode
2177
  *
2178
+ * @return $this
2179
  *
2180
  * @throws TIG_PostNL_Exception
2181
  */
2200
  'number' => $barcode,
2201
  );
2202
 
2203
+ /**
2204
+ * @var Mage_Sales_Model_Order_Shipment_Track $track
2205
+ */
2206
  $track = Mage::getModel('sales/order_shipment_track')->addData($data);
2207
  $shipment->addTrack($track);
2208
 
2209
  /**
2210
+ * Save the Mage_Sales_Order_Shipment object and the TIG_PostNL_Model_Core_Shipment objects simultaneously.
2211
+ *
2212
+ * @var Mage_Core_Model_Resource_Transaction $transaction
2213
  */
2214
+ $transaction = Mage::getModel('core/resource_transaction');
2215
+ $transaction->addObject($this)
2216
+ ->addObject($shipment)
2217
+ ->save();
2218
 
2219
  return $this;
2220
  }
2223
  * Send a track & trace email to the customer containing a link to the 'mijnpakket' environment where they
2224
  * can track their shipment.
2225
  *
2226
+ * @param boolean $ignoreAlreadySent Flag to ignore the 'already sent' check.
2227
+ * @param boolean $ignoreConfig Flag to ignore the configuration settings related to track&trace e-mails.
2228
+ *
2229
+ * @throws TIG_PostNL_Exception
2230
  *
2231
+ * @return $this
2232
  */
2233
+ public function sendTrackAndTraceEmail($ignoreAlreadySent = false, $ignoreConfig = false)
2234
  {
2235
+ if (!$this->canSendTrackAndTraceEmail($ignoreAlreadySent, $ignoreConfig)) {
2236
  throw new TIG_PostNL_Exception(
2237
  Mage::helper('postnl')->__('The sendTrackAndTraceEmail action is currently unavailable.'),
2238
  'POSTNL-0076'
2239
  );
2240
  }
2241
 
 
2242
  $storeId = $this->getStoreId();
2243
 
2244
+ $template = Mage::getStoreConfig(self::XPATH_TRACK_AND_TRACE_EMAIL_TEMPLATE, $storeId);
2245
+
2246
+ /**
2247
+ * @var Mage_Core_Model_Email_Template $mailTemplate
2248
+ */
2249
  $mailTemplate = Mage::getModel('core/email_template');
2250
 
2251
  $shippingAddress = $this->getShippingAddress();
2252
  $recipient = array(
2253
  'email' => $this->getShipment()->getOrder()->getCustomerEmail(),
2254
+ 'name' => $shippingAddress->getName(),
2255
  );
2256
 
2257
  $mailTemplate->setDesignConfig(
2261
  )
2262
  );
2263
 
2264
+ /**
2265
+ * @var Mage_Sales_Model_Order $order
2266
+ */
2267
  $shipment = $this->getShipment();
2268
  $order = $shipment->getOrder();
2269
+ /** @noinspection PhpUndefinedMethodInspection */
2270
  $templateVariables = array(
2271
  'postnlshipment' => $this,
2272
  'barcode' => $this->getMainBarcode(),
2277
  'quote' => $order->getQuote(),
2278
  );
2279
 
2280
+ /**
2281
+ * @var $orderModel Mage_Sales_Model_Order
2282
+ */
2283
+ /** @noinspection PhpParamsInspection */
2284
  $orderModel = Mage::getConfig()->getModelClassName('sales/order');
2285
  $success = $mailTemplate->sendTransactional(
2286
  $template,
2292
 
2293
  if ($success === false) {
2294
  throw new TIG_PostNL_Exception(
2295
+ Mage::helper('postnl')->__(
2296
+ 'Unable to send track and trace email for shipment #',
2297
+ $this->getShipmentId()
2298
+ ),
2299
  'POSTNL-0077'
2300
  );
2301
  }
2302
 
2303
+ /**
2304
+ * Set the 'email sent' flag to true for this shipment.
2305
+ */
2306
+ $this->getShipment()
2307
+ ->setEmailSent(true)
2308
+ ->save();
2309
+
2310
  return $this;
2311
  }
2312
 
2313
+ /*******************************************************************************************************************
2314
  * BARCODE PROCESSING METHODS
2315
+ ******************************************************************************************************************/
2316
 
2317
  /**
2318
  * Add a barcode to this shipment's barcode collection
2320
  * @param string $barcode The barcode to add
2321
  * @param int $barcodeNumber The number of this barcode
2322
  *
2323
+ * @return $this
2324
  */
2325
  protected function _addBarcode($barcode, $barcodeNumber)
2326
  {
2327
+ /**
2328
+ * @var TIG_PostNL_Model_Core_Shipment_Barcode $barcodeModel
2329
+ */
2330
  $barcodeModel = Mage::getModel('postnl_core/shipment_barcode');
2331
  $barcodeModel->setParentId($this->getId())
2332
  ->setBarcode($barcode)
2336
  return $this;
2337
  }
2338
 
2339
+ /*******************************************************************************************************************
2340
  * LABEL PROCESSING METHODS
2341
+ ******************************************************************************************************************/
2342
 
2343
  /**
2344
  * Add labels to this shipment
2345
  *
2346
  * @param mixed $labels An array of labels or a single label object
2347
  *
2348
+ * @return $this
2349
  */
2350
  public function addLabels($labels)
2351
  {
2372
  *
2373
  * @param stdClass $label
2374
  *
2375
+ * @return $this
2376
  */
2377
  protected function _addLabel($label)
2378
  {
2382
  $labelType = 'Label-combi';
2383
  }
2384
 
2385
+ /**
2386
+ * @var TIG_PostNL_Model_Core_Shipment_Label $postnlLabel
2387
+ */
2388
  $postnlLabel = Mage::getModel('postnl_core/shipment_label');
2389
  $postnlLabel->setParentId($this->getId())
2390
  ->setLabel(base64_encode($label->Content))
2400
  *
2401
  * @param TIG_PostNL_Model_Core_Shipment_Label $label
2402
  *
2403
+ * @return $this
2404
  */
2405
  protected function _addLabelToSave($label)
2406
  {
2407
+ $labelsToSave = $this->getLabelsToSave();
2408
 
2409
  $labelsToSave[] = $label;
2410
 
2416
  /**
2417
  * Save all newly added labels at once
2418
  *
2419
+ * @return $this
2420
  */
2421
  protected function _saveLabels()
2422
  {
2423
+ /**
2424
+ * @var Mage_Core_Model_Resource_Transaction $transactionSave
2425
+ */
2426
  $transactionSave = Mage::getModel('core/resource_transaction');
2427
 
2428
  /**
2430
  */
2431
  $labelsToSave = $this->getLabelsToSave();
2432
 
2433
+ Mage::dispatchEvent(
2434
+ 'postnl_shipment_savelabels_before',
2435
+ array('shipment' => $this, 'labels' => $labelsToSave)
2436
+ );
2437
 
2438
  foreach ($labelsToSave as $label) {
2439
  $transactionSave->addObject($label);
2444
  */
2445
  $transactionSave->save();
2446
 
2447
+ Mage::dispatchEvent(
2448
+ 'postnl_shipment_savelabels_after',
2449
+ array('shipment' => $this, 'labels' => $labelsToSave)
2450
+ );
2451
 
2452
  return $this;
2453
  }
2454
 
2455
  /**
2456
+ * Check if the returned label is a combi-label.
2457
  *
2458
  * @param TIG_PostNL_Model_Core_Shipment_label
2459
  *
2486
  return true;
2487
  }
2488
 
2489
+ /*******************************************************************************************************************
2490
  * STATUS PROCESSING METHODS
2491
+ ******************************************************************************************************************/
2492
 
2493
  /**
2494
  * Sort a status history array based on the time the status was assigned
2521
  return array_values($sortedHistory);
2522
  }
2523
 
2524
+ /*******************************************************************************************************************
2525
  * PRODUCT CODE METHODS
2526
+ ******************************************************************************************************************/
2527
 
2528
  /**
2529
  * Gets the product code for this shipment. If specific options have been selected
2562
  */
2563
  protected function _checkProductCodeAllowed($productCode)
2564
  {
 
 
 
 
 
 
 
 
 
 
2565
  /**
2566
+ * @var TIG_PostNL_Helper_Cif $cifHelper
2567
  */
2568
+ $cifHelper = $this->getHelper('cif');
2569
+ $allowedProductCodes = $this->getAllowedProductCodes();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2570
 
2571
  /**
2572
  * Check if the product code is allowed
2603
  /**
2604
  * Checks if a given product code is only allowed for a specific country
2605
  *
2606
+ * @param $code
2607
+ *
2608
  * @return boolean|array Either false if the code is not restricted, or otherwise an array of allowed country IDs
2609
  */
2610
  protected function _isCodeRestricted($code)
2611
  {
2612
+ /**
2613
+ * @var TIG_PostNL_Helper_Cif $helper
2614
+ */
2615
+ $helper = $this->getHelper('cif');
2616
+ $countryRestrictedCodes = $helper->getCountryRestrictedProductCodes();
2617
 
2618
  /**
2619
  * Check if the supplied code is restricted
2629
  return $allowedCountries;
2630
  }
2631
 
2632
+ /*******************************************************************************************************************
2633
  * ADDITIONAL SHIPMENT OPTIONS
2634
+ ******************************************************************************************************************/
2635
 
2636
  /**
2637
  * Public alias for _saveAdditionalShippingOptions()
2638
  *
2639
+ * @return $this
2640
  *
2641
  * @see TIG_PostNL_Model_Core_Shipment::_saveAdditionalShippingOptions()
2642
  */
2648
  /**
2649
  * Stores additionally selected shipping options
2650
  *
2651
+ * @return $this
2652
  */
2653
  protected function _saveAdditionalShippingOptions()
2654
  {
2665
  'postnl_shipment_saveadditionaloptions_after',
2666
  array(
2667
  'shipment' => $this,
2668
+ 'options' => $additionalOptions
2669
  )
2670
  );
2671
 
2694
  $weight = $this->getTotalWeight(true);
2695
 
2696
  /**
2697
+ * get the weight per parcel.
2698
+ *
2699
+ * @var TIG_PostNL_Helper_Cif $helper
2700
  */
2701
+ $helper = $this->getHelper('cif');
2702
+ $weightPerParcel = Mage::getStoreConfig(self::XPATH_WEIGHT_PER_PARCEL, $this->getStoreId());
2703
+ $weightPerParcel = $helper->standardizeWeight($weightPerParcel, $this->getStoreId());
2704
 
2705
  /**
2706
  * calculate the number of parcels needed to ship the total weight of this shipment
2710
  return $parcelCount;
2711
  }
2712
 
2713
+ /*******************************************************************************************************************
2714
  * RESET AND DELETE METHODS
2715
+ ******************************************************************************************************************/
2716
 
2717
  /**
2718
  * Resets this shipment to a pre-confirmed state
2730
  ->deleteBarcodes() //delete all associated barcodes
2731
  ->deleteStatusHistory(); //delete all associated status history items
2732
 
2733
+
2734
  if ($deleteLabels) {
2735
  $this->setlabelsPrinted(false) //labels have not been printed
2736
  ->deleteLabels(); //delete all associated labels
2737
  }
2738
 
2739
  if ($deleteTracks) {
2740
+ $this->deleteShipmentTracks() //delete ale addociated tracks
2741
+ ->setTrackAndTraceEmailSent(false); //make sure that a new T&T e-mail is sent
2742
  }
2743
 
2744
  return $this;
2767
  /**
2768
  * Removes all labels associated with this shipment
2769
  *
2770
+ * @return $this
2771
  */
2772
  public function deleteLabels()
2773
  {
2774
+ $labelCollection = $this->getLabelCollection();
 
2775
 
2776
  $labels = $labelCollection->getItems();
2777
 
2778
+ /**
2779
+ * @var TIG_PostNL_Model_Core_Shipment_Label $label
2780
+ */
2781
  foreach ($labels as $label) {
2782
+ $label->delete();
 
2783
  }
2784
 
2785
  return $this;
2788
  /**
2789
  * Removes all barcodes associated with this shipment
2790
  *
2791
+ * @return $this
2792
  */
2793
  public function deleteBarcodes()
2794
  {
2795
  $barcodes = $this->getBarcodes(true);
2796
 
2797
+ /**
2798
+ * @var TIG_PostNL_Model_Core_Shipment_Barcode $barcode
2799
+ */
2800
  foreach ($barcodes as $barcode) {
2801
+ $barcode->delete();
 
2802
  }
2803
 
2804
  $this->setMainBarcode(false);
2809
  /**
2810
  * Deletes all status history items associated with this shipment
2811
  *
2812
+ * @return $this
2813
  */
2814
  public function deleteStatusHistory()
2815
  {
2816
  $statusHistoryCollection = Mage::getResourceModel('postnl_core/shipment_status_history_collection');
2817
  $statusHistoryCollection->addFieldToFilter('parent_id', array('eq' => $this->getid()));
2818
 
2819
+ /**
2820
+ * @var TIG_PostNL_Model_Core_Shipment_Status_History $status
2821
+ */
2822
  foreach ($statusHistoryCollection as $status) {
2823
+ $status->delete();
 
2824
  }
2825
 
2826
  return $this;
2827
  }
2828
 
2829
+ /*******************************************************************************************************************
2830
  * BEFORE- AND AFTERSAVE METHODS
2831
+ ******************************************************************************************************************/
2832
 
2833
  /**
2834
  * Updates the shipment's attributes before saving this shipment
2837
  */
2838
  protected function _beforeSave()
2839
  {
2840
+ /**
2841
+ * @var Mage_Core_Model_Date $dateModel
2842
+ */
2843
+ $dateModel = Mage::getModel('core/date');
2844
+ $currentTimestamp = $dateModel->gmtTimestamp();
2845
 
2846
  /**
2847
+ * Store any shipment options that have been saved in the registry.
2848
  */
2849
  if (Mage::registry('postnl_additional_options')) {
2850
  $this->_saveAdditionalShippingOptions();
2851
  }
2852
 
2853
  /**
2854
+ * Set confirm status.
2855
  */
2856
  if ($this->getConfirmStatus() === null) {
2857
  $this->setConfirmStatus(self::CONFIRM_STATUS_UNCONFIRMED);
2858
  }
2859
 
2860
  /**
2861
+ * Set confrirmed at.
2862
  */
2863
  if ($this->getConfirmedStatus() == self::CONFIRM_STATUS_CONFIRMED
2864
  && $this->getConfirmedAt() === null
2867
  }
2868
 
2869
  /**
2870
+ * Set whether labels have printed or not.
2871
  */
2872
  if ($this->getlabelsPrinted() == 0 && $this->hasLabels()) {
2873
  $this->setLabelsPrinted(1);
2874
  }
2875
 
2876
  /**
2877
+ * Set a product code.
2878
  */
2879
  if (!$this->getProductCode() || Mage::registry('postnl_product_option') !== null) {
2880
  $productCode = $this->_getProductCode();
2882
  }
2883
 
2884
  /**
2885
+ * Set the parcel count.
2886
  */
2887
  if (!$this->getParcelCount()) {
2888
  $parcelCount = $this->_calculateParcelCount();
2890
  }
2891
 
2892
  /**
2893
+ * Set the confirm date.
2894
  */
2895
  if (!$this->getConfirmDate()) {
2896
+ $this->setConfirmDate();
2897
  }
2898
 
2899
  /**
2900
+ * If this shipment is new, set it's created at date to the current timestamp.
2901
  */
2902
  if (!$this->getId()) {
2903
  $this->setCreatedAt($currentTimestamp);
2904
  }
2905
 
2906
  /**
2907
+ * Always update the updated at timestamp to the current timestamp.
2908
  */
2909
  $this->setUpdatedAt($currentTimestamp);
2910
 
app/code/community/TIG/PostNL/Model/Core/Shipment/Barcode.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,8 +33,18 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
 
 
 
 
 
 
 
38
  */
39
  class TIG_PostNL_Model_Core_Shipment_Barcode extends Mage_Core_Model_Abstract
40
  {
@@ -44,28 +54,38 @@ class TIG_PostNL_Model_Core_Shipment_Barcode extends Mage_Core_Model_Abstract
44
  * @var string
45
  */
46
  protected $_eventPrefix = 'postnl_shipment_barcode';
47
-
48
  public function _construct()
49
  {
50
  $this->_init('postnl_core/shipment_barcode');
51
  }
52
-
53
  /**
54
  * Load a barcode object based on a postnl shipment Id and a barcode number
55
- *
 
 
 
56
  * @return TIG_PostNL_Model_Core_Shipment_Barcode
57
  */
58
  public function loadByParentAndBarcodeNumber($parentId, $barcodeNumber)
59
  {
 
 
 
60
  $collection = $this->getCollection();
61
  $collection->addFieldToSelect('*')
62
  ->addFieldToFilter('parent_id', array('eq' => $parentId))
63
  ->addFieldToFilter('barcode_number', array('eq' => $barcodeNumber));
64
-
65
  if ($collection->getSize()) {
66
- return $collection->getFirstItem();
 
 
 
 
67
  }
68
-
69
  return $this;
70
  }
71
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * Class TIG_PostNL_Model_Core_Shipment_Barcode@method getBarcode
40
+ *
41
+ * @method int getBarcodeNumber()
42
+ * @method TIG_PostNL_Model_Core_Shipment_Barcode setBarcodeNumber(int $value)
43
+ * @method int getBarcodeId()
44
+ * @method TIG_PostNL_Model_Core_Shipment_Barcode setBarcodeId(int $value)
45
+ * @method TIG_PostNL_Model_Core_Shipment_Barcode setBarcode(string $value)
46
+ * @method int getParentId()
47
+ * @method TIG_PostNL_Model_Core_Shipment_Barcode setParentId(int $value)
48
  */
49
  class TIG_PostNL_Model_Core_Shipment_Barcode extends Mage_Core_Model_Abstract
50
  {
54
  * @var string
55
  */
56
  protected $_eventPrefix = 'postnl_shipment_barcode';
57
+
58
  public function _construct()
59
  {
60
  $this->_init('postnl_core/shipment_barcode');
61
  }
62
+
63
  /**
64
  * Load a barcode object based on a postnl shipment Id and a barcode number
65
+ *
66
+ * @param $parentId
67
+ * @param $barcodeNumber
68
+ *
69
  * @return TIG_PostNL_Model_Core_Shipment_Barcode
70
  */
71
  public function loadByParentAndBarcodeNumber($parentId, $barcodeNumber)
72
  {
73
+ /**
74
+ * @var TIG_PostNL_Model_Core_Resource_Shipment_Barcode_Collection $collection
75
+ */
76
  $collection = $this->getCollection();
77
  $collection->addFieldToSelect('*')
78
  ->addFieldToFilter('parent_id', array('eq' => $parentId))
79
  ->addFieldToFilter('barcode_number', array('eq' => $barcodeNumber));
80
+
81
  if ($collection->getSize()) {
82
+ $barcode = $collection->getFirstItem();
83
+
84
+ $this->setData($barcode->getData());
85
+ $this->setOrigData();
86
+ $this->_afterLoad();
87
  }
88
+
89
  return $this;
90
  }
91
  }
app/code/community/TIG/PostNL/Model/Core/Shipment/Label.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -35,6 +35,16 @@
35
  *
36
  * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
 
 
 
 
 
 
 
38
  */
39
  class TIG_PostNL_Model_Core_Shipment_Label extends Mage_Core_Model_Abstract
40
  {
@@ -44,27 +54,27 @@ class TIG_PostNL_Model_Core_Shipment_Label extends Mage_Core_Model_Abstract
44
  * @var string
45
  */
46
  protected $_eventPrefix = 'postnl_shipment_label';
47
-
48
  public function _construct()
49
  {
50
  $this->_init('postnl_core/shipment_label');
51
  }
52
-
53
  /**
54
  * Alias for magic getLabelType()
55
- *
56
  * @return mixed
57
  */
58
  public function getType()
59
  {
60
  return $this->getLabelType();
61
  }
62
-
63
  /**
64
  * Gets label contents. Optional parameter to base64 decode the content
65
- *
66
  * @param boolean $decode
67
- *
68
  * @return string
69
  */
70
  public function getLabel($decode = false)
@@ -73,7 +83,7 @@ class TIG_PostNL_Model_Core_Shipment_Label extends Mage_Core_Model_Abstract
73
  if ($decode && $label) {
74
  $label = base64_decode($label);
75
  }
76
-
77
  return $label;
78
  }
79
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
35
  *
36
  * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * Class TIG_PostNL_Model_Core_Shipment_Label
40
+ *
41
+ * @method string getLabelType()
42
+ * @method TIG_PostNL_Model_Core_Shipment_Label setLabelType(string $value)
43
+ * @method int getLabelId()
44
+ * @method TIG_PostNL_Model_Core_Shipment_Label setLabelId(int $value)
45
+ * @method TIG_PostNL_Model_Core_Shipment_Label setLabel(string $value)
46
+ * @method int getParentId()
47
+ * @method TIG_PostNL_Model_Core_Shipment_Label setParentId(int $value)
48
  */
49
  class TIG_PostNL_Model_Core_Shipment_Label extends Mage_Core_Model_Abstract
50
  {
54
  * @var string
55
  */
56
  protected $_eventPrefix = 'postnl_shipment_label';
57
+
58
  public function _construct()
59
  {
60
  $this->_init('postnl_core/shipment_label');
61
  }
62
+
63
  /**
64
  * Alias for magic getLabelType()
65
+ *
66
  * @return mixed
67
  */
68
  public function getType()
69
  {
70
  return $this->getLabelType();
71
  }
72
+
73
  /**
74
  * Gets label contents. Optional parameter to base64 decode the content
75
+ *
76
  * @param boolean $decode
77
+ *
78
  * @return string
79
  */
80
  public function getLabel($decode = false)
83
  if ($decode && $label) {
84
  $label = base64_decode($label);
85
  }
86
+
87
  return $label;
88
  }
89
  }
app/code/community/TIG/PostNL/Model/Core/Shipment/Process.php CHANGED
@@ -33,26 +33,21 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
40
  {
41
- /**
42
- * Flag to dtermine if the process is locked
43
- *
44
- * @var null | boolean
45
- */
46
  protected $_isLocked = null;
47
 
48
  /**
49
  * Get lock file resource
50
  *
51
- * @param boolean $asFile
52
- *
53
  * @return resource | TIG_PostNL_Model_Core_Shipment_Process
54
  */
55
- protected function _getLockFile($asPath = false)
56
  {
57
  if ($this->_lockFile !== null) {
58
  return $this->_lockFile;
@@ -61,15 +56,19 @@ class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
61
  $varDir = Mage::getConfig()->getVarDir('locks');
62
  $file = $varDir . DS . 'postnl_process_' . $this->getId() . '.lock';
63
 
64
- $this->_lockFile = fopen($file, 'w');
65
-
66
- $timestamp = Mage::getModel('core/date')->gmtTimestamp();
67
- fwrite($this->_lockFile, date('r', $timestamp));
68
-
69
- if ($asPath === true) {
70
- return $file;
 
 
71
  }
72
 
 
 
73
  return $this->_lockFile;
74
  }
75
 
@@ -82,6 +81,7 @@ class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
82
  public function lock()
83
  {
84
  $this->_isLocked = true;
 
85
 
86
  flock($this->_getLockFile(), LOCK_EX | LOCK_NB);
87
 
@@ -96,7 +96,7 @@ class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
96
  public function lockAndBlock()
97
  {
98
  $this->_isLocked = true;
99
- $file = $this->_getLockFile();
100
 
101
  flock($this->_getLockFile(), LOCK_EX);
102
 
@@ -111,6 +111,8 @@ class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
111
  public function unlock()
112
  {
113
  $this->_isLocked = false;
 
 
114
  $file = $this->_getLockFile();
115
 
116
  flock($file, LOCK_UN);
@@ -137,23 +139,31 @@ class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
137
  return $this->_isLocked;
138
  }
139
 
140
- $fp = $this->_getLockFile();
141
- if (flock($fp, LOCK_EX | LOCK_NB)) {
142
- flock($fp, LOCK_UN);
 
 
 
 
 
 
 
 
 
143
  return false;
144
  }
145
- fclose($fp);
146
 
147
  //if the lock exists and exists for longer then 5minutes then remove lock & return false
148
  if($this->_lockIsExpired()){
149
- $varDir = Mage::getConfig()->getVarDir('locks');
150
- $lockFile = $varDir . DS . 'postnl_process_' . $this->getId() . '.lock';
151
  @unlink($lockFile);
 
152
 
153
- $this->_getLockFile();//create new lock file
154
  return false;
155
  }
156
 
 
 
157
  return true;
158
  }
159
 
@@ -162,34 +172,41 @@ class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
162
  *
163
  * @return bool
164
  */
165
- protected function _lockIsExpired()
166
- {
167
- $file = $this->_getLockFile(true);
168
 
169
  if(!is_file($file)){
170
- $fp = fopen($file, 'x');
171
- fwrite($fp, date('r'));
172
- fclose($fp);
173
  return false;
174
  }
175
 
176
- $fiveMinAgo = time() - 300;//300
 
177
  $contents = file_get_contents($file);
178
- $time = strtotime($contents);
 
179
 
180
- if($time <= $fiveMinAgo){
181
- $fp = fopen($file,'w');
182
- flock($fp, LOCK_UN);
183
- fclose($fp);
184
- @unlink($file);
185
  return true;
186
  }
187
 
188
  return false;
189
  }
190
 
 
 
 
 
 
191
  public function __destruct()
192
  {
 
 
 
 
 
 
193
 
 
194
  }
195
  }
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
40
  {
41
+ protected $_own = false;
42
+
 
 
 
43
  protected $_isLocked = null;
44
 
45
  /**
46
  * Get lock file resource
47
  *
 
 
48
  * @return resource | TIG_PostNL_Model_Core_Shipment_Process
49
  */
50
+ protected function _getLockFile()
51
  {
52
  if ($this->_lockFile !== null) {
53
  return $this->_lockFile;
56
  $varDir = Mage::getConfig()->getVarDir('locks');
57
  $file = $varDir . DS . 'postnl_process_' . $this->getId() . '.lock';
58
 
59
+ if (is_file($file)) {
60
+ if($this->_lockIsExpired()){
61
+ unlink($file);//remove file
62
+ $this->_lockFile = fopen($file, 'x');//create new lock file
63
+ }else{
64
+ $this->_lockFile = fopen($file, 'w');
65
+ }
66
+ } else {
67
+ $this->_lockFile = fopen($file, 'x');
68
  }
69
 
70
+ fwrite($this->_lockFile, date('r', Mage::getModel('core/date')->gmtTimestamp()));
71
+
72
  return $this->_lockFile;
73
  }
74
 
81
  public function lock()
82
  {
83
  $this->_isLocked = true;
84
+ $this->_own = true;
85
 
86
  flock($this->_getLockFile(), LOCK_EX | LOCK_NB);
87
 
96
  public function lockAndBlock()
97
  {
98
  $this->_isLocked = true;
99
+ $this->_getLockFile();
100
 
101
  flock($this->_getLockFile(), LOCK_EX);
102
 
111
  public function unlock()
112
  {
113
  $this->_isLocked = false;
114
+ $this->_own = false;
115
+
116
  $file = $this->_getLockFile();
117
 
118
  flock($file, LOCK_UN);
139
  return $this->_isLocked;
140
  }
141
 
142
+ if ($this->_own === true) {
143
+ $this->_isLocked = false;
144
+
145
+ return false;
146
+ }
147
+
148
+ $varDir = Mage::getConfig()->getVarDir('locks');
149
+ $lockFile = $varDir . DS . 'postnl_process_' . $this->getId() . '.lock';
150
+
151
+ if (!is_file($lockFile)) {
152
+ $this->_isLocked = false;
153
+
154
  return false;
155
  }
 
156
 
157
  //if the lock exists and exists for longer then 5minutes then remove lock & return false
158
  if($this->_lockIsExpired()){
 
 
159
  @unlink($lockFile);
160
+ $this->_isLocked = false;
161
 
 
162
  return false;
163
  }
164
 
165
+ $this->_isLocked = true;
166
+
167
  return true;
168
  }
169
 
172
  *
173
  * @return bool
174
  */
175
+ protected function _lockIsExpired(){
176
+ $varDir = Mage::getConfig()->getVarDir('locks');
177
+ $file = $varDir . DS . 'postnl_process_'.$this->getId().'.lock';
178
 
179
  if(!is_file($file)){
 
 
 
180
  return false;
181
  }
182
 
183
+ $fiveMinAgo = Mage::getModel('core/date')->gmtTimestamp();
184
+
185
  $contents = file_get_contents($file);
186
+ $lockTime = strtotime($contents);
187
+ $lockExpiration = $lockTime + 300; //300s = 5min
188
 
189
+ if($lockExpiration <= $fiveMinAgo){
 
 
 
 
190
  return true;
191
  }
192
 
193
  return false;
194
  }
195
 
196
+ /**
197
+ * Destroy the lock file if it still exists
198
+ *
199
+ * @return void
200
+ */
201
  public function __destruct()
202
  {
203
+ $varDir = Mage::getConfig()->getVarDir('locks');
204
+ $lockFile = $varDir . DS . 'postnl_process_' . $this->getId() . '.lock';
205
+
206
+ if (is_file($lockFile)) {
207
+ @unlink($lockFile);
208
+ }
209
 
210
+ return;
211
  }
212
  }
app/code/community/TIG/PostNL/Model/Core/Shipment/Status/History.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -35,6 +35,27 @@
35
  *
36
  * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  */
39
  class TIG_PostNL_Model_Core_Shipment_Status_History extends Mage_Core_Model_Abstract
40
  {
@@ -44,17 +65,17 @@ class TIG_PostNL_Model_Core_Shipment_Status_History extends Mage_Core_Model_Abst
44
  * @var string
45
  */
46
  protected $_eventPrefix = 'postnl_shipment_status_history';
47
-
48
  public function _construct()
49
  {
50
  $this->_init('postnl_core/shipment_status_history');
51
  }
52
-
53
  /**
54
  * Set the 'phase' attribute. The phase must be formatted as a 2 digit number (i.e. 01, 04, 12, 99 etc.)
55
- *
56
  * @param string | int $phase
57
- *
58
  * @return TIG_PostNL_Model_Core_Shipment_Status_History
59
  */
60
  public function setPhase($phase)
@@ -62,72 +83,78 @@ class TIG_PostNL_Model_Core_Shipment_Status_History extends Mage_Core_Model_Abst
62
  if (strlen($phase) < 2) {
63
  $phase = '0' . $phase;
64
  }
65
-
66
  $this->setData('phase', $phase);
67
  return $this;
68
  }
69
-
70
  /**
71
  * Load a history item based on a postnl shipment id and a status code.
72
- *
73
  * @param int $shipmentId
74
  * @param string $code
75
- *
76
  * @return TIG_PostNL_Model_Core_Shipment_Status_History
77
  */
78
  public function loadByShipmentIdAndCode($shipmentId, $code)
79
  {
 
 
 
80
  $collection = $this->getCollection();
81
  $collection->addFieldToSelect('status_id')
82
  ->addFieldToFilter('parent_id', array('eq' => $shipmentId))
83
  ->addFieldToFilter('code', array('eq' => $code));
84
-
85
  $collection->getSelect()->limit(1); //we only want 1 item
86
-
87
  $id = $collection->getFirstItem()->getId();
88
-
89
  if ($id) {
90
  $this->load($id);
91
  }
92
-
93
  return $this;
94
  }
95
-
96
  /**
97
  * Check if a status history item exists for the given postnl shipment and status
98
- *
99
  * @param int $shipmentId
100
- * @param StdClass $code
101
- *
102
  * @return boolean
103
  */
104
  public function statusHistoryIsNew($shipmentId, $status)
105
  {
 
 
 
106
  $collection = $this->getCollection();
107
  $collection->addFieldToSelect('status_id')
108
  ->addFieldToFilter('parent_id', array('eq' => $shipmentId))
109
  ->addFieldToFilter('code', array('eq' => $status->Code));
110
-
111
  if ($status->LocationCode !== '') {
112
  $collection->addFieldToFilter('location_code', array('eq' => $status->LocationCode));
113
  }
114
-
115
  if ($status->DestinationLocationCode !== '') {
116
  $collection->addFieldToFilter('destination_location_code', array('eq' => $status->DestinationLocationCode));
117
  }
118
-
119
  if ($status->RouteCode !== '') {
120
  $collection->addFieldToFilter('route_code', array('eq' => $status->RouteCode));
121
  }
122
-
123
  if ($status->RouteName !== '') {
124
  $collection->addFieldToFilter('route_name', array('eq' => $status->RouteName));
125
  }
126
-
127
  if ($collection->getSize() < 1) {
128
  return true;
129
  }
130
-
131
  return false;
132
  }
133
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
35
  *
36
  * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * Class TIG_PostNL_Model_Core_Shipment_Status_History
40
+ *
41
+ * @method string getTimestamp()
42
+ * @method TIG_PostNL_Model_Core_Shipment_Status_History setTimestamp(string $value)
43
+ * @method string getRouteName()
44
+ * @method TIG_PostNL_Model_Core_Shipment_Status_History setRouteName(string $value)
45
+ * @method string getDescription()
46
+ * @method TIG_PostNL_Model_Core_Shipment_Status_History setDescription(string $value)
47
+ * @method string getLocationCode()
48
+ * @method TIG_PostNL_Model_Core_Shipment_Status_History setLocationCode(string $value)
49
+ * @method int getStatusId()
50
+ * @method TIG_PostNL_Model_Core_Shipment_Status_History setStatusId(int $value)
51
+ * @method string getCode()
52
+ * @method TIG_PostNL_Model_Core_Shipment_Status_History setCode(string $value)
53
+ * @method string getDestinationLocationCode()
54
+ * @method TIG_PostNL_Model_Core_Shipment_Status_History setDestinationLocationCode(string $value)
55
+ * @method string getRouteCode()
56
+ * @method TIG_PostNL_Model_Core_Shipment_Status_History setRouteCode(string $value)
57
+ * @method int getParentId()
58
+ * @method TIG_PostNL_Model_Core_Shipment_Status_History setParentId(int $value)
59
  */
60
  class TIG_PostNL_Model_Core_Shipment_Status_History extends Mage_Core_Model_Abstract
61
  {
65
  * @var string
66
  */
67
  protected $_eventPrefix = 'postnl_shipment_status_history';
68
+
69
  public function _construct()
70
  {
71
  $this->_init('postnl_core/shipment_status_history');
72
  }
73
+
74
  /**
75
  * Set the 'phase' attribute. The phase must be formatted as a 2 digit number (i.e. 01, 04, 12, 99 etc.)
76
+ *
77
  * @param string | int $phase
78
+ *
79
  * @return TIG_PostNL_Model_Core_Shipment_Status_History
80
  */
81
  public function setPhase($phase)
83
  if (strlen($phase) < 2) {
84
  $phase = '0' . $phase;
85
  }
86
+
87
  $this->setData('phase', $phase);
88
  return $this;
89
  }
90
+
91
  /**
92
  * Load a history item based on a postnl shipment id and a status code.
93
+ *
94
  * @param int $shipmentId
95
  * @param string $code
96
+ *
97
  * @return TIG_PostNL_Model_Core_Shipment_Status_History
98
  */
99
  public function loadByShipmentIdAndCode($shipmentId, $code)
100
  {
101
+ /**
102
+ * @var TIG_PostNL_Model_Core_Resource_Shipment_Status_History_Collection $collection
103
+ */
104
  $collection = $this->getCollection();
105
  $collection->addFieldToSelect('status_id')
106
  ->addFieldToFilter('parent_id', array('eq' => $shipmentId))
107
  ->addFieldToFilter('code', array('eq' => $code));
108
+
109
  $collection->getSelect()->limit(1); //we only want 1 item
110
+
111
  $id = $collection->getFirstItem()->getId();
112
+
113
  if ($id) {
114
  $this->load($id);
115
  }
116
+
117
  return $this;
118
  }
119
+
120
  /**
121
  * Check if a status history item exists for the given postnl shipment and status
122
+ *
123
  * @param int $shipmentId
124
+ * @param $status
125
+ *
126
  * @return boolean
127
  */
128
  public function statusHistoryIsNew($shipmentId, $status)
129
  {
130
+ /**
131
+ * @var TIG_PostNL_Model_Core_Resource_Shipment_Status_History_Collection $collection
132
+ */
133
  $collection = $this->getCollection();
134
  $collection->addFieldToSelect('status_id')
135
  ->addFieldToFilter('parent_id', array('eq' => $shipmentId))
136
  ->addFieldToFilter('code', array('eq' => $status->Code));
137
+
138
  if ($status->LocationCode !== '') {
139
  $collection->addFieldToFilter('location_code', array('eq' => $status->LocationCode));
140
  }
141
+
142
  if ($status->DestinationLocationCode !== '') {
143
  $collection->addFieldToFilter('destination_location_code', array('eq' => $status->DestinationLocationCode));
144
  }
145
+
146
  if ($status->RouteCode !== '') {
147
  $collection->addFieldToFilter('route_code', array('eq' => $status->RouteCode));
148
  }
149
+
150
  if ($status->RouteName !== '') {
151
  $collection->addFieldToFilter('route_name', array('eq' => $status->RouteName));
152
  }
153
+
154
  if ($collection->getSize() < 1) {
155
  return true;
156
  }
157
+
158
  return false;
159
  }
160
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/ValidateDefaultOption.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method boolean hasIsIncludingTax()
40
+ * @method TIG_PostNL_Model_DeliveryOptions_System_Config_Backend_ValidateFee setIsIncludingTax(boolean $value)
41
+ * @method boolean hasMockShippingAddress()
42
+ * @method TIG_PostNL_Model_DeliveryOptions_System_Config_Backend_ValidateFee setMockShippingAddress(Mage_Customer_Model_Address $value)
43
+ */
44
+ class TIG_PostNL_Model_Core_System_Config_Backend_ValidateDefaultOption extends Mage_Core_Model_Config_Data
45
+ {
46
+ /**
47
+ * Xpath to supported options configuration setting
48
+ */
49
+ const XPATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
50
+
51
+ /**
52
+ * Validate that a chosen default option is actually available.
53
+ *
54
+ * @param $value
55
+ *
56
+ * @return bool
57
+ *
58
+ * @throws TIG_PostNL_Exception
59
+ */
60
+ public function validateDefaultOption($value)
61
+ {
62
+ /**
63
+ * Get a list of supported options.
64
+ */
65
+ $postData = Mage::app()->getRequest()->getPost();
66
+ if (isset($postData['groups']['cif_product_options']['fields']['supported_product_options']['value'])) {
67
+ $options = $postData['groups']['cif_product_options']['fields']['supported_product_options']['value'];
68
+ } else {
69
+ $options = Mage::getStoreConfig(self::XPATH_SUPPORTED_PRODUCT_OPTIONS, Mage_Core_Model_App::ADMIN_STORE_ID);
70
+ $options = explode(',', $options);
71
+ }
72
+
73
+ /**
74
+ * Check if the current field's value is among them.
75
+ */
76
+ if (in_array($value, $options)) {
77
+ return true;
78
+ }
79
+
80
+ $helper = Mage::helper('postnl');
81
+
82
+ /**
83
+ * Get the system.xml configuration.
84
+ */
85
+ $configFields = Mage::getSingleton('adminhtml/config');
86
+ $sections = $configFields->getSections('postnl');
87
+
88
+ /**
89
+ * Get the path of the current field split into parts.
90
+ */
91
+ $path = $this->getPath();
92
+ $pathParts = explode('/', $path);
93
+
94
+ /**
95
+ * Search for the label of the current field and translate it.
96
+ */
97
+ $label = $sections->$pathParts[0]->groups->$pathParts[1]->fields->$pathParts[2]->label;
98
+ $label = $helper->__($label);
99
+
100
+ /**
101
+ * Get the translated label of the supported options field.
102
+ */
103
+ $supportedOptionsLabel =(string) $sections->postnl
104
+ ->groups
105
+ ->cif_product_options
106
+ ->fields
107
+ ->supported_product_options
108
+ ->label;
109
+ $supportedOptionsLabel = $helper->__($supportedOptionsLabel);
110
+
111
+ /**
112
+ * Format the warning message.
113
+ */
114
+ $message = $helper->__(
115
+ "You have chosen a value for the '%s' field that is not supported. Please select a option that you have " .
116
+ "selected in the '%s' field, otherwise you may not be able to send shipments of this type.",
117
+ $label,
118
+ $supportedOptionsLabel
119
+ );
120
+
121
+ /**
122
+ * Add the warning.
123
+ */
124
+ $helper->addSessionMessage(
125
+ 'adminhtml',
126
+ 'POSTNL-0159',
127
+ 'warning',
128
+ $message
129
+ );
130
+
131
+ /**
132
+ * Set this field's value to null, as it's selected option is invalid.
133
+ */
134
+ $this->setValue(null);
135
+
136
+ return true;
137
+ }
138
+
139
+ /**
140
+ * @return Mage_Core_Model_Abstract
141
+ */
142
+ protected function _beforeSave()
143
+ {
144
+ $value = $this->getValue();
145
+
146
+ if ($value) {
147
+ $this->validateDefaultOption($value);
148
+ }
149
+
150
+ return parent::_beforeSave();
151
+ }
152
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/AllProductOptions.php CHANGED
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
@@ -46,11 +46,13 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
46
  /**
47
  * Returns an option array for all possible PostNL product options
48
  *
 
 
49
  * @return array
50
  *
51
  * @todo implement COD
52
  */
53
- public function toOptionArray()
54
  {
55
  $helper = Mage::helper('postnl');
56
  $availableOptions = array(
@@ -67,58 +69,71 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
67
  * @todo implement these options
68
  */
69
  /*'3086' => array(
70
- 'value' => '3086',
71
- 'label' => $helper->__('COD'),
 
72
  ),
73
  '3091' => array(
74
- 'value' => '3091',
75
- 'label' => $helper->__('COD + Extra cover'),
 
76
  ),
77
  '3093' => array(
78
- 'value' => '3093',
79
- 'label' => $helper->__('COD + Return when not home'),
 
80
  ),
81
  '3097' => array(
82
- 'value' => '3097',
83
- 'label' => $helper->__('COD + Extra cover + Return when not home'),
 
84
  ),*/
85
  '3087' => array(
86
  'value' => '3087',
87
  'label' => $helper->__('Extra Cover'),
88
  'isExtraCover' => true,
 
89
  ),
90
  '3094' => array(
91
  'value' => '3094',
92
  'label' => $helper->__('Extra cover + Return when not home'),
93
  'isExtraCover' => true,
 
94
  ),
95
  '3189' => array(
96
  'value' => '3189',
97
  'label' => $helper->__('Signature on delivery'),
98
  ),
99
  '3089' => array(
100
- 'value' => '3089',
101
- 'label' => $helper->__('Signature on delivery + Delivery to stated address only'),
 
102
  ),
103
  '3389' => array(
104
  'value' => '3389',
105
  'label' => $helper->__('Signature on delivery + Return when not home'),
106
  ),
107
  '3096' => array(
108
- 'value' => '3096',
109
- 'label' => $helper->__('Signature on delivery + Deliver to stated address only + Return when not home'),
 
 
 
110
  ),
111
  '3090' => array(
112
- 'value' => '3090',
113
- 'label' => $helper->__('Delivery to neighbour + Return when not home'),
 
114
  ),
115
  '3385' => array(
116
- 'value' => '3385',
117
- 'label' => $helper->__('Deliver to stated address only'),
 
118
  ),
119
  '3390' => array(
120
- 'value' => '3390',
121
- 'label' => $helper->__('Deliver to stated address only + Return when not home'),
 
122
  ),
123
  ),
124
  ),
@@ -132,19 +147,22 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
132
  */
133
  /*'3535' => array(
134
  'value' => '3535',
135
- 'label' => $helper->__('Post Office + COD')
136
  ),
137
  '3545' => array(
138
  'value' => '3545',
139
- 'label' => $helper->__('Post Office + COD + Notification')
 
140
  ),
141
  '3536' => array(
142
  'value' => '3536',
143
- 'label' => $helper->__('Post Office + COD + Extra Cover')
 
144
  ),
145
  '3546' => array(
146
  'value' => '3546',
147
- 'label' => $helper->__('Post Office + COD + Extra Cover + Notification')
 
148
  ),*/
149
  '3534' => array(
150
  'value' => '3534',
@@ -155,14 +173,16 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
155
  'value' => '3544',
156
  'label' => $helper->__('Post Office + Extra Cover + Notification'),
157
  'isExtraCover' => true,
 
158
  ),
159
  '3533' => array(
160
  'value' => '3533',
161
- 'label' => $helper->__('Post Office + Signature on Delivery')
162
  ),
163
  '3543' => array(
164
  'value' => '3543',
165
- 'label' => $helper->__('Post Office + Signature on Delivery + Notification')
 
166
  ),
167
  ),
168
  ),
@@ -178,8 +198,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
178
  *
179
  * @deprecated v1.1.2
180
  */
181
- /*
182
- '4955' => array(
183
  'value' => '4955',
184
  'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
185
  'isBelgiumOnly' => true,
@@ -206,6 +225,16 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
206
  'value' => '4945',
207
  'label' => $helper->__('GlobalPack'),
208
  'isExtraCover' => true,
 
 
 
 
 
 
 
 
 
 
209
  ),
210
  ),
211
  ),
@@ -219,23 +248,32 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
219
  );
220
  }
221
 
222
- $this->_markDefault($availableOptions);
223
-
224
  return $availableOptions;
225
  }
226
 
227
  /**
228
  * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
229
  *
230
- * @param boolean $withDefault Determines whether or not a 'default' option is prepended to the array
231
  * @param bool $withExtraCover
232
  * @param boolean|int $storeId
233
- * @param boolean $codesOnly
 
 
 
 
 
234
  *
235
  * @return array
236
  */
237
- public function getAvailableOptions($withDefault = false, $withExtraCover = true, $storeId = false, $codesOnly = false)
238
- {
 
 
 
 
 
 
239
  if ($storeId === false) {
240
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
241
  }
@@ -243,7 +281,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
243
  $helper = Mage::helper('postnl');
244
  $canUseEpsBEOnly = $helper->canUseEpsBEOnlyOption();
245
 
246
- $options = $this->toOptionArray();
247
 
248
  /**
249
  * Get a list of all possible options
@@ -269,10 +307,19 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
269
  $supportedOptionsArray[] = '4955';
270
  }
271
 
 
 
 
 
 
 
 
 
 
 
272
  /**
273
  * Check each standard option to see if it's supprted
274
  */
275
- $availableStandardOptions = array();
276
  foreach ($options['standard_options']['value'] as $option) {
277
  if (!in_array($option['value'], $supportedOptionsArray)) {
278
  continue;
@@ -287,13 +334,21 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
287
  continue;
288
  }
289
 
 
 
 
 
 
 
 
 
 
290
  $availableStandardOptions[] = $option;
291
  }
292
 
293
  /**
294
  * Check each pakje gemak option to see if it's supprted
295
  */
296
- $availablePakjeGemakOptions = array();
297
  foreach ($options['pakjegemak_options']['value'] as $option) {
298
  if (!in_array($option['value'], $supportedOptionsArray)) {
299
  continue;
@@ -308,13 +363,21 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
308
  continue;
309
  }
310
 
 
 
 
 
 
 
 
 
 
311
  $availablePakjeGemakOptions[] = $option;
312
  }
313
 
314
  /**
315
  * Check each eu option to see if it's supprted
316
  */
317
- $availableEuOptions = array();
318
  foreach ($options['eu_options']['value'] as $option) {
319
  if (!in_array($option['value'], $supportedOptionsArray)) {
320
  continue;
@@ -329,13 +392,17 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
329
  continue;
330
  }
331
 
 
 
 
 
 
332
  $availableEuOptions[] = $option;
333
  }
334
 
335
  /**
336
- * Check each eu option to see if it's supprted
337
  */
338
- $availableGlobalOptions = array();
339
  if ($helper->isGlobalAllowed()) {
340
  foreach ($options['global_options']['value'] as $option) {
341
  if (!in_array($option['value'], $supportedOptionsArray)) {
@@ -351,15 +418,48 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
351
  continue;
352
  }
353
 
 
 
 
 
 
354
  $availableGlobalOptions[] = $option;
355
  }
356
  }
357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  /**
359
  * If we only need the codes, we can return the $availableOptions array. Otherwise, we need to order and merge the
360
  * other arrays
361
  */
362
- if ($codesOnly === true) {
363
  return $availableOptions;
364
  }
365
 
@@ -394,12 +494,33 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
394
  );
395
  }
396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  return $availableOptions;
398
  }
399
 
400
  /**
401
  * Get the list of available product options that have extra cover
402
  *
 
 
403
  * @return array
404
  */
405
  public function getExtraCoverOptions($valuesOnly = false)
@@ -465,32 +586,25 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
465
  /**
466
  * Mark each default option as default if it is present in the available options array
467
  */
468
- if (isset($options['standard_options'])
469
- && isset($options['standard_options']['value'])
470
- && isset($options['standard_options']['value'][$defaultOptions['dutch']])
471
- ) {
472
- $options['standard_options']['value'][$defaultOptions['dutch']]['label'] .= ' ' . $helper->__('(default)');
 
 
473
  }
474
 
475
- if (isset($options['pakjegemak_options'])
476
- && isset($options['pakjegemak_options']['value'])
477
- && isset($options['pakjegemak_options']['value'][$defaultOptions['eu']])
478
- ) {
479
- $options['pakjegemak_options']['value'][$defaultOptions['pakjegemak']]['label'] .= ' ' . $helper->__('(default)');
480
  }
481
 
482
- if (isset($options['eu_options'])
483
- && isset($options['eu_options']['value'])
484
- && isset($options['eu_options']['value'][$defaultOptions['eu']])
485
- ) {
486
- $options['eu_options']['value'][$defaultOptions['eu']]['label'] .= ' ' . $helper->__('(default)');
487
  }
488
 
489
- if (isset($options['global_options'])
490
- && isset($options['global_options']['value'])
491
- && isset($options['global_options']['value'][$defaultOptions['global']])
492
- ) {
493
- $options['global_options']['value'][$defaultOptions['global']]['label'] .= ' ' . $helper->__('(default)');
494
  }
495
 
496
  return $options;
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
46
  /**
47
  * Returns an option array for all possible PostNL product options
48
  *
49
+ * @param boolean $markDefault Flag that determines whether default options will be marked as such.
50
+ *
51
  * @return array
52
  *
53
  * @todo implement COD
54
  */
55
+ public function toOptionArray($markDefault = true)
56
  {
57
  $helper = Mage::helper('postnl');
58
  $availableOptions = array(
69
  * @todo implement these options
70
  */
71
  /*'3086' => array(
72
+ 'value' => '3086',
73
+ 'label' => $helper->__('COD'),
74
+ 'isAvond' => true,
75
  ),
76
  '3091' => array(
77
+ 'value' => '3091',
78
+ 'label' => $helper->__('COD + Extra cover'),
79
+ 'isAvond' => true,
80
  ),
81
  '3093' => array(
82
+ 'value' => '3093',
83
+ 'label' => $helper->__('COD + Return when not home'),
84
+ 'isAvond' => true,
85
  ),
86
  '3097' => array(
87
+ 'value' => '3097',
88
+ 'label' => $helper->__('COD + Extra cover + Return when not home'),
89
+ 'isAvond' => true,
90
  ),*/
91
  '3087' => array(
92
  'value' => '3087',
93
  'label' => $helper->__('Extra Cover'),
94
  'isExtraCover' => true,
95
+ 'isAvond' => true,
96
  ),
97
  '3094' => array(
98
  'value' => '3094',
99
  'label' => $helper->__('Extra cover + Return when not home'),
100
  'isExtraCover' => true,
101
+ 'isAvond' => true,
102
  ),
103
  '3189' => array(
104
  'value' => '3189',
105
  'label' => $helper->__('Signature on delivery'),
106
  ),
107
  '3089' => array(
108
+ 'value' => '3089',
109
+ 'label' => $helper->__('Signature on delivery + Delivery to stated address only'),
110
+ 'isAvond' => true,
111
  ),
112
  '3389' => array(
113
  'value' => '3389',
114
  'label' => $helper->__('Signature on delivery + Return when not home'),
115
  ),
116
  '3096' => array(
117
+ 'value' => '3096',
118
+ 'label' => $helper->__(
119
+ 'Signature on delivery + Deliver to stated address only + Return when not home'
120
+ ),
121
+ 'isAvond' => true,
122
  ),
123
  '3090' => array(
124
+ 'value' => '3090',
125
+ 'label' => $helper->__('Delivery to neighbour + Return when not home'),
126
+ 'isAvond' => true,
127
  ),
128
  '3385' => array(
129
+ 'value' => '3385',
130
+ 'label' => $helper->__('Deliver to stated address only'),
131
+ 'isAvond' => true,
132
  ),
133
  '3390' => array(
134
+ 'value' => '3390',
135
+ 'label' => $helper->__('Deliver to stated address only + Return when not home'),
136
+ 'isAvond' => true,
137
  ),
138
  ),
139
  ),
147
  */
148
  /*'3535' => array(
149
  'value' => '3535',
150
+ 'label' => $helper->__('Post Office + COD'),
151
  ),
152
  '3545' => array(
153
  'value' => '3545',
154
+ 'label' => $helper->__('Post Office + COD + Notification'),
155
+ 'isPge' => true,
156
  ),
157
  '3536' => array(
158
  'value' => '3536',
159
+ 'label' => $helper->__('Post Office + COD + Extra Cover'),
160
+ 'isPge' => true,
161
  ),
162
  '3546' => array(
163
  'value' => '3546',
164
+ 'label' => $helper->__('Post Office + COD + Extra Cover + Notification'),
165
+ 'isPge' => true,
166
  ),*/
167
  '3534' => array(
168
  'value' => '3534',
173
  'value' => '3544',
174
  'label' => $helper->__('Post Office + Extra Cover + Notification'),
175
  'isExtraCover' => true,
176
+ 'isPge' => true,
177
  ),
178
  '3533' => array(
179
  'value' => '3533',
180
+ 'label' => $helper->__('Post Office + Signature on Delivery'),
181
  ),
182
  '3543' => array(
183
  'value' => '3543',
184
+ 'label' => $helper->__('Post Office + Signature on Delivery + Notification'),
185
+ 'isPge' => true,
186
  ),
187
  ),
188
  ),
198
  *
199
  * @deprecated v1.1.2
200
  */
201
+ /*'4955' => array(
 
202
  'value' => '4955',
203
  'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
204
  'isBelgiumOnly' => true,
225
  'value' => '4945',
226
  'label' => $helper->__('GlobalPack'),
227
  'isExtraCover' => true,
228
+ 'extraCover' => 200,
229
+ ),
230
+ ),
231
+ ),
232
+ 'pakketautomaat' => array(
233
+ 'label' => $helper->__('Parcel Dispenser options'),
234
+ 'value' => array(
235
+ '3553' => array(
236
+ 'value' => '3553',
237
+ 'label' => $helper->__('Parcel Dispenser'),
238
  ),
239
  ),
240
  ),
248
  );
249
  }
250
 
 
 
251
  return $availableOptions;
252
  }
253
 
254
  /**
255
  * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
256
  *
257
+ * @param boolean $withDefault Determines whether or not a 'default' option is prepended to the array
258
  * @param bool $withExtraCover
259
  * @param boolean|int $storeId
260
+ * @param boolean $codesOnly Flag that dtermines whether to only return the product codes and not the
261
+ * labels
262
+ * @param boolean $flat FLag that dtermines whether to return a flat 'code => label' array
263
+ * @param boolean $markDefault Flag that determines whether default options will be marked as such.
264
+ * @param boolean $addDeliveryOptions If set to true, additional options will be added for evening delivery and
265
+ * early pickup shipment types.
266
  *
267
  * @return array
268
  */
269
+ public function getAvailableOptions($withDefault = false,
270
+ $withExtraCover = true,
271
+ $storeId = false,
272
+ $codesOnly = false,
273
+ $flat = false,
274
+ $markDefault = true,
275
+ $addDeliveryOptions = false
276
+ ) {
277
  if ($storeId === false) {
278
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
279
  }
281
  $helper = Mage::helper('postnl');
282
  $canUseEpsBEOnly = $helper->canUseEpsBEOnlyOption();
283
 
284
+ $options = $this->toOptionArray($markDefault);
285
 
286
  /**
287
  * Get a list of all possible options
307
  $supportedOptionsArray[] = '4955';
308
  }
309
 
310
+ /**
311
+ * Initialize empty arrays for each supported shipment type. These will be filled with available options.
312
+ */
313
+ $availableStandardOptions = array();
314
+ $availableAvondOptions = array();
315
+ $availablePakjeGemakOptions = array();
316
+ $availablePgeOptions = array();
317
+ $availableEuOptions = array();
318
+ $availableGlobalOptions = array();
319
+
320
  /**
321
  * Check each standard option to see if it's supprted
322
  */
 
323
  foreach ($options['standard_options']['value'] as $option) {
324
  if (!in_array($option['value'], $supportedOptionsArray)) {
325
  continue;
334
  continue;
335
  }
336
 
337
+ if ($flat === true) {
338
+ $availableOptions[$option['value']] = $option['label'];
339
+ continue;
340
+ }
341
+
342
+ if (isset($option['isAvond']) && $option['isAvond']) {
343
+ $availableAvondOptions[] = $option;
344
+ }
345
+
346
  $availableStandardOptions[] = $option;
347
  }
348
 
349
  /**
350
  * Check each pakje gemak option to see if it's supprted
351
  */
 
352
  foreach ($options['pakjegemak_options']['value'] as $option) {
353
  if (!in_array($option['value'], $supportedOptionsArray)) {
354
  continue;
363
  continue;
364
  }
365
 
366
+ if ($flat === true) {
367
+ $availableOptions[$option['value']] = $option['label'];
368
+ continue;
369
+ }
370
+
371
+ if (isset($option['isPge']) && $option['isPge']) {
372
+ $availablePgeOptions[] = $option;
373
+ }
374
+
375
  $availablePakjeGemakOptions[] = $option;
376
  }
377
 
378
  /**
379
  * Check each eu option to see if it's supprted
380
  */
 
381
  foreach ($options['eu_options']['value'] as $option) {
382
  if (!in_array($option['value'], $supportedOptionsArray)) {
383
  continue;
392
  continue;
393
  }
394
 
395
+ if ($flat === true) {
396
+ $availableOptions[$option['value']] = $option['label'];
397
+ continue;
398
+ }
399
+
400
  $availableEuOptions[] = $option;
401
  }
402
 
403
  /**
404
+ * Check each global option to see if it's supprted
405
  */
 
406
  if ($helper->isGlobalAllowed()) {
407
  foreach ($options['global_options']['value'] as $option) {
408
  if (!in_array($option['value'], $supportedOptionsArray)) {
418
  continue;
419
  }
420
 
421
+ if ($flat === true) {
422
+ $availableOptions[$option['value']] = $option['label'];
423
+ continue;
424
+ }
425
+
426
  $availableGlobalOptions[] = $option;
427
  }
428
  }
429
 
430
+ /**
431
+ * Check each pakketautomaat option to see if it's supprted
432
+ */
433
+ $availablePakketautomaatOptions = array();
434
+ if ($helper->isGlobalAllowed()) {
435
+ foreach ($options['pakketautomaat']['value'] as $option) {
436
+ if (!in_array($option['value'], $supportedOptionsArray)) {
437
+ continue;
438
+ }
439
+
440
+ if (isset($option['isExtraCover']) && $withExtraCover !== true) {
441
+ continue;
442
+ }
443
+
444
+ if ($codesOnly === true) {
445
+ $availableOptions[] = $option['value'];
446
+ continue;
447
+ }
448
+
449
+ if ($flat === true) {
450
+ $availableOptions[$option['value']] = $option['label'];
451
+ continue;
452
+ }
453
+
454
+ $availablePakketautomaatOptions[] = $option;
455
+ }
456
+ }
457
+
458
  /**
459
  * If we only need the codes, we can return the $availableOptions array. Otherwise, we need to order and merge the
460
  * other arrays
461
  */
462
+ if ($codesOnly === true || $flat === true) {
463
  return $availableOptions;
464
  }
465
 
494
  );
495
  }
496
 
497
+ if (!empty($availablePakketautomaatOptions)) {
498
+ $availableOptions['pakketautomaat_option'] = array(
499
+ 'label' => $helper->__('Parcel Dispenser options'),
500
+ 'value' => $availablePakketautomaatOptions,
501
+ );
502
+ }
503
+
504
+ if ($addDeliveryOptions) {
505
+ $availableOptions['avond_options'] = array(
506
+ 'label' => $helper->__('Evening Delivery options'),
507
+ 'value' => $availableAvondOptions,
508
+ );
509
+
510
+ $availableOptions['pge_options'] = array(
511
+ 'label' => $helper->__('Early Pickup options'),
512
+ 'value' => $availablePgeOptions,
513
+ );
514
+ }
515
+
516
  return $availableOptions;
517
  }
518
 
519
  /**
520
  * Get the list of available product options that have extra cover
521
  *
522
+ * @param bool $valuesOnly
523
+ *
524
  * @return array
525
  */
526
  public function getExtraCoverOptions($valuesOnly = false)
586
  /**
587
  * Mark each default option as default if it is present in the available options array
588
  */
589
+ $defaultText = ' ' . $helper->__('(default)');
590
+ if (isset($options['standard_options']['value'][$defaultOptions['dutch']])) {
591
+ $options['standard_options']['value'][$defaultOptions['dutch']]['label'] .= $defaultText;
592
+ }
593
+
594
+ if (isset($options['pakjegemak_options']['value'][$defaultOptions['eu']])) {
595
+ $options['pakjegemak_options']['value'][$defaultOptions['pakjegemak']]['label'] .= $defaultText;
596
  }
597
 
598
+ if (isset($options['eu_options']['value'][$defaultOptions['eu']])) {
599
+ $options['eu_options']['value'][$defaultOptions['eu']]['label'] .= $defaultText;
 
 
 
600
  }
601
 
602
+ if (isset($options['global_options']['value'][$defaultOptions['global']])) {
603
+ $options['global_options']['value'][$defaultOptions['global']]['label'] .= $defaultText;
 
 
 
604
  }
605
 
606
+ if (isset($options['pakketautomaat_options']['value'][$defaultOptions['pakketautomaat']])) {
607
+ $options['pakketautomaat_options']['value'][$defaultOptions['pakketautomaat']]['label'] .= $defaultText;
 
 
 
608
  }
609
 
610
  return $options;
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/Attributes.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,35 +33,39 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_Attributes
40
  {
41
  /**
42
  * Get an option array of all product attributes available
43
- *
44
  * @return array
45
  */
46
  public function toOptionArray()
47
  {
48
  $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
49
  ->addFieldToFilter('frontend_label', array('notnull' => true));
50
-
51
  $attributes->getSelect()->order('frontend_label ASC');
52
-
 
 
 
 
53
  foreach ($attributes as $attribute) {
54
  $label = $attribute->getFrontendLabel();
55
  if (empty($label)) {
56
  continue;
57
  }
58
-
59
  $options[] = array(
60
  'label' => $label,
61
  'value' => $attribute->getAttributeCode()
62
  );
63
  }
64
-
65
  return $options;
66
  }
67
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_Attributes
40
  {
41
  /**
42
  * Get an option array of all product attributes available
43
+ *
44
  * @return array
45
  */
46
  public function toOptionArray()
47
  {
48
  $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
49
  ->addFieldToFilter('frontend_label', array('notnull' => true));
50
+
51
  $attributes->getSelect()->order('frontend_label ASC');
52
+
53
+ $options = array();
54
+ /**
55
+ * @var Mage_Catalog_Model_Entity_Attribute $attribute
56
+ */
57
  foreach ($attributes as $attribute) {
58
  $label = $attribute->getFrontendLabel();
59
  if (empty($label)) {
60
  continue;
61
  }
62
+
63
  $options[] = array(
64
  'label' => $label,
65
  'value' => $attribute->getAttributeCode()
66
  );
67
  }
68
+
69
  return $options;
70
  }
71
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/DebugMode.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -40,7 +40,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_DebugMode
40
  {
41
  /**
42
  * Returns an option array for debug mode options
43
- *
44
  * @return array
45
  */
46
  public function toOptionArray()
@@ -60,7 +60,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_DebugMode
60
  'label' => $helper->__('Full'),
61
  ),
62
  );
63
-
64
  return $options;
65
  }
66
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
40
  {
41
  /**
42
  * Returns an option array for debug mode options
43
+ *
44
  * @return array
45
  */
46
  public function toOptionArray()
60
  'label' => $helper->__('Full'),
61
  ),
62
  );
63
+
64
  return $options;
65
  }
66
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/Direction.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -40,7 +40,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_Direction
40
  {
41
  /**
42
  * Returns an option array for sorting direction options
43
- *
44
  * @return array
45
  */
46
  public function toOptionArray()
@@ -56,7 +56,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_Direction
56
  'label' => $helper->__('Descending'),
57
  ),
58
  );
59
-
60
  return $options;
61
  }
62
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
40
  {
41
  /**
42
  * Returns an option array for sorting direction options
43
+ *
44
  * @return array
45
  */
46
  public function toOptionArray()
56
  'label' => $helper->__('Descending'),
57
  ),
58
  );
59
+
60
  return $options;
61
  }
62
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/EuProductOptions.php CHANGED
@@ -132,6 +132,10 @@ class TIG_PostNL_Model_Core_System_Config_Source_EuProductOptions
132
  * Check each standard option to see if it's supprted
133
  */
134
  foreach ($options as $option) {
 
 
 
 
135
  if (!in_array($option['value'], $supportedOptionsArray)) {
136
  continue;
137
  }
132
  * Check each standard option to see if it's supprted
133
  */
134
  foreach ($options as $option) {
135
+ if (!array_key_exists('value', $option)) {
136
+ continue;
137
+ }
138
+
139
  if (!in_array($option['value'], $supportedOptionsArray)) {
140
  continue;
141
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalProductOptions.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_GlobalProductOptions
@@ -42,10 +42,10 @@ class TIG_PostNL_Model_Core_System_Config_Source_GlobalProductOptions
42
  * XML path to supported options configuration setting
43
  */
44
  const XML_PATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
45
-
46
  /**
47
  * Returns an option array for all possible PostNL product options
48
- *
49
  * @return array
50
  */
51
  public function toOptionArray()
@@ -58,16 +58,16 @@ class TIG_PostNL_Model_Core_System_Config_Source_GlobalProductOptions
58
  'isExtraCover' => true,
59
  ),
60
  );
61
-
62
  return $availableOptions;
63
  }
64
-
65
  /**
66
  * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
67
- *
68
  * @param boolean|int $storeId
69
  * @param boolean $codesOnly
70
- *
71
  * @return array
72
  */
73
  public function getAvailableOptions($storeId = false, $codesOnly = false)
@@ -75,38 +75,40 @@ class TIG_PostNL_Model_Core_System_Config_Source_GlobalProductOptions
75
  if ($storeId === false) {
76
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
77
  }
78
-
79
- $helper = Mage::helper('postnl');
80
  $options = $this->toOptionArray();
81
-
82
  /**
83
  * Get a list of all possible options
84
  */
85
  $availableOptions = array();
86
-
87
  /**
88
  * Get the list of supported product options from the shop's configuration
89
  */
90
  $supportedOptions = Mage::getStoreConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
91
  $supportedOptionsArray = explode(',', $supportedOptions);
92
-
93
  /**
94
  * Check each standard option to see if it's supprted
95
  */
96
- $availableStandardOptions = array();
97
  foreach ($options as $option) {
 
 
 
 
98
  if (!in_array($option['value'], $supportedOptionsArray)) {
99
  continue;
100
  }
101
-
102
  if ($codesOnly === true) {
103
  $availableOptions[] = $option['value'];
104
  continue;
105
  }
106
-
107
  $availableOptions[] = $option;
108
  }
109
-
110
  return $availableOptions;
111
  }
112
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_GlobalProductOptions
42
  * XML path to supported options configuration setting
43
  */
44
  const XML_PATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
45
+
46
  /**
47
  * Returns an option array for all possible PostNL product options
48
+ *
49
  * @return array
50
  */
51
  public function toOptionArray()
58
  'isExtraCover' => true,
59
  ),
60
  );
61
+
62
  return $availableOptions;
63
  }
64
+
65
  /**
66
  * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
67
+ *
68
  * @param boolean|int $storeId
69
  * @param boolean $codesOnly
70
+ *
71
  * @return array
72
  */
73
  public function getAvailableOptions($storeId = false, $codesOnly = false)
75
  if ($storeId === false) {
76
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
77
  }
78
+
 
79
  $options = $this->toOptionArray();
80
+
81
  /**
82
  * Get a list of all possible options
83
  */
84
  $availableOptions = array();
85
+
86
  /**
87
  * Get the list of supported product options from the shop's configuration
88
  */
89
  $supportedOptions = Mage::getStoreConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
90
  $supportedOptionsArray = explode(',', $supportedOptions);
91
+
92
  /**
93
  * Check each standard option to see if it's supprted
94
  */
 
95
  foreach ($options as $option) {
96
+ if (!array_key_exists('value', $option)) {
97
+ continue;
98
+ }
99
+
100
  if (!in_array($option['value'], $supportedOptionsArray)) {
101
  continue;
102
  }
103
+
104
  if ($codesOnly === true) {
105
  $availableOptions[] = $option['value'];
106
  continue;
107
  }
108
+
109
  $availableOptions[] = $option;
110
  }
111
+
112
  return $availableOptions;
113
  }
114
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalpackShipmentType.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_Core_System_Config_Source_GlobalpackShipmentType
40
+ {
41
+ /**
42
+ * Returns an option array for possible GlobalPack shipment types.
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
+ {
48
+ $helper = Mage::helper('postnl');
49
+ $options = array(
50
+ array(
51
+ 'value' => 'Gift',
52
+ 'label' => $helper->__('Gift'),
53
+ ),
54
+ array(
55
+ 'value' => 'Documents',
56
+ 'label' => $helper->__('Documents'),
57
+ ),
58
+ array(
59
+ 'value' => 'Commercial Goods',
60
+ 'label' => $helper->__('Commercial Goods'),
61
+ ),
62
+ array(
63
+ 'value' => 'Commercial Sample',
64
+ 'label' => $helper->__('Commercial Sample'),
65
+ ),
66
+ array(
67
+ 'value' => 'Returned Goods',
68
+ 'label' => $helper->__('Returned Goods'),
69
+ ),
70
+ );
71
+
72
+ return $options;
73
+ }
74
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/LabelSize.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -40,7 +40,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_LabelSize
40
  {
41
  /**
42
  * Returns an option array for all supported label sizes
43
- *
44
  * @return array
45
  */
46
  public function toOptionArray()
@@ -56,7 +56,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_LabelSize
56
  'label' => $helper->__('A6')
57
  ),
58
  );
59
-
60
  return $labelSizes;
61
  }
62
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
40
  {
41
  /**
42
  * Returns an option array for all supported label sizes
43
+ *
44
  * @return array
45
  */
46
  public function toOptionArray()
56
  'label' => $helper->__('A6')
57
  ),
58
  );
59
+
60
  return $labelSizes;
61
  }
62
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakjeGemakProductOptions.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_PakjeGemakProductOptions
@@ -42,12 +42,12 @@ class TIG_PostNL_Model_Core_System_Config_Source_PakjeGemakProductOptions
42
  * XML path to supported options configuration setting
43
  */
44
  const XML_PATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
45
-
46
  /**
47
  * Returns an option array for all possible PostNL product options
48
- *
49
  * @return array
50
- *
51
  * @todo implement COD
52
  */
53
  public function toOptionArray()
@@ -56,24 +56,26 @@ class TIG_PostNL_Model_Core_System_Config_Source_PakjeGemakProductOptions
56
  $availableOptions = array(
57
  /**
58
  * These are not currently implemented
59
- *
60
- * TODO implement these options
61
  */
62
  /*array(
63
  'value' => '3535',
64
- 'label' => $helper->__('Post Office + COD')
65
  ),
66
  array(
67
  'value' => '3545',
68
- 'label' => $helper->__('Post Office + COD + Notification')
 
69
  ),
70
  array(
71
  'value' => '3536',
72
- 'label' => $helper->__('Post Office + COD + Extra Cover')
73
  ),
74
  array(
75
  'value' => '3546',
76
- 'label' => $helper->__('Post Office + COD + Extra Cover + Notification')
 
77
  ),*/
78
  array(
79
  'value' => '3534',
@@ -84,6 +86,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_PakjeGemakProductOptions
84
  'value' => '3544',
85
  'label' => $helper->__('Post Office + Extra Cover + Notification'),
86
  'isExtraCover' => true,
 
87
  ),
88
  array(
89
  'value' => '3533',
@@ -91,58 +94,106 @@ class TIG_PostNL_Model_Core_System_Config_Source_PakjeGemakProductOptions
91
  ),
92
  array(
93
  'value' => '3543',
94
- 'label' => $helper->__('Post Office + Signature on Delivery + Notification')
 
95
  ),
96
  );
97
-
98
  return $availableOptions;
99
  }
100
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  /**
102
  * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
103
- *
104
  * @param boolean|int $storeId
105
- * @param boolean $codesOnly
106
- *
 
107
  * @return array
108
  */
109
- public function getAvailableOptions($storeId = false, $codesOnly = false)
110
  {
111
  if ($storeId === false) {
112
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
113
  }
114
-
115
- $helper = Mage::helper('postnl');
116
- $options = $this->toOptionArray();
117
-
 
 
 
118
  /**
119
  * Get a list of all possible options
120
  */
121
  $availableOptions = array();
122
-
123
  /**
124
  * Get the list of supported product options from the shop's configuration
125
  */
126
  $supportedOptions = Mage::getStoreConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
127
  $supportedOptionsArray = explode(',', $supportedOptions);
128
-
129
  /**
130
  * Check each standard option to see if it's supprted
131
  */
132
- $availableStandardOptions = array();
133
  foreach ($options as $option) {
 
 
 
 
134
  if (!in_array($option['value'], $supportedOptionsArray)) {
135
  continue;
136
  }
137
-
138
  if ($codesOnly === true) {
139
  $availableOptions[] = $option['value'];
140
  continue;
141
  }
142
-
143
  $availableOptions[] = $option;
144
  }
145
-
146
  return $availableOptions;
147
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_PakjeGemakProductOptions
42
  * XML path to supported options configuration setting
43
  */
44
  const XML_PATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
45
+
46
  /**
47
  * Returns an option array for all possible PostNL product options
48
+ *
49
  * @return array
50
+ *
51
  * @todo implement COD
52
  */
53
  public function toOptionArray()
56
  $availableOptions = array(
57
  /**
58
  * These are not currently implemented
59
+ *
60
+ * @todo implement these options
61
  */
62
  /*array(
63
  'value' => '3535',
64
+ 'label' => $helper->__('Post Office + COD'),
65
  ),
66
  array(
67
  'value' => '3545',
68
+ 'label' => $helper->__('Post Office + COD + Notification'),
69
+ 'isPge' => true,
70
  ),
71
  array(
72
  'value' => '3536',
73
+ 'label' => $helper->__('Post Office + COD + Extra Cover'),
74
  ),
75
  array(
76
  'value' => '3546',
77
+ 'label' => $helper->__('Post Office + COD + Extra Cover + Notification'),
78
+ 'isPge' => true,
79
  ),*/
80
  array(
81
  'value' => '3534',
86
  'value' => '3544',
87
  'label' => $helper->__('Post Office + Extra Cover + Notification'),
88
  'isExtraCover' => true,
89
+ 'isPge' => true,
90
  ),
91
  array(
92
  'value' => '3533',
94
  ),
95
  array(
96
  'value' => '3543',
97
+ 'label' => $helper->__('Post Office + Signature on Delivery + Notification'),
98
+ 'isPge' => true,
99
  ),
100
  );
101
+
102
  return $availableOptions;
103
  }
104
+
105
+ /**
106
+ * Gets an array of possible PGE product options.
107
+ *
108
+ * @param boolean $asFlatArray
109
+ *
110
+ * @return array
111
+ */
112
+ public function getPgeOptions($asFlatArray = false)
113
+ {
114
+ $options = $this->toOptionArray();
115
+
116
+ $pgeOptions = array();
117
+ foreach ($options as $option) {
118
+ if (!isset($option['isPge']) || !$option['isPge']) {
119
+ continue;
120
+ }
121
+
122
+ if ($asFlatArray) {
123
+ $pgeOptions[] = $option;
124
+ }
125
+
126
+ $pgeOptions[$option['value']] = $option['label'];
127
+ }
128
+
129
+ return $pgeOptions;
130
+ }
131
+
132
  /**
133
  * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
134
+ *
135
  * @param boolean|int $storeId
136
+ * @param boolean $codesOnly
137
+ * @param boolean $isPge
138
+ *
139
  * @return array
140
  */
141
+ public function getAvailableOptions($storeId = false, $codesOnly = false, $isPge = false)
142
  {
143
  if ($storeId === false) {
144
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
145
  }
146
+
147
+ if (!$isPge) {
148
+ $options = $this->toOptionArray();
149
+ } else {
150
+ $options = $this->getPgeOptions(true);
151
+ }
152
+
153
  /**
154
  * Get a list of all possible options
155
  */
156
  $availableOptions = array();
157
+
158
  /**
159
  * Get the list of supported product options from the shop's configuration
160
  */
161
  $supportedOptions = Mage::getStoreConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
162
  $supportedOptionsArray = explode(',', $supportedOptions);
163
+
164
  /**
165
  * Check each standard option to see if it's supprted
166
  */
 
167
  foreach ($options as $option) {
168
+ if (!is_array($option) || !array_key_exists('value', $option)) {
169
+ continue;
170
+ }
171
+
172
  if (!in_array($option['value'], $supportedOptionsArray)) {
173
  continue;
174
  }
175
+
176
  if ($codesOnly === true) {
177
  $availableOptions[] = $option['value'];
178
  continue;
179
  }
180
+
181
  $availableOptions[] = $option;
182
  }
183
+
184
  return $availableOptions;
185
  }
186
+
187
+ /**
188
+ * Alias for getAvailableOptions() with $isPge === true.
189
+ *
190
+ * @param bool $storeId
191
+ * @param bool $codesOnly
192
+ *
193
+ * @return array
194
+ */
195
+ public function getAvailablePgeOptions($storeId = false, $codesOnly = false)
196
+ {
197
+ return $this->getAvailableOptions($storeId, $codesOnly, true);
198
+ }
199
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakketautomaatProductOptions.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ */
39
+ class TIG_PostNL_Model_Core_System_Config_Source_PakketautomaatProductOptions
40
+ {
41
+ /**
42
+ * XML path to supported options configuration setting
43
+ */
44
+ const XML_PATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
45
+
46
+ /**
47
+ * Returns an option array for all possible PostNL product options
48
+ *
49
+ * @return array
50
+ */
51
+ public function toOptionArray()
52
+ {
53
+ $helper = Mage::helper('postnl');
54
+ $availableOptions = array(
55
+ array(
56
+ 'value' => '3553',
57
+ 'label' => $helper->__('Parcel Dispenser'),
58
+ ),
59
+ );
60
+
61
+ return $availableOptions;
62
+ }
63
+
64
+ /**
65
+ * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
66
+ *
67
+ * @param boolean|int $storeId
68
+ * @param boolean $codesOnly
69
+ *
70
+ * @return array
71
+ */
72
+ public function getAvailableOptions($storeId = false, $codesOnly = false)
73
+ {
74
+ if ($storeId === false) {
75
+ $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
76
+ }
77
+
78
+ $options = $this->toOptionArray();
79
+
80
+ /**
81
+ * Get a list of all possible options
82
+ */
83
+ $availableOptions = array();
84
+
85
+ /**
86
+ * Get the list of supported product options from the shop's configuration
87
+ */
88
+ $supportedOptions = Mage::getStoreConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
89
+ $supportedOptionsArray = explode(',', $supportedOptions);
90
+
91
+ /**
92
+ * Check each standard option to see if it's supprted
93
+ */
94
+ foreach ($options as $option) {
95
+ if (!array_key_exists('value', $option)) {
96
+ continue;
97
+ }
98
+
99
+ if (!in_array($option['value'], $supportedOptionsArray)) {
100
+ continue;
101
+ }
102
+
103
+ if ($codesOnly === true) {
104
+ $availableOptions[] = $option['value'];
105
+ continue;
106
+ }
107
+
108
+ $availableOptions[] = $option;
109
+ }
110
+
111
+ return $availableOptions;
112
+ }
113
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ReferenceType.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -40,7 +40,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_ReferenceType
40
  {
41
  /**
42
  * Returns an option array for possible shipment references
43
- *
44
  * @return array
45
  */
46
  public function toOptionArray()
@@ -64,7 +64,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_ReferenceType
64
  'label' => $helper->__('Use a custom value'),
65
  ),
66
  );
67
-
68
  return $options;
69
  }
70
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
40
  {
41
  /**
42
  * Returns an option array for possible shipment references
43
+ *
44
  * @return array
45
  */
46
  public function toOptionArray()
64
  'label' => $helper->__('Use a custom value'),
65
  ),
66
  );
67
+
68
  return $options;
69
  }
70
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StandardProductOptions.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,7 +33,7 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_StandardProductOptions
@@ -42,12 +42,12 @@ class TIG_PostNL_Model_Core_System_Config_Source_StandardProductOptions
42
  * XML path to supported options configuration setting
43
  */
44
  const XML_PATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
45
-
46
  /**
47
  * Returns an option array for all possible PostNL product options
48
- *
49
  * @return array
50
- *
51
  * @todo implement COD
52
  */
53
  public function toOptionArray()
@@ -60,113 +60,172 @@ class TIG_PostNL_Model_Core_System_Config_Source_StandardProductOptions
60
  ),
61
  /**
62
  * These are not currently implemented
63
- *
64
- * TODO implement these options
65
  */
66
  /*array(
67
- 'value' => '3086',
68
- 'label' => $helper->__('COD'),
 
69
  ),
70
  array(
71
- 'value' => '3091',
72
- 'label' => $helper->__('COD + Extra cover'),
 
73
  ),
74
  array(
75
- 'value' => '3093',
76
- 'label' => $helper->__('COD + Return when not home'),
 
77
  ),
78
  array(
79
- 'value' => '3097',
80
- 'label' => $helper->__('COD + Extra cover + Return when not home'),
 
81
  ),*/
82
  array(
83
  'value' => '3087',
84
  'label' => $helper->__('Extra Cover'),
85
  'isExtraCover' => true,
 
86
  ),
87
  array(
88
  'value' => '3094',
89
  'label' => $helper->__('Extra cover + Return when not home'),
90
  'isExtraCover' => true,
 
91
  ),
92
  array(
93
  'value' => '3189',
94
  'label' => $helper->__('Signature on delivery'),
95
  ),
96
  array(
97
- 'value' => '3089',
98
- 'label' => $helper->__('Signature on delivery + Delivery to stated address only'),
 
99
  ),
100
  array(
101
  'value' => '3389',
102
  'label' => $helper->__('Signature on delivery + Return when not home'),
103
  ),
104
  array(
105
- 'value' => '3096',
106
- 'label' => $helper->__('Signature on delivery + Deliver to stated address only + Return when not home'),
 
 
 
107
  ),
108
  array(
109
  'value' => '3090',
110
  'label' => $helper->__('Delivery to neighbour + Return when not home'),
111
  ),
112
  array(
113
- 'value' => '3385',
114
- 'label' => $helper->__('Deliver to stated address only'),
 
115
  ),
116
  array(
117
- 'value' => '3390',
118
- 'label' => $helper->__('Deliver to stated address only + Return when not home'),
 
119
  ),
120
  );
121
-
122
  return $availableOptions;
123
  }
124
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  /**
126
  * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
127
- *
128
  * @param boolean|int $storeId
129
- * @param boolean $codesOnly
130
- *
 
131
  * @return array
132
  */
133
- public function getAvailableOptions($storeId = false, $codesOnly = false)
134
  {
135
  if ($storeId === false) {
136
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
137
  }
138
-
139
- $helper = Mage::helper('postnl');
140
- $options = $this->toOptionArray();
141
-
 
 
 
142
  /**
143
  * Get a list of all possible options
144
  */
145
  $availableOptions = array();
146
-
147
  /**
148
  * Get the list of supported product options from the shop's configuration
149
  */
150
  $supportedOptions = Mage::getStoreConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
151
  $supportedOptionsArray = explode(',', $supportedOptions);
152
-
153
  /**
154
  * Check each standard option to see if it's supprted
155
  */
156
- $availableStandardOptions = array();
157
  foreach ($options as $option) {
 
 
 
 
158
  if (!in_array($option['value'], $supportedOptionsArray)) {
159
  continue;
160
  }
161
-
162
  if ($codesOnly === true) {
163
  $availableOptions[] = $option['value'];
164
  continue;
165
  }
166
-
167
  $availableOptions[] = $option;
168
  }
169
-
170
  return $availableOptions;
171
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_StandardProductOptions
42
  * XML path to supported options configuration setting
43
  */
44
  const XML_PATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
45
+
46
  /**
47
  * Returns an option array for all possible PostNL product options
48
+ *
49
  * @return array
50
+ *
51
  * @todo implement COD
52
  */
53
  public function toOptionArray()
60
  ),
61
  /**
62
  * These are not currently implemented
63
+ *
64
+ * @todo implement these options
65
  */
66
  /*array(
67
+ 'value' => '3086',
68
+ 'label' => $helper->__('COD'),
69
+ 'isAvond' => true,
70
  ),
71
  array(
72
+ 'value' => '3091',
73
+ 'label' => $helper->__('COD + Extra cover'),
74
+ 'isAvond' => true,
75
  ),
76
  array(
77
+ 'value' => '3093',
78
+ 'label' => $helper->__('COD + Return when not home'),
79
+ 'isAvond' => true,
80
  ),
81
  array(
82
+ 'value' => '3097',
83
+ 'label' => $helper->__('COD + Extra cover + Return when not home'),
84
+ 'isAvond' => true,
85
  ),*/
86
  array(
87
  'value' => '3087',
88
  'label' => $helper->__('Extra Cover'),
89
  'isExtraCover' => true,
90
+ 'isAvond' => true,
91
  ),
92
  array(
93
  'value' => '3094',
94
  'label' => $helper->__('Extra cover + Return when not home'),
95
  'isExtraCover' => true,
96
+ 'isAvond' => true,
97
  ),
98
  array(
99
  'value' => '3189',
100
  'label' => $helper->__('Signature on delivery'),
101
  ),
102
  array(
103
+ 'value' => '3089',
104
+ 'label' => $helper->__('Signature on delivery + Delivery to stated address only'),
105
+ 'isAvond' => true,
106
  ),
107
  array(
108
  'value' => '3389',
109
  'label' => $helper->__('Signature on delivery + Return when not home'),
110
  ),
111
  array(
112
+ 'value' => '3096',
113
+ 'label' => $helper->__(
114
+ 'Signature on delivery + Deliver to stated address only + Return when not home'
115
+ ),
116
+ 'isAvond' => true,
117
  ),
118
  array(
119
  'value' => '3090',
120
  'label' => $helper->__('Delivery to neighbour + Return when not home'),
121
  ),
122
  array(
123
+ 'value' => '3385',
124
+ 'label' => $helper->__('Deliver to stated address only'),
125
+ 'isAvond' => true,
126
  ),
127
  array(
128
+ 'value' => '3390',
129
+ 'label' => $helper->__('Deliver to stated address only + Return when not home'),
130
+ 'isAvond' => true,
131
  ),
132
  );
133
+
134
  return $availableOptions;
135
  }
136
+
137
+ /**
138
+ * Gets an array of possible evening delivery product options.
139
+ *
140
+ * @param boolean $asFlatArray
141
+ *
142
+ * @return array
143
+ */
144
+ public function getAvondOptions($asFlatArray = false)
145
+ {
146
+ $options = $this->toOptionArray();
147
+
148
+ $avondOptions = array();
149
+ foreach ($options as $option) {
150
+ if (!isset($option['isAvond']) || !$option['isAvond']) {
151
+ continue;
152
+ }
153
+
154
+ if ($asFlatArray) {
155
+ $avondOptions[] = $option;
156
+ }
157
+
158
+ $avondOptions[$option['value']] = $option['label'];
159
+ }
160
+
161
+ return $avondOptions;
162
+ }
163
+
164
  /**
165
  * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
166
+ *
167
  * @param boolean|int $storeId
168
+ * @param boolean $codesOnly
169
+ * @param boolean $isAvond
170
+ *
171
  * @return array
172
  */
173
+ public function getAvailableOptions($storeId = false, $codesOnly = false, $isAvond = false)
174
  {
175
  if ($storeId === false) {
176
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
177
  }
178
+
179
+ if (!$isAvond) {
180
+ $options = $this->toOptionArray();
181
+ } else {
182
+ $options = $this->getAvondOptions(true);
183
+ }
184
+
185
  /**
186
  * Get a list of all possible options
187
  */
188
  $availableOptions = array();
189
+
190
  /**
191
  * Get the list of supported product options from the shop's configuration
192
  */
193
  $supportedOptions = Mage::getStoreConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
194
  $supportedOptionsArray = explode(',', $supportedOptions);
195
+
196
  /**
197
  * Check each standard option to see if it's supprted
198
  */
 
199
  foreach ($options as $option) {
200
+ if (!is_array($option) || !array_key_exists('value', $option)) {
201
+ continue;
202
+ }
203
+
204
  if (!in_array($option['value'], $supportedOptionsArray)) {
205
  continue;
206
  }
207
+
208
  if ($codesOnly === true) {
209
  $availableOptions[] = $option['value'];
210
  continue;
211
  }
212
+
213
  $availableOptions[] = $option;
214
  }
215
+
216
  return $availableOptions;
217
  }
218
+
219
+ /**
220
+ * Alias for getAvailableOptions() with $isAvond === true.
221
+ *
222
+ * @param bool $storeId
223
+ * @param bool $codesOnly
224
+ *
225
+ * @return array
226
+ */
227
+ public function getAvailableAvondOptions($storeId = false, $codesOnly = false)
228
+ {
229
+ return $this->getAvailableOptions($storeId, $codesOnly, true);
230
+ }
231
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetField.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -43,15 +43,15 @@ class TIG_PostNL_Model_Core_System_Config_Source_StreetField
43
  * XML path to community edition address lines configuration option
44
  */
45
  const XML_PATH_COMMUNITY_STREET_LINES = 'customer/address/street_lines';
46
-
47
  /**
48
  * @var null|array The resulting product option array
49
  */
50
  protected $_options = null;
51
-
52
  /**
53
  * Source model for street line settings
54
- *
55
  * @return array
56
  */
57
  public function toOptionArray()
@@ -59,30 +59,30 @@ class TIG_PostNL_Model_Core_System_Config_Source_StreetField
59
  if ($this->_options !== null) {
60
  return $this->_options;
61
  }
62
-
63
  if (Mage::helper('postnl')->isEnterprise()) {
64
  $array = $this->_getEnterpriseOptions();
65
-
66
  $this->_options = $array;
67
  return $array;
68
  }
69
-
70
  $array = $this->_getCommunityOptions();
71
-
72
  $this->_options = $array;
73
  return $array;
74
  }
75
-
76
  /**
77
  * Gets options for community edition shops
78
- *
79
  * @return array
80
  */
81
  protected function _getCommunityOptions()
82
  {
83
  $request = Mage::app()->getRequest();
84
  $helper = Mage::helper('postnl');
85
-
86
  /**
87
  * Get the allowed number of address lines based on the current scope
88
  */
@@ -94,7 +94,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_StreetField
94
  } else {
95
  $lineCount = Mage::getStoreConfig(self::XML_PATH_COMMUNITY_STREET_LINES, Mage_Core_Model_App::ADMIN_STORE_ID);
96
  }
97
-
98
  /**
99
  * Build the option array
100
  */
@@ -105,20 +105,20 @@ class TIG_PostNL_Model_Core_System_Config_Source_StreetField
105
  'label' => $helper->__('Street line #%s', $n),
106
  );
107
  }
108
-
109
  return $array;
110
  }
111
-
112
  /**
113
  * Gets options for enterprise edition shops
114
- *
115
  * @return array
116
  */
117
  protected function _getEnterpriseOptions()
118
  {
119
  $helper = Mage::helper('postnl');
120
  $lineCount = Mage::helper('customer/address')->getStreetLines();
121
-
122
  /**
123
  * Build the option array
124
  */
@@ -129,7 +129,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_StreetField
129
  'label' => $helper->__('Street line #%s', $n),
130
  );
131
  }
132
-
133
  return $array;
134
  }
135
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
43
  * XML path to community edition address lines configuration option
44
  */
45
  const XML_PATH_COMMUNITY_STREET_LINES = 'customer/address/street_lines';
46
+
47
  /**
48
  * @var null|array The resulting product option array
49
  */
50
  protected $_options = null;
51
+
52
  /**
53
  * Source model for street line settings
54
+ *
55
  * @return array
56
  */
57
  public function toOptionArray()
59
  if ($this->_options !== null) {
60
  return $this->_options;
61
  }
62
+
63
  if (Mage::helper('postnl')->isEnterprise()) {
64
  $array = $this->_getEnterpriseOptions();
65
+
66
  $this->_options = $array;
67
  return $array;
68
  }
69
+
70
  $array = $this->_getCommunityOptions();
71
+
72
  $this->_options = $array;
73
  return $array;
74
  }
75
+
76
  /**
77
  * Gets options for community edition shops
78
+ *
79
  * @return array
80
  */
81
  protected function _getCommunityOptions()
82
  {
83
  $request = Mage::app()->getRequest();
84
  $helper = Mage::helper('postnl');
85
+
86
  /**
87
  * Get the allowed number of address lines based on the current scope
88
  */
94
  } else {
95
  $lineCount = Mage::getStoreConfig(self::XML_PATH_COMMUNITY_STREET_LINES, Mage_Core_Model_App::ADMIN_STORE_ID);
96
  }
97
+
98
  /**
99
  * Build the option array
100
  */
105
  'label' => $helper->__('Street line #%s', $n),
106
  );
107
  }
108
+
109
  return $array;
110
  }
111
+
112
  /**
113
  * Gets options for enterprise edition shops
114
+ *
115
  * @return array
116
  */
117
  protected function _getEnterpriseOptions()
118
  {
119
  $helper = Mage::helper('postnl');
120
  $lineCount = Mage::helper('customer/address')->getStreetLines();
121
+
122
  /**
123
  * Build the option array
124
  */
129
  'label' => $helper->__('Street line #%s', $n),
130
  );
131
  }
132
+
133
  return $array;
134
  }
135
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetFieldWithDefault.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -41,20 +41,20 @@ class TIG_PostNL_Model_Core_System_Config_Source_StreetFieldWithDefault extends
41
  {
42
  /**
43
  * Source model for street line settings
44
- *
45
  * @return array
46
  */
47
  public function toOptionArray()
48
  {
49
  $options = parent::toOptionArray();
50
-
51
  $defaultOption = array(
52
  'value' => '',
53
  'label' => Mage::helper('postnl')->__('Field not used.'),
54
  );
55
-
56
  array_unshift($options, $defaultOption);
57
-
58
  return $options;
59
  }
60
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
41
  {
42
  /**
43
  * Source model for street line settings
44
+ *
45
  * @return array
46
  */
47
  public function toOptionArray()
48
  {
49
  $options = parent::toOptionArray();
50
+
51
  $defaultOption = array(
52
  'value' => '',
53
  'label' => Mage::helper('postnl')->__('Field not used.'),
54
  );
55
+
56
  array_unshift($options, $defaultOption);
57
+
58
  return $options;
59
  }
60
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/WeightUnit.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  /**
3
- * ___________ __ __
4
- * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
- * \/
9
- * ___ __ __
10
- * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
- * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
- * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
- * \/ \/
15
- * ________
16
- * / _____/_______ ____ __ __ ______
17
- * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
- * \______ /|__| \____/ |____/ | __/
20
- * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
- * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
@@ -33,16 +33,16 @@
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
- * @copyright Copyright (c) 2013 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_WeightUnit
40
  {
41
  /**
42
  * Returns an option array for all possible PostNL product options
43
- *
44
  * @return array
45
- *
46
  * @todo implement COD and extra cover
47
  */
48
  public function toOptionArray()
@@ -149,7 +149,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_WeightUnit
149
  ),
150
  ),
151
  );
152
-
153
  return $availableOptions;
154
  }
155
  }
1
  <?php
2
  /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
  * | | / _ \\ __\\__ \ | |
6
  * | | | |_| || | / __ \_| |__
7
  * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
  * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
  * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
  *
22
  * NOTICE OF LICENSE
23
  *
24
  * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
  * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
  * If you are unable to obtain it through the world-wide-web, please send an email
28
  * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
33
  * versions in the future. If you wish to customize this module for your
34
  * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
  *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
  * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
  */
39
  class TIG_PostNL_Model_Core_System_Config_Source_WeightUnit
40
  {
41
  /**
42
  * Returns an option array for all possible PostNL product options
43
+ *
44
  * @return array
45
+ *
46
  * @todo implement COD and extra cover
47
  */
48
  public function toOptionArray()
149
  ),
150
  ),
151
  );
152
+
153
  return $availableOptions;
154
  }
155
  }
app/code/community/TIG/PostNL/Model/DeliveryOptions/Cif.php ADDED
@@ -0,0 +1,435 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ___________ __ __
4
+ * \__ ___/____ _/ |_ _____ | |
5
+ * | | / _ \\ __\\__ \ | |
6
+ * | | | |_| || | / __ \_| |__
7
+ * |____| \____/ |__| (____ /|____/
8
+ * \/
9
+ * ___ __ __
10
+ * | | ____ _/ |_ ____ _______ ____ ____ _/ |_
11
+ * | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
12
+ * | || | \| | \ ___/ | | \/| | \\ ___/ | |
13
+ * |___||___| /|__| \_____>|__| |___| / \_____>|__|
14
+ * \/ \/
15
+ * ________
16
+ * / _____/_______ ____ __ __ ______
17
+ * / \ ___\_ __ \ / _ \ | | \\____ \
18
+ * \ \_\ \| | \/| |_| || | /| |_| |
19
+ * \______ /|__| \____/ |____/ | __/
20
+ * \/ |__|
21
+ *
22
+ * NOTICE OF LICENSE
23
+ *
24
+ * This source file is subject to the Creative Commons License.
25
+ * It is available through the world-wide-web at this URL:
26
+ * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
27
+ * If you are unable to obtain it through the world-wide-web, please send an email
28
+ * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately.
29
+ *
30
+ * DISCLAIMER
31
+ *
32
+ * Do not edit or add to this file if you wish to upgrade this module to newer
33
+ * versions in the future. If you wish to customize this module for your
34
+ * needs please contact servicedesk@totalinternetgroup.nl for more information.
35
+ *
36
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
37
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
38
+ *
39
+ * @method TIG_PostNL_Model_DeliveryOptions_Cif setStoreId(int $value)
40
+ * @method int getStoreId()
41
+ */
42
+ class TIG_PostNL_Model_DeliveryOptions_Cif extends TIG_PostNL_Model_Core_Cif
43
+ {
44
+ /**
45
+ * Delivery option codes.
46
+ */
47
+ const PAKJEGEMAK_DELIVERY_OPTION = 'PG';
48
+ const PAKJEGEMAK_EXPRESS_DELIVERY_OPTION = 'PGE';
49
+ const PAKKETAUTOMAAT_DELIVERY_OPTION = 'PA';
50
+
51
+ /**
52
+ * Config options used by the getDeliveryDate service.
53
+ */
54
+ const XPATH_SHIPPING_DURATION = 'postnl/delivery_options/shipping_duration';
55
+ const XPATH_CUTOFF_TIME = 'postnl/delivery_options/cutoff_time';
56
+ const XPATH_ALLOW_SUNDAY_SORTING = 'postnl/delivery_options/allow_sunday_sorting';
57
+ const XPATH_SUNDAY_CUTOFF_TIME = 'postnl/delivery_options/sunday_cutoff_time';
58
+ const XPATH_DELIVERY_DAYS_NUMBER = 'postnl/delivery_options/delivery_days_number';
59
+
60
+ /**
61
+ * Check if the module is set to test mode
62
+ *
63
+ * @param bool $storeId
64
+ *
65
+ * @return boolean
66
+ *
67
+ * @see TIG_PostNL_Helper_Checkout::isTestMode()
68
+ */
69
+ public function isTestMode($storeId = false)
70
+ {
71
+ $testMode = Mage::helper('postnl/cif')->isTestMode($storeId);
72
+
73
+ return $testMode;
74
+ }
75
+
76
+ /**
77
+ * Gets the delivery date based on the shop's cut-off time.
78
+ *
79
+ * @param string $postcode
80
+ * @param Mage_Sales_Model_Quote $quote
81
+ *
82
+ * @return string
83
+ *
84
+ * @throws TIG_PostNL_Exception
85
+ */
86
+ public function getDeliveryDate($postcode, Mage_Sales_Model_Quote $quote)
87
+ {
88
+ if (empty($postcode)) {
89
+ throw new TIG_PostNL_Exception(
90
+ Mage::helper('postnl')->__('No data available for GetDeliveryDay request.'),
91
+ 'POSTNL-0115'
92
+ );
93
+ }
94
+
95
+ $shippingDuration = Mage::helper('postnl/deliveryoptions')->getShippingDuration($quote);
96
+
97
+ $soapParams = array(
98
+ 'GetDeliveryDate' => array(
99
+ 'Postalcode' => $postcode,
100
+ 'ShippingDate' => date('d-m-Y H:i:s', Mage::getModel('core/date')->timestamp()),
101
+ 'ShippingDuration' => $shippingDuration,
102
+ 'CutOffTime' => $this->_getCutOffTime(),
103
+ 'AllowSundaySorting' => $this->_getSundaySortingAllowed(),
104
+ 'CutOffTimeForSundaySorting' => $this->_getSundaySortingCutOffTime(),
105
+ ),
106
+ 'Message' => $this->_getMessage('')
107
+ );
108
+
109
+ /**
110
+ * Send the SOAP request
111
+ */
112
+ $response = $this->call(
113
+ 'deliverydate',
114
+ 'GetDeliveryDate',
115
+ $soapParams
116
+ );
117
+
118
+ if (!is_object($response)
119
+ || !isset($response->DeliveryDate)
120
+ || !is_string($response->DeliveryDate)
121
+ ) {
122
+ throw new TIG_PostNL_Exception(
123
+ Mage::helper('postnl')->__('Invalid GetDeliveryDate response: %s', "\n" . var_export($response, true)),
124
+ 'POSTNL-0116'
125
+ );
126
+ }
127
+
128
+ return $response->DeliveryDate;
129
+ }
130
+
131
+ /**
132
+ * Get evening timeframes for the specified postcode and delivery window.
133
+ *
134
+ * @param array $data
135
+ *
136
+ * @return StdClass
137
+ *
138
+ * @throws TIG_PostNL_Exception
139
+ */
140
+ public function getDeliveryTimeframes($data)
141
+ {
142
+ if (empty($data)) {
143
+ throw new TIG_PostNL_Exception(
144
+ Mage::helper('postnl')->__('No data available for request.'),
145
+ 'POSTNL-0117'
146
+ );
147
+ }
148
+
149
+ $startDate = $data['deliveryDate'];
150
+
151
+ /**
152
+ * To calculate the end date we need to number of days we want to display minus 1.
153
+ */
154
+ $storeId = Mage::app()->getStore()->getId();
155
+ $maximumNumberOfDeliveryDays = (int) Mage::getStoreConfig(self::XPATH_DELIVERY_DAYS_NUMBER, $storeId);
156
+ $maximumNumberOfDeliveryDays--;
157
+
158
+ $endDate = date('d-m-Y', strtotime("+{$maximumNumberOfDeliveryDays} days", strtotime($startDate)));
159
+
160
+ $soapParams = array(
161
+ 'Timeframe' => array(
162
+ 'PostalCode' => $data['postcode'],
163
+ 'HouseNumber' => $data['housenumber'],
164
+ 'StartDate' => $startDate,
165
+ 'EndDate' => $endDate,
166
+ ),
167
+ 'Message' => $this->_getMessage('')
168
+ );
169
+
170
+ /**
171
+ * Send the SOAP request
172
+ */
173
+ $response = $this->call(
174
+ 'timeframe',
175
+ 'GetDeliveryTimeframes',
176
+ $soapParams
177
+ );
178
+
179
+ if (!isset($response->Timeframes)
180
+ || !isset($response->Timeframes->Timeframe)
181
+ ) {
182
+ throw new TIG_PostNL_Exception(
183
+ Mage::helper('postnl')->__('Invalid response for getDeliveryTimeframes request: %s', $response),
184
+ 'POSTNL-0122'
185
+ );
186
+ }
187
+
188
+ return $response->Timeframes->Timeframe;
189
+ }
190
+
191
+ /**
192
+ * Gets nearby post office locations. This service can be based off of a postcode or a set of coordinates. Results may
193
+ * include PakjeGemak, PakjeGemak Express or pakket automaat locations based on the configuration of the extension.
194
+ *
195
+ * @param $data
196
+ *
197
+ * @return string
198
+ *
199
+ * @throws TIG_PostNL_Exception
200
+ */
201
+ public function getNearestLocations($data)
202
+ {
203
+ if (empty($data)) {
204
+ throw new TIG_PostNL_Exception(
205
+ Mage::helper('postnl')->__('No data available for request.'),
206
+ 'POSTNL-0117'
207
+ );
208
+ }
209
+
210
+ $location = $this->_getLocation($data);
211
+ $message = $this->_getMessage('');
212
+
213
+ $soapParams = array(
214
+ 'Location' => $location,
215
+ 'Message' => $message,
216
+ );
217
+
218
+ /**
219
+ * Send the SOAP request
220
+ */
221
+ $response = $this->call(
222
+ 'location',
223
+ 'GetNearestLocations',
224
+ $soapParams
225
+ );
226
+
227
+ if (!isset($response->GetLocationsResult)
228
+ || !isset($response->GetLocationsResult->ResponseLocation)
229
+ ) {
230
+ throw new TIG_PostNL_Exception(
231
+ Mage::helper('postnl')->__('Invalid response for GetNearestLocations request: %s', $response),
232
+ 'POSTNL-0123'
233
+ );
234
+ }
235
+
236
+ return $response->GetLocationsResult->ResponseLocation;
237
+ }
238
+
239
+ /**
240
+ * gets post office locations within a specific area, marked by a set of coordinates.
241
+ *
242
+ * @param $data
243
+ *
244
+ * @return string
245
+ *
246
+ * @throws TIG_PostNL_Exception
247
+ */
248
+ public function getLocationsInArea($data)
249
+ {
250
+ if (empty($data)) {
251
+ throw new TIG_PostNL_Exception(
252
+ Mage::helper('postnl')->__('No data available for request.'),
253
+ 'POSTNL-0117'
254
+ );
255
+ }
256
+
257
+ $location = $this->_getLocation($data);
258
+ $message = $this->_getMessage('');
259
+
260
+ $soapParams = array(
261
+ 'Location' => $location,
262
+ 'Message' => $message,
263
+ );
264
+
265
+ /**
266
+ * Send the SOAP request
267
+ */
268
+ $response = $this->call(
269
+ 'location',
270
+ 'GetLocationsInArea',
271
+ $soapParams
272
+ );
273
+
274
+ if (!isset($response->GetLocationsResult)
275
+ || !isset($response->GetLocationsResult)
276
+ ) {
277
+ throw new TIG_PostNL_Exception(
278
+ Mage::helper('postnl')->__('Invalid response for getLocationsInArea request: %s', $response),
279
+ 'POSTNL-0123'
280
+ );
281
+ }
282
+
283
+ return $response->GetLocationsResult->ResponseLocation;
284
+ }
285
+
286
+ /**
287
+ * Gets the regular cut-off time for this storeview.
288
+ *
289
+ * @return string
290
+ */
291
+ protected function _getCutOffTime()
292
+ {
293
+ $storeId = $this->getStoreId();
294
+
295
+ $cutOffTime = Mage::getStoreConfig(self::XPATH_CUTOFF_TIME, $storeId);
296
+ if (!$cutOffTime) {
297
+ $cutOffTime = '23:59:59';
298
+ }
299
+
300
+ return $cutOffTime;
301
+ }
302
+
303
+ /**
304
+ * Checks whether sunday sorting is allowed for this storeview.
305
+ *
306
+ * @return string
307
+ */
308
+ protected function _getSundaySortingAllowed()
309
+ {
310
+ $storeId = $this->getStoreId();
311
+
312
+ $allowSundaySorting = Mage::getStoreConfigFlag(self::XPATH_ALLOW_SUNDAY_SORTING, $storeId);
313
+ if ($allowSundaySorting === true) {
314
+ return 'true';
315
+ }
316
+
317
+ return 'false';
318
+ }
319
+
320
+ /**
321
+ * Gets the regular cut-off time for this storeview.
322
+ *
323
+ * @return string
324
+ */
325
+ protected function _getSundaySortingCutOffTime()
326
+ {
327
+ $storeId = $this->getStoreId();
328
+
329
+ $cutOffTime = Mage::getStoreConfig(self::XPATH_SUNDAY_CUTOFF_TIME, $storeId);
330
+ if (!$cutOffTime) {
331
+ $cutOffTime = '23:59:59';
332
+ }
333
+
334
+ return $cutOffTime;
335
+ }
336
+
337
+ /**
338
+ * Gets the location SOAP parameter array.
339
+ *
340
+ * @param array $data
341
+ *
342
+ * @return array
343
+ */
344
+ protected function _getLocation($data)
345
+ {
346
+ /**
347
+ * Start building the location array by adding the available delivery options.
348
+ */
349
+ $location = array(
350
+ 'DeliveryOptions' => $this->_getDeliveryOptions(),
351
+ );
352
+
353
+ /**
354
+ * Next we add the desired delivery date. If none is specified, we set it to tomorrow.
355
+ */
356
+ if (isset($data['deliveryDate'])) {
357
+ $location['DeliveryDate'] = $data['deliveryDate'];
358
+ } else {
359
+ $tomorrow = strtotime('tomorrow', Mage::getModel('core/date')->timestamp());
360
+ $location['DeliveryDate'] = date('d-m-Y', $tomorrow);
361
+ }
362
+
363
+ /**
364
+ * If an opening time was specified, add that as well.
365
+ */
366
+ if (isset($data['openingTime'])) {
367
+ $location['OpeningTime'] = $data['openingTime'];
368
+ }
369
+
370
+ /**
371
+ * Add the postcode if available.
372
+ */
373
+ if (isset($data['postcode'])) {
374
+ $location['Postalcode'] = $data['postcode'];
375
+ }
376
+
377
+ /**
378
+ * Add coordinates if both a latitude and longitude are available.
379
+ */
380
+ if (isset($data['lat']) && isset($data['long'])) {
381
+ $location['Coordinates'] = array(
382
+ 'Latitude' => $data['lat'],
383
+ 'Longitude' => $data['long'],
384
+ );
385
+ }
386
+
387
+ /**
388
+ * Add coordinates for an area marked by two sets of coordinates.
389
+ *
390
+ * Please note that PostNL uses NW and SE, while google maps uses NE and SW.
391
+ */
392
+ if (isset($data['northEast']['lat'])
393
+ && isset($data['northEast']['long'])
394
+ && isset($data['southWest']['lat']