tig_postnl - Version 1.3.1

Version Notes

==== v1.3.1 ====
==== Bug fixes ====
- Confirm dates will no longer be shown as always being in the future.
- Added additional checks to prevent deleted Magento orders and shipments from causing errors.
- Prevented VAT amounts from being shown twice on the checkout page.
- It is no longer impossible to create multi-parcel shipments when 'letter box calculation mode' is set to automatic.
- Prevented COD fees from causing errors on the invoice page in the backend.

==== v1.3.0 ====
==== New features ====
- Added the option to ship orders as letter box parcels. Letter box parcels are shipped using the regular mail service and can be shipped at a reduced rate. It's possible to let the PostNL extension determine when an order qualifies as a letter box parcel or to decide this manually when creating a shipment in Magento.
- Added a new PostNL COD payment method that is fully integrated in the other PostNL services offered by the extension. It's possible to charge an additional fee to customers for using PostNL COD. It's also possible to have the extension automatically invoice COD orders once they have been delivered to the customer.
- Added a new PostNL packing slip. This packing slip may contain the PostNL shipping label, allowing you to use the packing slip as the shipping label for the parcel.
- Added the option to enable or disable delivery options at the product level.
- Added the ability to convert existing shipments to a letter box parcel or to a regular parcel as long as they have not been received by PostNL.
- Added the ability to change the selected shipping option for a shipment as long as it has not yet been received by PostNL.
- Added the option to use additional shipping methods for PostNL.
- Added the option to create a shipment, confirm it and print it's shipping labels for an order straight from the order grid in a single click.

==== Improvements ====
- It's now possible to enable or disable time frames separately from delivery days.
- You can now specify the cut-off time in minutes as well as hours.
- You can now view an order's confirm date, confirm status and shipping phase in the order grid.
- Additional information regarding the chosen delivery option is now shown on the order detail page.
- Added a button to download all PostNL debug log files to the PostNL configuration page.
- The 'create shipments' massaction interface has been modified so that only valid options are displayed.
- Errors that occur whilst processing multiple shipments or orders will no longer stop the entire process. Instead the remaining orders and shipments will be processed and an error message specifying which orders or shipments caused an error will be displayed afterwards.
- The first and last name fields are no longer mandatory for the sender's address fields in the PostNL configuration.
- Spaces are now allowed in postcodes.

==== Bug fixes ====
- Deleting orders from Magento should no longer cause errors when processing PostNL shipments.
- The PostNL shipping method will no longer be selected by default.
- Greece will now be processed with EPS, instead of GlobalPack.
- Upgrade and install scripts will now check if certain columns and attributes exist before modifying them.
- The progress bar on the Onepage Checkout page will now correctly update the shipping costs when the customer has chosen a delivery option that charges an additional fee.
- Creating shipments for which no default shipping option is selected will no longer cause errors.

==== v1.2.2 ====
==== New features ====
- Added the option to send a copy of the track & trace email to a specified email address.

==== Improvements ====
- Performance of the entire extension has been improved. The extension will now attempt to cache several configuration values.
- Label printing will now always follow the 'label size' configuration setting.

==== Bug fixes ====
- Fixed several small html errors in the track & trace email template.
- Fixed an SQL error that could occur when filtering the 'store' column in the order and shipment grids.

==== v1.2.1 ====
==== Release highlights ====
- The extension now fully supports Magento 1.9 and 1.14!

==== Minor improvements ====
- Added additional checks to prevent errors when Magento's layout has been altered or PostNL's layout has not been uploaded properly.
- Added additional compatibility enhancements for MultiSafePay and other PSP extensions.
- Improved several minor texts and translations.

==== Bug fixes ====
- Fixed an issue that prevented MijnPakket login data from being cached.
- Fixed an issue where using PostNL-only features on non-PostNL shipments would cause an error.
- Fixed an issue where PostNL's feed messages would be loaded in the wrong order.
- Fixed an issue where several notifications would be added to Magento when installing an unsupported version of Magento with the PostNL extension.
- Fixed an issue with EPS comb-labels. EPS combi-labels were rotated by 90 degrees, causing overlapping issues with other labels being printed.

==== 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.3.1
Comparing to
See all releases


Code changes from version 1.2.2 to 1.3.1

Files changed (156) hide show
  1. app/code/community/TIG/PostNL/Block/Adminhtml/CronNotification.php +6 -4
  2. app/code/community/TIG/PostNL/Block/Adminhtml/LogNotification.php +129 -0
  3. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Items/Column/Qty.php +109 -0
  4. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Create/Totals/CodFee.php +105 -0
  5. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Creditmemo/Create/CodFee.php +172 -0
  6. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Creditmemo/Totals/CodFee.php +142 -0
  7. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Invoice/Totals/CodFee.php +139 -0
  8. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/ProductOptions.php +1 -1
  9. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/Create/ShipmentOptions.php +121 -18
  10. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/DeliveryOptions.php +246 -0
  11. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/ShippingStatus.php +4 -1
  12. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tab/StatusHistory.php +1 -1
  13. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tabs.php +31 -22
  14. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Totals/CodFee.php +131 -0
  15. app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/View/DeliveryOptions.php +176 -0
  16. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form.php +39 -12
  17. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ActivateButton.php +2 -2
  18. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ConfigCheck.php +3 -3
  19. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/HourMinute.php +236 -0
  20. app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/PackingSlipItemColumns.php +175 -0
  21. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Action.php +17 -6
  22. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Barcode.php +13 -7
  23. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmDate.php +34 -23
  24. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmStatus.php +29 -14
  25. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/DeliveryDate.php +6 -4
  26. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/OrderConfirmDate.php +149 -0
  27. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/OrderConfirmStatus.php +112 -0
  28. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/OrderType.php +98 -0
  29. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShipmentType.php +4 -124
  30. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingDescription.php +2 -3
  31. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingPhase.php +12 -5
  32. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Type/Abstract.php +413 -0
  33. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/YesNo.php +2 -3
  34. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Massaction/{LabelStartPos.php → Item/Additional/LabelStartPos.php} +2 -1
  35. app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Massaction/Item/Additional/ProductOptions.php +61 -0
  36. app/code/community/TIG/PostNL/Block/Checkout/Cart/Js.php +5 -5
  37. app/code/community/TIG/PostNL/Block/Core/JsTranslate.php +1 -1
  38. app/code/community/TIG/PostNL/Block/DeliveryOptions/Checkout/DeliveryOptions.php +50 -14
  39. app/code/community/TIG/PostNL/Block/DeliveryOptions/Js.php +14 -0
  40. app/code/community/TIG/PostNL/Block/Mijnpakket/AccountNotification.php +6 -13
  41. app/code/community/TIG/PostNL/Block/Mijnpakket/OrderSuccessJs.php +2 -2
  42. app/code/community/TIG/PostNL/Block/Payment/Checkout/Total/CodFee.php +105 -0
  43. app/code/community/TIG/PostNL/Block/Payment/Form/Cod.php +123 -0
  44. app/code/community/TIG/PostNL/Block/Payment/Info.php +61 -0
  45. app/code/community/TIG/PostNL/Block/Payment/Sales/Order/Creditmemo/Totals/CodFee.php +141 -0
  46. app/code/community/TIG/PostNL/Block/Payment/Sales/Order/Invoice/Totals/CodFee.php +134 -0
  47. app/code/community/TIG/PostNL/Block/Payment/Sales/Order/Totals/CodFee.php +131 -0
  48. app/code/community/TIG/PostNL/Controller/Adminhtml/Shipment.php +631 -0
  49. app/code/community/TIG/PostNL/Exception.php +4 -6
  50. app/code/community/TIG/PostNL/Helper/AddressValidation.php +20 -20
  51. app/code/community/TIG/PostNL/Helper/Carrier.php +116 -10
  52. app/code/community/TIG/PostNL/Helper/Checkout.php +10 -10
  53. app/code/community/TIG/PostNL/Helper/Cif.php +272 -225
  54. app/code/community/TIG/PostNL/Helper/Data.php +660 -174
  55. app/code/community/TIG/PostNL/Helper/DeliveryOptions.php +1482 -203
  56. app/code/community/TIG/PostNL/Helper/Mijnpakket.php +40 -12
  57. app/code/community/TIG/PostNL/Helper/Parcelware.php +11 -7
  58. app/code/community/TIG/PostNL/Helper/Payment.php +301 -0
  59. app/code/community/TIG/PostNL/Helper/Webservices.php +11 -11
  60. app/code/community/TIG/PostNL/Model/AddressValidation/Cendris.php +1 -1
  61. app/code/community/TIG/PostNL/Model/AddressValidation/Observer/AddressBook.php +1 -1
  62. app/code/community/TIG/PostNL/Model/AddressValidation/Observer/OneStepCheckout.php +1 -1
  63. app/code/community/TIG/PostNL/Model/AddressValidation/Observer/Onepage.php +2 -2
  64. app/code/community/TIG/PostNL/Model/Admin/Inbox.php +189 -0
  65. app/code/community/TIG/PostNL/Model/Admin/Logging/Handler/Postnl.php +6 -2
  66. app/code/community/TIG/PostNL/Model/Adminhtml/Form/Element/Checkbox.php +89 -0
  67. app/code/community/TIG/PostNL/Model/Adminhtml/Observer/OrderGrid.php +802 -60
  68. app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentGrid.php +188 -180
  69. app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentView.php +160 -44
  70. app/code/community/TIG/PostNL/Model/Adminhtml/Observer/SystemConfig.php +104 -0
  71. app/code/community/TIG/PostNL/Model/Adminhtml/Support/Logs.php +178 -0
  72. app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/OrderGridColumns.php +70 -0
  73. app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/OrderGridMassaction.php +70 -0
  74. app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/ShipmentGridMassaction.php +9 -1
  75. app/code/community/TIG/PostNL/Model/Carrier/Postnl.php +24 -74
  76. app/code/community/TIG/PostNL/Model/Carrier/Quote/Address/Total/Shipping.php +237 -0
  77. app/code/community/TIG/PostNL/Model/Checkout/Cif.php +29 -29
  78. app/code/community/TIG/PostNL/Model/Checkout/Observer/Order.php +1 -1
  79. app/code/community/TIG/PostNL/Model/Checkout/Observer/Shipment.php +1 -1
  80. app/code/community/TIG/PostNL/Model/Checkout/Service.php +41 -39
  81. app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/ActivePaymentMethods.php +1 -1
  82. app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/CmsPage.php +1 -1
  83. app/code/community/TIG/PostNL/Model/Core/Cache.php +39 -17
  84. app/code/community/TIG/PostNL/Model/Core/Cif.php +253 -176
  85. app/code/community/TIG/PostNL/Model/Core/Cif/Abstract.php +40 -17
  86. app/code/community/TIG/PostNL/Model/Core/Cif/Exception.php +17 -5
  87. app/code/community/TIG/PostNL/Model/Core/Label.php +433 -191
  88. app/code/community/TIG/PostNL/Model/Core/Observer/Barcode.php +10 -8
  89. app/code/community/TIG/PostNL/Model/Core/Observer/Cache.php +9 -0
  90. app/code/community/TIG/PostNL/Model/Core/Observer/Cron.php +117 -44
  91. app/code/community/TIG/PostNL/Model/Core/Observer/SaveShipment.php +23 -8
  92. app/code/community/TIG/PostNL/Model/Core/Order.php +91 -26
  93. app/code/community/TIG/PostNL/Model/Core/PackingSlip.php +1495 -0
  94. app/code/community/TIG/PostNL/Model/Core/Packingslip/Pdf/Items/Invoice/Default.php +164 -0
  95. app/code/community/TIG/PostNL/Model/Core/Resource/Order.php +4 -1
  96. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment.php +1 -1
  97. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode.php +1 -1
  98. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode/Collection.php +1 -1
  99. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Collection.php +1 -1
  100. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label.php +1 -1
  101. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label/Collection.php +1 -1
  102. app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Status/History/Collection.php +1 -1
  103. app/code/community/TIG/PostNL/Model/Core/Service.php +246 -0
  104. app/code/community/TIG/PostNL/Model/Core/Service/InvoiceDummy.php +55 -0
  105. app/code/community/TIG/PostNL/Model/Core/Service/OrderDummy.php +65 -0
  106. app/code/community/TIG/PostNL/Model/Core/Shipment.php +1242 -197
  107. app/code/community/TIG/PostNL/Model/Core/Shipment/Barcode.php +1 -1
  108. app/code/community/TIG/PostNL/Model/Core/Shipment/Label.php +1 -1
  109. app/code/community/TIG/PostNL/Model/Core/Shipment/Process.php +11 -5
  110. app/code/community/TIG/PostNL/Model/Core/Shipment/Status/History.php +1 -1
  111. app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/HourMinute.php +57 -0
  112. app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/Image/Pdf.php +125 -0
  113. app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/ValidateDefaultOption.php +9 -9
  114. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/AllProductOptions.php +265 -532
  115. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/BuspakjeProductOptions.php +55 -0
  116. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/CommentType.php +62 -0
  117. app/code/community/TIG/PostNL/Model/{DeliveryOptions → Core}/System/Config/Source/CutOffTime.php +1 -1
  118. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/DebugMode.php +1 -1
  119. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/Direction.php +1 -1
  120. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/EuProductOptions.php +20 -96
  121. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalProductOptions.php +9 -71
  122. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalpackShipmentType.php +28 -25
  123. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/HourMinute.php +71 -0
  124. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/LabelSize.php +1 -1
  125. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ManualAutomatic.php +62 -0
  126. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PackingSlipItemFields.php +78 -0
  127. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakjeGemakProductOptions.php +85 -123
  128. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakketautomaatProductOptions.php +8 -70
  129. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ProductOptions/Abstract.php +261 -0
  130. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ReferenceType.php +1 -1
  131. app/code/community/TIG/PostNL/Model/{DeliveryOptions → Core}/System/Config/Source/ShippingDuration.php +1 -1
  132. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ShippingMethods.php +122 -0
  133. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StandardProductOptions.php +145 -149
  134. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetField.php +5 -5
  135. app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetFieldWithDefault.php +1 -1
  136. app/code/community/TIG/PostNL/Model/DeliveryOptions/Cif.php +11 -10
  137. app/code/community/TIG/PostNL/Model/DeliveryOptions/Observer/UpdatePostnlOrder.php +65 -18
  138. app/code/community/TIG/PostNL/Model/DeliveryOptions/Product/Attribute/Source/ShippingDuration.php +1 -1
  139. app/code/community/TIG/PostNL/Model/DeliveryOptions/Service.php +9 -6
  140. app/code/community/TIG/PostNL/Model/ExtensionControl/Feed.php +4 -4
  141. app/code/community/TIG/PostNL/Model/ExtensionControl/Webservices.php +354 -43
  142. app/code/community/TIG/PostNL/Model/Inbox.php +3 -147
  143. app/code/community/TIG/PostNL/Model/Mijnpakket/Observer/Onepage.php +0 -123
  144. app/code/community/TIG/PostNL/Model/Parcelware/Export.php +12 -10
  145. app/code/community/TIG/PostNL/Model/Payment/Cod.php +373 -0
  146. app/code/community/TIG/PostNL/Model/Payment/Observer/Cod.php +171 -0
  147. app/code/community/TIG/PostNL/Model/Payment/Order/Creditmemo/Total/CodFee.php +247 -0
  148. app/code/community/TIG/PostNL/Model/Payment/Order/Creditmemo/Total/CodFee/Abstract.php +210 -0
  149. app/code/community/TIG/PostNL/Model/Payment/Order/Creditmemo/Total/CodFeeTax.php +129 -0
  150. app/code/community/TIG/PostNL/Model/Payment/Order/Invoice/Total/CodFee.php +87 -0
  151. app/code/community/TIG/PostNL/Model/Payment/Order/Invoice/Total/CodFeeTax.php +107 -0
  152. app/code/community/TIG/PostNL/Model/Payment/Order/Invoice/Total/Subtotal.php +143 -0
  153. app/code/community/TIG/PostNL/Model/Payment/Order/Pdf/Total/CodFee.php +165 -0
  154. app/code/community/TIG/PostNL/Model/Payment/Order/Pdf/Total/Grandtotal.php +127 -0
  155. app/code/community/TIG/PostNL/Model/Payment/Order/Pdf/Total/Tax.php +127 -0
  156. app/code/community/TIG/PostNL/Model/Payment/Quote/Address/Total/CodFee.php +221 -0
app/code/community/TIG/PostNL/Block/Adminhtml/CronNotification.php CHANGED
@@ -110,11 +110,13 @@ class TIG_PostNL_Block_Adminhtml_CronNotification extends TIG_PostNL_Block_Admin
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.
112
  */
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
 
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.
112
  */
113
+ $currentTime = new DateTime();
114
+ $currentTime->setTimestamp(Mage::getModel('core/date')->gmtTimestamp());
 
115
 
116
+ $oneHourAgo = $currentTime->sub(new DateInterval('PT1H'));
117
+ $lastExecutionTime = new DateTime($lastExecutionTime);
118
+
119
+ if ($lastExecutionTime < $oneHourAgo) {
120
  return false;
121
  }
122
 
app/code/community/TIG/PostNL/Block/Adminhtml/LogNotification.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 hasMaxLogSize()
40
+ * @method TIG_PostNL_Block_Adminhtml_LogNotification setMaxLogSize(int $value)
41
+ */
42
+ class TIG_PostNL_Block_Adminhtml_LogNotification extends TIG_PostNL_Block_Adminhtml_Template
43
+ {
44
+ /**
45
+ * @var string
46
+ */
47
+ protected $_eventPrefix = 'postnl_adminhtml_lognotification';
48
+
49
+ /**
50
+ * Gets the maximum allowed log size for all PostNL logs.
51
+ *
52
+ * @return mixed
53
+ */
54
+ public function getMaxLogSize()
55
+ {
56
+ if ($this->hasMaxLogSize()) {
57
+ return $this->_getData('max_log_size');
58
+ }
59
+
60
+ /**
61
+ * @var $logModelClass TIG_PostNL_Model_Adminhtml_Support_Logs
62
+ */
63
+ $logModelClass = Mage::getConfig()->getModelClassName('postnl_adminhtml/support_logs');
64
+ $maxSize = $logModelClass::LOG_MAX_TOTAL_SIZE;
65
+
66
+ $this->setMaxLogSize($maxSize);
67
+ return $maxSize;
68
+ }
69
+
70
+ /**
71
+ * Get the total size of all PostNL log files.
72
+ *
73
+ * @return int
74
+ */
75
+ public function getLogSize()
76
+ {
77
+ /**
78
+ * Get the folder where all PostNL logs are stored and make sure it exists.
79
+ */
80
+ $logFolder = Mage::getBaseDir('var') . DS . 'log' . DS . 'TIG_PostNL';
81
+ if (!is_dir($logFolder)) {
82
+ return 0;
83
+ }
84
+
85
+ /**
86
+ * Get all log files in the PostNL log folder.
87
+ */
88
+ $logs = glob($logFolder . DS . '*.log');
89
+
90
+ /**
91
+ * Calculate the sum of the file sizes of all logs in the PostNL log folder.
92
+ */
93
+ $totalSize = 0;
94
+ foreach ($logs as $log) {
95
+ /**
96
+ * Make sure the log is a file and is readable.
97
+ */
98
+ if (!is_file($log) || !is_readable($log)) {
99
+ continue;
100
+ }
101
+
102
+ $fileSize = filesize($log);
103
+
104
+ /**
105
+ * Add the log's file size to the total size of all valid logs and add the log to the array.
106
+ */
107
+ $totalSize += $fileSize;
108
+ }
109
+
110
+ return $totalSize;
111
+ }
112
+
113
+ /**
114
+ * Get whether the size of all PostNL logs exceeds the maximum allowed.
115
+ *
116
+ * @return bool
117
+ */
118
+ public function logsExceedMaxSize()
119
+ {
120
+ $maxSize = $this->getMaxLogSize();
121
+ $logSize = $this->getLogSize();
122
+
123
+ if ($logSize > $maxSize) {
124
+ return true;
125
+ }
126
+
127
+ return false;
128
+ }
129
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Items/Column/Qty.php ADDED
@@ -0,0 +1,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.
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_Sales_Items_Column_Qty extends Mage_Adminhtml_Block_Sales_Items_Column_Qty
40
+ {
41
+ /**
42
+ * The original template used by Magento.
43
+ */
44
+ const DEFAULT_TEMPLATE = 'sales/items/column/qty.phtml';
45
+
46
+ /**
47
+ * Attribute code used to determine how many of this product would fit in a letter box parcel.
48
+ */
49
+ const MAX_QTY_ATTRIBUTE_CODE = 'postnl_max_qty_for_buspakje';
50
+
51
+ /**
52
+ * Gets the maximum qty allowed for buspakje.
53
+ *
54
+ * @return int|string
55
+ */
56
+ public function getMaxQtyForBuspakje()
57
+ {
58
+ /**
59
+ * @var Mage_Sales_Model_Order_Item $item
60
+ */
61
+ $item = $this->getItem();
62
+
63
+ $childrenItems = $item->getChildrenItems();
64
+ if (!$childrenItems) {
65
+ $maxQty = Mage::getResourceModel('postnl/catalog_product')->getAttributeRawValue(
66
+ $item->getProductId(),
67
+ self::MAX_QTY_ATTRIBUTE_CODE,
68
+ $item->getStoreId()
69
+ );
70
+
71
+ return (int) $maxQty;
72
+ }
73
+
74
+ $maxQty = false;
75
+ /**
76
+ * @var Mage_Sales_Model_Order_Item $childItem
77
+ */
78
+ foreach ($childrenItems as $childItem) {
79
+ $maxChildQty = Mage::getResourceModel('postnl/catalog_product')->getAttributeRawValue(
80
+ $childItem->getProductId(),
81
+ self::MAX_QTY_ATTRIBUTE_CODE,
82
+ $childItem->getStoreId()
83
+ );
84
+
85
+ if ($maxQty === false
86
+ || $maxChildQty < $maxQty
87
+ ) {
88
+ $maxQty = $maxChildQty;
89
+ }
90
+ }
91
+
92
+ return (int) $maxQty;
93
+ }
94
+
95
+ /**
96
+ * Before rendering the template, check that the PostNl extension is active. If not, use the default Magento
97
+ * template.
98
+ *
99
+ * @return string
100
+ */
101
+ protected function _toHtml()
102
+ {
103
+ if (!Mage::helper('postnl')->isEnabled($this->getItem()->getStoreId())) {
104
+ $this->setTemplate(self::DEFAULT_TEMPLATE);
105
+ }
106
+
107
+ return parent::_toHtml();
108
+ }
109
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Create/Totals/CodFee.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
+ * @method Varien_Object getTotal()
40
+ */
41
+ class TIG_PostNL_Block_Adminhtml_Sales_Order_Create_Totals_CodFee extends Mage_Adminhtml_Block_Sales_Order_Create_Totals
42
+ {
43
+ /**
44
+ * Display modes for the PostNL COD fee.
45
+ */
46
+ const DISPLAY_MODE_EXCL = 1;
47
+ const DISPLAY_MODE_INCL = 2;
48
+ const DISPLAY_MODE_BOTH = 3;
49
+
50
+ /**
51
+ * Xpath to the PostNL COD fee display mode setting.
52
+ */
53
+ const XPATH_DISPLAY_MODE_COD_FEE = 'tax/cart_display/postnl_cod_fee';
54
+
55
+ /**
56
+ * @var string
57
+ */
58
+ protected $_template = 'TIG/PostNL/sales/order/create/totals/cod_fee.phtml';
59
+
60
+ /**
61
+ * Get the display mode for the PostNL COD fee.
62
+ *
63
+ * @return int
64
+ */
65
+ public function getDisplayMode()
66
+ {
67
+ $displayMode = (int) Mage::getStoreConfig(self::XPATH_DISPLAY_MODE_COD_FEE, $this->_store);
68
+
69
+ return $displayMode;
70
+ }
71
+
72
+ /**
73
+ * Get the tax label for either incl. or excl. tax.
74
+ *
75
+ * @param boolean $inclTax
76
+ *
77
+ * @return string
78
+ */
79
+ public function getTaxLabel($inclTax = false)
80
+ {
81
+ $taxLabel = Mage::helper('tax')->getIncExcTaxLabel($inclTax);
82
+
83
+ return $taxLabel;
84
+ }
85
+
86
+ /**
87
+ * Get the PostNL COD fee value incl or excl. tax.
88
+ *
89
+ * @param bool $inclTax
90
+ *
91
+ * @return bool
92
+ */
93
+ public function getValue($inclTax = false)
94
+ {
95
+ $address = $this->getTotal()->getAddress();
96
+
97
+ $exclTax = $address->getPostnlCodFee();
98
+ if (!$inclTax) {
99
+ return $exclTax;
100
+ }
101
+
102
+ $inclTax = $exclTax + $address->getPostnlCodFeeTax();
103
+ return $inclTax;
104
+ }
105
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Creditmemo/Create/CodFee.php ADDED
@@ -0,0 +1,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.
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_Sales_Order_Creditmemo_Create_CodFee extends Mage_Adminhtml_Block_Template
40
+ {
41
+ /**
42
+ * Xpath to the PostNL COD fee including tax setting.
43
+ */
44
+ const XPATH_COD_FEE_INCLUDING_TAX = 'tax/calculation/postnl_cod_fee_including_tax';
45
+
46
+ /**
47
+ * Source model.
48
+ *
49
+ * @var Mage_Sales_Model_Order_Creditmemo
50
+ */
51
+ protected $_source;
52
+
53
+ /**
54
+ * @var boolean|null
55
+ */
56
+ protected $_feeIsInclTax = null;
57
+
58
+ /**
59
+ * Initialize creditmemo PostNL COD fee totals
60
+ *
61
+ * @return $this
62
+ */
63
+ public function initTotals()
64
+ {
65
+ /**
66
+ * @var Mage_Adminhtml_Block_Sales_Order_Creditmemo_Totals $parent
67
+ */
68
+ $parent = $this->getParentBlock();
69
+
70
+ $this->_source = $parent->getSource();
71
+
72
+ $total = new Varien_Object(
73
+ array(
74
+ 'code' => 'postnl_cod_fee',
75
+ 'block_name' => $this->getNameInLayout()
76
+ )
77
+ );
78
+
79
+ $parent->addTotalBefore($total, 'agjustments');
80
+
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * Get the source model.
86
+ *
87
+ * @return Mage_Sales_Model_Order_Creditmemo
88
+ */
89
+ public function getSource()
90
+ {
91
+ return $this->_source;
92
+ }
93
+
94
+ /**
95
+ * get whether the fee is incl or excl tax.
96
+ *
97
+ * @return boolean
98
+ */
99
+ public function getFeeIsInclTax()
100
+ {
101
+ if ($this->_feeIsInclTax !== null) {
102
+ return $this->_feeIsInclTax;
103
+ }
104
+
105
+ $source = $this->getSource();
106
+
107
+ $feeIsInclTax = Mage::getStoreConfigFlag(self::XPATH_COD_FEE_INCLUDING_TAX, $source->getStoreId());
108
+
109
+ $this->setFeeIsInclTax($feeIsInclTax);
110
+ return $feeIsInclTax;
111
+ }
112
+
113
+ /**
114
+ * @param bool $feeIsInclTax
115
+ *
116
+ * @return $this
117
+ */
118
+ public function setFeeIsInclTax($feeIsInclTax)
119
+ {
120
+ $this->_feeIsInclTax = $feeIsInclTax;
121
+
122
+ return $this;
123
+ }
124
+
125
+ /**
126
+ * Get the fee amount.
127
+ *
128
+ * @return float
129
+ */
130
+ public function getCodFeeAmount()
131
+ {
132
+ $source = $this->getSource();
133
+
134
+ $feeAmount = $source->getBasePostnlCodFee();
135
+ if ($this->getFeeIsInclTax()) {
136
+ $feeAmount += $source->getBasePostnlCodFeeTax();
137
+ }
138
+
139
+ $feeAmount = Mage::app()->getStore()->roundPrice($feeAmount) * 1;
140
+ return $feeAmount;
141
+ }
142
+
143
+ /**
144
+ * Get the fee label.
145
+ *
146
+ * @return string
147
+ */
148
+ public function getCodFeeLabel()
149
+ {
150
+ $source = $this->getSource();
151
+
152
+ $label = Mage::helper('postnl/payment')->getPostnlCodFeeLabel($source->getStoreId());
153
+
154
+ $label .= ' ' . Mage::helper('tax')->getIncExcTaxLabel($this->getFeeIsInclTax());
155
+
156
+ return $label;
157
+ }
158
+
159
+ /**
160
+ * If no fee is available, return an empty string.
161
+ *
162
+ * @return string
163
+ */
164
+ protected function _toHtml()
165
+ {
166
+ if (!$this->_source->getPostnlCodFee()) {
167
+ return '';
168
+ }
169
+
170
+ return parent::_toHtml();
171
+ }
172
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Creditmemo/Totals/CodFee.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Sales_Order_Creditmemo_Totals_CodFee
40
+ extends Mage_Adminhtml_Block_Sales_Order_Creditmemo_Totals
41
+ {
42
+ /**
43
+ * Display modes for the PostNL COD fee.
44
+ */
45
+ const DISPLAY_MODE_EXCL = 1;
46
+ const DISPLAY_MODE_INCL = 2;
47
+ const DISPLAY_MODE_BOTH = 3;
48
+
49
+ /**
50
+ * Xpath to the PostNL COD fee display mode setting.
51
+ */
52
+ const XPATH_DISPLAY_MODE_COD_FEE = 'tax/sales_display/postnl_cod_fee';
53
+
54
+ /**
55
+ * Initialize order totals array
56
+ *
57
+ * @return $this
58
+ */
59
+ public function initTotals()
60
+ {
61
+ /**
62
+ * @var Mage_Adminhtml_Block_Sales_Order_Invoice_Totals $parent
63
+ * @var Mage_Sales_Model_Order_Creditmemo $creditmemo
64
+ */
65
+ $parent = $this->getParentBlock();
66
+ $creditmemo = $this->getCreditmemo();
67
+
68
+ $fee = $creditmemo->getPostnlCodFee();
69
+ $baseFee = $creditmemo->getBasePostnlCodFee();
70
+
71
+ if ($fee < 0.01 || $baseFee < 0.01) {
72
+ return $this;
73
+ }
74
+
75
+ $displayMode = $this->getDisplayMode();
76
+ $baseLabel = Mage::helper('postnl/payment')->getPostnlCodFeeLabel($creditmemo->getStoreId());
77
+
78
+ if ($displayMode === self::DISPLAY_MODE_EXCL
79
+ || $displayMode === self::DISPLAY_MODE_BOTH
80
+ && $creditmemo->getId()
81
+ ) {
82
+ $label = $baseLabel;
83
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
84
+ $label .= ' (' . $this->getTaxLabel(false) . ')';
85
+ }
86
+
87
+ $total = new Varien_Object();
88
+ $total->setLabel($label)
89
+ ->setValue($fee)
90
+ ->setBaseValue($baseFee)
91
+ ->setCode('postnl_cod_fee');
92
+
93
+ $parent->addTotal($total, 'subtotal_incl');
94
+ }
95
+
96
+ if ($displayMode === self::DISPLAY_MODE_INCL
97
+ || $displayMode === self::DISPLAY_MODE_BOTH
98
+ && $creditmemo->getId()
99
+ ) {
100
+ $label = $baseLabel;
101
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
102
+ $label .= ' (' . $this->getTaxLabel(true) . ')';
103
+ }
104
+
105
+ $totalInclTax = new Varien_Object();
106
+ $totalInclTax->setLabel($label)
107
+ ->setValue($fee + $creditmemo->getPostnlCodFeeTax())
108
+ ->setBaseValue($baseFee + $creditmemo->getBasePostnlCodFeeTax())
109
+ ->setCode('postnl_cod_fee_incl_tax');
110
+
111
+ $parent->addTotal($totalInclTax, 'subtotal_incl');
112
+ }
113
+
114
+ return $this;
115
+ }
116
+
117
+ /**
118
+ * Get the display mode for the PostNL COD fee.
119
+ *
120
+ * @return int
121
+ */
122
+ public function getDisplayMode()
123
+ {
124
+ $displayMode = (int) Mage::getStoreConfig(self::XPATH_DISPLAY_MODE_COD_FEE, $this->_store);
125
+
126
+ return $displayMode;
127
+ }
128
+
129
+ /**
130
+ * Get the tax label for either incl. or excl. tax.
131
+ *
132
+ * @param boolean $inclTax
133
+ *
134
+ * @return string
135
+ */
136
+ public function getTaxLabel($inclTax = false)
137
+ {
138
+ $taxLabel = Mage::helper('tax')->getIncExcText($inclTax);
139
+
140
+ return $taxLabel;
141
+ }
142
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Invoice/Totals/CodFee.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Sales_Order_Invoice_Totals_CodFee
40
+ extends Mage_Adminhtml_Block_Sales_Order_Invoice_Totals
41
+ {
42
+ /**
43
+ * Display modes for the PostNL COD fee.
44
+ */
45
+ const DISPLAY_MODE_EXCL = 1;
46
+ const DISPLAY_MODE_INCL = 2;
47
+ const DISPLAY_MODE_BOTH = 3;
48
+
49
+ /**
50
+ * Xpath to the PostNL COD fee display mode setting.
51
+ */
52
+ const XPATH_DISPLAY_MODE_COD_FEE = 'tax/sales_display/postnl_cod_fee';
53
+
54
+ /**
55
+ * Initialize order totals array
56
+ *
57
+ * @return $this
58
+ */
59
+ public function initTotals()
60
+ {
61
+ /**
62
+ * @var Mage_Adminhtml_Block_Sales_Order_Invoice_Totals $parent
63
+ */
64
+ $parent = $this->getParentBlock();
65
+ $invoice = $this->getInvoice();
66
+
67
+ if (!$invoice) {
68
+ return $this;
69
+ }
70
+
71
+ $fee = $invoice->getPostnlCodFee();
72
+ $baseFee = $invoice->getBasePostnlCodFee();
73
+
74
+ if ($fee < 0.01 || $baseFee < 0.01) {
75
+ return $this;
76
+ }
77
+
78
+ $displayMode = $this->getDisplayMode();
79
+ $baseLabel = Mage::helper('postnl/payment')->getPostnlCodFeeLabel($invoice->getStoreId());
80
+
81
+ if ($displayMode === self::DISPLAY_MODE_EXCL || $displayMode === self::DISPLAY_MODE_BOTH) {
82
+ $label = $baseLabel;
83
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
84
+ $label .= ' (' . $this->getTaxLabel(false) . ')';
85
+ }
86
+
87
+ $total = new Varien_Object();
88
+ $total->setLabel($label)
89
+ ->setValue($fee)
90
+ ->setBaseValue($baseFee)
91
+ ->setCode('postnl_cod_fee');
92
+
93
+ $parent->addTotalBefore($total, 'shipping');
94
+ }
95
+
96
+ if ($displayMode === self::DISPLAY_MODE_INCL || $displayMode === self::DISPLAY_MODE_BOTH) {
97
+ $label = $baseLabel;
98
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
99
+ $label .= ' (' . $this->getTaxLabel(true) . ')';
100
+ }
101
+
102
+ $totalInclTax = new Varien_Object();
103
+ $totalInclTax->setLabel($label)
104
+ ->setValue($fee + $invoice->getPostnlCodFeeTax())
105
+ ->setBaseValue($baseFee + $invoice->getBasePostnlCodFeeTax())
106
+ ->setCode('postnl_cod_fee_incl_tax');
107
+
108
+ $parent->addTotalBefore($totalInclTax, 'shipping');
109
+ }
110
+
111
+ return $this;
112
+ }
113
+
114
+ /**
115
+ * Get the display mode for the PostNL COD fee.
116
+ *
117
+ * @return int
118
+ */
119
+ public function getDisplayMode()
120
+ {
121
+ $displayMode = (int) Mage::getStoreConfig(self::XPATH_DISPLAY_MODE_COD_FEE, $this->_store);
122
+
123
+ return $displayMode;
124
+ }
125
+
126
+ /**
127
+ * Get the tax label for either incl. or excl. tax.
128
+ *
129
+ * @param boolean $inclTax
130
+ *
131
+ * @return string
132
+ */
133
+ public function getTaxLabel($inclTax = false)
134
+ {
135
+ $taxLabel = Mage::helper('tax')->getIncExcText($inclTax);
136
+
137
+ return $taxLabel;
138
+ }
139
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/ProductOptions.php CHANGED
@@ -104,7 +104,7 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_ProductOptions extends TIG_PostNL_B
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
  */
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
  */
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/Create/ShipmentOptions.php CHANGED
@@ -35,9 +35,24 @@
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
  */
@@ -46,12 +61,12 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
46
  /**
47
  * Get current shipment
48
  *
49
- * @return Mage_Sales_Model_Order_Shipment
50
  */
51
  public function getShipment()
52
  {
53
- if ($this->getData('shipment')) {
54
- return $this->getData('shipment');
55
  }
56
 
57
  $shipment = Mage::registry('current_shipment');
@@ -61,14 +76,14 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
61
  }
62
 
63
  /**
64
- * Get available product options for the current shipment
65
  *
66
  * @return array
67
  */
68
  public function getProductOptions()
69
  {
70
- if ($this->getData('product_options')) {
71
- return $this->getData('product_options');
72
  }
73
 
74
  $shipment = $this->getShipment();
@@ -80,26 +95,76 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
80
  }
81
 
82
  /**
83
- * Get the default product option for the current shipment
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  *
85
  * @return string
86
  */
87
  public function getDefaultProductOption()
88
  {
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
  */
@@ -111,7 +176,7 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
111
  }
112
 
113
  /**
114
- * Check if the current shipment is belgian
115
  *
116
  * @return boolean
117
  */
@@ -126,7 +191,7 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
126
  }
127
 
128
  /**
129
- * Gets the number of parcels in this shipment based on it's weight
130
  *
131
  * @return int
132
  */
@@ -134,14 +199,53 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
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
  */
@@ -154,8 +258,7 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions ext
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
 
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 hasShipment()
40
+ * @method boolean hasProductOptions()
41
+ * @method boolean hasBuspakjeProductOptions()
42
+ * @method boolean hasDefaultProductOption()
43
+ *
44
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions setShipment(Mage_Sales_Model_Order_Shipment $value)
45
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions setProductOptions(array $value)
46
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions setDefaultProductOption(string $value)
47
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions setBuspakjeProductOptions(array $value)
48
  */
49
  class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions extends TIG_PostNL_Block_Adminhtml_Template
50
  {
51
+ /**
52
+ * Xpath to the buspakje calculation mode setting.
53
+ */
54
+ const XPATH_BUSPAKJE_CALC_MODE = 'postnl/cif_labels_and_confirming/buspakje_calculation_mode';
55
+
56
  /**
57
  * @var string
58
  */
61
  /**
62
  * Get current shipment
63
  *
64
+ * @return Mage_Sales_Model_Order_Shipment.
65
  */
66
  public function getShipment()
67
  {
68
+ if ($this->hasShipment()) {
69
+ return $this->_getData('shipment');
70
  }
71
 
72
  $shipment = Mage::registry('current_shipment');
76
  }
77
 
78
  /**
79
+ * Get available product options for the current shipment.
80
  *
81
  * @return array
82
  */
83
  public function getProductOptions()
84
  {
85
+ if ($this->hasProductOptions()) {
86
+ return $this->_getData('product_options');
87
  }
88
 
89
  $shipment = $this->getShipment();
95
  }
96
 
97
  /**
98
+ * Gets all allowed buspakje product options.
99
+ *
100
+ * @return array
101
+ */
102
+ public function getBuspakjeProductOptions()
103
+ {
104
+ if ($this->hasBuspakjeProductOptions()) {
105
+ return $this->getData('buspakje_product_options');
106
+ }
107
+
108
+ $productOptions = Mage::helper('postnl/cif')->getBuspakjeProductCodes(false);
109
+
110
+ $this->setBuspakjeProductOptions($productOptions);
111
+ return $productOptions;
112
+ }
113
+
114
+ /**
115
+ * Get the default product option for the current shipment.
116
  *
117
  * @return string
118
  */
119
  public function getDefaultProductOption()
120
  {
121
+ if ($this->hasDefaultProductOption()) {
122
+ return $this->_getData('default_product_option');
123
  }
124
 
125
  $shipment = $this->getShipment();
126
 
127
+ try {
128
+ $productOption = Mage::helper('postnl/cif')->getDefaultProductOptionForShipment($shipment);
129
+ } catch (Exception $e) {
130
+ Mage::helper('postnl')->logException($e);
131
+
132
+ $productOption = '';
133
+ }
134
 
135
  $this->setDefaultProductOption($productOption);
136
  return $productOption;
137
  }
138
 
139
  /**
140
+ * Get the default product option for the current shipment.
141
+ *
142
+ * @return string
143
+ */
144
+ public function getDefaultBuspakjeOption()
145
+ {
146
+ if ($this->hasDefaultBuspakjeOption()) {
147
+ return $this->_getData('default_buspakje_option');
148
+ }
149
+
150
+ $postnlShipment = Mage::getModel('postnl_core/shipment')
151
+ ->setShipmentType('buspakje')
152
+ ->setStoreId($this->getShipment()->getStoreId());
153
+
154
+ try {
155
+ $productOption = $postnlShipment->getDefaultProductCode();
156
+ } catch (Exception $e) {
157
+ Mage::helper('postnl')->logException($e);
158
+
159
+ $productOption = '';
160
+ }
161
+
162
+ $this->setDefaultBuspakjeOption($productOption);
163
+ return $productOption;
164
+ }
165
+
166
+ /**
167
+ * Gets an array of shipment types for use with GlobalPack shipments.
168
  *
169
  * @return array
170
  */
176
  }
177
 
178
  /**
179
+ * Check if the current shipment is belgian.
180
  *
181
  * @return boolean
182
  */
191
  }
192
 
193
  /**
194
+ * Gets the number of parcels in this shipment based on it's weight.
195
  *
196
  * @return int
197
  */
199
  {
200
  $shipment = $this->getShipment();
201
 
202
+ $parcelCount = (int) Mage::helper('postnl/cif')->getParcelCount($shipment);
203
+ if ($parcelCount < 1) {
204
+ $parcelCount = 1;
205
+ }
206
+
207
  return $parcelCount;
208
  }
209
 
210
  /**
211
+ * Check whether the current shipment would fit as a buspakje.
212
+ *
213
+ * @return bool
214
+ */
215
+ public function getFitsAsBuspakje()
216
+ {
217
+ $shipment = $this->getShipment();
218
+ $items = $shipment->getAllItems();
219
+
220
+ /**
221
+ * @var Mage_Sales_Model_Order_Shipment_Item $item
222
+ */
223
+ $orderItems = array();
224
+ foreach ($items as $item) {
225
+ $orderItems[] = $item->getOrderItem()->setQtyOrdered($item->getQty());
226
+ }
227
+
228
+ $fits = Mage::helper('postnl')->fitsAsBuspakje($orderItems, true);
229
+
230
+ return $fits;
231
+ }
232
+
233
+ /**
234
+ * Gets the configured calculation mode for buspakje shipments.
235
  *
236
+ * @return mixed
237
+ */
238
+ public function getBuspakjeCalcMode()
239
+ {
240
+ $calcMode = Mage::getStoreConfig(self::XPATH_BUSPAKJE_CALC_MODE, Mage_Core_Model_App::ADMIN_STORE_ID);
241
+
242
+ return $calcMode;
243
+ }
244
+
245
+ /**
246
+ * Do a few checks to see if the template should be rendered before actually rendering it.
247
+ *
248
+ * @return string
249
  *
250
  * @see Mage_Adminhtml_Block_Abstract::_toHtml()
251
  */
258
 
259
  $shipment = $this->getShipment();
260
 
261
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shipment->getOrder()->getShippingMethod())) {
 
262
  return '';
263
  }
264
 
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/DeliveryOptions.php ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 hasPostnlShipment()
40
+ *
41
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_View_DeliveryOptions setPostnlShipment(TIG_PostNL_Model_Core_Shipment $value)
42
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_View_DeliveryOptions setIsCod(boolean $value)
43
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_View_DeliveryOptions setSubType(string $value)
44
+ *
45
+ * @method boolean getIsCod()
46
+ * @method string getSubType()
47
+ */
48
+ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_DeliveryOptions
49
+ extends TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_Create_ShipmentOptions
50
+ {
51
+ /**
52
+ * @var string
53
+ */
54
+ protected $_eventPrefix = 'postnl_adminhtml_sales_order_shipment_view_deliveryoptions';
55
+
56
+ /**
57
+ * @var string
58
+ */
59
+ protected $_template = 'TIG/PostNL/sales/order/shipment/view/delivery_options.phtml';
60
+
61
+ /**
62
+ * Prepares layout of block
63
+ *
64
+ * @return $this
65
+ */
66
+ protected function _prepareLayout()
67
+ {
68
+ $onclick = "changeProductCode('{$this->getChangeProductCodeUrl()}')";
69
+
70
+ $block = $this->getLayout()
71
+ ->createBlock('adminhtml/widget_button')
72
+ ->setData(
73
+ array(
74
+ 'label' => $this->__('Change'),
75
+ 'class' => 'btn-reset',
76
+ 'onclick' => $onclick
77
+ )
78
+ );
79
+
80
+ $this->setChild('change_product_code_button', $block);
81
+
82
+ return parent::_prepareLayout();
83
+ }
84
+
85
+ /**
86
+ * @return TIG_PostNL_Model_Core_Shipment
87
+ */
88
+ public function getPostnlShipment()
89
+ {
90
+ if ($this->hasPostnlShipment()) {
91
+ return $this->_getData('postnl_shipment');
92
+ }
93
+
94
+ $shipment = $this->getShipment();
95
+
96
+ $postnlShipment = Mage::getModel('postnl_core/shipment')->loadByShipment($shipment);
97
+
98
+ $this->setPostnlShipment($postnlShipment);
99
+ return $postnlShipment;
100
+ }
101
+
102
+ /**
103
+ * Get available product options for the current shipment.
104
+ *
105
+ * @return array
106
+ */
107
+ public function getProductOptions()
108
+ {
109
+ if ($this->hasProductOptions()) {
110
+ return $this->_getData('product_options');
111
+ }
112
+
113
+ $shipment = $this->getPostnlShipment();
114
+
115
+ $productOptions = Mage::helper('postnl/cif')->getProductOptionsForShipment($shipment);
116
+
117
+ $this->setProductOptions($productOptions);
118
+ return $productOptions;
119
+ }
120
+
121
+ /**
122
+ * Get the shipment type for the current order.
123
+ *
124
+ * @return string
125
+ */
126
+ public function getShipmentType()
127
+ {
128
+ $postnlShipment = $this->getPostnlShipment();
129
+ $shipmentType = $postnlShipment->getShipmentType();
130
+
131
+ switch ($shipmentType) {
132
+ case $postnlShipment::SHIPMENT_TYPE_DOMESTIC:
133
+ $shipmentType = $this->__('Domestic');
134
+ break;
135
+ case $postnlShipment::SHIPMENT_TYPE_DOMESTIC_COD:
136
+ $shipmentType = $this->__('Domestic');
137
+ $this->setIsCod(true);
138
+ break;
139
+ case $postnlShipment::SHIPMENT_TYPE_AVOND:
140
+ $shipmentType = $this->__('Domestic');
141
+ $this->setSubType('Evening Delivery');
142
+ break;
143
+ case $postnlShipment::SHIPMENT_TYPE_AVOND_COD:
144
+ $shipmentType = $this->__('Domestic');
145
+ $this->setSubType('Evening Delivery');
146
+ $this->setIsCod(true);
147
+ break;
148
+ case $postnlShipment::SHIPMENT_TYPE_PG:
149
+ $shipmentType = $this->__('Post Office');
150
+ break;
151
+ case $postnlShipment::SHIPMENT_TYPE_PG_COD:
152
+ $shipmentType = $this->__('Post Office');
153
+ $this->setIsCod(true);
154
+ break;
155
+ case $postnlShipment::SHIPMENT_TYPE_PGE:
156
+ $shipmentType = $this->__('Post Office');
157
+ $this->setSubType('Early Pickup');
158
+ break;
159
+ case $postnlShipment::SHIPMENT_TYPE_PGE_COD:
160
+ $shipmentType = $this->__('Post Office');
161
+ $this->setSubType('Early Pickup');
162
+ $this->setIsCod(true);
163
+ break;
164
+ case $postnlShipment::SHIPMENT_TYPE_PA:
165
+ $shipmentType = $this->__('Parcel Dispenser');
166
+ break;
167
+ case $postnlShipment::SHIPMENT_TYPE_EPS:
168
+ $shipmentType = $this->__('EPS');
169
+ break;
170
+ case $postnlShipment::SHIPMENT_TYPE_GLOBALPACK:
171
+ $shipmentType = $this->__('GlobalPack');
172
+ break;
173
+ case $postnlShipment::SHIPMENT_TYPE_BUSPAKJE:
174
+ $shipmentType = $this->__('Letter Box Parcel');
175
+ break;
176
+ }
177
+
178
+ return $shipmentType;
179
+ }
180
+
181
+ /**
182
+ * Get the current order's sub type.
183
+ *
184
+ * @return boolean|string
185
+ */
186
+ public function getShipmentSubType()
187
+ {
188
+ $subType = $this->getSubType();
189
+
190
+ if (!$subType) {
191
+ return false;
192
+ }
193
+
194
+ $isCod = $this->getIsCod();
195
+ if (!$isCod) {
196
+ return $subType;
197
+ }
198
+
199
+ $subType .= ' + ' . $this->__('COD');
200
+ return $subType;
201
+ }
202
+
203
+ /**
204
+ * @return bool
205
+ */
206
+ public function canChangeProductCode()
207
+ {
208
+ $postnlShipment = $this->getPostnlShipment();
209
+
210
+ /**
211
+ * Check if the current user is allowed to perform this action.
212
+ */
213
+ if (!Mage::helper('postnl')->checkIsPostnlActionAllowed(array('change_product_code'))) {
214
+ return false;
215
+ }
216
+
217
+ return $postnlShipment->canChangeProductCode();
218
+ }
219
+
220
+ /**
221
+ * Retrieve the change_product_code_button html.
222
+ *
223
+ * @return string
224
+ */
225
+ public function getChangeProductCodeButtonHtml()
226
+ {
227
+ return $this->getChildHtml('change_product_code_button');
228
+ }
229
+
230
+ /**
231
+ * Get the changeProductUrl for this shipment.
232
+ *
233
+ * @return string
234
+ */
235
+ public function getChangeProductCodeUrl()
236
+ {
237
+ $url = $this->getUrl(
238
+ 'postnl_admin/adminhtml_shipment/changeProductCode',
239
+ array(
240
+ 'shipment_id' => $this->getShipment()->getId()
241
+ )
242
+ );
243
+
244
+ return $url;
245
+ }
246
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/ShippingStatus.php CHANGED
@@ -62,6 +62,9 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_ShippingStatus extend
62
  */
63
  public function getShippingStatus($shipment)
64
  {
 
 
 
65
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
66
 
67
  /**
@@ -95,7 +98,7 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_ShippingStatus extend
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
  */
62
  */
63
  public function getShippingStatus($shipment)
64
  {
65
+ /**
66
+ * @var TIG_PostnL_Model_Core_Shipment $postnlShipment
67
+ */
68
  $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipment->getId(), 'shipment_id');
69
 
70
  /**
98
  /**
99
  * Checks if a given shipment has been confirmed with PostNL
100
  *
101
+ * @param Mage_Sales_Model_Order_Shipment $shipment
102
  *
103
  * @return boolean
104
  */
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tab/StatusHistory.php CHANGED
@@ -67,7 +67,7 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tab_StatusHistory ext
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
  */
67
  /**
68
  * Get the basic collection for this grid
69
  *
70
+ * @return $this
71
  *
72
  * @see Mage_Adminhtml_Block_Widget_Grid::_prepareCollection
73
  */
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tabs.php CHANGED
@@ -63,39 +63,48 @@ class TIG_PostNL_Block_Adminhtml_Sales_Order_Shipment_View_Tabs extends Mage_Adm
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'),
68
- 'content' => $this->getLayout()
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();
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(
67
+ 'shipment_info',
68
+ array(
69
+ 'label' => Mage::helper('sales')->__('Information'),
70
+ 'content' => $this->getLayout()
71
+ ->getBlock('form')
72
+ ->toHtml(),
73
+ )
74
+ );
75
 
76
  /**
77
+ * Load a PosTNL shipment corresponding to the current Magento shipment.
78
+ *
79
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipment
80
  */
81
+ $shipment = Mage::registry('current_shipment');
82
+ $postnlShipment = Mage::getModel('postnl_core/shipment')->loadByShipment($shipment);
83
 
84
  /**
85
  * Only show the status history tab if a postnl shipment entity was found for the current shipment and the
86
+ * current admin user is allowed to view the complete shipment status history. If the shipment uses a custom
87
+ * barcode we also can't show the status history, because custom barcodes can't be tracked.
88
  */
89
  $historyAllowed = Mage::helper('postnl')->checkIsPostnlActionAllowed('view_complete_status');
90
+ if ($historyAllowed && $postnlShipment->getId() && !$postnlShipment->hasCustomBarcode()) {
91
  /**
92
  * Add the status history tab. This is added by PostNL
93
  */
94
+ $this->addTab(
95
+ 'shipment_status_history',
96
+ array(
97
+ 'label' => Mage::helper('postnl')->__('Shipping event history'),
98
+ 'url' => $this->getUrl(
99
+ 'postnl_admin/adminhtml_shipment/statusHistory',
100
+ array(
101
+ '_current' => true,
102
+ 'shipment_id' => $shipment->getId(),
103
+ )
104
+ ),
105
+ 'class' => 'ajax',
106
+ )
107
+ );
108
  }
109
 
110
  return parent::_prepareLayout();
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Totals/CodFee.php ADDED
@@ -0,0 +1,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.
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_Sales_Order_Totals_CodFee extends Mage_Adminhtml_Block_Sales_Order_Totals
40
+ {
41
+ /**
42
+ * Display modes for the PostNL COD fee.
43
+ */
44
+ const DISPLAY_MODE_EXCL = 1;
45
+ const DISPLAY_MODE_INCL = 2;
46
+ const DISPLAY_MODE_BOTH = 3;
47
+
48
+ /**
49
+ * Xpath to the PostNL COD fee display mode setting.
50
+ */
51
+ const XPATH_DISPLAY_MODE_COD_FEE = 'tax/sales_display/postnl_cod_fee';
52
+
53
+ /**
54
+ * Initialize order totals array
55
+ *
56
+ * @return $this
57
+ */
58
+ public function initTotals()
59
+ {
60
+ $parent = $this->getParentBlock();
61
+ $order = $this->getOrder();
62
+
63
+ $fee = $order->getPostnlCodFee();
64
+ $baseFee = $order->getBasePostnlCodFee();
65
+
66
+ if ($fee < 0.01 || $baseFee < 0.01) {
67
+ return $this;
68
+ }
69
+
70
+ $displayMode = $this->getDisplayMode();
71
+ $baseLabel = Mage::helper('postnl/payment')->getPostnlCodFeeLabel($order->getStoreId());
72
+
73
+ if ($displayMode === self::DISPLAY_MODE_EXCL || $displayMode === self::DISPLAY_MODE_BOTH) {
74
+ $label = $baseLabel;
75
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
76
+ $label .= ' (' . $this->getTaxLabel(false) . ')';
77
+ }
78
+
79
+ $total = new Varien_Object();
80
+ $total->setLabel($label)
81
+ ->setValue($fee)
82
+ ->setBaseValue($baseFee)
83
+ ->setCode('postnl_cod_fee');
84
+
85
+ $parent->addTotalBefore($total, 'shipping');
86
+ }
87
+
88
+ if ($displayMode === self::DISPLAY_MODE_INCL || $displayMode === self::DISPLAY_MODE_BOTH) {
89
+ $label = $baseLabel;
90
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
91
+ $label .= ' (' . $this->getTaxLabel(true) . ')';
92
+ }
93
+
94
+ $totalInclTax = new Varien_Object();
95
+ $totalInclTax->setLabel($label)
96
+ ->setValue($fee + $order->getPostnlCodFeeTax())
97
+ ->setBaseValue($baseFee + $order->getBasePostnlCodFeeTax())
98
+ ->setCode('postnl_cod_fee_incl_tax');
99
+
100
+ $parent->addTotalBefore($totalInclTax, 'shipping');
101
+ }
102
+
103
+ return $this;
104
+ }
105
+
106
+ /**
107
+ * Get the display mode for the PostNL COD fee.
108
+ *
109
+ * @return int
110
+ */
111
+ public function getDisplayMode()
112
+ {
113
+ $displayMode = (int) Mage::getStoreConfig(self::XPATH_DISPLAY_MODE_COD_FEE, $this->_store);
114
+
115
+ return $displayMode;
116
+ }
117
+
118
+ /**
119
+ * Get the tax label for either incl. or excl. tax.
120
+ *
121
+ * @param boolean $inclTax
122
+ *
123
+ * @return string
124
+ */
125
+ public function getTaxLabel($inclTax = false)
126
+ {
127
+ $taxLabel = Mage::helper('tax')->getIncExcText($inclTax);
128
+
129
+ return $taxLabel;
130
+ }
131
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/View/DeliveryOptions.php ADDED
@@ -0,0 +1,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.
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 hasOrder()
40
+ * @method boolean hasPostnlOrder()
41
+ *
42
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_View_DeliveryOptions setOrder(Mage_Sales_Model_Order $value)
43
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_View_DeliveryOptions setPostnlOrder(TIG_PostNL_Model_Core_Order $value)
44
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_View_DeliveryOptions setIsCod(boolean $value)
45
+ * @method TIG_PostNL_Block_Adminhtml_Sales_Order_View_DeliveryOptions setSubType(string $value)
46
+ *
47
+ * @method boolean getIsCod()
48
+ * @method string getSubType()
49
+ */
50
+ class TIG_PostNL_Block_Adminhtml_Sales_Order_View_DeliveryOptions extends TIG_PostNL_Block_Adminhtml_Template
51
+ {
52
+ /**
53
+ * @var string
54
+ */
55
+ protected $_eventPrefix = 'postnl_adminhtml_sales_order_view_deliveryoptions';
56
+
57
+ /**
58
+ * @var string
59
+ */
60
+ protected $_template = 'TIG/PostNL/sales/order/view/delivery_options.phtml';
61
+
62
+ /**
63
+ * @return Mage_Sales_Model_Order
64
+ */
65
+ public function getOrder()
66
+ {
67
+ if ($this->hasOrder()) {
68
+ return $this->_getData('order');
69
+ }
70
+
71
+ $order = Mage::registry('current_order');
72
+
73
+ $this->setOrder($order);
74
+ return $order;
75
+ }
76
+
77
+ /**
78
+ * @return TIG_PostNL_Model_Core_Order
79
+ */
80
+ public function getPostnlOrder()
81
+ {
82
+ if ($this->hasPostnlOrder()) {
83
+ return $this->_getData('postnl_order');
84
+ }
85
+
86
+ $order = $this->getOrder();
87
+
88
+ $postnlOrder = Mage::getModel('postnl_core/order')->loadByOrder($order);
89
+
90
+ $this->setPostnlOrder($postnlOrder);
91
+ return $postnlOrder;
92
+ }
93
+
94
+ /**
95
+ * Get the shipment type for the current order.
96
+ *
97
+ * @return string
98
+ */
99
+ public function getShipmentType()
100
+ {
101
+ $order = $this->getOrder();
102
+ $postnlOrder = $this->getPostnlOrder();
103
+
104
+ $paymentMethod = $order->getPayment()->getMethod();
105
+ $codPaymentMethods = Mage::helper('postnl/payment')->getCodPaymentMethods();
106
+ if (in_array($paymentMethod, $codPaymentMethods)) {
107
+ $this->setIsCod(true);
108
+ }
109
+
110
+ $shipmentType = false;
111
+ switch ($postnlOrder->getType()) {
112
+ case 'PA':
113
+ $shipmentType = $this->__('Parcel Dispenser');
114
+ break;
115
+ case 'PGE':
116
+ $this->setSubType($this->__('Early Pickup'));
117
+ $shipmentType = $this->__('Post Office');
118
+ break;
119
+ case 'PG':
120
+ $shipmentType = $this->__('Post Office');
121
+ break;
122
+ case 'Avond':
123
+ $this->setSubType($this->__('Evening Delivery'));
124
+ $shipmentType = $this->__('Domestic');
125
+ break;
126
+ case 'Overdag':
127
+ $shipmentType = $this->__('Domestic');
128
+ break;
129
+ }
130
+
131
+ if ($shipmentType) {
132
+ return $shipmentType;
133
+ }
134
+
135
+ $countryId = $order->getShippingAddress()->getCountryId();
136
+
137
+ if ($countryId == 'NL') {
138
+ $shipmentType = $this->__('Domestic');
139
+
140
+ return $shipmentType;
141
+ }
142
+
143
+ $euCountries = Mage::helper('postnl/cif')->getEuCountries();
144
+ if (in_array($countryId, $euCountries)) {
145
+ $shipmentType = $this->__('EPS');
146
+
147
+ return $shipmentType;
148
+ }
149
+
150
+ $shipmentType = $this->__('GlobalPack');
151
+
152
+ return $shipmentType;
153
+ }
154
+
155
+ /**
156
+ * Get the current order's sub type.
157
+ *
158
+ * @return boolean|string
159
+ */
160
+ public function getShipmentSubType()
161
+ {
162
+ $subType = $this->getSubType();
163
+
164
+ if (!$subType) {
165
+ return false;
166
+ }
167
+
168
+ $isCod = $this->getIsCod();
169
+ if (!$isCod) {
170
+ return $subType;
171
+ }
172
+
173
+ $subType .= ' + ' . $this->__('COD');
174
+ return $subType;
175
+ }
176
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form.php CHANGED
@@ -44,8 +44,8 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
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.
@@ -67,16 +67,17 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
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
  {
@@ -154,7 +155,27 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
154
  $helperName = $this->_configFields->getAttributeModule($section, $group);
155
  $fieldsetConfig = array('legend' => Mage::helper($helperName)->__((string)$group->label));
156
  if (!empty($group->comment)) {
157
- $fieldsetConfig['comment'] = Mage::helper($helperName)->__((string)$group->comment);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  }
159
  if (!empty($group->expanded)) {
160
  $fieldsetConfig['expanded'] = (bool)$group->expanded;
@@ -206,7 +227,8 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
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
@@ -266,6 +288,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
266
  }
267
  }
268
 
 
269
  $data = $this->_configDataObject->getConfigDataValue($path, $inherit, $this->_configData);
270
 
271
  /**
@@ -289,6 +312,10 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form extends Mage_Adminhtml_Block
289
  */
290
  $isBelowMinimumVersion = version_compare($version, $minimumVersion, '<');
291
 
 
 
 
 
292
  if (!$data && $isBelowMinimumVersion === true) {
293
  if (isset($this->_configData[$path])) {
294
  $data = $this->_configData[$path];
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.1';
48
+ const MINIMUM_ENTERPRISE_VERSION_COMPATIBILITY = '1.12.0.1';
49
 
50
  /**
51
  * Gets the fieldset parameter from the GET superglobal if available.
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
71
+ * a field can only depend on a field that is in the same fieldset or in a fieldset that is already initialized. An
72
+ * example: We have fieldset_a containing field_a. We also have fieldset_b containing field_b. If field_a depends on
73
+ * field_b, this is not possible. When field_a is initialized, fieldset_b and therefore field_b, will not yet have
74
+ * been initialized and will not be available.
75
  *
76
+ * We have split the initialization of fieldsets and fields. This way Magento will first initialize all fieldsets
77
+ * and then init all fields. So when field_a is initialized, fieldset_b is already available and the dependency will
78
+ * work.
79
  *
80
+ * @return $this
81
  */
82
  public function initForm()
83
  {
155
  $helperName = $this->_configFields->getAttributeModule($section, $group);
156
  $fieldsetConfig = array('legend' => Mage::helper($helperName)->__((string)$group->label));
157
  if (!empty($group->comment)) {
158
+ if (!empty($group->comment_url)) {
159
+ if (!empty($group->comment_url->base)) {
160
+ $baseUrl = (string) $group->comment_url->base;
161
+ } else {
162
+ $baseUrl = '';
163
+ }
164
+
165
+ $params = array();
166
+ if (!empty($group->comment_url->params)) {
167
+ foreach ($group->comment_url->params->asArray() as $param => $value) {
168
+ $params[$param] = $value;
169
+ }
170
+ }
171
+
172
+ $commentUrl = $this->getUrl($baseUrl, $params);
173
+
174
+ $comment = Mage::helper($helperName)->__((string)$group->comment, $commentUrl);
175
+ } else {
176
+ $comment = Mage::helper($helperName)->__((string)$group->comment);
177
+ }
178
+ $fieldsetConfig['comment'] = $comment;
179
  }
180
  if (!empty($group->expanded)) {
181
  $fieldsetConfig['expanded'] = (bool)$group->expanded;
227
 
228
  /**
229
  * Init fieldset fields. Copied from EE1.13 Mage_Adminhtml_Block_System_Config_Form::initFields to allow for
230
+ * cross-fieldset dependencies in CE 1.6 and 1.7.0.0, and EE 1.11 and 1.12.0.0. Only made a small change to core
231
+ * code for backwards compatibility.
232
  *
233
  * @param Varien_Data_Form_Element_Fieldset $fieldset
234
  * @param Varien_Simplexml_Element $group
288
  }
289
  }
290
 
291
+ $inherit = null;
292
  $data = $this->_configDataObject->getConfigDataValue($path, $inherit, $this->_configData);
293
 
294
  /**
312
  */
313
  $isBelowMinimumVersion = version_compare($version, $minimumVersion, '<');
314
 
315
+ /**
316
+ * If the current version is below the minimum version or if we have no data, use the old method of
317
+ * getting config data.
318
+ */
319
  if (!$data && $isBelowMinimumVersion === true) {
320
  if (isset($this->_configData[$path])) {
321
  $data = $this->_configData[$path];
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ActivateButton.php CHANGED
@@ -45,7 +45,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivateButton
45
  /**
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
@@ -58,7 +58,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ActivateButton
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 {
45
  /**
46
  * XML path to 'is_activated' flag
47
  */
48
+ const XPATH_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
58
  {
59
  $this->setElement($element);
60
 
61
+ $isActivated = Mage::getStoreConfig(self::XPATH_IS_ACTIVATED, Mage_Core_Model_App::ADMIN_STORE_ID);
62
  if ($isActivated === '1') {
63
  $label = $this->__('Finish activation');
64
  } else {
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ConfigCheck.php CHANGED
@@ -50,8 +50,8 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ConfigCheck
50
  /**
51
  * XML paths to use GlobalPack/Checkout settings.
52
  */
53
- const XML_PATH_USE_GLOBALPACK = 'postnl/cif/use_globalpack';
54
- const XML_PATH_USE_CHECKOUT = 'postnl/cif/use_checkout';
55
 
56
  /**
57
  * Template file used by this element.
@@ -136,7 +136,7 @@ class TIG_PostNL_Block_Adminhtml_System_Config_Form_Field_ConfigCheck
136
  */
137
  public function isGlobalConfigured()
138
  {
139
- $globalEnabled = Mage::getStoreConfigFlag(self::XML_PATH_USE_GLOBALPACK, Mage_Core_Model_App::ADMIN_STORE_ID);
140
  if (!$globalEnabled) {
141
  return true;
142
  }
50
  /**
51
  * XML paths to use GlobalPack/Checkout settings.
52
  */
53
+ const XPATH_USE_GLOBALPACK = 'postnl/cif/use_globalpack';
54
+ const XPATH_USE_CHECKOUT = 'postnl/cif/use_checkout';
55
 
56
  /**
57
  * Template file used by this element.
136
  */
137
  public function isGlobalConfigured()
138
  {
139
+ $globalEnabled = Mage::getStoreConfigFlag(self::XPATH_USE_GLOBALPACK, Mage_Core_Model_App::ADMIN_STORE_ID);
140
  if (!$globalEnabled) {
141
  return true;
142
  }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/HourMinute.php ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_HourMinute
40
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
41
+ {
42
+
43
+ /**
44
+ * Enter description here...
45
+ *
46
+ * @param Varien_Data_Form_Element_Abstract $element
47
+ * @return string
48
+ */
49
+ public function render(Varien_Data_Form_Element_Abstract $element)
50
+ {
51
+ $id = $element->getHtmlId();
52
+
53
+ $html = '<td class="label"><label for="'.$id.'">'.$element->getLabel().'</label></td>';
54
+
55
+ //$isDefault = !$this->getRequest()->getParam('website') && !$this->getRequest()->getParam('store');
56
+ $isMultiple = $element->getExtType()==='multiple';
57
+
58
+ // replace [value] with [inherit]
59
+ $namePrefix = preg_replace('#\[value\](\[\])?$#', '', $element->getName());
60
+
61
+ $options = $element->getValues();
62
+
63
+ $addInheritCheckbox = false;
64
+ if ($element->getCanUseWebsiteValue()) {
65
+ $addInheritCheckbox = true;
66
+ $checkboxLabel = Mage::helper('adminhtml')->__('Use Website');
67
+ }
68
+ elseif ($element->getCanUseDefaultValue()) {
69
+ $addInheritCheckbox = true;
70
+ $checkboxLabel = Mage::helper('adminhtml')->__('Use Default');
71
+ }
72
+
73
+ if ($addInheritCheckbox) {
74
+ $inherit = $element->getInherit()==1 ? 'checked="checked"' : '';
75
+ if ($inherit) {
76
+ $element->setDisabled(true);
77
+ }
78
+ }
79
+
80
+ if ($element->getTooltip()) {
81
+ $html .= '<td class="value with-tooltip">';
82
+ $html .= $this->_getElementHtml($element);
83
+ $html .= '<div class="field-tooltip"><div>' . $element->getTooltip() . '</div></div>';
84
+ } else {
85
+ $html .= '<td class="value">';
86
+ $html .= $this->_getElementHtml($element);
87
+ };
88
+ if ($element->getComment()) {
89
+ $html.= '<p class="note"><span>'.$element->getComment().'</span></p>';
90
+ }
91
+ $html.= '</td>';
92
+
93
+ if ($addInheritCheckbox) {
94
+ $defText = $element->getDefaultValue();
95
+
96
+ // default value
97
+ $html.= '<td class="use-default">';
98
+ $html.= '<input id="' . $id . '_inherit" name="'
99
+ . $namePrefix . '[inherit]" type="checkbox" value="1" class="checkbox config-inherit" '
100
+ . $inherit . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> ';
101
+ $html.= '<label for="' . $id . '_inherit" class="inherit" title="'
102
+ . htmlspecialchars($defText) . '">' . $checkboxLabel . '</label>';
103
+ $html.= '</td>';
104
+ }
105
+
106
+ $html.= '<td class="scope-label">';
107
+ if ($element->getScope()) {
108
+ $html .= $element->getScopeLabel();
109
+ }
110
+ $html.= '</td>';
111
+
112
+ $html.= '<td class="">';
113
+ if ($element->getHint()) {
114
+ $html.= '<div class="hint" >';
115
+ $html.= '<div style="display: none;">' . $element->getHint() . '</div>';
116
+ $html.= '</div>';
117
+ }
118
+ $html.= '</td>';
119
+
120
+ return $this->_decorateRowHtml($element, $html);
121
+ }
122
+
123
+ /**
124
+ * Gets the element's HTML.
125
+ *
126
+ * @param Varien_Data_Form_Element_Abstract $element
127
+ *
128
+ * @return string
129
+ *
130
+ * @see Varien_Data_Form_Element_Abstract::getElementHtml()
131
+ */
132
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
133
+ {
134
+ /**
135
+ * The value is formed as H:i:s. We need to get the H and i value from this.
136
+ */
137
+ $value = $element->getEscapedValue();
138
+ $value = explode(':', $value);
139
+
140
+ $hour = $value[0];
141
+ $minute = $value[1];
142
+
143
+ $options = $element->getValues();
144
+
145
+ /**
146
+ * The html consists of 2 select fields and corresponding labels. First we build the select field for the hours.
147
+ */
148
+ $html = '<select id="'
149
+ . $element->getHtmlId()
150
+ . '_hour" name="'
151
+ . $element->getName()
152
+ . '[hour]"'
153
+ . $element->serialize($this->getHtmlAttributes())
154
+ . '>';
155
+
156
+ /**
157
+ * Add option elements for all possible hours (0-23).
158
+ */
159
+ foreach ($options['hour'] as $option) {
160
+ $selected = '';
161
+ if ($option['value'] == $hour) {
162
+ $selected = ' selected="selected"';
163
+ }
164
+
165
+ $html .= "<option value=\"{$option['value']}\"{$selected}>{$option['label']}</option>";
166
+ }
167
+
168
+ /**
169
+ * Add the label for the hour field.
170
+ */
171
+ $html .= '</select>'
172
+ . '<label for="'
173
+ . $element->getHtmlId()
174
+ . '_hour">'
175
+ . $this->__('hour')
176
+ . '</label>';
177
+
178
+ /**
179
+ * Add the minute field.
180
+ */
181
+ $html .= '<select id="'
182
+ . $element->getHtmlId()
183
+ . '_minute" name="'
184
+ . $element->getName()
185
+ . '[minute]"'
186
+ . $element->serialize($this->getHtmlAttributes())
187
+ . '>;';
188
+
189
+ /**
190
+ * Add option elements for all possible minutes (0-60 in 5 min intervals).
191
+ */
192
+ foreach ($options['minute'] as $option) {
193
+ $selected = '';
194
+ if ($option['value'] == $minute) {
195
+ $selected = ' selected="selected"';
196
+ }
197
+
198
+ $html .= "<option value=\"{$option['value']}\"{$selected}>{$option['label']}</option>";
199
+ }
200
+
201
+ /**
202
+ * Add the minute label and possible 'AfterElementHtml'.
203
+ */
204
+ $html .= '</select>'
205
+ . '<label for="'
206
+ . $element->getHtmlId()
207
+ . '_minute">'
208
+ . $this->__('minutes')
209
+ . '</label>'
210
+ . $element->getAfterElementHtml();
211
+
212
+ return $html;
213
+ }
214
+
215
+ /**
216
+ * Gets a list of supported HTML attributes for this element.
217
+ *
218
+ * @return array
219
+ */
220
+ public function getHtmlAttributes()
221
+ {
222
+ $attributes = array(
223
+ 'type',
224
+ 'title',
225
+ 'class',
226
+ 'style',
227
+ 'onclick',
228
+ 'onchange',
229
+ 'disabled',
230
+ 'readonly',
231
+ 'tabindex',
232
+ );
233
+
234
+ return $attributes;
235
+ }
236
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/PackingSlipItemColumns.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_PackingSlipItemColumns
40
+ extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
41
+ {
42
+ /**
43
+ * @var string
44
+ */
45
+ protected $_template = 'TIG/PostNL/system/config/form/field/array.phtml';
46
+
47
+ /**
48
+ * Add columns for the array interface.
49
+ */
50
+ public function __construct()
51
+ {
52
+ $this->addColumn(
53
+ 'field',
54
+ array(
55
+ 'label' => $this->__('Field'),
56
+ 'style' => 'width:120px',
57
+ 'type' => 'select',
58
+ 'options' => Mage::getModel('postnl_core/system_config_source_packingSlipItemFields')->toOptionArray(),
59
+ 'class' => 'required-entry validate-select',
60
+ )
61
+ );
62
+ $this->addColumn(
63
+ 'title',
64
+ array(
65
+ 'label' => $this->__('Title'),
66
+ 'style' => 'width:120px',
67
+ 'class' => 'required-entry validate-alpha',
68
+ )
69
+ );
70
+ $this->addColumn(
71
+ 'width',
72
+ array(
73
+ 'label' => $this->__('Width'),
74
+ 'style' => 'width:120px',
75
+ 'class' => 'required-entry validate-digits',
76
+ )
77
+ );
78
+ $this->addColumn(
79
+ 'position',
80
+ array(
81
+ 'label' => $this->__('Position'),
82
+ 'style' => 'width:120px',
83
+ 'class' => 'required-entry validate-digits',
84
+ )
85
+ );
86
+
87
+ $this->_addAfter = false;
88
+ $this->_addButtonLabel = $this->__('Add column');
89
+
90
+ parent::__construct();
91
+ }
92
+
93
+ /**
94
+ * Add a column to the array-grid.
95
+ *
96
+ * @param string $name
97
+ * @param array $params
98
+ */
99
+ public function addColumn($name, $params)
100
+ {
101
+ $this->_columns[$name] = array(
102
+ 'label' => empty($params['label']) ? 'Column' : $params['label'],
103
+ 'size' => empty($params['size']) ? false : $params['size'],
104
+ 'style' => empty($params['style']) ? null : $params['style'],
105
+ 'class' => empty($params['class']) ? null : $params['class'],
106
+ 'type' => empty($params['type']) ? null : $params['type'],
107
+ 'options' => empty($params['options']) ? null : $params['options'],
108
+ 'renderer' => false,
109
+ );
110
+ if ((!empty($params['renderer'])) && ($params['renderer'] instanceof Mage_Core_Block_Abstract)) {
111
+ $this->_columns[$name]['renderer'] = $params['renderer'];
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Render array cell for prototypeJS template
117
+ *
118
+ * @param string $columnName
119
+ *
120
+ * @throws Exception
121
+ *
122
+ * @return string
123
+ */
124
+ protected function _renderCellTemplate($columnName)
125
+ {
126
+ if (empty($this->_columns[$columnName])) {
127
+ throw new Exception('Wrong column name specified.');
128
+ }
129
+
130
+ $column = $this->_columns[$columnName];
131
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
132
+
133
+ if ($column['renderer']) {
134
+ return $column['renderer']->setInputName($inputName)
135
+ ->setColumnName($columnName)
136
+ ->setColumn($column)
137
+ ->toHtml();
138
+ }
139
+
140
+ if ($column['type'] == 'select') {
141
+ $html = '<select name="';
142
+ } else {
143
+ $html = '<input type="text" name="';
144
+ }
145
+
146
+ $html .= $inputName
147
+ . '" value="#{'
148
+ . $columnName
149
+ . '}" '
150
+ . ($column['size'] ? 'size="' . $column['size'] . '"' : '')
151
+ . ' class="'
152
+ . (isset($column['class']) ? $column['class'] : 'input-text')
153
+ . '"'
154
+ . (isset($column['style']) ? ' style="'.$column['style'] . '"' : '');
155
+
156
+ if ($column['type'] == 'select') {
157
+ $html .= '>';
158
+
159
+ foreach ($column['options'] as $option) {
160
+ $selected = '';
161
+ if ($columnName == $option['value']) {
162
+ $selected = 'selected="selected"';
163
+ }
164
+
165
+ $html .= "<option value=\"{$option['value']}\" {$selected}>{$option['label']}</option>";
166
+ }
167
+
168
+ $html .= '</select>';
169
+ } else {
170
+ $html .= '/>';
171
+ }
172
+
173
+ return $html;
174
+ }
175
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Action.php CHANGED
@@ -40,15 +40,16 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Action
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
41
  {
42
  /**
43
- * Additional column names used
44
  */
45
  const SHIPPING_METHOD_COLUMN = 'shipping_method';
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
  *
@@ -117,14 +118,12 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_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;
@@ -150,6 +149,7 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Action
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.
@@ -175,6 +175,17 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Action
175
  return $action;
176
  }
177
 
 
 
 
 
 
 
 
 
 
 
 
178
  return $action;
179
  }
180
 
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
41
  {
42
  /**
43
+ * Additional column names used.
44
  */
45
  const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
  const COUNTRY_ID_COLUMN = 'country_id';
47
  const LABELS_PRINTED_COLUMN = 'labels_printed';
48
  const CONFIRM_STATUS_COLUMN = 'confirm_status';
49
+ const PRODUCT_CODE_COLUMN = 'product_code';
50
 
51
  /**
52
+ * Render column.
53
  *
54
  * @param Varien_Object $row
55
  *
118
  {
119
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
120
 
 
 
121
  /**
122
  * If this is a PostNL action, but this shipment was not shipped using PosTNL, skip it
123
  */
124
+ if (isset($action['is_postnl'])
125
  && $action['is_postnl']
126
+ && !Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)
127
  ) {
128
  unset($action['is_postnl']);
129
  return false;
149
  $euCountries = $helper->getEuCountries();
150
  $countryId = $row->getData(self::COUNTRY_ID_COLUMN);
151
  $confirmStatus = $row->getData(self::CONFIRM_STATUS_COLUMN);
152
+ $productCode = $row->getData(self::PRODUCT_CODE_COLUMN);
153
 
154
  /**
155
  * If the shipment is confirmed, we can't confirm it again.
175
  return $action;
176
  }
177
 
178
+ /**
179
+ * If this shipment uses a custom barcode it does not need to be confirmed.
180
+ */
181
+ $customBarcodeProductCodes = $helper->getCustomBarcodes();
182
+ if (isset($customBarcodeProductCodes[$productCode])) {
183
+ $message = $helper->__('This shipment does not need to be confirmed.');
184
+ $action = $this->_disableAction($action, $message);
185
+
186
+ return $action;
187
+ }
188
+
189
  return $action;
190
  }
191
 
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Barcode.php CHANGED
@@ -61,14 +61,23 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Barcode
61
  /**
62
  * The shipment was not shipped using PostNL
63
  */
64
- $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
65
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
66
- if (!in_array($shippingMethod, $postnlShippingMethods)) {
67
- return parent::render($row);
68
  }
69
 
70
  /**
71
- * Check if any data is available
 
 
 
 
 
 
 
 
 
 
72
  */
73
  $value = $row->getData($this->getColumn()->getIndex());
74
  if (!$value) {
@@ -78,10 +87,7 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Barcode
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
  }
61
  /**
62
  * The shipment was not shipped using PostNL
63
  */
 
64
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
65
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
66
+ return '';
67
  }
68
 
69
  /**
70
+ * If this is a buspakje shipment, a custom barcode is used that will not be displayed here.
71
+ *
72
+ * @var $postnlShipmentClassName TIG_PostNL_Model_Core_Shipment
73
+ */
74
+ $postnlShipmentClassName = Mage::getConfig()->getModelClassName('postnl_core/shipment');
75
+ if ($row->getData(self::CONFIRM_STATUS_COLUMN) == $postnlShipmentClassName::CONFIRM_STATUS_BUSPAKJE) {
76
+ return '';
77
+ }
78
+
79
+ /**
80
+ * Check if any data is available.
81
  */
82
  $value = $row->getData($this->getColumn()->getIndex());
83
  if (!$value) {
87
 
88
  /**
89
  * If the shipment hasn't been confirmed yet, the barcode will not be known by PostNL track & trace.
 
 
90
  */
 
91
  if ($row->getData(self::CONFIRM_STATUS_COLUMN) != $postnlShipmentClassName::CONFIRM_STATUS_CONFIRMED) {
92
  return $value;
93
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmDate.php CHANGED
@@ -40,10 +40,9 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmDate
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_STATUS_COLUMN = 'confirm_status';
47
 
48
  /**
49
  * Renders column.
@@ -54,53 +53,65 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmDate
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
- $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
  */
105
  return parent::render($row);
106
  }
40
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Date
41
  {
42
  /**
43
+ * Additional column name used
44
  */
45
  const SHIPPING_METHOD_COLUMN = 'shipping_method';
 
46
 
47
  /**
48
  * Renders column.
53
  */
54
  public function render(Varien_Object $row)
55
  {
 
56
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
57
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
58
+ return '';
59
  }
60
 
61
+ $value = $row->getData($this->getColumn()->getIndex());
62
+ $origDate = new DateTime($value);
63
+ $now = new DateTime(Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s'));
64
 
65
+ $interval = $now->diff($origDate);
 
 
 
 
 
66
 
67
  /**
68
+ * Check if the shipment should be confirmed somewhere in the future.
69
  */
70
+ if (
71
+ (($interval->days > 0 || $interval->h > 0) && !$interval->invert)
72
+ || ($interval->days == 0 && $interval->h < 24) && $interval->invert
73
+ ) {
74
  $confirmDate = new DateTime($value);
75
+ $diff = $now->diff($confirmDate);
76
+
77
+ /**
78
+ * Get the number of days until the shipment should be confirmed.
79
+ */
80
+ $diffDays = $diff->format('%a');
81
 
82
  /**
83
+ * If the difference is more than X days exactly, add a day.
84
  */
85
+ if (($diff->h > 0 || $diff->i > 0 || $diff->s > 0) && !$diff->invert) {
86
+ $diffDays++;
87
+ }
88
+
89
+ /**
90
+ * Check if the shipment should be confirmed today.
91
+ */
92
+ if ($diffDays == 0) {
93
+ return Mage::helper('postnl')->__('Today');
94
+ }
95
 
96
  /**
97
+ * Check if it should be confirmed tomorrow.
98
  */
99
+ if ($diffDays == 1) {
100
  $renderedValue = Mage::helper('postnl')->__('Tomorrow');
101
 
102
  return $renderedValue;
103
  }
104
 
105
  /**
106
+ * Render the number of days before the shipment should be confirmed.
107
  */
108
+ $renderedValue = Mage::helper('postnl')->__('%s days from now', $diffDays);
109
 
110
  return $renderedValue;
111
  }
112
 
113
  /**
114
+ * Finally, simply render the date.
115
  */
116
  return parent::render($row);
117
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmStatus.php CHANGED
@@ -43,6 +43,7 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmStatus
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
@@ -56,36 +57,50 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ConfirmStatus
56
  /**
57
  * The shipment was not shipped using PostNL
58
  */
59
- $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
60
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
61
- if (!in_array($shippingMethod, $postnlShippingMethods)) {
62
- return parent::render($row);
63
  }
64
 
65
  /**
66
  * Check if any data is available
67
  */
68
- $value = $row->getData($this->getColumn()->getIndex());
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
  }
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
57
  /**
58
  * The shipment was not shipped using PostNL
59
  */
 
60
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
61
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
62
+ return '';
63
  }
64
 
65
  /**
66
  * Check if any data is available
67
  */
68
+ $values = $row->getData($this->getColumn()->getIndex());
69
+ if (is_null($values) || $values === '') {
70
  return parent::render($row);
71
  }
72
 
73
+ $helper = Mage::helper('postnl');
74
+
75
  /**
76
  * @var $postnlShipmentClass TIG_PostNL_Model_Core_Shipment
77
  */
78
  $postnlShipmentClass = Mage::app()->getConfig()->getModelClassName('postnl_core/shipment');
79
+ $values = explode(',', $values);
80
+
81
+ $labels = array();
82
+ foreach ($values as $value) {
83
+ if ($value == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
84
+ $labels[] = $helper->__('Confirmed');
85
+
86
+ continue;
87
+ }
88
+
89
+ if ($value == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED) {
90
+ $labels[] = $helper->__('Unconfirmed');
91
+
92
+ continue;
93
+ }
94
+
95
+ if ($value == $postnlShipmentClass::CONFIRM_STATUS_CONFIRM_EXPIRED) {
96
+ $labels[] = $helper->__('Confirmation Expired');
97
 
98
+ continue;
99
+ }
 
100
  }
101
 
102
+ $label = implode(',', $labels);
103
 
104
+ return $label;
105
  }
106
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/DeliveryDate.php CHANGED
@@ -54,10 +54,9 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_DeliveryDate
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());
@@ -67,7 +66,10 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_DeliveryDate
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
  }
54
  */
55
  public function render(Varien_Object $row)
56
  {
 
57
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
58
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
59
+ return '';
60
  }
61
 
62
  $value = $row->getData($this->getColumn()->getIndex());
66
  */
67
  if (!$value) {
68
  $confirmDate = $row->getData(self::CONFIRM_DATE_COLUMN);
69
+ $confirmDate = new DateTime($confirmDate);
70
+ $confirmDate->add(new DateInterval('P1D'));
71
+
72
+ $deliveryDate = $confirmDate->format('Y-m-d H:i:s');
73
 
74
  $row->setData($this->getColumn()->getIndex(), $deliveryDate);
75
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/OrderConfirmDate.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_OrderConfirmDate
40
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Date
41
+ {
42
+ /**
43
+ * Additional column name used.
44
+ */
45
+ const SHIPPING_METHOD_COLUMN = 'shipping_method';
46
+
47
+ /**
48
+ * Renders column.
49
+ *
50
+ * @param Varien_Object $row
51
+ *
52
+ * @return string
53
+ */
54
+ public function render(Varien_Object $row)
55
+ {
56
+ $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
57
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
58
+ return '';
59
+ }
60
+
61
+ $value = $row->getData($this->getColumn()->getIndex());
62
+
63
+ /**
64
+ * If we have no value, then no delivery date was chosen by the customer. In this case we can calculate when the
65
+ * order could be shipped.
66
+ */
67
+ if (!$value) {
68
+ $deliveryDate = Mage::helper('postnl/deliveryOptions')->getDeliveryDate(
69
+ $row->getCreatedAt(),
70
+ $row->getStoreId()
71
+ );
72
+
73
+ $deliveryDate = new DateTime($deliveryDate);
74
+ $value = $deliveryDate->sub(new DateInterval('P1D'));
75
+ } else {
76
+ $value = new DateTime($value);
77
+ }
78
+
79
+ $now = new DateTime();
80
+ $now->setTimestamp(Mage::getModel('core/date')->gmtTimestamp());
81
+
82
+ /**
83
+ * Check if the shipment should be confirmed somewhere in the future
84
+ */
85
+ $diff = $now->diff($value);
86
+ if (
87
+ (($diff->days > 0 || $diff->h > 0) && !$diff->invert)
88
+ || ($diff->days == 0 && $diff->h < 24) && $diff->invert
89
+ ) {
90
+ /**
91
+ * Get the number of days until the shipment should be confirmed
92
+ */
93
+ $diffDays = $diff->format('%a');
94
+
95
+ /**
96
+ * If the difference is more than X days exactly, add a day.
97
+ */
98
+ if (($diff->h > 0 || $diff->i > 0 || $diff->s > 0) && !$diff->invert) {
99
+ $diffDays++;
100
+ }
101
+
102
+ /**
103
+ * Check if the shipment should be confirmed today
104
+ */
105
+ if ($diffDays == 0) {
106
+ return Mage::helper('postnl')->__('Today');
107
+ }
108
+
109
+ /**
110
+ * Check if it should be confirmed tomorrow
111
+ */
112
+ if ($diffDays == 1) {
113
+ $renderedValue = Mage::helper('postnl')->__('Tomorrow');
114
+
115
+ return $renderedValue;
116
+ }
117
+
118
+ /**
119
+ * Render the number of days before the shipment should be confirmed
120
+ */
121
+ $renderedValue = Mage::helper('postnl')->__('%s days from now', $diffDays);
122
+
123
+ return $renderedValue;
124
+ }
125
+
126
+ /**
127
+ * Finally, simply render the date
128
+ */
129
+ $format = $this->_getFormat();
130
+ $value = $value->format('Y-m-d H:i:s');
131
+ try {
132
+ if($this->getColumn()->getGmtoffset()) {
133
+ $data = Mage::app()->getLocale()
134
+ ->date($value, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
135
+ } else {
136
+ $data = Mage::getSingleton('core/locale')
137
+ ->date($value, Zend_Date::ISO_8601, null, false)->toString($format);
138
+ }
139
+ } catch (Exception $e) {
140
+ if($this->getColumn()->getTimezone()) {
141
+ $data = Mage::app()->getLocale()
142
+ ->date($value, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
143
+ } else {
144
+ $data = Mage::getSingleton('core/locale')->date($value, null, null, false)->toString($format);
145
+ }
146
+ }
147
+ return $data;
148
+ }
149
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/OrderConfirmStatus.php ADDED
@@ -0,0 +1,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.
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_OrderConfirmStatus
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 CONFIRM_DATE_COLUMN = 'confirm_date';
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
+ $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
61
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
62
+ return '';
63
+ }
64
+
65
+ /**
66
+ * Check if any data is available.
67
+ */
68
+ $values = $row->getData($this->getColumn()->getIndex());
69
+ if (is_null($values)) {
70
+ return Mage::helper('postnl')->__('No shipments found');
71
+ }
72
+
73
+ /**
74
+ * @var $postnlShipmentClass TIG_PostNL_Model_Core_Shipment
75
+ */
76
+ $postnlShipmentClass = Mage::app()->getConfig()->getModelClassName('postnl_core/shipment');
77
+ $values = explode(',', $values);
78
+
79
+ $labels = array();
80
+ foreach ($values as $value) {
81
+ if ($value == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
82
+ $labels[] = Mage::helper('postnl')
83
+ ->__('Confirmed');
84
+
85
+ continue;
86
+ }
87
+
88
+ if ($value == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED) {
89
+ $labels[] = Mage::helper('postnl')
90
+ ->__('Unconfirmed');
91
+
92
+ continue;
93
+ }
94
+
95
+ if ($value == $postnlShipmentClass::CONFIRM_STATUS_CONFIRM_EXPIRED) {
96
+ $labels[] = Mage::helper('postnl')
97
+ ->__('Confirmation Expired');
98
+ continue;
99
+ }
100
+
101
+ if ($value == $postnlShipmentClass::CONFIRM_STATUS_BUSPAKJE) {
102
+ $labels[] = Mage::helper('postnl')
103
+ ->__('No Confirmation Required');
104
+ continue;
105
+ }
106
+ }
107
+
108
+ $label = implode(',', $labels);
109
+
110
+ return $label;
111
+ }
112
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/OrderType.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_OrderType
40
+ extends TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Type_Abstract
41
+ {
42
+ /**
43
+ * Renders the column value as a shipment type value (Domestic, EPS or GlobalPack)
44
+ *
45
+ * @param Varien_Object $row
46
+ *
47
+ * @return string
48
+ */
49
+ public function render(Varien_Object $row)
50
+ {
51
+ /**
52
+ * @var Mage_Adminhtml_Block_Widget_Grid_Column $column
53
+ */
54
+ $column = $this->getColumn();
55
+
56
+ /**
57
+ * The shipment was not shipped using PostNL.
58
+ */
59
+ $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
60
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
61
+ return '';
62
+ }
63
+
64
+ /**
65
+ * Check if any data is available.
66
+ */
67
+ $value = $row->getData($column->getIndex());
68
+ if (is_null($value) || $value === '') {
69
+ return '';
70
+ }
71
+
72
+ /**
73
+ * If this row has any corresponding shipments, the shipment_type column will be filled. Use the parent rendered
74
+ * to render this column instead, as it will be more accurate.
75
+ */
76
+ if ($row->getData('shipment_type')) {
77
+ $types = explode(',', $row->getData('shipment_type'));
78
+ $productCodes = explode(',', $row->getData('product_code'));
79
+
80
+ $renderedValues = array();
81
+ foreach ($types as $key => $type) {
82
+ $rowDummy = new Varien_Object(
83
+ array(
84
+ 'id' => $row->getId(),
85
+ 'product_code' => $productCodes[$key],
86
+ )
87
+ );
88
+ $renderedValues[] = $this->getShipmentTypeRenderedValue($type, $rowDummy);
89
+ }
90
+
91
+ return implode('<br />', $renderedValues);
92
+ }
93
+
94
+ $renderedValue = $this->getOrderTypeRenderedValue($value, $row);
95
+
96
+ return $renderedValue;
97
+ }
98
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShipmentType.php CHANGED
@@ -37,16 +37,8 @@
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
  *
@@ -62,11 +54,10 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShipmentType
62
  $column = $this->getColumn();
63
 
64
  /**
65
- * The shipment was not shipped using PostNL
66
  */
67
- $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
68
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
69
- if (!in_array($shippingMethod, $postnlShippingMethods)) {
70
  return '';
71
  }
72
 
@@ -78,119 +69,8 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShipmentType
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
- }
185
- elseif (preg_match('/^([0-9]+)px$/', $customWidth, $matches)) {
186
- $width = (int)$matches[1];
187
- }
188
- }
189
-
190
- if (null !== $width) {
191
- $out .= ' width="' . $width . '"';
192
- }
193
-
194
- return $out;
195
- }
196
  }
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 TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_Type_Abstract
41
  {
 
 
 
 
 
 
 
 
42
  /**
43
  * Renders the column value as a shipment type value (Domestic, EPS or GlobalPack)
44
  *
54
  $column = $this->getColumn();
55
 
56
  /**
57
+ * The shipment was not shipped using PostNL.
58
  */
 
59
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
60
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
61
  return '';
62
  }
63
 
69
  return '';
70
  }
71
 
72
+ $renderedValue = $this->getShipmentTypeRenderedValue($value, $row);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  return $renderedValue;
75
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingDescription.php CHANGED
@@ -57,10 +57,9 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShippingDescription
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
  /**
57
  /**
58
  * The shipment was not shipped using PostNL
59
  */
 
60
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
61
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
62
+ return '';
63
  }
64
 
65
  /**
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingPhase.php CHANGED
@@ -48,17 +48,24 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShippingPhase
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
  }
48
  */
49
  public function render(Varien_Object $row)
50
  {
51
+ $values = $row->getData($this->getColumn()->getIndex());
52
 
53
+ if (empty($values)) {
54
  return '';
55
  }
56
 
57
+ $helper = Mage::helper('postnl');
58
+ $values = explode(',', $values);
59
  $shippingPhases = Mage::helper('postnl/cif')->getShippingPhases();
60
+
61
+ $labels = array();
62
+ foreach ($values as $value) {
63
+ if (isset($shippingPhases[$value])) {
64
+ $labels[] = $helper->__($shippingPhases[$value]);
65
+ }
66
  }
67
+ $labels = implode(',', $labels);
68
 
69
+ return $labels;
70
  }
71
  }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Type/Abstract.php ADDED
@@ -0,0 +1,413 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Type_Abstract
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
+ const IS_PAKJE_GEMAK_COLUMN = 'is_pakje_gemak';
48
+ const IS_PAKKETAUTOMAAT_COLUMN = 'is_pakketautomaat';
49
+ const DELIVERY_OPTION_TYPE_COLUMN = 'delivery_option_type';
50
+ const PAYMENT_METHOD_COLUMN = 'payment_method';
51
+
52
+ /**
53
+ * Renders a type column for a shipment type.
54
+ *
55
+ * @param string $type
56
+ * @param Varien_Object $row
57
+ *
58
+ * @return string
59
+ */
60
+ public function getShipmentTypeRenderedValue($type, Varien_Object $row)
61
+ {
62
+ $helper = Mage::helper('postnl');
63
+
64
+ $label = '';
65
+ $comment = false;
66
+ switch ($type) {
67
+ case 'domestic':
68
+ $label = $helper->__('Domestic');
69
+ break;
70
+ case 'domestic_cod':
71
+ $label = $helper->__('Domestic');
72
+ $comment = $helper->__('COD');
73
+ break;
74
+ case 'avond':
75
+ $label = $helper->__('Domestic');
76
+ $comment = $helper->__('Evening Delivery');
77
+ break;
78
+ case 'avond_cod':
79
+ $label = $helper->__('Domestic');
80
+ $comment = $helper->__('Evening Delivery') . ' + ' . $helper->__('COD');
81
+ break;
82
+ case 'pg':
83
+ $label = $helper->__('Post Office');
84
+ break;
85
+ case 'pg_cod':
86
+ $label = $helper->__('Post Office');
87
+ $comment = $helper->__('COD');
88
+ break;
89
+ case 'pge':
90
+ $label = $helper->__('Post Office');
91
+ $comment = $helper->__('Early Pickup');
92
+ break;
93
+ case 'pge_cod':
94
+ $label = $helper->__('Post Office');
95
+ $comment = $helper->__('Early Pickup') . ' + ' . $helper->__('COD');
96
+ break;
97
+ case 'pa':
98
+ $label = $helper->__('Parcel Dispenser');
99
+ break;
100
+ case 'pa_cod':
101
+ $label = $helper->__('Parcel Dispenser');
102
+ $comment = $helper->__('COD');
103
+ break;
104
+ case 'eps':
105
+ $label = $helper->__('EPS');
106
+ break;
107
+ case 'globalpack':
108
+ $label = $helper->__('GlobalPack');
109
+ break;
110
+ case 'buspakje':
111
+ $label = $helper->__('Letter Box Parcel');
112
+
113
+ if ($row->getData(self::PRODUCT_CODE_COLUMN) == '2928') {
114
+ $comment = $helper->__('Extra');
115
+ }
116
+ break;
117
+ }
118
+
119
+ $renderedValue = "<b id='postnl-shipmenttype-{$row->getId()}' data-product-type='{$type}'>{$label}</b>";
120
+ if ($comment) {
121
+ $renderedValue .= "<br /><em>{$comment}</em>";
122
+ }
123
+
124
+ return $renderedValue;
125
+ }
126
+
127
+ /**
128
+ * Renders the <col> element of the column. Added check for $this->getColumn()->getDisplay() == 'none' that causes
129
+ * the entire element to be hidden.
130
+ *
131
+ * @return string
132
+ *
133
+ * @see Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract::renderProperty()
134
+ */
135
+ public function renderProperty()
136
+ {
137
+ /**
138
+ * @var Mage_Adminhtml_Block_Widget_Grid_Column $column
139
+ */
140
+ $column = $this->getColumn();
141
+
142
+ $out = '';
143
+ if ($column->hasData('display')) {
144
+ $out .= " style='display:{$column->getDisplay()};'";
145
+ }
146
+
147
+ $width = $this->_defaultWidth;
148
+
149
+ if ($column->hasData('width')) {
150
+ $customWidth = $column->getData('width');
151
+ if ((null === $customWidth) || (preg_match('/^[0-9]+%?$/', $customWidth))) {
152
+ $width = $customWidth;
153
+ }
154
+ elseif (preg_match('/^([0-9]+)px$/', $customWidth, $matches)) {
155
+ $width = (int)$matches[1];
156
+ }
157
+ }
158
+
159
+ if (null !== $width) {
160
+ $out .= ' width="' . $width . '"';
161
+ }
162
+
163
+ return $out;
164
+ }
165
+
166
+ /**
167
+ * Get the rendered value for this row.
168
+ *
169
+ * @param string $value
170
+ * @param Varien_Object $row
171
+ *
172
+ * @return string
173
+ */
174
+ public function getOrderTypeRenderedValue($value, Varien_Object $row)
175
+ {
176
+ $helper = Mage::helper('postnl/cif');
177
+
178
+ /**
179
+ * Try to render the value based on the delivery option type.
180
+ */
181
+ $optionType = $row->getData(self::DELIVERY_OPTION_TYPE_COLUMN);
182
+ if ($optionType == 'Avond') {
183
+ return $this->_getAvondRenderedValue($row);
184
+ } elseif ($optionType == 'PGE') {
185
+ return $this->_getPgeRenderedValue($row);
186
+ } elseif ($row->getData(self::IS_PAKKETAUTOMAAT_COLUMN)) {
187
+ return $this->_getPaRenderedValue($row);
188
+ } elseif ($row->getData(self::IS_PAKJE_GEMAK_COLUMN)) {
189
+ return $this->_getPgRenderedValue($row);
190
+ }
191
+
192
+ /**
193
+ * Check if this order is domestic.
194
+ */
195
+ if ($value == 'NL') {
196
+ return $this->_getDomesticRenderedValue($row);
197
+ }
198
+
199
+ /**
200
+ * Check if this order's shipping address is in an EU country.
201
+ */
202
+ $euCountries = $helper->getEuCountries();
203
+ if (in_array($value, $euCountries)) {
204
+ return $this->_getEpsRenderedValue($row);
205
+ }
206
+
207
+ /**
208
+ * If none of the above apply, it's an international order.
209
+ */
210
+ return $this->_getGlobalpackRenderedValue($row);
211
+ }
212
+
213
+ /**
214
+ * Render this column for an Avond shipment.
215
+ *
216
+ * @param Varien_Object $row
217
+ *
218
+ * @return string
219
+ */
220
+ protected function _getAvondRenderedValue(Varien_Object $row)
221
+ {
222
+ $helper = Mage::helper('postnl');
223
+
224
+ $label = $helper->__('Domestic');
225
+ $comment = $helper->__('Evening Delivery');
226
+ $type = 'avond';
227
+
228
+ if ($this->_isCod($row)) {
229
+ $comment .= ' + ' . $helper->__('COD');
230
+ $type .= '_cod';
231
+ }
232
+
233
+ $renderedValue = "<b id='postnl-shipmenttype-{$row->getId()}' data-product-type='{$type}'>{$label}</b>" .
234
+ "<br /><em>{$comment}</em>";
235
+
236
+ return $renderedValue;
237
+ }
238
+
239
+ /**
240
+ * Render this column for a PGE shipment.
241
+ *
242
+ * @param Varien_Object $row
243
+ *
244
+ * @return string
245
+ */
246
+ protected function _getPgeRenderedValue(Varien_Object $row)
247
+ {
248
+ $helper = Mage::helper('postnl');
249
+
250
+ $label = $helper->__('Post Office');
251
+ $comment = $helper->__('Early Pickup');
252
+ $type = 'pge';
253
+
254
+ if ($this->_isCod($row)) {
255
+ $type .= '_cod';
256
+ $comment .= ' + ' . $helper->__('COD');
257
+ }
258
+
259
+ $renderedValue = "<b id='postnl-shipmenttype-{$row->getId()}' data-product-type='{$type}'>{$label}</b>" .
260
+ "<br /><em>{$comment}</em>";
261
+
262
+ return $renderedValue;
263
+ }
264
+
265
+ /**
266
+ * Render this column for a PA shipment.
267
+ *
268
+ * @param Varien_Object $row
269
+ *
270
+ * @return string
271
+ */
272
+ protected function _getPaRenderedValue(Varien_Object $row)
273
+ {
274
+ $label = Mage::helper('postnl')->__('Parcel Dispenser');
275
+
276
+ $renderedValue = "<b id='postnl-shipmenttype-{$row->getId()}' data-product-type='pakketautomaat'>{$label}" .
277
+ "</b>";
278
+
279
+ return $renderedValue;
280
+ }
281
+
282
+ /**
283
+ * Render this column for a PGE shipment.
284
+ *
285
+ * @param Varien_Object $row
286
+ *
287
+ * @return string
288
+ */
289
+ protected function _getPgRenderedValue(Varien_Object $row)
290
+ {
291
+ $helper = Mage::helper('postnl');
292
+
293
+ $label = $helper->__('Post Office');
294
+ $type = 'pg';
295
+
296
+ $isCod = $this->_isCod($row);
297
+
298
+ if ($isCod) {
299
+ $type .= '_cod';
300
+ }
301
+
302
+ $renderedValue = "<b id='postnl-shipmenttype-{$row->getId()}' data-product-type='{$type}'>{$label}</b>";
303
+
304
+ if ($isCod) {
305
+ $renderedValue .= '<br /><em>' . $helper->__('COD') . '</em>';
306
+ }
307
+
308
+ return $renderedValue;
309
+ }
310
+
311
+ /**
312
+ * Render this column for a domestic shipment.
313
+ *
314
+ * @param Varien_Object $row
315
+ *
316
+ * @return string
317
+ */
318
+ protected function _getDomesticRenderedValue(Varien_Object $row)
319
+ {
320
+ $helper = Mage::helper('postnl');
321
+ $deliveryOptionsHelper = Mage::helper('postnl/deliveryOptions');
322
+
323
+ $label = $helper->__('Domestic');
324
+ $type = 'domestic';
325
+
326
+ $isCod = $this->_isCod($row);
327
+
328
+ if ($isCod) {
329
+ $type .= '_cod';
330
+ } elseif ($deliveryOptionsHelper->getBuspakjeCalculationMode() == 'automatic') {
331
+ /**
332
+ * If the buspakje calculation mode is set to automatic and the order fits as a buspakje, we should render
333
+ * the column as such.
334
+ */
335
+ $orderItems = Mage::getResourceModel('sales/order_item_collection')->setOrderFilter($row->getId());
336
+ if ($deliveryOptionsHelper->fitsAsBuspakje($orderItems)) {
337
+ $label = $helper->__('Letter Box Parcel');
338
+ $type = 'buspakje';
339
+
340
+ return "<b id='postnl-shipmenttype-{$row->getId()}' data-product-type='{$type}'>{$label}</b>";
341
+ }
342
+ }
343
+
344
+ $renderedValue = "<b id='postnl-shipmenttype-{$row->getId()}' data-product-type='{$type}'>{$label}</b>";
345
+
346
+ if ($isCod) {
347
+ $renderedValue .= '<br /><em>' . $helper->__('COD') . '</em>';
348
+ } else {
349
+ /**
350
+ * If the buspakje calculation mode is set to manual, we can only inform the merchant that this might be a
351
+ * buspakje.
352
+ */
353
+ $orderItems = Mage::getResourceModel('sales/order_item_collection')->setOrderFilter($row->getId());
354
+ if (Mage::helper('postnl/deliveryOptions')->fitsAsBuspakje($orderItems)) {
355
+ $renderedValue .= '<br /><em>(' . $helper->__('possibly letter box parcel') . ')</em>';
356
+ }
357
+ }
358
+
359
+ return $renderedValue;
360
+ }
361
+
362
+ /**
363
+ * Render this column for an EPS shipment.
364
+ *
365
+ * @param Varien_Object $row
366
+ *
367
+ * @return string
368
+ */
369
+ protected function _getEpsRenderedValue(Varien_Object $row)
370
+ {
371
+ $label = Mage::helper('postnl')->__('EPS');
372
+
373
+ $renderedValue = "<b id='postnl-shipmenttype-{$row->getId()}' data-product-type='eps'>{$label}</b>";
374
+
375
+ return $renderedValue;
376
+ }
377
+
378
+ /**
379
+ * Render this column for a Globalpack shipment.
380
+ *
381
+ * @param Varien_Object $row
382
+ *
383
+ * @return string
384
+ */
385
+ protected function _getGlobalpackRenderedValue(Varien_Object $row)
386
+ {
387
+ $label = Mage::helper('postnl')->__('GlobalPack');
388
+
389
+ $renderedValue = "<b id='postnl-shipmenttype-{$row->getId()}' data-product-type='globalpack'>{$label}</b>";
390
+
391
+ return $renderedValue;
392
+ }
393
+
394
+ /**
395
+ * Checks if a specified order is placed using a PostNL COD payment method.
396
+ *
397
+ * @param Varien_Object $row
398
+ *
399
+ * @return bool
400
+ */
401
+ protected function _isCod(Varien_Object $row)
402
+ {
403
+ $isCod = false;
404
+ $paymentMethod = $row->getData(self::PAYMENT_METHOD_COLUMN);
405
+
406
+ $codPaymentMethods = Mage::helper('postnl/payment')->getCodPaymentMethods();
407
+ if (in_array($paymentMethod, $codPaymentMethods)) {
408
+ $isCod = true;
409
+ }
410
+
411
+ return $isCod;
412
+ }
413
+ }
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/YesNo.php CHANGED
@@ -56,10 +56,9 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_YesNo
56
  /**
57
  * The shipment was not shipped using PostNL
58
  */
59
- $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
60
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
61
- if (!in_array($shippingMethod, $postnlShippingMethods)) {
62
- return parent::render($row);
63
  }
64
 
65
  /**
56
  /**
57
  * The shipment was not shipped using PostNL
58
  */
 
59
  $shippingMethod = $row->getData(self::SHIPPING_METHOD_COLUMN);
60
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
61
+ return '';
62
  }
63
 
64
  /**
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Massaction/{LabelStartPos.php → Item/Additional/LabelStartPos.php} RENAMED
@@ -42,7 +42,8 @@
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
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_Item_Additional_LabelStartPos
46
+ extends Mage_Adminhtml_Block_Abstract
47
  {
48
  /**
49
  * @var string
app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Massaction/Item/Additional/ProductOptions.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Massaction_Item_Additional_ProductOptions
40
+ extends Mage_Adminhtml_Block_Widget_Grid_Massaction_Item_Additional_Default
41
+ {
42
+ /**
43
+ * Create a new massaction item from a config array.
44
+ *
45
+ * @param array $configuration
46
+ *
47
+ * @return $this
48
+ */
49
+ public function createFromConfiguration(array $configuration)
50
+ {
51
+ $form = new Varien_Data_Form();
52
+ $form->addType('postnl_checkbox', 'TIG_PostNL_Model_Adminhtml_Form_Element_Checkbox');
53
+
54
+ foreach ($configuration as $itemId=>$item) {
55
+ $item['class'] = isset($item['class']) ? $item['class'] . ' absolute-advice' : 'absolute-advice';
56
+ $form->addField($itemId, $item['type'], $item);
57
+ }
58
+ $this->setForm($form);
59
+ return $this;
60
+ }
61
+ }
app/code/community/TIG/PostNL/Block/Checkout/Cart/Js.php CHANGED
@@ -57,12 +57,12 @@ class TIG_PostNL_Block_Checkout_Cart_Js extends TIG_PostNL_Block_Core_Template
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
@@ -73,7 +73,7 @@ class TIG_PostNL_Block_Checkout_Cart_Js extends TIG_PostNL_Block_Core_Template
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';
@@ -91,7 +91,7 @@ class TIG_PostNL_Block_Checkout_Cart_Js extends TIG_PostNL_Block_Core_Template
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;
@@ -187,7 +187,7 @@ class TIG_PostNL_Block_Checkout_Cart_Js extends TIG_PostNL_Block_Core_Template
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
 
57
  /**
58
  * XML path for webshop ID setting
59
  */
60
+ const XPATH_PUBLIC_WEBSHOP_ID = 'postnl/cif/public_webshop_id';
61
 
62
  /**
63
  * XML path of show_summary_page setting
64
  */
65
+ const XPATH_SHOW_SUMMARY_PAGE = 'postnl/checkout/show_summary_page';
66
 
67
  /**
68
  * URLs of the primary PostNL Checkout JS files for test and live mode
73
  const LIVE_CHECKOUT_PREMIUM_JS_URL = 'https://mijnpakket.postnl.nl/Checkout2/CheckoutPremium.js';
74
 
75
  /**
76
+ * Possible PostNL Checkout environments
77
  */
78
  const TEST_ENVIRONMENT = 'PostNL_OP_Checkout.environment_sandbox';
79
  const LIVE_ENVIRONMENT = 'PostNL_OP_Checkout.environment_production';
91
 
92
  $storeId = Mage::app()->getStore()->getId();
93
 
94
+ $webshopId = Mage::getStoreConfig(self::XPATH_PUBLIC_WEBSHOP_ID, $storeId);
95
 
96
  $this->setWebshopId($webshopId);
97
  return $webshopId;
187
  }
188
 
189
  $storeId = Mage::app()->getStore()->getId();
190
+ $showConfirmPage = Mage::getStoreConfigFlag(self::XPATH_SHOW_SUMMARY_PAGE, $storeId);
191
  if ($showConfirmPage) {
192
  $url = $this->getUrl('postnl/checkout/summary');
193
 
app/code/community/TIG/PostNL/Block/Core/JsTranslate.php CHANGED
@@ -92,7 +92,7 @@ class TIG_PostNL_Block_Core_JsTranslate extends TIG_PostNL_Block_Core_Template
92
  /**
93
  * @param null|Varien_Simplexml_Config $config
94
  *
95
- * @return TIG_PostNL_Block_Core_JsTranslate
96
  */
97
  public function setConfig($config)
98
  {
92
  /**
93
  * @param null|Varien_Simplexml_Config $config
94
  *
95
+ * @return $this
96
  */
97
  public function setConfig($config)
98
  {
app/code/community/TIG/PostNL/Block/DeliveryOptions/Checkout/DeliveryOptions.php CHANGED
@@ -73,7 +73,7 @@ class TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions extends TIG_Post
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
  {
@@ -212,8 +212,13 @@ class TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions extends TIG_Post
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);
@@ -225,7 +230,7 @@ class TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions extends TIG_Post
225
  *
226
  * @param string $deliveryDate
227
  *
228
- * @return TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions
229
  */
230
  public function setDeliveryDate($deliveryDate)
231
  {
@@ -280,13 +285,6 @@ class TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions extends TIG_Post
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
 
@@ -413,7 +411,7 @@ class TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions extends TIG_Post
413
  }
414
 
415
  /**
416
- * Checks whether Pakket Automaat locations are allowed.
417
  *
418
  * @return boolean
419
  */
@@ -424,7 +422,18 @@ class TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions extends TIG_Post
424
  }
425
 
426
  /**
427
- * Checks whether timeframes are allowed.
 
 
 
 
 
 
 
 
 
 
 
428
  *
429
  * @return boolean
430
  */
@@ -435,7 +444,7 @@ class TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions extends TIG_Post
435
  }
436
 
437
  /**
438
- * Checks whether evening timeframes are allowed.
439
  *
440
  * @return boolean
441
  */
@@ -488,6 +497,33 @@ class TIG_PostNL_Block_DeliveryOptions_Checkout_DeliveryOptions extends TIG_Post
488
  return false;
489
  }
490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
  /**
492
  * Checks if debug mode is allowed. Debug mode is enabled if the PostNl extension's debug mode is set to 'full'.
493
  *
73
  *
74
  * @param Mage_Sales_Model_Quote_Address|null $shippingAddress
75
  *
76
+ * @return $this
77
  */
78
  public function setShippingAddress($shippingAddress)
79
  {
212
  } catch (Exception $e) {
213
  Mage::helper('postnl')->logException($e);
214
 
215
+ $shippingDuration = Mage::helper('postnl/deliveryOptions')->getDeliveryDate(null, null, true);
216
+
217
+ $nextDeliveryDay = new DateTime();
218
+ $nextDeliveryDay->setTimestamp(Mage::getModel('core/date')->timestamp());
219
+ $nextDeliveryDay->add(new DateInterval("P{$shippingDuration}D"));
220
+
221
+ $deliveryDate = $nextDeliveryDay->format('d-m-Y');
222
  }
223
 
224
  $this->setDeliveryDate($deliveryDate);
230
  *
231
  * @param string $deliveryDate
232
  *
233
+ * @return $this
234
  */
235
  public function setDeliveryDate($deliveryDate)
236
  {
285
  return 0;
286
  }
287
 
 
 
 
 
 
 
 
288
  return $fee;
289
  }
290
 
411
  }
412
 
413
  /**
414
+ * Checks whether Pakketautomaat locations are allowed.
415
  *
416
  * @return boolean
417
  */
422
  }
423
 
424
  /**
425
+ * Checks whether delivery days are allowed.
426
+ *
427
+ * @return boolean
428
+ */
429
+ public function canUseDeliveryDays()
430
+ {
431
+ $canUseDeliveryDays = Mage::helper('postnl/deliveryOptions')->canUseDeliveryDays();
432
+ return $canUseDeliveryDays;
433
+ }
434
+
435
+ /**
436
+ * Checks whether time frames are allowed.
437
  *
438
  * @return boolean
439
  */
444
  }
445
 
446
  /**
447
+ * Checks whether evening time frames are allowed.
448
  *
449
  * @return boolean
450
  */
497
  return false;
498
  }
499
 
500
+ /**
501
+ * Get whether this order is a buspakje order.
502
+ *
503
+ * @return bool
504
+ */
505
+ public function getIsBuspakje()
506
+ {
507
+ /**
508
+ * Check if the buspakje calculation mode is set to automatic.
509
+ */
510
+ $helper = Mage::helper('postnl');
511
+ $calculationMode = $helper->getBuspakjeCalculationMode();
512
+ if ($calculationMode != 'automatic') {
513
+ return false;
514
+ }
515
+
516
+ /**
517
+ * Check if the current quote fits as a letter box parcel.
518
+ */
519
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
520
+ if (!$helper->fitsAsBuspakje($quote->getAllItems())) {
521
+ return false;
522
+ }
523
+
524
+ return true;
525
+ }
526
+
527
  /**
528
  * Checks if debug mode is allowed. Debug mode is enabled if the PostNl extension's debug mode is set to 'full'.
529
  *
app/code/community/TIG/PostNL/Block/DeliveryOptions/Js.php CHANGED
@@ -67,4 +67,18 @@ class TIG_PostNL_Block_DeliveryOptions_Js extends TIG_PostNL_Block_DeliveryOptio
67
  $this->setApiKey($apiKey);
68
  return $apiKey;
69
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  }
67
  $this->setApiKey($apiKey);
68
  return $apiKey;
69
  }
70
+
71
+ /**
72
+ * Render the template if allowed.
73
+ *
74
+ * @return string
75
+ */
76
+ protected function _toHtml()
77
+ {
78
+ if (!Mage::helper('postnl/deliveryOptions')->isDeliveryOptionsEnabled()) {
79
+ return '';
80
+ }
81
+
82
+ return parent::_toHtml();
83
+ }
84
  }
app/code/community/TIG/PostNL/Block/Mijnpakket/AccountNotification.php CHANGED
@@ -73,7 +73,6 @@ class TIG_PostNL_Block_Mijnpakket_AccountNotification extends TIG_PostNL_Block_C
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
 
@@ -93,13 +92,7 @@ class TIG_PostNL_Block_Mijnpakket_AccountNotification extends TIG_PostNL_Block_C
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;
@@ -284,12 +277,12 @@ class TIG_PostNL_Block_Mijnpakket_AccountNotification extends TIG_PostNL_Block_C
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) {
@@ -301,12 +294,12 @@ class TIG_PostNL_Block_Mijnpakket_AccountNotification extends TIG_PostNL_Block_C
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
  */
73
  /**
74
  * Xpaths determining various options regarding the MijnPakket notification.
75
  */
 
76
  const XPATH_SHOW_CREATE_MIJNPAKKET_ACCOUNT_LINK = 'postnl/delivery_options/show_create_mijnpakket_account_link';
77
  const XPATH_SHOW_MIJNPAKKET_APP_LINK = 'postnl/delivery_options/show_mijnpakket_app_link';
78
 
92
  return $this->_getData('can_show_notification');
93
  }
94
 
95
+ $canShowNotification = Mage::helper('postnl/mijnpakket')->canShowMijnpakketNotification();
 
 
 
 
 
 
96
 
97
  $this->setCanShowNotification($canShowNotification);
98
  return $canShowNotification;
277
  'middleName' => $shippingAddress->getMiddlename(),
278
  'lastName' => $shippingAddress->getLastname(),
279
  'email' => $shippingAddress->getEmail(),
280
+ 'postalCode' => str_replace(' ', '', $shippingAddress->getPostcode()),
281
  'business' => 'P',
282
  );
283
 
284
  /**
285
+ * If this address has a VAT ID, it's probably a B2B client.
286
  */
287
  $vat = $shippingAddress->getVatId();
288
  if ($vat) {
294
  */
295
  $dob = $shippingAddress->getDob();
296
  if ($dob) {
297
+ $dob = new DateTime($dob);
298
+ $params['birthDate'] = $dob->format('d-m-Y');
299
  }
300
 
301
  /**
302
+ * If we have a mobile phone number for this address, add that as well.
303
  *
304
  * @var TIG_PostNL_Model_Core_Order $postnlOrder
305
  */
app/code/community/TIG/PostNL/Block/Mijnpakket/OrderSuccessJs.php CHANGED
@@ -54,14 +54,14 @@ class TIG_PostNL_Block_Mijnpakket_OrderSuccessJs extends TIG_PostNL_Block_Checko
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
 
54
  protected $_template = 'TIG/PostNL/mijnpakket/order_success_js.phtml';
55
 
56
  /**
57
+ * Check if the MijnPakket notification may be shown.
58
  *
59
  * @return string
60
  */
61
  protected function _tohtml()
62
  {
63
  $helper = Mage::helper('postnl/mijnpakket');
64
+ if (!$helper->canShowMijnpakketNotification()) {
65
  return '';
66
  }
67
 
app/code/community/TIG/PostNL/Block/Payment/Checkout/Total/CodFee.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
+ * @method Varien_Object getTotal()
40
+ */
41
+ class TIG_PostNL_Block_Payment_Checkout_Total_CodFee extends Mage_Checkout_Block_Total_Default
42
+ {
43
+ /**
44
+ * Display modes for the PostNL COD fee.
45
+ */
46
+ const DISPLAY_MODE_EXCL = 1;
47
+ const DISPLAY_MODE_INCL = 2;
48
+ const DISPLAY_MODE_BOTH = 3;
49
+
50
+ /**
51
+ * Xpath to the PostNL COD fee display mode setting.
52
+ */
53
+ const XPATH_DISPLAY_MODE_COD_FEE = 'tax/cart_display/postnl_cod_fee';
54
+
55
+ /**
56
+ * @var string
57
+ */
58
+ protected $_template = 'TIG/PostNL/payment/checkout/total/cod_fee.phtml';
59
+
60
+ /**
61
+ * Get the display mode for the PostNL COD fee.
62
+ *
63
+ * @return int
64
+ */
65
+ public function getDisplayMode()
66
+ {
67
+ $displayMode = (int) Mage::getStoreConfig(self::XPATH_DISPLAY_MODE_COD_FEE, $this->_store);
68
+
69
+ return $displayMode;
70
+ }
71
+
72
+ /**
73
+ * Get the tax label for either incl. or excl. tax.
74
+ *
75
+ * @param boolean $inclTax
76
+ *
77
+ * @return string
78
+ */
79
+ public function getTaxLabel($inclTax = false)
80
+ {
81
+ $taxLabel = Mage::helper('tax')->getIncExcTaxLabel($inclTax);
82
+
83
+ return $taxLabel;
84
+ }
85
+
86
+ /**
87
+ * Get the PostNL COD fee value incl or excl. tax.
88
+ *
89
+ * @param bool $inclTax
90
+ *
91
+ * @return bool
92
+ */
93
+ public function getValue($inclTax = false)
94
+ {
95
+ $address = $this->getTotal()->getAddress();
96
+
97
+ $exclTax = $address->getPostnlCodFee();
98
+ if (!$inclTax) {
99
+ return $exclTax;
100
+ }
101
+
102
+ $inclTax = $exclTax + $address->getPostnlCodFeeTax();
103
+ return $inclTax;
104
+ }
105
+ }
app/code/community/TIG/PostNL/Block/Payment/Form/Cod.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_Payment_Form_Cod extends Mage_Payment_Block_Form
40
+ {
41
+ /**
42
+ * Xpath to the 'allow_for_buspakje' configuration setting.
43
+ */
44
+ const XPATH_ALLOW_FOR_BUSPAKJE = 'payment/postnl_cod/allow_for_buspakje';
45
+
46
+ /**
47
+ * @var string
48
+ */
49
+ protected $_eventPrefix = 'postnl_payment_form_cod';
50
+
51
+ /**
52
+ * @var string
53
+ */
54
+ protected $_instructions;
55
+
56
+ /**
57
+ * @var string
58
+ */
59
+ protected $_template = 'TIG/PostNL/payment/checkout/form/cod.phtml';
60
+
61
+ /**
62
+ * Get instructions text from config
63
+ *
64
+ * @return string
65
+ */
66
+ public function getInstructions()
67
+ {
68
+ if (is_null($this->_instructions)) {
69
+ $this->_instructions = $this->getMethod()->getInstructions();
70
+ }
71
+ return $this->_instructions;
72
+ }
73
+
74
+ /**
75
+ * Check if the PostNL COD payment method may be shown for letter box parcel orders.
76
+ *
77
+ * @return boolean
78
+ */
79
+ public function canShowForBuspakje()
80
+ {
81
+ /**
82
+ * Check the configuration setting.
83
+ */
84
+ $showForBuspakje = Mage::getStoreConfigFlag(self::XPATH_ALLOW_FOR_BUSPAKJE, Mage::app()->getStore()->getId());
85
+ if ($showForBuspakje) {
86
+ return true;
87
+ }
88
+
89
+ /**
90
+ * Check if the buspakje calculation mode is set to automatic.
91
+ */
92
+ $helper = Mage::helper('postnl');
93
+ $calculationMode = $helper->getBuspakjeCalculationMode();
94
+ if ($calculationMode != 'automatic') {
95
+ return true;
96
+ }
97
+
98
+ /**
99
+ * Check if the current quote fits as a letter box parcel.
100
+ */
101
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
102
+ if (!$helper->fitsAsBuspakje($quote->getAllItems())) {
103
+ return true;
104
+ }
105
+
106
+ return false;
107
+ }
108
+
109
+ /**
110
+ * Renders a template block. Also throws 2 events based on the current event prefix.
111
+ *
112
+ * @return string
113
+ */
114
+ protected function _toHtml()
115
+ {
116
+ Mage::dispatchEvent($this->_eventPrefix . '_to_html_before');
117
+
118
+ $html = parent::_toHtml();
119
+
120
+ Mage::dispatchEvent($this->_eventPrefix . '_to_html_after');
121
+ return $html;
122
+ }
123
+ }
app/code/community/TIG/PostNL/Block/Payment/Info.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Payment_Info extends Mage_Payment_Block_Info
40
+ {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_payment_info';
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
+
61
+ }
app/code/community/TIG/PostNL/Block/Payment/Sales/Order/Creditmemo/Totals/CodFee.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Payment_Sales_Order_Creditmemo_Totals_CodFee extends Mage_Sales_Block_Order_Creditmemo_Totals
40
+ {
41
+ /**
42
+ * Display modes for the PostNL COD fee.
43
+ */
44
+ const DISPLAY_MODE_EXCL = 1;
45
+ const DISPLAY_MODE_INCL = 2;
46
+ const DISPLAY_MODE_BOTH = 3;
47
+
48
+ /**
49
+ * Xpath to the PostNL COD fee display mode setting.
50
+ */
51
+ const XPATH_DISPLAY_MODE_COD_FEE = 'tax/sales_display/postnl_cod_fee';
52
+
53
+ /**
54
+ * Initialize order totals array
55
+ *
56
+ * @return $this
57
+ */
58
+ public function initTotals()
59
+ {
60
+ /**
61
+ * @var Mage_Adminhtml_Block_Sales_Order_Invoice_Totals $parent
62
+ * @var Mage_Sales_Model_Order_Creditmemo $creditmemo
63
+ */
64
+ $parent = $this->getParentBlock();
65
+ $creditmemo = $parent->getCreditmemo();
66
+
67
+ $fee = $creditmemo->getPostnlCodFee();
68
+ $baseFee = $creditmemo->getBasePostnlCodFee();
69
+
70
+ if ($fee < 0.01 || $baseFee < 0.01) {
71
+ return $this;
72
+ }
73
+
74
+ $displayMode = $this->getDisplayMode();
75
+ $baseLabel = Mage::helper('postnl/payment')->getPostnlCodFeeLabel($creditmemo->getStoreId());
76
+
77
+ if ($displayMode === self::DISPLAY_MODE_EXCL
78
+ || $displayMode === self::DISPLAY_MODE_BOTH
79
+ && $creditmemo->getId()
80
+ ) {
81
+ $label = $baseLabel;
82
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
83
+ $label .= ' (' . $this->getTaxLabel(false) . ')';
84
+ }
85
+
86
+ $total = new Varien_Object();
87
+ $total->setLabel($label)
88
+ ->setValue($fee)
89
+ ->setBaseValue($baseFee)
90
+ ->setCode('postnl_cod_fee');
91
+
92
+ $parent->addTotal($total, 'subtotal_incl');
93
+ }
94
+
95
+ if ($displayMode === self::DISPLAY_MODE_INCL
96
+ || $displayMode === self::DISPLAY_MODE_BOTH
97
+ && $creditmemo->getId()
98
+ ) {
99
+ $label = $baseLabel;
100
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
101
+ $label .= ' (' . $this->getTaxLabel(true) . ')';
102
+ }
103
+
104
+ $totalInclTax = new Varien_Object();
105
+ $totalInclTax->setLabel($label)
106
+ ->setValue($fee + $creditmemo->getPostnlCodFeeTax())
107
+ ->setBaseValue($baseFee + $creditmemo->getBasePostnlCodFeeTax())
108
+ ->setCode('postnl_cod_fee_incl_tax');
109
+
110
+ $parent->addTotal($totalInclTax, 'subtotal_incl');
111
+ }
112
+
113
+ return $this;
114
+ }
115
+
116
+ /**
117
+ * Get the display mode for the PostNL COD fee.
118
+ *
119
+ * @return int
120
+ */
121
+ public function getDisplayMode()
122
+ {
123
+ $displayMode = (int) Mage::getStoreConfig(self::XPATH_DISPLAY_MODE_COD_FEE, $this->_store);
124
+
125
+ return $displayMode;
126
+ }
127
+
128
+ /**
129
+ * Get the tax label for either incl. or excl. tax.
130
+ *
131
+ * @param boolean $inclTax
132
+ *
133
+ * @return string
134
+ */
135
+ public function getTaxLabel($inclTax = false)
136
+ {
137
+ $taxLabel = Mage::helper('tax')->getIncExcText($inclTax);
138
+
139
+ return $taxLabel;
140
+ }
141
+ }
app/code/community/TIG/PostNL/Block/Payment/Sales/Order/Invoice/Totals/CodFee.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Payment_Sales_Order_Invoice_Totals_CodFee extends Mage_Sales_Block_Order_Invoice_Totals
40
+ {
41
+ /**
42
+ * Display modes for the PostNL COD fee.
43
+ */
44
+ const DISPLAY_MODE_EXCL = 1;
45
+ const DISPLAY_MODE_INCL = 2;
46
+ const DISPLAY_MODE_BOTH = 3;
47
+
48
+ /**
49
+ * Xpath to the PostNL COD fee display mode setting.
50
+ */
51
+ const XPATH_DISPLAY_MODE_COD_FEE = 'tax/sales_display/postnl_cod_fee';
52
+
53
+ /**
54
+ * Initialize order totals array
55
+ *
56
+ * @return $this
57
+ */
58
+ public function initTotals()
59
+ {
60
+ /**
61
+ * @var Mage_Adminhtml_Block_Sales_Order_Invoice_Totals $parent
62
+ */
63
+ $parent = $this->getParentBlock();
64
+ $invoice = $parent->getInvoice();
65
+
66
+ $fee = $invoice->getPostnlCodFee();
67
+ $baseFee = $invoice->getBasePostnlCodFee();
68
+
69
+ if ($fee < 0.01 || $baseFee < 0.01) {
70
+ return $this;
71
+ }
72
+
73
+ $displayMode = $this->getDisplayMode();
74
+ $baseLabel = Mage::helper('postnl/payment')->getPostnlCodFeeLabel($invoice->getStoreId());
75
+
76
+ if ($displayMode === self::DISPLAY_MODE_EXCL || $displayMode === self::DISPLAY_MODE_BOTH) {
77
+ $label = $baseLabel;
78
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
79
+ $label .= ' (' . $this->getTaxLabel(false) . ')';
80
+ }
81
+
82
+ $total = new Varien_Object();
83
+ $total->setLabel($label)
84
+ ->setValue($fee)
85
+ ->setBaseValue($baseFee)
86
+ ->setCode('postnl_cod_fee');
87
+
88
+ $parent->addTotalBefore($total, 'shipping');
89
+ }
90
+
91
+ if ($displayMode === self::DISPLAY_MODE_INCL || $displayMode === self::DISPLAY_MODE_BOTH) {
92
+ $label = $baseLabel;
93
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
94
+ $label .= ' (' . $this->getTaxLabel(true) . ')';
95
+ }
96
+
97
+ $totalInclTax = new Varien_Object();
98
+ $totalInclTax->setLabel($label)
99
+ ->setValue($fee + $invoice->getPostnlCodFeeTax())
100
+ ->setBaseValue($baseFee + $invoice->getBasePostnlCodFeeTax())
101
+ ->setCode('postnl_cod_fee_incl_tax');
102
+
103
+ $parent->addTotalBefore($totalInclTax, 'shipping');
104
+ }
105
+
106
+ return $this;
107
+ }
108
+
109
+ /**
110
+ * Get the display mode for the PostNL COD fee.
111
+ *
112
+ * @return int
113
+ */
114
+ public function getDisplayMode()
115
+ {
116
+ $displayMode = (int) Mage::getStoreConfig(self::XPATH_DISPLAY_MODE_COD_FEE, $this->_store);
117
+
118
+ return $displayMode;
119
+ }
120
+
121
+ /**
122
+ * Get the tax label for either incl. or excl. tax.
123
+ *
124
+ * @param boolean $inclTax
125
+ *
126
+ * @return string
127
+ */
128
+ public function getTaxLabel($inclTax = false)
129
+ {
130
+ $taxLabel = Mage::helper('tax')->getIncExcText($inclTax);
131
+
132
+ return $taxLabel;
133
+ }
134
+ }
app/code/community/TIG/PostNL/Block/Payment/Sales/Order/Totals/CodFee.php ADDED
@@ -0,0 +1,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.
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_Payment_Sales_Order_Totals_CodFee extends Mage_Sales_Block_Order_Totals
40
+ {
41
+ /**
42
+ * Display modes for the PostNL COD fee.
43
+ */
44
+ const DISPLAY_MODE_EXCL = 1;
45
+ const DISPLAY_MODE_INCL = 2;
46
+ const DISPLAY_MODE_BOTH = 3;
47
+
48
+ /**
49
+ * Xpath to the PostNL COD fee display mode setting.
50
+ */
51
+ const XPATH_DISPLAY_MODE_COD_FEE = 'tax/sales_display/postnl_cod_fee';
52
+
53
+ /**
54
+ * Initialize order totals array
55
+ *
56
+ * @return $this
57
+ */
58
+ public function initTotals()
59
+ {
60
+ $parent = $this->getParentBlock();
61
+ $order = $this->getOrder();
62
+
63
+ $fee = $order->getPostnlCodFee();
64
+ $baseFee = $order->getBasePostnlCodFee();
65
+
66
+ if ($fee < 0.01 || $baseFee < 0.01) {
67
+ return $this;
68
+ }
69
+
70
+ $displayMode = $this->getDisplayMode();
71
+ $baseLabel = Mage::helper('postnl/payment')->getPostnlCodFeeLabel($order->getStoreId());
72
+
73
+ if ($displayMode === self::DISPLAY_MODE_EXCL || $displayMode === self::DISPLAY_MODE_BOTH) {
74
+ $label = $baseLabel;
75
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
76
+ $label .= ' (' . $this->getTaxLabel(false) . ')';
77
+ }
78
+
79
+ $total = new Varien_Object();
80
+ $total->setLabel($label)
81
+ ->setValue($fee)
82
+ ->setBaseValue($baseFee)
83
+ ->setCode('postnl_cod_fee');
84
+
85
+ $parent->addTotalBefore($total, 'shipping');
86
+ }
87
+
88
+ if ($displayMode === self::DISPLAY_MODE_INCL || $displayMode === self::DISPLAY_MODE_BOTH) {
89
+ $label = $baseLabel;
90
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
91
+ $label .= ' (' . $this->getTaxLabel(true) . ')';
92
+ }
93
+
94
+ $totalInclTax = new Varien_Object();
95
+ $totalInclTax->setLabel($label)
96
+ ->setValue($fee + $order->getPostnlCodFeeTax())
97
+ ->setBaseValue($baseFee + $order->getBasePostnlCodFeeTax())
98
+ ->setCode('postnl_cod_fee_incl_tax');
99
+
100
+ $parent->addTotalBefore($totalInclTax, 'shipping');
101
+ }
102
+
103
+ return $this;
104
+ }
105
+
106
+ /**
107
+ * Get the display mode for the PostNL COD fee.
108
+ *
109
+ * @return int
110
+ */
111
+ public function getDisplayMode()
112
+ {
113
+ $displayMode = (int) Mage::getStoreConfig(self::XPATH_DISPLAY_MODE_COD_FEE, $this->_store);
114
+
115
+ return $displayMode;
116
+ }
117
+
118
+ /**
119
+ * Get the tax label for either incl. or excl. tax.
120
+ *
121
+ * @param boolean $inclTax
122
+ *
123
+ * @return string
124
+ */
125
+ public function getTaxLabel($inclTax = false)
126
+ {
127
+ $taxLabel = Mage::helper('tax')->getIncExcText($inclTax);
128
+
129
+ return $taxLabel;
130
+ }
131
+ }
app/code/community/TIG/PostNL/Controller/Adminhtml/Shipment.php ADDED
@@ -0,0 +1,631 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Controller_Adminhtml_Shipment extends Mage_Adminhtml_Controller_Action
40
+ {
41
+ /**
42
+ * Used module name in current adminhtml controller.
43
+ */
44
+ protected $_usedModuleName = 'TIG_PostNL';
45
+
46
+ /**
47
+ * @var array
48
+ */
49
+ protected $_warnings = array();
50
+
51
+ /**
52
+ * @return array
53
+ */
54
+ public function getWarnings()
55
+ {
56
+ return $this->_warnings;
57
+ }
58
+
59
+ /**
60
+ * @param array $warnings
61
+ *
62
+ * @return $this
63
+ */
64
+ public function setWarnings(array $warnings)
65
+ {
66
+ $this->_warnings = $warnings;
67
+
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * @param array|string $warning
73
+ *
74
+ * @return $this
75
+ */
76
+ public function addWarning($warning)
77
+ {
78
+ if (!is_array($warning)) {
79
+ $warning = array(
80
+ 'entity_id' => null,
81
+ 'code' => null,
82
+ 'description' => $warning,
83
+ );
84
+ }
85
+
86
+ $warnings = $this->getWarnings();
87
+ $warnings[] = $warning;
88
+
89
+ $this->setWarnings($warnings);
90
+ return $this;
91
+ }
92
+
93
+ /**
94
+ * Get shipment Ids from the request.
95
+ *
96
+ * @return array
97
+ *
98
+ * @throws TIG_PostNL_Exception
99
+ */
100
+ protected function _getShipmentIds()
101
+ {
102
+ $shipmentIds = $this->getRequest()->getParam('shipment_ids', array());
103
+
104
+ /**
105
+ * Check if a shipment was selected.
106
+ */
107
+ if (!is_array($shipmentIds) || empty($shipmentIds)) {
108
+ throw new TIG_PostNL_Exception(
109
+ $this->__('Please select one or more shipments.'),
110
+ 'POSTNL-0013'
111
+ );
112
+ }
113
+
114
+ return $shipmentIds;
115
+ }
116
+
117
+ /**
118
+ * Get order Ids from the request.
119
+ *
120
+ * @return array
121
+ *
122
+ * @throws TIG_PostNL_Exception
123
+ */
124
+ protected function _getOrderIds()
125
+ {
126
+ $orderIds = $this->getRequest()->getParam('order_ids', array());
127
+
128
+ /**
129
+ * Check if an order was selected.
130
+ */
131
+ if (!is_array($orderIds) || empty($orderIds)) {
132
+ throw new TIG_PostNL_Exception(
133
+ $this->__('Please select one or more orders.'),
134
+ 'POSTNL-0011'
135
+ );
136
+ }
137
+
138
+ return $orderIds;
139
+ }
140
+
141
+ /**
142
+ * Gets the postnl shipment associated with a shipment
143
+ *
144
+ * @param int $shipmentId
145
+ *
146
+ * @return TIG_PostNL_Model_Core_Shipment
147
+ */
148
+ protected function _getPostnlShipment($shipmentId)
149
+ {
150
+ $postnlShipment = Mage::getModel('postnl_core/shipment')->load($shipmentId, 'shipment_id');
151
+
152
+ return $postnlShipment;
153
+ }
154
+
155
+ /**
156
+ * Initialize shipment items QTY
157
+ *
158
+ * @param Mage_Sales_Model_Order $order
159
+ *
160
+ * @return array
161
+ */
162
+ protected function _getItemQtys($order)
163
+ {
164
+ $itemQtys = array();
165
+
166
+ /**
167
+ * @var Mage_Sales_Model_Order_Item $item
168
+ */
169
+ $items = $order->getAllVisibleItems();
170
+ foreach ($items as $item) {
171
+ /**
172
+ * the qty to ship is the total remaining (not yet shipped) qty of every item
173
+ */
174
+ $itemQty = $item->getQtyOrdered() - $item->getQtyShipped();
175
+
176
+ $itemQtys[$item->getId()] = $itemQty;
177
+ }
178
+
179
+ return $itemQtys;
180
+ }
181
+
182
+ /**
183
+ * Creates a shipment of an order containing all available items
184
+ *
185
+ * @param int $orderId
186
+ *
187
+ * @return int
188
+ *
189
+ * @throws TIG_PostNL_Exception
190
+ */
191
+ protected function _createShipment($orderId)
192
+ {
193
+ /**
194
+ * @var Mage_Sales_Model_Order $order
195
+ */
196
+ $order = Mage::getModel('sales/order')->load($orderId);
197
+
198
+ if (!$order->canShip()) {
199
+ throw new TIG_PostNL_Exception(
200
+ $this->__('Order #%s cannot be shipped at this time.', $order->getIncrementId()),
201
+ 'POSTNL-0015'
202
+ );
203
+ }
204
+
205
+ $shipment = Mage::getModel('sales/service_order', $order)
206
+ ->prepareShipment($this->_getItemQtys($order));
207
+
208
+ $shipment->register();
209
+ $this->_saveShipment($shipment);
210
+
211
+ return $shipment->getId();
212
+ }
213
+
214
+ /**
215
+ * Save shipment and order in one transaction
216
+ *
217
+ * @param Mage_Sales_Model_Order_Shipment $shipment
218
+ *
219
+ * @return $this
220
+ */
221
+ protected function _saveShipment($shipment)
222
+ {
223
+ $shipment->getOrder()->setIsInProcess(true);
224
+ Mage::getModel('core/resource_transaction')
225
+ ->addObject($shipment)
226
+ ->addObject($shipment->getOrder())
227
+ ->save();
228
+
229
+ return $this;
230
+ }
231
+
232
+ /**
233
+ * Retrieves the shipping label for a given shipment ID.
234
+ *
235
+ * If the shipment has a stored label, it is returned. Otherwise a new one is generated.
236
+ *
237
+ * @param Mage_Sales_Model_Order_Shipment|TIG_PostNL_Model_Core_Shipment $shipment
238
+ * @param boolean $confirm Optional parameter to also confirm the shipment
239
+ *
240
+ * @return array
241
+ *
242
+ * @throws TIG_PostNL_Exception
243
+ */
244
+ protected function _getLabels($shipment, $confirm = false)
245
+ {
246
+ /**
247
+ * Load the PostNL shipment.
248
+ */
249
+ if ($shipment instanceof Mage_Sales_Model_Order_Shipment) {
250
+ $postnlShipment = $this->_getPostnlShipment($shipment->getId());
251
+ } else {
252
+ $postnlShipment = $shipment;
253
+ }
254
+
255
+ /**
256
+ * Check if the shipment already has any labels. If so, return those. If we also need to confirm the shipment,
257
+ * do that first.
258
+ */
259
+ if ($postnlShipment->hasLabels()) {
260
+ if ($confirm === true && !$postnlShipment->isConfirmed() && $postnlShipment->canConfirm()) {
261
+ $this->_confirmShipment($postnlShipment);
262
+ }
263
+
264
+ return $postnlShipment->getlabels();
265
+ }
266
+
267
+ /**
268
+ * If the PostNL shipment is new, set the magento shipment ID.
269
+ */
270
+ if (!$postnlShipment->getShipmentId()) {
271
+ $postnlShipment->setShipmentId($shipment->getId());
272
+ }
273
+
274
+ /**
275
+ * If the shipment does not have a barcode, generate one.
276
+ */
277
+ if (!$postnlShipment->getMainBarcode() && $postnlShipment->canGenerateBarcode()) {
278
+ $postnlShipment->generateBarcodes();
279
+ }
280
+
281
+ if ($confirm === true
282
+ && !$postnlShipment->hasLabels()
283
+ && !$postnlShipment->isConfirmed()
284
+ && $postnlShipment->canConfirm(true)
285
+ ) {
286
+ /**
287
+ * Confirm the shipment and request a new label.
288
+ */
289
+ $postnlShipment->confirmAndGenerateLabel();
290
+
291
+ if ($postnlShipment->canAddTrackingCode()) {
292
+ $postnlShipment->addTrackingCodeToShipment();
293
+ }
294
+
295
+ $postnlShipment->save();
296
+ } else {
297
+ /**
298
+ * generate new shipping labels without confirming.
299
+ */
300
+ $postnlShipment->generateLabel()
301
+ ->save();
302
+ }
303
+
304
+ $labels = $postnlShipment->getLabels();
305
+ return $labels;
306
+ }
307
+
308
+ /**
309
+ * Confirms the shipment without printing labels.
310
+ *
311
+ * @param Mage_Sales_Model_Order_Shipment|TIG_PostNL_Model_Core_Shipment $shipment
312
+ *
313
+ * @return $this
314
+ *
315
+ * @throws TIG_PostNL_Exception
316
+ */
317
+ protected function _confirmShipment($shipment)
318
+ {
319
+ /**
320
+ * Load the PostNL shipment.
321
+ */
322
+ if ($shipment instanceof Mage_Sales_Model_Order_Shipment) {
323
+ $postnlShipment = $this->_getPostnlShipment($shipment->getId());
324
+ } else {
325
+ $postnlShipment = $shipment;
326
+ }
327
+
328
+ /**
329
+ * Prevent EU shipments from being confirmed if their labels are not yet printed.
330
+ */
331
+ if ($postnlShipment->isEuShipment() && !$postnlShipment->getLabelsPrinted()) {
332
+ throw new TIG_PostNL_Exception(
333
+ $this->__(
334
+ "Shipment #%s could not be confirmed, because for EU shipments you may only confirm a shipment " .
335
+ "after it's labels have been printed.",
336
+ $postnlShipment->getShipment()->getIncrementId()
337
+ ),
338
+ 'POSTNL-0016'
339
+ );
340
+ }
341
+
342
+ /**
343
+ * If the PostNL shipment is new, set the magento shipment ID.
344
+ */
345
+ if (!$postnlShipment->getShipmentId()) {
346
+ $postnlShipment->setShipmentId($shipment->getId());
347
+ }
348
+
349
+ /**
350
+ * If the shipment does not have a main barcode, generate new barcodes.
351
+ */
352
+ if (!$postnlShipment->getMainBarcode() && $postnlShipment->canGenerateBarcode()) {
353
+ $postnlShipment->generateBarcodes();
354
+ }
355
+
356
+ if ($postnlShipment->getConfirmStatus() === $postnlShipment::CONFIRM_STATUS_CONFIRMED) {
357
+ /**
358
+ * The shipment is already confirmed.
359
+ */
360
+ throw new TIG_PostNL_Exception(
361
+ $this->__('Shipment #%s has already been confirmed.', $postnlShipment->getShipment()->getIncrementId()),
362
+ 'POSTNL-0017'
363
+ );
364
+ }
365
+
366
+ if (!$postnlShipment->canConfirm()) {
367
+ /**
368
+ * The shipment cannot be confirmed at this time.
369
+ */
370
+ throw new TIG_PostNL_Exception(
371
+ $this->__(
372
+ 'Shipment #%s cannot be confirmed at this time.',
373
+ $postnlShipment->getShipment()->getIncrementId()
374
+ ),
375
+ 'POSTNL-00018'
376
+ );
377
+ }
378
+
379
+ /**
380
+ * Confirm the shipment.
381
+ */
382
+ $postnlShipment->confirm();
383
+
384
+ if ($postnlShipment->canAddTrackingCode()) {
385
+ $postnlShipment->addTrackingCodeToShipment();
386
+ }
387
+
388
+ $postnlShipment->save();
389
+
390
+ return $this;
391
+ }
392
+
393
+ /**
394
+ * Load an array of shipments based on an array of shipmentIds and check if they're shipped using PostNL
395
+ *
396
+ * @param array|int $shipmentIds
397
+ * @param boolean $loadPostnlShipments Flag that determines whether the shipments will be loaded as
398
+ * Mage_Sales_Model_Shipment or TIG_PostNL_Model_Core_Shipment objects.
399
+ * @param boolean $throwException Flag whether an exception should be thrown when loading the shipment fails.
400
+ *
401
+ * @return array
402
+ *
403
+ * @throws TIG_PostNL_Exception
404
+ */
405
+ protected function _loadAndCheckShipments($shipmentIds, $loadPostnlShipments = false, $throwException = true)
406
+ {
407
+ if (!is_array($shipmentIds)) {
408
+ $shipmentIds = array($shipmentIds);
409
+ }
410
+
411
+ $shipments = array();
412
+ foreach ($shipmentIds as $shipmentId) {
413
+ /**
414
+ * Load the shipment.
415
+ *
416
+ * @var Mage_Sales_Model_Order_Shipment|TIG_PostNL_Model_Core_Shipment|boolean $shipment
417
+ */
418
+ $shipment = $this->_loadShipment($shipmentId, $loadPostnlShipments);
419
+
420
+ if (!$shipment && $throwException) {
421
+ throw new TIG_PostNL_Exception(
422
+ $this->__(
423
+ 'This action is not available for shipment #%s, because it was not shipped using PostNL.',
424
+ $shipment->getIncrementId()
425
+ ),
426
+ 'POSTNL-0009'
427
+ );
428
+ } elseif (!$shipment) {
429
+ $this->addWarning(
430
+ array(
431
+ 'entity_id' => $shipmentId,
432
+ 'code' => 'POSTNL-0009',
433
+ 'description' => $this->__(
434
+ 'This action is not available for shipment #%s, because it was not shipped using PostNL.',
435
+ $shipmentId
436
+ ),
437
+ )
438
+ );
439
+
440
+ continue;
441
+ }
442
+
443
+ $shipments[] = $shipment;
444
+ }
445
+
446
+ return $shipments;
447
+ }
448
+
449
+ /**
450
+ * Load a shipment based on a shipment ID.
451
+ *
452
+ * @param int $shipmentId
453
+ * @param boolean $loadPostnlShipments
454
+ *
455
+ * @return boolean|Mage_Sales_Model_Order_Shipment|TIG_PostNL_Model_Core_Shipment
456
+ */
457
+ protected function _loadShipment($shipmentId, $loadPostnlShipments)
458
+ {
459
+ if ($loadPostnlShipments === false) {
460
+ /**
461
+ * @var Mage_Sales_Model_Order_Shipment $shipment
462
+ */
463
+ $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
464
+ if (!$shipment || !$shipment->getId()) {
465
+ return false;
466
+ }
467
+
468
+ $shippingMethod = $shipment->getOrder()->getShippingMethod();
469
+ } else {
470
+ /**
471
+ * @var TIG_PostNL_Model_Core_Shipment $shipment
472
+ */
473
+ $shipment = $this->_getPostnlShipment($shipmentId);
474
+ if (!$shipment || !$shipment->getId()) {
475
+ return false;
476
+ }
477
+
478
+ $shippingMethod = $shipment->getShipment()->getOrder()->getShippingMethod();
479
+ }
480
+
481
+ /**
482
+ * Check if the shipping method used is allowed
483
+ */
484
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
485
+ return false;
486
+ }
487
+
488
+ return $shipment;
489
+ }
490
+
491
+ /**
492
+ * Output the specified string as a pdf.
493
+ *
494
+ * @param string $filename
495
+ * @param string $output
496
+ *
497
+ * @return $this
498
+ * @throws Zend_Controller_Response_Exception
499
+ */
500
+ protected function _preparePdfResponse($filename, $output)
501
+ {
502
+ $this->getResponse()
503
+ ->setHttpResponseCode(200)
504
+ ->setHeader('Pragma', 'public', true)
505
+ ->setHeader('Cache-Control', 'private, max-age=0, must-revalidate', true)
506
+ ->setHeader('Content-type', 'application/pdf', true)
507
+ ->setHeader('Content-Disposition', 'inline; filename="' . $filename . '"')
508
+ ->setHeader('Last-Modified', date('r'))
509
+ ->setBody($output);
510
+
511
+ return $this;
512
+ }
513
+
514
+ /**
515
+ * Checks if any warnings were received while processing the shipments and/or orders. If any warnings are found they
516
+ * are added to the adminhtml session as a notice.
517
+ *
518
+ * @return $this
519
+ */
520
+ protected function _checkForWarnings()
521
+ {
522
+ /**
523
+ * Check if any warnings were registered
524
+ */
525
+ $cifWarnings = Mage::registry('postnl_cif_warnings');
526
+
527
+ if (is_array($cifWarnings) && !empty($cifWarnings)) {
528
+ $this->_addWarningMessages($cifWarnings, $this->__('PostNL replied with the following warnings:'));
529
+ }
530
+
531
+ $warnings = $this->getWarnings();
532
+
533
+ if (!empty($warnings)) {
534
+ $this->_addWarningMessages(
535
+ $warnings,
536
+ $this->__('The following shipments or orders could not be processed:')
537
+ );
538
+ }
539
+
540
+ return $this;
541
+ }
542
+
543
+ /**
544
+ * Add an array of warning messages to the adminhtml session.
545
+ *
546
+ * @param $warnings
547
+ * @param string $headerText
548
+ *
549
+ * @return $this
550
+ * @throws TIG_PostNL_Exception
551
+ */
552
+ protected function _addWarningMessages($warnings, $headerText = '')
553
+ {
554
+ $helper = Mage::helper('postnl');
555
+
556
+ /**
557
+ * Create a warning message to display to the merchant.
558
+ */
559
+ $warningMessage = $headerText;
560
+ $warningMessage .= '<ul class="postnl-warning">';
561
+
562
+ /**
563
+ * Add each warning to the message.
564
+ */
565
+ foreach ($warnings as $warning) {
566
+ /**
567
+ * Warnings must have a description.
568
+ */
569
+ if (!array_key_exists('description', $warning)) {
570
+ continue;
571
+ }
572
+
573
+ /**
574
+ * Codes are optional for warnings, but must be present in the array. If no code is found in the warning we
575
+ * add an empty one.
576
+ */
577
+ if (!array_key_exists('code', $warning)) {
578
+ $warning['code'] = null;
579
+ }
580
+
581
+ /**
582
+ * Get the formatted warning message.
583
+ */
584
+ $warningText = $helper->getSessionMessage(
585
+ $warning['code'],
586
+ 'warning',
587
+ $this->__($warning['description'])
588
+ );
589
+
590
+ /**
591
+ * Prepend the warning's entity ID if present.
592
+ */
593
+ if (!empty($warning['entity_id'])) {
594
+ $warningText = $warning['entity_id'] . ': ' . $warningText;
595
+ }
596
+
597
+ /**
598
+ * Build the message proper.
599
+ */
600
+ $warningMessage .= '<li>' . $warningText . '</li>';
601
+ }
602
+
603
+ $warningMessage .= '</ul>';
604
+
605
+ /**
606
+ * Add the warnings to the session.
607
+ */
608
+ Mage::helper('postnl')->addSessionMessage('adminhtml/session', null, 'notice',
609
+ $warningMessage
610
+ );
611
+
612
+ return $this;
613
+ }
614
+
615
+ /**
616
+ * Checks if the specified actions are allowed.
617
+ *
618
+ * @param array $actions
619
+ *
620
+ * @throws TIG_PostNL_Exception
621
+ *
622
+ * @return bool
623
+ */
624
+ protected function _checkIsAllowed($actions = array())
625
+ {
626
+ $helper = Mage::helper('postnl');
627
+ $isAllowed = $helper->checkIsPostnlActionAllowed($actions, false);
628
+
629
+ return $isAllowed;
630
+ }
631
+ }
app/code/community/TIG/PostNL/Exception.php CHANGED
@@ -35,9 +35,7 @@
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
@@ -60,7 +58,7 @@ class TIG_PostNL_Exception extends Mage_Core_Exception
60
  parent::__construct($message, 0, $previous);
61
 
62
  /**
63
- * Replace the code with the actual, non-integer code
64
  */
65
  if ($code !== 0) {
66
  $code = (string) $code;
@@ -69,7 +67,7 @@ class TIG_PostNL_Exception extends Mage_Core_Exception
69
  }
70
 
71
  /**
72
- * Custom __toString method that includes the error code, if preset.
73
  *
74
  * @return string
75
  *
@@ -87,7 +85,7 @@ class TIG_PostNL_Exception extends Mage_Core_Exception
87
 
88
  $code = $this->getCode();
89
  if ($code !== 0 && !empty($code)) {
90
- $string .= " and code: '"
91
  . $this->getCode()
92
  . "'";
93
  }
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
  * General exception class for TIG_PostNL extension
40
  *
41
  * @see Mage_Core_Exception
58
  parent::__construct($message, 0, $previous);
59
 
60
  /**
61
+ * Replace the code with the actual, non-integer code.
62
  */
63
  if ($code !== 0) {
64
  $code = (string) $code;
67
  }
68
 
69
  /**
70
+ * Custom __toString method that includes the error code, if present.
71
  *
72
  * @return string
73
  *
85
 
86
  $code = $this->getCode();
87
  if ($code !== 0 && !empty($code)) {
88
+ $string .= " and code '"
89
  . $this->getCode()
90
  . "'";
91
  }
app/code/community/TIG/PostNL/Helper/AddressValidation.php CHANGED
@@ -41,28 +41,28 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
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 determine 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.
@@ -119,7 +119,7 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
119
  return true;
120
  }
121
 
122
- $useSplitStreet = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_STREET, $storeId);
123
  return $useSplitStreet;
124
  }
125
 
@@ -140,7 +140,7 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
140
  return true;
141
  }
142
 
143
- $useSplitStreet = Mage::getStoreConfigFlag(self::XML_PATH_SPLIT_HOUSENUMBER, $storeId);
144
  return $useSplitStreet;
145
  }
146
 
@@ -161,7 +161,7 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
161
  return 1;
162
  }
163
 
164
- $streetnameField = (int) Mage::getStoreConfig(self::XML_PATH_STREETNAME_FIELD, $storeId);
165
  return $streetnameField;
166
  }
167
 
@@ -183,7 +183,7 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
183
  return 2;
184
  }
185
 
186
- $housenumberField = (int) Mage::getStoreConfig(self::XML_PATH_HOUSENUMBER_FIELD, $storeId);
187
  return $housenumberField;
188
  }
189
 
@@ -204,7 +204,7 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
204
  return 3;
205
  }
206
 
207
- $housenumberExtensionField = (int) Mage::getStoreConfig(self::XML_PATH_HOUSENUMBER_EXTENSION_FIELD, $storeId);
208
  return $housenumberExtensionField;
209
  }
210
 
@@ -221,7 +221,7 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
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
 
@@ -239,7 +239,7 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
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
  }
@@ -277,7 +277,7 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
277
  $storeId = Mage::app()->getStore()->getId();
278
  }
279
 
280
- $usePostcodeCheck = Mage::getStoreConfigFlag(self::XML_PATH_USE_POSTCODE_CHECK, $storeId);
281
  return $usePostcodeCheck;
282
  }
283
 
@@ -312,10 +312,10 @@ class TIG_PostNL_Helper_AddressValidation extends TIG_PostNL_Helper_Data
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;
41
  /**
42
  * XML path to use_postcode_check setting
43
  */
44
+ const XPATH_USE_POSTCODE_CHECK = 'postnl/cif_address/use_postcode_check';
45
 
46
  /**
47
  * Constants containing XML paths to cif address configuration options
48
  */
49
+ const XPATH_SPLIT_STREET = 'postnl/cif_address/split_street';
50
+ const XPATH_STREETNAME_FIELD = 'postnl/cif_address/streetname_field';
51
+ const XPATH_HOUSENUMBER_FIELD = 'postnl/cif_address/housenr_field';
52
+ const XPATH_SPLIT_HOUSENUMBER = 'postnl/cif_address/split_housenr';
53
+ const XPATH_HOUSENUMBER_EXTENSION_FIELD = 'postnl/cif_address/housenr_extension_field';
54
 
55
  /**
56
  * XML paths to flags that determine which environment allows the postcode check functionality
57
  */
58
+ const XPATH_POSTCODE_CHECK_IN_CHECKOUT = 'postnl/cif_address/postcode_check_in_checkout';
59
+ const XPATH_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 XPATH_POSTCODE_CHECK_MAX_ATTEMPTS = 'postnl/cif_address/postcode_check_max_attempts';
65
+ const XPATH_POSTCODE_CHECK_TIMEOUT = 'postnl/cif_address/postcode_check_timeout';
66
 
67
  /**
68
  * Xpath to OSC street fields sort order.
119
  return true;
120
  }
121
 
122
+ $useSplitStreet = Mage::getStoreConfigFlag(self::XPATH_SPLIT_STREET, $storeId);
123
  return $useSplitStreet;
124
  }
125
 
140
  return true;
141
  }
142
 
143
+ $useSplitStreet = Mage::getStoreConfigFlag(self::XPATH_SPLIT_HOUSENUMBER, $storeId);
144
  return $useSplitStreet;
145
  }
146
 
161
  return 1;
162
  }
163
 
164
+ $streetnameField = (int) Mage::getStoreConfig(self::XPATH_STREETNAME_FIELD, $storeId);
165
  return $streetnameField;
166
  }
167
 
183
  return 2;
184
  }
185
 
186
+ $housenumberField = (int) Mage::getStoreConfig(self::XPATH_HOUSENUMBER_FIELD, $storeId);
187
  return $housenumberField;
188
  }
189
 
204
  return 3;
205
  }
206
 
207
+ $housenumberExtensionField = (int) Mage::getStoreConfig(self::XPATH_HOUSENUMBER_EXTENSION_FIELD, $storeId);
208
  return $housenumberExtensionField;
209
  }
210
 
221
  $storeId = Mage::app()->getStore()->getId();
222
  }
223
 
224
+ $timeout = (int) Mage::getStoreConfig(self::XPATH_POSTCODE_CHECK_TIMEOUT, $storeId);
225
  return $timeout;
226
  }
227
 
239
  $storeId = Mage::app()->getStore()->getId();
240
  }
241
 
242
+ $maxAttempts = (int) Mage::getStoreConfig(self::XPATH_POSTCODE_CHECK_MAX_ATTEMPTS, $storeId);
243
  if (!$maxAttempts) {
244
  return 'false';
245
  }
277
  $storeId = Mage::app()->getStore()->getId();
278
  }
279
 
280
+ $usePostcodeCheck = Mage::getStoreConfigFlag(self::XPATH_USE_POSTCODE_CHECK, $storeId);
281
  return $usePostcodeCheck;
282
  }
283
 
312
  $environmentAllowed = false;
313
  switch ($environment) {
314
  case 'checkout':
315
+ $environmentAllowed = Mage::getStoreConfigFlag(self::XPATH_POSTCODE_CHECK_IN_CHECKOUT, $storeId);
316
  break;
317
  case 'addressbook':
318
+ $environmentAllowed = Mage::getStoreConfigFlag(self::XPATH_POSTCODE_CHECK_IN_ADDRESSBOOK, $storeId);
319
  break;
320
  case false:
321
  $environmentAllowed = true;
app/code/community/TIG/PostNL/Helper/Carrier.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_Carrier extends TIG_PostNL_Helper_Data
@@ -61,18 +61,26 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
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(
72
- 'postnl_postnl', //deprecated
73
- 'postnl_flatrate',
74
- 'postnl_tablerate',
75
- );
 
 
 
76
 
77
  /**
78
  * Gets an array of possible PostNL shipping methods
@@ -81,10 +89,66 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
81
  */
82
  public function getPostnlShippingMethods()
83
  {
84
- $shippingMethods = $this->_postnlShippingMethods;
 
 
 
 
 
 
 
85
  return $shippingMethods;
86
  }
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  /**
89
  * Alias for getCurrentPostnlShippingMethod()
90
  *
@@ -117,7 +181,7 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
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) {
@@ -138,6 +202,48 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
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
  *
@@ -159,7 +265,7 @@ class TIG_PostNL_Helper_Carrier extends TIG_PostNL_Helper_Data
159
 
160
  if (is_object($destination) && $destination instanceof Varien_Object) {
161
  $countryCode = $destination->getCountry();
162
- $postcode = $destination->getPostcode();
163
  }
164
 
165
  /**
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_Carrier extends TIG_PostNL_Helper_Data
61
  /**
62
  * XML path to rate type setting
63
  */
64
+ const XPATH_RATE_TYPE = 'carriers/postnl/rate_type';
65
+
66
+ /**
67
+ * Xpath to the 'postnl_shipping_methods' setting.
68
+ */
69
+ const XPATH_POSTNL_SHIPPING_METHODS = 'postnl/advanced/postnl_shipping_methods';
70
 
71
  /**
72
  * Array of possible PostNL shipping methods
73
  *
74
  * @var array
75
  */
76
+ protected $_postnlShippingMethods;
77
+
78
+ /**
79
+ * Array of shipping methods that have already been checked for whether they're PostNL.
80
+ *
81
+ * @var array
82
+ */
83
+ protected $_matchedMethods = array();
84
 
85
  /**
86
  * Gets an array of possible PostNL shipping methods
89
  */
90
  public function getPostnlShippingMethods()
91
  {
92
+ if ($this->_postnlShippingMethods) {
93
+ return $this->_postnlShippingMethods;
94
+ }
95
+
96
+ $shippingMethods = Mage::getStoreConfig(self::XPATH_POSTNL_SHIPPING_METHODS, Mage::app()->getStore()->getId());
97
+ $shippingMethods = explode(',', $shippingMethods);
98
+
99
+ $this->setPostnlShippingMethods($shippingMethods);
100
  return $shippingMethods;
101
  }
102
 
103
+ /**
104
+ * @param array $postnlShippingMethods
105
+ *
106
+ * @return $this
107
+ */
108
+ public function setPostnlShippingMethods($postnlShippingMethods)
109
+ {
110
+ $this->_postnlShippingMethods = $postnlShippingMethods;
111
+
112
+ return $this;
113
+ }
114
+
115
+ /**
116
+ * @return array
117
+ */
118
+ public function getMatchedMethods()
119
+ {
120
+ return $this->_matchedMethods;
121
+ }
122
+
123
+ /**
124
+ * @param array $matchedMethods
125
+ *
126
+ * @return $this
127
+ */
128
+ public function setMatchedMethods($matchedMethods)
129
+ {
130
+ $this->_matchedMethods = $matchedMethods;
131
+
132
+ return $this;
133
+ }
134
+
135
+ /**
136
+ * Adds a matched method to the matched methods array.
137
+ *
138
+ * @param string $method
139
+ * @param boolean $value
140
+ *
141
+ * @return $this
142
+ */
143
+ public function addMatchedMethod($method, $value)
144
+ {
145
+ $matchedMethods = $this->getMatchedMethods();
146
+ $matchedMethods[$method] = $value;
147
+
148
+ $this->setMatchedMethods($matchedMethods);
149
+ return $this;
150
+ }
151
+
152
  /**
153
  * Alias for getCurrentPostnlShippingMethod()
154
  *
181
  $storeId = Mage::app()->getStore()->getId();
182
  }
183
 
184
+ $rateType = Mage::getStoreConfig(self::XPATH_RATE_TYPE, $storeId);
185
 
186
  $carrier = self::POSTNL_CARRIER;
187
  switch ($rateType) {
202
  return $shippingMethod;
203
  }
204
 
205
+ /**
206
+ * Checks if a specified shipping method is a PostNL shipping method.
207
+ *
208
+ * @param $shippingMethod
209
+ *
210
+ * @return bool
211
+ */
212
+ public function isPostnlShippingMethod($shippingMethod)
213
+ {
214
+ /**
215
+ * Check if we've matched this shipping method before.
216
+ */
217
+ $matchedMethods = $this->getMatchedMethods();
218
+ if (isset($matchedMethods[$shippingMethod])) {
219
+ return $matchedMethods[$shippingMethod];
220
+ }
221
+
222
+ /**
223
+ * Check if the shipping method exists in the configured array of supported methods.
224
+ */
225
+ $postnlShippingMethods = $this->getPostnlShippingMethods();
226
+ if (in_array($shippingMethod, $postnlShippingMethods)) {
227
+ $this->addMatchedMethod($shippingMethod, true);
228
+ return true;
229
+ }
230
+
231
+ /**
232
+ * Some shipping methods add suffixes to the method code.
233
+ */
234
+ foreach ($postnlShippingMethods as $postnlShippingMethod) {
235
+ $regex = "/^({$postnlShippingMethod})(_?\d*)$/";
236
+
237
+ if (preg_match($regex, $shippingMethod) === 1) {
238
+ $this->addMatchedMethod($shippingMethod, true);
239
+ return true;
240
+ }
241
+ }
242
+
243
+ $this->addMatchedMethod($shippingMethod, false);
244
+ return false;
245
+ }
246
+
247
  /**
248
  * Constructs a PostNL track & trace url based on a barcode and the destination of the package (country and zipcode)
249
  *
265
 
266
  if (is_object($destination) && $destination instanceof Varien_Object) {
267
  $countryCode = $destination->getCountry();
268
+ $postcode = str_replace(' ', '', $destination->getPostcode());
269
  }
270
 
271
  /**
app/code/community/TIG/PostNL/Helper/Checkout.php CHANGED
@@ -41,24 +41,24 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
41
  /**
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.
48
  * N.B. last part of the XML path is missing.
49
  */
50
- const XML_PATH_CHECKOUT_PAYMENT_METHOD = 'postnl/checkout_payment_methods';
51
 
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
59
  */
60
- const XML_PATH_SHOW_CHECKOUT_FOR_LETTER = 'postnl/checkout/show_checkout_for_letter';
61
- const XML_PATH_SHOW_CHECKOUT_FOR_BACKORDERS = 'postnl/checkout/show_checkout_for_backorders';
62
 
63
  /**
64
  * Log filename to log all non-specific PostNL debug messages
@@ -266,7 +266,7 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
266
  /**
267
  * Check if PostNL Checkout may be used for 'letter' orders and if not, if the quote could fit in an envelope
268
  */
269
- $showCheckoutForLetters = Mage::getStoreConfigFlag(self::XML_PATH_SHOW_CHECKOUT_FOR_LETTER, $storeId);
270
  if (!$showCheckoutForLetters) {
271
  $isLetterQuote = $this->quoteIsLetter($quote, $storeId);
272
  if ($isLetterQuote) {
@@ -287,7 +287,7 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
287
  /**
288
  * Check if PostNL Checkout may be used for out-og-stock orders and if not, whether the quote has any such products
289
  */
290
- $showCheckoutForBackorders = Mage::getStoreConfigFlag(self::XML_PATH_SHOW_CHECKOUT_FOR_BACKORDERS, $storeId);
291
  if (!$showCheckoutForBackorders) {
292
  $containsOutOfStockItems = $this->quoteHasOutOfStockItems($quote);
293
  if ($containsOutOfStockItems) {
@@ -352,7 +352,7 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
352
  $totalWeight += $item->getRowWeight();
353
  }
354
 
355
- $kilograms = Mage::helper('postnl/cif')->standardizeWeight($totalWeight, $storeId);
356
 
357
  if ($kilograms < 2) {
358
  return true;
@@ -399,7 +399,7 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
399
  $storeId = Mage::app()->getStore()->getId();
400
  }
401
 
402
- $isActive = Mage::getStoreConfigFlag(self::XML_PATH_CHECKOUT_ACTIVE, $storeId);
403
  return $isActive;
404
  }
405
 
@@ -531,7 +531,7 @@ class TIG_PostNL_Helper_Checkout extends TIG_PostNL_Helper_Data
531
  * Go through each supported payment method. At least one of them must be activated.
532
  */
533
  $paymentMethods = $this->getCheckoutPaymentMethods();
534
- $paymentMethodSettings = Mage::getStoreConfig(self::XML_PATH_CHECKOUT_PAYMENT_METHOD, $storeId);
535
  foreach ($paymentMethods as $methodCode => $method) {
536
  if (array_key_exists($methodCode, $paymentMethodSettings)
537
  && $paymentMethodSettings[$methodCode] === '1'
41
  /**
42
  * XML path to checkout on/off switch
43
  */
44
+ const XPATH_CHECKOUT_ACTIVE = 'postnl/checkout/active';
45
 
46
  /**
47
  * XML path to all PostNL Checkout payment methods.
48
  * N.B. last part of the XML path is missing.
49
  */
50
+ const XPATH_CHECKOUT_PAYMENT_METHOD = 'postnl/checkout_payment_methods';
51
 
52
  /**
53
  * XML path to test / live mode setting
54
  */
55
+ const XPATH_TEST_MODE = 'postnl/cif/mode';
56
 
57
  /**
58
  * XML path for config options used to determine whether or not PostNL Checkout is available
59
  */
60
+ const XPATH_SHOW_CHECKOUT_FOR_LETTER = 'postnl/checkout/show_checkout_for_letter';
61
+ const XPATH_SHOW_CHECKOUT_FOR_BACKORDERS = 'postnl/checkout/show_checkout_for_backorders';
62
 
63
  /**
64
  * Log filename to log all non-specific PostNL debug messages
266
  /**
267
  * Check if PostNL Checkout may be used for 'letter' orders and if not, if the quote could fit in an envelope
268
  */
269
+ $showCheckoutForLetters = Mage::getStoreConfigFlag(self::XPATH_SHOW_CHECKOUT_FOR_LETTER, $storeId);
270
  if (!$showCheckoutForLetters) {
271
  $isLetterQuote = $this->quoteIsLetter($quote, $storeId);
272
  if ($isLetterQuote) {
287
  /**
288
  * Check if PostNL Checkout may be used for out-og-stock orders and if not, whether the quote has any such products
289
  */
290
+ $showCheckoutForBackorders = Mage::getStoreConfigFlag(self::XPATH_SHOW_CHECKOUT_FOR_BACKORDERS, $storeId);
291
  if (!$showCheckoutForBackorders) {
292
  $containsOutOfStockItems = $this->quoteHasOutOfStockItems($quote);
293
  if ($containsOutOfStockItems) {
352
  $totalWeight += $item->getRowWeight();
353
  }
354
 
355
+ $kilograms = $this->standardizeWeight($totalWeight, $storeId);
356
 
357
  if ($kilograms < 2) {
358
  return true;
399
  $storeId = Mage::app()->getStore()->getId();
400
  }
401
 
402
+ $isActive = Mage::getStoreConfigFlag(self::XPATH_CHECKOUT_ACTIVE, $storeId);
403
  return $isActive;
404
  }
405
 
531
  * Go through each supported payment method. At least one of them must be activated.
532
  */
533
  $paymentMethods = $this->getCheckoutPaymentMethods();
534
+ $paymentMethodSettings = Mage::getStoreConfig(self::XPATH_CHECKOUT_PAYMENT_METHOD, $storeId);
535
  foreach ($paymentMethods as $methodCode => $method) {
536
  if (array_key_exists($methodCode, $paymentMethodSettings)
537
  && $paymentMethodSettings[$methodCode] === '1'
app/code/community/TIG/PostNL/Helper/Cif.php CHANGED
@@ -60,36 +60,31 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
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
 
@@ -122,6 +117,7 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
122
  'ES',
123
  'CZ',
124
  'SE',
 
125
  );
126
 
127
  /**
@@ -177,6 +173,19 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
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
@@ -226,96 +235,161 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
226
  }
227
 
228
  /**
229
- * Get an array of standard product codes
230
  *
231
- * @param bool $storeId
232
  *
233
  * @return array
234
  */
235
- public function getStandardProductCodes($storeId = false)
236
  {
237
  $standardProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
238
- return $standardProductCodes->getAvailableOptions($storeId, true);
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  }
240
 
241
  /**
242
  * Get an array of evening delivery product codes.
243
  *
244
- * @param bool $storeId
245
  *
246
  * @return array
247
  */
248
- public function getAvondProductCodes($storeId = false)
249
  {
250
  $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
251
- return $pakjeGemakProductCodes->getAvailableAvondOptions($storeId, true);
252
  }
253
 
254
  /**
255
- * Get an array of pakjegemak product codes
256
  *
257
- * @param bool $storeId
258
  *
259
  * @return array
260
  */
261
- public function getPakjeGemakProductCodes($storeId = false)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  {
263
  $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
264
- return $pakjeGemakProductCodes->getAvailableOptions($storeId, true);
265
  }
266
 
267
  /**
268
  * Get an array of PakjeGemak Express product codes.
269
  *
270
- * @param bool $storeId
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  *
272
  * @return array
273
  */
274
- public function getPgeProductCodes($storeId = false)
275
  {
276
  $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
277
- return $pakjeGemakProductCodes->getAvailablePgeOptions($storeId, true);
278
  }
279
 
280
  /**
281
- * Get an array of pakketautomaat product codes
282
  *
283
- * @param bool $storeId
284
  *
285
  * @return array
286
  */
287
- public function getPakketautomaatProductCodes($storeId = false)
288
  {
289
  $pakketautomaatProductCodes = Mage::getSingleton(
290
  'postnl_core/system_config_source_pakketautomaatProductOptions'
291
  );
292
- return $pakketautomaatProductCodes->getAvailableOptions($storeId, true);
293
  }
294
 
295
  /**
296
- * Get an array of eu product codes
297
  *
298
- * @param bool $storeId
299
  *
300
  * @return array
301
  */
302
- public function getEuProductCodes($storeId = false)
303
  {
304
  $euProductCodes = Mage::getSingleton('postnl_core/system_config_source_euProductOptions');
305
- return $euProductCodes->getAvailableOptions($storeId, true);
306
  }
307
 
308
  /**
309
- * Get an array of global product codes
310
  *
311
- * @param bool $storeId
312
  *
313
  * @return array
314
  */
315
- public function getGlobalProductCodes($storeId = false)
316
  {
317
  $globalProductCodes = Mage::getSingleton('postnl_core/system_config_source_globalProductOptions');
318
- return $globalProductCodes->getAvailableOptions($storeId, true);
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  }
320
 
321
  /**
@@ -339,7 +413,7 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
339
  }
340
 
341
  /**
342
- * Get an array of possible shipping phases
343
  *
344
  * @return array
345
  */
@@ -353,6 +427,16 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
353
  return $shippingPhases;
354
  }
355
 
 
 
 
 
 
 
 
 
 
 
356
  /**
357
  * Get country IDs that allow fullstreet usage
358
  *
@@ -381,7 +465,7 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
381
  public function allowInfinitePrinting()
382
  {
383
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
384
- $enabled = Mage::getStoreConfigFlag(self::XML_PATH_INFINITE_LABEL_PRINTING, $storeId);
385
 
386
  return $enabled;
387
  }
@@ -425,63 +509,20 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
425
  /**
426
  * Get a list of available product options for a specified shipment
427
  *
428
- * @param Mage_Sales_Model_Order_Shipment $shipment
429
  *
430
  * @return array | null
431
  */
432
  public function getProductOptionsForShipment($shipment)
433
  {
434
- /**
435
- * PakjeGemak product options
436
- */
437
- if ($this->isPakjeGemakShipment($shipment)) {
438
- $options = Mage::getModel('postnl_core/system_config_source_pakjeGemakProductOptions')
439
- ->getAvailableOptions();
440
-
441
- return $options;
442
- }
443
-
444
- /**
445
- * Pakketautomaat product options
446
- */
447
- if ($this->isPakketautomaatShipment($shipment)) {
448
- $options = Mage::getModel('postnl_core/system_config_source_pakketautomaatProductOptions')
449
- ->getAvailableOptions();
450
-
451
- return $options;
452
- }
453
-
454
- /**
455
- * Dutch product options
456
- */
457
- if ($this->isDutchShipment($shipment)) {
458
- $options = Mage::getModel('postnl_core/system_config_source_standardProductOptions')
459
- ->getAvailableOptions();
460
-
461
- return $options;
462
- }
463
-
464
- /**
465
- * EU product options
466
- */
467
- if ($this->isEuShipment($shipment)) {
468
- $options = Mage::getModel('postnl_core/system_config_source_euProductOptions')
469
- ->getAvailableOptions();
470
-
471
- return $options;
472
- }
473
-
474
- /**
475
- * Global product options
476
- */
477
- if ($this->isGlobalShipment($shipment)) {
478
- $options = Mage::getModel('postnl_core/system_config_source_globalProductOptions')
479
- ->getAvailableOptions();
480
-
481
- return $options;
482
  }
483
 
484
- return null;
485
  }
486
 
487
  /**
@@ -609,6 +650,32 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
609
  return $tempPostnlShipment->isGlobalShipment();
610
  }
611
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
  /**
613
  * Gets the default product option for a shipment
614
  *
@@ -634,16 +701,18 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
634
  * TIG_PostNL_Model_Core_Shipment::getDefaultProductCode() which is more precise.
635
  *
636
  * @return array
 
 
637
  */
638
  public function getDefaultProductOptions()
639
  {
640
  $storeId = Mage::app()->getStore()->getId();
641
 
642
- $defaultDutchOption = Mage::getStoreConfig(self::XML_PATH_DEFAULT_STANDARD_PRODUCT_OPTION, $storeId);
643
- $defaultEuOption = Mage::getStoreConfig(self::XML_PATH_DEFAULT_EU_PRODUCT_OPTION, $storeId);
644
- $defaultGlobalOption = Mage::getStoreConfig(self::XML_PATH_DEFAULT_GLOBAL_PRODUCT_OPTION, $storeId);
645
  $defaultPakketautomaatOption = Mage::getStoreConfig(
646
- self::XML_PATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION,
647
  $storeId
648
  );
649
 
@@ -670,28 +739,32 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
670
  $postnlShipment->setShipment($shipment);
671
 
672
  /**
673
- * Only NL shipments support multi-colli shipments
674
  */
675
  if (!$postnlShipment->isDutchShipment()) {
676
  return 1;
677
  }
678
 
679
  /**
680
- * get this shipment's total weight
681
  */
682
  $weight = $postnlShipment->getTotalWeight(true);
683
 
684
  /**
685
- * get the weight per parcel
686
  */
687
- $weightPerParcel = Mage::getStoreConfig(self::XML_PATH_WEIGHT_PER_PARCEL, $shipment->getStoreId());
688
  $weightPerParcel = $this->standardizeWeight($weightPerParcel, $shipment->getStoreId());
689
 
690
  /**
691
- * calculate the number of parcels needed to ship the total weight of this shipment
692
  */
693
  $parcelCount = ceil($weight / $weightPerParcel);
694
 
 
 
 
 
695
  return $parcelCount;
696
  }
697
 
@@ -782,107 +855,15 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
782
  }
783
 
784
  /**
785
- * Convert a given weight to kilogram or gram
786
- *
787
- * @param float $weight The weight to be converted
788
- * @param int | null $storeId Store Id used to determine the weight unit that was originally used
789
- * @param boolean $toGram Optional parameter to convert to gram instead of kilogram
790
- *
791
- * @return float
792
- */
793
- public function standardizeWeight($weight, $storeId = null, $toGram = false)
794
- {
795
- if (is_null($storeId)) {
796
- $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
797
- }
798
-
799
- $unitUsed = Mage::getStoreConfig(self::XML_PATH_WEIGHT_UNIT, $storeId);
800
-
801
- switch ($unitUsed) {
802
- case 'tonne':
803
- $returnWeight = $weight * 1000;
804
- break;
805
- case 'kilogram':
806
- $returnWeight = $weight * 1;
807
- break;
808
- case 'hectogram':
809
- $returnWeight = $weight * 10;
810
- break;
811
- case 'gram':
812
- $returnWeight = $weight * 0.001;
813
- break;
814
- case 'carat':
815
- $returnWeight = $weight * 0.0002;
816
- break;
817
- case 'centigram':
818
- $returnWeight = $weight * 0.00001;
819
- break;
820
- case 'milligram':
821
- $returnWeight = $weight * 0.000001;
822
- break;
823
- case 'longton':
824
- $returnWeight = $weight * 1016.0469088;
825
- break;
826
- case 'shortton':
827
- $returnWeight = $weight * 907.18474;
828
- break;
829
- case 'longhundredweight':
830
- $returnWeight = $weight * 50.80234544;
831
- break;
832
- case 'shorthundredweight':
833
- $returnWeight = $weight * 45.359237;
834
- break;
835
- case 'stone':
836
- $returnWeight = $weight * 6.35029318;
837
- break;
838
- case 'pound':
839
- $returnWeight = $weight * 0.45359237;
840
- break;
841
- case 'ounce':
842
- $returnWeight = $weight * 0.028349523125;
843
- break;
844
- case 'grain': //no break
845
- case 'troy_grain':
846
- $returnWeight = $weight * 0.00006479891;
847
- break;
848
- case 'troy_pound':
849
- $returnWeight = $weight * 0.3732417216;
850
- break;
851
- case 'troy_ounce':
852
- $returnWeight = $weight * 0.0311034768;
853
- break;
854
- case 'troy_pennyweight':
855
- $returnWeight = $weight * 0.00155517384;
856
- break;
857
- case 'troy_carat':
858
- $returnWeight = $weight * 0.00020519654;
859
- break;
860
- case 'troy_mite':
861
- $returnWeight = $weight * 0.00000323994;
862
- break;
863
- default:
864
- $returnWeight = $weight;
865
- break;
866
- }
867
-
868
- if ($toGram === true) {
869
- $returnWeight *= 1000;
870
- }
871
-
872
- return $returnWeight;
873
- }
874
-
875
- /**
876
- * Retrieves streetname, housenumber and housenumber extension from the shipping address.
877
- * The shipping address may be in multiple streetlines configuration or single line
878
- * configuration. In the case of multi-line, each part of the street data will be in a seperate
879
- * field. In the single line configuration, each part will be in the same field and will have
880
- * to be split using PREG.
881
  *
882
- * PREG cannot be relied on as it is impossible to create a regex that can filter all
883
- * possible street syntaxes. Therefore we strongly recommend to use multiple street lines. This
884
- * can be enabled in Magento community in system > config > customer configuration. Or if you
885
- * use Enterprise, in customers > attributes > manage customer address attributes.
886
  *
887
  * @param int $storeId
888
  * @param Mage_Customer_Model_Address_Abstract $address
@@ -943,8 +924,8 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
943
  }
944
 
945
  /**
946
- * Retrieves streetname, housenumber and housenumber extension from the shipping address in the multiple streetlines
947
- * configuration.
948
  *
949
  * @param int $storeId
950
  * @param Mage_Sales_Model_Order_Address $address
@@ -955,22 +936,22 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
955
  {
956
  $addressHelper = Mage::helper('postnl/addressValidation');
957
 
958
- $streetnameField = $addressHelper->getStreetnameField($storeId);;
959
- $housenumberField = $addressHelper->getHousenumberField($storeId);;
960
 
961
  $streetname = $address->getStreet($streetnameField);
962
  $housenumber = $address->getStreet($housenumberField);
963
  $housenumber = trim($housenumber);
964
 
965
  /**
966
- * If street or housenr fields are empty, use alternative options to obtain the address data
967
  */
968
  if (empty($streetname) || empty($housenumber)) {
969
  return false;
970
  }
971
 
972
  /**
973
- * Split the housenumber into a number and an extension
974
  */
975
  $splitHouseNumber = $addressHelper->useSplitHousenumber();
976
  if ($splitHouseNumber) {
@@ -978,7 +959,7 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
978
  $housenumberExtension = $address->getStreet($housenumberExtensionField);
979
 
980
  /**
981
- * Make sure the housenumber is actually split.
982
  */
983
  if (!$housenumberExtension && !is_numeric($housenumber)) {
984
  $housenumberParts = $this->_splitHousenumber($housenumber);
@@ -1006,9 +987,9 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
1006
  }
1007
 
1008
  /**
1009
- * Splits street data into seperate parts for streetname, housenumber and extension.
1010
  *
1011
- * @param string $fullStreet The full streetname including all parts
1012
  *
1013
  * @return array
1014
  *
@@ -1049,7 +1030,7 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
1049
  }
1050
 
1051
  /**
1052
- * Splits a supplier housenumber into a number and an extension.
1053
  *
1054
  * @param string $housenumber
1055
  *
@@ -1086,6 +1067,67 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
1086
  return $housenumberParts;
1087
  }
1088
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1089
  /**
1090
  * Logs a CIF request and response for debug purposes.
1091
  *
@@ -1093,7 +1135,7 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
1093
  *
1094
  * @param Zend_Soap_Client $client
1095
  *
1096
- * @return TIG_PostNL_Helper_Cif
1097
  *
1098
  * @see Mage::log()
1099
  *
@@ -1107,9 +1149,12 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
1107
  $requestXml = $this->formatXml($client->getLastRequest());
1108
  $responseXML = $this->formatXml($client->getLastResponse());
1109
 
1110
- $logMessage = "Request sent:\n"
 
1111
  . $requestXml
1112
- . "\nResponse received:\n"
 
 
1113
  . $responseXML;
1114
 
1115
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::CIF_DEBUG_LOG_FILE;
@@ -1123,7 +1168,7 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
1123
  *
1124
  * @param Mage_Core_Exception | TIG_PostNL_Model_Core_Cif_Exception $exception
1125
  *
1126
- * @return TIG_PostNL_Helper_Cif
1127
  *
1128
  * @see Mage::logException()
1129
  */
@@ -1133,24 +1178,26 @@ class TIG_PostNL_Helper_Cif extends TIG_PostNL_Helper_Data
1133
  return $this;
1134
  }
1135
 
 
 
1136
  if ($exception instanceof TIG_PostNL_Model_Core_Cif_Exception) {
1137
  $requestXml = $this->formatXml($exception->getRequestXml());
1138
  $responseXML = $this->formatXml($exception->getResponseXml());
1139
 
1140
- $logMessage = '';
1141
-
1142
  $errorNumbers = $exception->getErrorNumbers();
1143
  if (!empty($errorNumbers)) {
1144
  $errorNumbers = implode(', ', $errorNumbers);
1145
- $logMessage .= "Error numbers received: {$errorNumbers}\n";
1146
  }
1147
 
1148
- $logMessage .= "<<< REQUEST SENT >>>\n"
1149
- . $requestXml
1150
- . "\n<<< RESPONSE RECEIVED >>>\n"
1151
- . $responseXML;
1152
- } else {
1153
- $logMessage = "\n" . $exception->__toString();
 
 
1154
  }
1155
 
1156
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::CIF_EXCEPTION_LOG_FILE;
60
  const GLOBAL_BARCODE_TYPE = 'GLOBAL';
61
 
62
  /**
63
+ * XML path to infinite label printing setting
64
  */
65
+ const XPATH_INFINITE_LABEL_PRINTING = 'postnl/advanced/infinite_label_printing';
 
 
 
 
 
66
 
67
  /**
68
  * XML path to weight per parcel config setting
69
  */
70
+ const XPATH_WEIGHT_PER_PARCEL = 'postnl/cif_labels_and_confirming/weight_per_parcel';
71
 
72
  /**
73
  * XML paths to default product options settings
74
  */
75
+ const XPATH_DEFAULT_STANDARD_PRODUCT_OPTION = 'postnl/cif_product_options/default_product_option';
76
+ const XPATH_DEFAULT_EU_PRODUCT_OPTION = 'postnl/cif_product_options/default_eu_product_option';
77
+ const XPATH_DEFAULT_GLOBAL_PRODUCT_OPTION = 'postnl/cif_product_options/default_global_product_option';
78
+ const XPATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION = 'postnl/cif_product_options/default_pakketautomaat_product_option';
79
 
80
  /**
81
+ * Regular expression used to split street name from house number. This regex works well for dutch addresses, but
82
+ * may fail for international addresses. We strongly recommend using split address lines instead.
83
  */
84
  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})#';
85
 
86
  /**
87
+ * Regular expression used to split house number and house number extension
88
  */
89
  const SPLIT_HOUSENUMBER_REGEX = '#^([\d]+)(.*)#s';
90
 
117
  'ES',
118
  'CZ',
119
  'SE',
120
+ 'GR',
121
  );
122
 
123
  /**
173
  '99' => 'Shipment not found',
174
  );
175
 
176
+ /**
177
+ * Array of possible shipping phase codes.
178
+ *
179
+ * @var array
180
+ */
181
+ protected $_shippingPhaseCodes = array(
182
+ '1' => 'reported',
183
+ '2' => 'sorted',
184
+ '3' => 'distribution',
185
+ '4' => 'delivered',
186
+ '99' => 'not_found',
187
+ );
188
+
189
  /**
190
  * Array of countires which may send their full street data in a single line,
191
  * rather than having to split them into streetname, housenr and extension parts
235
  }
236
 
237
  /**
238
+ * Get an array of standard product codes.
239
  *
240
+ * @param boolean $flat
241
  *
242
  * @return array
243
  */
244
+ public function getStandardProductCodes($flat = true)
245
  {
246
  $standardProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
247
+ return $standardProductCodes->getAvailableOptions($flat);
248
+ }
249
+
250
+ /**
251
+ * Get an array of standard COD product codes.
252
+ *
253
+ * @param boolean $flat
254
+ *
255
+ * @return array
256
+ */
257
+ public function getStandardCodProductCodes($flat = true)
258
+ {
259
+ $standardProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
260
+ return $standardProductCodes->getAvailableCodOptions($flat);
261
  }
262
 
263
  /**
264
  * Get an array of evening delivery product codes.
265
  *
266
+ * @param boolean $flat
267
  *
268
  * @return array
269
  */
270
+ public function getAvondProductCodes($flat = true)
271
  {
272
  $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
273
+ return $pakjeGemakProductCodes->getAvailableAvondOptions($flat);
274
  }
275
 
276
  /**
277
+ * Get an array of evening delivery COD product codes.
278
  *
279
+ * @param boolean $flat
280
  *
281
  * @return array
282
  */
283
+ public function getAvondCodProductCodes($flat = true)
284
+ {
285
+ $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
286
+ return $pakjeGemakProductCodes->getAvailableAvondCodOptions($flat);
287
+ }
288
+
289
+ /**
290
+ * Get an array of PakjeGemak product codes.
291
+ *
292
+ * @param boolean $flat
293
+ *
294
+ * @return array
295
+ */
296
+ public function getPakjeGemakProductCodes($flat = true)
297
+ {
298
+ $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
299
+ return $pakjeGemakProductCodes->getAvailableOptions($flat);
300
+ }
301
+
302
+ /**
303
+ * Get an array of PakjeGemak COD product codes.
304
+ *
305
+ * @param boolean $flat
306
+ *
307
+ * @return array
308
+ */
309
+ public function getPakjeGemakCodProductCodes($flat = true)
310
  {
311
  $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
312
+ return $pakjeGemakProductCodes->getAvailableCodOptions($flat);
313
  }
314
 
315
  /**
316
  * Get an array of PakjeGemak Express product codes.
317
  *
318
+ * @param boolean $flat
319
+ *
320
+ * @return array
321
+ */
322
+ public function getPgeProductCodes($flat = true)
323
+ {
324
+ $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
325
+ return $pakjeGemakProductCodes->getAvailablePgeOptions($flat);
326
+ }
327
+
328
+ /**
329
+ * Get an array of PakjeGemak Express COD product codes.
330
+ *
331
+ * @param boolean $flat
332
  *
333
  * @return array
334
  */
335
+ public function getPgeCodProductCodes($flat = true)
336
  {
337
  $pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
338
+ return $pakjeGemakProductCodes->getAvailablePgeCodOptions($flat);
339
  }
340
 
341
  /**
342
+ * Get an array of pakketautomaat product codes.
343
  *
344
+ * @param boolean $flat
345
  *
346
  * @return array
347
  */
348
+ public function getPakketautomaatProductCodes($flat = true)
349
  {
350
  $pakketautomaatProductCodes = Mage::getSingleton(
351
  'postnl_core/system_config_source_pakketautomaatProductOptions'
352
  );
353
+ return $pakketautomaatProductCodes->getAvailableOptions($flat);
354
  }
355
 
356
  /**
357
+ * Get an array of eu product codes.
358
  *
359
+ * @param boolean $flat
360
  *
361
  * @return array
362
  */
363
+ public function getEuProductCodes($flat = true)
364
  {
365
  $euProductCodes = Mage::getSingleton('postnl_core/system_config_source_euProductOptions');
366
+ return $euProductCodes->getAvailableOptions($flat);
367
  }
368
 
369
  /**
370
+ * Get an array of global product codes.
371
  *
372
+ * @param boolean $flat
373
  *
374
  * @return array
375
  */
376
+ public function getGlobalProductCodes($flat = true)
377
  {
378
  $globalProductCodes = Mage::getSingleton('postnl_core/system_config_source_globalProductOptions');
379
+ return $globalProductCodes->getAvailableOptions($flat);
380
+ }
381
+
382
+ /**
383
+ * Get an array of buspakje product codes.
384
+ *
385
+ * @param boolean $flat
386
+ *
387
+ * @return array
388
+ */
389
+ public function getBuspakjeProductCodes($flat = true)
390
+ {
391
+ $buspakjeProductCodes = Mage::getSingleton('postnl_core/system_config_source_buspakjeProductOptions');
392
+ return $buspakjeProductCodes->getAvailableOptions($flat);
393
  }
394
 
395
  /**
413
  }
414
 
415
  /**
416
+ * Get an array of possible shipping phases.
417
  *
418
  * @return array
419
  */
427
  return $shippingPhases;
428
  }
429
 
430
+ /**
431
+ * Get an array of possible shipping phase codes.
432
+ *
433
+ * @return array
434
+ */
435
+ public function getShippingPhaseCodes()
436
+ {
437
+ return $this->_shippingPhaseCodes;
438
+ }
439
+
440
  /**
441
  * Get country IDs that allow fullstreet usage
442
  *
465
  public function allowInfinitePrinting()
466
  {
467
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
468
+ $enabled = Mage::getStoreConfigFlag(self::XPATH_INFINITE_LABEL_PRINTING, $storeId);
469
 
470
  return $enabled;
471
  }
509
  /**
510
  * Get a list of available product options for a specified shipment
511
  *
512
+ * @param Mage_Sales_Model_Order_Shipment|TIG_PostNL_Model_Core_Shipment $shipment
513
  *
514
  * @return array | null
515
  */
516
  public function getProductOptionsForShipment($shipment)
517
  {
518
+ if ($shipment instanceof Mage_Sales_Model_Order_Shipment) {
519
+ $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
520
+ $tempPostnlShipment->setShipment($shipment);
521
+ } else {
522
+ $tempPostnlShipment = $shipment;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
  }
524
 
525
+ return $tempPostnlShipment->getAllowedProductOptions(false);
526
  }
527
 
528
  /**
650
  return $tempPostnlShipment->isGlobalShipment();
651
  }
652
 
653
+ /**
654
+ * Check if a given shipment is COD
655
+ *
656
+ * @param TIG_PostNL_Model_Core_Shipment|Mage_Sales_Model_Order_Shipment $shipment
657
+ *
658
+ * @return boolean
659
+ *
660
+ * @see TIG_PostNL_Model_Core_Shipment->isCod();
661
+ */
662
+ public function isCodShipment($shipment)
663
+ {
664
+ $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
665
+ if ($shipment instanceof $postnlShipmentClass) {
666
+ /**
667
+ * @var TIG_PostNL_Model_Core_Shipment $shipment
668
+ */
669
+ return $shipment->isCod();
670
+ }
671
+
672
+ $tempPostnlShipment = Mage::getModel('postnl_core/shipment');
673
+ $tempPostnlShipment->setShipment($shipment);
674
+
675
+ return $tempPostnlShipment->isCod();
676
+ }
677
+
678
+
679
  /**
680
  * Gets the default product option for a shipment
681
  *
701
  * TIG_PostNL_Model_Core_Shipment::getDefaultProductCode() which is more precise.
702
  *
703
  * @return array
704
+ *
705
+ * @deprecated v1.3.0
706
  */
707
  public function getDefaultProductOptions()
708
  {
709
  $storeId = Mage::app()->getStore()->getId();
710
 
711
+ $defaultDutchOption = Mage::getStoreConfig(self::XPATH_DEFAULT_STANDARD_PRODUCT_OPTION, $storeId);
712
+ $defaultEuOption = Mage::getStoreConfig(self::XPATH_DEFAULT_EU_PRODUCT_OPTION, $storeId);
713
+ $defaultGlobalOption = Mage::getStoreConfig(self::XPATH_DEFAULT_GLOBAL_PRODUCT_OPTION, $storeId);
714
  $defaultPakketautomaatOption = Mage::getStoreConfig(
715
+ self::XPATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION,
716
  $storeId
717
  );
718
 
739
  $postnlShipment->setShipment($shipment);
740
 
741
  /**
742
+ * Only NL shipments support multi-colli shipments.
743
  */
744
  if (!$postnlShipment->isDutchShipment()) {
745
  return 1;
746
  }
747
 
748
  /**
749
+ * Get this shipment's total weight.
750
  */
751
  $weight = $postnlShipment->getTotalWeight(true);
752
 
753
  /**
754
+ * Get the weight per parcel.
755
  */
756
+ $weightPerParcel = Mage::getStoreConfig(self::XPATH_WEIGHT_PER_PARCEL, $shipment->getStoreId());
757
  $weightPerParcel = $this->standardizeWeight($weightPerParcel, $shipment->getStoreId());
758
 
759
  /**
760
+ * Calculate the number of parcels needed to ship the total weight of this shipment.
761
  */
762
  $parcelCount = ceil($weight / $weightPerParcel);
763
 
764
+ if ($parcelCount < 1) {
765
+ $parcelCount = 1;
766
+ }
767
+
768
  return $parcelCount;
769
  }
770
 
855
  }
856
 
857
  /**
858
+ * Retrieves street name, house number and house number extension from the shipping address.
859
+ * The shipping address may be in multiple street lines configuration or single line configuration. In the case of
860
+ * multi-line, each part of the street data will be in a separate field. In the single line configuration, each part
861
+ * will be in the same field and will have to be split using PREG.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
862
  *
863
+ * PREG cannot be relied on as it is impossible to create a regex that can filter all possible street syntaxes.
864
+ * Therefore we strongly recommend to use multiple street lines. This can be enabled in Magento community in
865
+ * system > config > customer configuration. Or if you use Enterprise, in customers > attributes > manage customer
866
+ * address attributes.
867
  *
868
  * @param int $storeId
869
  * @param Mage_Customer_Model_Address_Abstract $address
924
  }
925
 
926
  /**
927
+ * Retrieves street name, house number and housen umber extension from the shipping address in the multiple street
928
+ * ines configuration.
929
  *
930
  * @param int $storeId
931
  * @param Mage_Sales_Model_Order_Address $address
936
  {
937
  $addressHelper = Mage::helper('postnl/addressValidation');
938
 
939
+ $streetnameField = $addressHelper->getStreetnameField($storeId);
940
+ $housenumberField = $addressHelper->getHousenumberField($storeId);
941
 
942
  $streetname = $address->getStreet($streetnameField);
943
  $housenumber = $address->getStreet($housenumberField);
944
  $housenumber = trim($housenumber);
945
 
946
  /**
947
+ * If street or house number fields are empty, use alternative options to obtain the address data
948
  */
949
  if (empty($streetname) || empty($housenumber)) {
950
  return false;
951
  }
952
 
953
  /**
954
+ * Split the house number into a number and an extension
955
  */
956
  $splitHouseNumber = $addressHelper->useSplitHousenumber();
957
  if ($splitHouseNumber) {
959
  $housenumberExtension = $address->getStreet($housenumberExtensionField);
960
 
961
  /**
962
+ * Make sure the house number is actually split.
963
  */
964
  if (!$housenumberExtension && !is_numeric($housenumber)) {
965
  $housenumberParts = $this->_splitHousenumber($housenumber);
987
  }
988
 
989
  /**
990
+ * Splits street data into separate parts for street name, house number and extension.
991
  *
992
+ * @param string $fullStreet The full street name including all parts
993
  *
994
  * @return array
995
  *
1030
  }
1031
 
1032
  /**
1033
+ * Splits a supplier house number into a number and an extension.
1034
  *
1035
  * @param string $housenumber
1036
  *
1067
  return $housenumberParts;
1068
  }
1069
 
1070
+ /**
1071
+ * Parses a CIF exception. If the last error number is a known error, we replace the message and code with our own.
1072
+ *
1073
+ * @param TIG_PostNL_Model_Core_Cif_Exception &$exception
1074
+ *
1075
+ * @return $this
1076
+ */
1077
+ public function parseCifException(TIG_PostNL_Model_Core_Cif_Exception &$exception)
1078
+ {
1079
+ $errorNumbers = $exception->getErrorNumbers();
1080
+ $errorNumber = end($errorNumbers);
1081
+
1082
+ $code = $exception->getCode();
1083
+ $message = $exception->getMessage();
1084
+ switch ($errorNumber) {
1085
+ case '1':
1086
+ $code = 'POSTNL-0181';
1087
+ $message = $this->__(
1088
+ 'It appears the PostNL username and/or password you have entered is incorrect.'
1089
+ );
1090
+ break;
1091
+ case '2':
1092
+ $code = 'POSTNL-0182';
1093
+ $message = $this->__(
1094
+ 'Your PostNL account is unfortunately not allowed to perform this action. Please contact PostNL.'
1095
+ );
1096
+ break;
1097
+ case '9':
1098
+ $code = 'POSTNL-0183';
1099
+ $message = $this->__(
1100
+ 'Unfortunately you have exceeded the maximum amount of PostNL requests you may send each minute.' .
1101
+ ' Please wait a few minutes and try again. If this problem persists, please contact PostNL.'
1102
+ );
1103
+ break;
1104
+ case '10':
1105
+ $code = 'POSTNL-0184';
1106
+ $message = $this->__('This PostNL service is currently disabled. Please contact PostNL.');
1107
+ break;
1108
+ case '11':
1109
+ $code = 'POSTNL-0185';
1110
+ $message = $this->__(
1111
+ "There was a problem connecting to PostNL's services. This may be due to a timeout. Please wait a " .
1112
+ 'few minutes and try again. If this problem persists, please contact PostNL.'
1113
+ );
1114
+ break;
1115
+ case '19':
1116
+ $code = 'POSTNL-0186';
1117
+ $message = $this->__(
1118
+ 'Your PostNL customer code appears to be incorrect. Please make sure you have entered the correct' .
1119
+ ' code.'
1120
+ );
1121
+ break;
1122
+ //no default
1123
+ }
1124
+
1125
+ $exception->setCode($code)
1126
+ ->setMessage($message);
1127
+
1128
+ return $this;
1129
+ }
1130
+
1131
  /**
1132
  * Logs a CIF request and response for debug purposes.
1133
  *
1135
  *
1136
  * @param Zend_Soap_Client $client
1137
  *
1138
+ * @return $this
1139
  *
1140
  * @see Mage::log()
1141
  *
1149
  $requestXml = $this->formatXml($client->getLastRequest());
1150
  $responseXML = $this->formatXml($client->getLastResponse());
1151
 
1152
+ $logMessage = "<<< REQUEST SENT >>>"
1153
+ . PHP_EOL
1154
  . $requestXml
1155
+ . PHP_EOL
1156
+ . "<<< RESPONSE RECEIVED >>>"
1157
+ . PHP_EOL
1158
  . $responseXML;
1159
 
1160
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::CIF_DEBUG_LOG_FILE;
1168
  *
1169
  * @param Mage_Core_Exception | TIG_PostNL_Model_Core_Cif_Exception $exception
1170
  *
1171
+ * @return $this
1172
  *
1173
  * @see Mage::logException()
1174
  */
1178
  return $this;
1179
  }
1180
 
1181
+ $logMessage = PHP_EOL . $exception->__toString();
1182
+
1183
  if ($exception instanceof TIG_PostNL_Model_Core_Cif_Exception) {
1184
  $requestXml = $this->formatXml($exception->getRequestXml());
1185
  $responseXML = $this->formatXml($exception->getResponseXml());
1186
 
 
 
1187
  $errorNumbers = $exception->getErrorNumbers();
1188
  if (!empty($errorNumbers)) {
1189
  $errorNumbers = implode(', ', $errorNumbers);
1190
+ $logMessage .= PHP_EOL . PHP_EOL . "Error numbers received: {$errorNumbers}\n";
1191
  }
1192
 
1193
+ $logMessage .= PHP_EOL
1194
+ . "<<< REQUEST SENT >>>"
1195
+ . PHP_EOL
1196
+ . $requestXml
1197
+ . PHP_EOL
1198
+ . "<<< RESPONSE RECEIVED >>>"
1199
+ . PHP_EOL
1200
+ . $responseXML;
1201
  }
1202
 
1203
  $file = self::POSTNL_LOG_DIRECTORY . DS . self::CIF_EXCEPTION_LOG_FILE;
app/code/community/TIG/PostNL/Helper/Data.php CHANGED
@@ -61,48 +61,63 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
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 carrier 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
 
101
  /**
102
  * XPATH to allow EPS BE only product option setting.
103
  */
104
  const XPATH_ALLOW_EPS_BE_ONLY_OPTION = 'postnl/cif_product_options/allow_eps_be_only_options';
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  /**
107
  * Required configuration fields.
108
  *
@@ -113,8 +128,10 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
113
  'postnl/cif/customer_number',
114
  'postnl/cif/collection_location',
115
  'postnl/cif_labels_and_confirming/label_size',
116
- 'postnl/cif_sender_address/firstname',
117
- 'postnl/cif_sender_address/lastname',
 
 
118
  'postnl/cif_sender_address/streetname',
119
  'postnl/cif_sender_address/housenumber',
120
  'postnl/cif_sender_address/postcode',
@@ -156,10 +173,46 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
156
  );
157
 
158
  /**
159
- * @var null|TIG_PostNL_Model_Core_Cache
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  */
161
  protected $_cache = null;
162
 
 
 
 
 
 
 
 
163
  /**
164
  * Get required fields array.
165
  *
@@ -201,7 +254,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
201
  }
202
 
203
  /**
204
- * @param null|TIG_PostNL_Model_Core_Cache $cache
205
  *
206
  * @return TIG_PostNL_Helper_Data
207
  */
@@ -213,7 +266,11 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
213
  }
214
 
215
  /**
216
- * @return null|TIG_PostNL_Model_Core_Cache
 
 
 
 
217
  */
218
  public function getCache()
219
  {
@@ -230,6 +287,68 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
230
  return $cache;
231
  }
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  /**
234
  * Get debug mode config setting.
235
  *
@@ -241,7 +360,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
241
  return Mage::registry('postnl_debug_mode');
242
  }
243
 
244
- $debugMode = (int) Mage::getStoreConfig(self::XML_PATH_DEBUG_MODE, Mage_Core_Model_App::ADMIN_STORE_ID);
245
 
246
  Mage::register('postnl_debug_mode', $debugMode);
247
  return $debugMode;
@@ -273,14 +392,13 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
273
  /**
274
  * Check if this order was placed using PostNL.
275
  */
276
- $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
277
  $shippingMethod = $order->getShippingMethod();
278
 
279
  /**
280
  * If this shipment's order was not placed with PostNL, we need to ignore any PakjeGemak addresses that may have
281
  * been saved.
282
  */
283
- if (!in_array($shippingMethod, $postnlShippingMethods)) {
284
  return false;
285
  }
286
 
@@ -300,11 +418,9 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
300
  /**
301
  * Checks to see if the module may ship to the Netherlands using PostNL standard shipments.
302
  *
303
- * @param boolean|int $storeId
304
- *
305
  * @return boolean
306
  */
307
- public function canUseStandard($storeId = false)
308
  {
309
  $cache = $this->getCache();
310
 
@@ -312,12 +428,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
312
  return $cache->getPostnlCoreCanUseStandard();
313
  }
314
 
315
- if ($storeId === false) {
316
- $storeId = Mage::app()->getStore()->getId();
317
- }
318
-
319
  $standardProductOptions = Mage::getModel('postnl_core/system_config_source_standardProductOptions')
320
- ->getAvailableOptions($storeId);
321
  if (empty($standardProductOptions)) {
322
  if ($cache) {
323
  $cache->setPostnlCoreCanUseStandard(false)
@@ -338,11 +450,9 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
338
  /**
339
  * Checks to see if the module may ship using PakjeGemak.
340
  *
341
- * @param boolean|int $storeId
342
- *
343
  * @return boolean
344
  */
345
- public function canUsePakjeGemak($storeId = false)
346
  {
347
  $cache = $this->getCache();
348
 
@@ -350,12 +460,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
350
  return $cache->getPostnlCoreCanUsePakjeGemak();
351
  }
352
 
353
- if ($storeId === false) {
354
- $storeId = Mage::app()->getStore()->getId();
355
- }
356
-
357
  $pakjeGemakProductoptions = Mage::getModel('postnl_core/system_config_source_pakjeGemakProductOptions')
358
- ->getAvailableOptions($storeId);
359
 
360
  if (empty($pakjeGemakProductoptions)) {
361
  if ($cache) {
@@ -376,11 +482,9 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
376
  /**
377
  * Checks to see if the module may ship to EU countries using EPS
378
  *
379
- * @param boolean|int $storeId
380
- *
381
  * @return boolean
382
  */
383
- public function canUseEps($storeId = false)
384
  {
385
  $cache = $this->getCache();
386
 
@@ -388,12 +492,8 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
388
  return $cache->getPostnlCoreCanUseEps();
389
  }
390
 
391
- if ($storeId === false) {
392
- $storeId = Mage::app()->getStore()->getId();
393
- }
394
-
395
  $euProductOptions = Mage::getModel('postnl_core/system_config_source_euProductOptions')
396
- ->getAvailableOptions($storeId);
397
 
398
  if (empty($euProductOptions)) {
399
  if ($cache) {
@@ -413,11 +513,9 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
413
  /**
414
  * Checks to see if the module may ship to countries outside the EU using GlobalPack
415
  *
416
- * @param boolean|int $storeId
417
- *
418
  * @return boolean
419
  */
420
- public function canUseGlobalPack($storeId = false)
421
  {
422
  $cache = $this->getCache();
423
 
@@ -425,10 +523,6 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
425
  return $cache->getPostnlCoreCanUseGlobalPack();
426
  }
427
 
428
- if ($storeId === false) {
429
- $storeId = Mage::app()->getStore()->getId();
430
- }
431
-
432
  if (!$this->isGlobalAllowed()) {
433
  if ($cache) {
434
  $cache->setPostnlCoreCanUseGlobalPack(false)
@@ -438,7 +532,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
438
  }
439
 
440
  $globalProductOptions = Mage::getModel('postnl_core/system_config_source_globalProductOptions')
441
- ->getAvailableOptions($storeId);
442
 
443
  if (empty($globalProductOptions)) {
444
  if ($cache) {
@@ -455,6 +549,50 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
455
  return true;
456
  }
457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
458
  /**
459
  * Checks whether the EPS BE only product option is allowed.
460
  *
@@ -526,6 +664,222 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
526
  return true;
527
  }
528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  /**
530
  * Checks if the current admin user is allowed for the specified actions.
531
  *
@@ -573,26 +927,31 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
573
  case 'create_shipment':
574
  $aclPath = 'sales/order/actions/ship';
575
  break;
576
- case 'confirm':
577
- $aclPath = 'postnl/shipment/actions/confirm';
578
- break;
579
- case 'print_label':
580
- $aclPath = 'postnl/shipment/actions/print_label';
581
- break;
582
  case 'view_complete_status':
583
  $aclPath = 'postnl/shipment/complete_status';
584
  break;
585
- case 'reset_confirmation':
586
- $aclPath = 'postnl/shipment/actions/reset_confirmation';
 
 
 
587
  break;
588
- case 'delete_labels':
589
- $aclPath = 'postnl/shipment/actions/delete_labels';
590
  break;
591
- case 'create_parcelware_export':
592
- $aclPath = 'postnl/shipment/actions/create_parcelware_export';
593
  break;
 
 
 
 
 
 
 
 
594
  case 'send_track_and_trace':
595
- $aclPath = 'postnl/shipment/actions/send_track_and_trace';
596
  break;
597
  default:
598
  $aclPath = false;
@@ -616,7 +975,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
616
  {
617
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
618
 
619
- $useGlobal = Mage::getStoreConfigFlag(self::XML_PATH_USE_GLOBALPACK, $storeId);
620
  return $useGlobal;
621
  }
622
 
@@ -637,7 +996,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
637
  $storeId = Mage::app()->getStore()->getId();
638
  }
639
 
640
- $testMode = Mage::getStoreConfigFlag(self::XML_PATH_TEST_MODE, $storeId);
641
 
642
  Mage::register('postnl_test_mode', $testMode);
643
  return $testMode;
@@ -713,6 +1072,10 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
713
  */
714
  protected function _isEnabled($storeId, $forceTestMode, $ignoreCache)
715
  {
 
 
 
 
716
  if ($storeId === false) {
717
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
718
  }
@@ -722,7 +1085,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
722
  /**
723
  * Check if the module has been enabled
724
  */
725
- $enabled = Mage::getStoreConfigFlag(self::XML_PATH_EXTENSION_ACTIVE, $storeId);
726
  if ($enabled === false) {
727
  $errors = array(
728
  array(
@@ -752,10 +1115,27 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
752
  }
753
 
754
  /**
755
- * Check if the PostNL shipping method is active
 
 
 
756
  */
757
- $postnlShippingMethodEnabled = Mage::getStoreConfigFlag(self::XML_PATH_CARRIER_ACTIVE, $storeId);
758
- if ($postnlShippingMethodEnabled === false) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
759
  if ($this->isSystemConfig() || $this->isLoggingEnabled()) {
760
  $shippingMethodSectionurl = Mage::helper("adminhtml")->getUrl(
761
  'adminhtml/system_config/edit',
@@ -765,23 +1145,21 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
765
  )
766
  );
767
 
768
- $errorMessage = $this->__(
769
- 'The PostNL shipping method has not been enabled. You can enable the PostNL shipping method under '
770
- . '%sSystem > Config > Shipping Methods%s.',
771
- '<a href="'
772
- . $shippingMethodSectionurl
773
- . '" target="_blank" title="'
774
- . $this->__('Shipping Methods')
775
- . '">',
776
- '</a>'
777
- );
778
- } else {
779
- $errorMessage = $this->__(
780
- 'The PostNL shipping method has not been enabled. You can enable the PostNL shipping method under '
781
- . 'System > Config > Shipping Methods.'
782
- );
783
  }
784
 
 
 
 
 
 
 
 
785
  $errors = array(
786
  array(
787
  'code' => 'POSTNL-0031',
@@ -914,9 +1292,14 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
914
  Mage::unregister('postnl_core_is_configured_errors');
915
 
916
  /**
917
- * Check if the module has been activated
 
 
 
 
 
918
  */
919
- $isActivated = Mage::getStoreConfig(self::XML_PATH_IS_ACTIVATED, Mage_Core_Model_App::ADMIN_STORE_ID);
920
  if ($isActivated != 2) {
921
  $errors[] = array(
922
  'code' => 'POSTNL-0033',
@@ -934,7 +1317,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
934
  $baseFields = $this->getRequiredFields();
935
 
936
  /**
937
- * Get either the live mode or test mode required fields
938
  */
939
  if ($testMode) {
940
  $modeFields = $this->getTestModeRequiredFields();
@@ -943,12 +1326,15 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
943
  }
944
  $requiredFields = array_merge($modeFields, $baseFields);
945
 
 
 
 
 
946
  $fieldErrors = $this->_getFieldsConfiguredErrors($requiredFields, $storeId);
947
-
948
  $errors = array_merge($errors, $fieldErrors);
949
 
950
  /**
951
- * If any errors were detected, add them to the registry and return false
952
  */
953
  if (!empty($errors)) {
954
  Mage::register('postnl_core_is_configured_errors', $errors);
@@ -1018,49 +1404,75 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1018
  $errors = array();
1019
 
1020
  /**
1021
- * Check if each required field is filled.
 
 
1022
  */
1023
  if ($this->isSystemConfig() || $this->isLoggingEnabled()) {
1024
  /**
1025
- * If not, add the field's label to an array of missing fields so we can later inform the merchant which
1026
- * fields exactly are missing.
1027
  *
1028
  * @var Varien_Simplexml_Element $section
1029
  */
1030
  $configFields = Mage::getSingleton('adminhtml/config');
1031
- $sections = $configFields->getSections('postnl');
1032
- $section = $sections->postnl;
1033
  }
1034
 
 
 
 
 
 
 
1035
  foreach ($requiredFields as $requiredField) {
1036
- $value = Mage::getStoreConfig($requiredField, $storeId);
 
 
 
 
 
 
 
 
 
 
 
 
 
1037
 
 
 
 
1038
  if ($value !== null && $value !== '') {
1039
  continue;
1040
  }
1041
 
1042
- if (isset($section)) {
1043
- $fieldParts = explode('/', $requiredField);
1044
- $field = $fieldParts[2];
1045
- $group = $fieldParts[1];
1046
-
1047
- /**
1048
- * @var Varien_Simplexml_Element $sectionGroup
1049
- */
1050
- $sectionGroup = $section->groups->$group;
1051
-
1052
- $label = (string) $sectionGroup->fields->$field->label;
1053
- $groupLabel = (string) $sectionGroup->label;
1054
- $groupName = $sectionGroup->getName();
1055
 
1056
  $errors[] = array(
1057
  'code' => 'POSTNL-0034',
1058
- 'message' => $this->__('%s > %s is required.', $this->__($groupLabel), $this->__($label)),
1059
  );
 
 
1060
 
1061
- if ($this->isSystemConfig()) {
1062
- $this->saveConfigState(array('postnl_' . $groupName => 1));
 
1063
  }
 
 
 
 
 
 
 
 
1064
  } else {
1065
  $errors[] = array(
1066
  'code' => 'POSTNL-0160',
@@ -1072,6 +1484,43 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1072
  return $errors;
1073
  }
1074
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1075
  /**
1076
  * Check if debug logging is enabled
1077
  *
@@ -1079,6 +1528,10 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1079
  */
1080
  public function isLoggingEnabled()
1081
  {
 
 
 
 
1082
  $debugMode = $this->getDebugMode();
1083
  if ($debugMode > 1) {
1084
  return true;
@@ -1094,6 +1547,10 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1094
  */
1095
  public function isExceptionLoggingEnabled()
1096
  {
 
 
 
 
1097
  $debugMode = $this->getDebugMode();
1098
  if ($debugMode > 0) {
1099
  return true;
@@ -1166,15 +1623,21 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1166
  * @param boolean $forced
1167
  * @param boolean $isError
1168
  *
1169
- * @return TIG_PostNL_Helper_Data
1170
  *
1171
  * @see Mage::log
1172
  */
1173
  public function log($message, $level = null, $file = null, $forced = false, $isError = false)
1174
  {
1175
- if ($isError === true && !$this->isExceptionLoggingEnabled()) {
 
 
 
1176
  return $this;
1177
- } elseif ($isError !== true && !$this->isLoggingEnabled()) {
 
 
 
1178
  return $this;
1179
  }
1180
 
@@ -1194,12 +1657,12 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1194
  }
1195
 
1196
  /**
1197
- * Logs a cron debug message to a separate file in order to differentiate it from other debug messages
1198
  *
1199
  * @param string $message
1200
  * @param int $level
1201
  *
1202
- * @return TIG_PostNL_Helper_Data
1203
  *
1204
  * @see Mage::log
1205
  */
@@ -1217,7 +1680,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1217
  *
1218
  * @param string|Exception $exception
1219
  *
1220
- * @return TIG_PostNL_Helper_Data
1221
  *
1222
  * @see Mage::logException
1223
  */
@@ -1279,14 +1742,6 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1279
  return true;
1280
  }
1281
 
1282
- /**
1283
- * Do a version check instead.
1284
- */
1285
- $version = Mage::getVersion();
1286
- if (version_compare($version, '1.9.0.0', '>=')) {
1287
- return true;
1288
- }
1289
-
1290
  return false;
1291
  }
1292
 
@@ -1333,7 +1788,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1333
  /**
1334
  * Creates a separate dir to log PostNL log files. Does nothing if the dir already exists.
1335
  *
1336
- * @return TIG_PostNL_Exception
1337
  */
1338
  public function createLogDir()
1339
  {
@@ -1371,9 +1826,9 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1371
  * $session->addError() call.
1372
  *
1373
  * @param string|Mage_Core_Model_Session_Abstract $session The session to which the messages will be added.
1374
- * @param Exception $exception
1375
  *
1376
- * @return TIG_PostNL_Helper_Data
1377
  *
1378
  * @see TIG_PostNL_Helper_Data::addSessionMessage()
1379
  */
@@ -1437,7 +1892,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1437
  * @param string|null $messageType
1438
  * @param string|null $message
1439
  *
1440
- * @return TIG_PostNL_Helper_Data
1441
  *
1442
  * @see Mage_Core_Model_Session_Abstract::addMessage()
1443
  *
@@ -1447,11 +1902,11 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1447
  public function addSessionMessage($session, $code = null, $messageType = null, $message = null)
1448
  {
1449
  /***************************************************************************************************************
1450
- * Check that the required arguments are available and valid
1451
  **************************************************************************************************************/
1452
 
1453
  /**
1454
- * If $code is null or 0, $messageType and $message are required
1455
  */
1456
  if (
1457
  (is_null($code) || $code === 0)
@@ -1463,7 +1918,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1463
  }
1464
 
1465
  /**
1466
- * If the session is a string, treat it as a class name and instantiate it
1467
  */
1468
  if (is_string($session) && strpos($session, '/') !== false) {
1469
  $session = Mage::getSingleton($session);
@@ -1472,7 +1927,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1472
  }
1473
 
1474
  /**
1475
- * If the session could not be loaded or is not of the correct type, throw an exception
1476
  */
1477
  if (!$session
1478
  || !is_object($session)
@@ -1484,8 +1939,63 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1484
  );
1485
  }
1486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1487
  /***************************************************************************************************************
1488
- * Get the actual error from config.xml if it's available
1489
  **************************************************************************************************************/
1490
 
1491
  $error = false;
@@ -1507,14 +2017,14 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1507
  **************************************************************************************************************/
1508
 
1509
  /**
1510
- * If the specified error was found and no message was supplied, get the error's default message
1511
  */
1512
  if ($error && !$message) {
1513
  $message = (string) $error->message;
1514
  }
1515
 
1516
  /**
1517
- * If we still don't have a valid message, throw an exception
1518
  */
1519
  if (!$message) {
1520
  throw new TIG_PostNL_Exception(
@@ -1524,7 +2034,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1524
  }
1525
 
1526
  /**
1527
- * If the specified error was found and no message type was supplied, get the error's default type
1528
  */
1529
  if ($error && !$messageType) {
1530
  $messageType = (string) $error->type;
@@ -1532,7 +2042,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1532
 
1533
 
1534
  /**
1535
- * If we still don't have a valid message type, throw an exception
1536
  */
1537
  if (!$messageType) {
1538
  throw new TIG_PostNL_Exception(
@@ -1548,7 +2058,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1548
 
1549
  /**
1550
  * Flag that determines whether the error code and knowledgebase link will be included in the error message
1551
- * (if available)
1552
  */
1553
  $canShowErrorDetails = $this->_canShowErrorDetails();
1554
 
@@ -1564,46 +2074,22 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1564
  }
1565
 
1566
  /**
1567
- * Add the actual message. This is the only required part. The code and link are optional
1568
  */
1569
  $errorMessage .= $this->__($message);
1570
 
1571
  /**
1572
- * Add the link to the knowledgebase if we have one
1573
  */
1574
  if ($canShowErrorDetails && $link) {
1575
  $errorMessage .= ' <a href="'
1576
- . $link
1577
- . '" target="_blank" class="postnl-message">'
1578
- . $this->__('Click here for more information from the TiG knowledgebase.')
1579
- . '</a>';
1580
- }
1581
-
1582
- /***************************************************************************************************************
1583
- * Finally, let's add the error to the session
1584
- **************************************************************************************************************/
1585
-
1586
- /**
1587
- * The method we'll use to add the message to the session has to be built first
1588
- */
1589
- $addMethod = 'add' . ucfirst($messageType);
1590
-
1591
- /**
1592
- * If the method doesn't exist, throw an exception
1593
- */
1594
- if (!method_exists($session, $addMethod)) {
1595
- throw new TIG_PostNL_Exception(
1596
- $this->__('Invalid message type requested: %s.', $messageType),
1597
- 'POSTNL-0094'
1598
- );
1599
  }
1600
 
1601
- /**
1602
- * Add the message to the session
1603
- */
1604
- $session->$addMethod($errorMessage);
1605
-
1606
- return $this;
1607
  }
1608
 
1609
  /**
@@ -1625,7 +2111,7 @@ class TIG_PostNL_Helper_Data extends Mage_Core_Helper_Abstract
1625
  * Check if the show_error_details_in_frontend setting is set to true
1626
  */
1627
  $storeId = Mage::app()->getStore()->getId();
1628
- if (Mage::getStoreConfigFlag(self::XML_PATH_SHOW_ERROR_DETAILS_IN_FRONTEND, $storeId)) {
1629
  return true;
1630
  }
1631
 
61
  /**
62
  * XML path to postnl general active/inactive setting.
63
  */
64
+ const XPATH_EXTENSION_ACTIVE = 'postnl/general/active';
 
 
 
 
 
65
 
66
  /**
67
  * XML path to test/live mode config option.
68
  */
69
+ const XPATH_TEST_MODE = 'postnl/cif/mode';
70
 
71
  /**
72
  * XML path to the test mode allowed config option.
73
  */
74
+ const XPATH_TEST_MODE_ALLOWED = 'postnl/advanced/allow_test_mode';
75
 
76
  /**
77
  * XML path to debug mode config option.
78
  */
79
+ const XPATH_DEBUG_MODE = 'postnl/advanced/debug_mode';
80
 
81
  /**
82
  * XML path to 'is_activated' flag.
83
  */
84
+ const XPATH_IS_ACTIVATED = 'postnl/general/is_activated';
85
 
86
  /**
87
  * XML path to 'show_error_details_in_frontend' flag.
88
  */
89
+ const XPATH_SHOW_ERROR_DETAILS_IN_FRONTEND = 'postnl/advanced/show_error_details_in_frontend';
90
+
91
+ /**
92
+ * XML path to use_globalpack setting.
93
+ */
94
+ const XPATH_USE_GLOBALPACK = 'postnl/cif/use_globalpack';
95
 
96
  /**
97
+ * Xpath to use_buspakje setting.
98
  */
99
+ const XPATH_USE_BUSPAKJE = 'postnl/cif_labels_and_confirming/use_buspakje';
100
 
101
  /**
102
  * XPATH to allow EPS BE only product option setting.
103
  */
104
  const XPATH_ALLOW_EPS_BE_ONLY_OPTION = 'postnl/cif_product_options/allow_eps_be_only_options';
105
 
106
+ /**
107
+ * XML path to weight unit used
108
+ */
109
+ const XPATH_WEIGHT_UNIT = 'postnl/cif_labels_and_confirming/weight_unit';
110
+
111
+ /**
112
+ * Xpath to the buspakje calculation mode setting.
113
+ */
114
+ const XPATH_BUSPAKJE_CALC_MODE = 'postnl/cif_labels_and_confirming/buspakje_calculation_mode';
115
+
116
+ /**
117
+ * Minimum PHP version required by this extension.
118
+ */
119
+ const MIN_PHP_VERSION = '5.3.0';
120
+
121
  /**
122
  * Required configuration fields.
123
  *
128
  'postnl/cif/customer_number',
129
  'postnl/cif/collection_location',
130
  'postnl/cif_labels_and_confirming/label_size',
131
+ array(
132
+ 'postnl/cif_sender_address/lastname',
133
+ 'postnl/cif_sender_address/company',
134
+ ),
135
  'postnl/cif_sender_address/streetname',
136
  'postnl/cif_sender_address/housenumber',
137
  'postnl/cif_sender_address/postcode',
173
  );
174
 
175
  /**
176
+ * Array of possible log files created by the PostNL extension.
177
+ *
178
+ * @var array
179
+ */
180
+ protected $_logFiles = array(
181
+ 'TIG_PostNL_Cendris_Debug.log',
182
+ 'TIG_PostNL_Cendris_Exception.log',
183
+ 'TIG_PostNL_Checkout_Debug.log',
184
+ 'TIG_PostNL_CIF_Debug.log',
185
+ 'TIG_PostNL_CIF_Exception.log',
186
+ 'TIG_PostNL_Cron_Debug.log',
187
+ 'TIG_PostNL_Debug.log',
188
+ 'TIG_PostNL_Exception.log',
189
+ 'TIG_PostNL_MijnPakket_Debug.log',
190
+ 'TIG_PostNL_Payment_Debug.log',
191
+ 'TIG_PostNL_Webservices_Debug.log',
192
+ 'TIG_PostNL_Webservices_Exception.log',
193
+ );
194
+
195
+ /**
196
+ * For certain product codes a custom barcode is required.
197
+ *
198
+ * @var array
199
+ */
200
+ protected $_customBarcodes = array(
201
+ '2828' => '3STFGG000000000'
202
+ );
203
+
204
+ /**
205
+ * @var null|boolean|TIG_PostNL_Model_Core_Cache
206
  */
207
  protected $_cache = null;
208
 
209
+ /**
210
+ * THe current server's memory limit.
211
+ *
212
+ * @var int
213
+ */
214
+ protected $_memoryLimit;
215
+
216
  /**
217
  * Get required fields array.
218
  *
254
  }
255
 
256
  /**
257
+ * @param null|boolean|TIG_PostNL_Model_Core_Cache $cache
258
  *
259
  * @return TIG_PostNL_Helper_Data
260
  */
266
  }
267
 
268
  /**
269
+ * Gets the cache if it's been set. If the cache is null, it means the cache had not been defined yet. In this case
270
+ * we instantiate the cache model. If the cache is active, the _cache variable will be set with the cache instance.
271
+ * Otherwise the _cache variable will be false.
272
+ *
273
+ * @return null|boolean|TIG_PostNL_Model_Core_Cache
274
  */
275
  public function getCache()
276
  {
287
  return $cache;
288
  }
289
 
290
+ /**
291
+ * @return array
292
+ */
293
+ public function getLogFiles()
294
+ {
295
+ return $this->_logFiles;
296
+ }
297
+
298
+ /**
299
+ * Gets the current memory limit in bytes.
300
+ *
301
+ * @return int
302
+ */
303
+ public function getMemoryLimit()
304
+ {
305
+ if ($this->_memoryLimit) {
306
+ return $this->_memoryLimit;
307
+ }
308
+
309
+ $memoryLimit = ini_get('memory_limit');
310
+ if (preg_match('/^(\d+)(.)$/', $memoryLimit, $matches)) {
311
+ if (!isset($matches[1])) {
312
+ $memoryLimit = (int) $memoryLimit;
313
+ } elseif (!isset($matches[2])) {
314
+ $memoryLimit = $matches[1];
315
+ } elseif ($matches[2] == 'G' || $matches[2] == 'g') {
316
+ $memoryLimit = $matches[1] * 1024 * 1024 * 1024;
317
+ } elseif ($matches[2] == 'M' || $matches[2] == 'm') {
318
+ $memoryLimit = $matches[1] * 1024 * 1024;
319
+ } elseif ($matches[2] == 'K' || $matches[2] == 'k') {
320
+ $memoryLimit = $matches[1] * 1024;
321
+ }
322
+ } else {
323
+ $memoryLimit = (int) $memoryLimit;
324
+ }
325
+
326
+ $this->setMemoryLimit($memoryLimit);
327
+ return $memoryLimit;
328
+ }
329
+
330
+ /**
331
+ * @param int $memoryLimit
332
+ *
333
+ * @return $this
334
+ */
335
+ public function setMemoryLimit($memoryLimit)
336
+ {
337
+ $this->_memoryLimit = $memoryLimit;
338
+
339
+ return $this;
340
+ }
341
+
342
+ /**
343
+ * get an array of product codes which use a custom barcode.
344
+ *
345
+ * @return array
346
+ */
347
+ public function getCustomBarcodes()
348
+ {
349
+ return $this->_customBarcodes;
350
+ }
351
+
352
  /**
353
  * Get debug mode config setting.
354
  *
360
  return Mage::registry('postnl_debug_mode');
361
  }
362
 
363
+ $debugMode = (int) Mage::getStoreConfig(self::XPATH_DEBUG_MODE, Mage_Core_Model_App::ADMIN_STORE_ID);
364
 
365
  Mage::register('postnl_debug_mode', $debugMode);
366
  return $debugMode;
392
  /**
393
  * Check if this order was placed using PostNL.
394
  */
 
395
  $shippingMethod = $order->getShippingMethod();
396
 
397
  /**
398
  * If this shipment's order was not placed with PostNL, we need to ignore any PakjeGemak addresses that may have
399
  * been saved.
400
  */
401
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
402
  return false;
403
  }
404
 
418
  /**
419
  * Checks to see if the module may ship to the Netherlands using PostNL standard shipments.
420
  *
 
 
421
  * @return boolean
422
  */
423
+ public function canUseStandard()
424
  {
425
  $cache = $this->getCache();
426
 
428
  return $cache->getPostnlCoreCanUseStandard();
429
  }
430
 
 
 
 
 
431
  $standardProductOptions = Mage::getModel('postnl_core/system_config_source_standardProductOptions')
432
+ ->getAvailableOptions();
433
  if (empty($standardProductOptions)) {
434
  if ($cache) {
435
  $cache->setPostnlCoreCanUseStandard(false)
450
  /**
451
  * Checks to see if the module may ship using PakjeGemak.
452
  *
 
 
453
  * @return boolean
454
  */
455
+ public function canUsePakjeGemak()
456
  {
457
  $cache = $this->getCache();
458
 
460
  return $cache->getPostnlCoreCanUsePakjeGemak();
461
  }
462
 
 
 
 
 
463
  $pakjeGemakProductoptions = Mage::getModel('postnl_core/system_config_source_pakjeGemakProductOptions')
464
+ ->getAvailableOptions();
465
 
466
  if (empty($pakjeGemakProductoptions)) {
467
  if ($cache) {
482
  /**
483
  * Checks to see if the module may ship to EU countries using EPS
484
  *
 
 
485
  * @return boolean
486
  */
487
+ public function canUseEps()
488
  {
489
  $cache = $this->getCache();
490
 
492
  return $cache->getPostnlCoreCanUseEps();
493
  }
494
 
 
 
 
 
495
  $euProductOptions = Mage::getModel('postnl_core/system_config_source_euProductOptions')
496
+ ->getAvailableOptions();
497
 
498
  if (empty($euProductOptions)) {
499
  if ($cache) {
513
  /**
514
  * Checks to see if the module may ship to countries outside the EU using GlobalPack
515
  *
 
 
516
  * @return boolean
517
  */
518
+ public function canUseGlobalPack()
519
  {
520
  $cache = $this->getCache();
521
 
523
  return $cache->getPostnlCoreCanUseGlobalPack();
524
  }
525
 
 
 
 
 
526
  if (!$this->isGlobalAllowed()) {
527
  if ($cache) {
528
  $cache->setPostnlCoreCanUseGlobalPack(false)
532
  }
533
 
534
  $globalProductOptions = Mage::getModel('postnl_core/system_config_source_globalProductOptions')
535
+ ->getAvailableOptions();
536
 
537
  if (empty($globalProductOptions)) {
538
  if ($cache) {
549
  return true;
550
  }
551
 
552
+ /**
553
+ * Checks to see if the module may ship buspakjes.
554
+ *
555
+ * @return boolean
556
+ */
557
+ public function canUseBuspakje()
558
+ {
559
+ $cache = $this->getCache();
560
+
561
+ if ($cache && $cache->hasPostnlCoreCanUseBuspakje()) {
562
+ return $cache->getPostnlCoreCanUseBuspakje();
563
+ }
564
+
565
+ $isBuspakjeActive = Mage::getStoreConfigFlag(self::XPATH_USE_BUSPAKJE);
566
+
567
+ if (!$isBuspakjeActive) {
568
+ if ($cache) {
569
+ $cache->setPostnlCoreCanUseBuspakje(false)
570
+ ->saveCache();
571
+ }
572
+
573
+ return false;
574
+ }
575
+
576
+ $buspakjeProductOptions = Mage::getModel('postnl_core/system_config_source_buspakjeProductOptions')
577
+ ->getAvailableOptions();
578
+
579
+ if (empty($buspakjeProductOptions)) {
580
+ if ($cache) {
581
+ $cache->setPostnlCoreCanUseBuspakje(false)
582
+ ->saveCache();
583
+ }
584
+
585
+ return false;
586
+ }
587
+
588
+ if ($cache) {
589
+ $cache->setPostnlCoreCanUseBuspakje(true)
590
+ ->saveCache();
591
+ }
592
+
593
+ return true;
594
+ }
595
+
596
  /**
597
  * Checks whether the EPS BE only product option is allowed.
598
  *
664
  return true;
665
  }
666
 
667
+ /**
668
+ * Gets the currently configured buspakje calculation mode.
669
+ *
670
+ * @param null|int|string $storeId
671
+ *
672
+ * @return string
673
+ */
674
+ public function getBuspakjeCalculationMode($storeId = null)
675
+ {
676
+ if ($storeId === null) {
677
+ $storeId = Mage::app()->getStore()->getId();
678
+ }
679
+
680
+ $calculationMode = Mage::getStoreConfig(self::XPATH_BUSPAKJE_CALC_MODE, $storeId);
681
+
682
+ return $calculationMode;
683
+ }
684
+
685
+ /**
686
+ * Determines whether an array of items would fit as a buspakje shipment.
687
+ *
688
+ * @param array|Mage_Sales_Model_Resource_Collection_Abstract $items
689
+ * @param boolean $registerReason
690
+ *
691
+ * @return boolean
692
+ */
693
+ public function fitsAsBuspakje($items, $registerReason = false)
694
+ {
695
+ $totalQtyRatio = 0;
696
+ $totalWeight = 0;
697
+
698
+ if ($registerReason) {
699
+ Mage::unregister('postnl_reason_not_buspakje');
700
+ }
701
+
702
+ /**
703
+ * @var Mage_Sales_Model_Order_Item|Mage_Sales_Model_Order_Shipment_Item $item
704
+ */
705
+ foreach ($items as $item) {
706
+ /**
707
+ * Get either the qty ordered or the qty shipped, depending on whether this is an order or a shipment item.
708
+ */
709
+ if ($item instanceof Mage_Sales_Model_Order_Item) {
710
+ if ($item->getParentItemId()) {
711
+ $qty = $item->getParentItem()->getQtyOrdered();
712
+ } else {
713
+ $qty = $item->getQtyOrdered();
714
+ }
715
+ } elseif ($item instanceof Mage_Sales_Model_Order_Shipment_Item) {
716
+ $qty = $item->getQty();
717
+ } elseif($item instanceof Mage_Sales_Model_Quote_Item) {
718
+ if ($item->getParentItemId()) {
719
+ $qty = $item->getParentItem()->getQty();
720
+ } else {
721
+ $qty = $item->getQty();
722
+ }
723
+ } else {
724
+ if ($registerReason) {
725
+ Mage::register('postnl_reason_not_buspakje', 'missing_qty');
726
+ }
727
+ return false;
728
+ }
729
+
730
+ /**
731
+ * The max qty attribute is only available on simple products.
732
+ */
733
+ if ($item->getProductType() != Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
734
+ continue;
735
+ }
736
+
737
+ /**
738
+ * Calculate the weight of the item in kilograms.
739
+ */
740
+ $weight = $item->getWeight() * $qty;
741
+ $convertedWeight = $this->standardizeWeight($weight, $item->getStoreId());
742
+
743
+ $totalWeight += $convertedWeight;
744
+
745
+ /**
746
+ * Get how many of this product would fit in a buspakje package.
747
+ */
748
+ $maxQty = Mage::getResourceSingleton('postnl/catalog_product')->getAttributeRawValue(
749
+ $item->getProductId(),
750
+ 'postnl_max_qty_for_buspakje',
751
+ $item->getStoreId()
752
+ );
753
+
754
+ if (!is_numeric($maxQty) || !$maxQty) {
755
+ if ($registerReason) {
756
+ Mage::register('postnl_reason_not_buspakje', 'invalid_max_qty');
757
+ }
758
+ return false;
759
+ }
760
+
761
+ /**
762
+ * Determine the ratio. If 2 products fit, then the ratio is 1/2 = 0.5. If 3 fit, the ratio is 1/3 = 0.33.
763
+ */
764
+ $qtyRatio = 1 / $maxQty;
765
+
766
+ $totalQtyRatio += $qtyRatio * $qty;
767
+ }
768
+
769
+ /**
770
+ * If the combined weight of all items is more than 2 kg, this shipment is not a buspakje.
771
+ */
772
+ if ($totalWeight > 2) {
773
+ if ($registerReason) {
774
+ Mage::register('postnl_reason_not_buspakje', 'weight');
775
+ }
776
+ return false;
777
+ }
778
+
779
+ /**
780
+ * If the combined qty ratios of the items is more than 1 this is not a buspakje.
781
+ */
782
+ if ($totalQtyRatio > 1) {
783
+ if ($registerReason) {
784
+ Mage::register('postnl_reason_not_buspakje', 'qty_ratio');
785
+ }
786
+ return false;
787
+ }
788
+
789
+ return true;
790
+ }
791
+
792
+ /**
793
+ * Convert a given weight to kilogram or gram.
794
+ *
795
+ * @param float $weight The weight to be converted
796
+ * @param int | null $storeId Store Id used to determine the weight unit that was originally used
797
+ * @param boolean $toGram Optional parameter to convert to gram instead of kilogram
798
+ *
799
+ * @return float
800
+ */
801
+ public function standardizeWeight($weight, $storeId = null, $toGram = false)
802
+ {
803
+ if (is_null($storeId)) {
804
+ $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
805
+ }
806
+
807
+ $unitUsed = Mage::getStoreConfig(self::XPATH_WEIGHT_UNIT, $storeId);
808
+
809
+ switch ($unitUsed) {
810
+ case 'tonne':
811
+ $returnWeight = $weight * 1000;
812
+ break;
813
+ case 'kilogram':
814
+ $returnWeight = $weight * 1;
815
+ break;
816
+ case 'hectogram':
817
+ $returnWeight = $weight * 10;
818
+ break;
819
+ case 'gram':
820
+ $returnWeight = $weight * 0.001;
821
+ break;
822
+ case 'carat':
823
+ $returnWeight = $weight * 0.0002;
824
+ break;
825
+ case 'centigram':
826
+ $returnWeight = $weight * 0.00001;
827
+ break;
828
+ case 'milligram':
829
+ $returnWeight = $weight * 0.000001;
830
+ break;
831
+ case 'longton':
832
+ $returnWeight = $weight * 1016.0469088;
833
+ break;
834
+ case 'shortton':
835
+ $returnWeight = $weight * 907.18474;
836
+ break;
837
+ case 'longhundredweight':
838
+ $returnWeight = $weight * 50.80234544;
839
+ break;
840
+ case 'shorthundredweight':
841
+ $returnWeight = $weight * 45.359237;
842
+ break;
843
+ case 'stone':
844
+ $returnWeight = $weight * 6.35029318;
845
+ break;
846
+ case 'pound':
847
+ $returnWeight = $weight * 0.45359237;
848
+ break;
849
+ case 'ounce':
850
+ $returnWeight = $weight * 0.028349523125;
851
+ break;
852
+ case 'grain': //no break
853
+ case 'troy_grain':
854
+ $returnWeight = $weight * 0.00006479891;
855
+ break;
856
+ case 'troy_pound':
857
+ $returnWeight = $weight * 0.3732417216;
858
+ break;
859
+ case 'troy_ounce':
860
+ $returnWeight = $weight * 0.0311034768;
861
+ break;
862
+ case 'troy_pennyweight':
863
+ $returnWeight = $weight * 0.00155517384;
864
+ break;
865
+ case 'troy_carat':
866
+ $returnWeight = $weight * 0.00020519654;
867
+ break;
868
+ case 'troy_mite':
869
+ $returnWeight = $weight * 0.00000323994;
870
+ break;
871
+ default:
872
+ $returnWeight = $weight;
873
+ break;
874
+ }
875
+
876
+ if ($toGram === true) {
877
+ $returnWeight *= 1000;
878
+ }
879
+
880
+ return $returnWeight;
881
+ }
882
+
883
  /**
884
  * Checks if the current admin user is allowed for the specified actions.
885
  *
927
  case 'create_shipment':
928
  $aclPath = 'sales/order/actions/ship';
929
  break;
 
 
 
 
 
 
930
  case 'view_complete_status':
931
  $aclPath = 'postnl/shipment/complete_status';
932
  break;
933
+ case 'download_logs':
934
+ $aclPath = 'system/config/postnl/download_logs';
935
+ break;
936
+ case 'print_packing_slips':
937
+ $aclPath = 'postnl/shipment/actions/print_label/print_packing_slips';
938
  break;
939
+ case 'convert_to_buspakje':
940
+ $aclPath = 'postnl/shipment/actions/convert/to_buspakje';
941
  break;
942
+ case 'convert_to_package':
943
+ $aclPath = 'postnl/shipment/actions/convert/to_package';
944
  break;
945
+ case 'change_product_code':
946
+ $aclPath = 'postnl/shipment/actions/convert/change_product_code';
947
+ break;
948
+ case 'confirm': //no break
949
+ case 'print_label': //no break
950
+ case 'reset_confirmation': //no break
951
+ case 'delete_labels': //no break
952
+ case 'create_parcelware_export': //no break
953
  case 'send_track_and_trace':
954
+ $aclPath = 'postnl/shipment/actions/' . $action;
955
  break;
956
  default:
957
  $aclPath = false;
975
  {
976
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
977
 
978
+ $useGlobal = Mage::getStoreConfigFlag(self::XPATH_USE_GLOBALPACK, $storeId);
979
  return $useGlobal;
980
  }
981
 
996
  $storeId = Mage::app()->getStore()->getId();
997
  }
998
 
999
+ $testMode = Mage::getStoreConfigFlag(self::XPATH_TEST_MODE, $storeId);
1000
 
1001
  Mage::register('postnl_test_mode', $testMode);
1002
  return $testMode;
1072
  */
1073
  protected function _isEnabled($storeId, $forceTestMode, $ignoreCache)
1074
  {
1075
+ if (version_compare(phpversion(), self::MIN_PHP_VERSION, '<')) {
1076
+ return false;
1077
+ }
1078
+
1079
  if ($storeId === false) {
1080
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
1081
  }
1085
  /**
1086
  * Check if the module has been enabled
1087
  */
1088
+ $enabled = Mage::getStoreConfigFlag(self::XPATH_EXTENSION_ACTIVE, $storeId);
1089
  if ($enabled === false) {
1090
  $errors = array(
1091
  array(
1115
  }
1116
 
1117
  /**
1118
+ * Check if at least one PostNL shipping method is active.
1119
+ *
1120
+ * First get a list of all PostNl shipping methods from the PostNl config. Then compare this to a list of all
1121
+ * active shipping methods in Magento.
1122
  */
1123
+ $postnlShippingMethodEnabled = false;
1124
+ $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
1125
+ $activeMethods = Mage::getModel('postnl_core/system_config_source_shippingMethods')
1126
+ ->toArray(true);
1127
+
1128
+ if ($postnlShippingMethods) {
1129
+ $activePostnlMethods = array_intersect($postnlShippingMethods, $activeMethods);
1130
+ if (!empty($activePostnlMethods)) {
1131
+ $postnlShippingMethodEnabled = true;
1132
+ }
1133
+ }
1134
+
1135
+ if (!$postnlShippingMethodEnabled) {
1136
+ $link = '';
1137
+ $linkEnd = '';
1138
+
1139
  if ($this->isSystemConfig() || $this->isLoggingEnabled()) {
1140
  $shippingMethodSectionurl = Mage::helper("adminhtml")->getUrl(
1141
  'adminhtml/system_config/edit',
1145
  )
1146
  );
1147
 
1148
+ $link = '<a href="'
1149
+ . $shippingMethodSectionurl
1150
+ . '" target="_blank" title="'
1151
+ . $this->__('Shipping Methods')
1152
+ . '">';
1153
+ $linkEnd = '</a>';
 
 
 
 
 
 
 
 
 
1154
  }
1155
 
1156
+ $errorMessage = $this->__(
1157
+ 'No PostNL shipping method has been enabled. You can enable the PostNL shipping method under '
1158
+ . '%sSystem > Config > Shipping Methods%s.',
1159
+ $link,
1160
+ $linkEnd
1161
+ );
1162
+
1163
  $errors = array(
1164
  array(
1165
  'code' => 'POSTNL-0031',
1292
  Mage::unregister('postnl_core_is_configured_errors');
1293
 
1294
  /**
1295
+ * Check if the module has been activated.
1296
+ *
1297
+ * The is_activated config value can have 3 possible values:
1298
+ * 0 - The extension has not yet been activated.
1299
+ * 1 - The activation procedure has begun and keys have been sent to the merchant.
1300
+ * 2 - The activation procedure has been finished. The merchant has entered his keys.
1301
  */
1302
+ $isActivated = Mage::getStoreConfig(self::XPATH_IS_ACTIVATED, Mage_Core_Model_App::ADMIN_STORE_ID);
1303
  if ($isActivated != 2) {
1304
  $errors[] = array(
1305
  'code' => 'POSTNL-0033',
1317
  $baseFields = $this->getRequiredFields();
1318
 
1319
  /**
1320
+ * Get either the live mode or test mode required fields.
1321
  */
1322
  if ($testMode) {
1323
  $modeFields = $this->getTestModeRequiredFields();
1326
  }
1327
  $requiredFields = array_merge($modeFields, $baseFields);
1328
 
1329
+ /**
1330
+ * Check if all required fields are entered. This method will return an array of errors containing the fields
1331
+ * that are missing. If all fields are entered, the array will be empty.
1332
+ */
1333
  $fieldErrors = $this->_getFieldsConfiguredErrors($requiredFields, $storeId);
 
1334
  $errors = array_merge($errors, $fieldErrors);
1335
 
1336
  /**
1337
+ * If any errors were detected, add them to the registry and return false.
1338
  */
1339
  if (!empty($errors)) {
1340
  Mage::register('postnl_core_is_configured_errors', $errors);
1404
  $errors = array();
1405
 
1406
  /**
1407
+ * If full logging is enabled or we are on the system > config page in the backend, we may add additional
1408
+ * details about fields that are missing. To do this we need to load the very large Mage_Adminhtml_Model_Config
1409
+ * singleton.
1410
  */
1411
  if ($this->isSystemConfig() || $this->isLoggingEnabled()) {
1412
  /**
1413
+ * Load the adminhtml config model and get the PostNL section.
 
1414
  *
1415
  * @var Varien_Simplexml_Element $section
1416
  */
1417
  $configFields = Mage::getSingleton('adminhtml/config');
1418
+ $section = $configFields->getSections('postnl')->postnl;
 
1419
  }
1420
 
1421
+ /**
1422
+ * Loop through all required fields and check if they're configured.
1423
+ *
1424
+ * $requiredField may be the full xpath to the config setting or it may be an array of xpaths. In the latter
1425
+ * case one of the fields in the array must be configured.
1426
+ */
1427
  foreach ($requiredFields as $requiredField) {
1428
+ /**
1429
+ * Get the value of this field.
1430
+ */
1431
+ if (is_array($requiredField)) {
1432
+ $value = null;
1433
+ foreach ($requiredField as $requiredSubField) {
1434
+ if (Mage::getStoreConfig($requiredSubField, $storeId)) {
1435
+ $value = true;
1436
+ break;
1437
+ }
1438
+ }
1439
+ } else {
1440
+ $value = Mage::getStoreConfig($requiredField, $storeId);
1441
+ }
1442
 
1443
+ /**
1444
+ * If the value is null or an empty string, it is not configured. Please note that 0 is a valid value.
1445
+ */
1446
  if ($value !== null && $value !== '') {
1447
  continue;
1448
  }
1449
 
1450
+ /**
1451
+ * Add the error message. The error message may be different based on whether the missing field is a single
1452
+ * field, an array of fields and whether we are currently on the system > config page.
1453
+ */
1454
+ if (isset($section) && !is_array($requiredField)) {
1455
+ $errorMessage = $this->_getFieldMissingErrorMessage($requiredField, $section);
 
 
 
 
 
 
 
1456
 
1457
  $errors[] = array(
1458
  'code' => 'POSTNL-0034',
1459
+ 'message' => $errorMessage,
1460
  );
1461
+ } elseif (isset($section)) {
1462
+ $message = $this->__('One of the following fields is required:');
1463
 
1464
+ $fieldErrors = array();
1465
+ foreach ($requiredField as $requiredSubField) {
1466
+ $fieldErrors[] = $this->_getFieldMissingErrorMessage($requiredSubField, $section, '%s > %s');
1467
  }
1468
+
1469
+ $implodeString = ' ' . $this->__('or') . ' ';
1470
+ $message .= ' ' . implode($implodeString, $fieldErrors);
1471
+
1472
+ $errors[] = array(
1473
+ 'code' => 'POSTNL-0034',
1474
+ 'message' => $message,
1475
+ );
1476
  } else {
1477
  $errors[] = array(
1478
  'code' => 'POSTNL-0160',
1484
  return $errors;
1485
  }
1486
 
1487
+ /**
1488
+ * Get a formatted error message for a missing system > config value.
1489
+ *
1490
+ * @param string $requiredField The full xpath to the field.
1491
+ * @param Varien_Simplexml_Element $section The system.xml section the field is present in.
1492
+ * @param null|string $format The format of the message. By default: '%s > %s is required.'.
1493
+ * @param boolean $saveConfigState
1494
+ *
1495
+ * @return string
1496
+ */
1497
+ protected function _getFieldMissingErrorMessage($requiredField, $section, $format = null, $saveConfigState = true)
1498
+ {
1499
+ $fieldParts = explode('/', $requiredField);
1500
+ $field = $fieldParts[2];
1501
+ $group = $fieldParts[1];
1502
+
1503
+ /**
1504
+ * @var Varien_Simplexml_Element $sectionGroup
1505
+ */
1506
+ $sectionGroup = $section->groups->$group;
1507
+
1508
+ $label = (string) $sectionGroup->fields->$field->label;
1509
+ $groupLabel = (string) $sectionGroup->label;
1510
+ $groupName = $sectionGroup->getName();
1511
+
1512
+ if (!$format) {
1513
+ $format = '%s > %s is required.';
1514
+ }
1515
+ $message = $this->__($format, $this->__($groupLabel), $this->__($label));
1516
+
1517
+ if ($saveConfigState && $this->isSystemConfig()) {
1518
+ $this->saveConfigState(array('postnl_' . $groupName => 1));
1519
+ }
1520
+
1521
+ return $message;
1522
+ }
1523
+
1524
  /**
1525
  * Check if debug logging is enabled
1526
  *
1528
  */
1529
  public function isLoggingEnabled()
1530
  {
1531
+ if (version_compare(phpversion(), self::MIN_PHP_VERSION, '<')) {
1532
+ return false;
1533
+ }
1534
+
1535
  $debugMode = $this->getDebugMode();
1536
  if ($debugMode > 1) {
1537
  return true;
1547
  */
1548
  public function isExceptionLoggingEnabled()
1549
  {
1550
+ if (version_compare(phpversion(), self::MIN_PHP_VERSION, '<')) {
1551
+ return false;
1552
+ }
1553
+
1554
  $debugMode = $this->getDebugMode();
1555
  if ($debugMode > 0) {
1556
  return true;
1623
  * @param boolean $forced
1624
  * @param boolean $isError
1625
  *
1626
+ * @return $this
1627
  *
1628
  * @see Mage::log
1629
  */
1630
  public function log($message, $level = null, $file = null, $forced = false, $isError = false)
1631
  {
1632
+ if ($isError === true
1633
+ && !$this->isExceptionLoggingEnabled()
1634
+ && !$forced
1635
+ ) {
1636
  return $this;
1637
+ } elseif ($isError !== true
1638
+ && !$this->isLoggingEnabled()
1639
+ && !$forced
1640
+ ) {
1641
  return $this;
1642
  }
1643
 
1657
  }
1658
 
1659
  /**
1660
+ * Logs a cron debug message to a separate file in order to differentiate it from other debug messages.
1661
  *
1662
  * @param string $message
1663
  * @param int $level
1664
  *
1665
+ * @return $this
1666
  *
1667
  * @see Mage::log
1668
  */
1680
  *
1681
  * @param string|Exception $exception
1682
  *
1683
+ * @return $this
1684
  *
1685
  * @see Mage::logException
1686
  */
1742
  return true;
1743
  }
1744
 
 
 
 
 
 
 
 
 
1745
  return false;
1746
  }
1747
 
1788
  /**
1789
  * Creates a separate dir to log PostNL log files. Does nothing if the dir already exists.
1790
  *
1791
+ * @return $this
1792
  */
1793
  public function createLogDir()
1794
  {
1826
  * $session->addError() call.
1827
  *
1828
  * @param string|Mage_Core_Model_Session_Abstract $session The session to which the messages will be added.
1829
+ * @param Exception $exception
1830
  *
1831
+ * @return $this
1832
  *
1833
  * @see TIG_PostNL_Helper_Data::addSessionMessage()
1834
  */
1892
  * @param string|null $messageType
1893
  * @param string|null $message
1894
  *
1895
+ * @return $this
1896
  *
1897
  * @see Mage_Core_Model_Session_Abstract::addMessage()
1898
  *
1902
  public function addSessionMessage($session, $code = null, $messageType = null, $message = null)
1903
  {
1904
  /***************************************************************************************************************
1905
+ * Check that the required arguments are available and valid.
1906
  **************************************************************************************************************/
1907
 
1908
  /**
1909
+ * If $code is null or 0, $messageType and $message are required.
1910
  */
1911
  if (
1912
  (is_null($code) || $code === 0)
1918
  }
1919
 
1920
  /**
1921
+ * If the session is a string, treat it as a class name and instantiate it.
1922
  */
1923
  if (is_string($session) && strpos($session, '/') !== false) {
1924
  $session = Mage::getSingleton($session);
1927
  }
1928
 
1929
  /**
1930
+ * If the session could not be loaded or is not of the correct type, throw an exception.
1931
  */
1932
  if (!$session
1933
  || !is_object($session)
1939
  );
1940
  }
1941
 
1942
+ $errorMessage = $this->getSessionMessage($code, $messageType, $message);
1943
+
1944
+ /***************************************************************************************************************
1945
+ * Add the error to the session.
1946
+ **************************************************************************************************************/
1947
+
1948
+ /**
1949
+ * The method we'll use to add the message to the session has to be built first.
1950
+ */
1951
+ $addMethod = 'add' . ucfirst($messageType);
1952
+
1953
+ /**
1954
+ * If the method doesn't exist, throw an exception.
1955
+ */
1956
+ if (!method_exists($session, $addMethod)) {
1957
+ throw new TIG_PostNL_Exception(
1958
+ $this->__('Invalid message type requested: %s.', $messageType),
1959
+ 'POSTNL-0094'
1960
+ );
1961
+ }
1962
+
1963
+ /**
1964
+ * Add the message to the session.
1965
+ */
1966
+ $session->$addMethod($errorMessage);
1967
+
1968
+ return $this;
1969
+ }
1970
+
1971
+ /**
1972
+ * Formats a message string so it can be added as a session message.
1973
+ *
1974
+ * @param null|string $code
1975
+ * @param null|string $messageType
1976
+ * @param null|string $message
1977
+ *
1978
+ * @return string
1979
+ *
1980
+ * @throws TIG_PostNL_Exception
1981
+ * @throws InvalidArgumentException
1982
+ */
1983
+ public function getSessionMessage($code = null, $messageType = null, $message = null)
1984
+ {
1985
+ /**
1986
+ * If $code is null or 0, $messageType and $message are required.
1987
+ */
1988
+ if (
1989
+ (is_null($code) || $code === 0)
1990
+ && (is_null($messageType) || is_null($message))
1991
+ ) {
1992
+ throw new InvalidArgumentException(
1993
+ "Warning: Missing argument for addSessionMessage method: 'messageType' and 'message' are required."
1994
+ );
1995
+ }
1996
+
1997
  /***************************************************************************************************************
1998
+ * Get the actual error from config.xml if it's available.
1999
  **************************************************************************************************************/
2000
 
2001
  $error = false;
2017
  **************************************************************************************************************/
2018
 
2019
  /**
2020
+ * If the specified error was found and no message was supplied, get the error's default message.
2021
  */
2022
  if ($error && !$message) {
2023
  $message = (string) $error->message;
2024
  }
2025
 
2026
  /**
2027
+ * If we still don't have a valid message, throw an exception.
2028
  */
2029
  if (!$message) {
2030
  throw new TIG_PostNL_Exception(
2034
  }
2035
 
2036
  /**
2037
+ * If the specified error was found and no message type was supplied, get the error's default type.
2038
  */
2039
  if ($error && !$messageType) {
2040
  $messageType = (string) $error->type;
2042
 
2043
 
2044
  /**
2045
+ * If we still don't have a valid message type, throw an exception.
2046
  */
2047
  if (!$messageType) {
2048
  throw new TIG_PostNL_Exception(
2058
 
2059
  /**
2060
  * Flag that determines whether the error code and knowledgebase link will be included in the error message
2061
+ * (if available).
2062
  */
2063
  $canShowErrorDetails = $this->_canShowErrorDetails();
2064
 
2074
  }
2075
 
2076
  /**
2077
+ * Add the actual message. This is the only required part. The code and link are optional.
2078
  */
2079
  $errorMessage .= $this->__($message);
2080
 
2081
  /**
2082
+ * Add the link to the knowledgebase if we have one.
2083
  */
2084
  if ($canShowErrorDetails && $link) {
2085
  $errorMessage .= ' <a href="'
2086
+ . $link
2087
+ . '" target="_blank" class="postnl-message">'
2088
+ . $this->__('Click here for more information from the TiG knowledgebase.')
2089
+ . '</a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2090
  }
2091
 
2092
+ return $errorMessage;
 
 
 
 
 
2093
  }
2094
 
2095
  /**
2111
  * Check if the show_error_details_in_frontend setting is set to true
2112
  */
2113
  $storeId = Mage::app()->getStore()->getId();
2114
+ if (Mage::getStoreConfigFlag(self::XPATH_SHOW_ERROR_DETAILS_IN_FRONTEND, $storeId)) {
2115
  return true;
2116
  }
2117
 
app/code/community/TIG/PostNL/Helper/DeliveryOptions.php CHANGED
@@ -35,6 +35,9 @@
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
  {
@@ -49,25 +52,33 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
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 we consider to be the start of the evening.
@@ -114,20 +125,32 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
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
  }
@@ -137,61 +160,420 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
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
  /**
@@ -211,8 +593,10 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
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
 
@@ -244,20 +628,24 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
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
  /**
@@ -276,7 +664,8 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
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
  /**
@@ -354,26 +743,127 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
354
  * Checks if PakjeGemak is available.
355
  *
356
  * @param boolean $storeId
 
357
  *
358
  * @return boolean
359
  */
360
- public function canUsePakjeGemak($storeId = false)
361
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  $cache = $this->getCache();
363
 
364
  if ($cache && $cache->hasPostnlDeliveryOptionsCanUsePakjeGemak()) {
365
- return $cache->getPostnlDeliveryOptionsCanUsePakjeGemak();
 
 
 
 
 
 
366
  }
367
 
368
  $allowed = $this->_canUsePakjeGemak();
369
 
370
  if ($cache) {
 
 
 
371
  $cache->setPostnlDeliveryOptionsCanUsePakjeGemak($allowed)
372
  ->saveCache();
373
  }
 
 
374
  return $allowed;
375
  }
376
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  /**
378
  * Checks if PakjeGemak is available.
379
  *
@@ -383,11 +873,17 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
383
  {
384
  $storeId = Mage::app()->getStore()->getId();
385
 
 
 
 
386
  $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_PAKJEGEMAK, $storeId);
387
  if (!$enabled) {
388
  return false;
389
  }
390
 
 
 
 
391
  $allowed = parent::canUsePakjeGemak($storeId);
392
 
393
  return $allowed;
@@ -400,18 +896,55 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
400
  */
401
  public function canUsePakjeGemakExpress()
402
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  $cache = $this->getCache();
404
 
405
  if ($cache && $cache->hasPostnlDeliveryOptionsCanUsePakjeGemakExpress()) {
406
- return $cache->getPostnlDeliveryOptionsCanUsePakjeGemakExpress();
 
 
 
 
 
 
407
  }
408
 
409
  $allowed = $this->_canUsePakjeGemakExpress();
410
 
411
  if ($cache) {
 
 
 
412
  $cache->setPostnlDeliveryOptionsCanUsePakjeGemakExpress($allowed)
413
  ->saveCache();
414
  }
 
 
415
  return $allowed;
416
  }
417
 
@@ -424,15 +957,14 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
424
  {
425
  $storeId = Mage::app()->getStore()->getId();
426
 
427
- if (!$this->canUsePakjeGemak($storeId)) {
428
- return false;
429
- }
430
-
431
  $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_PAKJEGEMAK_EXPRESS, $storeId);
432
  if (!$enabled) {
433
  return false;
434
  }
435
 
 
 
 
436
  $pgeOptions = Mage::getModel('postnl_core/system_config_source_pakjeGemakProductOptions')
437
  ->getAvailablePgeOptions($storeId);
438
 
@@ -445,29 +977,131 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
445
  }
446
 
447
  /**
448
- * Checks if 'pakket automaat' is available.
 
 
449
  *
450
  * @return boolean
451
  */
452
- public function canUsePakketAutomaat()
453
  {
454
- $cache = $this->getCache();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455
 
456
  if ($cache && $cache->hasPostnlDeliveryOptionsCanUsePakketAutomaat()) {
457
- return $cache->getPostnlDeliveryOptionsCanUsePakketAutomaat();
 
 
 
 
 
 
458
  }
459
 
460
  $allowed = $this->_canUsePakketAutomaat();
461
 
462
  if ($cache) {
 
 
 
463
  $cache->setPostnlDeliveryOptionsCanUsePakketAutomaat($allowed)
464
  ->saveCache();
465
  }
 
 
466
  return $allowed;
467
  }
468
 
469
  /**
470
- * Checks if 'pakket automaat' is available.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
  *
472
  * @return boolean
473
  */
@@ -480,8 +1114,11 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
480
  return false;
481
  }
482
 
 
 
 
483
  $pakketautomaatOptions = Mage::getModel('postnl_core/system_config_source_pakketautomaatProductOptions')
484
- ->getAvailableOptions($storeId);
485
 
486
  $allowed = false;
487
  if (!empty($pakketautomaatOptions)) {
@@ -492,253 +1129,855 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
492
  }
493
 
494
  /**
495
- * Checks if timeframes are available.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  *
497
- * @return boolean
 
 
498
  */
499
- public function canUseTimeframes()
500
  {
501
- $cache = $this->getCache();
 
 
 
 
502
 
503
- if ($cache && $cache->hasPostnlDeliveryOptionsCanUseTimeframes()) {
504
- return $cache->getPostnlDeliveryOptionsCanUseTimeframes();
 
 
 
505
  }
506
 
507
- $storeId = Mage::app()->getStore()->getId();
 
 
 
 
 
 
 
508
 
509
- $allowed = Mage::getStoreConfigFlag(self::XPATH_ENABLE_TIMEFRAMES, $storeId);
 
 
 
510
 
511
- if ($cache) {
512
- $cache->setPostnlDeliveryOptionsCanUseTimeframes($allowed)
513
- ->saveCache();
514
- }
515
- return $allowed;
516
  }
517
 
518
  /**
519
- * Checks if evening timeframes are available.
520
  *
521
- * @return boolean
 
 
522
  */
523
- public function canUseEveningTimeframes()
524
  {
525
- $cache = $this->getCache();
 
 
 
 
526
 
527
- if ($cache && $cache->hasPostnlDeliveryOptionsCanUseEveningTimeframes()) {
528
- return $cache->getPostnlDeliveryOptionsCanUseEveningTimeframes();
 
 
 
529
  }
530
 
531
- $allowed = $this->_canUseEveningTimeframes();
 
 
 
 
 
 
532
 
533
- if ($cache) {
534
- $cache->setPostnlDeliveryOptionsCanUseEveningTimeframes($allowed)
535
- ->saveCache();
536
- }
537
- return $allowed;
538
  }
539
 
540
  /**
541
- * Checks if evening timeframes are available.
542
  *
543
- * @return boolean
 
 
544
  */
545
- protected function _canUseEveningTimeframes()
546
  {
547
- $storeId = Mage::app()->getStore()->getId();
 
 
 
 
548
 
549
- if (!$this->canUseTimeframes()) {
550
- return false;
 
 
 
551
  }
552
 
553
- $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_EVENING_TIMEFRAMES, $storeId);
554
- if (!$enabled) {
 
 
 
555
  return false;
556
  }
557
 
558
- $eveningOptions = Mage::getModel('postnl_core/system_config_source_standardProductOptions')
559
- ->getAvailableAvondOptions($storeId);
560
-
561
- $allowed = false;
562
- if (!empty($eveningOptions)) {
563
- $allowed = true;
564
- }
565
 
566
- return $allowed;
 
567
  }
568
 
569
  /**
570
- * Checks if sunday sorting is allowed.
 
 
 
 
571
  *
572
  * @return bool
573
  */
574
- public function canUseSundaySorting()
575
  {
576
- $cache = $this->getCache();
 
 
 
 
577
 
578
- if ($cache && $cache->hasPostnlDeliveryOptionsCanUseSundaySorting()) {
579
- return $cache->getPostnlDeliveryOptionsCanUseSundaySorting();
 
 
 
580
  }
581
 
582
- $storeId = Mage::app()->getStore()->getId();
583
-
584
- $allowed = Mage::getStoreConfigFlag(self::XPATH_ALLOW_SUNDAY_SORTING, $storeId);
 
 
 
 
585
 
586
- if ($cache) {
587
- $cache->setPostnlDeliveryOptionsCanUseSundaySorting($allowed)
588
- ->saveCache();
 
 
 
589
  }
590
 
591
- return $allowed;
 
 
 
 
 
 
 
 
 
592
  }
593
 
594
  /**
595
- * Check if PostNL delivery options may be used based on a quote.
 
 
596
  *
597
- * @param Mage_Sales_Model_Quote|boolean $quote
598
  *
599
- * @return boolean
600
  */
601
- public function canUseDeliveryOptions($quote = false)
602
  {
603
- $registryKey = 'can_use_delivery_options';
604
- if ($quote && $quote->getId()) {
605
- $registryKey .= '_quote_id_' . $quote->getId();
606
- }
607
-
608
- if (Mage::registry($registryKey) !== null) {
609
- return Mage::registry($registryKey);
610
- }
611
-
612
- Mage::unregister('postnl_delivery_options_can_use_delivery_options_errors');
613
-
614
- $deliveryOptionsEnabled = $this->isDeliveryOptionsEnabled();
615
- if (!$deliveryOptionsEnabled) {
616
- Mage::register($registryKey, false);
617
- return false;
618
- }
619
-
620
  /**
621
- * PostNL delivery options cannot be used for virtual orders
 
622
  */
623
- if ($quote && $quote->isVirtual()) {
624
- $errors = array(
625
- array(
626
- 'code' => 'POSTNL-0104',
627
- 'message' => $this->__('The quote is virtual.'),
628
- )
629
- );
630
- Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
631
- Mage::register($registryKey, false);
632
- return false;
633
- }
634
 
635
  /**
636
- * Check if the quote has a valid minimum amount
637
  */
638
- if ($quote && !$quote->validateMinimumAmount()) {
639
- $errors = array(
640
- array(
641
- 'code' => 'POSTNL-0105',
642
- 'message' => $this->__("The quote's grand total is below the minimum amount required."),
643
- )
644
- );
645
- Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
646
- Mage::register($registryKey, false);
647
- return false;
648
  }
649
 
650
  /**
651
- * Check that dutch addresses are allowed
652
  */
653
- if (!$this->canUseStandard()) {
654
- $errors = array(
655
- array(
656
- 'code' => 'POSTNL-0106',
657
- 'message' => $this->__(
658
- 'No standard product options are enabled. At least 1 option must be active.'
659
- ),
660
- )
661
- );
662
- Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
663
  Mage::register($registryKey, false);
664
  return false;
665
  }
666
 
667
  /**
668
- * If we have no quote, we have no further checks to perform.
669
  */
670
- if (!$quote) {
671
  Mage::register($registryKey, true);
672
  return true;
673
  }
674
 
675
- $storeId = $quote->getStoreId();
676
-
677
- /**
678
- * Check if PostNL delivery options may be used for 'letter' orders and if not, if the quote could fit in an
679
- * envelope.
680
- */
681
- $showDeliveryOptionsForLetters = Mage::getStoreConfigFlag(self::XPATH_SHOW_OPTIONS_FOR_LETTER, $storeId);
682
- if (!$showDeliveryOptionsForLetters) {
683
- $isLetterQuote = $this->quoteIsLetter($quote, $storeId);
684
- if ($isLetterQuote) {
685
- $errors = array(
686
- array(
687
- 'code' => 'POSTNL-0150',
688
- 'message' => $this->__(
689
- "The quote's total weight is below the miniumum required to use PostNL delivery options."
690
- ),
691
- )
692
- );
693
- Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
694
- Mage::register($registryKey, false);
695
- return false;
696
- }
697
- }
698
-
699
  /**
700
- * Check if PostNL delivery options may be used for out-og-stock orders and if not, whether the quote has any
701
- * such products.
702
  */
703
- $showDeliveryOptionsForBackorders = Mage::getStoreConfigFlag(self::XPATH_SHOW_OPTIONS_FOR_BACKORDERS, $storeId);
704
- if (!$showDeliveryOptionsForBackorders) {
705
- $containsOutOfStockItems = $this->quoteHasOutOfStockItems($quote);
706
- if ($containsOutOfStockItems) {
707
- $errors = array(
708
- array(
709
- 'code' => 'POSTNL-0102',
710
- 'message' => $this->__('One or more items in the cart are out of stock.'),
711
- )
712
- );
713
- Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
714
- Mage::register($registryKey, false);
715
- return false;
716
- }
717
- }
718
 
719
- Mage::register($registryKey, true);
720
- return true;
721
  }
722
 
723
  /**
724
- * Checks if the delivery options may be used for the currently chosen shipping destination.
 
 
725
  *
726
  * @param Mage_Sales_Model_Quote $quote
727
  *
728
- * @return boolean
729
  */
730
- public function canUseDeliveryOptionsForCountry(Mage_Sales_Model_Quote $quote)
731
  {
732
- $shippingAddress = $quote->getShippingAddress();
733
- if (!$shippingAddress) {
734
- return false;
 
 
 
 
 
 
 
 
735
  }
736
 
737
- if ($shippingAddress->getCountry() != 'NL') {
 
 
 
 
738
  return false;
739
  }
740
 
741
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
742
  }
743
 
744
  /**
@@ -750,6 +1989,9 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
750
  */
751
  public function isTestMode($storeId = false)
752
  {
 
 
 
753
  if (Mage::registry('delivery_options_test_mode') !== null) {
754
  return Mage::registry('delivery_options_test_mode');
755
  }
@@ -758,7 +2000,7 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
758
  $storeId = Mage::app()->getStore()->getId();
759
  }
760
 
761
- $testMode = Mage::getStoreConfigFlag(self::XML_PATH_TEST_MODE, $storeId);
762
 
763
  Mage::register('delivery_options_test_mode', $testMode);
764
  return $testMode;
@@ -773,19 +2015,50 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
773
  */
774
  public function isDeliveryOptionsEnabled($storeId = null)
775
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
776
  $cache = $this->getCache();
777
 
778
  if ($cache && $cache->hasPostnlDeliveryOptionsIsEnabled()) {
779
- return $cache->getPostnlDeliveryOptionsIsEnabled();
 
 
 
 
 
 
780
  }
781
 
 
 
 
782
  $isEnabled = $this->_isDeliveryOptionsEnabled($storeId);
783
 
784
  if ($cache) {
 
 
 
785
  $cache->setPostnlDeliveryOptionsIsEnabled($isEnabled)
786
  ->saveCache();
787
  }
788
 
 
789
  return $isEnabled;
790
  }
791
 
@@ -804,6 +2077,9 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
804
 
805
  Mage::unregister('postnl_delivery_options_is_enabled_errors');
806
 
 
 
 
807
  $isPostnlEnabled = $this->isEnabled($storeId);
808
  if ($isPostnlEnabled === false) {
809
  $errors = array(
@@ -816,6 +2092,9 @@ class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
816
  return false;
817
  }
818
 
 
 
 
819
  $isDeliveryOptionsActive = $this->isDeliveryOptionsActive($storeId);
820
  if (!$isDeliveryOptionsActive) {
821
  $errors = array(
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
+ * @todo Cache the available delivery options in the checkout session. That way we only recalculate them if the quote
40
+ * has changed.
41
  */
42
  class TIG_PostNL_Helper_DeliveryOptions extends TIG_PostNL_Helper_Checkout
43
  {
52
  const XPATH_ENABLE_PAKJEGEMAK = 'postnl/delivery_options/enable_pakjegemak';
53
  const XPATH_ENABLE_PAKJEGEMAK_EXPRESS = 'postnl/delivery_options/enable_pakjegemak_express';
54
  const XPATH_ENABLE_PAKKETAUTOMAAT_LOCATIONS = 'postnl/delivery_options/enable_pakketautomaat_locations';
55
+ const XPATH_ENABLE_DELIVERY_DAYS = 'postnl/delivery_options/enable_delivery_days';
56
  const XPATH_ENABLE_TIMEFRAMES = 'postnl/delivery_options/enable_timeframes';
57
  const XPATH_ENABLE_EVENING_TIMEFRAMES = 'postnl/delivery_options/enable_evening_timeframes';
58
 
59
  /**
60
  * Xpaths to various business rule settings.
61
  */
62
+ const XPATH_SHOW_OPTIONS_FOR_BACKORDERS = 'postnl/delivery_options/show_options_for_backorders';
63
+ const XPATH_ALLOW_SUNDAY_SORTING = 'postnl/cif_labels_and_confirming/allow_sunday_sorting';
64
+ const XPATH_SHOW_OPTIONS_FOR_BUSPAKJE = 'postnl/delivery_options/show_options_for_buspakje';
65
+ const XPATH_SHOW_ALL_OPTIONS_FOR_BUSPAKJE = 'postnl/delivery_options/show_all_options_for_buspakje';
66
+ const XPATH_ENABLE_DELIVERY_DAYS_FOR_BUSPAKJE = 'postnl/delivery_options/enable_delivery_days_for_buspakje';
67
+ const XPATH_ENABLE_PAKJEGEMAK_FOR_BUSPAKJE = 'postnl/delivery_options/enable_pakjegemak_for_buspakje';
68
+ const XPATH_ENABLE_PAKKETAUTOMAAT_FOR_BUSPAKJE = 'postnl/delivery_options/enable_pakketautomaat_for_buspakje';
69
 
70
  /**
71
  * Xpaths to extra fee config settings.
72
  */
73
  const XPATH_EVENING_TIMEFRAME_FEE = 'postnl/delivery_options/evening_timeframe_fee';
74
  const XPATH_PAKJEGEMAK_EXPRESS_FEE = 'postnl/delivery_options/pakjegemak_express_fee';
75
+
76
  /**
77
  * Xpath for shipping duration setting.
78
  */
79
+ const XPATH_SHIPPING_DURATION = 'postnl/cif_labels_and_confirming/shipping_duration';
80
+ const XPATH_CUTOFF_TIME = 'postnl/cif_labels_and_confirming/cutoff_time';
81
+ const XPATH_SUNDAY_CUTOFF_TIME = 'postnl/cif_labels_and_confirming/sunday_cutoff_time';
82
 
83
  /**
84
  * The time we consider to be the start of the evening.
125
  }
126
 
127
  /**
128
+ * Get the fee charged for evening time frames.
129
  *
130
  * @param boolean $formatted
131
  * @param boolean $includingTax
132
+ * @param boolean $convert
133
  *
134
  * @return float
135
  */
136
+ public function getEveningFee($formatted = false, $includingTax = true, $convert = true)
137
  {
138
  $storeId = Mage::app()->getStore()->getId();
139
 
140
  $eveningFee = (float) Mage::getStoreConfig(self::XPATH_EVENING_TIMEFRAME_FEE, $storeId);
141
 
142
+ $price = $this->getPriceWithTax($eveningFee, $includingTax, $formatted, false);
143
+
144
+ if ($price > 2) {
145
+ $price = 0;
146
+ }
147
+
148
+ if ($convert) {
149
+ $quote = $this->getQuote();
150
+ $store = $quote->getStore();
151
+
152
+ $price = $store->convertPrice($price, $formatted, false);
153
+ }
154
 
155
  return $price;
156
  }
160
  *
161
  * @param boolean $formatted
162
  * @param boolean $includingTax
163
+ * @param boolean $convert
164
  *
165
  * @return float
166
  */
167
+ public function getExpressFee($formatted = false, $includingTax = true, $convert = true)
168
  {
169
  $storeId = Mage::app()->getStore()->getId();
170
 
171
  $expressFee = (float) Mage::getStoreConfig(self::XPATH_PAKJEGEMAK_EXPRESS_FEE, $storeId);
172
 
173
+ $price = $this->getPriceWithTax($expressFee, $includingTax, $formatted, false);
174
+
175
+ if ($price > 2) {
176
+ $price = 0;
177
+ }
178
+
179
+ if ($convert) {
180
+ $quote = $this->getQuote();
181
+ $store = $quote->getStore();
182
+
183
+ $price = $store->convertPrice($price, $formatted, false);
184
+ }
185
 
186
  return $price;
187
  }
188
 
189
  /**
190
+ * Gets an array of info regarding chosen delivery options from a specified entity.
191
+ *
192
+ * @param Mage_Core_Model_Abstract $entity
193
+ * @param boolean $asVarienObject
194
+ *
195
+ * @return array|false
196
+ */
197
+ public function getDeliveryOptionsInfo(Mage_Core_Model_Abstract $entity, $asVarienObject = true)
198
+ {
199
+ $quoteId = false;
200
+ $orderId = false;
201
+ $postnlOrder = false;
202
+ $postnlShipment = false;
203
+
204
+ /**
205
+ * Depending on the type of entity we need to load the PostNL order using a different parameter.
206
+ */
207
+ if ($entity instanceof TIG_PostNL_Model_Core_Order) {
208
+ $postnlOrder = $entity;
209
+ } elseif ($entity instanceof TIG_PostNL_Model_Core_Shipment) {
210
+ $postnlOrder = $entity->getPostnlOrder();
211
+ $postnlShipment = $entity;
212
+ } elseif ($entity instanceof Mage_Sales_Model_Quote) {
213
+ $quoteId = $entity->getId();
214
+ } elseif ($entity instanceof Mage_Sales_Model_Order) {
215
+ $orderId = $entity->getId();
216
+ } elseif ($entity instanceof Mage_Sales_Model_Order_Invoice
217
+ || $entity instanceof Mage_Sales_Model_Order_Creditmemo
218
+ ) {
219
+ $orderId = $entity->getOrderId();
220
+ } elseif ($entity instanceof Mage_Sales_Model_Order_Shipment) {
221
+ $orderId = $entity->getOrderId();
222
+
223
+ $postnlShipment = Mage::getModel('postnl_core/shipment')->load($entity->getId(), 'shipment_id');
224
+ if (!$postnlShipment->getId()) {
225
+ $postnlShipment = false;
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Load the PostNL order if we don't already have it using either the order or quote ID.
231
+ */
232
+ if (!$postnlOrder && $quoteId) {
233
+ $postnlOrder = Mage::getModel('postnl_core/order')->load($quoteId, 'quote_id');
234
+ } elseif (!$postnlOrder && $orderId) {
235
+ $postnlOrder = Mage::getModel('postnl_core/order')->load($orderId, 'order_id');
236
+ }
237
+
238
+ /**
239
+ * If we still don't have a PostNL order nor a PostNL shipment return false as no info is available.
240
+ */
241
+ if (!$postnlOrder && !$postnlShipment) {
242
+ return false;
243
+ }
244
+
245
+ /**
246
+ * This is the basic, empty array of delivery options info.
247
+ */
248
+ $deliveryOptionsInfo = array(
249
+ 'type' => false,
250
+ 'shipment_type' => false,
251
+ 'formatted_type' => false,
252
+ 'product_code' => false,
253
+ 'product_option' => false,
254
+ 'shipment_costs' => false,
255
+ 'confirm_date' => false,
256
+ 'delivery_date' => false,
257
+ 'pakje_gemak_address' => false,
258
+ 'confirm_status' => false,
259
+ 'shipping_phase' => false,
260
+ 'formatted_shipping_phase' => false,
261
+ );
262
+
263
+ /**
264
+ * If this was a PakjeGemak order, we need to add the PakjeGemak address.
265
+ */
266
+ $pakjeGemakAddress = $postnlOrder->getPakjeGemakAddress();
267
+ if ($pakjeGemakAddress) {
268
+ $deliveryOptionsInfo['pakje_gemak_address'] = $pakjeGemakAddress->getData();
269
+ }
270
+
271
+ /**
272
+ * If the order had any additional fees, we need to add them as well.
273
+ */
274
+ $shipmentCosts = $postnlOrder->getShipmentCosts();
275
+ if ($shipmentCosts) {
276
+ $deliveryOptionsInfo['shipment_costs'] = $shipmentCosts;
277
+ }
278
+
279
+ /**
280
+ * If we have a PostNL shipment, we can get some accurate data from it. Otherwise we need to get it from the
281
+ * PostNL order.
282
+ *
283
+ * @var TIG_PostNL_Model_Core_Order $postnlOrder
284
+ */
285
+ if ($postnlShipment) {
286
+ /**
287
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipment
288
+ */
289
+ $type = $postnlShipment->getShipmentType();
290
+ $deliveryOptionsInfo['shipment_type'] = $type;
291
+
292
+ /**
293
+ * Confirm status and shipping phase are only known if the supplied entity was a shipment.
294
+ */
295
+ $confirmStatus = $postnlShipment->getConfirmStatus();
296
+ $shippingPhase = $postnlShipment->getShippingPhase();
297
+
298
+ if ($confirmStatus) {
299
+ $deliveryOptionsInfo['confirm_status'] = $confirmStatus;
300
+ }
301
+
302
+ if ($shippingPhase) {
303
+ /**
304
+ * Get the string representation of the shipping phase.
305
+ */
306
+ $formattedShippingPhase = $postnlShipment->getFormattedShippingPhase();
307
+
308
+ $deliveryOptionsInfo['shipping_phase'] = $shippingPhase;
309
+ $deliveryOptionsInfo['formatted_shipping_phase'] = $formattedShippingPhase;
310
+ }
311
+
312
+ $deliveryDate = $postnlShipment->getDeliveryDate();
313
+ $confirmDate = $postnlShipment->getConfirmDate();
314
+ $productCode = $postnlShipment->getProductCode();
315
+ } else {
316
+ $type = $postnlOrder->getType();
317
+ $deliveryOptionsInfo['type'] = $type;
318
+
319
+ $deliveryDate = $postnlOrder->getDeliveryDate();
320
+ $confirmDate = $postnlOrder->getConfirmDate();
321
+ $productCode = $postnlOrder->getProductCode();
322
+ }
323
+
324
+ /**
325
+ * Add the delivery date.
326
+ */
327
+ if ($deliveryDate) {
328
+ $deliveryOptionsInfo['delivery_date'] = $deliveryDate;
329
+ }
330
+
331
+ /**
332
+ * Add the confirm date.
333
+ */
334
+ if ($confirmDate) {
335
+ $deliveryOptionsInfo['confirm_date'] = $confirmDate;
336
+ }
337
+
338
+ /**
339
+ * Add the product code.
340
+ */
341
+ if ($productCode) {
342
+ $deliveryOptionsInfo['product_code'] = $productCode;
343
+
344
+ $allProductOptions = Mage::getModel('postnl_core/system_config_source_allProductOptions')
345
+ ->getOptions(array(), true);
346
+
347
+ if (array_key_exists($productCode, $allProductOptions)) {
348
+ $deliveryOptionsInfo['product_option'] = $allProductOptions[$productCode];
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Determine the formatted order type.
354
+ */
355
+ switch ($type) {
356
+ case 'domestic':
357
+ case 'Overdag':
358
+ $deliveryOptionsInfo['formatted_type'] = 'Overdag';
359
+ break;
360
+ case 'domestic_cod':
361
+ $deliveryOptionsInfo['formatted_type'] = 'Overdag rembours';
362
+ break;
363
+ case 'avond':
364
+ case 'Avond':
365
+ $deliveryOptionsInfo['formatted_type'] = 'Avond';
366
+ break;
367
+ case 'avond_cod':
368
+ $deliveryOptionsInfo['formatted_type'] = 'Avond rembours';
369
+ break;
370
+ case 'pg':
371
+ case 'PG':
372
+ $deliveryOptionsInfo['formatted_type'] = 'PakjeGemak';
373
+ break;
374
+ case 'pg_cod':
375
+ $deliveryOptionsInfo['formatted_type'] = 'PakjeGemak rembours';
376
+ break;
377
+ case 'pge':
378
+ case 'PGE':
379
+ $deliveryOptionsInfo['formatted_type'] = 'PakjeGemak Express';
380
+ break;
381
+ case 'pge_cod':
382
+ $deliveryOptionsInfo['formatted_type'] = 'PakjeGemak Express rembours';
383
+ break;
384
+ case 'pa':
385
+ case 'PA':
386
+ $deliveryOptionsInfo['formatted_type'] = 'Pakketautomaat';
387
+ break;
388
+ case 'eps':
389
+ $deliveryOptionsInfo['formatted_type'] = 'EPS';
390
+ break;
391
+ case 'globalpack':
392
+ $deliveryOptionsInfo['formatted_type'] = 'GlobalPack';
393
+ break;
394
+ case 'buspakje':
395
+ $deliveryOptionsInfo['formatted_type'] = 'Brievenbuspakje';
396
+ break;
397
+ //no default
398
+ }
399
+
400
+ if ($asVarienObject) {
401
+ $deliveryOptionsInfo = new Varien_Object($deliveryOptionsInfo);
402
+ }
403
+
404
+ /**
405
+ * Return the data.
406
+ */
407
+ return $deliveryOptionsInfo;
408
+ }
409
+
410
+ /**
411
+ * Get the delivery date for a specified order date.
412
  *
413
  * @param null|string $orderDate
414
  * @param null|int $storeId
415
+ * @param boolean $asDays
416
  *
417
+ * @return bool|string|int
418
  */
419
+ public function getDeliveryDate($orderDate = null, $storeId = null, $asDays = false)
420
  {
421
+ if (!$orderDate) {
422
+ $orderDate = new DateTime(Mage::getModel('core/date')->date('Y-m-d H:i:s'));
423
  }
424
 
425
  if ($storeId === null) {
426
  $storeId = Mage::app()->getStore()->getId();
427
  }
428
 
429
+ if (is_string($orderDate)) {
430
+ $orderDate = new DateTime($orderDate);
431
+ }
432
+
433
+ /**
434
+ * Get the base shipping duration for this order.
435
+ */
436
  $shippingDuration = Mage::getStoreConfig(self::XPATH_SHIPPING_DURATION, $storeId);
437
+ $deliveryTime = clone $orderDate;
438
+ $deliveryTime->add(new DateInterval("P{$shippingDuration}D"));
439
+
440
+ /**
441
+ * Get the cut-off time. This is formatted as H:i:s.
442
+ */
443
+ $cutOffTime = Mage::getStoreConfig(self::XPATH_CUTOFF_TIME, $storeId);
444
+ $orderTime = $orderDate->format('His');
445
+
446
+ /**
447
+ * Check if the current time (as His) is greater than the cut-off time.
448
+ */
449
+ if ($orderTime > str_replace(':', '', $cutOffTime)) {
450
+ $deliveryTime->add(new DateInterval('P1D'));
451
+ $shippingDuration++;
452
+ }
453
+
454
+ /**
455
+ * Get the delivery day (1-7).
456
+ */
457
+ $deliveryDay = $deliveryTime->format('N');
458
 
459
+ /**
460
+ * If the delivery day is a monday, we need to make sure that sunday sorting is allowed. Otherwise delivery on a
461
+ * monday is not possible.
462
+ */
463
  if ($deliveryDay == 1 && !Mage::helper('postnl/deliveryOptions')->canUseSundaySorting()) {
464
+ $sundayCutOffTime = Mage::getStoreConfig(self::XPATH_SUNDAY_CUTOFF_TIME, $storeId);
465
+ if ($orderTime <= str_replace(':', '', $sundayCutOffTime)) {
466
+ $deliveryTime->add(new DateInterval('P1D'));
467
+ $shippingDuration++;
468
+ }
469
+ }
470
+
471
+ if ($asDays) {
472
+ return $shippingDuration;
473
  }
474
 
475
+ $deliveryDate = $deliveryTime->format('Y-m-d');
476
  return $deliveryDate;
477
  }
478
 
479
+ /**
480
+ * Get the first possible delivery date as determined by PostNL.
481
+ *
482
+ * @param string $postcode A valid Dutch postcode (4 numbers and 2 letters).
483
+ * @param bool|Mage_Sales_Model_Quote $quote
484
+ * @param bool $throwException
485
+ *
486
+ * @return bool|string
487
+ *
488
+ * @throws Exception
489
+ * @throws TIG_PostNL_Exception
490
+ */
491
+ public function getPostcodeDeliveryDate($postcode, $quote = false, $throwException = false)
492
+ {
493
+ /**
494
+ * Parse the postcode so it is fully uppercase and contains no spaces.
495
+ */
496
+ $postcode = str_replace(' ', '', strtoupper($postcode));
497
+
498
+ /**
499
+ * Validate the postcode.
500
+ */
501
+ $validator = new Zend_Validate_PostCode('nl_NL');
502
+ $isValid = $validator->isValid($postcode);
503
+ if (!$isValid && $throwException) {
504
+ throw new TIG_PostNL_Exception(
505
+ $this->__(
506
+ 'Invalid postcode supplied for GetDeliveryDate request: %s Postcodes may only contain 4 numbers '
507
+ . 'and 2 letters.',
508
+ $postcode
509
+ ),
510
+ 'POSTNL-0131'
511
+ );
512
+ } elseif (!$isValid) {
513
+ return false;
514
+ }
515
+
516
+ /**
517
+ * If no quote was specified, try to load the quote.
518
+ */
519
+ if (!$quote && $this->isAdmin()) {
520
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
521
+ } elseif(!$quote) {
522
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
523
+ }
524
+
525
+ if (!$quote) {
526
+ return false;
527
+ }
528
+
529
+ /**
530
+ * Send a SOAP request to PostNL to get the earliest possible delivery date.
531
+ */
532
+ try {
533
+ $cif = Mage::getModel('postnl_deliveryoptions/cif');
534
+ $response = $cif->setStoreId(Mage::app()->getStore()->getId())
535
+ ->getDeliveryDate($postcode, $quote);
536
+ } catch(Exception $e) {
537
+ $this->logException($e);
538
+
539
+ if ($this->_canShowErrorDetails()) {
540
+ $this->addExceptionSessionMessage('core/session', $e);
541
+ }
542
+
543
+ if ($throwException) {
544
+ throw $e;
545
+ }
546
+
547
+ return false;
548
+ }
549
+
550
+ return $response;
551
+ }
552
+
553
  /**
554
  * Gets the shipping duration for the specified quote.
555
  *
556
+ * @param bool|Mage_Sales_Model_Quote $quote
557
  *
558
+ * @return int|bool
559
  *
560
  * @throws TIG_PostNL_Exception
561
  */
562
+ public function getShippingDuration(Mage_Sales_Model_Quote $quote = null)
563
  {
564
+ /**
565
+ * If no quote was specified, try to load the quote.
566
+ */
567
+ if (!$quote && $this->isAdmin()) {
568
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
569
+ } elseif(!$quote) {
570
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
571
+ }
572
+
573
+ if (!$quote) {
574
+ return false;
575
+ }
576
+
577
  $storeId = $quote->getStoreId();
578
 
579
  /**
593
  /**
594
  * If the product has a specific shipping duration, add it to the array of durations.
595
  */
596
+ if ($product->hasData('postnl_shipping_duration')
597
+ && $product->getData('postnl_shipping_duration') !== ''
598
+ ) {
599
+ $durationArray[] = (int) $product->getData('postnl_shipping_duration');
600
  }
601
  }
602
 
628
  * @param float $price
629
  * @param boolean $includingTax
630
  * @param boolean $formatted
631
+ * @param boolean $convert
632
  *
633
  * @return float
634
  *
635
  * @see Mage_Checkout_Block_Onepage_Shipping_Method_Available::getShippingPrice()
636
  */
637
+ public function getPriceWithTax($price, $includingTax, $formatted = false, $convert = true)
638
  {
639
  $quote = $this->getQuote();
640
  $store = $quote->getStore();
641
 
642
  $shippingPrice = Mage::helper('tax')->getShippingPrice($price, $includingTax, $quote->getShippingAddress());
 
643
 
644
+ if ($convert) {
645
+ $shippingPrice = $store->convertPrice($shippingPrice, $formatted, false);
646
+ }
647
+
648
+ return $shippingPrice;
649
  }
650
 
651
  /**
664
  *
665
  * date('l') returns the full textual representation of the day of the week (Sunday through Saturday).
666
  */
667
+ $deliveryDate = new DateTime($deliveryDate);
668
+ $weekDay = $deliveryDate->format('l');
669
 
670
  foreach ($locations as &$location) {
671
  /**
743
  * Checks if PakjeGemak is available.
744
  *
745
  * @param boolean $storeId
746
+ * @param boolean $checkQuote
747
  *
748
  * @return boolean
749
  */
750
+ public function canUsePakjeGemak($storeId = false, $checkQuote = true)
751
  {
752
+ /**
753
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
754
+ * the registry.
755
+ */
756
+ $registryKey = 'can_use_pakje_gemak';
757
+
758
+ $quote = $this->getQuote();
759
+ if ($quote) {
760
+ $registryKey .= '_' . $quote->getId();
761
+ }
762
+
763
+ /**
764
+ * Check if the result of this method has been cached in the registry.
765
+ */
766
+ if (Mage::registry($registryKey) !== null) {
767
+ return Mage::registry($registryKey);
768
+ }
769
+
770
+ if ($checkQuote) {
771
+ /**
772
+ * Check if these options are allowed for this specific quote.
773
+ */
774
+ $canUseForQuote = $this->canUsePakjeGemakForQuote();
775
+
776
+ if (!$canUseForQuote) {
777
+ Mage::register($registryKey, false);
778
+ return false;
779
+ }
780
+ }
781
+
782
  $cache = $this->getCache();
783
 
784
  if ($cache && $cache->hasPostnlDeliveryOptionsCanUsePakjeGemak()) {
785
+ /**
786
+ * Check if the result of this method has been cached in the PostNL cache.
787
+ */
788
+ $allowed = $cache->getPostnlDeliveryOptionsCanUsePakjeGemak();
789
+
790
+ Mage::register($registryKey, $allowed);
791
+ return $allowed;
792
  }
793
 
794
  $allowed = $this->_canUsePakjeGemak();
795
 
796
  if ($cache) {
797
+ /**
798
+ * Save the result in the PostNL cache.
799
+ */
800
  $cache->setPostnlDeliveryOptionsCanUsePakjeGemak($allowed)
801
  ->saveCache();
802
  }
803
+
804
+ Mage::register($registryKey, $allowed);
805
  return $allowed;
806
  }
807
 
808
+ /**
809
+ * Check if PakjeGemak is allowed for the current quote.
810
+ *
811
+ * @return bool
812
+ */
813
+ public function canUsePakjeGemakForQuote()
814
+ {
815
+ /**
816
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
817
+ * the registry.
818
+ */
819
+ $quote = $this->getQuote();
820
+ if (!$quote) {
821
+ return true;
822
+ }
823
+
824
+ $registryKey = 'can_use_pakje_gemak_for_quote_' . $quote->getId();
825
+
826
+ /**
827
+ * Check if the result of this method has been cached in the registry.
828
+ */
829
+ if (Mage::registry($registryKey) !== null) {
830
+ return Mage::registry($registryKey);
831
+ }
832
+
833
+ /**
834
+ * If the current quote fits as a letter box parcel and the calculation mode is set to 'automatic', check if
835
+ * these options are available for letter box parcel orders.
836
+ */
837
+ if ($this->isBuspakjeConfigApplicableToQuote($quote)
838
+ && !$this->canShowPakjeGemakForBuspakje($quote)
839
+ ) {
840
+ Mage::register($registryKey, false);
841
+ return false;
842
+ }
843
+
844
+ /**
845
+ * Check if any products in the quote have explicitly disabled PakjeGemak locations.
846
+ *
847
+ * @var Mage_Sales_Model_Quote_item $item
848
+ */
849
+ $quoteItems = $quote->getAllItems();
850
+ foreach ($quoteItems as $item) {
851
+ $poLocationsAllowed = Mage::getResourceSingleton('postnl/catalog_product')->getAttributeRawValue(
852
+ $item->getProductId(),
853
+ 'postnl_allow_pakje_gemak',
854
+ $item->getStoreId()
855
+ );
856
+
857
+ if (!is_null($poLocationsAllowed) && !$poLocationsAllowed) {
858
+ Mage::register($registryKey, false);
859
+ return false;
860
+ }
861
+ }
862
+
863
+ Mage::register($registryKey, true);
864
+ return true;
865
+ }
866
+
867
  /**
868
  * Checks if PakjeGemak is available.
869
  *
873
  {
874
  $storeId = Mage::app()->getStore()->getId();
875
 
876
+ /**
877
+ * Check if PakjeGemak has ben enabled in the configuration.
878
+ */
879
  $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_PAKJEGEMAK, $storeId);
880
  if (!$enabled) {
881
  return false;
882
  }
883
 
884
+ /**
885
+ * The parent canUsePakjeGemak() method will check if any PakjeGemak product options are available.
886
+ */
887
  $allowed = parent::canUsePakjeGemak($storeId);
888
 
889
  return $allowed;
896
  */
897
  public function canUsePakjeGemakExpress()
898
  {
899
+ /**
900
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
901
+ * the registry.
902
+ */
903
+ $registryKey = 'can_use_pakje_gemak_express';
904
+
905
+ $quote = $this->getQuote();
906
+ if ($quote) {
907
+ $registryKey .= '_' . $quote->getId();
908
+ }
909
+
910
+ /**
911
+ * Check if the result of this method has been cached in the registry.
912
+ */
913
+ if (Mage::registry($registryKey) !== null) {
914
+ return Mage::registry($registryKey);
915
+ }
916
+
917
+ /**
918
+ * If PakjeGemak is not allowed, neither is PakjeGemak Express.
919
+ */
920
+ if (!$this->canUsePakjeGemak()) {
921
+ Mage::register($registryKey, false);
922
+ return false;
923
+ }
924
+
925
  $cache = $this->getCache();
926
 
927
  if ($cache && $cache->hasPostnlDeliveryOptionsCanUsePakjeGemakExpress()) {
928
+ /**
929
+ * Check if the result of this method has been cached in the PostNL cache.
930
+ */
931
+ $allowed = $cache->getPostnlDeliveryOptionsCanUsePakjeGemakExpress();
932
+
933
+ Mage::register($registryKey, $allowed);
934
+ return $allowed;
935
  }
936
 
937
  $allowed = $this->_canUsePakjeGemakExpress();
938
 
939
  if ($cache) {
940
+ /**
941
+ * Save the result in the PostNL cache.
942
+ */
943
  $cache->setPostnlDeliveryOptionsCanUsePakjeGemakExpress($allowed)
944
  ->saveCache();
945
  }
946
+
947
+ Mage::register($registryKey, $allowed);
948
  return $allowed;
949
  }
950
 
957
  {
958
  $storeId = Mage::app()->getStore()->getId();
959
 
 
 
 
 
960
  $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_PAKJEGEMAK_EXPRESS, $storeId);
961
  if (!$enabled) {
962
  return false;
963
  }
964
 
965
+ /**
966
+ * Check if any PGE product options are available.
967
+ */
968
  $pgeOptions = Mage::getModel('postnl_core/system_config_source_pakjeGemakProductOptions')
969
  ->getAvailablePgeOptions($storeId);
970
 
977
  }
978
 
979
  /**
980
+ * Checks if 'pakketautomaat' is available.
981
+ *
982
+ * @param boolean $checkQuote
983
  *
984
  * @return boolean
985
  */
986
+ public function canUsePakketAutomaat($checkQuote = true)
987
  {
988
+ /**
989
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
990
+ * the registry.
991
+ */
992
+ $registryKey = 'can_use_pakketautomaat';
993
+
994
+ $quote = $this->getQuote();
995
+ if ($quote) {
996
+ $registryKey .= '_' . $quote->getId();
997
+ }
998
+
999
+ /**
1000
+ * Check if the result of this method has been cached in the registry.
1001
+ */
1002
+ if (Mage::registry($registryKey) !== null) {
1003
+ return Mage::registry($registryKey);
1004
+ }
1005
+
1006
+ if ($checkQuote) {
1007
+ /**
1008
+ * Check if these options are allowed for this specific quote.
1009
+ */
1010
+ $canUseForQuote = $this->canUsePakketAutomaatForQuote();
1011
+
1012
+ if (!$canUseForQuote) {
1013
+ Mage::register($registryKey, false);
1014
+ return false;
1015
+ }
1016
+ }
1017
+
1018
+ $cache = $this->getCache();
1019
 
1020
  if ($cache && $cache->hasPostnlDeliveryOptionsCanUsePakketAutomaat()) {
1021
+ /**
1022
+ * Check if the result of this method has been cached in the PostNL cache.
1023
+ */
1024
+ $allowed = $cache->getPostnlDeliveryOptionsCanUsePakketAutomaat();
1025
+
1026
+ Mage::register($registryKey, $allowed);
1027
+ return $allowed;
1028
  }
1029
 
1030
  $allowed = $this->_canUsePakketAutomaat();
1031
 
1032
  if ($cache) {
1033
+ /**
1034
+ * Save the result in the PostNL cache.
1035
+ */
1036
  $cache->setPostnlDeliveryOptionsCanUsePakketAutomaat($allowed)
1037
  ->saveCache();
1038
  }
1039
+
1040
+ Mage::register($registryKey, $allowed);
1041
  return $allowed;
1042
  }
1043
 
1044
  /**
1045
+ * Check if 'pakketautomaat' is allowed for the current quote.
1046
+ *
1047
+ * @return bool
1048
+ */
1049
+ public function canUsePakketAutomaatForQuote()
1050
+ {
1051
+ /**
1052
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1053
+ * the registry.
1054
+ */
1055
+ $quote = $this->getQuote();
1056
+ if (!$quote) {
1057
+ return true;
1058
+ }
1059
+
1060
+ $registryKey = 'can_use_pakketautomaat_for_quote_' . $quote->getId();
1061
+
1062
+ /**
1063
+ * Check if the result of this method has been cached in the registry.
1064
+ */
1065
+ if (Mage::registry($registryKey) !== null) {
1066
+ return Mage::registry($registryKey);
1067
+ }
1068
+
1069
+ /**
1070
+ * If the current quote fits as a letter box parcel and the calculation mode is set to 'automatic', check if
1071
+ * these options are available for letter box parcel orders.
1072
+ */
1073
+ if ($this->isBuspakjeConfigApplicableToQuote($quote)
1074
+ && !$this->canShowPakketAutomaatForBuspakje($quote)
1075
+ ) {
1076
+ Mage::register($registryKey, false);
1077
+ return false;
1078
+ }
1079
+
1080
+ /**
1081
+ * Check if any product in the quote has explicitly disabled pakketautomaat.
1082
+ *
1083
+ * @var Mage_Sales_Model_Quote_item $item
1084
+ */
1085
+ $quoteItems = $quote->getAllItems();
1086
+ foreach ($quoteItems as $item) {
1087
+ $pakketautomaatAllowed = Mage::getResourceSingleton('postnl/catalog_product')->getAttributeRawValue(
1088
+ $item->getProductId(),
1089
+ 'postnl_allow_pakketautomaat',
1090
+ $item->getStoreId()
1091
+ );
1092
+
1093
+ if ($pakketautomaatAllowed === '0') {
1094
+ Mage::register($registryKey, false);
1095
+ return false;
1096
+ }
1097
+ }
1098
+
1099
+ Mage::register($registryKey, true);
1100
+ return true;
1101
+ }
1102
+
1103
+ /**
1104
+ * Checks if 'pakketautomaat' is available.
1105
  *
1106
  * @return boolean
1107
  */
1114
  return false;
1115
  }
1116
 
1117
+ /**
1118
+ * Check if any pakketautomaat product options are available.
1119
+ */
1120
  $pakketautomaatOptions = Mage::getModel('postnl_core/system_config_source_pakketautomaatProductOptions')
1121
+ ->getAvailableOptions();
1122
 
1123
  $allowed = false;
1124
  if (!empty($pakketautomaatOptions)) {
1129
  }
1130
 
1131
  /**
1132
+ * Checks if delivery days are available.
1133
+ *
1134
+ * @param bool $checkQuote
1135
+ *
1136
+ * @return bool
1137
+ */
1138
+ public function canUseDeliveryDays($checkQuote = true)
1139
+ {
1140
+ /**
1141
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1142
+ * the registry.
1143
+ */
1144
+ $registryKey = 'can_use_delivery_days';
1145
+
1146
+ $quote = $this->getQuote();
1147
+ if ($quote) {
1148
+ $registryKey .= '_' . $quote->getId();
1149
+ }
1150
+
1151
+ /**
1152
+ * Check if the result of this method has been cached in the registry.
1153
+ */
1154
+ if (Mage::registry($registryKey) !== null) {
1155
+ return Mage::registry($registryKey);
1156
+ }
1157
+
1158
+ if ($checkQuote) {
1159
+ /**
1160
+ * Check if these options are allowed for this specific quote.
1161
+ */
1162
+ $canUseForQuote = $this->canUseDeliveryDaysForQuote();
1163
+
1164
+ if (!$canUseForQuote) {
1165
+ Mage::register($registryKey, false);
1166
+ return false;
1167
+ }
1168
+ }
1169
+
1170
+ $cache = $this->getCache();
1171
+
1172
+ if ($cache && $cache->hasPostnlDeliveryOptionsCanUseDeliveryDays()) {
1173
+ /**
1174
+ * Check if the result of this method has been cached in the PostNL cache.
1175
+ */
1176
+ $allowed = $cache->getPostnlDeliveryOptionsCanUseDeliveryDays();
1177
+
1178
+ Mage::register($registryKey, $allowed);
1179
+ return $allowed;
1180
+ }
1181
+
1182
+ $storeId = Mage::app()->getStore()->getId();
1183
+
1184
+ $allowed = Mage::getStoreConfigFlag(self::XPATH_ENABLE_DELIVERY_DAYS, $storeId);
1185
+
1186
+ if ($cache) {
1187
+ /**
1188
+ * Save the result in the PostNL cache.
1189
+ */
1190
+ $cache->setPostnlDeliveryOptionsCanUseDeliveryDays($allowed)
1191
+ ->saveCache();
1192
+ }
1193
+
1194
+ Mage::register($registryKey, $allowed);
1195
+ return $allowed;
1196
+ }
1197
+
1198
+ /**
1199
+ * Check if delivery days are allowed for the current quote.
1200
+ *
1201
+ * @return bool
1202
+ */
1203
+ public function canUseDeliveryDaysForQuote()
1204
+ {
1205
+ /**
1206
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1207
+ * the registry.
1208
+ */
1209
+ $quote = $this->getQuote();
1210
+ if (!$quote) {
1211
+ return true;
1212
+ }
1213
+
1214
+ $registryKey = 'can_use_delivery_days_for_quote_' . $quote->getId();
1215
+
1216
+ /**
1217
+ * Check if the result of this method has been cached in the registry.
1218
+ */
1219
+ if (Mage::registry($registryKey) !== null) {
1220
+ return Mage::registry($registryKey);
1221
+ }
1222
+
1223
+ /**
1224
+ * If the current quote fits as a letter box parcel and the calculation mode is set to 'automatic', check if
1225
+ * these options are available for letter box parcel orders.
1226
+ */
1227
+ if ($this->isBuspakjeConfigApplicableToQuote($quote)
1228
+ && !$this->canShowDeliveryDaysForBuspakje($quote)
1229
+ ) {
1230
+ Mage::register($registryKey, false);
1231
+ return false;
1232
+ }
1233
+
1234
+ /**
1235
+ * @var Mage_Sales_Model_Quote_item $item
1236
+ */
1237
+ $quoteItems = $quote->getAllItems();
1238
+ foreach ($quoteItems as $item) {
1239
+ $deliveryDaysAllowed = Mage::getResourceSingleton('postnl/catalog_product')->getAttributeRawValue(
1240
+ $item->getProductId(),
1241
+ 'postnl_allow_delivery_days',
1242
+ $item->getStoreId()
1243
+ );
1244
+
1245
+ if ($deliveryDaysAllowed === '0') {
1246
+ Mage::register($registryKey, false);
1247
+ return false;
1248
+ }
1249
+ }
1250
+
1251
+ Mage::register($registryKey, true);
1252
+ return true;
1253
+ }
1254
+
1255
+ /**
1256
+ * Checks if time frames are available.
1257
+ *
1258
+ * @param boolean $checkQuote
1259
+ *
1260
+ * @return boolean
1261
+ */
1262
+ public function canUseTimeframes($checkQuote = true)
1263
+ {
1264
+ /**
1265
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1266
+ * the registry.
1267
+ */
1268
+ $registryKey = 'can_use_timeframes';
1269
+
1270
+ $quote = $this->getQuote();
1271
+ if ($quote) {
1272
+ $registryKey .= '_' . $quote->getId();
1273
+ }
1274
+
1275
+ /**
1276
+ * Check if the result of this method has been cached in the registry.
1277
+ */
1278
+ if (Mage::registry($registryKey) !== null) {
1279
+ return Mage::registry($registryKey);
1280
+ }
1281
+
1282
+ if (!$this->canUseDeliveryDays()) {
1283
+ Mage::register($registryKey, false);
1284
+ return false;
1285
+ }
1286
+
1287
+ if ($checkQuote) {
1288
+ /**
1289
+ * Check if these options are allowed for this specific quote.
1290
+ */
1291
+ $canUseForQuote = $this->canUseTimeframesForQuote();
1292
+
1293
+ if (!$canUseForQuote) {
1294
+ Mage::register($registryKey, false);
1295
+ return false;
1296
+ }
1297
+ }
1298
+
1299
+ $cache = $this->getCache();
1300
+
1301
+ if ($cache && $cache->hasPostnlDeliveryOptionsCanUseTimeframes()) {
1302
+ /**
1303
+ * Check if the result of this method has been cached in the PostNL cache.
1304
+ */
1305
+ $allowed = $cache->getPostnlDeliveryOptionsCanUseTimeframes();
1306
+
1307
+ Mage::register($registryKey, $allowed);
1308
+ return $allowed;
1309
+ }
1310
+
1311
+ if ($quote) {
1312
+ $storeId = $quote->getStoreId();
1313
+ } else {
1314
+ $storeId = Mage::app()->getStore()->getId();
1315
+ }
1316
+
1317
+ $allowed = Mage::getStoreConfigFlag(self::XPATH_ENABLE_TIMEFRAMES, $storeId);
1318
+
1319
+ if ($cache) {
1320
+ /**
1321
+ * Save the result in the PostNL cache.
1322
+ */
1323
+ $cache->setPostnlDeliveryOptionsCanUseTimeframes($allowed)
1324
+ ->saveCache();
1325
+ }
1326
+
1327
+ Mage::register($registryKey, $allowed);
1328
+ return $allowed;
1329
+ }
1330
+
1331
+ /**
1332
+ * Check if time frames are allowed for the current quote.
1333
+ *
1334
+ * @return bool
1335
+ */
1336
+ public function canUseTimeframesForQuote()
1337
+ {
1338
+ /**
1339
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1340
+ * the registry.
1341
+ */
1342
+ $quote = $this->getQuote();
1343
+ if (!$quote) {
1344
+ return true;
1345
+ }
1346
+
1347
+ $registryKey = 'can_use_timeframes_for_quote_' . $quote->getId();
1348
+
1349
+ /**
1350
+ * Check if the result of this method has been cached in the registry.
1351
+ */
1352
+ if (Mage::registry($registryKey) !== null) {
1353
+ return Mage::registry($registryKey);
1354
+ }
1355
+
1356
+ /**
1357
+ * If the current quote fits as a letter box parcel and the calculation mode is set to 'automatic', check if
1358
+ * these options are available for letter box parcel orders.
1359
+ */
1360
+ if ($this->isBuspakjeConfigApplicableToQuote($quote)
1361
+ && !$this->canShowAllDeliveryOptionsForBuspakje($quote)
1362
+ ) {
1363
+ Mage::register($registryKey, false);
1364
+ return false;
1365
+ }
1366
+
1367
+ /**
1368
+ * @var Mage_Sales_Model_Quote_item $item
1369
+ */
1370
+ $quoteItems = $quote->getAllItems();
1371
+ foreach ($quoteItems as $item) {
1372
+ $timeframesAllowed = Mage::getResourceSingleton('postnl/catalog_product')->getAttributeRawValue(
1373
+ $item->getProductId(),
1374
+ 'postnl_allow_timeframes',
1375
+ $item->getStoreId()
1376
+ );
1377
+
1378
+ if ($timeframesAllowed === '0') {
1379
+ Mage::register($registryKey, false);
1380
+ return false;
1381
+ }
1382
+ }
1383
+
1384
+ Mage::register($registryKey, true);
1385
+ return true;
1386
+ }
1387
+
1388
+ /**
1389
+ * Checks if evening time frames are available.
1390
+ *
1391
+ * @return boolean
1392
+ */
1393
+ public function canUseEveningTimeframes()
1394
+ {
1395
+ /**
1396
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1397
+ * the registry.
1398
+ */
1399
+ $registryKey = 'can_use_evening_timeframes';
1400
+
1401
+ $quote = $this->getQuote();
1402
+ if ($quote) {
1403
+ $registryKey .= '_' . $quote->getId();
1404
+ }
1405
+
1406
+ /**
1407
+ * Check if the result of this method has been cached in the registry.
1408
+ */
1409
+ if (Mage::registry($registryKey) !== null) {
1410
+ return Mage::registry($registryKey);
1411
+ }
1412
+
1413
+ if (!$this->canUseTimeframes()) {
1414
+ Mage::register($registryKey, false);
1415
+ return false;
1416
+ }
1417
+
1418
+ $cache = $this->getCache();
1419
+
1420
+ if ($cache && $cache->hasPostnlDeliveryOptionsCanUseEveningTimeframes()) {
1421
+ /**
1422
+ * Check if the result of this method has been cached in the PostNL cache.
1423
+ */
1424
+ $allowed = $cache->getPostnlDeliveryOptionsCanUseEveningTimeframes();
1425
+
1426
+ Mage::register($registryKey, $allowed);
1427
+ return $allowed;
1428
+ }
1429
+
1430
+ $allowed = $this->_canUseEveningTimeframes();
1431
+
1432
+ if ($cache) {
1433
+ /**
1434
+ * Save the result in the PostNL cache.
1435
+ */
1436
+ $cache->setPostnlDeliveryOptionsCanUseEveningTimeframes($allowed)
1437
+ ->saveCache();
1438
+ }
1439
+
1440
+ Mage::register($registryKey, $allowed);
1441
+ return $allowed;
1442
+ }
1443
+
1444
+ /**
1445
+ * Checks if evening time frames are available.
1446
+ *
1447
+ * @return boolean
1448
+ */
1449
+ protected function _canUseEveningTimeframes()
1450
+ {
1451
+ $storeId = Mage::app()->getStore()->getId();
1452
+
1453
+ $enabled = Mage::getStoreConfigFlag(self::XPATH_ENABLE_EVENING_TIMEFRAMES, $storeId);
1454
+ if (!$enabled) {
1455
+ return false;
1456
+ }
1457
+
1458
+ $eveningOptions = Mage::getModel('postnl_core/system_config_source_standardProductOptions')
1459
+ ->getAvailableAvondOptions($storeId);
1460
+
1461
+ $allowed = false;
1462
+ if (!empty($eveningOptions)) {
1463
+ $allowed = true;
1464
+ }
1465
+
1466
+ return $allowed;
1467
+ }
1468
+
1469
+ /**
1470
+ * Checks if sunday sorting is allowed.
1471
+ *
1472
+ * @return bool
1473
+ */
1474
+ public function canUseSundaySorting()
1475
+ {
1476
+ $cache = $this->getCache();
1477
+
1478
+ if ($cache && $cache->hasPostnlDeliveryOptionsCanUseSundaySorting()) {
1479
+ return $cache->getPostnlDeliveryOptionsCanUseSundaySorting();
1480
+ }
1481
+
1482
+ $storeId = Mage::app()->getStore()->getId();
1483
+
1484
+ $allowed = Mage::getStoreConfigFlag(self::XPATH_ALLOW_SUNDAY_SORTING, $storeId);
1485
+
1486
+ if ($cache) {
1487
+ /**
1488
+ * Save the result in the PostNL cache.
1489
+ */
1490
+ $cache->setPostnlDeliveryOptionsCanUseSundaySorting($allowed)
1491
+ ->saveCache();
1492
+ }
1493
+
1494
+ return $allowed;
1495
+ }
1496
+
1497
+ /**
1498
+ * Check if PostNL delivery options may be used based on a quote.
1499
+ *
1500
+ * @param Mage_Sales_Model_Quote|boolean $quote
1501
+ *
1502
+ * @return boolean
1503
+ */
1504
+ public function canUseDeliveryOptions($quote = false)
1505
+ {
1506
+ /**
1507
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1508
+ * the registry.
1509
+ */
1510
+ $registryKey = 'can_use_delivery_options';
1511
+ if ($quote && $quote->getId()) {
1512
+ $registryKey .= '_quote_id_' . $quote->getId();
1513
+ }
1514
+
1515
+ /**
1516
+ * Check if the result of this method has been cached in the registry.
1517
+ */
1518
+ if (Mage::registry($registryKey) !== null) {
1519
+ return Mage::registry($registryKey);
1520
+ }
1521
+
1522
+ Mage::unregister('postnl_delivery_options_can_use_delivery_options_errors');
1523
+
1524
+ $deliveryOptionsEnabled = $this->isDeliveryOptionsEnabled();
1525
+ if (!$deliveryOptionsEnabled) {
1526
+ Mage::register($registryKey, false);
1527
+ return false;
1528
+ }
1529
+
1530
+ /**
1531
+ * Check that dutch addresses are allowed
1532
+ */
1533
+ if (!$this->canUseStandard()) {
1534
+ $errors = array(
1535
+ array(
1536
+ 'code' => 'POSTNL-0106',
1537
+ 'message' => $this->__(
1538
+ 'No standard product options are enabled. At least 1 option must be active.'
1539
+ ),
1540
+ )
1541
+ );
1542
+ Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
1543
+ Mage::register($registryKey, false);
1544
+ return false;
1545
+ }
1546
+
1547
+ /**
1548
+ * If we have no quote, we have no further checks to perform.
1549
+ */
1550
+ if (!$quote) {
1551
+ Mage::register($registryKey, true);
1552
+ return true;
1553
+ }
1554
+
1555
+ $canUseDeliveryOptionsForQuote = $this->canUseDeliveryOptionsForQuote($quote);
1556
+
1557
+ Mage::register($registryKey, $canUseDeliveryOptionsForQuote);
1558
+ return $canUseDeliveryOptionsForQuote;
1559
+ }
1560
+
1561
+ /**
1562
+ * Check if delivery options are allowed for the specified quote.
1563
+ *
1564
+ * @param Mage_Sales_Model_Quote $quote
1565
+ *
1566
+ * @return bool
1567
+ */
1568
+ public function canUseDeliveryOptionsForQuote(Mage_Sales_Model_Quote $quote)
1569
+ {
1570
+ Mage::unregister('postnl_delivery_options_can_use_delivery_options_errors');
1571
+
1572
+ /**
1573
+ * PostNL delivery options cannot be used for virtual orders
1574
+ */
1575
+ if ($quote->isVirtual()) {
1576
+ $errors = array(
1577
+ array(
1578
+ 'code' => 'POSTNL-0104',
1579
+ 'message' => $this->__('The quote is virtual.'),
1580
+ )
1581
+ );
1582
+ Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
1583
+ return false;
1584
+ }
1585
+
1586
+ /**
1587
+ * Check if the quote has a valid minimum amount
1588
+ */
1589
+ if (!$quote->validateMinimumAmount()) {
1590
+ $errors = array(
1591
+ array(
1592
+ 'code' => 'POSTNL-0105',
1593
+ 'message' => $this->__("The quote's grand total is below the minimum amount required."),
1594
+ )
1595
+ );
1596
+ Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
1597
+ return false;
1598
+ }
1599
+
1600
+ /**
1601
+ * Check if the current quote is a letter box parcel order and if so, if delivery options are allowed for letter
1602
+ * box parcel orders.
1603
+ */
1604
+ if ($this->isBuspakjeConfigApplicableToQuote($quote)
1605
+ && !$this->canShowDeliveryOptionsForBuspakje($quote)
1606
+ ) {
1607
+ $errors = array(
1608
+ array(
1609
+ 'code' => 'POSTNL-0190',
1610
+ 'message' => $this->__('Delivery options are not allowed for letter box parcel orders.'),
1611
+ )
1612
+ );
1613
+ Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
1614
+ return false;
1615
+ }
1616
+
1617
+ $storeId = $quote->getStoreId();
1618
+
1619
+ /**
1620
+ * Check if PostNL delivery options may be used for out-og-stock orders and if not, whether the quote has any
1621
+ * such products.
1622
+ */
1623
+ $showDeliveryOptionsForBackorders = Mage::getStoreConfigFlag(self::XPATH_SHOW_OPTIONS_FOR_BACKORDERS, $storeId);
1624
+ if (!$showDeliveryOptionsForBackorders) {
1625
+ $containsOutOfStockItems = $this->quoteHasOutOfStockItems($quote);
1626
+ if ($containsOutOfStockItems) {
1627
+ $errors = array(
1628
+ array(
1629
+ 'code' => 'POSTNL-0102',
1630
+ 'message' => $this->__('One or more items in the cart are out of stock.'),
1631
+ )
1632
+ );
1633
+ Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
1634
+ return false;
1635
+ }
1636
+ }
1637
+
1638
+ /**
1639
+ * Check if the quote contains a product for which delivery options are not allowed.
1640
+ *
1641
+ * @var Mage_Sales_Model_Quote_Item $item
1642
+ */
1643
+ foreach ($quote->getAllVisibleItems() as $item) {
1644
+ $productId = $item->getProductId();
1645
+ $allowDeliveryOptions = Mage::getResourceSingleton('postnl/catalog_product')->getAttributeRawValue(
1646
+ $productId,
1647
+ 'postnl_allow_delivery_options',
1648
+ $item->getStoreId()
1649
+ );
1650
+
1651
+ if ($allowDeliveryOptions === '0') {
1652
+ $errors = array(
1653
+ array(
1654
+ 'code' => 'POSTNL-0161',
1655
+ 'message' => $this->__('Delivery options are not allowed for product #%s.', $productId),
1656
+ )
1657
+ );
1658
+ Mage::register('postnl_delivery_options_can_use_delivery_options_errors', $errors);
1659
+ return false;
1660
+ }
1661
+ }
1662
+
1663
+ return true;
1664
+ }
1665
+
1666
+ /**
1667
+ * Checks if the delivery options may be used for the currently chosen shipping destination.
1668
+ *
1669
+ * @param Mage_Sales_Model_Quote $quote
1670
+ *
1671
+ * @return boolean
1672
+ */
1673
+ public function canUseDeliveryOptionsForCountry(Mage_Sales_Model_Quote $quote)
1674
+ {
1675
+ /**
1676
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1677
+ * the registry.
1678
+ */
1679
+ $registryKey = 'can_use_delivery_options_for_country_' . $quote->getId();
1680
+
1681
+ /**
1682
+ * Check if the result of this method has been cached in the registry.
1683
+ */
1684
+ if (Mage::registry($registryKey) !== null) {
1685
+ return Mage::registry($registryKey);
1686
+ }
1687
+
1688
+ /**
1689
+ * If no shipping address is available, we have nothing to check and delivery options will not be allowed.
1690
+ */
1691
+ $shippingAddress = $quote->getShippingAddress();
1692
+ if (!$shippingAddress) {
1693
+ Mage::register($registryKey, false);
1694
+ return false;
1695
+ }
1696
+
1697
+ /**
1698
+ * Delivery options are only available when shipping to the Netherlands.
1699
+ */
1700
+ if ($shippingAddress->getCountry() != 'NL') {
1701
+ Mage::register($registryKey, false);
1702
+ return false;
1703
+ }
1704
+
1705
+ Mage::register($registryKey, true);
1706
+ return true;
1707
+ }
1708
+
1709
+ /**
1710
+ * Checks if the buspakje-specific configuration is applicable to the current quote.
1711
  *
1712
+ * @param Mage_Sales_Model_Quote $quote
1713
+ *
1714
+ * @return bool
1715
  */
1716
+ public function isBuspakjeConfigApplicableToQuote(Mage_Sales_Model_Quote $quote)
1717
  {
1718
+ /**
1719
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1720
+ * the registry.
1721
+ */
1722
+ $registryKey = 'is_buspakje_config_applicable_to_quote_' . $quote->getId();
1723
 
1724
+ /**
1725
+ * Check if the result of this method has been cached in the registry.
1726
+ */
1727
+ if (Mage::registry($registryKey) !== null) {
1728
+ return Mage::registry($registryKey);
1729
  }
1730
 
1731
+ /**
1732
+ * If the buspakje calculation mode is set to 'manual', no further checks are required as the regular delivery
1733
+ * option rules will apply.
1734
+ */
1735
+ if ($this->getBuspakjeCalculationMode() != 'automatic') {
1736
+ Mage::register($registryKey, false);
1737
+ return false;
1738
+ }
1739
 
1740
+ /**
1741
+ * Check if the current quote would fit as a letter box parcel.
1742
+ */
1743
+ $quoteItems = $quote->getAllItems();
1744
 
1745
+ $fits = $this->fitsAsBuspakje($quoteItems);
1746
+
1747
+ Mage::register($registryKey, $fits);
1748
+ return $fits;
 
1749
  }
1750
 
1751
  /**
1752
+ * Checks if delivery options are disabled for letter box parcel orders.
1753
  *
1754
+ * @param Mage_Sales_Model_Quote $quote
1755
+ *
1756
+ * @return bool
1757
  */
1758
+ public function canShowDeliveryOptionsForBuspakje(Mage_Sales_Model_Quote $quote)
1759
  {
1760
+ /**
1761
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1762
+ * the registry.
1763
+ */
1764
+ $registryKey = 'can_show_options_for_buspakje_' . $quote->getId();
1765
 
1766
+ /**
1767
+ * Check if the result of this method has been cached in the registry.
1768
+ */
1769
+ if (Mage::registry($registryKey) !== null) {
1770
+ return Mage::registry($registryKey);
1771
  }
1772
 
1773
+ /**
1774
+ * Check if showing delivery options for letter box parcel orders is allowed in the configuration.
1775
+ */
1776
+ $showDeliveryOptions = Mage::getStoreConfigFlag(
1777
+ self::XPATH_SHOW_OPTIONS_FOR_BUSPAKJE,
1778
+ $quote->getStoreId()
1779
+ );
1780
 
1781
+ Mage::register($registryKey, $showDeliveryOptions);
1782
+ return $showDeliveryOptions;
 
 
 
1783
  }
1784
 
1785
  /**
1786
+ * Checks whether all delivery options are allowed for letter box parcel orders.
1787
  *
1788
+ * @param Mage_Sales_Model_Quote $quote
1789
+ *
1790
+ * @return bool
1791
  */
1792
+ public function canShowAllDeliveryOptionsForBuspakje(Mage_Sales_Model_Quote $quote)
1793
  {
1794
+ /**
1795
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1796
+ * the registry.
1797
+ */
1798
+ $registryKey = 'can_show_all_options_for_buspakje_' . $quote->getId();
1799
 
1800
+ /**
1801
+ * Check if the result of this method has been cached in the registry.
1802
+ */
1803
+ if (Mage::registry($registryKey) !== null) {
1804
+ return Mage::registry($registryKey);
1805
  }
1806
 
1807
+ /**
1808
+ * If we can't show any delivery options for letter box parcels, return false.
1809
+ */
1810
+ if (!$this->canShowDeliveryOptionsForBuspakje($quote)) {
1811
+ Mage::register($registryKey, false);
1812
  return false;
1813
  }
1814
 
1815
+ /**
1816
+ * Check if showing all delivery options is allowed in the configuration.
1817
+ */
1818
+ $canShowAllOptions = Mage::getStoreConfigFlag(
1819
+ self::XPATH_SHOW_ALL_OPTIONS_FOR_BUSPAKJE,
1820
+ $quote->getStoreId()
1821
+ );
1822
 
1823
+ Mage::register($registryKey, $canShowAllOptions);
1824
+ return $canShowAllOptions;
1825
  }
1826
 
1827
  /**
1828
+ * Determine whether delivery days are allowed for letter box parcel orders.This method will return true if the
1829
+ * buspakje calculation mode is set to manual, the order isn't a letter box parcel order or if all delivery options
1830
+ * are allowed for letter box parcel orders.
1831
+ *
1832
+ * @param Mage_Sales_Model_Quote $quote
1833
  *
1834
  * @return bool
1835
  */
1836
+ public function canShowDeliveryDaysForBuspakje(Mage_Sales_Model_Quote $quote)
1837
  {
1838
+ /**
1839
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1840
+ * the registry.
1841
+ */
1842
+ $registryKey = 'can_show_delivery_days_for_buspakje_' . $quote->getId();
1843
 
1844
+ /**
1845
+ * Check if the result of this method has been cached in the registry.
1846
+ */
1847
+ if (Mage::registry($registryKey) !== null) {
1848
+ return Mage::registry($registryKey);
1849
  }
1850
 
1851
+ /**
1852
+ * If we can't show any delivery options for letter box parcels, return false.
1853
+ */
1854
+ if (!$this->canShowDeliveryOptionsForBuspakje($quote)) {
1855
+ Mage::register($registryKey, false);
1856
+ return false;
1857
+ }
1858
 
1859
+ /**
1860
+ * If all delivery options are allowed for letter box parcels, return true.
1861
+ */
1862
+ if ($this->canShowAllDeliveryOptionsForBuspakje($quote)) {
1863
+ Mage::register($registryKey, true);
1864
+ return true;
1865
  }
1866
 
1867
+ /**
1868
+ * Check the configuration to see if delivery days are allowed for letter box parcels.
1869
+ */
1870
+ $deliveryDaysEnabledForBuspakje = Mage::getStoreConfigFlag(
1871
+ self::XPATH_ENABLE_DELIVERY_DAYS_FOR_BUSPAKJE,
1872
+ $quote->getStoreId()
1873
+ );
1874
+
1875
+ Mage::register($registryKey, $deliveryDaysEnabledForBuspakje);
1876
+ return $deliveryDaysEnabledForBuspakje;
1877
  }
1878
 
1879
  /**
1880
+ * Determine whether PakjeGemak locations (including parcel dispensers) are allowed for letter box parcel orders.
1881
+ * This method will return true if the buspakje calculation mode is set to manual, the order isn't a letter box
1882
+ * parcel order or if all delivery options are allowed for letter box parcel orders.
1883
  *
1884
+ * @param Mage_Sales_Model_Quote $quote
1885
  *
1886
+ * @return bool
1887
  */
1888
+ public function canShowPakjeGemakForBuspakje(Mage_Sales_Model_Quote $quote)
1889
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1890
  /**
1891
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1892
+ * the registry.
1893
  */
1894
+ $registryKey = 'can_show_pakje_gemak_for_buspakje_' . $quote->getId();
 
 
 
 
 
 
 
 
 
 
1895
 
1896
  /**
1897
+ * Check if the result of this method has been cached in the registry.
1898
  */
1899
+ if (Mage::registry($registryKey) !== null) {
1900
+ return Mage::registry($registryKey);
 
 
 
 
 
 
 
 
1901
  }
1902
 
1903
  /**
1904
+ * If we can't show any delivery options for letter box parcels, return false.
1905
  */
1906
+ if (!$this->canShowDeliveryOptionsForBuspakje($quote)) {
 
 
 
 
 
 
 
 
 
1907
  Mage::register($registryKey, false);
1908
  return false;
1909
  }
1910
 
1911
  /**
1912
+ * If all delivery options are allowed for letter box parcels, return true.
1913
  */
1914
+ if ($this->canShowAllDeliveryOptionsForBuspakje($quote)) {
1915
  Mage::register($registryKey, true);
1916
  return true;
1917
  }
1918
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1919
  /**
1920
+ * Check the configuration to see if PakjeGemak is allowed for letter box parcels.
 
1921
  */
1922
+ $pakjeGemakEnabledForBuspakje = Mage::getStoreConfigFlag(
1923
+ self::XPATH_ENABLE_PAKJEGEMAK_FOR_BUSPAKJE,
1924
+ $quote->getStoreId()
1925
+ );
 
 
 
 
 
 
 
 
 
 
 
1926
 
1927
+ Mage::register($registryKey, $pakjeGemakEnabledForBuspakje);
1928
+ return $pakjeGemakEnabledForBuspakje;
1929
  }
1930
 
1931
  /**
1932
+ * Determine whether PakjeGemak locations (including parcel dispensers) are allowed for letter box parcel orders.
1933
+ * This method will return true if the buspakje calculation mode is set to manual, the order isn't a letter box
1934
+ * parcel order or if all delivery options are allowed for letter box parcel orders.
1935
  *
1936
  * @param Mage_Sales_Model_Quote $quote
1937
  *
1938
+ * @return bool
1939
  */
1940
+ public function canShowPakketAutomaatForBuspakje(Mage_Sales_Model_Quote $quote)
1941
  {
1942
+ /**
1943
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
1944
+ * the registry.
1945
+ */
1946
+ $registryKey = 'can_show_pakketautomaat_for_buspakje_' . $quote->getId();
1947
+
1948
+ /**
1949
+ * Check if the result of this method has been cached in the registry.
1950
+ */
1951
+ if (Mage::registry($registryKey) !== null) {
1952
+ return Mage::registry($registryKey);
1953
  }
1954
 
1955
+ /**
1956
+ * If we can't show any delivery options for letter box parcels, return false.
1957
+ */
1958
+ if (!$this->canShowDeliveryOptionsForBuspakje($quote)) {
1959
+ Mage::register($registryKey, false);
1960
  return false;
1961
  }
1962
 
1963
+ /**
1964
+ * If all delivery options are allowed for letter box parcels, return true.
1965
+ */
1966
+ if ($this->canShowAllDeliveryOptionsForBuspakje($quote)) {
1967
+ Mage::register($registryKey, true);
1968
+ return true;
1969
+ }
1970
+
1971
+ /**
1972
+ * Check the configuration to see if 'pakketautomaat' is allowed for letter box parcels.
1973
+ */
1974
+ $pakketautomaatEnabledForBuspakje = Mage::getStoreConfigFlag(
1975
+ self::XPATH_ENABLE_PAKKETAUTOMAAT_FOR_BUSPAKJE,
1976
+ $quote->getStoreId()
1977
+ );
1978
+
1979
+ Mage::register($registryKey, $pakketautomaatEnabledForBuspakje);
1980
+ return $pakketautomaatEnabledForBuspakje;
1981
  }
1982
 
1983
  /**
1989
  */
1990
  public function isTestMode($storeId = false)
1991
  {
1992
+ /**
1993
+ * Check if the result of this method has been cached in the registry.
1994
+ */
1995
  if (Mage::registry('delivery_options_test_mode') !== null) {
1996
  return Mage::registry('delivery_options_test_mode');
1997
  }
2000
  $storeId = Mage::app()->getStore()->getId();
2001
  }
2002
 
2003
+ $testMode = Mage::getStoreConfigFlag(self::XPATH_TEST_MODE, $storeId);
2004
 
2005
  Mage::register('delivery_options_test_mode', $testMode);
2006
  return $testMode;
2015
  */
2016
  public function isDeliveryOptionsEnabled($storeId = null)
2017
  {
2018
+ /**
2019
+ * Form a unique registry key for the current quote (if available) so we can cache the result of this method in
2020
+ * the registry.
2021
+ */
2022
+ $registryKey = 'is_delivery_options_enabled';
2023
+
2024
+ $quote = $this->getQuote();
2025
+ if ($quote) {
2026
+ $registryKey .= '_' . $quote->getId();
2027
+ }
2028
+
2029
+ /**
2030
+ * Check if the result of this method has been cached in the registry.
2031
+ */
2032
+ if (Mage::registry($registryKey) !== null) {
2033
+ return Mage::registry($registryKey);
2034
+ }
2035
+
2036
  $cache = $this->getCache();
2037
 
2038
  if ($cache && $cache->hasPostnlDeliveryOptionsIsEnabled()) {
2039
+ /**
2040
+ * Check if the result of this method has been cached in the PostNL cache.
2041
+ */
2042
+ $allowed = $cache->getPostnlDeliveryOptionsIsEnabled();
2043
+
2044
+ Mage::register($registryKey, $allowed);
2045
+ return $allowed;
2046
  }
2047
 
2048
+ /**
2049
+ * Calculate if the delivery options are enabled.
2050
+ */
2051
  $isEnabled = $this->_isDeliveryOptionsEnabled($storeId);
2052
 
2053
  if ($cache) {
2054
+ /**
2055
+ * Save the result in the PostNL cache.
2056
+ */
2057
  $cache->setPostnlDeliveryOptionsIsEnabled($isEnabled)
2058
  ->saveCache();
2059
  }
2060
 
2061
+ Mage::register($registryKey, $isEnabled);
2062
  return $isEnabled;
2063
  }
2064
 
2077
 
2078
  Mage::unregister('postnl_delivery_options_is_enabled_errors');
2079
 
2080
+ /**
2081
+ * Check if the PostNL extension is enabled.
2082
+ */
2083
  $isPostnlEnabled = $this->isEnabled($storeId);
2084
  if ($isPostnlEnabled === false) {
2085
  $errors = array(
2092
  return false;
2093
  }
2094
 
2095
+ /**
2096
+ * Check if delivery options have been enabled in the config.
2097
+ */
2098
  $isDeliveryOptionsActive = $this->isDeliveryOptionsActive($storeId);
2099
  if (!$isDeliveryOptionsActive) {
2100
  $errors = array(
app/code/community/TIG/PostNL/Helper/Mijnpakket.php CHANGED
@@ -39,15 +39,36 @@
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
  *
@@ -95,22 +116,29 @@ class TIG_PostNL_Helper_Mijnpakket extends TIG_PostNL_Helper_Data
95
  }
96
 
97
  /**
98
- * Get initials based on a firstname.
99
  *
100
- * @param string $firstName
101
- *
102
- * @return string
103
  */
104
- public function getInitials($firstName)
105
  {
106
- $nameParts = preg_split("/\s+/", $firstName);
 
 
 
107
 
108
- $initials = '';
109
- foreach ($nameParts as $name) {
110
- $initials .= substr($name, 0, 1) . '.';
111
  }
112
 
113
- $initials = strtoupper($initials);
114
- return $initials;
 
 
 
 
 
 
 
115
  }
116
  }
39
  class TIG_PostNL_Helper_Mijnpakket extends TIG_PostNL_Helper_Data
40
  {
41
  /**
42
+ * Xpaths to MijnPakket settings.
43
  */
44
  const XPATH_MIJNPAKKET_LOGIN_ACTIVE = 'postnl/delivery_options/mijnpakket_login_active';
45
+ const XPATH_MIJNPAKKET_NOTIFICATION = 'postnl/delivery_options/mijnpakket_notification';
46
 
47
  /**
48
  * Log filename to log all non-specific PostNL debug messages.
49
  */
50
  const POSTNL_DEBUG_LOG_FILE = 'TIG_PostNL_MijnPakket_Debug.log';
51
 
52
+ /**
53
+ * Get initials based on a firstname.
54
+ *
55
+ * @param string $firstName
56
+ *
57
+ * @return string
58
+ */
59
+ public function getInitials($firstName)
60
+ {
61
+ $nameParts = preg_split("/\s+/", $firstName);
62
+
63
+ $initials = '';
64
+ foreach ($nameParts as $name) {
65
+ $initials .= substr($name, 0, 1) . '.';
66
+ }
67
+
68
+ $initials = strtoupper($initials);
69
+ return $initials;
70
+ }
71
+
72
  /**
73
  * Check whether MijnPakket login is active.
74
  *
116
  }
117
 
118
  /**
119
+ * Check if the MijnPakket notification may be shown.
120
  *
121
+ * @return bool
 
 
122
  */
123
+ public function canShowMijnpakketNotification()
124
  {
125
+ $cache = $this->getCache();
126
+ if ($cache && $cache->hasPostnlMijnpakketCanShowNotification()) {
127
+ return $cache->getPostnlMijnpakketCanShowNotification();
128
+ }
129
 
130
+ if (!Mage::helper('postnl/deliveryOptions')->canUseDeliveryOptions()) {
131
+ return false;
 
132
  }
133
 
134
+ $storeId = Mage::app()->getStore()->getId();
135
+ $canShowNotification = Mage::getStoreConfigFlag(self::XPATH_MIJNPAKKET_NOTIFICATION, $storeId);
136
+
137
+ if ($cache) {
138
+ $cache->setPostnlMijnpakketCanShowNotification($canShowNotification)
139
+ ->saveCache();
140
+ }
141
+
142
+ return $canShowNotification;
143
  }
144
  }
app/code/community/TIG/PostNL/Helper/Parcelware.php CHANGED
@@ -41,17 +41,17 @@ class TIG_PostNL_Helper_Parcelware extends TIG_PostNL_Helper_Data
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
@@ -75,7 +75,7 @@ class TIG_PostNL_Helper_Parcelware extends TIG_PostNL_Helper_Data
75
  *
76
  * @param boolean $autoConfirmEnabled
77
  *
78
- * @return TIG_PostNL_Helper_Parcelware
79
  */
80
  public function setAutoConfirmEnabled($autoConfirmEnabled)
81
  {
@@ -100,7 +100,7 @@ class TIG_PostNL_Helper_Parcelware extends TIG_PostNL_Helper_Data
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
 
@@ -115,6 +115,10 @@ class TIG_PostNL_Helper_Parcelware extends TIG_PostNL_Helper_Data
115
 
116
  /**
117
  * Check to see if Parcelware export functionality is enabled.
 
 
 
 
118
  */
119
  public function isParcelwareExportEnabled($storeId = null)
120
  {
@@ -122,7 +126,7 @@ class TIG_PostNL_Helper_Parcelware extends TIG_PostNL_Helper_Data
122
  $storeId = Mage::app()->getStore()->getId();
123
  }
124
 
125
- $active = Mage::getStoreConfigFlag(self::XML_PATH_ACTIVE, $storeId);
126
 
127
  return $active;
128
  }
@@ -138,7 +142,7 @@ class TIG_PostNL_Helper_Parcelware extends TIG_PostNL_Helper_Data
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;
41
  /**
42
  * XML path to auto confirm setting
43
  */
44
+ const XPATH_AUTO_CONFIRM = 'postnl/parcelware_export/auto_confirm';
45
 
46
  /**
47
  * XML path to the active/inactive setting
48
  */
49
+ const XPATH_ACTIVE = 'postnl/parcelware_export/active';
50
 
51
  /**
52
  * XML path to the customer code setting.
53
  */
54
+ const XPATH_CUSTOMER_CODE = 'postnl/cif/customer_code';
55
 
56
  /**
57
  * AutoConfirmEnabled flag
75
  *
76
  * @param boolean $autoConfirmEnabled
77
  *
78
+ * @return $this
79
  */
80
  public function setAutoConfirmEnabled($autoConfirmEnabled)
81
  {
100
 
101
  $type = substr($barcode, 0, 2);
102
 
103
+ $customerCode = (string) Mage::getStoreConfig(self::XPATH_CUSTOMER_CODE, $storeId);
104
 
105
  $number = substr($barcode, 2 + strlen($customerCode));
106
 
115
 
116
  /**
117
  * Check to see if Parcelware export functionality is enabled.
118
+ *
119
+ * @param int|null $storeId
120
+ *
121
+ * @return boolean
122
  */
123
  public function isParcelwareExportEnabled($storeId = null)
124
  {
126
  $storeId = Mage::app()->getStore()->getId();
127
  }
128
 
129
+ $active = Mage::getStoreConfigFlag(self::XPATH_ACTIVE, $storeId);
130
 
131
  return $active;
132
  }
142
  return $this->getAutoConfirmEnabled();
143
  }
144
 
145
+ $autoConfirmEnabled = Mage::getStoreConfigFlag(self::XPATH_AUTO_CONFIRM, Mage_Core_Model_App::ADMIN_STORE_ID);
146
 
147
  $this->setAutoConfirmEnabled($autoConfirmEnabled);
148
  return $autoConfirmEnabled;
app/code/community/TIG/PostNL/Helper/Payment.php ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @category TIG
37
+ * @package TIG_PostNL
38
+ * @copyright Copyright (c) 2014 Total Internet Group B.V. (http://www.totalinternetgroup.nl)
39
+ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
40
+ * @link http://store.totalinternetgroup.nl/tig/postnl.html
41
+ */
42
+ class TIG_PostNL_Helper_Payment extends TIG_PostNL_Helper_Data
43
+ {
44
+ /**
45
+ * Xpath to PostNL COD fee tax class.
46
+ */
47
+ const XPATH_COD_FEE_TAX_CLASS = 'tax/classes/postnl_cod_fee';
48
+
49
+ /**
50
+ * Xpath to PostNL COD fee label setting.
51
+ */
52
+ const XPATH_COD_FEE_LABEL = 'payment/postnl_cod/fee_label';
53
+
54
+ /**
55
+ * Debug log file for PostNL payments.
56
+ */
57
+ const POSTNL_DEBUG_LOG_FILE = 'TIG_PostNL_Payment_Debug.log';
58
+
59
+ /**
60
+ * An array of PostNL COD payment methods.
61
+ *
62
+ * @var array
63
+ */
64
+ protected $_codPaymentMethods = array(
65
+ 'postnl_cod',
66
+ );
67
+
68
+ /**
69
+ * Gets an array of PostNL COD payment methods.
70
+ *
71
+ * @return array
72
+ */
73
+ public function getCodPaymentMethods()
74
+ {
75
+ return $this->_codPaymentMethods;
76
+ }
77
+
78
+ /**
79
+ * Get the PostNL COD fee label for a given store.
80
+ *
81
+ * @param null|int|Mage_Core_Model_Store $store
82
+ *
83
+ * @return mixed
84
+ */
85
+ public function getPostnlCodFeeLabel($store = null)
86
+ {
87
+ if (is_null($store)) {
88
+ $store = Mage::app()->getStore();
89
+ }
90
+
91
+ $label = Mage::getStoreConfig(self::XPATH_COD_FEE_LABEL, $store);
92
+ return $label;
93
+ }
94
+
95
+ /**
96
+ * Add PostNL COD fee tax info to the full tax info array.
97
+ *
98
+ * This is a really annoying hack to fix the problem where the full tax info does not include the custom PostNL COD
99
+ * fee tax info. Magento only supports tax info from shipping tax or product tax by default
100
+ * (see Mage_Tax_Helper_Data::getCalculatedTaxes()). If anybody knows of a better way to fix this (that does not
101
+ * require a core rewrite) please let us know at servicedesk@totalinternetgroup.nl.
102
+ *
103
+ * @param array $fullInfo
104
+ * @param Mage_Sales_Model_Order|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $source
105
+ * @param Mage_Sales_Model_Order $order
106
+ *
107
+ * @return array
108
+ *
109
+ * @see Mage_Tax_Helper_Data::getCalculatedTaxes()
110
+ */
111
+ public function addPostnlCodFeeTaxInfo($fullInfo, $source, Mage_Sales_Model_Order $order)
112
+ {
113
+ $feeTax = (float) $order->getPostnlCodFeeTax();
114
+ if ($feeTax <= 0) {
115
+ return $fullInfo;
116
+ }
117
+
118
+ /**
119
+ * There are 3 possible ways to add the COD fee tax info:
120
+ * - Go through all tax info records of an order and add the COD fee info to the record with the same title and
121
+ * a discrepancy in the recorded and expected amount.
122
+ * - Add a missing tax info record.
123
+ * - Recalculate the tax info for the COD fee and update the amount of the tax record with the same title.
124
+ */
125
+ $orderClassName = Mage::getConfig()->getModelClassName('sales/order');
126
+ if ($source instanceof $orderClassName) {
127
+ $fullInfo = $this->_updateTaxAmountForTaxInfo($order, $fullInfo);
128
+ } else {
129
+ /**
130
+ * Try to find a tax record that does not have a corresponding tax item record.
131
+ */
132
+ $taxItemCollection = Mage::getResourceModel('tax/sales_order_tax_item_collection');
133
+ $taxItemCollection->addFieldToSelect('tax_id');
134
+ $taxItemCollection->getSelect()->distinct();
135
+
136
+ $taxItemIds = $taxItemCollection->getColumnValues('tax_id');
137
+
138
+ $taxCollection = Mage::getResourceModel('sales/order_tax_collection')
139
+ ->addFieldToFilter('order_id', array('eq' => $order->getId()))
140
+ ->addFieldToFilter('tax_id', array('nin' => $taxItemIds));
141
+
142
+ /**
143
+ * If we have found a missing record, we need to add it with the COD fee tax info. Otherwise we need to
144
+ * recreate the entire tax request for the COD fee tax so we can match the title to an existing tax item
145
+ * record.
146
+ */
147
+ if ($taxCollection->getSize()) {
148
+ $fullInfo = $this->_addPostnlCodFeeTaxInfoFromCollection($taxCollection, $fullInfo, $source);
149
+ } else {
150
+ $fullInfo = $this->_addPostnlCodFeeTaxInfoFromRequest($order, $fullInfo, $source);
151
+ }
152
+ }
153
+
154
+ return $fullInfo;
155
+ }
156
+
157
+ /**
158
+ * Add PostNL COD fee tax info by updating an incorrect tax record.
159
+ *
160
+ * @param Mage_Sales_Model_Order $order
161
+ * @param array $fullInfo
162
+ *
163
+ * @return array
164
+ */
165
+ protected function _updateTaxAmountForTaxInfo($order, $fullInfo)
166
+ {
167
+ $taxCollection = Mage::getResourceModel('sales/order_tax_collection')
168
+ ->addFieldToSelect('amount')
169
+ ->addFieldToFilter('order_id', array('eq' => $order->getId()));
170
+
171
+ /**
172
+ * Go through each tax record and update the tax info entry that has the same title, but a different amount.
173
+ */
174
+ foreach ($taxCollection as $tax) {
175
+ foreach ($fullInfo as $key => $taxInfo) {
176
+ if ($tax->getTitle() == $taxInfo['title'] && $tax->getAmount() != $taxInfo['tax_amount']) {
177
+ /**
178
+ * Update the amounts.
179
+ */
180
+ $fullInfo[$key]['tax_amount'] = $tax->getAmount();
181
+ $fullInfo[$key]['base_tax_amount'] = $tax->getBaseAmount();
182
+ }
183
+ }
184
+ }
185
+
186
+ return $fullInfo;
187
+ }
188
+
189
+ /**
190
+ * Add PostNL COD fee tax info by updating or adding a missing tax record.
191
+ *
192
+ * @param Mage_Sales_Model_Resource_Order_Tax_Collection $taxCollection
193
+ * @param array $fullInfo
194
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $source
195
+ *
196
+ * @return array
197
+ */
198
+ protected function _addPostnlCodFeeTaxInfoFromCollection($taxCollection, $fullInfo, $source)
199
+ {
200
+ /**
201
+ * Go through all tax records and add the COD fee tax to the entry that has the right title. If no entry exists
202
+ * with that title, add it.
203
+ */
204
+ foreach ($taxCollection as $tax) {
205
+ foreach ($fullInfo as $key => $taxInfo) {
206
+ /**
207
+ * Update an existing entry.
208
+ */
209
+ if ($taxInfo['title'] == $tax->getTitle()) {
210
+ $fullInfo[$key]['tax_amount'] += $source->getPostnlCodFeeTax();
211
+ $fullInfo[$key]['base_tax_amount'] += $source->getBasePostnlCodFeeTax();
212
+
213
+ break(2);
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Add a missing entry.
219
+ */
220
+ $fullInfo[] = array(
221
+ 'tax_amount' => $source->getPostnlCodFeeTax(),
222
+ 'base_tax_amount' => $source->getBasePostnlCodFeeTax(),
223
+ 'title' => $tax->getTitle(),
224
+ 'percent' => $tax->getPercent(),
225
+ );
226
+ }
227
+
228
+ return $fullInfo;
229
+ }
230
+
231
+ /**
232
+ * Add PostNL COD fee tax info by recreating the tax request.
233
+ *
234
+ * @param Mage_Sales_Model_Order $order
235
+ * @param array $fullInfo
236
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $source
237
+ *
238
+ * @return array
239
+ */
240
+ protected function _addPostnlCodFeeTaxInfoFromRequest($order, $fullInfo, $source)
241
+ {
242
+ $store = $order->getStore();
243
+ $taxCalculation = Mage::getSingleton('tax/calculation');
244
+
245
+ /**
246
+ * Recalculate the tax request.
247
+ */
248
+ $customerTaxClass = $order->getCustomerTaxClassId();
249
+ $shippingAddress = $order->getShippingAddress();
250
+ $billingAddress = $order->getBillingAddress();
251
+ $codTaxClass = Mage::getStoreConfig(self::XPATH_COD_FEE_TAX_CLASS, $store);
252
+
253
+ $taxRequest = $taxCalculation->getRateRequest(
254
+ $shippingAddress,
255
+ $billingAddress,
256
+ $customerTaxClass,
257
+ $store
258
+ );
259
+
260
+ $taxRequest->setProductClassId($codTaxClass);
261
+
262
+ /**
263
+ * If the tax request fails, there is nothing more we can do. This might occur, if the tax rules have been
264
+ * changed since this order was placed. Unfortunately there is nothing we can do about this.
265
+ */
266
+ if (!$taxRequest) {
267
+ return $fullInfo;
268
+ }
269
+
270
+ /**
271
+ * Get the applied rates.
272
+ */
273
+ $appliedRates = Mage::getSingleton('tax/calculation')
274
+ ->getAppliedRates($taxRequest);
275
+
276
+ if (!isset($appliedRates[0]['rates'][0]['title'])) {
277
+ return $fullInfo;
278
+ }
279
+
280
+ /**
281
+ * Get the tax title from the applied rates.
282
+ */
283
+ $postnlCodFeeTaxTitle = $appliedRates[0]['rates'][0]['title'];
284
+
285
+ /**
286
+ * Fo through all tax info entries and try to match the title.
287
+ */
288
+ foreach ($fullInfo as $key => $taxInfo) {
289
+ if ($taxInfo['title'] == $postnlCodFeeTaxTitle) {
290
+ /**
291
+ * Update the tax info entry with the COD fee tax.
292
+ */
293
+ $fullInfo[$key]['tax_amount'] += $source->getPostnlCodFeeTax();
294
+ $fullInfo[$key]['base_tax_amount'] += $source->getBasePostnlCodFeeTax();
295
+ break;
296
+ }
297
+ }
298
+
299
+ return $fullInfo;
300
+ }
301
+ }
app/code/community/TIG/PostNL/Helper/Webservices.php CHANGED
@@ -45,18 +45,18 @@ class TIG_PostNL_Helper_Webservices extends TIG_PostNL_Helper_Data
45
  /**
46
  * XML paths for security keys
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
@@ -87,12 +87,12 @@ class TIG_PostNL_Helper_Webservices extends TIG_PostNL_Helper_Data
87
  /**
88
  * If a website was specified, check if the module may send statistics for that website
89
  */
90
- $sendStatistics = $website->getConfig(self::XML_PATH_SEND_STATISTICS);
91
  } else {
92
  /**
93
  * otherwise, check if ending statistics was enabled in default settings
94
  */
95
- $sendStatistics = Mage::getStoreConfigFlag(self::XML_PATH_SEND_STATISTICS, $storeId);
96
  }
97
 
98
  if (!$sendStatistics) {
@@ -102,8 +102,8 @@ class TIG_PostNL_Helper_Webservices extends TIG_PostNL_Helper_Data
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;
@@ -121,7 +121,7 @@ class TIG_PostNL_Helper_Webservices extends TIG_PostNL_Helper_Data
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
  }
@@ -150,7 +150,7 @@ class TIG_PostNL_Helper_Webservices extends TIG_PostNL_Helper_Data
150
  *
151
  * @param Zend_Soap_Client $client
152
  *
153
- * @return TIG_PostNL_Helper_Webservices
154
  *
155
  * @see Mage::log()
156
  */
@@ -181,7 +181,7 @@ class TIG_PostNL_Helper_Webservices extends TIG_PostNL_Helper_Data
181
  *
182
  * @param Mage_Core_Exception|TIG_PostNL_Exception|SoapFault $exception
183
  *
184
- * @return TIG_PostNL_Helper_Webservices
185
  *
186
  * @see Mage::logException()
187
  */
45
  /**
46
  * XML paths for security keys
47
  */
48
+ const XPATH_EXTENSIONCONTROL_UNIQUE_KEY = 'postnl/general/unique_key';
49
+ const XPATH_EXTENSIONCONTROL_PRIVATE_KEY = 'postnl/general/private_key';
50
 
51
  /**
52
  * XML path to updateStatistics on/off switch
53
  */
54
+ const XPATH_SEND_STATISTICS = 'postnl/advanced/send_statistics';
55
 
56
  /**
57
  * XML path to receiveUpdates on/off switch
58
  */
59
+ const XPATH_RECEIVE_UPDATES = 'postnl/advanced/receive_updates';
60
 
61
  /**
62
  * Log filename to log all webservices exceptions
87
  /**
88
  * If a website was specified, check if the module may send statistics for that website
89
  */
90
+ $sendStatistics = $website->getConfig(self::XPATH_SEND_STATISTICS);
91
  } else {
92
  /**
93
  * otherwise, check if ending statistics was enabled in default settings
94
  */
95
+ $sendStatistics = Mage::getStoreConfigFlag(self::XPATH_SEND_STATISTICS, $storeId);
96
  }
97
 
98
  if (!$sendStatistics) {
102
  /**
103
  * Check if the security keys have been entered.
104
  */
105
+ $privateKey = Mage::getStoreConfig(self::XPATH_EXTENSIONCONTROL_PRIVATE_KEY, $storeId);
106
+ $uniqueKey = Mage::getStoreConfig(self::XPATH_EXTENSIONCONTROL_UNIQUE_KEY, $storeId);
107
 
108
  if (empty($privateKey) || empty($uniqueKey)) {
109
  return false;
121
  {
122
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
123
 
124
+ $receiveUpdates = Mage::getStoreConfigFlag(self::XPATH_RECEIVE_UPDATES, $storeId);
125
  if (!$receiveUpdates) {
126
  return false;
127
  }
150
  *
151
  * @param Zend_Soap_Client $client
152
  *
153
+ * @return $this
154
  *
155
  * @see Mage::log()
156
  */
181
  *
182
  * @param Mage_Core_Exception|TIG_PostNL_Exception|SoapFault $exception
183
  *
184
+ * @return $this
185
  *
186
  * @see Mage::logException()
187
  */
app/code/community/TIG/PostNL/Model/AddressValidation/Cendris.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_AddressValidation_Cendris extends TIG_PostNL_Model_AddressValidation_Cendris_Abstract
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 extends TIG_PostNL_Model_AddressValidation_Cendris_Abstract
app/code/community/TIG/PostNL/Model/AddressValidation/Observer/AddressBook.php CHANGED
@@ -73,7 +73,7 @@ class TIG_PostNL_Model_AddressValidation_Observer_AddressBook extends Varien_Obj
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
  *
73
  *
74
  * @param Varien_Event_Observer $observer
75
  *
76
+ * @return $this
77
  *
78
  * @event core_block_abstract_to_html_before
79
  *
app/code/community/TIG/PostNL/Model/AddressValidation/Observer/OneStepCheckout.php CHANGED
@@ -81,7 +81,7 @@ class TIG_PostNL_Model_AddressValidation_Observer_OneStepCheckout extends Varien
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
  *
81
  *
82
  * @param Varien_Event_Observer $observer
83
  *
84
+ * @return $this
85
  *
86
  * @event core_block_abstract_to_html_before
87
  *
app/code/community/TIG/PostNL/Model/AddressValidation/Observer/Onepage.php CHANGED
@@ -93,7 +93,7 @@ class TIG_PostNL_Model_AddressValidation_Observer_Onepage extends Varien_Object
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
  *
@@ -137,7 +137,7 @@ class TIG_PostNL_Model_AddressValidation_Observer_Onepage extends Varien_Object
137
  *
138
  * @param Varien_Event_Observer $observer
139
  *
140
- * @return TIG_PostNL_Model_AddressValidation_Observer_Onepage
141
  *
142
  * @event core_block_abstract_to_html_before
143
  *
93
  *
94
  * @param Varien_Event_Observer $observer
95
  *
96
+ * @return $this
97
  *
98
  * @event core_block_abstract_to_html_before
99
  *
137
  *
138
  * @param Varien_Event_Observer $observer
139
  *
140
+ * @return $this
141
  *
142
  * @event core_block_abstract_to_html_before
143
  *
app/code/community/TIG/PostNL/Model/Admin/Inbox.php ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * The only reason this class exists is because the add() method and it's derivatives are only present since EE 1.12 and
40
+ * CE 1.7. This class adds those methods in case they're missing. Each method will return it's parent if it exists to
41
+ * ensure forwards compatibility.
42
+ */
43
+ class TIG_PostNL_Model_Admin_Inbox extends Mage_AdminNotification_Model_Inbox
44
+ {
45
+ /**
46
+ * Add new message.
47
+ *
48
+ * @param int $severity
49
+ * @param string $title
50
+ * @param string|array $description
51
+ * @param string $url
52
+ * @param bool $isInternal
53
+ *
54
+ * @throws TIG_PostNL_Exception
55
+ *
56
+ * @return Mage_AdminNotification_Model_Inbox
57
+ */
58
+ public function add($severity, $title, $description, $url = '', $isInternal = true)
59
+ {
60
+ if ($this->_parentMethodExists($this, 'add')) {
61
+ return parent::add($severity, $title, $description, $url, $isInternal);
62
+ }
63
+
64
+ if (!$this->getSeverities($severity)) {
65
+ throw new TIG_PostNL_Exception(Mage::helper('postnl')->__('Wrong message type'), 'POSTNL-0087');
66
+ }
67
+
68
+ if (is_array($description)) {
69
+ $description = '<ul><li>' . implode('</li><li>', $description) . '</li></ul>';
70
+ }
71
+
72
+ $date = date('Y-m-d H:i:s');
73
+ $this->parse(
74
+ array(
75
+ array(
76
+ 'severity' => $severity,
77
+ 'date_added' => $date,
78
+ 'title' => $title,
79
+ 'description' => $description,
80
+ 'url' => $url,
81
+ 'internal' => $isInternal
82
+ )
83
+ )
84
+ );
85
+ return $this;
86
+ }
87
+
88
+ /**
89
+ * Add critical severity message.
90
+ *
91
+ * @param string $title
92
+ * @param string|array $description
93
+ * @param string $url
94
+ * @param bool $isInternal
95
+ *
96
+ * @return Mage_AdminNotification_Model_Inbox
97
+ */
98
+ public function addCritical($title, $description, $url = '', $isInternal = true)
99
+ {
100
+ if ($this->_parentMethodExists($this, 'addCritical')) {
101
+ return parent::addCritical($title, $description, $url, $isInternal);
102
+ }
103
+
104
+ $this->add(self::SEVERITY_CRITICAL, $title, $description, $url, $isInternal);
105
+ return $this;
106
+ }
107
+
108
+ /**
109
+ * Add major severity message.
110
+ *
111
+ * @param string $title
112
+ * @param string|array $description
113
+ * @param string $url
114
+ * @param bool $isInternal
115
+ *
116
+ * @return Mage_AdminNotification_Model_Inbox
117
+ */
118
+ public function addMajor($title, $description, $url = '', $isInternal = true)
119
+ {
120
+ if ($this->_parentMethodExists($this, 'addMajor')) {
121
+ return parent::addMajor($title, $description, $url, $isInternal);
122
+ }
123
+
124
+ $this->add(self::SEVERITY_MAJOR, $title, $description, $url, $isInternal);
125
+ return $this;
126
+ }
127
+
128
+ /**
129
+ * Add minor severity message.
130
+ *
131
+ * @param string $title
132
+ * @param string|array $description
133
+ * @param string $url
134
+ * @param bool $isInternal
135
+ *
136
+ * @return Mage_AdminNotification_Model_Inbox
137
+ */
138
+ public function addMinor($title, $description, $url = '', $isInternal = true)
139
+ {
140
+ if ($this->_parentMethodExists($this, 'addMinor')) {
141
+ return parent::addMinor($title, $description, $url, $isInternal);
142
+ }
143
+
144
+ $this->add(self::SEVERITY_MINOR, $title, $description, $url, $isInternal);
145
+ return $this;
146
+ }
147
+
148
+ /**
149
+ * Add notice.
150
+ *
151
+ * @param string $title
152
+ * @param string|array $description
153
+ * @param string $url
154
+ * @param bool $isInternal
155
+ *
156
+ * @return Mage_AdminNotification_Model_Inbox
157
+ */
158
+ public function addNotice($title, $description, $url = '', $isInternal = true)
159
+ {
160
+ if ($this->_parentMethodExists($this, 'addNotice')) {
161
+ return parent::addNotice($title, $description, $url, $isInternal);
162
+ }
163
+
164
+ $this->add(self::SEVERITY_NOTICE, $title, $description, $url, $isInternal);
165
+ return $this;
166
+ }
167
+
168
+ /**
169
+ * Checks parent class to see if the specified method exists.
170
+ *
171
+ * @param object $object
172
+ * @param string $method
173
+ *
174
+ * @return boolean
175
+ */
176
+ protected function _parentMethodExists($object, $method)
177
+ {
178
+ $parentClass = get_parent_class($object);
179
+ if ($parentClass === false) {
180
+ return false;
181
+ }
182
+
183
+ if (method_exists($parentClass, $method)) {
184
+ return true;
185
+ }
186
+
187
+ return false;
188
+ }
189
+ }
app/code/community/TIG/PostNL/Model/Admin/Logging/Handler/Postnl.php CHANGED
@@ -50,13 +50,17 @@ class TIG_PostNL_Model_Admin_Logging_Handler_Postnl extends Enterprise_Logging_M
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
  }
50
  {
51
  $request = Mage::app()->getRequest();
52
  if ($request->getParam('shipment_ids')) {
53
+ $eventModel->setInfo(
54
+ Mage::helper('enterprise_logging')->implodeValues($request->getParam('shipment_ids'))
55
+ );
56
 
57
  return true;
58
  }
59
 
60
  if ($request->getParam('order_ids')) {
61
+ $eventModel->setInfo(
62
+ Mage::helper('enterprise_logging')->implodeValues($request->getParam('order_ids'))
63
+ );
64
 
65
  return true;
66
  }
app/code/community/TIG/PostNL/Model/Adminhtml/Form/Element/Checkbox.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Adminhtml_Form_Element_Checkbox extends Varien_Data_Form_Element_Checkbox
40
+ {
41
+ /**
42
+ * Render a checkbox with an associated hidden field. This allows you to disable the checkbox while still
43
+ * transmitting it's value when submitting the form.
44
+ *
45
+ * @return string
46
+ */
47
+ public function getElementHtml()
48
+ {
49
+ $checked = $this->getChecked();
50
+ if ($checked) {
51
+ $this->setData('checked', true);
52
+ } else {
53
+ $this->unsetData('checked');
54
+ }
55
+
56
+ $html = '<input id="'.$this->getHtmlId().'" name="'.$this->getName()
57
+ .'" value="'.$this->getEscapedValue().'" type="hidden"/>'."\n";
58
+ $html .= '<input id="'.$this->getHtmlId().'_checkbox" name="'.$this->getName()
59
+ .'_checkbox" value="'.$this->getEscapedValue().'" '.$this->serialize($this->getHtmlAttributes()).'/>'."\n";
60
+
61
+ $html .= '<script type="text/javascript">' . PHP_EOL
62
+ . '//<![CDATA[' . PHP_EOL
63
+ . '$("'.$this->getHtmlId().'_checkbox").observe("click", '
64
+ . 'function(){$('.$this->getHtmlId().').setValue(this.getValue());});' . PHP_EOL
65
+ . '//]]>' . PHP_EOL
66
+ . '</script>';
67
+
68
+ $html.= $this->getAfterElementHtml();
69
+
70
+ return $html;
71
+ }
72
+
73
+ /**
74
+ * Render HTML for element's label
75
+ *
76
+ * @param string $idSuffix
77
+ * @return string
78
+ */
79
+ public function getLabelHtml($idSuffix = '')
80
+ {
81
+ if (!is_null($this->getLabel())) {
82
+ $html = '<label for="'.$this->getHtmlId() . $idSuffix . '_checkbox">' . $this->_escape($this->getLabel())
83
+ . ( $this->getRequired() ? ' <span class="required">*</span>' : '' ) . '</label>' . "\n";
84
+ } else {
85
+ $html = '';
86
+ }
87
+ return $html;
88
+ }
89
+ }
app/code/community/TIG/PostNL/Model/Adminhtml/Observer/OrderGrid.php CHANGED
@@ -68,12 +68,27 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
68
  /**
69
  * XML path to show_grid_options setting.
70
  */
71
- const XML_PATH_SHOW_OPTIONS = 'postnl/cif_labels_and_confirming/show_grid_options';
72
 
73
  /**
74
- * XML path to show shipment type column setting.
75
  */
76
- const XML_PATH_SHOW_SHIPMENT_TYPE_COLUMN = 'postnl/cif_labels_and_confirming/show_shipment_type_column';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  /**
79
  * Edits the sales order grid by adding a mass action to create shipments for selected orders.
@@ -118,7 +133,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
118
  * replace the collection, as the default collection has a bug preventing it from being reset.
119
  * Without being able to reset it, we can't edit it. Therefore we are forced to replace it altogether
120
  *
121
- * TODO see if this can be avoided in any way
122
  */
123
  $collection = Mage::getResourceModel('postnl/order_grid_collection');
124
  $collection->setSelect($select)
@@ -131,7 +146,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
131
  $this->_joinCollection($collection);
132
  $this->_modifyColumns($block);
133
  $this->_addColumns($block);
134
- $this->_applySortAndFilter($collection);
135
  $this->_addMassaction($block);
136
 
137
  $block->setCollection($collection);
@@ -139,7 +154,57 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
139
  }
140
 
141
  /**
142
- * Adds additional joins to the collection that will be used by newly added columns
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  *
144
  * @param TIG_PostNL_Model_Resource_Order_Grid_Collection $collection
145
  *
@@ -149,21 +214,45 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
149
  {
150
  $resource = Mage::getSingleton('core/resource');
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  $select = $collection->getSelect();
153
 
154
  /**
155
- * Join sales_flat_order table
156
  */
157
  $select->joinInner(
158
  array('order' => $resource->getTableName('sales/order')),
159
  '`main_table`.`entity_id`=`order`.`entity_id`',
160
  array(
161
- 'shipping_method' => 'order.shipping_method',
162
  )
163
  );
164
 
165
  /**
166
- * Join sales_flat_order_address table
 
 
 
 
 
 
 
 
 
 
 
167
  */
168
  $select->joinLeft(
169
  array('shipping_address' => $resource->getTableName('sales/order_address')),
@@ -174,7 +263,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
174
  );
175
 
176
  /**
177
- * Join tig_postnl_order table
178
  */
179
  $select->joinLeft(
180
  array('postnl_order' => $resource->getTableName('postnl_core/order')),
@@ -186,6 +275,37 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
186
  )
187
  );
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  return $this;
190
  }
191
 
@@ -268,13 +388,13 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
268
  {
269
  $helper = Mage::helper('postnl');
270
 
271
- $columnAttributes = array(
272
  'header' => $helper->__('Shipment type'),
273
  'align' => 'left',
274
  'index' => 'country_id',
275
  'type' => 'options',
276
- 'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_shipmentType',
277
- 'width' => '110px',
278
  'filter_condition_callback' => array($this, '_filterShipmentType'),
279
  'sortable' => false,
280
  'options' => array(
@@ -288,31 +408,334 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
288
  ),
289
  );
290
 
291
- $showShipmentTypeColumn = Mage::getStoreConfigFlag(
292
- self::XML_PATH_SHOW_SHIPMENT_TYPE_COLUMN,
293
- Mage_Core_Model_App::ADMIN_STORE_ID
294
- );
295
 
296
  /**
297
- * If we don't need to display the shipment type column, hide it. We'll still need it for some javascript functionality
 
298
  */
299
- if (!$showShipmentTypeColumn) {
300
- $columnAttributes['column_css_class'] = 'no-display';
301
- $columnAttributes['header_css_class'] = 'no-display';
302
- $columnAttributes['display'] = 'none';
303
  }
304
 
305
  $block->addColumnAfter(
306
  'country_id',
307
- $columnAttributes,
308
  'shipping_name'
309
  );
310
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  $block->sortColumnsByOrder();
312
 
313
  return $this;
314
  }
315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  /**
317
  * Adds a massaction to confirm the order and print the shipping labels
318
  *
@@ -325,58 +748,363 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
325
  $helper = Mage::helper('postnl');
326
 
327
  /**
328
- * Make sure the admin is allowed ship orders.
329
  */
330
- if (!$helper->checkIsPostnlActionAllowed('create_shipment')) {
331
- return $this;
 
 
 
 
 
 
 
 
 
332
  }
333
 
334
  /**
335
- * Build an array of options for the massaction item
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  */
337
  $massActionData = array(
338
  'label'=> $helper->__('PostNL - Create Shipments'),
339
  'url' => Mage::helper('adminhtml')->getUrl('postnl_admin/adminhtml_shipment/massCreateShipments'),
340
  );
341
 
342
- $showOptions = Mage::getStoreConfig(self::XML_PATH_SHOW_OPTIONS, Mage_Core_Model_App::ADMIN_STORE_ID);
 
 
 
 
 
 
 
343
 
344
  if ($showOptions) {
 
 
345
  /**
346
- * Add another dropdown containing the possible product options
 
347
  */
348
- $massActionData['additional'] = array(
349
- 'product_options' => array(
350
- 'name' => 'product_options',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  'type' => 'select',
352
  'class' => 'required-entry',
353
  'label' => $helper->__('Product options'),
354
- 'values' => Mage::getModel('postnl_core/system_config_source_allProductOptions')
355
- ->getAvailableOptions(true, true, false, false, false, true, true),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
  ),
357
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  }
359
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  /**
361
- * Add the massaction
362
  */
363
- $block->getMassactionBlock()
364
- ->addItem(
365
- 'create_shipments',
366
- $massActionData
367
- );
368
 
369
- return $this;
 
 
 
 
 
 
 
 
 
370
  }
371
 
372
  /**
373
  * Applies sorting and filtering to the collection
374
  *
375
- * @param TIG_PostNL_Model_Resource_Order_Grid_Collection $collection
376
- *
377
  * @return $this
378
  */
379
- protected function _applySortAndFilter($collection)
380
  {
381
  $session = Mage::getSingleton('adminhtml/session');
382
 
@@ -384,7 +1112,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
384
  $filter = Mage::helper('adminhtml')->prepareFilterString($filter);
385
 
386
  if ($filter) {
387
- $this->_filterCollection($collection, $filter);
388
  }
389
 
390
  $sort = $session->getData(self::ORDER_GRID_SORT_VAR_NAME);
@@ -392,7 +1120,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
392
  if ($sort) {
393
  $dir = $session->getData(self::ORDER_GRID_DIR_VAR_NAME);
394
 
395
- $this->_sortCollection($collection, $sort, $dir);
396
  }
397
 
398
  return $this;
@@ -401,18 +1129,21 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
401
  /**
402
  * Adds new filters to the collection if these filters are based on columns added by this observer
403
  *
404
- * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
405
- * @param array $filter Array of filters to be added
406
  *
407
  * @return $this
408
  */
409
- protected function _filterCollection($collection, $filter)
410
  {
411
  $block = $this->getBlock();
412
 
413
  foreach ($filter as $columnName => $value) {
414
  $column = $block->getColumn($columnName);
415
 
 
 
 
 
416
  $column->getFilter()->setValue($value);
417
  $this->_addColumnFilterToCollection($column);
418
  }
@@ -423,8 +1154,8 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
423
  /**
424
  * Filters the collection by the 'shipment_type' column. Th column has 3 options: domestic, EPS and GlobalPack.
425
  *
426
- * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
427
- * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
428
  *
429
  * @return $this
430
  */
@@ -434,10 +1165,22 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
434
  $filterCond = $cond['eq'];
435
 
436
  /**
437
- * First filter out all non-postnl orders
438
  */
439
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
440
- $collection->addFieldToFilter('order.shipping_method', array('in' => $postnlShippingMethods));
 
 
 
 
 
 
 
 
 
 
 
 
441
 
442
  /**
443
  * If the filter condition is PakjeGemak Express, filter out all non-PakjeGemak Express orders
@@ -461,7 +1204,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
461
  * If the filter condition is PakjeGemak, filter out all non-PakjeGemak orders
462
  */
463
  if ($filterCond == 'pakje_gemak') {
464
- $collection->addFieldToFilter('is_pakje_gemak', array('eq' => 1));
465
  $collection->addFieldToFilter('postnl_order.type', array(array('eq' => 'PG'), array('null' => true)));
466
 
467
  return $this;
@@ -471,7 +1214,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
471
  * If the filter condition is Pakket Automaat, filter out all non-Pakket Automaat orders
472
  */
473
  if ($filterCond == 'pakketautomaat') {
474
- $collection->addFieldToFilter('is_pakketautomaat', array('eq' => 1));
475
  $collection->addFieldToFilter(
476
  'postnl_order.type',
477
  array(
@@ -485,7 +1228,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
485
 
486
  /**
487
  * If the filter condition is NL, filter out all orders not being shipped to the Netherlands. PakjeGemak,
488
- * PakjeeGmak Express, evening delivery and pakketautomaat shipments are also shipped to the Netherlands so we
489
  * need to explicitly filter those as well.
490
  */
491
  if ($filterCond == 'nl') {
@@ -498,14 +1241,14 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
498
  )
499
  );
500
  $collection->addFieldToFilter(
501
- 'is_pakje_gemak',
502
  array(
503
  array('eq' => 0),
504
  array('null' => true)
505
  )
506
  );
507
  $collection->addFieldToFilter(
508
- 'is_pakketautomaat',
509
  array(
510
  array('eq' => 0),
511
  array('null' => true)
@@ -573,13 +1316,12 @@ class TIG_PostNL_Model_Adminhtml_Observer_OrderGrid extends Varien_Object
573
  /**
574
  * Sorts the collection by a specified column in a specified direction
575
  *
576
- * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
577
  * @param string $sort The column that the collection is sorted by
578
  * @param string $dir The direction that is used to sort the collection
579
  *
580
  * @return $this
581
  */
582
- protected function _sortCollection($collection, $sort, $dir)
583
  {
584
  $block = $this->getBlock();
585
  $column = $block->getColumn($sort);
68
  /**
69
  * XML path to show_grid_options setting.
70
  */
71
+ const XPATH_SHOW_OPTIONS = 'postnl/cif_labels_and_confirming/show_grid_options';
72
 
73
  /**
74
+ * XML path to show_buspakje_options setting.
75
  */
76
+ const XPATH_SHOW_BUSPAKJE_OPTION = 'postnl/cif_labels_and_confirming/show_buspakje_option';
77
+
78
+ /**
79
+ * XML path to buspakje_calculation_mode setting.
80
+ */
81
+ const XPATH_BUSPAKJE_CALCULATION_MODE = 'postnl/cif_labels_and_confirming/buspakje_calculation_mode';
82
+
83
+ /**
84
+ * XML path to 'order grid columns' setting
85
+ */
86
+ const XPATH_ORDER_GRID_COLUMNS = 'postnl/cif_labels_and_confirming/order_grid_columns';
87
+
88
+ /**
89
+ * Xpath to the 'order_grid_massaction_default' setting.
90
+ */
91
+ const XPATH_ORDER_GRID_MASSACTION_DEFAULT = 'postnl/cif_labels_and_confirming/order_grid_massaction_default';
92
 
93
  /**
94
  * Edits the sales order grid by adding a mass action to create shipments for selected orders.
133
  * replace the collection, as the default collection has a bug preventing it from being reset.
134
  * Without being able to reset it, we can't edit it. Therefore we are forced to replace it altogether
135
  *
136
+ * @todo see if this can be avoided in any way
137
  */
138
  $collection = Mage::getResourceModel('postnl/order_grid_collection');
139
  $collection->setSelect($select)
146
  $this->_joinCollection($collection);
147
  $this->_modifyColumns($block);
148
  $this->_addColumns($block);
149
+ $this->_applySortAndFilter();
150
  $this->_addMassaction($block);
151
 
152
  $block->setCollection($collection);
154
  }
155
 
156
  /**
157
+ * Adds additional joins to the collection that will be used by newly added columns.
158
+ *
159
+ * Resulting query:
160
+ * SELECT `main_table`.*,
161
+ * `order`.`shipping_method`,
162
+ * `payment`.`method` AS `payment_method`,
163
+ * `shipping_address`.`country_id`,
164
+ * `postnl_order`.`is_pakje_gemak`,
165
+ * `postnl_order`.`is_pakketautomaat`,
166
+ * `postnl_order`.`type` AS `delivery_option_type`,
167
+ * `postnl_order`.`confirm_date`,
168
+ * group_concat(
169
+ * `postnl_shipment`.`confirm_status`
170
+ * ORDER BY `postnl_shipment`.`created_at` DESC
171
+ * SEPARATOR ","
172
+ * ) AS `confirm_status`,
173
+ * group_concat(
174
+ * `postnl_shipment`.`shipping_phase`
175
+ * ORDER BY `postnl_shipment`.`created_at` DESC
176
+ * SEPARATOR ","
177
+ * ) AS `shipping_phase`,
178
+ * group_concat(
179
+ * `postnl_shipment`.`shipment_type`
180
+ * ORDER BY `postnl_shipment`.`created_at` DESC
181
+ * SEPARATOR ","
182
+ * ) AS `shipment_type`,
183
+ * group_concat(
184
+ * `postnl_shipment`.`product_code`
185
+ * ORDER BY `postnl_shipment`.`created_at` DESC
186
+ * SEPARATOR ","
187
+ * ) AS `product_code`,
188
+ * IF(
189
+ * `postnl_shipment`.`confirm_date`,
190
+ * `postnl_shipment`.`confirm_date`,
191
+ * `postnl_order`.`confirm_date`
192
+ * ) AS `confirm_date`
193
+ * FROM `sales_flat_order_grid` AS `main_table`
194
+ * INNER JOIN `sales_flat_order` AS `order`
195
+ * ON `main_table`.`entity_id`=`order`.`entity_id`
196
+ * LEFT JOIN `sales_flat_order_payment` AS `payment`
197
+ * ON `main_table`.`entity_id`=`payment`.`parent_id`
198
+ * LEFT JOIN `sales_flat_order_address` AS `shipping_address`
199
+ * ON `main_table`.`entity_id`=`shipping_address`.`parent_id`
200
+ * AND `shipping_address`.`address_type`='shipping'
201
+ * LEFT JOIN `tig_postnl_order` AS `postnl_order`
202
+ * ON `main_table`.`entity_id`=`postnl_order`.`order_id`
203
+ * LEFT JOIN `tig_postnl_shipment` AS `postnl_shipment`
204
+ * ON `main_table`.`entity_id`=`postnl_shipment`.`order_id`
205
+ * GROUP BY `main_table`.`entity_id`
206
+ * ORDER BY created_at DESC
207
+ * LIMIT 20
208
  *
209
  * @param TIG_PostNL_Model_Resource_Order_Grid_Collection $collection
210
  *
214
  {
215
  $resource = Mage::getSingleton('core/resource');
216
 
217
+ /**
218
+ * If the order has any PostNl shipments, we can use their confirm_date. Otherwise we can check the confirm_date
219
+ * stored by the tig_postnl_order table.
220
+ */
221
+ $collection->addExpressionFieldToSelect(
222
+ 'confirm_date',
223
+ 'IF({{shipment_confirm_date}}, {{shipment_confirm_date}}, {{order_confirm_date}})',
224
+ array(
225
+ 'shipment_confirm_date' => '`postnl_shipment`.`confirm_date`',
226
+ 'order_confirm_date' => '`postnl_order`.`confirm_date`',
227
+ )
228
+ );
229
+
230
  $select = $collection->getSelect();
231
 
232
  /**
233
+ * Join sales_flat_order table.
234
  */
235
  $select->joinInner(
236
  array('order' => $resource->getTableName('sales/order')),
237
  '`main_table`.`entity_id`=`order`.`entity_id`',
238
  array(
239
+ 'shipping_method' => 'order.shipping_method',
240
  )
241
  );
242
 
243
  /**
244
+ * Join sales_flat_order_payment table.
245
+ */
246
+ $select->joinLeft(
247
+ array('payment' => $resource->getTableName('sales/order_payment')),
248
+ '`main_table`.`entity_id`=`payment`.`parent_id`',
249
+ array(
250
+ 'payment_method' => 'payment.method',
251
+ )
252
+ );
253
+
254
+ /**
255
+ * Join sales_flat_order_address table.
256
  */
257
  $select->joinLeft(
258
  array('shipping_address' => $resource->getTableName('sales/order_address')),
263
  );
264
 
265
  /**
266
+ * Join tig_postnl_order table.
267
  */
268
  $select->joinLeft(
269
  array('postnl_order' => $resource->getTableName('postnl_core/order')),
275
  )
276
  );
277
 
278
+ /**
279
+ * Join tig_postnl_shipment table.
280
+ */
281
+ $select->joinLeft(
282
+ array('postnl_shipment' => $resource->getTableName('postnl_core/shipment')),
283
+ '`main_table`.`entity_id`=`postnl_shipment`.`order_id`',
284
+ array(
285
+ 'confirm_status' => new Zend_Db_Expr(
286
+ 'group_concat(`postnl_shipment`.`confirm_status` ORDER BY `postnl_shipment`.`created_at` DESC ' .
287
+ 'SEPARATOR ",")'
288
+ ),
289
+ 'shipping_phase' => new Zend_Db_Expr(
290
+ 'group_concat(`postnl_shipment`.`shipping_phase` ORDER BY `postnl_shipment`.`created_at` DESC ' .
291
+ 'SEPARATOR ",")'
292
+ ),
293
+ 'shipment_type' => new Zend_Db_Expr(
294
+ 'group_concat(`postnl_shipment`.`shipment_type` ORDER BY `postnl_shipment`.`created_at` DESC ' .
295
+ 'SEPARATOR ",")'
296
+ ),
297
+ 'product_code' => new Zend_Db_Expr(
298
+ 'group_concat(`postnl_shipment`.`product_code` ORDER BY `postnl_shipment`.`created_at` DESC ' .
299
+ 'SEPARATOR ",")'
300
+ ),
301
+ )
302
+ );
303
+
304
+ /**
305
+ * Group the results by the ID column.
306
+ */
307
+ $select->group('main_table.entity_id');
308
+
309
  return $this;
310
  }
311
 
388
  {
389
  $helper = Mage::helper('postnl');
390
 
391
+ $countryIdColumnAttributes = array(
392
  'header' => $helper->__('Shipment type'),
393
  'align' => 'left',
394
  'index' => 'country_id',
395
  'type' => 'options',
396
+ 'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_orderType',
397
+ 'width' => '140px',
398
  'filter_condition_callback' => array($this, '_filterShipmentType'),
399
  'sortable' => false,
400
  'options' => array(
408
  ),
409
  );
410
 
411
+ $showOrderColumns = Mage::getStoreConfig(self::XPATH_ORDER_GRID_COLUMNS, Mage_Core_Model_App::ADMIN_STORE_ID);
412
+ $showOrderColumns = explode(',', $showOrderColumns);
 
 
413
 
414
  /**
415
+ * If we don't need to display the shipment type column, hide it. We'll still need it for some javascript
416
+ * functionality
417
  */
418
+ if (!in_array('shipment_type', $showOrderColumns)) {
419
+ $countryIdColumnAttributes['column_css_class'] = 'no-display';
420
+ $countryIdColumnAttributes['header_css_class'] = 'no-display';
421
+ $countryIdColumnAttributes['display'] = 'none';
422
  }
423
 
424
  $block->addColumnAfter(
425
  'country_id',
426
+ $countryIdColumnAttributes,
427
  'shipping_name'
428
  );
429
 
430
+ /**
431
+ * Add the confirm date column.
432
+ */
433
+ $after = 'country_id';
434
+ if (in_array('confirm_date', $showOrderColumns)) {
435
+ $block->addColumnAfter(
436
+ 'confirm_date',
437
+ array(
438
+ 'type' => 'date',
439
+ 'header' => $helper->__('Send date'),
440
+ 'index' => 'confirm_date',
441
+ 'filter_index' => 'postnl_order.confirm_date',
442
+ 'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_orderConfirmDate',
443
+ 'width' => '150px',
444
+ 'frame_callback' => array($this, 'decorateConfirmDate'),
445
+ ),
446
+ $after
447
+ );
448
+
449
+ $after = 'confirm_date';
450
+ }
451
+
452
+ /**
453
+ * Add the confirm status column.
454
+ */
455
+ if (in_array('confirm_status', $showOrderColumns)) {
456
+ $block->addColumnAfter(
457
+ 'confirm_status',
458
+ array(
459
+ 'header' => $helper->__('Confirm Status'),
460
+ 'type' => 'text',
461
+ 'index' => 'confirm_status',
462
+ 'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_orderConfirmStatus',
463
+ 'frame_callback' => array($this, 'decorateConfirmStatus'),
464
+ 'sortable' => false,
465
+ 'filter' => false,
466
+ ),
467
+ $after
468
+ );
469
+
470
+ $after = 'confirm_status';
471
+ }
472
+
473
+ /**
474
+ * Add the shipping phase column.
475
+ */
476
+ if (in_array('shipping_phase', $showOrderColumns)) {
477
+ $block->addColumnAfter(
478
+ 'shipping_phase',
479
+ array(
480
+ 'header' => $helper->__('Shipping Phase'),
481
+ 'align' => 'left',
482
+ 'index' => 'shipping_phase',
483
+ 'type' => 'text',
484
+ 'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_shippingPhase',
485
+ 'frame_callback' => array($this, 'decorateShippingPhase'),
486
+ 'sortable' => false,
487
+ 'filter' => false,
488
+ ),
489
+ $after
490
+ );
491
+ }
492
+
493
  $block->sortColumnsByOrder();
494
 
495
  return $this;
496
  }
497
 
498
+ /**
499
+ * Decorates the confirm_sate column
500
+ *
501
+ * @param string|null $value
502
+ * @param Mage_Sales_Model_Order_Shipment $row
503
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
504
+ * @param boolean $isExport
505
+ *
506
+ * @return string
507
+ */
508
+ public function decorateConfirmDate($value, $row, $column, $isExport)
509
+ {
510
+ if ($isExport) {
511
+ return $value;
512
+ }
513
+
514
+ $class = $this->_getConfirmDateClass($value, $row, $column);
515
+
516
+ return '<span class="'.$class.'"><span>'.$value.'</span></span>';
517
+ }
518
+
519
+ /**
520
+ * Gets class name for the confirmDate column of the current row.
521
+ *
522
+ * @param string|null $value
523
+ * @param Mage_Sales_Model_Order_Shipment $row
524
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
525
+ *
526
+ * @return string
527
+ */
528
+ protected function _getConfirmDateClass($value, $row, $column)
529
+ {
530
+ if (!$value) {
531
+ return '';
532
+ }
533
+
534
+ $origValue = $row->getData($column->getIndex());
535
+ $dateModel = Mage::getModel('core/date');
536
+ $now = new DateTime($dateModel->gmtDate());
537
+
538
+ if (!$origValue) {
539
+ $deliveryDate = Mage::helper('postnl/deliveryOptions')->getDeliveryDate(
540
+ $row->getCreatedAt(),
541
+ $row->getStoreId()
542
+ );
543
+ $origDate = new DateTime($deliveryDate);
544
+ $origDate = $origDate->sub(new DateInterval('P1D'));
545
+ } else {
546
+ $origDate = new DateTime($origValue);
547
+ }
548
+
549
+ /**
550
+ * @var $postnlShipmentClass TIG_PostNL_Model_Core_Shipment
551
+ */
552
+ $interval = $now->diff($origDate);
553
+ $isConfirmed = $this->_isRowConfirmed($row);
554
+ $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
555
+
556
+ if ($isConfirmed ||
557
+ ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_BUSPAKJE
558
+ && $interval->d >= 1
559
+ && $interval->invert
560
+ )
561
+ ) {
562
+ return 'grid-severity-notice';
563
+ }
564
+
565
+ if ($interval->d == 0) {
566
+ return 'grid-severity-major';
567
+ }
568
+
569
+ if ($interval->d >= 1 && $interval->invert) {
570
+ return 'grid-severity-critical';
571
+ }
572
+
573
+ return 'grid-severity-minor';
574
+ }
575
+
576
+ /**
577
+ * Checks if the row has been fully confirmed.
578
+ *
579
+ * @param Mage_Sales_Model_Order_Shipment $row
580
+ *
581
+ * @return boolean
582
+ */
583
+ protected function _isRowConfirmed($row)
584
+ {
585
+ $confirmStatus = $row->getConfirmStatus();
586
+
587
+ /**
588
+ * @var $postnlShipmentClass TIG_PostNL_Model_Core_Shipment
589
+ */
590
+ $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
591
+ $statusses = explode(',', $confirmStatus);
592
+ foreach ($statusses as $status) {
593
+ if ($status != $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
594
+ return false;
595
+ }
596
+ }
597
+
598
+ return true;
599
+ }
600
+
601
+ /**
602
+ * Decorates the confirm_status column
603
+ *
604
+ * @param string | null $values
605
+ * @param Mage_Sales_Model_Order_Shipment $row
606
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
607
+ * @param boolean $isExport
608
+ *
609
+ * @return string
610
+ */
611
+ public function decorateConfirmStatus($values, $row, $column, $isExport)
612
+ {
613
+ if ($isExport) {
614
+ return $values;
615
+ }
616
+
617
+ if (is_null($values)) {
618
+ return '';
619
+ }
620
+
621
+ $origValues = $row->getData($column->getIndex());
622
+ if (!$origValues) {
623
+ $html = '<span class="grid-severity-minor"><span>' . $values . '</span></span>';
624
+ return $html;
625
+ }
626
+
627
+ $html = '';
628
+ $statusses = explode(',', $origValues);
629
+ $values = explode(',', $values);
630
+
631
+ foreach ($statusses as $key => $status) {
632
+ $html .= $this->_decorateConfirmStatus($status, $values[$key]);
633
+ }
634
+
635
+ return $html;
636
+ }
637
+
638
+ /**
639
+ * Decorate a single confirm status value.
640
+ *
641
+ * @param string $status
642
+ * @param string $value
643
+ *
644
+ * @return string
645
+ */
646
+ protected function _decorateConfirmStatus($status, $value)
647
+ {
648
+ /**
649
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipmentClass
650
+ */
651
+ $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
652
+
653
+ switch ($status) {
654
+ case $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED:
655
+ $class = 'grid-severity-notice';
656
+ break;
657
+ case $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED: //no break
658
+ case $postnlShipmentClass::CONFIRM_STATUS_CONFIRM_EXPIRED:
659
+ $class = 'grid-severity-critical';
660
+ break;
661
+ case $postnlShipmentClass::CONFIRM_STATUS_BUSPAKJE:
662
+ $class = 'grid-severity-notice no-display';
663
+ break;
664
+ default:
665
+ $class = '';
666
+ break;
667
+ }
668
+
669
+ $html = '<span class="'.$class.'"><span>'.$value.'</span></span>';
670
+ return $html;
671
+ }
672
+
673
+ /**
674
+ * Decorates the shipping_phase column
675
+ *
676
+ * @param string|null $values
677
+ * @param Mage_Sales_Model_Order_Shipment $row
678
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
679
+ * @param boolean $isExport
680
+ *
681
+ * @return string
682
+ */
683
+ public function decorateShippingPhase($values, $row, $column, $isExport)
684
+ {
685
+ if ($isExport) {
686
+ return $values;
687
+ }
688
+
689
+ $html = '';
690
+ $shippingPhases = explode(',', $row->getData($column->getIndex()));
691
+ $values = explode(',', $values);
692
+
693
+ foreach ($shippingPhases as $key => $phase) {
694
+ $html .= $this->_decorateShippingPhase($phase, $values[$key]);
695
+ }
696
+
697
+ return $html;
698
+ }
699
+
700
+ /**
701
+ * Decorate a single shipping phase and corresponding value.
702
+ *
703
+ * @param string|int $phase
704
+ * @param string $value
705
+ *
706
+ * @return string
707
+ */
708
+ protected function _decorateShippingPhase($phase, $value)
709
+ {
710
+ /**
711
+ * @var TIG_PostNL_Model_Core_Shipment $postnlShipmentClass
712
+ */
713
+ $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
714
+
715
+ switch ($phase) {
716
+ case null: //rows with no value (non-PostNL shipments) or unconfirmed shipments.
717
+ $class = '';
718
+ break;
719
+ case $postnlShipmentClass::SHIPPING_PHASE_DELIVERED:
720
+ $class = 'grid-severity-notice';
721
+ break;
722
+ case $postnlShipmentClass::SHIPPING_PHASE_SORTING: //no break;
723
+ case $postnlShipmentClass::SHIPPING_PHASE_DISTRIBUTION: //no break;
724
+ case $postnlShipmentClass::SHIPPING_PHASE_COLLECTION:
725
+ $class = 'grid-severity-minor';
726
+ break;
727
+ case $postnlShipmentClass::SHIPPING_PHASE_NOT_APPLICABLE:
728
+ $class = 'grid-severity-critical';
729
+ break;
730
+ default:
731
+ $class = '';
732
+ break;
733
+ }
734
+
735
+ $html = '<span class="' . $class . '"><span>' . $value . '</span></span>';
736
+ return $html;
737
+ }
738
+
739
  /**
740
  * Adds a massaction to confirm the order and print the shipping labels
741
  *
748
  $helper = Mage::helper('postnl');
749
 
750
  /**
751
+ * Make sure the admin is allowed to ship orders and add the mass action.
752
  */
753
+ if ($helper->checkIsPostnlActionAllowed('create_shipment')) {
754
+ $createShipmentMassActionData = $this->_getCreateShipmentMassAction();
755
+
756
+ /**
757
+ * Add the massaction.
758
+ */
759
+ $block->getMassactionBlock()
760
+ ->addItem(
761
+ 'postnl_create_shipments',
762
+ $createShipmentMassActionData
763
+ );
764
  }
765
 
766
  /**
767
+ * Make sure the admin is allowed to ship orders, print labels and confirm shipments. If so, add the
768
+ * massaction.
769
+ */
770
+ if ($helper->checkIsPostnlActionAllowed(
771
+ array(
772
+ 'create_shipment',
773
+ 'confirm',
774
+ 'print_label',
775
+ )
776
+ )
777
+ ) {
778
+ $fullPostnlFlowMassActionData = $this->_getFullPostnlFlowMassAction();
779
+
780
+ /**
781
+ * Add the massaction.
782
+ */
783
+ $block->getMassactionBlock()
784
+ ->addItem(
785
+ 'postnl_create_shipment_print_label_and_confirm',
786
+ $fullPostnlFlowMassActionData
787
+ );
788
+ }
789
+
790
+ /**
791
+ * Make sure the admin is allowed to print packing slips and add the mass action.
792
+ */
793
+ if ($helper->checkIsPostnlActionAllowed('print_packing_slips')) {
794
+ $printPackingSlipMassActionData = $this->_getCreatePackingSlipMassAction();
795
+
796
+ /**
797
+ * Add the massaction.
798
+ */
799
+ $block->getMassactionBlock()
800
+ ->addItem(
801
+ 'postnl_print_packing_slip',
802
+ $printPackingSlipMassActionData
803
+ );
804
+ }
805
+
806
+ return $this;
807
+ }
808
+
809
+ /**
810
+ * Gets mass action data for the createShipments mass action.
811
+ *
812
+ * @return array
813
+ */
814
+ protected function _getCreateShipmentMassAction()
815
+ {
816
+ $helper = Mage::helper('postnl');
817
+
818
+ /**
819
+ * Build an array of options for the massaction item.
820
  */
821
  $massActionData = array(
822
  'label'=> $helper->__('PostNL - Create Shipments'),
823
  'url' => Mage::helper('adminhtml')->getUrl('postnl_admin/adminhtml_shipment/massCreateShipments'),
824
  );
825
 
826
+ $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
827
+
828
+ $defaultMassAction = Mage::getStoreConfig(self::XPATH_ORDER_GRID_MASSACTION_DEFAULT, $storeId);
829
+ if ($defaultMassAction == 'postnl_create_shipments') {
830
+ $massActionData['selected'] = true;
831
+ }
832
+
833
+ $showOptions = Mage::getStoreConfig(self::XPATH_SHOW_OPTIONS, $storeId);
834
 
835
  if ($showOptions) {
836
+ $optionsModel = Mage::getModel('postnl_core/system_config_source_allProductOptions');
837
+
838
  /**
839
+ * Add another dropdown containing the possible product options.
840
+ * Mage_Adminhtml_Block_Widget_Grid_Massaction_Item_Additional_Default
841
  */
842
+ $config = array(
843
+ 'postnl_use_default' => array(
844
+ 'name' => 'product_options[use_default]',
845
+ 'type' => 'postnl_checkbox',
846
+ 'label' => $helper->__('Use default option'),
847
+ 'value' => 1,
848
+ 'checked' => 'checked',
849
+ ),
850
+ 'postnl_domestic_options' => array(
851
+ 'name' => 'product_options[domestic_options]',
852
+ 'type' => 'select',
853
+ 'label' => $helper->__('Product options'),
854
+ 'values' => $optionsModel->getOptions(
855
+ array(
856
+ 'group' => 'standard_options',
857
+ 'isCod' => false,
858
+ ),
859
+ false,
860
+ true
861
+ ),
862
+ ),
863
+ 'postnl_avond_options' => array(
864
+ 'name' => 'product_options[avond_options]',
865
+ 'type' => 'select',
866
+ 'label' => $helper->__('Product options'),
867
+ 'values' => $optionsModel->getOptions(
868
+ array(
869
+ 'group' => 'standard_options',
870
+ 'isCod' => false,
871
+ 'isAvond' => true),
872
+ false,
873
+ true
874
+ ),
875
+ ),
876
+ 'postnl_pg_options' => array(
877
+ 'name' => 'product_options[pg_options]',
878
+ 'type' => 'select',
879
+ 'label' => $helper->__('Product options'),
880
+ 'values' => $optionsModel->getOptions(
881
+ array(
882
+ 'group' => 'pakjegemak_options',
883
+ 'isCod' => false,
884
+ ),
885
+ false,
886
+ true
887
+ ),
888
+ ),
889
+ 'postnl_pge_options' => array(
890
+ 'name' => 'product_options[pge_options]',
891
  'type' => 'select',
892
  'class' => 'required-entry',
893
  'label' => $helper->__('Product options'),
894
+ 'values' => $optionsModel->getOptions(
895
+ array(
896
+ 'group' => 'pakjegemak_options',
897
+ 'isCod' => false,
898
+ 'isPge' => true,
899
+ ),
900
+ false,
901
+ true
902
+ ),
903
+ ),
904
+ 'postnl_eps_options' => array(
905
+ 'name' => 'product_options[eps_options]',
906
+ 'type' => 'select',
907
+ 'label' => $helper->__('Product options'),
908
+ 'values' => $optionsModel->getOptions(
909
+ array(
910
+ 'group' => 'eu_options',
911
+ ),
912
+ false,
913
+ true
914
+ ),
915
+ ),
916
+ 'postnl_globalpack_options' => array(
917
+ 'name' => 'product_options[globalpack_options]',
918
+ 'type' => 'select',
919
+ 'label' => $helper->__('Product options'),
920
+ 'values' => $optionsModel->getOptions(
921
+ array(
922
+ 'group' => 'global_options',
923
+ ),
924
+ false,
925
+ true
926
+ ),
927
+ ),
928
+ 'postnl_domestic_cod_options' => array(
929
+ 'name' => 'product_options[domestic_cod_options]',
930
+ 'type' => 'select',
931
+ 'label' => $helper->__('Product options'),
932
+ 'values' => $optionsModel->getOptions(
933
+ array(
934
+ 'group' => 'standard_options',
935
+ 'isCod' => true,
936
+ ),
937
+ false,
938
+ true
939
+ ),
940
+ ),
941
+ 'postnl_avond_cod_options' => array(
942
+ 'name' => 'product_options[avond_cod_options]',
943
+ 'type' => 'select',
944
+ 'label' => $helper->__('Product options'),
945
+ 'values' => $optionsModel->getOptions(
946
+ array(
947
+ 'group' => 'standard_options',
948
+ 'isCod' => true,
949
+ 'isAvond' => true,
950
+ ),
951
+ false,
952
+ true
953
+ ),
954
+ ),
955
+ 'postnl_pg_cod_options' => array(
956
+ 'name' => 'product_options[pg_cod_options]',
957
+ 'type' => 'select',
958
+ 'label' => $helper->__('Product options'),
959
+ 'values' => $optionsModel->getOptions(
960
+ array(
961
+ 'group' => 'pakjegemak_options',
962
+ 'isCod' => true,
963
+ ),
964
+ false,
965
+ true
966
+ ),
967
+ ),
968
+ 'postnl_pge_cod_options' => array(
969
+ 'name' => 'product_options[pge_cod_options]',
970
+ 'type' => 'select',
971
+ 'label' => $helper->__('Product options'),
972
+ 'values' => $optionsModel->getOptions(
973
+ array(
974
+ 'group' => 'pakjegemak_options',
975
+ 'isCod' => true,
976
+ 'isPge' => true,
977
+ ),
978
+ false,
979
+ true
980
+ ),
981
+ ),
982
+ 'postnl_pa_options' => array(
983
+ 'name' => 'product_options[pa_options]',
984
+ 'type' => 'select',
985
+ 'label' => $helper->__('Product options'),
986
+ 'values' => $optionsModel->getOptions(
987
+ array(
988
+ 'group' => 'pakketautomaat_options',
989
+ ),
990
+ false,
991
+ true
992
+ ),
993
+ ),
994
+ 'postnl_buspakje_options' => array(
995
+ 'name' => 'product_options[buspakje_options]',
996
+ 'type' => 'select',
997
+ 'class' => 'required-entry',
998
+ 'label' => $helper->__('Product options'),
999
+ 'values' => $optionsModel->getOptions(
1000
+ array(
1001
+ 'group' => 'buspakje_options',
1002
+ ),
1003
+ false,
1004
+ true
1005
+ ),
1006
  ),
1007
  );
1008
+
1009
+ $buspakjeCalculationMode = Mage::getStoreConfig(self::XPATH_BUSPAKJE_CALCULATION_MODE, $storeId);
1010
+ $showBuspakjeOptions = Mage::getStoreConfigFlag(self::XPATH_SHOW_BUSPAKJE_OPTION, $storeId);
1011
+ if ($helper->canUseBuspakje()
1012
+ && $buspakjeCalculationMode == 'manual'
1013
+ && $showBuspakjeOptions
1014
+ ) {
1015
+ $buspakjeConfig = array(
1016
+ 'postnl_is_buspakje' => array(
1017
+ 'name' => 'product_options[is_buspakje]',
1018
+ 'type' => 'postnl_checkbox',
1019
+ 'label' => $helper->__('Is letter box parcel'),
1020
+ 'value' => 1,
1021
+ ),
1022
+ );
1023
+
1024
+ /**
1025
+ * Insert the is_buspakje checkbox at the second position in the config array.
1026
+ */
1027
+ $config = array_slice($config, 0, 1, true)
1028
+ + $buspakjeConfig
1029
+ + array_slice($config, 1, count($config) - 1, true);
1030
+ }
1031
+
1032
+ /**
1033
+ * @var TIG_PostNL_Block_Adminhtml_Widget_Grid_Massaction_Item_Additional_ProductOptions $block
1034
+ */
1035
+ $block = Mage::app()
1036
+ ->getLayout()
1037
+ ->createBlock('postnl_adminhtml/widget_grid_massaction_item_additional_productOptions');
1038
+ $massActionData['additional'] = $block->createFromConfiguration($config);
1039
+ }
1040
+
1041
+ return $massActionData;
1042
+ }
1043
+
1044
+ /**
1045
+ * Gets mass action data for the full PostNL flow mass action.
1046
+ *
1047
+ * @return array
1048
+ */
1049
+ protected function _getFullPostnlFlowMassAction()
1050
+ {
1051
+ $helper = Mage::helper('postnl');
1052
+
1053
+ /**
1054
+ * Build an array of options for the massaction item.
1055
+ */
1056
+ $massActionData = array(
1057
+ 'label' => $helper->__('PostNL - Create shipments, print labels and confirm'),
1058
+ 'url' => Mage::helper('adminhtml')->getUrl('postnl_admin/adminhtml_shipment/massFullPostnlFlow'),
1059
+ );
1060
+
1061
+ $defaultMassAction = Mage::getStoreConfig(
1062
+ self::XPATH_ORDER_GRID_MASSACTION_DEFAULT,
1063
+ Mage_Core_Model_App::ADMIN_STORE_ID
1064
+ );
1065
+
1066
+ if ($defaultMassAction == 'postnl_create_shipment_print_label_and_confirm') {
1067
+ $massActionData['selected'] = true;
1068
  }
1069
 
1070
+ return $massActionData;
1071
+ }
1072
+
1073
+ /**
1074
+ * Gets mass action data for the printPackingSlips mass action.
1075
+ *
1076
+ * @return array
1077
+ */
1078
+ protected function _getCreatePackingSlipMassAction()
1079
+ {
1080
+ $helper = Mage::helper('postnl');
1081
+
1082
  /**
1083
+ * Build an array of options for the massaction item.
1084
  */
1085
+ $massActionData = array(
1086
+ 'label' => $helper->__('PostNL - Print packing slips'),
1087
+ 'url' => Mage::helper('adminhtml')->getUrl('postnl_admin/adminhtml_shipment/massPrintPackingslips'),
1088
+ );
 
1089
 
1090
+ $defaultMassAction = Mage::getStoreConfig(
1091
+ self::XPATH_ORDER_GRID_MASSACTION_DEFAULT,
1092
+ Mage_Core_Model_App::ADMIN_STORE_ID
1093
+ );
1094
+
1095
+ if ($defaultMassAction == 'postnl_print_packing_slip') {
1096
+ $massActionData['selected'] = true;
1097
+ }
1098
+
1099
+ return $massActionData;
1100
  }
1101
 
1102
  /**
1103
  * Applies sorting and filtering to the collection
1104
  *
 
 
1105
  * @return $this
1106
  */
1107
+ protected function _applySortAndFilter()
1108
  {
1109
  $session = Mage::getSingleton('adminhtml/session');
1110
 
1112
  $filter = Mage::helper('adminhtml')->prepareFilterString($filter);
1113
 
1114
  if ($filter) {
1115
+ $this->_filterCollection($filter);
1116
  }
1117
 
1118
  $sort = $session->getData(self::ORDER_GRID_SORT_VAR_NAME);
1120
  if ($sort) {
1121
  $dir = $session->getData(self::ORDER_GRID_DIR_VAR_NAME);
1122
 
1123
+ $this->_sortCollection($sort, $dir);
1124
  }
1125
 
1126
  return $this;
1129
  /**
1130
  * Adds new filters to the collection if these filters are based on columns added by this observer
1131
  *
1132
+ * @param array $filter Array of filters to be added
 
1133
  *
1134
  * @return $this
1135
  */
1136
+ protected function _filterCollection($filter)
1137
  {
1138
  $block = $this->getBlock();
1139
 
1140
  foreach ($filter as $columnName => $value) {
1141
  $column = $block->getColumn($columnName);
1142
 
1143
+ if (!$column) {
1144
+ continue;
1145
+ }
1146
+
1147
  $column->getFilter()->setValue($value);
1148
  $this->_addColumnFilterToCollection($column);
1149
  }
1154
  /**
1155
  * Filters the collection by the 'shipment_type' column. Th column has 3 options: domestic, EPS and GlobalPack.
1156
  *
1157
+ * @param TIG_PostNL_Model_Resource_Order_Grid_Collection $collection
1158
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
1159
  *
1160
  * @return $this
1161
  */
1165
  $filterCond = $cond['eq'];
1166
 
1167
  /**
1168
+ * First filter out all non-postnl orders.
1169
  */
1170
  $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
1171
+ $postnlShippingMethodsRegex = '';
1172
+ foreach ($postnlShippingMethods as $method) {
1173
+ if ($postnlShippingMethodsRegex) {
1174
+ $postnlShippingMethodsRegex .= '|';
1175
+ } else {
1176
+ $postnlShippingMethodsRegex .= '^';
1177
+ }
1178
+
1179
+ $postnlShippingMethodsRegex .= "({$method})(_{0,1}[0-9]*)";
1180
+ }
1181
+
1182
+ $postnlShippingMethodsRegex .= '$';
1183
+ $collection->addFieldToFilter('order.shipping_method', array('regexp' => $postnlShippingMethodsRegex));
1184
 
1185
  /**
1186
  * If the filter condition is PakjeGemak Express, filter out all non-PakjeGemak Express orders
1204
  * If the filter condition is PakjeGemak, filter out all non-PakjeGemak orders
1205
  */
1206
  if ($filterCond == 'pakje_gemak') {
1207
+ $collection->addFieldToFilter('postnl_order.is_pakje_gemak', array('eq' => 1));
1208
  $collection->addFieldToFilter('postnl_order.type', array(array('eq' => 'PG'), array('null' => true)));
1209
 
1210
  return $this;
1214
  * If the filter condition is Pakket Automaat, filter out all non-Pakket Automaat orders
1215
  */
1216
  if ($filterCond == 'pakketautomaat') {
1217
+ $collection->addFieldToFilter('postnl_order.is_pakketautomaat', array('eq' => 1));
1218
  $collection->addFieldToFilter(
1219
  'postnl_order.type',
1220
  array(
1228
 
1229
  /**
1230
  * If the filter condition is NL, filter out all orders not being shipped to the Netherlands. PakjeGemak,
1231
+ * PakjeGemak Express, evening delivery and pakketautomaat shipments are also shipped to the Netherlands so we
1232
  * need to explicitly filter those as well.
1233
  */
1234
  if ($filterCond == 'nl') {
1241
  )
1242
  );
1243
  $collection->addFieldToFilter(
1244
+ 'postnl_order.is_pakje_gemak',
1245
  array(
1246
  array('eq' => 0),
1247
  array('null' => true)
1248
  )
1249
  );
1250
  $collection->addFieldToFilter(
1251
+ 'postnl_order.is_pakketautomaat',
1252
  array(
1253
  array('eq' => 0),
1254
  array('null' => true)
1316
  /**
1317
  * Sorts the collection by a specified column in a specified direction
1318
  *
 
1319
  * @param string $sort The column that the collection is sorted by
1320
  * @param string $dir The direction that is used to sort the collection
1321
  *
1322
  * @return $this
1323
  */
1324
+ protected function _sortCollection($sort, $dir)
1325
  {
1326
  $block = $this->getBlock();
1327
  $column = $block->getColumn($sort);
app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentGrid.php CHANGED
@@ -70,18 +70,28 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
70
  /**
71
  * XML path to 'shipping grid columns' setting
72
  */
73
- const XML_PATH_SHIPPING_GRID_COLUMNS = 'postnl/cif_labels_and_confirming/shipping_grid_columns';
74
 
75
  /**
76
  * XML path to default selected mass action setting
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
  *
@@ -90,7 +100,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
90
  public function getOptionalColumnsToDisplay()
91
  {
92
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
93
- $columnsToDisplay = Mage::getStoreConfig(self::XML_PATH_SHIPPING_GRID_COLUMNS, $storeId);
94
 
95
  $columnsToDisplay = explode(',', $columnsToDisplay);
96
 
@@ -170,7 +180,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
170
  $this->_joinCollection($collection);
171
  $this->_modifyColumns($block);
172
  $this->_addColumns($block);
173
- $this->_applySortAndFilter($collection);
174
  $this->_addMassaction($block);
175
 
176
  $block->setCollection($this->getCollection());
@@ -178,7 +188,50 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
178
  }
179
 
180
  /**
181
- * Adds additional joins to the collection that will be used by newly added columns
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  *
183
  * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
184
  *
@@ -188,10 +241,34 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
188
  {
189
  $resource = Mage::getSingleton('core/resource');
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  $select = $collection->getSelect();
192
 
193
  /**
194
- * Join sales_flat_order table
195
  */
196
  $select->joinInner(
197
  array('order' => $resource->getTableName('sales/order')),
@@ -203,19 +280,23 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
203
  );
204
 
205
  /**
206
- * join sales_flat_order_address table
 
207
  */
208
  $select->joinLeft(
209
  array('shipping_address' => $resource->getTableName('sales/order_address')),
210
  "`main_table`.`order_id`=`shipping_address`.`parent_id` AND `shipping_address`.`address_type`='shipping'",
211
- array(
212
- 'postcode' => 'shipping_address.postcode',
213
- 'country_id' => 'shipping_address.country_id',
214
- )
 
 
 
215
  );
216
 
217
  /**
218
- * Join tig_postnl_shipment table
219
  */
220
  $select->joinLeft(
221
  array('postnl_shipment' => $resource->getTableName('postnl_core/shipment')),
@@ -230,20 +311,18 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
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
 
236
  /**
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
 
@@ -319,7 +398,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
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
  );
@@ -333,11 +412,10 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
333
  array(
334
  'header' => $helper->__('Shipment type'),
335
  'align' => 'left',
336
- 'index' => 'country_id',
337
  'type' => 'options',
338
  'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_shipmentType',
339
  'width' => '75px',
340
- 'filter_condition_callback' => array($this, '_filterShipmentType'),
341
  'sortable' => false,
342
  'options' => array(
343
  'nl' => $helper->__('Domestic'),
@@ -347,6 +425,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
347
  'pakketautomaat' => $helper->__('Parcel Dispenser'),
348
  'avond' => $helper->__('Evening Delivery'),
349
  'pakje_gemak_express' => $helper->__('Early Pickup'),
 
350
  ),
351
  ),
352
  $after
@@ -366,7 +445,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
366
  'filter_index' => 'postnl_shipment.product_code',
367
  'column_css_class' => 'nobr',
368
  'options' => Mage::getModel('postnl_core/system_config_source_allProductOptions')
369
- ->getAvailableOptions(false, true, false, false, true, false),
370
  ),
371
  $after
372
  );
@@ -382,7 +461,8 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
382
  'align' => 'left',
383
  'index' => 'extra_cover_amount',
384
  'type' => 'currency',
385
- 'currency_code' => Mage::app()->getStore()->getBaseCurrencyCode(), //returns the base currency code for the admin store
 
386
  ),
387
  $after
388
  );
@@ -539,7 +619,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
539
  if ($helper->checkIsPostnlActionAllowed('confirm')) {
540
  $actions[] = array(
541
  'caption' => $helper->__('Confirm'),
542
- 'url' => array('base' => 'postnl/adminhtml_shipment/confirm'),
543
  'field' => 'shipment_id',
544
  'is_postnl' => true, //custom flag for renderer
545
  'code' => 'postnl_confirm',
@@ -573,6 +653,10 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
573
 
574
  $class = $this->_getConfirmDateClass($row, $column);
575
 
 
 
 
 
576
  return '<span class="'.$class.'"><span>'.$value.'</span></span>';
577
  }
578
 
@@ -586,15 +670,29 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
586
  */
587
  protected function _getConfirmDateClass($row, $column)
588
  {
 
 
 
 
 
 
 
 
 
589
  /**
590
  * @var TIG_PostNL_Model_Core_Shipment $postnlShipmentClass
591
  */
 
 
 
592
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
593
 
594
- $origValue = $row->getData($column->getIndex());
595
- $dateModel = Mage::getModel('core/date');
596
-
597
- if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED) {
 
 
598
  return 'grid-severity-notice';
599
  }
600
 
@@ -602,23 +700,15 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
602
  return 'grid-severity-critical';
603
  }
604
 
605
- if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED
606
- && date('Ymd', $dateModel->gmtTimestamp()) == date('Ymd', strtotime($origValue))
607
- ) {
608
  return 'grid-severity-major';
609
  }
610
 
611
- if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED
612
- && $dateModel->gmtTimestamp() > strtotime($origValue)
613
- ) {
614
  return 'grid-severity-critical';
615
  }
616
 
617
- if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_UNCONFIRMED) {
618
- return 'grid-severity-minor';
619
- }
620
-
621
- return '';
622
  }
623
 
624
  /**
@@ -652,10 +742,18 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
652
  case $postnlShipmentClass::CONFIRM_STATUS_CONFIRM_EXPIRED:
653
  $class = 'grid-severity-critical';
654
  break;
 
 
 
655
  default:
656
  $class = '';
657
  break;
658
  }
 
 
 
 
 
659
  return '<span class="'.$class.'"><span>'.$value.'</span></span>';
660
  }
661
 
@@ -689,6 +787,11 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
689
  $class = '';
690
  break;
691
  }
 
 
 
 
 
692
  return '<span class="'.$class.'"><span>'.$value.'</span></span>';
693
  }
694
 
@@ -714,14 +817,14 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
714
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
715
 
716
  switch ($row->getData($column->getIndex())) {
717
- case null: //rows with no value (non-PostNL shipments) or unconfirmed shipments
718
  $class = '';
719
  break;
720
- case $postnlShipmentClass::SHIPPING_PHASE_SORTING: //no break;
721
- case $postnlShipmentClass::SHIPPING_PHASE_DISTRIBUTION: //no break;
722
  case $postnlShipmentClass::SHIPPING_PHASE_DELIVERED:
723
  $class = 'grid-severity-notice';
724
  break;
 
 
725
  case $postnlShipmentClass::SHIPPING_PHASE_COLLECTION:
726
  $class = 'grid-severity-minor';
727
  break;
@@ -732,6 +835,11 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
732
  $class = '';
733
  break;
734
  }
 
 
 
 
 
735
  return '<span class="'.$class.'"><span>'.$value.'</span></span>';
736
  }
737
 
@@ -753,13 +861,18 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
753
  * Build all the mass action option arrays
754
  */
755
  $printAndConfirmOptions = array(
756
- 'label' => $helper->__('PostNL - Print shipping labels & confirm shipment'),
757
- 'url' => $adminhtmlHelper->getUrl('postnl_admin/adminhtml_shipment/massPrintLabelsAndConfirm'),
758
  );
759
 
760
  $printOptions = array(
761
- 'label' => $helper->__('PostNL - Print shipping labels'),
762
- 'url' => $adminhtmlHelper->getUrl('postnl_admin/adminhtml_shipment/massPrintLabels'),
 
 
 
 
 
763
  );
764
 
765
  $confirmOptions = array(
@@ -779,14 +892,17 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
779
  /**
780
  * Get the additional options block for 'label printing' mass actions.
781
  */
782
- $printAdditional = Mage::app()->getLayout()
783
- ->createBlock('postnl_adminhtml/widget_grid_massaction_labelStartPos');
 
 
 
784
 
785
  $printAdditional->setData(
786
- array(
787
- 'name' => 'print_start_pos',
788
- 'label' => $helper->__('Choose printing start position'),
789
- )
790
  );
791
 
792
  /**
@@ -800,7 +916,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
800
  * Check which mass action should be selected by default
801
  */
802
  $defaultSelectedOption = Mage::getStoreConfig(
803
- self::XML_PATH_SHIPPING_GRID_MASSACTION_DEFAULT,
804
  Mage_Core_Model_App::ADMIN_STORE_ID
805
  );
806
 
@@ -814,6 +930,9 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
814
  case 'postnl_print_labels':
815
  $printOptions['selected'] = true;
816
  break;
 
 
 
817
  case 'postnl_confirm_shipments':
818
  $confirmOptions['selected'] = true;
819
  break;
@@ -823,9 +942,10 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
823
  // no default
824
  }
825
 
826
- $printAllowed = $helper->checkIsPostnlActionAllowed('print_label');
827
- $confirmAllowed = $helper->checkIsPostnlActionAllowed('confirm');
828
- $exportAllowed = $helper->checkIsPostnlActionAllowed('create_parcelware_export');
 
829
 
830
  /**
831
  * Add the mass actions to the grid if the current admin user is allowed to use them.
@@ -844,6 +964,13 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
844
  );
845
  }
846
 
 
 
 
 
 
 
 
847
  if ($confirmAllowed) {
848
  $massactionBlock->addItem(
849
  'postnl_confirm_shipments',
@@ -865,11 +992,9 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
865
  /**
866
  * Applies sorting and filtering to the collection
867
  *
868
- * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
869
- *
870
  * @return $this
871
  */
872
- protected function _applySortAndFilter($collection)
873
  {
874
  $session = Mage::getSingleton('adminhtml/session');
875
 
@@ -877,7 +1002,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
877
  $filter = Mage::helper('adminhtml')->prepareFilterString($filter);
878
 
879
  if ($filter) {
880
- $this->_filterCollection($collection, $filter);
881
  }
882
 
883
  $sort = $session->getData(self::SHIPMENT_GRID_SORT_VAR_NAME);
@@ -885,7 +1010,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
885
  if ($sort) {
886
  $dir = $session->getData(self::SHIPMENT_GRID_DIR_VAR_NAME);
887
 
888
- $this->_sortCollection($collection, $sort, $dir);
889
  }
890
 
891
  return $this;
@@ -894,17 +1019,17 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
894
  /**
895
  * Adds new filters to the collection if these filters are based on columns added by this observer
896
  *
897
- * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
898
  * @param array $filter Array of filters to be added
899
  *
900
  * @return $this
901
  */
902
- protected function _filterCollection($collection, $filter)
903
  {
904
  $block = $this->getBlock();
905
 
906
  foreach ($filter as $columnName => $value) {
907
  $column = $block->getColumn($columnName);
 
908
  if (!$column) {
909
  continue;
910
  }
@@ -916,122 +1041,6 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
916
  return $this;
917
  }
918
 
919
- /**
920
- * Filters the collection by the 'shipment_type' column. Th column has 3 options: domestic, EPS and GlobalPack.
921
- *
922
- * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
923
- * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
924
- *
925
- * @return $this
926
- */
927
- protected function _filterShipmentType($collection, $column)
928
- {
929
- $cond = $column->getFilter()->getCondition();
930
- $filterCond = $cond['eq'];
931
-
932
- /**
933
- * First filter out all non-postnl orders
934
- */
935
- $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
936
- $collection->addFieldToFilter('order.shipping_method', array('in' => $postnlShippingMethods));
937
-
938
- /**
939
- * If the filter condition is PakjeGemak Express, filter out all non-PakjeGemak Express orders
940
- */
941
- if ($filterCond == 'pakje_gemak_express') {
942
- $collection->addFieldToFilter('postnl_order.type', array('eq' => 'PGE'));
943
-
944
- return $this;
945
- }
946
-
947
- /**
948
- * If the filter condition is evening delivery, filter out all other orders
949
- */
950
- if ($filterCond == 'avond') {
951
- $collection->addFieldToFilter('postnl_order.type', array('eq' => 'Avond'));
952
-
953
- return $this;
954
- }
955
-
956
- /**
957
- * If the filter condition is PakjeGemak, filter out all non-PakjeGemak orders
958
- */
959
- if ($filterCond == 'pakje_gemak') {
960
- $collection->addFieldToFilter('is_pakje_gemak', array('eq' => 1));
961
- $collection->addFieldToFilter('postnl_order.type', array(array('eq' => 'PG'), array('null' => true)));
962
-
963
- return $this;
964
- }
965
-
966
- /**
967
- * If the filter condition is Pakket Automaat, filter out all non-Pakket Automaat orders
968
- */
969
- if ($filterCond == 'pakketautomaat') {
970
- $collection->addFieldToFilter('is_pakketautomaat', array('eq' => 1));
971
- $collection->addFieldToFilter(
972
- 'postnl_order.type',
973
- array(
974
- array('eq' => 'PA'),
975
- array('null' => true)
976
- )
977
- );
978
-
979
- return $this;
980
- }
981
-
982
- /**
983
- * If the filter condition is NL, filter out all orders not being shipped to the Netherlands. PakjeGemak,
984
- * PakjeGemak Express, evening delivery and pakketautomaat shipments are also shipped to the Netherlands so we
985
- * need to explicitly filter those as well.
986
- */
987
- if ($filterCond == 'nl') {
988
- $collection->addFieldToFilter('country_id', $cond);
989
- $collection->addFieldToFilter(
990
- 'postnl_order.type',
991
- array(
992
- array('eq' => 'Overdag'),
993
- array('null' => true)
994
- )
995
- );
996
- $collection->addFieldToFilter(
997
- 'is_pakje_gemak',
998
- array(
999
- array('eq' => 0),
1000
- array('null' => true)
1001
- )
1002
- );
1003
- $collection->addFieldToFilter(
1004
- 'is_pakketautomaat',
1005
- array(
1006
- array('eq' => 0),
1007
- array('null' => true)
1008
- )
1009
- );
1010
-
1011
- return $this;
1012
- }
1013
-
1014
- /**
1015
- * If the filter condition is EU, filter out all orders not being shipped to the EU and those being shipped to
1016
- * the Netherlands
1017
- */
1018
- $euCountries = Mage::helper('postnl/cif')->getEuCountries();
1019
- if ($filterCond == 'eu') {
1020
- $collection->addFieldToFilter('country_id', array('neq' => 'NL'));
1021
- $collection->addFieldToFilter('country_id', array('in', $euCountries));
1022
-
1023
- return $this;
1024
- }
1025
-
1026
- /**
1027
- * Lastly, filter out all orders who are being shipped to the Netherlands or other EU countries
1028
- */
1029
- $collection->addFieldToFilter('country_id', array('neq' => 'NL'));
1030
- $collection->addFieldToFilter('country_id', array('nin' => $euCountries));
1031
-
1032
- return $this;
1033
- }
1034
-
1035
  /**
1036
  * Based on Mage_Adminhtml_Block_Widget_Grid::_addColumnFilterToCollection()
1037
  *
@@ -1065,13 +1074,12 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentGrid extends Varien_Object
1065
  /**
1066
  * Sorts the collection by a specified column in a specified direction
1067
  *
1068
- * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
1069
  * @param string $sort The column that the collection is sorted by
1070
  * @param string $dir The direction that is used to sort the collection
1071
  *
1072
  * @return $this
1073
  */
1074
- protected function _sortCollection($collection, $sort, $dir)
1075
  {
1076
  $block = $this->getBlock();
1077
  $column = $block->getColumn($sort);
70
  /**
71
  * XML path to 'shipping grid columns' setting
72
  */
73
+ const XPATH_SHIPPING_GRID_COLUMNS = 'postnl/cif_labels_and_confirming/shipping_grid_columns';
74
 
75
  /**
76
  * XML path to default selected mass action setting
77
  */
78
+ const XPATH_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
+ * XML path to show_buspakje_options setting.
87
+ */
88
+ const XPATH_SHOW_BUSPAKJE_OPTION = 'postnl/cif_labels_and_confirming/show_buspakje_option';
89
+
90
+ /**
91
+ * XML path to buspakje_calculation_mode setting.
92
+ */
93
+ const XPATH_BUSPAKJE_CALCULATION_MODE = 'postnl/cif_labels_and_confirming/buspakje_calculation_mode';
94
+
95
  /**
96
  * Gets an array of optional columns to display
97
  *
100
  public function getOptionalColumnsToDisplay()
101
  {
102
  $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
103
+ $columnsToDisplay = Mage::getStoreConfig(self::XPATH_SHIPPING_GRID_COLUMNS, $storeId);
104
 
105
  $columnsToDisplay = explode(',', $columnsToDisplay);
106
 
180
  $this->_joinCollection($collection);
181
  $this->_modifyColumns($block);
182
  $this->_addColumns($block);
183
+ $this->_applySortAndFilter();
184
  $this->_addMassaction($block);
185
 
186
  $block->setCollection($this->getCollection());
188
  }
189
 
190
  /**
191
+ * Adds additional joins to the collection that will be used by newly added columns.
192
+ *
193
+ * Resulting query:
194
+ * SELECT `main_table`.*,
195
+ * IF(
196
+ * `pakjegemak_address`.`parent_id`,
197
+ * `pakjegemak_address`.`country_id`,
198
+ * `shipping_address`.`country_id`
199
+ * ) AS `country_id`,
200
+ * IF(
201
+ * `pakjegemak_address`.`parent_id`,
202
+ * `pakjegemak_address`.`postcode`,
203
+ * `shipping_address`.`postcode`
204
+ * ) AS `postcode`,
205
+ * `order`.`shipping_method`,
206
+ * `order`.`shipping_description`,
207
+ * `postnl_shipment`.`confirm_date`,
208
+ * `postnl_shipment`.`main_barcode`,
209
+ * `postnl_shipment`.`confirm_status`,
210
+ * `postnl_shipment`.`labels_printed`,
211
+ * `postnl_shipment`.`shipping_phase`,
212
+ * `postnl_shipment`.`parcel_count`,
213
+ * `postnl_shipment`.`is_parcelware_exported`,
214
+ * `postnl_shipment`.`product_code`,
215
+ * `postnl_shipment`.`extra_cover_amount`,
216
+ * `postnl_order`.`is_pakje_gemak`,
217
+ * `postnl_order`.`delivery_date`,
218
+ * `postnl_order`.`is_pakketautomaat`,
219
+ * `postnl_order`.`type` AS `delivery_option_type`
220
+ * FROM `sales_flat_shipment_grid` AS `main_table`
221
+ * INNER JOIN `sales_flat_order` AS `order`
222
+ * ON `main_table`.`order_id`=`order`.`entity_id`
223
+ * LEFT JOIN `sales_flat_order_address` AS `shipping_address`
224
+ * ON `main_table`.`order_id`=`shipping_address`.`parent_id`
225
+ * AND `shipping_address`.`address_type`='shipping'
226
+ * LEFT JOIN `sales_flat_order_address` AS `pakjegemak_address`
227
+ * ON `main_table`.`order_id`=`pakjegemak_address`.`parent_id`
228
+ * AND `pakjegemak_address`.`address_type`='pakje_gemak'
229
+ * LEFT JOIN `tig_postnl_shipment` AS `postnl_shipment`
230
+ * ON `main_table`.`entity_id`=`postnl_shipment`.`shipment_id`
231
+ * LEFT JOIN `tig_postnl_order` AS `postnl_order`
232
+ * ON `main_table`.`order_id`=`postnl_order`.`order_id`
233
+ * ORDER BY created_at DESC
234
+ * LIMIT 20
235
  *
236
  * @param TIG_PostNL_Model_Resource_Order_Shipment_Grid_Collection $collection
237
  *
241
  {
242
  $resource = Mage::getSingleton('core/resource');
243
 
244
+ /**
245
+ * Add a conditional SELECT clause for the country_id and postcode fields. If the shipment has a PakjeGemak
246
+ * address we need the postcode and country_id from that address. Otherwise we need them from the shipping
247
+ * address.
248
+ */
249
+ $collection->addExpressionFieldToSelect(
250
+ 'country_id',
251
+ 'IF({{pakjegemak_parent_id}}, {{pakjegemak_country_id}}, {{shipping_country_id}})',
252
+ array(
253
+ 'pakjegemak_parent_id' => '`pakjegemak_address`.`parent_id`',
254
+ 'pakjegemak_country_id' => '`pakjegemak_address`.`country_id`',
255
+ 'shipping_country_id' => '`shipping_address`.`country_id`',
256
+ )
257
+ );
258
+ $collection->addExpressionFieldToSelect(
259
+ 'postcode',
260
+ 'IF({{pakjegemak_parent_id}}, {{pakjegemak_postcode}}, {{shipping_postcode}})',
261
+ array(
262
+ 'pakjegemak_parent_id' => '`pakjegemak_address`.`parent_id`',
263
+ 'pakjegemak_postcode' => '`pakjegemak_address`.`postcode`',
264
+ 'shipping_postcode' => '`shipping_address`.`postcode`',
265
+ )
266
+ );
267
+
268
  $select = $collection->getSelect();
269
 
270
  /**
271
+ * Join sales_flat_order table.
272
  */
273
  $select->joinInner(
274
  array('order' => $resource->getTableName('sales/order')),
280
  );
281
 
282
  /**
283
+ * Join sales_flat_order_address table. Once for the shipping address and once for the pakje_gemak address. We
284
+ * need both for the conditional select used to get the postcode and country_id of the destination_address.
285
  */
286
  $select->joinLeft(
287
  array('shipping_address' => $resource->getTableName('sales/order_address')),
288
  "`main_table`.`order_id`=`shipping_address`.`parent_id` AND `shipping_address`.`address_type`='shipping'",
289
+ array()
290
+ );
291
+ $select->joinLeft(
292
+ array('pakjegemak_address' => $resource->getTableName('sales/order_address')),
293
+ "`main_table`.`order_id`=`pakjegemak_address`.`parent_id`" .
294
+ " AND `pakjegemak_address`.`address_type`='pakje_gemak'",
295
+ array()
296
  );
297
 
298
  /**
299
+ * Join tig_postnl_shipment table.
300
  */
301
  $select->joinLeft(
302
  array('postnl_shipment' => $resource->getTableName('postnl_core/shipment')),
311
  'is_parcelware_exported' => 'postnl_shipment.is_parcelware_exported',
312
  'product_code' => 'postnl_shipment.product_code',
313
  'extra_cover_amount' => 'postnl_shipment.extra_cover_amount',
314
+ 'shipment_type' => 'postnl_shipment.shipment_type',
315
  )
316
  );
317
 
318
  /**
319
+ * Join tig_postnl_order table.
320
  */
321
  $select->joinLeft(
322
  array('postnl_order' => $resource->getTableName('postnl_core/order')),
323
  '`main_table`.`order_id`=`postnl_order`.`order_id`',
324
  array(
325
+ 'delivery_date' => 'postnl_order.delivery_date',
 
 
 
326
  )
327
  );
328
 
398
  'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_shippingDescription',
399
  'column_css_class' => 'nobr',
400
  'options' => Mage::getModel('postnl_core/system_config_source_allProductOptions')
401
+ ->getAvailableOptions(true),
402
  ),
403
  $after
404
  );
412
  array(
413
  'header' => $helper->__('Shipment type'),
414
  'align' => 'left',
415
+ 'index' => 'shipment_type',
416
  'type' => 'options',
417
  'renderer' => 'postnl_adminhtml/widget_grid_column_renderer_shipmentType',
418
  'width' => '75px',
 
419
  'sortable' => false,
420
  'options' => array(
421
  'nl' => $helper->__('Domestic'),
425
  'pakketautomaat' => $helper->__('Parcel Dispenser'),
426
  'avond' => $helper->__('Evening Delivery'),
427
  'pakje_gemak_express' => $helper->__('Early Pickup'),
428
+ 'buspakje' => $helper->__('Letter Box Parcel'),
429
  ),
430
  ),
431
  $after
445
  'filter_index' => 'postnl_shipment.product_code',
446
  'column_css_class' => 'nobr',
447
  'options' => Mage::getModel('postnl_core/system_config_source_allProductOptions')
448
+ ->getAvailableOptions(true),
449
  ),
450
  $after
451
  );
461
  'align' => 'left',
462
  'index' => 'extra_cover_amount',
463
  'type' => 'currency',
464
+ 'currency_code' => Mage::app()->getStore()->getBaseCurrencyCode(), //returns the base currency
465
+ //code for the admin store
466
  ),
467
  $after
468
  );
619
  if ($helper->checkIsPostnlActionAllowed('confirm')) {
620
  $actions[] = array(
621
  'caption' => $helper->__('Confirm'),
622
+ 'url' => array('base' => 'postnl_admin/adminhtml_shipment/confirm'),
623
  'field' => 'shipment_id',
624
  'is_postnl' => true, //custom flag for renderer
625
  'code' => 'postnl_confirm',
653
 
654
  $class = $this->_getConfirmDateClass($row, $column);
655
 
656
+ if (!empty($class) && empty($value)) {
657
+ $class = '';
658
+ }
659
+
660
  return '<span class="'.$class.'"><span>'.$value.'</span></span>';
661
  }
662
 
670
  */
671
  protected function _getConfirmDateClass($row, $column)
672
  {
673
+
674
+ $origValue = $row->getData($column->getIndex());
675
+
676
+ if (!$origValue) {
677
+ return '';
678
+ }
679
+
680
+ $dateModel = Mage::getModel('core/date');
681
+
682
  /**
683
  * @var TIG_PostNL_Model_Core_Shipment $postnlShipmentClass
684
  */
685
+ $origDate = new DateTime($origValue);
686
+ $now = new DateTime($dateModel->gmtDate());
687
+ $interval = $now->diff($origDate);
688
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
689
 
690
+ if ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_CONFIRMED
691
+ || ($row->getData('confirm_status') == $postnlShipmentClass::CONFIRM_STATUS_BUSPAKJE
692
+ && $interval->d >= 1
693
+ && $interval->invert
694
+ )
695
+ ) {
696
  return 'grid-severity-notice';
697
  }
698
 
700
  return 'grid-severity-critical';
701
  }
702
 
703
+ if ($interval->d == 0) {
 
 
704
  return 'grid-severity-major';
705
  }
706
 
707
+ if ($interval->d >= 1 && $interval->invert) {
 
 
708
  return 'grid-severity-critical';
709
  }
710
 
711
+ return 'grid-severity-minor';
 
 
 
 
712
  }
713
 
714
  /**
742
  case $postnlShipmentClass::CONFIRM_STATUS_CONFIRM_EXPIRED:
743
  $class = 'grid-severity-critical';
744
  break;
745
+ case $postnlShipmentClass::CONFIRM_STATUS_BUSPAKJE:
746
+ $class = 'grid-severity-notice no-display';
747
+ break;
748
  default:
749
  $class = '';
750
  break;
751
  }
752
+
753
+ if (!empty($class) && empty($value)) {
754
+ $class = '';
755
+ }
756
+
757
  return '<span class="'.$class.'"><span>'.$value.'</span></span>';
758
  }
759
 
787
  $class = '';
788
  break;
789
  }
790
+
791
+ if (!empty($class) && empty($value)) {
792
+ $class = '';
793
+ }
794
+
795
  return '<span class="'.$class.'"><span>'.$value.'</span></span>';
796
  }
797
 
817
  $postnlShipmentClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
818
 
819
  switch ($row->getData($column->getIndex())) {
820
+ case null: //rows with no value (non-PostNL shipments) or unconfirmed shipments.
821
  $class = '';
822
  break;
 
 
823
  case $postnlShipmentClass::SHIPPING_PHASE_DELIVERED:
824
  $class = 'grid-severity-notice';
825
  break;
826
+ case $postnlShipmentClass::SHIPPING_PHASE_SORTING: //no break;
827
+ case $postnlShipmentClass::SHIPPING_PHASE_DISTRIBUTION: //no break;
828
  case $postnlShipmentClass::SHIPPING_PHASE_COLLECTION:
829
  $class = 'grid-severity-minor';
830
  break;
835
  $class = '';
836
  break;
837
  }
838
+
839
+ if (!empty($class) && empty($value)) {
840
+ $class = '';
841
+ }
842
+
843
  return '<span class="'.$class.'"><span>'.$value.'</span></span>';
844
  }
845
 
861
  * Build all the mass action option arrays
862
  */
863
  $printAndConfirmOptions = array(
864
+ 'label' => $helper->__('PostNL - Print shipping labels & confirm shipment'),
865
+ 'url' => $adminhtmlHelper->getUrl('postnl_admin/adminhtml_shipment/massPrintLabelsAndConfirm'),
866
  );
867
 
868
  $printOptions = array(
869
+ 'label' => $helper->__('PostNL - Print shipping labels'),
870
+ 'url' => $adminhtmlHelper->getUrl('postnl_admin/adminhtml_shipment/massPrintLabels'),
871
+ );
872
+
873
+ $packingSlipOptions = array(
874
+ 'label' => $helper->__('PostNL - Print packing slips'),
875
+ 'url' => $adminhtmlHelper->getUrl('postnl_admin/adminhtml_shipment/massPrintPackingslips'),
876
  );
877
 
878
  $confirmOptions = array(
892
  /**
893
  * Get the additional options block for 'label printing' mass actions.
894
  */
895
+ $printAdditional = Mage::app()
896
+ ->getLayout()
897
+ ->createBlock(
898
+ 'postnl_adminhtml/widget_grid_massaction_item_additional_labelStartPos'
899
+ );
900
 
901
  $printAdditional->setData(
902
+ array(
903
+ 'name' => 'print_start_pos',
904
+ 'label' => $helper->__('Choose printing start position'),
905
+ )
906
  );
907
 
908
  /**
916
  * Check which mass action should be selected by default
917
  */
918
  $defaultSelectedOption = Mage::getStoreConfig(
919
+ self::XPATH_SHIPPING_GRID_MASSACTION_DEFAULT,
920
  Mage_Core_Model_App::ADMIN_STORE_ID
921
  );
922
 
930
  case 'postnl_print_labels':
931
  $printOptions['selected'] = true;
932
  break;
933
+ case 'postnl_print_packing_slips':
934
+ $packingSlipOptions['selected'] = true;
935
+ break;
936
  case 'postnl_confirm_shipments':
937
  $confirmOptions['selected'] = true;
938
  break;
942
  // no default
943
  }
944
 
945
+ $printAllowed = $helper->checkIsPostnlActionAllowed('print_label');
946
+ $packingSlipAllowed = $helper->checkIsPostnlActionAllowed('print_packing_slips');
947
+ $confirmAllowed = $helper->checkIsPostnlActionAllowed('confirm');
948
+ $exportAllowed = $helper->checkIsPostnlActionAllowed('create_parcelware_export');
949
 
950
  /**
951
  * Add the mass actions to the grid if the current admin user is allowed to use them.
964
  );
965
  }
966
 
967
+ if ($printAllowed && $packingSlipAllowed) {
968
+ $massactionBlock->addItem(
969
+ 'postnl_print_packing_slips',
970
+ $packingSlipOptions
971
+ );
972
+ }
973
+
974
  if ($confirmAllowed) {
975
  $massactionBlock->addItem(
976
  'postnl_confirm_shipments',
992
  /**
993
  * Applies sorting and filtering to the collection
994
  *
 
 
995
  * @return $this
996
  */
997
+ protected function _applySortAndFilter()
998
  {
999
  $session = Mage::getSingleton('adminhtml/session');
1000
 
1002
  $filter = Mage::helper('adminhtml')->prepareFilterString($filter);
1003
 
1004
  if ($filter) {
1005
+ $this->_filterCollection($filter);
1006
  }
1007
 
1008
  $sort = $session->getData(self::SHIPMENT_GRID_SORT_VAR_NAME);
1010
  if ($sort) {
1011
  $dir = $session->getData(self::SHIPMENT_GRID_DIR_VAR_NAME);
1012
 
1013
+ $this->_sortCollection($sort, $dir);
1014
  }
1015
 
1016
  return $this;
1019
  /**
1020
  * Adds new filters to the collection if these filters are based on columns added by this observer
1021
  *
 
1022
  * @param array $filter Array of filters to be added
1023
  *
1024
  * @return $this
1025
  */
1026
+ protected function _filterCollection($filter)
1027
  {
1028
  $block = $this->getBlock();
1029
 
1030
  foreach ($filter as $columnName => $value) {
1031
  $column = $block->getColumn($columnName);
1032
+
1033
  if (!$column) {
1034
  continue;
1035
  }
1041
  return $this;
1042
  }
1043
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1044
  /**
1045
  * Based on Mage_Adminhtml_Block_Widget_Grid::_addColumnFilterToCollection()
1046
  *
1074
  /**
1075
  * Sorts the collection by a specified column in a specified direction
1076
  *
 
1077
  * @param string $sort The column that the collection is sorted by
1078
  * @param string $dir The direction that is used to sort the collection
1079
  *
1080
  * @return $this
1081
  */
1082
+ protected function _sortCollection($sort, $dir)
1083
  {
1084
  $block = $this->getBlock();
1085
  $column = $block->getColumn($sort);
app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentView.php CHANGED
@@ -50,7 +50,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
50
  *
51
  * @param Varien_Event_Observer $observer
52
  *
53
- * @return TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
54
  *
55
  * @event adminhtml_block_html_before
56
  *
@@ -83,11 +83,12 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
83
  }
84
 
85
  /**
86
- * Check if the current shipment was placed with PostNL
 
 
87
  */
88
  $shipment = Mage::registry('current_shipment');
89
- $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
90
- if (!in_array($shipment->getOrder()->getShippingMethod(), $postnlShippingMethods)) {
91
  return $this;
92
  }
93
 
@@ -122,6 +123,8 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
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
@@ -147,15 +150,74 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
147
  . ' and labels associated with this shipment. You can not undo this action.'
148
  );
149
 
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
  }
160
 
161
  /**
@@ -164,46 +226,60 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
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 "
182
- . "shipping label before you can send this shipment."
183
- );
 
184
 
185
- $block->addButton('remove_shipping_labels', array(
186
- 'label' => $helper->__('PostNL - Remove Shipping Label'),
187
- 'onclick' => "deleteConfirm('"
188
- . $removeLabelsWarningMessage
189
- . "', '"
190
- . $removeLabelsUrl
191
- . "')",
192
- 'class' => 'delete',
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;
@@ -296,4 +372,44 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
296
 
297
  return $url;
298
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  }
50
  *
51
  * @param Varien_Event_Observer $observer
52
  *
53
+ * @return $this
54
  *
55
  * @event adminhtml_block_html_before
56
  *
83
  }
84
 
85
  /**
86
+ * Check if the current shipment was placed with PostNL.
87
+ *
88
+ * @var Mage_Sales_Model_Order_Shipment $shipment
89
  */
90
  $shipment = Mage::registry('current_shipment');
91
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shipment->getOrder()->getShippingMethod())) {
 
92
  return $this;
93
  }
94
 
123
  $deleteLabelsAllowed = $helper->checkIsPostnlActionAllowed('delete_labels');
124
  $resetConfirmAllowed = $helper->checkIsPostnlActionAllowed(array('reset_confirmation', 'delete_labels'));
125
  $sendTrackAndTraceAllowed = $helper->checkIsPostnlActionAllowed('send_track_and_trace');
126
+ $convertToBuspakjeAllowed = $helper->checkIsPostnlActionAllowed('convert_to_buspakje');
127
+ $convertToPackageAllowed = $helper->checkIsPostnlActionAllowed('convert_to_package');
128
 
129
  /**
130
  * Add a button to print this shipment's shipping labels
150
  . ' and labels associated with this shipment. You can not undo this action.'
151
  );
152
 
153
+ $block->addButton(
154
+ 'reset_confirmation',
155
+ array(
156
+ 'label' => $helper->__('PostNL - Change Confirmation'),
157
+ 'onclick' => "deleteConfirm('"
158
+ . $resetWarningMessage
159
+ . "', '"
160
+ . $resetConfirmationUrl
161
+ . "')",
162
+ 'class' => 'delete',
163
+ )
164
+ );
165
+ }
166
+
167
+ if ($postnlShipment->canConvertShipmentToBuspakje() && $convertToBuspakjeAllowed
168
+ && (!$postnlShipment->isConfirmed()
169
+ || ($postnlShipment->canResetConfirmation()
170
+ && $resetConfirmAllowed
171
+ )
172
+ )
173
+ ) {
174
+ $convertToBuspakjeUrl = $this->getConvertToBuspakjeUrl($shipment->getId());
175
+ $convertToBuspakjeMessage = $helper->__(
176
+ 'Are you sure you wish to convert this shipment to a letter box parcel? You will need to confirm this' .
177
+ ' shipment with PostNL again before you can send it. This action will remove all barcodes and labels ' .
178
+ 'associated with this shipment. You can not undo this action.'
179
+ );
180
+
181
+ $block->addButton(
182
+ 'convert_to_buspakje',
183
+ array(
184
+ 'label' => $helper->__('PostNL - Convert to Letter Box Parcel'),
185
+ 'onclick' => "deleteConfirm('"
186
+ . $convertToBuspakjeMessage
187
+ . "', '"
188
+ . $convertToBuspakjeUrl
189
+ . "')",
190
+ 'class' => 'btn-reset',
191
+ )
192
+ );
193
+ }
194
+
195
+ if ($postnlShipment->canConvertShipmentToPackage() && $convertToPackageAllowed
196
+ && (!$postnlShipment->isConfirmed()
197
+ || ($postnlShipment->canResetConfirmation()
198
+ && $resetConfirmAllowed
199
+ )
200
+ )
201
+ ) {
202
+ $convertToPackageUrl = $this->getConvertToPackageUrl($shipment->getId());
203
+ $convertToPackageMessage = $helper->__(
204
+ 'Are you sure you wish to convert this shipment to a package? You will need to confirm this shipment ' .
205
+ 'with PostNL again before you can send it. This action will remove all barcodes and labels associated' .
206
+ ' with this shipment. You can not undo this action.'
207
+ );
208
+
209
+ $block->addButton(
210
+ 'convert_to_package',
211
+ array(
212
+ 'label' => $helper->__('PostNL - Convert to Package'),
213
+ 'onclick' => "deleteConfirm('"
214
+ . $convertToPackageMessage
215
+ . "', '"
216
+ . $convertToPackageUrl
217
+ . "')",
218
+ 'class' => 'btn-reset',
219
+ )
220
+ );
221
  }
222
 
223
  /**
226
  if ($postnlShipment->isConfirmed() && $sendTrackAndTraceAllowed) {
227
  $resendTrackAndTraceUrl = $this->getResendTrackAndTraceUrl($shipment->getId());
228
 
229
+ $block->updateButton(
230
+ 'save',
231
+ 'label',
232
+ $helper->__('PostNL - Send Tracking Information')
233
+ );
234
+ $block->updateButton(
235
+ 'save',
236
+ 'onclick',
237
  "deleteConfirm('"
238
  . $helper->__('Are you sure you want to send PostNL tracking information to the customer?')
239
  . "', '" . $resendTrackAndTraceUrl . "')"
240
  );
241
  }
242
 
243
+ if (!$postnlShipment->isConfirmed()) {
244
+ /**
245
+ * Add a button to remove any stored shipping labels for this shipment.
246
+ */
247
+ if ($postnlShipment->hasLabels() && $deleteLabelsAllowed) {
248
+ $removeLabelsUrl = $this->getRemoveLabelsUrl($shipment->getId());
249
+ $removeLabelsWarningMessage = $helper->__(
250
+ "Are you sure that you wish to remove this shipment\'s shipping label? You will need to print a new "
251
+ . "shipping label before you can send this shipment."
252
+ );
253
 
254
+ $block->addButton(
255
+ 'remove_shipping_labels',
256
+ array(
257
+ 'label' => $helper->__('PostNL - Remove Shipping Label'),
258
+ 'onclick' => "deleteConfirm('"
259
+ . $removeLabelsWarningMessage
260
+ . "', '"
261
+ . $removeLabelsUrl
262
+ . "')",
263
+ 'class' => 'delete',
264
+ )
265
+ );
266
+ }
267
 
268
+ /**
269
+ * Add a button to confirm this shipment.
270
+ */
271
+ if ($postnlShipment->canConfirm() && $confirmAllowed) {
272
+ $confirmUrl = $this->getConfirmUrl($shipment->getId());
273
 
274
+ $block->addButton(
275
+ 'confirm_shipment',
276
+ array(
277
+ 'label' => $helper->__('PostNL - Confirm Shipment'),
278
+ 'onclick' => "setLocation('{$confirmUrl}')",
279
+ 'class' => 'save',
280
+ )
281
+ );
282
+ }
283
  }
284
 
285
  return $this;
372
 
373
  return $url;
374
  }
375
+
376
+ /**
377
+ * Get adminhtml url for PostNL convert_to_buspakje shipment action
378
+ *
379
+ * @param int $shipmentId The ID of the current shipment
380
+ *
381
+ * @return string
382
+ */
383
+ public function getConvertToBuspakjeUrl($shipmentId)
384
+ {
385
+ $url = Mage::helper('adminhtml')->getUrl(
386
+ 'postnl_admin/adminhtml_shipment/convertToBuspakje',
387
+ array(
388
+ 'shipment_id' => $shipmentId,
389
+ 'return_to_view' => true,
390
+ )
391
+ );
392
+
393
+ return $url;
394
+ }
395
+
396
+ /**
397
+ * Get adminhtml url for PostNL convert_to_package shipment action
398
+ *
399
+ * @param int $shipmentId The ID of the current shipment
400
+ *
401
+ * @return string
402
+ */
403
+ public function getConvertToPackageUrl($shipmentId)
404
+ {
405
+ $url = Mage::helper('adminhtml')->getUrl(
406
+ 'postnl_admin/adminhtml_shipment/convertToPackage',
407
+ array(
408
+ 'shipment_id' => $shipmentId,
409
+ 'return_to_view' => true,
410
+ )
411
+ );
412
+
413
+ return $url;
414
+ }
415
  }
app/code/community/TIG/PostNL/Model/Adminhtml/Observer/SystemConfig.php ADDED
@@ -0,0 +1,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.
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_Adminhtml_Observer_SystemConfig
40
+ {
41
+ /**
42
+ * Adds a button to the system > config page for the PostNL section, allowing the admin to download all PostNL debug
43
+ * logs.
44
+ *
45
+ * @param Varien_Event_Observer $observer
46
+ *
47
+ * @return $this
48
+ *
49
+ * @event controller_action_layout_render_before_adminhtml_system_config_edit
50
+ *
51
+ * @observer postnl_add_download_log_button
52
+ */
53
+ public function addDownloadLogButton(Varien_Event_Observer $observer)
54
+ {
55
+ $section = Mage::app()->getRequest()->getParam('section');
56
+ if ($section !== 'postnl') {
57
+ return $this;
58
+ }
59
+
60
+ $configEditBlock = false;
61
+ $contentBlocks = Mage::getSingleton('core/layout')->getBlock('content')->getChild();
62
+
63
+ /**
64
+ * @var Mage_Core_Block_Abstract $block
65
+ * @var Mage_Adminhtml_Block_System_Config_Edit $configEditBlock
66
+ */
67
+ foreach ($contentBlocks as $block) {
68
+ if ($block instanceof Mage_Adminhtml_Block_System_Config_Edit) {
69
+ $configEditBlock = $block;
70
+ break;
71
+ }
72
+ }
73
+
74
+ if (!$configEditBlock) {
75
+ return $this;
76
+ }
77
+
78
+ $helper = Mage::helper('postnl');
79
+
80
+ if (!$helper->checkIsPostnlActionAllowed('download_logs')) {
81
+ return false;
82
+ }
83
+
84
+ $onClickUrl = $configEditBlock->getUrl('postnl_admin/adminhtml_config/downloadLogs');
85
+ $onClick = "setLocation('{$onClickUrl}')";
86
+
87
+ /**
88
+ * @var Mage_Adminhtml_Block_Widget_Button $button
89
+ */
90
+ $button = $configEditBlock->getLayout()->createBlock('adminhtml/widget_button');
91
+ $button->setData(
92
+ array(
93
+ 'label' => $helper->__('Download PostNL log files'),
94
+ 'onclick' => $onClick,
95
+ 'class' => 'download',
96
+ )
97
+ );
98
+
99
+ $configEditBlock->setChild('download_postnl_logs_button', $button);
100
+ $configEditBlock->setTemplate('TIG/PostNL/system/config/edit.phtml');
101
+
102
+ return $this;
103
+ }
104
+ }
app/code/community/TIG/PostNL/Model/Adminhtml/Support/Logs.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Adminhtml_Support_Logs
40
+ {
41
+ /**
42
+ * Max size for individual log files and the total size of all logs (in bytes).
43
+ */
44
+ const LOG_MAX_SIZE = '104857600'; //100MB
45
+ const LOG_MAX_TOTAL_SIZE = '1073741824'; //1GB
46
+
47
+ /**
48
+ * Get all PostNL log files, merge these into a zip file and return the path to said zip file.
49
+ *
50
+ * @return string
51
+ *
52
+ * @throws TIG_PostNL_Exception
53
+ */
54
+ public function downloadLogs()
55
+ {
56
+ $helper = Mage::helper('postnl');
57
+
58
+ /**
59
+ * Get the folder where all PostNL logs are stored and make sure it exists.
60
+ */
61
+ $logFolder = Mage::getBaseDir('var') . DS . 'log' . DS . 'TIG_PostNL';
62
+ if (!is_dir($logFolder)) {
63
+ throw new TIG_PostNL_Exception(
64
+ $helper->__('No valid log files were found.'),
65
+ 'POSTNL-0172'
66
+ );
67
+ }
68
+
69
+ /**
70
+ * Get all log files in the log folder and a list of all logs that are allowed for this download.
71
+ */
72
+ $logs = glob($logFolder . DS . '*.log');
73
+ $allowedLogs = Mage::helper('postnl')->getLogFiles();
74
+
75
+ /**
76
+ * Make sure each log is valid and put the valid logs in an array with the log's filename as the key. We need
77
+ * this later on to prevent the entire directory structure from being included in the zip file.
78
+ */
79
+ $logsWithNames = array();
80
+ $totalSize = 0;
81
+ foreach ($logs as $log) {
82
+ $logName = explode(DS, $log);
83
+ $logName = end($logName);
84
+
85
+ /**
86
+ * Make sure this log is allowed.
87
+ */
88
+ if (!in_array($logName, $allowedLogs)) {
89
+ continue;
90
+ }
91
+
92
+ /**
93
+ * Make sure the log is a file and is readable.
94
+ */
95
+ if (!is_file($log) || !is_readable($log)) {
96
+ continue;
97
+ }
98
+
99
+ /**
100
+ * Make sure the log is not too large. Otherwise we won't be able to read it anyway.
101
+ */
102
+ $fileSize = filesize($log);
103
+ if ($fileSize > self::LOG_MAX_SIZE) {
104
+ $helper->addSessionMessage(
105
+ 'adminhtml/session',
106
+ 'POSTNL-0173',
107
+ 'warning',
108
+ $helper->__(
109
+ 'Log %s is too large (%.2fMB) and was skipped.',
110
+ $logName,
111
+ $fileSize / 1024 / 1024
112
+ )
113
+ );
114
+
115
+ continue;
116
+ }
117
+
118
+ /**
119
+ * Add the log's filesize to the total size of all valid logs and add the log to the array.
120
+ */
121
+ $totalSize += $fileSize;
122
+ $logsWithNames[$logName] = $log;
123
+ }
124
+
125
+ /**
126
+ * If we have no valid logs, there is nothing to do.
127
+ */
128
+ if (empty($logsWithNames)) {
129
+ throw new TIG_PostNL_Exception(
130
+ $helper->__('No valid log files were found.'),
131
+ 'POSTNL-0172'
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Make sure the total size of all logs is not too large.
137
+ */
138
+ if ($totalSize > self::LOG_MAX_TOTAL_SIZE) {
139
+ throw new TIG_PostNL_Exception(
140
+ $helper->__('The total size of all log files exceeds the maximum size allowed.'),
141
+ 'POSTNL-0174'
142
+ );
143
+ }
144
+
145
+ /**
146
+ * Creating the zip file for large logs may take a while, so disable the PHP time limit.
147
+ */
148
+ set_time_limit(0);
149
+
150
+ /**
151
+ * Get the path to the final zip file.
152
+ */
153
+ $zipPath = $logFolder
154
+ . 'TIG_PostNL-logs-'
155
+ . date('Ymd-His', Mage::getSingleton('core/date')->timestamp())
156
+ . '.zip';
157
+
158
+ /**
159
+ * Open the zip file. Overwriting the previous file if it exists.
160
+ */
161
+ $zip = new ZipArchive();
162
+ $zip->open($zipPath, ZipArchive::OVERWRITE);
163
+
164
+ /**
165
+ * Add all the log files.
166
+ */
167
+ foreach ($logsWithNames as $name => $log) {
168
+ $zip->addFile($log, $name);
169
+ }
170
+
171
+ /**
172
+ * Close the zip file.
173
+ */
174
+ $zip->close();
175
+
176
+ return $zipPath;
177
+ }
178
+ }
app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/OrderGridColumns.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
+ class TIG_PostNL_Model_Adminhtml_System_Config_Source_OrderGridColumns
40
+ {
41
+ /**
42
+ * Returns an option array for optional shipment grid columns
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
+ {
48
+ $helper = Mage::helper('postnl');
49
+ $columns = array(
50
+ array(
51
+ 'value' => 'shipment_type',
52
+ 'label' => $helper->__('Shipment type')
53
+ ),
54
+ array(
55
+ 'value' => 'confirm_date',
56
+ 'label' => $helper->__('Send date')
57
+ ),
58
+ array(
59
+ 'value' => 'confirm_status',
60
+ 'label' => $helper->__('Confirm Status')
61
+ ),
62
+ array(
63
+ 'value' => 'shipping_phase',
64
+ 'label' => $helper->__('Shipping phase')
65
+ ),
66
+ );
67
+
68
+ return $columns;
69
+ }
70
+ }
app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/OrderGridMassaction.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
+ class TIG_PostNL_Model_Adminhtml_System_Config_Source_OrderGridMassaction
40
+ {
41
+ /**
42
+ * Returns an option array for available order grid mass actions.
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
+ {
48
+ $helper = Mage::helper('postnl');
49
+ $options = array(
50
+ array(
51
+ 'value' => '',
52
+ 'label' => $helper->__('None'),
53
+ ),
54
+ array(
55
+ 'value' => 'postnl_create_shipments',
56
+ 'label' => $helper->__('Create shipments'),
57
+ ),
58
+ array(
59
+ 'value' => 'postnl_create_shipment_print_label_and_confirm',
60
+ 'label' => $helper->__('Create shipments, print labels and confirm'),
61
+ ),
62
+ array(
63
+ 'value' => 'postnl_print_packing_slips',
64
+ 'label' => $helper->__('Print packing slips'),
65
+ ),
66
+ );
67
+
68
+ return $options;
69
+ }
70
+ }
app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/ShipmentGridMassaction.php CHANGED
@@ -39,7 +39,7 @@
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
  */
@@ -47,6 +47,10 @@ class TIG_PostNL_Model_Adminhtml_System_Config_Source_ShipmentGridMassAction
47
  {
48
  $helper = Mage::helper('postnl');
49
  $options = array(
 
 
 
 
50
  array(
51
  'value' => 'postnl_print_labels_and_confirm',
52
  'label' => $helper->__('Print shipping labels & confirm shipment'),
@@ -55,6 +59,10 @@ class TIG_PostNL_Model_Adminhtml_System_Config_Source_ShipmentGridMassAction
55
  'value' => 'postnl_print_labels',
56
  'label' => $helper->__('Print shipping labels'),
57
  ),
 
 
 
 
58
  array(
59
  'value' => 'postnl_confirm_shipments',
60
  'label' => $helper->__('Confirm shipments'),
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
  */
47
  {
48
  $helper = Mage::helper('postnl');
49
  $options = array(
50
+ array(
51
+ 'value' => '',
52
+ 'label' => $helper->__('None'),
53
+ ),
54
  array(
55
  'value' => 'postnl_print_labels_and_confirm',
56
  'label' => $helper->__('Print shipping labels & confirm shipment'),
59
  'value' => 'postnl_print_labels',
60
  'label' => $helper->__('Print shipping labels'),
61
  ),
62
+ array(
63
+ 'value' => 'postnl_print_packing_slips',
64
+ 'label' => $helper->__('Print packing slips'),
65
+ ),
66
  array(
67
  'value' => 'postnl_confirm_shipments',
68
  'label' => $helper->__('Confirm shipments'),
app/code/community/TIG/PostNL/Model/Carrier/Postnl.php CHANGED
@@ -51,7 +51,7 @@ class TIG_PostNL_Model_Carrier_Postnl extends Mage_Shipping_Model_Carrier_Abstra
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.
@@ -93,41 +93,6 @@ class TIG_PostNL_Model_Carrier_Postnl extends Mage_Shipping_Model_Carrier_Abstra
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
  *
@@ -197,7 +162,7 @@ class TIG_PostNL_Model_Carrier_Postnl extends Mage_Shipping_Model_Carrier_Abstra
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);
@@ -270,8 +235,6 @@ class TIG_PostNL_Model_Carrier_Postnl extends Mage_Shipping_Model_Carrier_Abstra
270
  $shippingPrice = '0.00';
271
  }
272
 
273
- $shippingPrice += $this->getPostnlFee();
274
-
275
  $method->setPrice($shippingPrice);
276
  $method->setCost($shippingPrice);
277
 
@@ -361,8 +324,6 @@ class TIG_PostNL_Model_Carrier_Postnl extends Mage_Shipping_Model_Carrier_Abstra
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) {
@@ -405,35 +366,6 @@ class TIG_PostNL_Model_Carrier_Postnl extends Mage_Shipping_Model_Carrier_Abstra
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
  *
@@ -501,10 +433,14 @@ class TIG_PostNL_Model_Carrier_Postnl extends Mage_Shipping_Model_Carrier_Abstra
501
  */
502
  public function getAllowedMethods()
503
  {
504
- return array(
505
- 'flatrate' => $this->getConfigData('name') . ' flat',
506
- 'tablerate' => $this->getConfigData('name') . ' table'
 
 
507
  );
 
 
508
  }
509
 
510
  /**
@@ -525,11 +461,25 @@ class TIG_PostNL_Model_Carrier_Postnl extends Mage_Shipping_Model_Carrier_Abstra
525
 
526
  $shippingAddress = $shipment->getShippingAddress();
527
 
 
 
 
 
 
 
 
 
 
 
 
 
528
  $statusModel->setCarrier($track->getCarrierCode())
529
  ->setCarrierTitle($this->getConfigData('name'))
530
  ->setTracking($track->getTrackNumber())
531
  ->setPopup(1)
532
- ->setUrl($this->getHelper()->getBarcodeUrl($track->getTrackNumber(), $shippingAddress, $lang, false));
 
 
533
 
534
  return $statusModel;
535
  }
51
  /**
52
  * Rate type (tablerate or flatrate).
53
  */
54
+ const XPATH_RATE_TYPE = 'carriers/postnl/rate_type';
55
 
56
  /**
57
  * Whether to use Magento's tabelrates or PostNL's.
93
  }
94
  }
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  /**
97
  * get PostNL Carrier helper
98
  *
162
  }
163
  }
164
 
165
+ $rateType = Mage::getStoreConfig(self::XPATH_RATE_TYPE, Mage::app()->getStore()->getId());
166
 
167
  if ($rateType == 'flat') {
168
  $result = $this->_getFlatRate($request);
235
  $shippingPrice = '0.00';
236
  }
237
 
 
 
238
  $method->setPrice($shippingPrice);
239
  $method->setCost($shippingPrice);
240
 
324
  $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
325
  }
326
 
 
 
327
  $price = $shippingPrice;
328
  $cost = $rate['cost'];
329
  } elseif (empty($rate) && $request->getFreeShipping() === true) {
366
  return $result;
367
  }
368
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  /**
370
  * @param Mage_Shipping_Model_Rate_Request $request
371
  *
433
  */
434
  public function getAllowedMethods()
435
  {
436
+ $helper = Mage::helper('postnl');
437
+
438
+ $methods = array(
439
+ 'flatrate' => $this->getConfigData('name') . ' (' . $helper->__('flat rate') . ')',
440
+ 'tablerate' => $this->getConfigData('name') . ' (' . $helper->__('table rate') . ')',
441
  );
442
+
443
+ return $methods;
444
  }
445
 
446
  /**
461
 
462
  $shippingAddress = $shipment->getShippingAddress();
463
 
464
+ /**
465
+ * @var Mage_Sales_Model_Order_Address $address
466
+ */
467
+ $addresses = $shipment->getOrder()->getAddressesCollection();
468
+ foreach ($addresses as $address) {
469
+ if ($address->getAddressType() == 'pakje_gemak') {
470
+ $shippingAddress = $address;
471
+ break;
472
+ }
473
+ }
474
+
475
+
476
  $statusModel->setCarrier($track->getCarrierCode())
477
  ->setCarrierTitle($this->getConfigData('name'))
478
  ->setTracking($track->getTrackNumber())
479
  ->setPopup(1)
480
+ ->setUrl(
481
+ $this->getHelper()->getBarcodeUrl($track->getTrackNumber(), $shippingAddress, $lang, false)
482
+ );
483
 
484
  return $statusModel;
485
  }
app/code/community/TIG/PostNL/Model/Carrier/Quote/Address/Total/Shipping.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Quote_Address_Total_Shipping
40
+ extends Mage_Sales_Model_Quote_Address_Total_Shipping
41
+ {
42
+ /**
43
+ * Collect totals information about shipping
44
+ *
45
+ * @param Mage_Sales_Model_Quote_Address $address
46
+ * @return Mage_Sales_Model_Quote_Address_Total_Shipping
47
+ */
48
+ public function collect(Mage_Sales_Model_Quote_Address $address)
49
+ {
50
+ Mage_Sales_Model_Quote_Address_Total_Abstract::collect($address);
51
+
52
+ $address->setWeight(0);
53
+ $address->setFreeMethodWeight(0);
54
+ $this->_setAmount(0)
55
+ ->_setBaseAmount(0);
56
+
57
+ $items = $this->_getAddressItems($address);
58
+ if (!count($items)) {
59
+ return $this;
60
+ }
61
+
62
+ $method = $address->getShippingMethod();
63
+
64
+ /**
65
+ * If the shipping method is not PostNL, load the regular shipping total model to process the total. We can't
66
+ * just return the parent, because another extension might rewrite the regular total model. This way the rewrite
67
+ * is only ignored for PostNL shipments at a slight cost to performance (roughly 0.0005s).
68
+ */
69
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($method)) {
70
+ return Mage::getModel('sales/quote_address_total_shipping')->collect($address);
71
+ }
72
+
73
+ $freeAddress= $address->getFreeShipping();
74
+
75
+ $addressWeight = $address->getWeight();
76
+ $freeMethodWeight = $address->getFreeMethodWeight();
77
+
78
+ $addressQty = 0;
79
+
80
+ /**
81
+ * @var Mage_Sales_Model_Quote_Item $item
82
+ * @var Mage_Sales_Model_Quote_Item $child
83
+ */
84
+ foreach ($items as $item) {
85
+ /**
86
+ * Skip if this item is virtual
87
+ */
88
+ if ($item->getProduct()->isVirtual()) {
89
+ continue;
90
+ }
91
+
92
+ /**
93
+ * Children weight we calculate for parent
94
+ */
95
+ if ($item->getParentItem()) {
96
+ continue;
97
+ }
98
+
99
+ if ($item->getHasChildren() && $item->isShipSeparately()) {
100
+ foreach ($item->getChildren() as $child) {
101
+ if ($child->getProduct()->isVirtual()) {
102
+ continue;
103
+ }
104
+ $addressQty += $child->getTotalQty();
105
+
106
+ if (!$item->getProduct()->getWeightType()) {
107
+ $itemWeight = $child->getWeight();
108
+ $itemQty = $child->getTotalQty();
109
+ $rowWeight = $itemWeight*$itemQty;
110
+ $addressWeight += $rowWeight;
111
+ if ($freeAddress || $child->getFreeShipping()===true) {
112
+ $rowWeight = 0;
113
+ } elseif (is_numeric($child->getFreeShipping())) {
114
+ $freeQty = $child->getFreeShipping();
115
+ if ($itemQty>$freeQty) {
116
+ $rowWeight = $itemWeight*($itemQty-$freeQty);
117
+ }
118
+ else {
119
+ $rowWeight = 0;
120
+ }
121
+ }
122
+ $freeMethodWeight += $rowWeight;
123
+ $item->setRowWeight($rowWeight);
124
+ }
125
+ }
126
+ if ($item->getProduct()->getWeightType()) {
127
+ $itemWeight = $item->getWeight();
128
+ $rowWeight = $itemWeight*$item->getQty();
129
+ $addressWeight+= $rowWeight;
130
+ if ($freeAddress || $item->getFreeShipping()===true) {
131
+ $rowWeight = 0;
132
+ } elseif (is_numeric($item->getFreeShipping())) {
133
+ $freeQty = $item->getFreeShipping();
134
+ if ($item->getQty()>$freeQty) {
135
+ $rowWeight = $itemWeight*($item->getQty()-$freeQty);
136
+ }
137
+ else {
138
+ $rowWeight = 0;
139
+ }
140
+ }
141
+ $freeMethodWeight+= $rowWeight;
142
+ $item->setRowWeight($rowWeight);
143
+ }
144
+ }
145
+ else {
146
+ if (!$item->getProduct()->isVirtual()) {
147
+ $addressQty += $item->getQty();
148
+ }
149
+ $itemWeight = $item->getWeight();
150
+ $rowWeight = $itemWeight*$item->getQty();
151
+ $addressWeight+= $rowWeight;
152
+ if ($freeAddress || $item->getFreeShipping()===true) {
153
+ $rowWeight = 0;
154
+ } elseif (is_numeric($item->getFreeShipping())) {
155
+ $freeQty = $item->getFreeShipping();
156
+ if ($item->getQty()>$freeQty) {
157
+ $rowWeight = $itemWeight*($item->getQty()-$freeQty);
158
+ }
159
+ else {
160
+ $rowWeight = 0;
161
+ }
162
+ }
163
+ $freeMethodWeight+= $rowWeight;
164
+ $item->setRowWeight($rowWeight);
165
+ }
166
+ }
167
+
168
+ if (isset($addressQty)) {
169
+ $address->setItemQty($addressQty);
170
+ }
171
+
172
+ $address->setWeight($addressWeight);
173
+ $address->setFreeMethodWeight($freeMethodWeight);
174
+
175
+ $address->collectShippingRates();
176
+
177
+ $this->_setAmount(0)
178
+ ->_setBaseAmount(0);
179
+
180
+ if (!$method) {
181
+ return $this;
182
+ }
183
+
184
+ /**
185
+ * @var Mage_Sales_Model_Quote_Address_Rate $rate
186
+ */
187
+ foreach ($address->getAllShippingRates() as $rate) {
188
+ if ($rate->getCode() != $method) {
189
+ continue;
190
+ }
191
+
192
+ $price = $rate->getPrice();
193
+
194
+ $postnlOrder = Mage::getModel('postnl_core/order');
195
+
196
+ $postnlOrder->load($address->getQuoteId(), 'quote_id');
197
+
198
+ if ($postnlOrder->getId() && $postnlOrder->getIsActive()) {
199
+ $type = $postnlOrder->getType();
200
+ } else {
201
+ $amountPrice = $address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
202
+ $this->_setAmount($amountPrice);
203
+ $this->_setBaseAmount($price);
204
+ $shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();
205
+ $address->setShippingDescription(trim($shippingDescription, ' -'));
206
+
207
+ break;
208
+ }
209
+
210
+ $includingTax = false;
211
+ if (Mage::getSingleton('tax/config')->shippingPriceIncludesTax()) {
212
+ $includingTax = true;
213
+ }
214
+
215
+ $fee = 0;
216
+ if ($type == 'PGE') {
217
+ $fee = Mage::helper('postnl/deliveryOptions')->getExpressFee(false, $includingTax, false);
218
+ } elseif ($type == 'Avond' ) {
219
+ $fee = Mage::helper('postnl/deliveryOptions')->getEveningFee(false, $includingTax, false);
220
+ }
221
+
222
+ $price += $fee;
223
+
224
+ $amountPrice = $address->getQuote()->getStore()->convertPrice($price, false);
225
+
226
+ $this->_setAmount($amountPrice);
227
+ $this->_setBaseAmount($price);
228
+
229
+ $shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();
230
+
231
+ $address->setShippingDescription(trim($shippingDescription, ' -'));
232
+ break;
233
+ }
234
+
235
+ return $this;
236
+ }
237
+ }
app/code/community/TIG/PostNL/Model/Checkout/Cif.php CHANGED
@@ -43,33 +43,33 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
43
  /**
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
  */
51
- const XML_PATH_NEWSLETTER_SUBSCRIPTION = 'postnl/checkout/newsletter_subscription';
52
- const XML_PATH_REMARK = 'postnl/checkout/remark';
53
- const XML_PATH_CONTACT_URL = 'postnl/checkout/contact_url';
54
- const XML_PATH_ALLOW_RETAIL_LOCATION = 'postnl/checkout/allow_retail_location';
55
- const XML_PATH_ALLOW_FOREIGN_ADDRESS = 'postnl/checkout/allow_foreign_address';
56
- const XML_PATH_ALLOW_PRICE_OVERVIEW = 'postnl/checkout/allow_price_overview';
57
- const XML_PATH_AGREE_CONDITIONS = 'postnl/checkout/agree_conditions';
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
@@ -371,7 +371,7 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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();
@@ -404,14 +404,14 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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',
@@ -456,12 +456,12 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
  }
@@ -478,7 +478,7 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
478
  {
479
  $storeId = $this->getStoreId();
480
 
481
- $contactUrl = Mage::getStoreConfig(self::XML_PATH_CONTACT_URL, $storeId);
482
  if (!$contactUrl) {
483
  return false;
484
  }
@@ -624,7 +624,7 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
@@ -641,7 +641,7 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
641
  $reference = $shipment->getOrder()->getIncrementId();
642
  break;
643
  case 'custom':
644
- $reference = Mage::getStoreConfig(self::XML_PATH_CUSTOM_SHIPMENT_REFERENCE, $storeId);
645
  break;
646
  default:
647
  throw new TIG_PostNL_Exception(
@@ -680,7 +680,7 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
680
  $parcelCount = $postnlShipment->getParcelCount();
681
 
682
  $parcelData = array();
683
- $postcode = $shipment->getShippingAddress()->getPostcode();
684
  for ($i = 0; $i < $parcelCount; $i++) {
685
  $parcelData[] = array(
686
  'Barcode' => $postnlShipment->getBarcode($i),
@@ -702,10 +702,10 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
@@ -753,7 +753,7 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
753
  {
754
  $storeId = $this->getStoreId();
755
 
756
- $serviceUrl = Mage::getStoreConfig(self::XML_PATH_SERVICE_URL, $storeId);
757
  if (!$serviceUrl) {
758
  return false;
759
  }
@@ -811,7 +811,7 @@ class TIG_PostNL_Model_Checkout_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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(
43
  /**
44
  * Webshop ID config option path
45
  */
46
+ const XPATH_WEBSHOP_ID = 'postnl/cif/webshop_id';
47
 
48
  /**
49
  * XML paths for various options
50
  */
51
+ const XPATH_NEWSLETTER_SUBSCRIPTION = 'postnl/checkout/newsletter_subscription';
52
+ const XPATH_REMARK = 'postnl/checkout/remark';
53
+ const XPATH_CONTACT_URL = 'postnl/checkout/contact_url';
54
+ const XPATH_ALLOW_RETAIL_LOCATION = 'postnl/checkout/allow_retail_location';
55
+ const XPATH_ALLOW_FOREIGN_ADDRESS = 'postnl/checkout/allow_foreign_address';
56
+ const XPATH_ALLOW_PRICE_OVERVIEW = 'postnl/checkout/allow_price_overview';
57
+ const XPATH_AGREE_CONDITIONS = 'postnl/checkout/agree_conditions';
58
+ const XPATH_SERVICE_URL = 'postnl/checkout/service_url';
59
+ const XPATH_USE_MOBILE = 'postnl/checkout/use_mobile';
60
+ const XPATH_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 XPATH_CHECKOUT_PAYMENT_METHODS = 'postnl/checkout_payment_methods';
67
 
68
  /**
69
  * XML paths for shipment reference info
70
  */
71
+ const XPATH_SHIPMENT_REFERENCE_TYPE = 'postnl/cif_labels_and_confirming/shipment_reference_type';
72
+ const XPATH_CUSTOM_SHIPMENT_REFERENCE = 'postnl/cif_labels_and_confirming/custom_shipment_reference';
73
 
74
  /**
75
  * Check if the module is set to test mode
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::XPATH_CHECKOUT_PAYMENT_METHODS, $storeId);
375
  $postnlPaymentMethods = Mage::helper('postnl/checkout')->getCheckoutPaymentMethods();
376
 
377
  $allowedMethods = array();
404
 
405
  $communicationOptions = array();
406
 
407
+ $newsletterSubscription = Mage::getStoreConfigFlag(self::XPATH_NEWSLETTER_SUBSCRIPTION, $storeId);
408
  if ($newsletterSubscription) {
409
  $communicationOptions[] = array(
410
  'Code' => 'NEWS',
411
  );
412
  }
413
 
414
+ $remark = Mage::getStoreConfigFlag(self::XPATH_REMARK, $storeId);
415
  if ($remark) {
416
  $communicationOptions[] = array(
417
  'Code' => 'REMARK',
456
  'BirthDate' => 'False',
457
  );
458
 
459
+ $useMobile = Mage::getStoreConfigFlag(self::XPATH_USE_MOBILE, $storeId);
460
  if ($useMobile) {
461
  $optional['MobileNumber'] = 'True';
462
  }
463
 
464
+ $useDob = Mage::getStoreConfigFlag(self::XPATH_USE_DOB, $storeId);
465
  if ($useDob) {
466
  $optional['BirthDate'] = 'True';
467
  }
478
  {
479
  $storeId = $this->getStoreId();
480
 
481
+ $contactUrl = Mage::getStoreConfig(self::XPATH_CONTACT_URL, $storeId);
482
  if (!$contactUrl) {
483
  return false;
484
  }
624
  protected function _getReference($shipment)
625
  {
626
  $storeId = $this->getStoreId();
627
+ $referenceType = Mage::getStoreConfig(self::XPATH_SHIPMENT_REFERENCE_TYPE, $storeId);
628
 
629
  /**
630
  * Parse the reference type
641
  $reference = $shipment->getOrder()->getIncrementId();
642
  break;
643
  case 'custom':
644
+ $reference = Mage::getStoreConfig(self::XPATH_CUSTOM_SHIPMENT_REFERENCE, $storeId);
645
  break;
646
  default:
647
  throw new TIG_PostNL_Exception(
680
  $parcelCount = $postnlShipment->getParcelCount();
681
 
682
  $parcelData = array();
683
+ $postcode = str_replace(' ', '', $shipment->getShippingAddress()->getPostcode());
684
  for ($i = 0; $i < $parcelCount; $i++) {
685
  $parcelData[] = array(
686
  'Barcode' => $postnlShipment->getBarcode($i),
702
 
703
  $restrictions = array();
704
 
705
+ $retailLocation = Mage::getStoreConfigFlag(self::XPATH_ALLOW_RETAIL_LOCATION, $storeId);
706
+ $foreignAddress = Mage::getStoreConfigFlag(self::XPATH_ALLOW_FOREIGN_ADDRESS, $storeId);
707
+ $priceOverview = Mage::getStoreConfigFlag(self::XPATH_ALLOW_PRICE_OVERVIEW, $storeId);
708
+ $agreeConditions = Mage::getStoreConfigFlag(self::XPATH_AGREE_CONDITIONS, $storeId);
709
 
710
  /**
711
  * If the module cannot use PakjeGemak, retail locations are not allowed in PostNL Checkout
753
  {
754
  $storeId = $this->getStoreId();
755
 
756
+ $serviceUrl = Mage::getStoreConfig(self::XPATH_SERVICE_URL, $storeId);
757
  if (!$serviceUrl) {
758
  return false;
759
  }
811
  {
812
  $storeId = $this->getStoreId();
813
 
814
+ $webshopId = Mage::getStoreConfig(self::XPATH_WEBSHOP_ID, $storeId);
815
  $webshopId = Mage::helper('core')->decrypt($webshopId);
816
 
817
  $webshop = array(
app/code/community/TIG/PostNL/Model/Checkout/Observer/Order.php CHANGED
@@ -43,7 +43,7 @@ class TIG_PostNL_Model_Checkout_Observer_Order
43
  *
44
  * @param Varien_Event_Observer $observer
45
  *
46
- * @return TIG_PostNL_Model_Checkout_Observer_Order
47
  *
48
  * @event order_cancel_after
49
  *
43
  *
44
  * @param Varien_Event_Observer $observer
45
  *
46
+ * @return $this
47
  *
48
  * @event order_cancel_after
49
  *
app/code/community/TIG/PostNL/Model/Checkout/Observer/Shipment.php CHANGED
@@ -45,7 +45,7 @@ class TIG_PostNL_Model_Checkout_Observer_Shipment
45
  *
46
  * @param Varien_Event_Observer $observer
47
  *
48
- * @return TIG_PostNL_Model_Core_Observer_Barcode
49
  *
50
  * @event postnl_shipment_confirm_after
51
  *
45
  *
46
  * @param Varien_Event_Observer $observer
47
  *
48
+ * @return $this
49
  *
50
  * @event postnl_shipment_confirm_after
51
  *
app/code/community/TIG/PostNL/Model/Checkout/Service.php CHANGED
@@ -45,28 +45,28 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
@@ -97,7 +97,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
  */
@@ -202,7 +202,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
  {
@@ -299,7 +299,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
  */
@@ -319,7 +319,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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'
@@ -341,7 +341,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
  {
@@ -349,7 +349,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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));
@@ -373,7 +373,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
  {
@@ -388,7 +388,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
 
@@ -429,7 +429,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
429
  */
430
  if ($optionValue) {
431
  $field = Mage::getStoreConfig(
432
- self::XML_PATH_PAYMENT_METHODS . '/' . $methodName . '_option_field',
433
  $quote->getStoreId()
434
  );
435
 
@@ -481,7 +481,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
  {
@@ -534,10 +534,12 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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;
@@ -549,7 +551,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
549
  * @param $data
550
  * @param null $quote
551
  *
552
- * @return TIG_PostNL_Model_Checkout_Service
553
  */
554
  public function updatePostnlOrder($data, $quote = null)
555
  {
@@ -717,7 +719,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
717
  *
718
  * @param Mage_Sales_Model_Quote
719
  *
720
- * @return TIG_PostNL_Model_Checkout_Service
721
  */
722
  public function confirmPostnlOrder($quote = null)
723
  {
@@ -760,11 +762,11 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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);
@@ -848,7 +850,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
  /**
@@ -869,8 +871,8 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
@@ -880,12 +882,12 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
  }
@@ -905,7 +907,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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
  */
@@ -926,7 +928,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
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) {
@@ -946,7 +948,7 @@ class TIG_PostNL_Model_Checkout_Service extends Varien_Object
946
  *
947
  * @param Mage_Sales_Model_Quote &$quote
948
  *
949
- * @return TIG_PostNL_Model_Checkout_Service
950
  */
951
  protected function _removeAllQuoteAddresses(&$quote)
952
  {
45
  /**
46
  * XML path to public webshop ID setting
47
  */
48
+ const XPATH_WEBSHOP_ID = 'postnl/cif/webshop_id';
49
 
50
  /**
51
  * Constants containing XML paths to cif address configuration options
52
  */
53
+ const XPATH_SPLIT_STREET = 'postnl/cif_address/split_street';
54
+ const XPATH_STREETNAME_FIELD = 'postnl/cif_address/streetname_field';
55
+ const XPATH_HOUSENUMBER_FIELD = 'postnl/cif_address/housenr_field';
56
+ const XPATH_SPLIT_HOUSENUMBER = 'postnl/cif_address/split_housenr';
57
+ const XPATH_HOUSENUMBER_EXTENSION_FIELD = 'postnl/cif_address/housenr_extension_field';
58
+ const XPATH_AREA_FIELD = 'postnl/cif_address/area_field';
59
+ const XPATH_BUILDING_NAME_FIELD = 'postnl/cif_address/building_name_field';
60
+ const XPATH_DEPARTMENT_FIELD = 'postnl/cif_address/department_field';
61
+ const XPATH_DOORCODE_FIELD = 'postnl/cif_address/doorcode_field';
62
+ const XPATH_FLOOR_FIELD = 'postnl/cif_address/floor_field';
63
+ const XPATH_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 XPATH_PAYMENT_METHODS = 'postnl/checkout_payment_methods';
70
 
71
  /**
72
  * Newly added 'pakje_gemak' address type
97
  * @param StdClass $data
98
  * @param Mage_Sales_Model_Quote | null $quote
99
  *
100
+ * @return $this
101
  *
102
  * @throws TIG_PostNL_Exception
103
  */
202
  * for the chosen payment method.
203
  * @param Mage_Sales_Model_Quote|null $quote
204
  *
205
+ * @return $this
206
  */
207
  public function updateQuotePayment($data, $isOrderdetails = true, $methodOnly = false, $quote = null)
208
  {
299
  * @param boolean $methodOnly
300
  * @param Mage_Sales_Model_Quote $quote
301
  *
302
+ * @return $this
303
  *
304
  * @throws TIG_PostNL_Exception
305
  */
319
  /**
320
  * Check if the payment method chosen is allowed
321
  */
322
+ if (!Mage::getStoreConfigFlag(self::XPATH_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'
341
  * @param string $methodName
342
  * @param Mage_Sales_Model_Quote $quote
343
  *
344
+ * @return $this
345
  */
346
  protected function _processPaymentMethod($methodName, $quote)
347
  {
349
  * Get the Magento payment method code associated with this method
350
  */
351
  $methodCode = Mage::getStoreConfig(
352
+ self::XPATH_PAYMENT_METHODS . '/' . $methodName . '_method',
353
  $quote->getStoreId()
354
  );
355
  Mage::register('postnl_payment_data', array('method' => $methodCode));
373
  * @param string $methodName
374
  * @param Mage_Sales_Model_Quote $quote
375
  *
376
+ * @return $this
377
  */
378
  protected function _processPaymentData($postnlPaymentData, $methodName, $quote)
379
  {
388
  * Get the payment method code associated with the chosen payment method
389
  */
390
  $methodCode = Mage::getStoreConfig(
391
+ self::XPATH_PAYMENT_METHODS . '/' . $methodName . '_method',
392
  $quote->getStoreId()
393
  );
394
 
429
  */
430
  if ($optionValue) {
431
  $field = Mage::getStoreConfig(
432
+ self::XPATH_PAYMENT_METHODS . '/' . $methodName . '_option_field',
433
  $quote->getStoreId()
434
  );
435
 
481
  * @param StdClass $data
482
  * @param Mage_Sales_Model_Quote | null $quote
483
  *
484
+ * @return $this
485
  */
486
  public function updateQuoteCustomer($data, $quote = null)
487
  {
534
  return $this;
535
  }
536
 
537
+ $dob = new DateTime($dob);
538
+
539
  /**
540
  * Update the customer with the DOB and save
541
  */
542
+ $customer->setDob($dob->getTimestamp())
543
  ->save();
544
 
545
  return $this;
551
  * @param $data
552
  * @param null $quote
553
  *
554
+ * @return $this
555
  */
556
  public function updatePostnlOrder($data, $quote = null)
557
  {
719
  *
720
  * @param Mage_Sales_Model_Quote
721
  *
722
+ * @return $this
723
  */
724
  public function confirmPostnlOrder($quote = null)
725
  {
762
  /**
763
  * Parse optional address fields
764
  */
765
+ $buildingNameField = Mage::getStoreConfig(self::XPATH_BUILDING_NAME_FIELD, $storeId);
766
+ $departmentField = Mage::getStoreConfig(self::XPATH_DEPARTMENT_FIELD, $storeId);
767
+ $doorcodeField = Mage::getStoreConfig(self::XPATH_DOORCODE_FIELD, $storeId);
768
+ $floorField = Mage::getStoreConfig(self::XPATH_FLOOR_FIELD, $storeId);
769
+ $areaField = Mage::getStoreConfig(self::XPATH_AREA_FIELD, $storeId);
770
 
771
  if ($buildingNameField) {
772
  $address->setData('street' . $buildingNameField, $addressData->Gebouw);
850
  protected function _parseStreetData($address, $addressData)
851
  {
852
  $storeId = $this->getStoreId();
853
+ $splitStreet = Mage::getStoreConfigFlag(self::XPATH_SPLIT_STREET, $storeId);
854
 
855
  if (!$splitStreet) {
856
  /**
871
  /**
872
  * If the store uses multiple address lines, check which part of the address goes where
873
  */
874
+ $streetnameField = Mage::getStoreConfig(self::XPATH_STREETNAME_FIELD, $storeId);
875
+ $housenumberField = Mage::getStoreCOnfig(self::XPATH_HOUSENUMBER_FIELD, $storeId);
876
 
877
  /**
878
  * Set the streetname to the appropriate field
882
  /**
883
  * Check if the store splits housenumber and housenumber extensions as well. Place them in appriopriate fields
884
  */
885
+ $splitHousenumber = Mage::getStoreConfigFlag(self::XPATH_SPLIT_HOUSENUMBER, $storeId);
886
  if (!$splitHousenumber) {
887
  $housenumber = $addressData->Huisnummer . ' ' . $addressData->HuisnummerExt;
888
  $streetData[$housenumberField] = $housenumber;
889
  } else {
890
+ $housenumberExtensionField = Mage::getStoreConfig(self::XPATH_HOUSENUMBER_EXTENSION_FIELD, $storeId);
891
  $streetData[$housenumberField] = $addressData->Huisnummer;
892
  $streetData[$housenumberExtensionField] = $addressData->HuisnummerExt;
893
  }
907
  * @param StdClass $data
908
  * @param Mage_Sales_Model_Quote $quote
909
  *
910
+ * @return $this
911
  *
912
  * @throws TIG_PostNL_Exception
913
  */
928
  * Verify the webshop ID to make sure this message was not meant for another shop
929
  */
930
  $dataWebshopId = $data->Webshop->IntRef;
931
+ $webshopId = Mage::getStoreConfig(self::XPATH_WEBSHOP_ID, $this->getStoreId());
932
  $webshopId = Mage::helper('core')->decrypt($webshopId);
933
 
934
  if ($webshopId != $dataWebshopId) {
948
  *
949
  * @param Mage_Sales_Model_Quote &$quote
950
  *
951
+ * @return $this
952
  */
953
  protected function _removeAllQuoteAddresses(&$quote)
954
  {
app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/ActivePaymentMethods.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_Checkout_System_Config_Source_ActivePaymentMethods
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_System_Config_Source_ActivePaymentMethods
app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/CmsPage.php CHANGED
@@ -58,7 +58,7 @@ class TIG_PostNL_Model_Checkout_System_Config_Source_CmsPage
58
  *
59
  * @param array $options
60
  *
61
- * @return TIG_PostNL_Model_Checkout_System_Config_Source_CmsPage
62
  */
63
  public function setOptions($options)
64
  {
58
  *
59
  * @param array $options
60
  *
61
+ * @return $this
62
  */
63
  public function setOptions($options)
64
  {
app/code/community/TIG/PostNL/Model/Core/Cache.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 hasPostnlCoreIsEnabled()
@@ -54,6 +54,9 @@
54
  * @method boolean hasPostnlDeliveryOptionsCanUseEveningTimeframes()
55
  * @method boolean hasPostnlDeliveryOptionsCanUseSundaySorting()
56
  * @method boolean hasPostnlMijnpakketIsActive()
 
 
 
57
  *
58
  * @method boolean getPostnlCoreIsEnabled()
59
  * @method boolean getPostnlCoreIsConfigured()
@@ -73,6 +76,9 @@
73
  * @method boolean getPostnlDeliveryOptionsCanUseEveningTimeframes()
74
  * @method boolean getPostnlDeliveryOptionsCanUseSundaySorting()
75
  * @method boolean getPostnlMijnpakketIsActive()
 
 
 
76
  *
77
  * @method TIG_PostNL_Model_Core_Cache setPostnlCoreIsEnabled(boolean $value)
78
  * @method TIG_PostNL_Model_Core_Cache setPostnlCoreIsConfigured(boolean $value)
@@ -92,6 +98,9 @@
92
  * @method TIG_PostNL_Model_Core_Cache setPostnlDeliveryOptionsCanUseEveningTimeframes(boolean $value)
93
  * @method TIG_PostNL_Model_Core_Cache setPostnlDeliveryOptionsCanUseSundaySorting(boolean $value)
94
  * @method TIG_PostNL_Model_Core_Cache setPostnlMijnpakketIsActive(boolean $value)
 
 
 
95
  */
96
  class TIG_PostNL_Model_Core_Cache extends Varien_Object
97
  {
@@ -103,16 +112,16 @@ class TIG_PostNL_Model_Core_Cache extends Varien_Object
103
  /**
104
  * PostNl cache ID.
105
  *
106
- * @var null|string
107
  */
108
- protected $_cacheId = null;
109
 
110
  /**
111
  * Flag whether or not the cache may be used.
112
  *
113
  * @var null|boolean
114
  */
115
- protected $_canUseCache = null;
116
 
117
  /**
118
  * @param string $cacheId
@@ -131,7 +140,14 @@ class TIG_PostNL_Model_Core_Cache extends Varien_Object
131
  */
132
  public function getCacheId()
133
  {
134
- return $this->_cacheId;
 
 
 
 
 
 
 
135
  }
136
 
137
  /**
@@ -201,6 +217,10 @@ class TIG_PostNL_Model_Core_Cache extends Varien_Object
201
  {
202
  if ($this->canUseCache()) {
203
  $data = $this->loadCache();
 
 
 
 
204
  $this->setData($data);
205
  }
206
 
@@ -218,7 +238,11 @@ class TIG_PostNL_Model_Core_Cache extends Varien_Object
218
  return array();
219
  }
220
 
221
- $data = Mage::app()->loadCache($this->_getCacheId());
 
 
 
 
222
  $data = unserialize($data);
223
 
224
  return $data;
@@ -235,7 +259,12 @@ class TIG_PostNL_Model_Core_Cache extends Varien_Object
235
  return $this;
236
  }
237
 
238
- Mage::app()->saveCache(serialize($this->getData()), $this->_getCacheId(), array(self::CACHE_TAG), null);
 
 
 
 
 
239
  return $this;
240
  }
241
 
@@ -250,7 +279,7 @@ class TIG_PostNL_Model_Core_Cache extends Varien_Object
250
  return $this->getCanUseCache();
251
  }
252
 
253
- $canUseCache = Mage::app()->useCache('postnl_config');
254
 
255
  $this->setCanUseCache($canUseCache);
256
  return $canUseCache;
@@ -273,11 +302,9 @@ class TIG_PostNL_Model_Core_Cache extends Varien_Object
273
  */
274
  public function cleanCache()
275
  {
276
- if ($this->canUseCache()) {
277
- Mage::app()->cleanCache(self::CACHE_TAG);
278
 
279
- $this->unsetData();
280
- }
281
 
282
  return $this;
283
  }
@@ -289,13 +316,8 @@ class TIG_PostNL_Model_Core_Cache extends Varien_Object
289
  */
290
  protected function _getCacheId()
291
  {
292
- if ($this->hasCacheId()) {
293
- return $this->getCacheId();
294
- }
295
-
296
  $cacheId = 'postnl_' . Mage::app()->getStore()->getId();
297
 
298
- $this->setCacheId($cacheId);
299
  return $cacheId;
300
  }
301
  }
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 hasPostnlCoreIsEnabled()
54
  * @method boolean hasPostnlDeliveryOptionsCanUseEveningTimeframes()
55
  * @method boolean hasPostnlDeliveryOptionsCanUseSundaySorting()
56
  * @method boolean hasPostnlMijnpakketIsActive()
57
+ * @method boolean hasPostnlMijnpakketCanShowNotification()
58
+ * @method boolean hasPostnlCoreCanUseBuspakje()
59
+ * @method boolean hasPostnlDeliveryOptionsCanUseDeliveryDays()
60
  *
61
  * @method boolean getPostnlCoreIsEnabled()
62
  * @method boolean getPostnlCoreIsConfigured()
76
  * @method boolean getPostnlDeliveryOptionsCanUseEveningTimeframes()
77
  * @method boolean getPostnlDeliveryOptionsCanUseSundaySorting()
78
  * @method boolean getPostnlMijnpakketIsActive()
79
+ * @method boolean getPostnlMijnpakketCanShowNotification()
80
+ * @method boolean getPostnlCoreCanUseBuspakje()
81
+ * @method boolean getPostnlDeliveryOptionsCanUseDeliveryDays()
82
  *
83
  * @method TIG_PostNL_Model_Core_Cache setPostnlCoreIsEnabled(boolean $value)
84
  * @method TIG_PostNL_Model_Core_Cache setPostnlCoreIsConfigured(boolean $value)
98
  * @method TIG_PostNL_Model_Core_Cache setPostnlDeliveryOptionsCanUseEveningTimeframes(boolean $value)
99
  * @method TIG_PostNL_Model_Core_Cache setPostnlDeliveryOptionsCanUseSundaySorting(boolean $value)
100
  * @method TIG_PostNL_Model_Core_Cache setPostnlMijnpakketIsActive(boolean $value)
101
+ * @method TIG_PostNL_Model_Core_Cache setPostnlMijnpakketCanShowNotification(boolean $value)
102
+ * @method TIG_PostNL_Model_Core_Cache setPostnlCoreCanUseBuspakje(boolean $value)
103
+ * @method TIG_PostNL_Model_Core_Cache setPostnlDeliveryOptionsCanUseDeliveryDays(boolean $value)
104
  */
105
  class TIG_PostNL_Model_Core_Cache extends Varien_Object
106
  {
112
  /**
113
  * PostNl cache ID.
114
  *
115
+ * @var string
116
  */
117
+ protected $_cacheId;
118
 
119
  /**
120
  * Flag whether or not the cache may be used.
121
  *
122
  * @var null|boolean
123
  */
124
+ protected $_canUseCache;
125
 
126
  /**
127
  * @param string $cacheId
140
  */
141
  public function getCacheId()
142
  {
143
+ if ($this->hasCacheId()) {
144
+ return $this->_cacheId;
145
+ }
146
+
147
+ $cacheId = $this->_getCacheId();
148
+
149
+ $this->setCacheId($cacheId);
150
+ return $cacheId;
151
  }
152
 
153
  /**
217
  {
218
  if ($this->canUseCache()) {
219
  $data = $this->loadCache();
220
+ if (!$data) {
221
+ return $this;
222
+ }
223
+
224
  $this->setData($data);
225
  }
226
 
238
  return array();
239
  }
240
 
241
+ $data = Mage::app()->loadCache($this->getCacheId());
242
+ if (!$data) {
243
+ return false;
244
+ }
245
+
246
  $data = unserialize($data);
247
 
248
  return $data;
259
  return $this;
260
  }
261
 
262
+ $data = $this->getData();
263
+ if (empty($data)) {
264
+ return $this;
265
+ }
266
+
267
+ Mage::app()->saveCache(serialize($data), $this->getCacheId(), array(self::CACHE_TAG), null);
268
  return $this;
269
  }
270
 
279
  return $this->getCanUseCache();
280
  }
281
 
282
+ $canUseCache = Mage::app()->useCache(self::CACHE_TAG);
283
 
284
  $this->setCanUseCache($canUseCache);
285
  return $canUseCache;
302
  */
303
  public function cleanCache()
304
  {
305
+ Mage::app()->cleanCache(self::CACHE_TAG);
 
306
 
307
+ $this->unsetData();
 
308
 
309
  return $this;
310
  }
316
  */
317
  protected function _getCacheId()
318
  {
 
 
 
 
319
  $cacheId = 'postnl_' . Mage::app()->getStore()->getId();
320
 
 
321
  return $cacheId;
322
  }
323
  }
app/code/community/TIG/PostNL/Model/Core/Cif.php CHANGED
@@ -58,64 +58,64 @@
58
  class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
59
  {
60
  /**
61
- * Constants containing xml paths to cif configuration options
62
  */
63
- const XML_PATH_CUSTOMER_CODE = 'postnl/cif/customer_code';
64
- const XML_PATH_CUSTOMER_NUMBER = 'postnl/cif/customer_number';
65
- const XML_PATH_COLLECTION_LOCATION = 'postnl/cif/collection_location';
66
- const XML_PATH_GLOBAL_BARCODE_TYPE = 'postnl/cif/global_barcode_type';
67
- const XML_PATH_GLOBAL_BARCODE_RANGE = 'postnl/cif/global_barcode_range';
68
 
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';
75
- const XML_PATH_DOORCODE_FIELD = 'postnl/cif_address/doorcode_field';
76
- const XML_PATH_FLOOR_FIELD = 'postnl/cif_address/floor_field';
77
- const XML_PATH_REMARK_FIELD = 'postnl/cif_address/remark_field';
78
 
79
  /**
80
- * Constants containing xml paths to cif customs configuration options
81
  */
82
- const XML_PATH_GLOBALPACK_CUSTOMS_LICENSE_NUMBER = 'postnl/cif_globalpack_settings/customs_license_number';
83
- const XML_PATH_GLOBALPACK_CUSTOMS_CERTIFICATE_NUMBER = 'postnl/cif_globalpack_settings/customs_certificate_number';
84
- const XML_PATH_GLOBALPACK_USE_HS_TARIFF_ATTRIBUTE = 'postnl/cif_globalpack_settings/use_hs_tariff';
85
- const XML_PATH_GLOBALPACK_HS_TARIFF_ATTRIBUTE = 'postnl/cif_globalpack_settings/hs_tariff_attribute';
86
- const XML_PATH_GLOBALPACK_CUSTOMS_VALUE_ATTRIBUTE = 'postnl/cif_globalpack_settings/customs_value_attribute';
87
- const XML_PATH_GLOBALPACK_COUNTRY_OF_ORIGIN_ATTRIBUTE = 'postnl/cif_globalpack_settings/country_of_origin_attribute';
88
- const XML_PATH_GLOBALPACK_DESCRIPTION_ATTRIBUTE = 'postnl/cif_globalpack_settings/description_attribute';
89
- const XML_PATH_GLOBALPACK_PRODUCT_SORTING_ATTRIBUTE = 'postnl/cif_globalpack_settings/product_sorting_attribute';
90
- const XML_PATH_GLOBALPACK_PRODUCT_SORTING_DIRECTION = 'postnl/cif_globalpack_settings/product_sorting_direction';
91
 
92
  /**
93
- * XML path to setting that dtermines whether to use a seperate return address
94
  */
95
- const XML_PATH_USE_SENDER_ADDRESS_AS_RETURN = 'postnl/cif_return_address/use_sender_address';
96
 
97
  /**
98
- * XML path to sender address data.
99
  *
100
  * N.B. missing last part so this will return an array of all fields.
101
  */
102
- const XML_PATH_SENDER_ADDRESS = 'postnl/cif_sender_address';
103
 
104
  /**
105
- * XML path to return address data.
106
  *
107
  * N.B. missing last part so this will return an array of all fields.
108
  */
109
- const XML_PATH_RETURN_ADDRESS = 'postnl/cif_return_address';
110
 
111
- /**
112
- * XML paths for shipment reference info
113
  */
114
- const XML_PATH_SHIPMENT_REFERENCE_TYPE = 'postnl/cif_labels_and_confirming/shipment_reference_type';
115
- const XML_PATH_CUSTOM_SHIPMENT_REFERENCE = 'postnl/cif_labels_and_confirming/custom_shipment_reference';
116
 
117
  /**
118
- * Possible barcodes series per barcode type
119
  */
120
  const NL_BARCODE_SERIE_LONG = '0000000000-9999999999';
121
  const NL_BARCODE_SERIE_SHORT = '000000000-999999999';
@@ -124,12 +124,19 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
124
  const GLOBAL_BARCODE_SERIE = '0000-9999';
125
 
126
  /**
127
- * XML path to weight per parcel config setting
 
 
 
 
 
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
  *
134
  * @var array
135
  */
@@ -346,7 +353,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
  *
351
  * @param array $data Array containing all data required for the request.
352
  *
@@ -525,8 +532,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
  );
@@ -612,13 +619,9 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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;
@@ -729,8 +732,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
  );
@@ -750,12 +753,12 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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();
759
 
760
  $message = array(
761
  'MessageID' => md5($messageIdString),
@@ -809,10 +812,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
809
  $barcode, $mainBarcode = false, $shipmentNumber = false)
810
  {
811
  $shipment = $postnlShipment->getShipment();
 
812
  $order = $shipment->getOrder();
813
- $shippingAddress = $shipment->getShippingAddress();
814
 
815
- $parcelCount = $postnlShipment->getParcelCount();
816
  $shipmentWeight = $postnlShipment->getTotalWeight(true, true);
817
 
818
  /**
@@ -823,8 +826,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
@@ -848,8 +851,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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(
@@ -860,11 +863,11 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
  );
@@ -875,10 +878,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
875
  if ($parcelCount > 1) {
876
  $groups = array(
877
  'Group' => $this->_getGroup(
878
- $parcelCount,
879
- $mainBarcode,
880
- $shipmentNumber
881
- ),
882
  );
883
 
884
  $shipmentData['Groups'] = $groups;
@@ -891,17 +894,17 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
891
  $shipmentData['Addresses'] = $addresses;
892
 
893
  /**
894
- * Add extra cover data and COD data
895
- * In the case of a multi-collo shipment this is only added to the first parcel
896
  */
897
  if (($shipmentNumber === false || $shipmentNumber == 1)
898
  && ($postnlShipment->hasExtraCover() || $postnlShipment->isCod())
899
  ) {
900
- $shipmentData['Amounts'] = $this->_getAmount($postnlShipment);
901
  }
902
 
903
  /**
904
- * Add customs data
905
  */
906
  if ($postnlShipment->isGlobalShipment()) {
907
  $shipmentData['Customs'] = $this->_getCustoms($postnlShipment);
@@ -916,6 +919,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
916
  }
917
 
918
  /**
 
 
919
  * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
920
  * @param Mage_Sales_Model_order_Address $shippingAddress
921
  *
@@ -924,8 +929,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
 
@@ -992,8 +997,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
992
  }
993
 
994
  /**
995
- * Determine which address to use. Currently only 'Sender' and 'Receiver' are fully supported.
996
- * Other possible address types will use the default 'receiver' address.
997
  */
998
  $streetData = false;
999
  switch ($addressType) {
@@ -1003,7 +1008,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1003
  * This allows the _prepareAddress method to access this data in the same way as a
1004
  * conventional Mage_Sales_Model_Order_Address object.
1005
  */
1006
- $senderAddress = Mage::getStoreConfig(self::XML_PATH_SENDER_ADDRESS, $this->getStoreId());
1007
 
1008
  $streetData = array(
1009
  'streetname' => $senderAddress['streetname'],
@@ -1016,10 +1021,10 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1016
  break;
1017
  case 'Alternative':
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) {
@@ -1027,11 +1032,11 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1027
  }
1028
 
1029
  /**
1030
- * Get all cif_return_address fields as an array and convert that to a Varien_Object
1031
- * This allows the _prepareAddress method to access this data in the same way as a
1032
- * conventional Mage_Sales_Model_Order_Address object.
1033
  */
1034
- $returnAddress = Mage::getStoreConfig(self::XML_PATH_RETURN_ADDRESS, $this->getStoreId());
1035
 
1036
  $streetData = array(
1037
  'streetname' => $returnAddress['streetname'],
@@ -1078,7 +1083,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1078
  'HouseNr' => $streetData['housenumber'],
1079
  'HouseNrExt' => $streetData['housenumberExtension'],
1080
  'StreetHouseNrExt' => $streetData['fullStreet'],
1081
- 'Zipcode' => $address->getPostcode(),
1082
  'City' => $address->getCity(),
1083
  'Region' => $address->getRegion(),
1084
  'Countrycode' => $address->getCountry(),
@@ -1090,6 +1095,12 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1090
  'Remark' => $this->_getRemark($address),
1091
  );
1092
 
 
 
 
 
 
 
1093
  return $addressArray;
1094
  }
1095
 
@@ -1155,13 +1166,14 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1155
  }
1156
 
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()) {
@@ -1183,7 +1195,23 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1183
  }
1184
 
1185
  if ($postnlShipment->isCod()) {
1186
- /** @todo implement COD here */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1187
  }
1188
 
1189
  return $amount;
@@ -1198,8 +1226,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
 
@@ -1356,6 +1383,8 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1356
  $content = array();
1357
  $items = $this->_sortCustomsItems($shipment->getAllItems());
1358
 
 
 
1359
  /**
1360
  * @var Mage_Sales_Model_Order_Shipment_Item $item
1361
  */
@@ -1370,7 +1399,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1370
  /**
1371
  * Calculate the item's weight in kg
1372
  */
1373
- $itemWeight = Mage::helper('postnl/cif')->standardizeWeight(
1374
  $item->getWeight(),
1375
  $this->getStoreId()
1376
  );
@@ -1428,11 +1457,11 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
 
@@ -1442,7 +1471,11 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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);
1447
  $sortedItems[$item->getId()] = $sortingAttributeValue;
1448
  }
@@ -1481,20 +1514,19 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1481
  /**
1482
  * HS Tariff is an optional attribute. Check if it's used and if not, return a default value of 000000
1483
  */
1484
- if (!Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_USE_HS_TARIFF_ATTRIBUTE, $storeId)) {
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);
1492
  $this->setHSTariffAttribute($hsTariffAttribute);
1493
  }
1494
 
1495
- $hsTariff = $shipmentItem->getOrderItem()
1496
- ->getProduct()
1497
- ->getDataUsingMethod($hsTariffAttribute);
1498
 
1499
  if (empty($hsTariff)) {
1500
  $hsTariff = '000000';
@@ -1519,21 +1551,22 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
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
 
1528
- $countryOfOrigin = $shipmentItem->getOrderItem()
1529
- ->getProduct()
1530
- ->getDataUsingMethod($countryOfOriginAttribute);
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
  );
@@ -1557,17 +1590,21 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1557
  if ($this->hasCustomsValueAttribute()) {
1558
  $customsValueAttribute = $this->getCustomsValueAttribute();
1559
  } else {
1560
- $customsValueAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_CUSTOMS_VALUE_ATTRIBUTE, $storeId);
1561
  $this->setCustomsValueAttribute($customsValueAttribute);
1562
  }
1563
 
1564
- $customsValue = $shipmentItem->getOrderItem()
1565
- ->getProduct()
1566
- ->getDataUsingMethod($customsValueAttribute);
1567
 
1568
  if (empty($customsValue)) {
 
1569
  throw new TIG_PostNL_Exception(
1570
- Mage::helper('postnl')->__('Missing customs value for product #%s.', $shipmentItem->getProductId()),
 
 
 
 
1571
  'POSTNL-0092'
1572
  );
1573
  }
@@ -1590,21 +1627,22 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1590
  if ($this->hasCustomsDescriptionAttribute()) {
1591
  $descriptionAttribute = $this->getCustomsDescriptionAttribute();
1592
  } else {
1593
- $descriptionAttribute = Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_DESCRIPTION_ATTRIBUTE, $storeId);
1594
  $this->setCustomsDescriptionAttribute($descriptionAttribute);
1595
  }
1596
 
1597
- $description = $shipmentItem->getOrderItem()
1598
- ->getProduct()
1599
- ->getDataUsingMethod($descriptionAttribute);
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
  }
1610
 
@@ -1619,7 +1657,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1619
  protected function _getCustomerCode()
1620
  {
1621
  $storeId = $this->getStoreId();
1622
- $customerCode = (string) Mage::getStoreConfig(self::XML_PATH_CUSTOMER_CODE, $storeId);
1623
 
1624
  return $customerCode;
1625
  }
@@ -1632,7 +1670,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1632
  protected function _getCustomerNumber()
1633
  {
1634
  $storeId = $this->getStoreId();
1635
- $customerNumber = (string) Mage::getStoreConfig(self::XML_PATH_CUSTOMER_NUMBER, $storeId);
1636
 
1637
  return $customerNumber;
1638
  }
@@ -1645,7 +1683,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1645
  protected function _getCollectionLocation()
1646
  {
1647
  $storeId = $this->getStoreId();
1648
- $collectionLocation = (string) Mage::getStoreConfig(self::XML_PATH_COLLECTION_LOCATION, $storeId);
1649
 
1650
  return $collectionLocation;
1651
  }
@@ -1658,7 +1696,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1658
  protected function _getGlobalBarcodeType()
1659
  {
1660
  $storeId = $this->getStoreId();
1661
- $barcodeType = (string) Mage::getStoreConfig(self::XML_PATH_GLOBAL_BARCODE_TYPE, $storeId);
1662
 
1663
  return $barcodeType;
1664
  }
@@ -1671,7 +1709,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1671
  protected function _getGlobalBarcodeRange()
1672
  {
1673
  $storeId = $this->getStoreId();
1674
- $barcodeRange = (string) Mage::getStoreConfig(self::XML_PATH_GLOBAL_BARCODE_RANGE, $storeId);
1675
 
1676
  return $barcodeRange;
1677
  }
@@ -1684,7 +1722,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1684
  protected function _getCustomsLicense()
1685
  {
1686
  $storeId = $this->getStoreId();
1687
- $customsLicense = (string) Mage::getStoreConfig(self::XML_PATH_GLOBALPACK_CUSTOMS_LICENSE_NUMBER, $storeId);
1688
 
1689
  if (empty($customsLicense)) {
1690
  return false;
@@ -1702,7 +1740,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1702
  {
1703
  $storeId = $this->getStoreId();
1704
  $customsCertificate = (string) Mage::getStoreConfig(
1705
- self::XML_PATH_GLOBALPACK_CUSTOMS_CERTIFICATE_NUMBER,
1706
  $storeId
1707
  );
1708
 
@@ -1723,7 +1761,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1723
  protected function _getArea($address)
1724
  {
1725
  $storeId = $this->getStoreId();
1726
- $areaField = (string) Mage::getStoreConfig(self::XML_PATH_AREA_FIELD, $storeId);
1727
  if ($areaField) {
1728
  $area = $address->getStreet($areaField);
1729
 
@@ -1749,7 +1787,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1749
  protected function _getBuildingName($address)
1750
  {
1751
  $storeId = $this->getStoreId();
1752
- $buildingNameField = (string) Mage::getStoreConfig(self::XML_PATH_BUILDING_NAME_FIELD, $storeId);
1753
  if ($buildingNameField) {
1754
  $buildingName = $address->getStreet($buildingNameField);
1755
 
@@ -1775,7 +1813,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1775
  protected function _getDepartment($address)
1776
  {
1777
  $storeId = $this->getStoreId();
1778
- $departmentField = (string) Mage::getStoreConfig(self::XML_PATH_DEPARTMENT_FIELD, $storeId);
1779
  if ($departmentField) {
1780
  $department = $address->getStreet($departmentField);
1781
 
@@ -1792,7 +1830,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1792
  }
1793
 
1794
  /**
1795
- * Get the doorcode field from an address if enabled
1796
  *
1797
  * @param Mage_Sales_Model_Order_Address $address
1798
  *
@@ -1801,7 +1839,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1801
  protected function _getDoorcode($address)
1802
  {
1803
  $storeId = $this->getStoreId();
1804
- $doorcodeField = (string) Mage::getStoreConfig(self::XML_PATH_DOORCODE_FIELD, $storeId);
1805
  if (!$doorcodeField) {
1806
  $doorcode = $address->getStreet($doorcodeField);
1807
 
@@ -1809,7 +1847,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1809
  }
1810
 
1811
  /**
1812
- * Attempt to get the doorcode through the magic getter instead
1813
  */
1814
  /** @noinspection PhpUndefinedMethodInspection */
1815
  $doorcode = $address->getDoorcode();
@@ -1827,7 +1865,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1827
  protected function _getFloor($address)
1828
  {
1829
  $storeId = $this->getStoreId();
1830
- $floorField = (string) Mage::getStoreConfig(self::XML_PATH_FLOOR_FIELD, $storeId);
1831
  if ($floorField) {
1832
  $floor = $address->getStreet($floorField);
1833
 
@@ -1853,7 +1891,7 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1853
  protected function _getRemark($address)
1854
  {
1855
  $storeId = $this->getStoreId();
1856
- $remarkField = (string) Mage::getStoreConfig(self::XML_PATH_REMARK_FIELD, $storeId);
1857
  if ($remarkField) {
1858
  $remark = $address->getStreet($remarkField);
1859
 
@@ -1878,47 +1916,86 @@ class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
1878
  *
1879
  * @throws TIG_PostNL_Exception
1880
  */
1881
- protected function _getReference($shipment)
1882
- {
1883
- $storeId = $this->getStoreId();
1884
- $referenceType = Mage::getStoreConfig(self::XML_PATH_SHIPMENT_REFERENCE_TYPE, $storeId);
1885
-
1886
- /**
1887
- * Parse the reference type
1888
- */
1889
- switch ($referenceType) {
1890
- case '': //no break
1891
- case 'none':
1892
- $reference = '';
1893
- break;
1894
- case 'shipment_increment_id':
1895
- $reference = $shipment->getIncrementId();
1896
- break;
1897
- case 'order_increment_id':
1898
- $reference = $shipment->getOrder()->getIncrementId();
1899
- break;
1900
- case 'custom':
1901
- $reference = Mage::getStoreConfig(self::XML_PATH_CUSTOM_SHIPMENT_REFERENCE, $storeId);
1902
- break;
1903
- default:
1904
- throw new TIG_PostNL_Exception(
1905
- Mage::helper('postnl')->__('Invalid reference type requested: %s', $referenceType),
1906
- 'POSTNL-0043'
1907
- );
1908
- }
1909
-
1910
- /**
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
-
1922
- return $reference;
1923
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1924
  }
58
  class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
59
  {
60
  /**
61
+ * Constants containing xpaths to cif configuration options.
62
  */
63
+ const XPATH_CUSTOMER_CODE = 'postnl/cif/customer_code';
64
+ const XPATH_CUSTOMER_NUMBER = 'postnl/cif/customer_number';
65
+ const XPATH_COLLECTION_LOCATION = 'postnl/cif/collection_location';
66
+ const XPATH_GLOBAL_BARCODE_TYPE = 'postnl/cif/global_barcode_type';
67
+ const XPATH_GLOBAL_BARCODE_RANGE = 'postnl/cif/global_barcode_range';
68
 
69
  /**
70
+ * Constants containing xpaths to cif address configuration options.
71
  */
72
+ const XPATH_AREA_FIELD = 'postnl/cif_address/area_field';
73
+ const XPATH_BUILDING_NAME_FIELD = 'postnl/cif_address/building_name_field';
74
+ const XPATH_DEPARTMENT_FIELD = 'postnl/cif_address/department_field';
75
+ const XPATH_DOORCODE_FIELD = 'postnl/cif_address/doorcode_field';
76
+ const XPATH_FLOOR_FIELD = 'postnl/cif_address/floor_field';
77
+ const XPATH_REMARK_FIELD = 'postnl/cif_address/remark_field';
78
 
79
  /**
80
+ * Constants containing xpaths to cif customs configuration options.
81
  */
82
+ const XPATH_GLOBALPACK_CUSTOMS_LICENSE_NUMBER = 'postnl/cif_globalpack_settings/customs_license_number';
83
+ const XPATH_GLOBALPACK_CUSTOMS_CERTIFICATE_NUMBER = 'postnl/cif_globalpack_settings/customs_certificate_number';
84
+ const XPATH_GLOBALPACK_USE_HS_TARIFF_ATTRIBUTE = 'postnl/cif_globalpack_settings/use_hs_tariff';
85
+ const XPATH_GLOBALPACK_HS_TARIFF_ATTRIBUTE = 'postnl/cif_globalpack_settings/hs_tariff_attribute';
86
+ const XPATH_GLOBALPACK_CUSTOMS_VALUE_ATTRIBUTE = 'postnl/cif_globalpack_settings/customs_value_attribute';
87
+ const XPATH_GLOBALPACK_COUNTRY_OF_ORIGIN_ATTRIBUTE = 'postnl/cif_globalpack_settings/country_of_origin_attribute';
88
+ const XPATH_GLOBALPACK_DESCRIPTION_ATTRIBUTE = 'postnl/cif_globalpack_settings/description_attribute';
89
+ const XPATH_GLOBALPACK_PRODUCT_SORTING_ATTRIBUTE = 'postnl/cif_globalpack_settings/product_sorting_attribute';
90
+ const XPATH_GLOBALPACK_PRODUCT_SORTING_DIRECTION = 'postnl/cif_globalpack_settings/product_sorting_direction';
91
 
92
  /**
93
+ * Xpath to setting that determines whether to use a separate return address.
94
  */
95
+ const XPATH_USE_SENDER_ADDRESS_AS_RETURN = 'postnl/cif_return_address/use_sender_address';
96
 
97
  /**
98
+ * Xpath to sender address data.
99
  *
100
  * N.B. missing last part so this will return an array of all fields.
101
  */
102
+ const XPATH_SENDER_ADDRESS = 'postnl/cif_sender_address';
103
 
104
  /**
105
+ * Xpath to return address data.
106
  *
107
  * N.B. missing last part so this will return an array of all fields.
108
  */
109
+ const XPATH_RETURN_ADDRESS = 'postnl/cif_return_address';
110
 
111
+ /**.
112
+ * Xpaths for shipment reference info
113
  */
114
+ const XPATH_SHIPMENT_REFERENCE_TYPE = 'postnl/cif_labels_and_confirming/shipment_reference_type';
115
+ const XPATH_CUSTOM_SHIPMENT_REFERENCE = 'postnl/cif_labels_and_confirming/custom_shipment_reference';
116
 
117
  /**
118
+ * Possible barcodes series per barcode type.
119
  */
120
  const NL_BARCODE_SERIE_LONG = '0000000000-9999999999';
121
  const NL_BARCODE_SERIE_SHORT = '000000000-999999999';
124
  const GLOBAL_BARCODE_SERIE = '0000-9999';
125
 
126
  /**
127
+ * Xpath to weight per parcel config setting.
128
+ */
129
+ const XPATH_WEIGHT_PER_PARCEL = 'postnl/cif_labels_and_confirming/weight_per_parcel';
130
+
131
+ /**
132
+ * XPaths for COD specific settings.
133
  */
134
+ const XPATH_COD_ACCOUNT_NAME = 'postnl/cod/account_name';
135
+ const XPATH_COD_BIC = 'postnl/cod/bic';
136
+ const XPATH_COD_IBAN = 'postnl/cod/iban';
137
 
138
  /**
139
+ * Array containing possible address types.
140
  *
141
  * @var array
142
  */
353
  * the CIF service is up and running. This is not meant to be used to generate an actual barcode for a shipment.
354
  * Use the generateBarcode method for that.
355
  *
356
+ * The generateBarcode CIF call was chosen as it is the simplest CIF function available.
357
  *
358
  * @param array $data Array containing all data required for the request.
359
  *
532
  */
533
  throw new TIG_PostNL_Exception(
534
  Mage::helper('postnl')->__(
535
+ 'Unable to match barcode to shippingStatus response: %s',
536
+ var_export($response, true)
537
  ),
538
  'POSTNL-0063'
539
  );
619
  * @return array
620
  *
621
  */
622
+ public function generateLabels(TIG_PostnL_Model_Core_Shipment $postnlShipment, $barcode, $mainBarcode = false,
623
+ $shipmentNumber = false, $printerType = 'GraphicFile|PDF')
624
+ {
 
 
 
 
625
  $shipment = $postnlShipment->getShipment();
626
 
627
  $availablePrinterTypes = $this->_printerTypes;
732
  ) {
733
  throw new TIG_PostNL_Exception(
734
  Mage::helper('postnl')->__(
735
+ 'Invalid generateLabelsWithoutConfirm response: %s',
736
+ var_export($response, true)
737
  ),
738
  'POSTNL-0058'
739
  );
753
  protected function _getMessage($barcode, $extra = array())
754
  {
755
  $messageIdString = uniqid(
756
+ 'postnl_'
757
+ . ip2long(Mage::helper('core/http')->getServerAddr())
758
+ )
759
+ . $this->_getCustomerNumber()
760
+ . $barcode
761
+ . microtime();
762
 
763
  $message = array(
764
  'MessageID' => md5($messageIdString),
812
  $barcode, $mainBarcode = false, $shipmentNumber = false)
813
  {
814
  $shipment = $postnlShipment->getShipment();
815
+ $shippingAddress = $postnlShipment->getShippingAddress();
816
  $order = $shipment->getOrder();
 
817
 
818
+ $parcelCount = $postnlShipment->getParcelCount();
819
  $shipmentWeight = $postnlShipment->getTotalWeight(true, true);
820
 
821
  /**
826
  /**
827
  * Get the parcel weight and then convert it to grams.
828
  */
829
+ $parcelWeight = Mage::getStoreConfig(self::XPATH_WEIGHT_PER_PARCEL, $postnlShipment->getStoreId());
830
+ $parcelWeight = Mage::helper('postnl')->standardizeWeight($parcelWeight, $shipment->getStoreId(), true);
831
 
832
  /**
833
  * All parcels except for the last one weigh a configured amount. The last parcel weighs the remainder
851
  */
852
  $deliveryDate = $postnlShipment->getDeliveryDate();
853
  if ($deliveryDate) {
854
+ $deliveryTime = new DateTime($deliveryDate);
855
+ $deliveryDate = $deliveryTime->format('d-m-Y H:i:s');
856
  }
857
 
858
  $shipmentData = array(
863
  'DownPartnerID' => '',
864
  'ProductCodeDelivery' => $postnlShipment->getProductCode(),
865
  'Contacts' => array(
866
+ 'Contact' => $this->_getContact($shippingAddress, $postnlShipment, $order),
867
+ ),
868
  'Dimension' => array(
869
+ 'Weight' => round($shipmentWeight),
870
+ ),
871
  'Reference' => $this->_getReference($shipment),
872
  'DeliveryDate' => $deliveryDate,
873
  );
878
  if ($parcelCount > 1) {
879
  $groups = array(
880
  'Group' => $this->_getGroup(
881
+ $parcelCount,
882
+ $mainBarcode,
883
+ $shipmentNumber
884
+ ),
885
  );
886
 
887
  $shipmentData['Groups'] = $groups;
894
  $shipmentData['Addresses'] = $addresses;
895
 
896
  /**
897
+ * Add extra cover data and COD data.
898
+ * In the case of a multi-colli shipment this is only added to the first parcel.
899
  */
900
  if (($shipmentNumber === false || $shipmentNumber == 1)
901
  && ($postnlShipment->hasExtraCover() || $postnlShipment->isCod())
902
  ) {
903
+ $shipmentData['Amounts'] = $this->_getAmount($postnlShipment, $shipment);
904
  }
905
 
906
  /**
907
+ * Add customs data.
908
  */
909
  if ($postnlShipment->isGlobalShipment()) {
910
  $shipmentData['Customs'] = $this->_getCustoms($postnlShipment);
919
  }
920
 
921
  /**
922
+ * Get all addresses for a given shipment.
923
+ *
924
  * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
925
  * @param Mage_Sales_Model_order_Address $shippingAddress
926
  *
929
  protected function _getShipmentAddresses(TIG_PostnL_Model_Core_Shipment $postnlShipment, $shippingAddress)
930
  {
931
  $useSenderAddressAsReturn = Mage::getStoreConfig(
932
+ self::XPATH_USE_SENDER_ADDRESS_AS_RETURN,
933
+ $this->getStoreId()
934
  );
935
  $pakjeGemakAddress = $postnlShipment->getPakjeGemakAddress();
936
 
997
  }
998
 
999
  /**
1000
+ * Determine which address to use. Currently only 'Sender', 'Alternative', 'PakjeGemak' and 'Receiver' are fully
1001
+ * supported.
1002
  */
1003
  $streetData = false;
1004
  switch ($addressType) {
1008
  * This allows the _prepareAddress method to access this data in the same way as a
1009
  * conventional Mage_Sales_Model_Order_Address object.
1010
  */
1011
+ $senderAddress = Mage::getStoreConfig(self::XPATH_SENDER_ADDRESS, $this->getStoreId());
1012
 
1013
  $streetData = array(
1014
  'streetname' => $senderAddress['streetname'],
1021
  break;
1022
  case 'Alternative':
1023
  /**
1024
+ * Check if the return address is the same as the sender address. If so, no address is returned.
1025
  */
1026
  $useSenderAddress = Mage::getStoreConfig(
1027
+ self::XPATH_USE_SENDER_ADDRESS_AS_RETURN,
1028
  $this->getStoreId()
1029
  );
1030
  if ($useSenderAddress) {
1032
  }
1033
 
1034
  /**
1035
+ * Get all cif_return_address fields as an array and convert that to a Varien_Object. This allows the
1036
+ * _prepareAddress method to access this data in the same way as a conventional
1037
+ * Mage_Sales_Model_Order_Address object.
1038
  */
1039
+ $returnAddress = Mage::getStoreConfig(self::XPATH_RETURN_ADDRESS, $this->getStoreId());
1040
 
1041
  $streetData = array(
1042
  'streetname' => $returnAddress['streetname'],
1083
  'HouseNr' => $streetData['housenumber'],
1084
  'HouseNrExt' => $streetData['housenumberExtension'],
1085
  'StreetHouseNrExt' => $streetData['fullStreet'],
1086
+ 'Zipcode' => str_replace(' ', '', $address->getPostcode()),
1087
  'City' => $address->getCity(),
1088
  'Region' => $address->getRegion(),
1089
  'Countrycode' => $address->getCountry(),
1095
  'Remark' => $this->_getRemark($address),
1096
  );
1097
 
1098
+ foreach ($addressArray as $field => $value) {
1099
+ if ($value === '') {
1100
+ $addressArray[$field] = null;
1101
+ }
1102
+ }
1103
+
1104
  return $addressArray;
1105
  }
1106
 
1166
  }
1167
 
1168
  /**
1169
+ * Generates the CIF amount object containing the shipment's insured amount (if any).
1170
  *
1171
+ * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
1172
+ * @param Mage_Sales_Model_Order_Shipment|boolean $shipment
1173
  *
1174
  * @return array
1175
  */
1176
+ protected function _getAmount(TIG_PostnL_Model_Core_Shipment $postnlShipment, $shipment = false)
1177
  {
1178
  $amount = array();
1179
  if (!$postnlShipment->hasExtraCover() && !$postnlShipment->isCod()) {
1195
  }
1196
 
1197
  if ($postnlShipment->isCod()) {
1198
+ if (!$shipment) {
1199
+ $shipment = $postnlShipment->getShipment();
1200
+ }
1201
+
1202
+ $order = $shipment->getOrder();
1203
+
1204
+ $value = number_format($order->getBaseGrandTotal(), 2, '.', '');
1205
+ $amount[] = array(
1206
+ 'AccountName' => $this->_getCodAccountName(),
1207
+ 'BIC' => $this->_getCodBic(),
1208
+ 'IBAN' => $this->_getCodIban(),
1209
+ 'AmountType' => '01', // 01 = COD, 02 = Insured
1210
+ 'Currency' => $order->getBaseCurrencyCode(),
1211
+ 'Reference' => $this->_getReference($shipment),
1212
+ 'TransactionNumber' => '',
1213
+ 'Value' => $value,
1214
+ );
1215
  }
1216
 
1217
  return $amount;
1226
  *
1227
  * @return array
1228
  */
1229
+ protected function _getContact($address, $postnlShipment, $order)
 
1230
  {
1231
  $smsNr = $this->_getMobilePhoneNumber($postnlShipment);
1232
 
1383
  $content = array();
1384
  $items = $this->_sortCustomsItems($shipment->getAllItems());
1385
 
1386
+ $helper = Mage::helper('postnl');
1387
+
1388
  /**
1389
  * @var Mage_Sales_Model_Order_Shipment_Item $item
1390
  */
1399
  /**
1400
  * Calculate the item's weight in kg
1401
  */
1402
+ $itemWeight = $helper->standardizeWeight(
1403
  $item->getWeight(),
1404
  $this->getStoreId()
1405
  );
1457
  * Get the attribute and direction used for sorting
1458
  */
1459
  $sortingAttribute = Mage::getStoreConfig(
1460
+ self::XPATH_GLOBALPACK_PRODUCT_SORTING_ATTRIBUTE,
1461
  $this->getStoreId()
1462
  );
1463
  $sortingDirection = Mage::getStoreConfig(
1464
+ self::XPATH_GLOBALPACK_PRODUCT_SORTING_DIRECTION,
1465
  $this->getStoreId()
1466
  );
1467
 
1471
  * @var Mage_Sales_Model_Order_Shipment_Item $item
1472
  */
1473
  foreach ($items as $item) {
1474
+ $product = Mage::getModel('catalog/product')->load($item->getOrderItem()->getProductId());
1475
+ if (!$product) {
1476
+ continue;
1477
+ }
1478
+
1479
  $sortingAttributeValue = $product->getDataUsingMethod($sortingAttribute);
1480
  $sortedItems[$item->getId()] = $sortingAttributeValue;
1481
  }
1514
  /**
1515
  * HS Tariff is an optional attribute. Check if it's used and if not, return a default value of 000000
1516
  */
1517
+ if (!Mage::getStoreConfig(self::XPATH_GLOBALPACK_USE_HS_TARIFF_ATTRIBUTE, $storeId)) {
1518
  return '000000';
1519
  }
1520
 
1521
  if ($this->hasHSTariffAttribute()) {
1522
  $hsTariffAttribute = $this->getHSTariffAttribute();
1523
  } else {
1524
+ $hsTariffAttribute = Mage::getStoreConfig(self::XPATH_GLOBALPACK_HS_TARIFF_ATTRIBUTE, $storeId);
1525
  $this->setHSTariffAttribute($hsTariffAttribute);
1526
  }
1527
 
1528
+ $product = Mage::getModel('catalog/product')->load($shipmentItem->getOrderItem()->getProductId());
1529
+ $hsTariff = $product->getDataUsingMethod($hsTariffAttribute);
 
1530
 
1531
  if (empty($hsTariff)) {
1532
  $hsTariff = '000000';
1551
  $countryOfOriginAttribute = $this->getCountryOfOriginAttribute();
1552
  } else {
1553
  $countryOfOriginAttribute = Mage::getStoreConfig(
1554
+ self::XPATH_GLOBALPACK_COUNTRY_OF_ORIGIN_ATTRIBUTE,
1555
  $storeId
1556
  );
1557
  $this->setCountryOfOriginAttribute($countryOfOriginAttribute);
1558
  }
1559
 
1560
+ $product = Mage::getModel('catalog/product')->load($shipmentItem->getOrderItem()->getProductId());
1561
+ $countryOfOrigin = $product->getDataUsingMethod($countryOfOriginAttribute);
 
1562
 
1563
  if (empty($countryOfOrigin)) {
1564
+ $productId = $shipmentItem->getProductId();
1565
  throw new TIG_PostNL_Exception(
1566
  Mage::helper('postnl')->__(
1567
+ 'Missing country of origin value for product <a href="%s" target="_blank">#%s</a>.',
1568
+ Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit', array('id' => $productId)),
1569
+ $productId
1570
  ),
1571
  'POSTNL-0091'
1572
  );
1590
  if ($this->hasCustomsValueAttribute()) {
1591
  $customsValueAttribute = $this->getCustomsValueAttribute();
1592
  } else {
1593
+ $customsValueAttribute = Mage::getStoreConfig(self::XPATH_GLOBALPACK_CUSTOMS_VALUE_ATTRIBUTE, $storeId);
1594
  $this->setCustomsValueAttribute($customsValueAttribute);
1595
  }
1596
 
1597
+ $product = Mage::getModel('catalog/product')->load($shipmentItem->getOrderItem()->getProductId());
1598
+ $customsValue = $product->getDataUsingMethod($customsValueAttribute);
 
1599
 
1600
  if (empty($customsValue)) {
1601
+ $productId = $shipmentItem->getProductId();
1602
  throw new TIG_PostNL_Exception(
1603
+ Mage::helper('postnl')->__(
1604
+ 'Missing customs value for product <a href="%s" target="_blank">#%s</a>.',
1605
+ Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit', array('id' => $productId)),
1606
+ $productId
1607
+ ),
1608
  'POSTNL-0092'
1609
  );
1610
  }
1627
  if ($this->hasCustomsDescriptionAttribute()) {
1628
  $descriptionAttribute = $this->getCustomsDescriptionAttribute();
1629
  } else {
1630
+ $descriptionAttribute = Mage::getStoreConfig(self::XPATH_GLOBALPACK_DESCRIPTION_ATTRIBUTE, $storeId);
1631
  $this->setCustomsDescriptionAttribute($descriptionAttribute);
1632
  }
1633
 
1634
+ $product = Mage::getModel('catalog/product')->load($shipmentItem->getOrderItem()->getProductId());
1635
+ $description = $product->getDataUsingMethod($descriptionAttribute);
 
1636
 
1637
  if (empty($description)) {
1638
+ $productId = $shipmentItem->getProductId();
1639
  throw new TIG_PostNL_Exception(
1640
  Mage::helper('postnl')->__(
1641
+ 'Missing customs description for product <a href="%s" target="_blank">#%s</a>.',
1642
+ Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit', array('id' => $productId)),
1643
+ $productId
1644
  ),
1645
+ 'POSTNL-0092'
1646
  );
1647
  }
1648
 
1657
  protected function _getCustomerCode()
1658
  {
1659
  $storeId = $this->getStoreId();
1660
+ $customerCode = (string) Mage::getStoreConfig(self::XPATH_CUSTOMER_CODE, $storeId);
1661
 
1662
  return $customerCode;
1663
  }
1670
  protected function _getCustomerNumber()
1671
  {
1672
  $storeId = $this->getStoreId();
1673
+ $customerNumber = (string) Mage::getStoreConfig(self::XPATH_CUSTOMER_NUMBER, $storeId);
1674
 
1675
  return $customerNumber;
1676
  }
1683
  protected function _getCollectionLocation()
1684
  {
1685
  $storeId = $this->getStoreId();
1686
+ $collectionLocation = (string) Mage::getStoreConfig(self::XPATH_COLLECTION_LOCATION, $storeId);
1687
 
1688
  return $collectionLocation;
1689
  }
1696
  protected function _getGlobalBarcodeType()
1697
  {
1698
  $storeId = $this->getStoreId();
1699
+ $barcodeType = (string) Mage::getStoreConfig(self::XPATH_GLOBAL_BARCODE_TYPE, $storeId);
1700
 
1701
  return $barcodeType;
1702
  }
1709
  protected function _getGlobalBarcodeRange()
1710
  {
1711
  $storeId = $this->getStoreId();
1712
+ $barcodeRange = (string) Mage::getStoreConfig(self::XPATH_GLOBAL_BARCODE_RANGE, $storeId);
1713
 
1714
  return $barcodeRange;
1715
  }
1722
  protected function _getCustomsLicense()
1723
  {
1724
  $storeId = $this->getStoreId();
1725
+ $customsLicense = (string) Mage::getStoreConfig(self::XPATH_GLOBALPACK_CUSTOMS_LICENSE_NUMBER, $storeId);
1726
 
1727
  if (empty($customsLicense)) {
1728
  return false;
1740
  {
1741
  $storeId = $this->getStoreId();
1742
  $customsCertificate = (string) Mage::getStoreConfig(
1743
+ self::XPATH_GLOBALPACK_CUSTOMS_CERTIFICATE_NUMBER,
1744
  $storeId
1745
  );
1746
 
1761
  protected function _getArea($address)
1762
  {
1763
  $storeId = $this->getStoreId();
1764
+ $areaField = (string) Mage::getStoreConfig(self::XPATH_AREA_FIELD, $storeId);
1765
  if ($areaField) {
1766
  $area = $address->getStreet($areaField);
1767
 
1787
  protected function _getBuildingName($address)
1788
  {
1789
  $storeId = $this->getStoreId();
1790
+ $buildingNameField = (string) Mage::getStoreConfig(self::XPATH_BUILDING_NAME_FIELD, $storeId);
1791
  if ($buildingNameField) {
1792
  $buildingName = $address->getStreet($buildingNameField);
1793
 
1813
  protected function _getDepartment($address)
1814
  {
1815
  $storeId = $this->getStoreId();
1816
+ $departmentField = (string) Mage::getStoreConfig(self::XPATH_DEPARTMENT_FIELD, $storeId);
1817
  if ($departmentField) {
1818
  $department = $address->getStreet($departmentField);
1819
 
1830
  }
1831
 
1832
  /**
1833
+ * Get the door code field from an address if enabled
1834
  *
1835
  * @param Mage_Sales_Model_Order_Address $address
1836
  *
1839
  protected function _getDoorcode($address)
1840
  {
1841
  $storeId = $this->getStoreId();
1842
+ $doorcodeField = (string) Mage::getStoreConfig(self::XPATH_DOORCODE_FIELD, $storeId);
1843
  if (!$doorcodeField) {
1844
  $doorcode = $address->getStreet($doorcodeField);
1845
 
1847
  }
1848
 
1849
  /**
1850
+ * Attempt to get the door code through the magic getter instead
1851
  */
1852
  /** @noinspection PhpUndefinedMethodInspection */
1853
  $doorcode = $address->getDoorcode();
1865
  protected function _getFloor($address)
1866
  {
1867
  $storeId = $this->getStoreId();
1868
+ $floorField = (string) Mage::getStoreConfig(self::XPATH_FLOOR_FIELD, $storeId);
1869
  if ($floorField) {
1870
  $floor = $address->getStreet($floorField);
1871
 
1891
  protected function _getRemark($address)
1892
  {
1893
  $storeId = $this->getStoreId();
1894
+ $remarkField = (string) Mage::getStoreConfig(self::XPATH_REMARK_FIELD, $storeId);
1895
  if ($remarkField) {
1896
  $remark = $address->getStreet($remarkField);
1897
 
1916
  *
1917
  * @throws TIG_PostNL_Exception
1918
  */
1919
+ protected function _getReference($shipment)
1920
+ {
1921
+ $storeId = $this->getStoreId();
1922
+ $referenceType = Mage::getStoreConfig(self::XPATH_SHIPMENT_REFERENCE_TYPE, $storeId);
1923
+
1924
+ /**
1925
+ * Parse the reference type
1926
+ */
1927
+ switch ($referenceType) {
1928
+ case '': //no break
1929
+ case 'none':
1930
+ $reference = '';
1931
+ break;
1932
+ case 'shipment_increment_id':
1933
+ $reference = $shipment->getIncrementId();
1934
+ break;
1935
+ case 'order_increment_id':
1936
+ $reference = $shipment->getOrder()->getIncrementId();
1937
+ break;
1938
+ case 'custom':
1939
+ $reference = Mage::getStoreConfig(self::XPATH_CUSTOM_SHIPMENT_REFERENCE, $storeId);
1940
+ break;
1941
+ default:
1942
+ throw new TIG_PostNL_Exception(
1943
+ Mage::helper('postnl')->__('Invalid reference type requested: %s', $referenceType),
1944
+ 'POSTNL-0043'
1945
+ );
1946
+ }
1947
+
1948
+ /**
1949
+ * For custom references we need to replace several optional variables
1950
+ */
1951
+ if ($referenceType == 'custom') {
1952
+ $store = Mage::getModel('core/store')->load($storeId);
1953
+
1954
+ $reference = str_replace('{{var shipment_increment_id}}', $shipment->getIncrementId(), $reference);
1955
+ $reference = str_replace('{{var order_increment_id}}', $shipment->getOrder()->getIncrementId(), $reference);
1956
+
1957
+ $reference = str_replace('{{var store_frontend_name}}', $store->getFrontendName(), $reference);
1958
+ }
1959
+
1960
+ return $reference;
1961
+ }
1962
+
1963
+ /**
1964
+ * Gets account name for COD shipments.
1965
+ *
1966
+ * @return string
1967
+ */
1968
+ protected function _getCodAccountName()
1969
+ {
1970
+ $storeId = $this->getStoreId();
1971
+ $customerNumber = (string) Mage::getStoreConfig(self::XPATH_COD_ACCOUNT_NAME, $storeId);
1972
+
1973
+ return $customerNumber;
1974
+ }
1975
+
1976
+ /**
1977
+ * Gets BIC code for COD shipments.
1978
+ *
1979
+ * @return string
1980
+ */
1981
+ protected function _getCodBic()
1982
+ {
1983
+ $storeId = $this->getStoreId();
1984
+ $customerNumber = (string) Mage::getStoreConfig(self::XPATH_COD_BIC, $storeId);
1985
+
1986
+ return $customerNumber;
1987
+ }
1988
+
1989
+ /**
1990
+ * Gets IBAN code for COD shipments.
1991
+ *
1992
+ * @return string
1993
+ */
1994
+ protected function _getCodIban()
1995
+ {
1996
+ $storeId = $this->getStoreId();
1997
+ $customerNumber = (string) Mage::getStoreConfig(self::XPATH_COD_IBAN, $storeId);
1998
+
1999
+ return $customerNumber;
2000
+ }
2001
  }
app/code/community/TIG/PostNL/Model/Core/Cif/Abstract.php CHANGED
@@ -307,7 +307,7 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
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
@@ -326,6 +326,9 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
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),
@@ -334,18 +337,18 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
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
 
@@ -353,7 +356,7 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
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
  */
@@ -387,8 +390,7 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
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
392
  */
393
  $wsdlType = strtolower($wsdlType);
394
  switch ($wsdlType) {
@@ -432,7 +434,7 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
432
  }
433
 
434
  /**
435
- * Check if we need the live or the sandbox wsdl
436
  */
437
  if ($this->isTestMode()) {
438
  $wsdlUrl = self::TEST_WSDL_BASE_URL;
@@ -441,7 +443,7 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
441
  }
442
 
443
  /**
444
- * Format the final wsdl URL
445
  */
446
  $wsdlUrl .= $wsdlFileName
447
  . '/'
@@ -479,7 +481,7 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
479
  *
480
  * @param Zend_Soap_Client $client
481
  *
482
- * @return TIG_PostNL_Model_Core_Cif_Abstract
483
  */
484
  protected function _processWarnings($client)
485
  {
@@ -539,11 +541,16 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
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
 
@@ -590,7 +597,17 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
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
  }
@@ -603,11 +620,17 @@ abstract class TIG_PostNL_Model_Core_Cif_Abstract extends Varien_Object
603
  ->setResponseXml($responseXML);
604
  }
605
 
606
- /**
607
- * Log the exception and throw it
608
- */
609
- $cifHelper->logCifException($exception);
 
 
610
 
611
- throw $exception;
 
 
 
 
612
  }
613
  }
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
326
  */
327
  $client = $this->getSoapClient($wsdlType);
328
 
329
+ /**
330
+ * Check if the requested SOAP method is callable.
331
+ */
332
  if (!is_callable(array($client, $method))) {
333
  throw new TIG_PostNL_Exception(
334
  Mage::helper('postnl')->__('The specified method "%s" is not callable.', $method),
337
  }
338
 
339
  /**
340
+ * Add SOAP header,
341
  */
342
  $header = $this->_getSoapHeader();
343
  $client->addSoapInputHeader($header, true); //permanent header
344
 
345
  /**
346
+ * Call the SOAP method,
347
  */
348
  $response = $client->$method($soapParams);
349
 
350
  /**
351
+ * Process any warnings that may have occurred,
352
  */
353
  $this->_processWarnings($client);
354
 
356
  return $response;
357
  } catch(SoapFault $e) {
358
  /**
359
+ * Only Soap exceptions are caught. Other exceptions must be caught by the caller,
360
  *
361
  * @throws TIG_PostNL_Exception
362
  */
390
  $adminStoreId = Mage_Core_Model_App::ADMIN_STORE_ID;
391
 
392
  /**
393
+ * Check which wsdl file we need for each wsdl type and get the configured WSDl version to use.
 
394
  */
395
  $wsdlType = strtolower($wsdlType);
396
  switch ($wsdlType) {
434
  }
435
 
436
  /**
437
+ * Check if we need the live or the sandbox wsdl.
438
  */
439
  if ($this->isTestMode()) {
440
  $wsdlUrl = self::TEST_WSDL_BASE_URL;
443
  }
444
 
445
  /**
446
+ * Format the final wsdl URL.
447
  */
448
  $wsdlUrl .= $wsdlFileName
449
  . '/'
481
  *
482
  * @param Zend_Soap_Client $client
483
  *
484
+ * @return $this
485
  */
486
  protected function _processWarnings($client)
487
  {
541
  *
542
  * @param SoapFault $e
543
  * @param Zend_Soap_Client $client
544
+ * @param boolean $throwException
545
+ *
546
+ * @return $this
547
  *
548
  * @throws TIG_PostNL_Model_Core_Cif_Exception
549
  */
550
+ protected function _handleCifException(SoapFault $e, $client = null, $throwException = true)
551
  {
552
+ $logException = true;
553
+
554
  $cifHelper = Mage::helper('postnl/cif');
555
  $exception = new TIG_PostNL_Model_Core_Cif_Exception($e->getMessage(), null, $e);
556
 
597
  $errorNumbers = $errorResponse->getElementsByTagNameNS(self::CIF_ERROR_NAMESPACE, 'ErrorNumber');
598
  if ($errorNumbers) {
599
  foreach ($errorNumbers as $errorNumber) {
600
+ /**
601
+ * Error number 13 means that the shipment was not found by PostNL. This error is very common and
602
+ * can be completely valid. To prevent the log files from filling up extremely quickly, we do not
603
+ * log this error.
604
+ */
605
+ $value = $errorNumber->nodeValue;
606
+ if ($value == '13') {
607
+ $logException = false;
608
+ }
609
+
610
+ $exception->addErrorNumber($value);
611
  }
612
  }
613
  }
620
  ->setResponseXml($responseXML);
621
  }
622
 
623
+ if ($logException) {
624
+ /**
625
+ * Log the exception and throw it.
626
+ */
627
+ $cifHelper->logCifException($exception);
628
+ }
629
 
630
+ if ($throwException) {
631
+ throw $exception;
632
+ }
633
+
634
+ return $this;
635
  }
636
  }
app/code/community/TIG/PostNL/Model/Core/Cif/Exception.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
 
@@ -73,7 +73,7 @@ class TIG_PostNL_Model_Core_Cif_Exception extends TIG_PostNL_Exception
73
  *
74
  * @param $xml
75
  *
76
- * @return TIG_PostNL_Model_Core_Cif_Exception
77
  */
78
  public function setRequestXml($xml)
79
  {
@@ -86,7 +86,7 @@ class TIG_PostNL_Model_Core_Cif_Exception extends TIG_PostNL_Exception
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
  {
@@ -100,7 +100,7 @@ class TIG_PostNL_Model_Core_Cif_Exception extends TIG_PostNL_Exception
100
  *
101
  * @param array $errorNumbers
102
  *
103
- * @return TIG_PostNL_Model_Core_Cif_Exception
104
  */
105
  public function setErrorNumbers($errorNumbers)
106
  {
@@ -139,12 +139,24 @@ class TIG_PostNL_Model_Core_Cif_Exception extends TIG_PostNL_Exception
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
  {
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
 
73
  *
74
  * @param $xml
75
  *
76
+ * @return $this
77
  */
78
  public function setRequestXml($xml)
79
  {
86
  * Set $_responseXml to specified value
87
  *
88
  * @param $xml
89
+ * @return $this
90
  */
91
  public function setResponseXml($xml)
92
  {
100
  *
101
  * @param array $errorNumbers
102
  *
103
+ * @return $this
104
  */
105
  public function setErrorNumbers($errorNumbers)
106
  {
139
  return $this->_errorNumbers;
140
  }
141
 
142
+ /**
143
+ * @param string|int $code
144
+ *
145
+ * @return $this
146
+ */
147
+ public function setCode($code)
148
+ {
149
+ $this->code = $code;
150
+
151
+ return $this;
152
+ }
153
+
154
  /**
155
  * Add an error number to the error numbers array
156
  *
157
  * @param int $errorNumber
158
  *
159
+ * @return $this
160
  */
161
  public function addErrorNumber($errorNumber)
162
  {
app/code/community/TIG/PostNL/Model/Core/Label.php CHANGED
@@ -41,16 +41,23 @@
41
  class TIG_PostNL_Model_Core_Label extends Varien_Object
42
  {
43
  /**
44
- * base name of temporary pdf files. An md5 hash will be prepended to this name in order to make each filename unique
 
45
  */
46
- const TEMP_LABEL_FILENAME = 'TIG_PostNL_temp.pdf';
 
47
 
48
  /**
49
  * XML path to label size setting
50
  *
51
  * This setting is ignored for GlobalPack labels and single Dutch or EPS labels
52
  */
53
- const XML_PATH_LABEL_SIZE = 'postnl/cif_labels_and_confirming/label_size';
 
 
 
 
 
54
 
55
  /**
56
  * An array of temporary files that have been created. these files will be destroyed at the end of the script.
@@ -73,10 +80,170 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
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
  {
@@ -93,6 +260,26 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
93
  return $this->_isFirstLabel;
94
  }
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  /**
97
  * Get the array of saved temporary labels
98
  *
@@ -108,7 +295,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
108
  *
109
  * @param array $tempFilesSaved
110
  *
111
- * @return TIG_PostNL_Model_Core_Label
112
  */
113
  public function setTempFilesSaved($tempFilesSaved)
114
  {
@@ -132,7 +319,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
132
  *
133
  * @param int $counter
134
  *
135
- * @return TIG_PostNL_Model_Core_Label
136
  */
137
  public function setLabelCounter($counter)
138
  {
@@ -152,16 +339,61 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
152
  return $this->getData('label_size');
153
  }
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  /**
162
  * Reset the counter to 0
163
  *
164
- * @return TIG_PostNL_Model_Core_Label
165
  */
166
  public function resetLabelCounter()
167
  {
@@ -175,7 +407,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
175
  *
176
  * @param int $increase
177
  *
178
- * @return TIG_PostNL_Model_Core_Label
179
  */
180
  public function increaseLabelCounter($increase = 1)
181
  {
@@ -192,7 +424,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
192
  *
193
  * @param string $tempFile
194
  *
195
- * @return TIG_PostNL_Model_Core_Label
196
  */
197
  public function addTempFileSaved($tempFile)
198
  {
@@ -206,30 +438,29 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
206
 
207
  /**
208
  * Creates a pdf containing shipping labels using FPDF and FPDI libraries.
209
- * Four labels will be printed on each page in a vertical position. All labels will be rotated 90 degrees counter-clockwise
 
210
  *
211
- * @param mixed $labels May be an array of labels or a single label string
 
212
  *
213
- * @return TIG_PostNL_Model_Core_Label
214
  *
215
  * @see TIG_PostNL_Fpdf
216
  * @see TIG_PostNL_Fpdi
217
  *
218
- * @link http://www.fpdf.org/ Fpdf library documentation
219
- * @link http://www.setasign.de/products/pdf-php-solutions/fpdi/ Fpdi library
220
  */
221
  public function createPdf($labels)
222
  {
223
  Varien_Profiler::start('tig::postnl::core::label_createpdf');
224
 
225
  /**
226
- * Open a new pdf object and assign some basic values
227
  */
228
  $pdf = new TIG_PostNL_Fpdi(); //lib/TIG/PostNL/Fpdi
229
  $pdf->open();
230
- $pdf->SetFont('Arial', 'I', 40);
231
- $pdf->SetTextColor(0,0,0);
232
- $pdf->SetFillColor(255,255,255);
233
  $pdf->SetTitle('PostNL Shipping Labels');
234
  $pdf->SetAuthor('PostNL');
235
  $pdf->SetCreator('PostNL');
@@ -238,25 +469,89 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
238
  $labels = array($labels);
239
  }
240
  /**
241
- * Create a pdf containing multiple labels
242
  */
243
  $pdf = $this->_createMultiLabelPdf($pdf, $labels);
244
 
245
  /**
246
- * Destroy the temporary labels as they are no longer needed
247
  */
248
  $this->_destroyTempLabels();
249
 
250
  /**
251
  * Get the final label.
252
  */
253
- $label = $pdf->Output('PostNL Shipping Labels.pdf', 'I');
254
 
255
  Varien_Profiler::stop('tig::postnl::core::label_createpdf');
256
 
257
  return $label;
258
  }
259
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  /**
261
  * Adds multiple labels to the pdf
262
  *
@@ -273,12 +568,11 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
273
  * Check if printing the required number of labels is allowed.
274
  *
275
  * This is limited to 200 by default to prevent out of memory errors.
276
- * On a clean Magento install with 256 MB of memory, several thousands of
277
- * labels can be printed at once. However, for safety reasons a limit
278
- * of 200 is used. By default you shouldn't be able to select more than 200
279
  * in the shipment grid.
280
  */
281
- if(count($labels) > 200 && !Mage::helper('postnl/cif')->allowInfinitePrinting()) {
282
  throw new TIG_PostNL_Exception(
283
  Mage::helper('postnl')->__(
284
  'Maximum amount of labels exceeded. Maximum allowed: 200. Requested: %s',
@@ -289,7 +583,8 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
289
  }
290
 
291
  $this->setIsFirstLabel(true);
292
- $labels = $this->_sortLabels($labels);
 
293
  foreach ($labels as $label) {
294
  $pdf = $this->_addPdfTemplate($pdf, $label);
295
  }
@@ -298,7 +593,9 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
298
  }
299
 
300
  /**
301
- * Adds a label to the pdf by storing it in a temporary pdf file and then adding it to the master pdf object
 
 
302
  *
303
  * @param TIG_PostNL_Fpdi $pdf
304
  * @param TIG_PostNL_Model_Core_Shipment_Label $label
@@ -311,9 +608,9 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
311
  {
312
  /**
313
  * Fpdi requires labels to be provided as files. Therefore the label will be saved as a temporary file in
314
- * var/TIG/PostNL/temp_labels/
315
  */
316
- $tempFilename = $this->_saveTempLabel($label->getLabel());
317
 
318
  $rotate = false;
319
 
@@ -321,31 +618,46 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
321
  * First we need to add pages to the pdf for certain label types under certain conditions.
322
  */
323
  $labelType = $label->getLabelType();
324
- if ($labelType == 'Label' || $labelType == 'Label-combi') {
325
- if ($this->getLabelSize() == 'A4'
326
- && (!$this->getLabelCounter() || $this->getLabelCounter() > 4)
 
 
 
 
 
 
 
 
 
 
 
 
327
  ) {
328
  $pdf->addOrientedPage('L', 'A4');
329
  $this->resetLabelCounter();
330
- } elseif ($this->getLabelSize() == 'A4' && $this->getIsFirstLabel()) {
331
- $pdf->addOrientedPage('L', 'A4');
332
- $this->setIsFirstLabel(false);
333
  }
334
 
335
  /**
336
- * If the configured label size is A6, add a new page every label
337
  */
338
  if($this->getLabelSize() == 'A6') {
339
  $this->setLabelCounter(3); //used to calculate the top left position
340
  $pdf->addOrientedPage('L', 'A6');
341
  }
342
- } else if ($labelType == 'CN23'
 
 
343
  || $labelType == 'CommercialInvoice'
344
  || $labelType == 'CODcard'
345
  ) {
346
  $pdf->addOrientedPage('P', 'A4');
347
  }
348
 
 
 
 
 
349
  switch ($labelType) {
350
  case 'Label-combi':
351
  /**
@@ -353,70 +665,44 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
353
  */
354
  $pdf->Rotate('-90');
355
 
356
- /**
357
- * Calculate the position of the next label to be printed
358
- */
359
- $position = $this->_getRotatedPosition($this->getLabelCounter());
360
- $position['w'] = $this->pix2pt(400);
361
 
362
  $this->increaseLabelCounter();
363
 
364
  $rotate = true;
365
  break;
366
  case 'Label':
367
- /**
368
- * Calculate the position of the next label to be printed
369
- */
370
- $position = $this->_getPosition($this->getLabelCounter());
371
- $position['w'] = $this->pix2pt(538);
372
 
373
  $this->increaseLabelCounter();
374
  break;
375
  case 'CN23':
376
  case 'CommercialInvoice':
377
- /**
378
- * Calculate the position of the next label to be printed
379
- */
380
- $position = array(
381
- 'x' => $this->pix2pt(15),
382
- 'y' => $this->pix2pt(17),
383
- 'w' => $this->pix2pt(776)
384
- );
385
 
386
  /**
387
- * increase the label counter to above 4. This will prompt the creation of a new page
388
  */
389
  $this->setLabelCounter(5);
390
  break;
391
  case 'CP71':
392
- /**
393
- * Calculate the position of the next label to be printed
394
- */
395
- $position = array(
396
- 'x' => $this->pix2pt(15),
397
- 'y' => $this->pix2pt(578),
398
- 'w' => $this->pix2pt(776)
399
- );
400
 
401
  /**
402
- * increase the label counter to above 4. This will prompt the creation of a new page
403
  */
404
  $this->setLabelCounter(5);
405
  break;
406
  case 'CODcard':
407
- /**
408
- * Calculate the position of the next label to be printed
409
- */
410
- $position = array(
411
- 'x' => $this->pix2pt(15),
412
- 'y' => $this->pix2pt(17),
413
- 'w' => $this->pix2pt(776)
414
- );
415
 
416
- /**
417
- * increase the label counter to above 4. This will prompt the creation of a new page
418
- */
419
- $this->setLabelCounter(5);
 
420
  break;
421
  default:
422
  throw new TIG_PostNL_Exception(
@@ -426,7 +712,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
426
  }
427
 
428
  /**
429
- * Add the next label to the pdf
430
  */
431
  $pdf->insertTemplate($tempFilename, $position['x'], $position['y'], $position['w']);
432
 
@@ -443,20 +729,20 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
443
  /**
444
  * Save a label to a temporary pdf file. Temporary pdf files are stored in var/TIG/PostNL/temp_label/
445
  *
446
- * @param string $label
447
  *
448
  * @throws TIG_PostNL_Exception
449
  *
450
  * @return string
451
  */
452
- protected function _saveTempLabel($label)
453
  {
454
  /**
455
- * construct the path to the temporary file
456
  */
457
  $tempFilePath = Mage::getConfig()->getVarDir('TIG' . DS . 'PostNL' . DS . 'temp_label')
458
  . DS
459
- . md5($label)
460
  . '-'
461
  . time()
462
  . '-'
@@ -470,12 +756,55 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
470
  }
471
 
472
  /**
473
- * Add the base64 decoded label to the file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  */
475
- file_put_contents($tempFilePath, base64_decode($label));
476
 
477
  /**
478
- * Save the name of the temp file so it can be destroyed later
479
  */
480
  $this->addTempFileSaved($tempFilePath);
481
 
@@ -485,29 +814,29 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
485
  /**
486
  * Destroy all temporary pdf files
487
  *
488
- * @return TIG_PostNL_Model_Core_Label
489
  */
490
  protected function _destroyTempLabels()
491
  {
492
  $tempFilesSaved = $this->getTempFilesSaved();
493
  foreach ($tempFilesSaved as $tempFile) {
494
- unlink($tempFile);
 
 
495
  }
496
 
497
  return $this;
498
  }
499
 
500
  /**
501
- * Sorts labels by label type. First all labels of the 'Label' type. Then all other labels in the
502
- * order of 'CN23' > 'CP71' > 'CommercialInvoice' grouped by shipments
503
  *
504
  * @param array $labels
505
  *
506
  * @return array
507
- *
508
- * @todo expand with cod labels
509
  */
510
- protected function _sortLabels($labels)
511
  {
512
  $generalLabels = array();
513
  $globalLabels = array();
@@ -518,15 +847,19 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
518
  */
519
  foreach ($labels as $label) {
520
  /**
521
- * Separate general labels from the rest
522
  */
523
- if ($label->getLabelType() == 'Label' || $label->getLabelType() == 'Label-combi') {
 
 
 
 
524
  $generalLabels[] = $label;
525
  continue;
526
  }
527
 
528
  /**
529
- * Separate COD cards
530
  */
531
  if ($label->getLabelType() == 'CODcard') {
532
  $codCards[] = $label;
@@ -534,7 +867,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
534
  }
535
 
536
  /**
537
- * Group other labels by shipment id (parent_id attribute)
538
  */
539
  if (isset($globalLabels[$label->getParentId()])) {
540
  $globalLabels[$label->getParentId()][$label->getLabelType()] = $label;
@@ -544,7 +877,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
544
  }
545
 
546
  /**
547
- * Sort all non-standard labels
548
  */
549
  $sortedGlobalLabels = array();
550
  foreach ($globalLabels as $shipmentLabels) {
@@ -562,103 +895,12 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
562
  }
563
 
564
  /**
565
- * merge all labels back into a single array
566
  */
567
  $labels = array_merge($generalLabels, $sortedGlobalLabels, $codCards);
568
  return $labels;
569
  }
570
 
571
- /**
572
- * Calculates the position of the requested label using a counter system.
573
- * The labels will be positioned accordingly:
574
- * first: top left
575
- * second: top right
576
- * third: bottom left
577
- * fourth: bottom right
578
- *
579
- * @param bool|int $counter
580
- *
581
- * @throws TIG_PostNL_Exception
582
- *
583
- * @return array
584
- */
585
- protected function _getPosition($counter = false)
586
- {
587
- if ($counter === false) {
588
- $position = array('x' => 0, 'y' => 0);
589
-
590
- return $position;
591
- }
592
-
593
- switch($counter) {
594
- case 1:
595
- $position = array('x' => $this->pix2pt(579), 'y' => $this->pix2pt(15));
596
- break;
597
- case 2:
598
- $position = array('x' => $this->pix2pt(579), 'y' => $this->pix2pt(414));
599
- break;
600
- case 3:
601
- $position = array('x' => $this->pix2pt(15), 'y' => $this->pix2pt(15));
602
- break;
603
- case 4:
604
- $position = array('x' => $this->pix2pt(15), 'y' => $this->pix2pt(414));
605
- break;
606
- default:
607
- throw new TIG_PostNL_Exception(
608
- Mage::helper('postnl')->__('Invalid counter: %s', $counter),
609
- 'POSTNL-0067'
610
- );
611
- }
612
-
613
- return $position;
614
- }
615
-
616
- /**
617
- * Calculates the position of the requested label using a counter system. This method is for labels which are
618
- * rotated by 90 degrees. Currently this is only used for EPS combi-labels.
619
- * The labels will be positioned accordingly:
620
- * first: top left
621
- * second: top right
622
- * third: bottom left
623
- * fourth: bottom right
624
- *
625
- * @param bool|int $counter
626
- *
627
- * @throws TIG_PostNL_Exception
628
- *
629
- * @return array
630
- */
631
- protected function _getRotatedPosition($counter = false)
632
- {
633
- if ($counter === false) {
634
- $position = array('x' => 0, 'y' => 0);
635
-
636
- return $position;
637
- }
638
-
639
- switch($counter) {
640
- case 1:
641
- $position = array('x' => $this->pix2pt(2), 'y' => $this->pix2pt(-1055));
642
- break;
643
- case 2:
644
- $position = array('x' => $this->pix2pt(400), 'y' => $this->pix2pt(-1055));
645
- break;
646
- case 3:
647
- $position = array('x' => $this->pix2pt(2), 'y' => $this->pix2pt(-483));
648
- break;
649
- case 4:
650
- $position = array('x' => $this->pix2pt(400), 'y' => $this->pix2pt(-483));
651
- break;
652
- default:
653
- throw new TIG_PostNL_Exception(
654
- Mage::helper('postnl')->__('Invalid counter: %s', $counter),
655
- 'POSTNL-0067'
656
- );
657
- }
658
-
659
- return $position;
660
- }
661
-
662
  /**
663
  * Converts pixels to points. 3.8 pixels is 1 pt in pdfs.
664
  *
@@ -669,7 +911,7 @@ class TIG_PostNL_Model_Core_Label extends Varien_Object
669
  public function pix2pt($pixels = 0)
670
  {
671
  if($pixels != 0) {
672
- $points = round($pixels / 3.8, 1);
673
  return $points;
674
  }
675
 
41
  class TIG_PostNL_Model_Core_Label extends Varien_Object
42
  {
43
  /**
44
+ * Base name of temporary pdf files. An md5 hash and several other parameters will be prepended to this file name to
45
+ * make it unique.
46
  */
47
+ const TEMP_LABEL_FILENAME = 'TIG_PostNL_temp.pdf';
48
+ const TEMP_PACKINGSLIP_FILENAME = 'TIG_PostNL_temp_packingslip.pdf';
49
 
50
  /**
51
  * XML path to label size setting
52
  *
53
  * This setting is ignored for GlobalPack labels and single Dutch or EPS labels
54
  */
55
+ const XPATH_LABEL_SIZE = 'postnl/cif_labels_and_confirming/label_size';
56
+
57
+ /**
58
+ * Maximum number of labels that may be printed at once.
59
+ */
60
+ const MAX_LABEL_COUNT = 200;
61
 
62
  /**
63
  * An array of temporary files that have been created. these files will be destroyed at the end of the script.
80
  */
81
  protected $_isFirstLabel = false;
82
 
83
+ /**
84
+ * Flag if the current label is the first CODCard label processed.
85
+ *
86
+ * @var bool
87
+ */
88
+ protected $_isFirstCodCardLabel = false;
89
+
90
+ /**
91
+ * Output mode. Currently 2 modes are supported: I and S.
92
+ *
93
+ * @see lib/TIG/PostNL/Fpdf/fpdf.php::Output()
94
+ *
95
+ * @var string
96
+ */
97
+ protected $_outputMode = 'I';
98
+
99
+ /**
100
+ * An array of label position coordinates per position per label type.
101
+ *
102
+ * @var array
103
+ */
104
+ protected $_labelPositions = array(
105
+ 'Label' => array(
106
+ 1 => array(
107
+ 'x' => 152.4,
108
+ 'y' => 3.9,
109
+ 'w' => 141.6,
110
+ ),
111
+ 2 => array(
112
+ 'x' => 152.4,
113
+ 'y' => 108.9,
114
+ 'w' => 141.6,
115
+ ),
116
+ 3 => array(
117
+ 'x' => 3.9,
118
+ 'y' => 3.9,
119
+ 'w' => 141.6,
120
+ ),
121
+ 4 => array(
122
+ 'x' => 3.9,
123
+ 'y' => 108.9,
124
+ 'w' => 141.6,
125
+ ),
126
+ ),
127
+ 'BusPakje' => array(
128
+ 1 => array(
129
+ 'x' => 152.4,
130
+ 'y' => 3.9,
131
+ 'w' => 141.6,
132
+ ),
133
+ 2 => array(
134
+ 'x' => 152.4,
135
+ 'y' => 108.9,
136
+ 'w' => 141.6,
137
+ ),
138
+ 3 => array(
139
+ 'x' => 3.9,
140
+ 'y' => 3.9,
141
+ 'w' => 141.6,
142
+ ),
143
+ 4 => array(
144
+ 'x' => 3.9,
145
+ 'y' => 108.9,
146
+ 'w' => 141.6,
147
+ ),
148
+ ),
149
+ 'BusPakjeExtra' => array(
150
+ 1 => array(
151
+ 'x' => 152.4,
152
+ 'y' => 3.9,
153
+ 'w' => 141.6,
154
+ ),
155
+ 2 => array(
156
+ 'x' => 152.4,
157
+ 'y' => 108.9,
158
+ 'w' => 141.6,
159
+ ),
160
+ 3 => array(
161
+ 'x' => 3.9,
162
+ 'y' => 3.9,
163
+ 'w' => 141.6,
164
+ ),
165
+ 4 => array(
166
+ 'x' => 3.9,
167
+ 'y' => 108.9,
168
+ 'w' => 141.6,
169
+ ),
170
+ ),
171
+ 'Label-combi' => array(
172
+ 1 => array(
173
+ 'x' => 0.5,
174
+ 'y' => -277.6,
175
+ 'w' => 105.3,
176
+ ),
177
+ 2 => array(
178
+ 'x' => 105.3,
179
+ 'y' => -277.6,
180
+ 'w' => 105.3,
181
+ ),
182
+ 3 => array(
183
+ 'x' => 0.5,
184
+ 'y' => -127.1,
185
+ 'w' => 105.3,
186
+ ),
187
+ 4 => array(
188
+ 'x' => 105.3,
189
+ 'y' => -127.1,
190
+ 'w' => 105.3,
191
+ ),
192
+ ),
193
+ 'CODcard' => array(
194
+ array(
195
+ 'x' => 2,
196
+ 'y' => -39,
197
+ 'w' => 103,
198
+ ),
199
+ ),
200
+ 'CN23' => array(
201
+ array(
202
+ 'x' => 3.9,
203
+ 'y' => 4.5,
204
+ 'w' => 204.2,
205
+ ),
206
+ ),
207
+ 'CommercialInvoice' => array(
208
+ array(
209
+ 'x' => 3.9,
210
+ 'y' => 4.5,
211
+ 'w' => 204.2,
212
+ ),
213
+ ),
214
+ 'CP71' => array(
215
+ array(
216
+ 'x' => 3.9,
217
+ 'y' => 152.1,
218
+ 'w' => 204.2,
219
+ ),
220
+ ),
221
+ );
222
+
223
+ /**
224
+ * @param string $outputMode
225
+ *
226
+ * @return $this
227
+ */
228
+ public function setOutputMode($outputMode)
229
+ {
230
+ $this->_outputMode = $outputMode;
231
+
232
+ return $this;
233
+ }
234
+
235
+ /**
236
+ * @return string
237
+ */
238
+ public function getOutputMode()
239
+ {
240
+ return $this->_outputMode;
241
+ }
242
+
243
  /**
244
  * @param boolean $isFirstLabel
245
  *
246
+ * @return $this
247
  */
248
  public function setIsFirstLabel($isFirstLabel)
249
  {
260
  return $this->_isFirstLabel;
261
  }
262
 
263
+ /**
264
+ * @param boolean $isFirstCodCardLabel
265
+ *
266
+ * @return $this
267
+ */
268
+ public function setIsFirstCodCardLabel($isFirstCodCardLabel)
269
+ {
270
+ $this->_isFirstCodCardLabel = $isFirstCodCardLabel;
271
+
272
+ return $this;
273
+ }
274
+
275
+ /**
276
+ * @return boolean
277
+ */
278
+ public function getIsFirstCodCardLabel()
279
+ {
280
+ return $this->_isFirstCodCardLabel;
281
+ }
282
+
283
  /**
284
  * Get the array of saved temporary labels
285
  *
295
  *
296
  * @param array $tempFilesSaved
297
  *
298
+ * @return $this
299
  */
300
  public function setTempFilesSaved($tempFilesSaved)
301
  {
319
  *
320
  * @param int $counter
321
  *
322
+ * @return $this
323
  */
324
  public function setLabelCounter($counter)
325
  {
339
  return $this->getData('label_size');
340
  }
341
 
342
+ $labelSize = Mage::getStoreConfig(self::XPATH_LABEL_SIZE, Mage_Core_Model_App::ADMIN_STORE_ID);
343
 
344
  $this->setLabelSize($labelSize);
345
  return $labelSize;
346
  }
347
 
348
+ /**
349
+ * @return array
350
+ */
351
+ public function getLabelPositions()
352
+ {
353
+ return $this->_labelPositions;
354
+ }
355
+
356
+ /**
357
+ * Gets position coordinates for a given label type and an optional counter.
358
+ *
359
+ * @param string $type
360
+ * @param boolean|int $counter
361
+ *
362
+ * @return array
363
+ *
364
+ * @throws TIG_PostNL_Exception
365
+ */
366
+ public function _getLabelPosition($type, $counter = false)
367
+ {
368
+ $labelPositions = $this->getLabelPositions();
369
+
370
+ if (!array_key_exists($type, $labelPositions)) {
371
+ throw new TIG_PostNL_Exception(
372
+ Mage::helper('postnl')->__('Invalid label type supplied: %s', $type),
373
+ 'POSTNL-0065'
374
+ );
375
+ }
376
+
377
+ $positions = $labelPositions[$type];
378
+ if (count($positions) === 1) {
379
+ return current($positions);
380
+ }
381
+
382
+ if (!$counter || !array_key_exists($counter, $positions)) {
383
+ return array(
384
+ 'x' => 0,
385
+ 'y' => 0,
386
+ 'w' => 0,
387
+ );
388
+ }
389
+
390
+ return $positions[$counter];
391
+ }
392
+
393
  /**
394
  * Reset the counter to 0
395
  *
396
+ * @return $this
397
  */
398
  public function resetLabelCounter()
399
  {
407
  *
408
  * @param int $increase
409
  *
410
+ * @return $this
411
  */
412
  public function increaseLabelCounter($increase = 1)
413
  {
424
  *
425
  * @param string $tempFile
426
  *
427
+ * @return $this
428
  */
429
  public function addTempFileSaved($tempFile)
430
  {
438
 
439
  /**
440
  * Creates a pdf containing shipping labels using FPDF and FPDI libraries.
441
+ * Four labels will be printed on each page in a vertical position. All labels will be rotated 90 degrees
442
+ * counter-clockwise.
443
  *
444
+ * @param array|TIG_PostNL_Model_Core_Shipment_Label $labels May be an array of labels or a single
445
+ * TIG_PostNL_Model_Core_Shipment_Label label.
446
  *
447
+ * @return $this
448
  *
449
  * @see TIG_PostNL_Fpdf
450
  * @see TIG_PostNL_Fpdi
451
  *
452
+ * @link http://www.fpdf.org/ Fpdf library documentation.
453
+ * @link http://www.setasign.de/products/pdf-php-solutions/fpdi/ Fpdi library documentation.
454
  */
455
  public function createPdf($labels)
456
  {
457
  Varien_Profiler::start('tig::postnl::core::label_createpdf');
458
 
459
  /**
460
+ * Open a new pdf object and assign some basic values.
461
  */
462
  $pdf = new TIG_PostNL_Fpdi(); //lib/TIG/PostNL/Fpdi
463
  $pdf->open();
 
 
 
464
  $pdf->SetTitle('PostNL Shipping Labels');
465
  $pdf->SetAuthor('PostNL');
466
  $pdf->SetCreator('PostNL');
469
  $labels = array($labels);
470
  }
471
  /**
472
+ * Create a pdf containing multiple labels.
473
  */
474
  $pdf = $this->_createMultiLabelPdf($pdf, $labels);
475
 
476
  /**
477
+ * Destroy the temporary labels as they are no longer needed.
478
  */
479
  $this->_destroyTempLabels();
480
 
481
  /**
482
  * Get the final label.
483
  */
484
+ $label = $pdf->Output('PostNL Shipping Labels.pdf', $this->getOutputMode());
485
 
486
  Varien_Profiler::stop('tig::postnl::core::label_createpdf');
487
 
488
  return $label;
489
  }
490
 
491
+ /**
492
+ * Creates a pdf containing both the packing slip and a shipping label. The shipping label must be of the 'Label' or
493
+ * 'Label-combi' type.
494
+ *
495
+ * @param TIG_PostNL_Model_Core_Shipment_Label $label
496
+ * @param string $packingSlip
497
+ *
498
+ * @return string
499
+ *
500
+ * @throws TIG_PostNL_Exception
501
+ */
502
+ public function createPackingSlipLabel($label, $packingSlip)
503
+ {
504
+ Varien_Profiler::start('tig::postnl::core::label_createpackingslippdf');
505
+
506
+ /**
507
+ * Open a new pdf object and assign some basic values.
508
+ */
509
+ $pdf = new TIG_PostNL_Fpdi(); //lib/TIG/PostNL/Fpdi
510
+ $pdf->open();
511
+ $pdf->SetTitle('PostNL Packingslip');
512
+ $pdf->SetAuthor('PostNL');
513
+ $pdf->SetCreator('PostNL');
514
+
515
+ $pdf->addOrientedPage('P', 'A4');
516
+
517
+ $tempPackingslip = $this->_saveTempPackingslip($label, $packingSlip);
518
+ $tempLabel = $this->_saveTempLabel($label);
519
+
520
+ $pdf->insertTemplate($tempPackingslip, 0, 0);
521
+
522
+ if ($label->getLabelType() == 'Label'
523
+ || $label->getLabelType() == 'BusPakje'
524
+ || $label->getLabelType() == 'BusPakjeExtra'
525
+ ) {
526
+ $pdf->Rotate(90);
527
+ $pdf->insertTemplate($tempLabel, $this->pix2pt(-1037), $this->pix2pt(413), $this->pix2pt(538));
528
+ $pdf->Rotate(0);
529
+ } elseif ($label->getLabelType() == 'Label-combi') {
530
+ $pdf->insertTemplate($tempLabel, $this->pix2pt(400), $this->pix2pt(569), $this->pix2pt(400));
531
+ } else {
532
+ throw new TIG_PostNL_Exception(
533
+ Mage::helper('postnl')->__(
534
+ 'Invalid label type supplied for packing slip label pdf: %s.', $label->getLabelType()
535
+ ),
536
+ 'POSTNL-0169'
537
+ );
538
+ }
539
+
540
+ /**
541
+ * Destroy the temporary labels as they are no longer needed.
542
+ */
543
+ $this->_destroyTempLabels();
544
+
545
+ /**
546
+ * Get the final label.
547
+ */
548
+ $label = $pdf->Output('PostNL Shipping Labels.pdf', $this->getOutputMode());
549
+
550
+ Varien_Profiler::stop('tig::postnl::core::label_createpackingslippdf');
551
+
552
+ return $label;
553
+ }
554
+
555
  /**
556
  * Adds multiple labels to the pdf
557
  *
568
  * Check if printing the required number of labels is allowed.
569
  *
570
  * This is limited to 200 by default to prevent out of memory errors.
571
+ * On a clean Magento install with 256 MB of memory, several thousands of labels can be printed at once.
572
+ * However, for safety reasons a limit of 200 is used. By default you shouldn't be able to select more than 200
 
573
  * in the shipment grid.
574
  */
575
+ if(count($labels) > self::MAX_LABEL_COUNT && !Mage::helper('postnl/cif')->allowInfinitePrinting()) {
576
  throw new TIG_PostNL_Exception(
577
  Mage::helper('postnl')->__(
578
  'Maximum amount of labels exceeded. Maximum allowed: 200. Requested: %s',
583
  }
584
 
585
  $this->setIsFirstLabel(true);
586
+ $this->setIsFirstCodCardLabel(true);
587
+ $labels = $this->sortLabels($labels);
588
  foreach ($labels as $label) {
589
  $pdf = $this->_addPdfTemplate($pdf, $label);
590
  }
593
  }
594
 
595
  /**
596
+ * Adds a label to the pdf by storing it in a temporary pdf file and then adding it to the master pdf object. Each
597
+ * label type has it's own properties and size. For some we need to add another A4-size page first, for others we
598
+ * need to rotate the pdf. This method calculates this before actually adding the pdf template.
599
  *
600
  * @param TIG_PostNL_Fpdi $pdf
601
  * @param TIG_PostNL_Model_Core_Shipment_Label $label
608
  {
609
  /**
610
  * Fpdi requires labels to be provided as files. Therefore the label will be saved as a temporary file in
611
+ * var/TIG/PostNL/temp_label/
612
  */
613
+ $tempFilename = $this->_saveTempLabel($label);
614
 
615
  $rotate = false;
616
 
618
  * First we need to add pages to the pdf for certain label types under certain conditions.
619
  */
620
  $labelType = $label->getLabelType();
621
+ if ($labelType == 'Label'
622
+ || $labelType == 'Label-combi'
623
+ || $labelType == 'BusPakje'
624
+ || $labelType == 'BusPakjeExtra'
625
+ ) {
626
+ if ($this->getLabelSize() == 'A4' && $this->getIsFirstLabel()) {
627
+ $pdf->addOrientedPage('L', 'A4');
628
+ $this->setIsFirstLabel(false);
629
+ if (!$this->getLabelCounter()) {
630
+ $this->resetLabelCounter();
631
+ }
632
+ } elseif ($this->getLabelSize() == 'A4'
633
+ && (
634
+ !$this->getLabelCounter() || $this->getLabelCounter() > 4
635
+ )
636
  ) {
637
  $pdf->addOrientedPage('L', 'A4');
638
  $this->resetLabelCounter();
 
 
 
639
  }
640
 
641
  /**
642
+ * If the configured label size is A6, add a new page every label.
643
  */
644
  if($this->getLabelSize() == 'A6') {
645
  $this->setLabelCounter(3); //used to calculate the top left position
646
  $pdf->addOrientedPage('L', 'A6');
647
  }
648
+ } elseif ($labelType == 'CODcard') {
649
+ $pdf->addOrientedPage('P', array(156.65, 73.85));
650
+ } elseif ($labelType == 'CN23'
651
  || $labelType == 'CommercialInvoice'
652
  || $labelType == 'CODcard'
653
  ) {
654
  $pdf->addOrientedPage('P', 'A4');
655
  }
656
 
657
+ /**
658
+ * Calculate the position of each label type and whether or not it should be rotated by a certain number of
659
+ * degrees.
660
+ */
661
  switch ($labelType) {
662
  case 'Label-combi':
663
  /**
665
  */
666
  $pdf->Rotate('-90');
667
 
668
+ $position = $this->_getLabelPosition($labelType, $this->getLabelCounter());
 
 
 
 
669
 
670
  $this->increaseLabelCounter();
671
 
672
  $rotate = true;
673
  break;
674
  case 'Label':
675
+ case 'BusPakje':
676
+ case 'BusPakjeExtra':
677
+ $position = $this->_getLabelPosition($labelType, $this->getLabelCounter());
 
 
678
 
679
  $this->increaseLabelCounter();
680
  break;
681
  case 'CN23':
682
  case 'CommercialInvoice':
683
+ $position = $this->_getLabelPosition($labelType);
 
 
 
 
 
 
 
684
 
685
  /**
686
+ * increase the label counter to above 4. This will prompt the creation of a new page.
687
  */
688
  $this->setLabelCounter(5);
689
  break;
690
  case 'CP71':
691
+ $position = $this->_getLabelPosition($labelType);
 
 
 
 
 
 
 
692
 
693
  /**
694
+ * increase the label counter to above 4. This will prompt the creation of a new page.
695
  */
696
  $this->setLabelCounter(5);
697
  break;
698
  case 'CODcard':
699
+ $pdf->Rotate('-90');
 
 
 
 
 
 
 
700
 
701
+ $position = $this->_getLabelPosition($labelType);
702
+
703
+ $this->increaseLabelCounter();
704
+
705
+ $rotate = true;
706
  break;
707
  default:
708
  throw new TIG_PostNL_Exception(
712
  }
713
 
714
  /**
715
+ * Add the next label to the pdf.
716
  */
717
  $pdf->insertTemplate($tempFilename, $position['x'], $position['y'], $position['w']);
718
 
729
  /**
730
  * Save a label to a temporary pdf file. Temporary pdf files are stored in var/TIG/PostNL/temp_label/
731
  *
732
+ * @param TIG_PostNL_Model_Core_Shipment_Label $label
733
  *
734
  * @throws TIG_PostNL_Exception
735
  *
736
  * @return string
737
  */
738
+ protected function _saveTempLabel(TIG_PostNL_Model_Core_Shipment_Label $label)
739
  {
740
  /**
741
+ * construct the path to the temporary file.
742
  */
743
  $tempFilePath = Mage::getConfig()->getVarDir('TIG' . DS . 'PostNL' . DS . 'temp_label')
744
  . DS
745
+ . md5($label->getLabel() . $label->getId())
746
  . '-'
747
  . time()
748
  . '-'
756
  }
757
 
758
  /**
759
+ * Add the base64 decoded label to the file.
760
+ */
761
+ file_put_contents($tempFilePath, base64_decode($label->getLabel()));
762
+
763
+ /**
764
+ * Save the name of the temp file so it can be destroyed later.
765
+ */
766
+ $this->addTempFileSaved($tempFilePath);
767
+
768
+ return $tempFilePath;
769
+ }
770
+
771
+ /**
772
+ * Save a packing slip to a temporary pdf file. Temporary pdf files are stored in var/TIG/PostNL/temp_label/
773
+ *
774
+ * @param TIG_PostNL_Model_Core_Shipment_Label $label
775
+ * @param string $packingSlip
776
+ *
777
+ * @return string
778
+ *
779
+ * @throws TIG_PostNL_Exception
780
+ */
781
+ protected function _saveTempPackingslip(TIG_PostNL_Model_Core_Shipment_Label $label, $packingSlip)
782
+ {
783
+ /**
784
+ * construct the path to the temporary file.
785
+ */
786
+ $tempFilePath = Mage::getConfig()->getVarDir('TIG' . DS . 'PostNL' . DS . 'temp_label')
787
+ . DS
788
+ . md5($label->getLabel() . $packingSlip)
789
+ . '-'
790
+ . time()
791
+ . '-'
792
+ . self::TEMP_PACKINGSLIP_FILENAME;
793
+
794
+ if (file_exists($tempFilePath)) {
795
+ throw new TIG_PostNL_Exception(
796
+ Mage::helper('postnl')->__('Temporary template file already exists: %s', $tempFilePath),
797
+ 'POSTNL-0066'
798
+ );
799
+ }
800
+
801
+ /**
802
+ * Add the packing slip to the file.
803
  */
804
+ file_put_contents($tempFilePath, $packingSlip);
805
 
806
  /**
807
+ * Save the name of the temp file so it can be destroyed later.
808
  */
809
  $this->addTempFileSaved($tempFilePath);
810
 
814
  /**
815
  * Destroy all temporary pdf files
816
  *
817
+ * @return $this
818
  */
819
  protected function _destroyTempLabels()
820
  {
821
  $tempFilesSaved = $this->getTempFilesSaved();
822
  foreach ($tempFilesSaved as $tempFile) {
823
+ if (file_exists($tempFile)) {
824
+ unlink($tempFile);
825
+ }
826
  }
827
 
828
  return $this;
829
  }
830
 
831
  /**
832
+ * Sorts labels by label type. First all labels of the 'Label', 'Label-combi', 'BusPakje' and 'BusPakjeExtra' type.
833
+ * Then all other labels in the order of 'CODcard' > 'CN23' > 'CP71' > 'CommercialInvoice' grouped by shipments.
834
  *
835
  * @param array $labels
836
  *
837
  * @return array
 
 
838
  */
839
+ public function sortLabels($labels)
840
  {
841
  $generalLabels = array();
842
  $globalLabels = array();
847
  */
848
  foreach ($labels as $label) {
849
  /**
850
+ * Separate general labels from the rest.
851
  */
852
+ if ($label->getLabelType() == 'Label'
853
+ || $label->getLabelType() == 'Label-combi'
854
+ || $label->getLabelType() == 'BusPakje'
855
+ || $label->getLabelType() == 'BusPakjeExtra'
856
+ ) {
857
  $generalLabels[] = $label;
858
  continue;
859
  }
860
 
861
  /**
862
+ * Separate COD cards.
863
  */
864
  if ($label->getLabelType() == 'CODcard') {
865
  $codCards[] = $label;
867
  }
868
 
869
  /**
870
+ * Group other labels by shipment id (parent_id attribute).
871
  */
872
  if (isset($globalLabels[$label->getParentId()])) {
873
  $globalLabels[$label->getParentId()][$label->getLabelType()] = $label;
877
  }
878
 
879
  /**
880
+ * Sort all GlobalPack labels.
881
  */
882
  $sortedGlobalLabels = array();
883
  foreach ($globalLabels as $shipmentLabels) {
895
  }
896
 
897
  /**
898
+ * Merge all labels back into a single array.
899
  */
900
  $labels = array_merge($generalLabels, $sortedGlobalLabels, $codCards);
901
  return $labels;
902
  }
903
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
904
  /**
905
  * Converts pixels to points. 3.8 pixels is 1 pt in pdfs.
906
  *
911
  public function pix2pt($pixels = 0)
912
  {
913
  if($pixels != 0) {
914
+ $points = round($pixels / 3.8, 1);
915
  return $points;
916
  }
917
 
app/code/community/TIG/PostNL/Model/Core/Observer/Barcode.php CHANGED
@@ -43,7 +43,7 @@ class TIG_PostNL_Model_Core_Observer_Barcode
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
  *
@@ -66,14 +66,13 @@ class TIG_PostNL_Model_Core_Observer_Barcode
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
 
@@ -121,13 +120,16 @@ class TIG_PostNL_Model_Core_Observer_Barcode
121
  $postnlShipment->save();
122
 
123
  /**
124
- * Barcode generation needs to be tried separately. 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 overburdened.
127
  */
128
  try {
129
- $postnlShipment->saveAdditionalShippingOptions()
130
- ->generateBarcodes();
 
 
 
131
  } catch (Exception $e) {
132
  Mage::helper('postnl')->logException($e);
133
  }
43
  *
44
  * @param Varien_Event_Observer $observer
45
  *
46
+ * @return $this
47
  *
48
  * @event sales_order_shipment_save_after
49
  *
66
  /**
67
  * Check if this shipment was placed using PostNL.
68
  */
 
69
  $shippingMethod = $shipment->getOrder()->getShippingMethod();
70
 
71
  /**
72
  * If this shipment's order was not placed with PostNL, remove any PakjeGemak addresses that may have been
73
  * saved.
74
  */
75
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
76
  return $this;
77
  }
78
 
120
  $postnlShipment->save();
121
 
122
  /**
123
+ * Barcode generation needs to be tried separately. This functionality may throw a valid exceptionin which case
124
+ * it needs to be tried again later without preventing the shipment from being created. This may happen when CIF
125
+ * is overburdened.
126
  */
127
  try {
128
+ $postnlShipment->saveAdditionalShippingOptions();
129
+
130
+ if ($postnlShipment->canGenerateBarcode()) {
131
+ $postnlShipment->generateBarcodes();
132
+ }
133
  } catch (Exception $e) {
134
  Mage::helper('postnl')->logException($e);
135
  }
app/code/community/TIG/PostNL/Model/Core/Observer/Cache.php CHANGED
@@ -38,6 +38,15 @@
38
  */
39
  class TIG_PostNL_Model_Core_Observer_Cache
40
  {
 
 
 
 
 
 
 
 
 
41
  public function cleanCache()
42
  {
43
  $cache = Mage::getSingleton('postnl_core/cache');
38
  */
39
  class TIG_PostNL_Model_Core_Observer_Cache
40
  {
41
+ /**
42
+ * Cleans the PostNL config cache after PostNL's configuration has been saved.
43
+ *
44
+ * @return $this
45
+ *
46
+ * @event admin_system_config_changed_section_postnl|admin_system_config_changed_section_carrier
47
+ *
48
+ * @observer postnl_clean_cache
49
+ */
50
  public function cleanCache()
51
  {
52
  $cache = Mage::getSingleton('postnl_core/cache');
app/code/community/TIG/PostNL/Model/Core/Observer/Cron.php CHANGED
@@ -41,28 +41,27 @@ class TIG_PostNL_Model_Core_Observer_Cron
41
  /**
42
  * Xml path to maximum file storage setting in system/config
43
  */
44
- const XML_PATH_MAX_FILE_STORAGE = 'postnl/advanced/max_temp_file_storage_time';
45
 
46
  /**
47
  * XML path to confirmation expire time setting
48
  */
49
- const XML_PATH_CONFIRM_EXPIRE_DAYS = 'postnl/advanced/confirm_expire_days';
50
 
51
  /**
52
  * XML path to setting that determines whether or not to send track and trace emails
53
  */
54
- const XML_PATH_SEND_TRACK_AND_TRACE_EMAIL = 'postnl/cif_labels_and_confirming/send_track_and_trace_email';
55
 
56
  /**
57
  * Method to destroy temporary label files that have been stored for too long.
58
  *
59
- * By default the PostNL module creates temporary label files in order to merge them into
60
- * a single shipping label. These files are then destroyed. However, sometimes these files
61
- * may survive the script if the script has encountered an error. This method will make
62
- * sure these files will not survive indefinitely, which may lead to the file system
63
- * being overburdened or the server running out of harddrive space.
64
  *
65
- * @return TIG_PostNL_Model_Core_Observer_Cron
66
  *
67
  * @throws TIG_PostNL_Exception
68
  */
@@ -93,7 +92,10 @@ class TIG_PostNL_Model_Core_Observer_Cron
93
  * Check the maximum amount of time a temp file may be stored. By default this is 300s (5m).
94
  * If this settings is empty, end the script.
95
  */
96
- $maxFileStorageTime = (int) Mage::getStoreConfig(self::XML_PATH_MAX_FILE_STORAGE, Mage_Core_Model_App::ADMIN_STORE_ID);
 
 
 
97
  if (empty($maxFileStorageTime)) {
98
  $helper->cronLog('No max file storage time defined. Exiting cron.');
99
  return $this;
@@ -108,6 +110,8 @@ class TIG_PostNL_Model_Core_Observer_Cron
108
  $labelModel = Mage::app()->getConfig()->getModelClassName('postnl_core/label');
109
  $tempLabelName = $labelModel::TEMP_LABEL_FILENAME;
110
 
 
 
111
  /**
112
  * Get all temporary label files in the directory
113
  */
@@ -147,7 +151,9 @@ class TIG_PostNL_Model_Core_Observer_Cron
147
  */
148
  $time = $nameParts[1];
149
  if ((time() - $time) < $maxFileStorageTime) {
150
- $helper->cronLog("File {$filename} is less than {$maxFileStorageTime}s old. Continuing with the next file.");
 
 
151
  continue;
152
  }
153
 
@@ -165,7 +171,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
165
  /**
166
  * Method to destroy old lock files.
167
  *
168
- * @return TIG_PostNL_Model_Core_Observer_Cron
169
  *
170
  * @throws TIG_PostNL_Exception
171
  */
@@ -191,6 +197,8 @@ class TIG_PostNL_Model_Core_Observer_Cron
191
  return $this;
192
  }
193
 
 
 
194
  /**
195
  * Get all PostNL lock files in the directory
196
  */
@@ -254,7 +262,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
254
  /**
255
  * Retrieve barcodes for postnl shipments that do not have one.
256
  *
257
- * @return TIG_PostNL_Model_Core_Observer_Cron
258
  */
259
  public function getBarcodes()
260
  {
@@ -273,7 +281,8 @@ class TIG_PostNL_Model_Core_Observer_Cron
273
  * Get all postnl shipments without a barcode
274
  */
275
  $postnlShipmentCollection = Mage::getResourceModel('postnl_core/shipment_collection');
276
- $postnlShipmentCollection->addFieldToFilter('main_barcode', array('null' => true));
 
277
 
278
  if ($postnlShipmentCollection->getSize() < 1) {
279
  $helper->cronLog('No valid shipments found. Exiting cron.');
@@ -284,14 +293,22 @@ class TIG_PostNL_Model_Core_Observer_Cron
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
 
 
 
 
 
295
  /**
296
  * Attempt to generate a barcode. Continue with the next one if it fails.
297
  */
@@ -314,7 +331,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
314
  /**
315
  * Update shipping status for all confirmed, but undelivered shipments.
316
  *
317
- * @return TIG_PostNL_Model_Core_Observer_Cron
318
  */
319
  public function updateShippingStatus()
320
  {
@@ -354,6 +371,12 @@ class TIG_PostNL_Model_Core_Observer_Cron
354
  array('neq' => $deliveredStatus),
355
  array('null' => true)
356
  )
 
 
 
 
 
 
357
  );
358
 
359
  if ($postnlShipmentCollection->getSize() < 1) {
@@ -371,7 +394,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
371
  * Attempt to update the shipping status. Continue with the next one if it fails.
372
  */
373
  try{
374
- if (!$postnlShipment->getShipment()) {
375
  continue;
376
  }
377
 
@@ -379,7 +402,8 @@ class TIG_PostNL_Model_Core_Observer_Cron
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
  }
385
 
@@ -407,7 +431,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
407
  * @param TIG_PostNL_Model_Core_Cif_Exception $e
408
  * @param TIG_PostNL_Model_Core_Shipment $postnlShipment
409
  *
410
- * @return TIG_PostNL_Model_Core_Observer_Cron
411
  */
412
  protected function _parseErrorCodes($e, $postnlShipment)
413
  {
@@ -440,8 +464,12 @@ class TIG_PostNL_Model_Core_Observer_Cron
440
  * Check if the shipment was confirmed more than a day ago
441
  */
442
  $confirmedAt = strtotime($postnlShipment->getConfirmedAt());
 
 
 
 
443
  $now = Mage::getModel('core/date')->gmtTimestamp();
444
- $yesterday = strtotime('-1 day', $now);
445
 
446
  if ($confirmedAt > $yesterday) {
447
  return $this;
@@ -466,7 +494,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
466
  /**
467
  * Removes expired confirmations by resetting the postnl shipment to a pre-confirm state
468
  *
469
- * @return TIG_PostNL_Model_Core_Observer_Cron
470
  */
471
  public function expireConfirmation()
472
  {
@@ -488,15 +516,22 @@ class TIG_PostNL_Model_Core_Observer_Cron
488
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
489
  $collectionPhase = $postnlShipmentModelClass::SHIPPING_PHASE_COLLECTION;
490
 
491
- $confirmationExpireDays = Mage::getStoreConfig(self::XML_PATH_CONFIRM_EXPIRE_DAYS, Mage_Core_Model_App::ADMIN_STORE_ID);
492
- $expireTimestamp = strtotime("-{$confirmationExpireDays} days", Mage::getModel('core/date')->gmtTimestamp());
493
- $expireDate = date('Y-m-d H:i:s', $expireTimestamp);
 
 
 
 
 
 
 
494
 
495
  $helper->cronLog("All confirmation placed before {$expireDate} will be expired.");
496
 
497
  /**
498
- * Get all postnl shipments that have been confirmed over X days ago and who have not yet been shipped (shipping_phase
499
- * other than 'collection')
500
  */
501
  $postnlShipmentCollection = Mage::getResourceModel('postnl_core/shipment_collection');
502
  $postnlShipmentCollection->addFieldToFilter(
@@ -516,6 +551,12 @@ class TIG_PostNL_Model_Core_Observer_Cron
516
  array('lt' => $expireDate),
517
  array('null' => true)
518
  )
 
 
 
 
 
 
519
  );
520
 
521
  /**
@@ -536,11 +577,21 @@ class TIG_PostNL_Model_Core_Observer_Cron
536
  * Attempt to reset the shipment to a pre-confirmed status
537
  */
538
  try{
 
 
 
 
539
  $helper->cronLog("Expiring confirmation of shipment #{$postnlShipment->getId()}");
540
  $postnlShipment->resetConfirmation()
541
- ->setConfirmStatus($postnlShipment::CONFIRM_STATUS_CONFIRM_EXPIRED)
542
- ->generateBarcodes() //generate new barcodes as the current ones have expired
543
- ->save();
 
 
 
 
 
 
544
  } catch (Exception $e) {
545
  $helper->logException($e);
546
  }
@@ -551,16 +602,16 @@ class TIG_PostNL_Model_Core_Observer_Cron
551
  }
552
 
553
  /**
554
- * Send a track & trace e-mail to the customer
555
  *
556
- * @return TIG_PostNL_Model_Core_Observer_Cron
557
  */
558
  public function sendTrackAndTraceEmail()
559
  {
560
  $helper = Mage::helper('postnl');
561
 
562
  /**
563
- * Check if the PostNL module is active
564
  */
565
  if (!$helper->isEnabled()) {
566
  return $this;
@@ -569,11 +620,11 @@ class TIG_PostNL_Model_Core_Observer_Cron
569
  $helper->cronLog('SendTrackAndTraceEmail cron starting...');
570
 
571
  /**
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
  }
579
  }
@@ -589,13 +640,18 @@ class TIG_PostNL_Model_Core_Observer_Cron
589
  $postnlShipmentModelClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
590
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
591
 
592
- $twentyMinutesAgo = strtotime("-20 minutes", Mage::getModel('core/date')->gmtTimestamp());
593
- $twentyMinutesAgo = date('Y-m-d H:i:s', $twentyMinutesAgo);
 
 
 
594
 
595
- $helper->cronLog("Track and trace email will be sent for all shipments that were confirmed on or before {$twentyMinutesAgo}.");
 
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` . *
@@ -619,6 +675,9 @@ class TIG_PostNL_Model_Core_Observer_Cron
619
  * )
620
  * )
621
  * )
 
 
 
622
  */
623
  $postnlShipmentCollection = Mage::getResourceModel('postnl_core/shipment_collection');
624
  $postnlShipmentCollection->addFieldToFilter(
@@ -639,6 +698,12 @@ class TIG_PostNL_Model_Core_Observer_Cron
639
  array('null' => true),
640
  array('eq' => '0')
641
  )
 
 
 
 
 
 
642
  );
643
 
644
  /**
@@ -655,12 +720,18 @@ class TIG_PostNL_Model_Core_Observer_Cron
655
  * Send the track and trace email for all shipments
656
  */
657
  foreach ($postnlShipmentCollection as $postnlShipment) {
 
 
 
 
658
  /**
659
  * Check if sending the email is allowed for this shipment
660
  */
661
  $storeId = $postnlShipment->getStoreId();
662
  if (!in_array($storeId, $allowedStoreIds) || !$postnlShipment->canSendTrackAndTraceEmail()) {
663
- $helper->cronLog("Sending the track and trace email is not allowed for shipment #{$postnlShipment->getId()}.");
 
 
664
  continue;
665
  }
666
 
@@ -682,9 +753,10 @@ class TIG_PostNL_Model_Core_Observer_Cron
682
  }
683
 
684
  /**
685
- * Deletes labels belonging to shipments that have been delievered as well as labels who have no associated shipments.
 
686
  *
687
- * @return TIG_PostNL_Model_Core_Observer_Cron
688
  */
689
  public function removeOldLabels()
690
  {
@@ -700,7 +772,7 @@ class TIG_PostNL_Model_Core_Observer_Cron
700
  $helper->cronLog('RemoveOldLabels cron starting...');
701
 
702
  /**
703
- * Get the PostNL Shipment classname for later use
704
  *
705
  * @var $postnlShipmentClass TIG_PostNL_Model_Core_Shipment
706
  */
@@ -737,7 +809,8 @@ class TIG_PostNL_Model_Core_Observer_Cron
737
  * Resulting query:
738
  * SELECT `main_table`.`label_id` , `postnl_shipment`.`shipping_phase`
739
  * FROM `tig_postnl_shipment_label` AS `main_table`
740
- * LEFT JOIN `tig_postnl_shipment` AS `postnl_shipment` ON `main_table`.`parent_id` = `postnl_shipment`.`entity_id`
 
741
  * WHERE (
742
  * (
743
  * parent_id IS NULL
41
  /**
42
  * Xml path to maximum file storage setting in system/config
43
  */
44
+ const XPATH_MAX_FILE_STORAGE = 'postnl/advanced/max_temp_file_storage_time';
45
 
46
  /**
47
  * XML path to confirmation expire time setting
48
  */
49
+ const XPATH_CONFIRM_EXPIRE_DAYS = 'postnl/advanced/confirm_expire_days';
50
 
51
  /**
52
  * XML path to setting that determines whether or not to send track and trace emails
53
  */
54
+ const XPATH_SEND_TRACK_AND_TRACE_EMAIL = 'postnl/cif_labels_and_confirming/send_track_and_trace_email';
55
 
56
  /**
57
  * Method to destroy temporary label files that have been stored for too long.
58
  *
59
+ * By default the PostNL module creates temporary label files in order to merge them into a single shipping label.
60
+ * These files are then destroyed. However, sometimes these files may survive the script if the script has
61
+ * encountered an error. This method will make sure these files will not survive indefinitely, which may lead to the
62
+ * file system being overburdened or the server running out of hard drive space.
 
63
  *
64
+ * @return $this
65
  *
66
  * @throws TIG_PostNL_Exception
67
  */
92
  * Check the maximum amount of time a temp file may be stored. By default this is 300s (5m).
93
  * If this settings is empty, end the script.
94
  */
95
+ $maxFileStorageTime = (int) Mage::getStoreConfig(
96
+ self::XPATH_MAX_FILE_STORAGE,
97
+ Mage_Core_Model_App::ADMIN_STORE_ID
98
+ );
99
  if (empty($maxFileStorageTime)) {
100
  $helper->cronLog('No max file storage time defined. Exiting cron.');
101
  return $this;
110
  $labelModel = Mage::app()->getConfig()->getModelClassName('postnl_core/label');
111
  $tempLabelName = $labelModel::TEMP_LABEL_FILENAME;
112
 
113
+ $helper->cronLog('Attempting to read temp label files from %s.', $tempLabelsDirectory);
114
+
115
  /**
116
  * Get all temporary label files in the directory
117
  */
151
  */
152
  $time = $nameParts[1];
153
  if ((time() - $time) < $maxFileStorageTime) {
154
+ $helper->cronLog(
155
+ "File {$filename} is less than {$maxFileStorageTime}s old. Continuing with the next file."
156
+ );
157
  continue;
158
  }
159
 
171
  /**
172
  * Method to destroy old lock files.
173
  *
174
+ * @return $this
175
  *
176
  * @throws TIG_PostNL_Exception
177
  */
197
  return $this;
198
  }
199
 
200
+ $helper->cronLog('Attempting to read lock files from %s.', $locksDirectory);
201
+
202
  /**
203
  * Get all PostNL lock files in the directory
204
  */
262
  /**
263
  * Retrieve barcodes for postnl shipments that do not have one.
264
  *
265
+ * @return $this
266
  */
267
  public function getBarcodes()
268
  {
281
  * Get all postnl shipments without a barcode
282
  */
283
  $postnlShipmentCollection = Mage::getResourceModel('postnl_core/shipment_collection');
284
+ $postnlShipmentCollection->addFieldToFilter('main_barcode', array('null' => true))
285
+ ->addFieldToFilter('shipment_id', array('notnull' => true));
286
 
287
  if ($postnlShipmentCollection->getSize() < 1) {
288
  $helper->cronLog('No valid shipments found. Exiting cron.');
293
 
294
  $counter = 1000;
295
  foreach ($postnlShipmentCollection as $postnlShipment) {
296
+ if (!$postnlShipment->getShipment(false)) {
297
+ continue;
298
+ }
299
+
300
  /**
301
+ * Process a maximum of 1000 shipments (to prevent Cif from being overburdened).
302
+ * Only successful requests count towards this number
303
  */
304
  if ($counter < 1) {
305
  break;
306
  }
307
 
308
+ if (!$postnlShipment->canGenerateBarcode()) {
309
+ continue;
310
+ }
311
+
312
  /**
313
  * Attempt to generate a barcode. Continue with the next one if it fails.
314
  */
331
  /**
332
  * Update shipping status for all confirmed, but undelivered shipments.
333
  *
334
+ * @return $this
335
  */
336
  public function updateShippingStatus()
337
  {
371
  array('neq' => $deliveredStatus),
372
  array('null' => true)
373
  )
374
+ )
375
+ ->addFieldToFilter(
376
+ 'shipment_id',
377
+ array(
378
+ 'notnull' => true
379
+ )
380
  );
381
 
382
  if ($postnlShipmentCollection->getSize() < 1) {
394
  * Attempt to update the shipping status. Continue with the next one if it fails.
395
  */
396
  try{
397
+ if (!$postnlShipment->getShipment(false)) {
398
  continue;
399
  }
400
 
402
 
403
  if (!$postnlShipment->canUpdateShippingStatus()) {
404
  $postnlShipment->unlock();
405
+ $helper->cronLog("Updating shipment #{$postnlShipment->getShipment()->getId()} is not allowed. " .
406
+ "Continuing with next shipment.");
407
  continue;
408
  }
409
 
431
  * @param TIG_PostNL_Model_Core_Cif_Exception $e
432
  * @param TIG_PostNL_Model_Core_Shipment $postnlShipment
433
  *
434
+ * @return $this
435
  */
436
  protected function _parseErrorCodes($e, $postnlShipment)
437
  {
464
  * Check if the shipment was confirmed more than a day ago
465
  */
466
  $confirmedAt = strtotime($postnlShipment->getConfirmedAt());
467
+ $yesterday = new DateTime();
468
+ $yesterday->setTimestamp(Mage::getModel('core/date')->gmtTimestamp())
469
+ ->sub(new DateInterval('P1D'));
470
+
471
  $now = Mage::getModel('core/date')->gmtTimestamp();
472
+ $yesterday = $yesterday->getTimestamp();
473
 
474
  if ($confirmedAt > $yesterday) {
475
  return $this;
494
  /**
495
  * Removes expired confirmations by resetting the postnl shipment to a pre-confirm state
496
  *
497
+ * @return $this
498
  */
499
  public function expireConfirmation()
500
  {
516
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
517
  $collectionPhase = $postnlShipmentModelClass::SHIPPING_PHASE_COLLECTION;
518
 
519
+ $confirmationExpireDays = Mage::getStoreConfig(
520
+ self::XPATH_CONFIRM_EXPIRE_DAYS,
521
+ Mage_Core_Model_App::ADMIN_STORE_ID
522
+ );
523
+
524
+ $expireTimestamp = new DateTime();
525
+ $expireTimestamp->setTimestamp(Mage::getModel('core/date')->gmtTimestamp())
526
+ ->sub(new DateInterval("P{$confirmationExpireDays}D"));
527
+
528
+ $expireDate = $expireTimestamp->format('Y-m-d H:i:s');
529
 
530
  $helper->cronLog("All confirmation placed before {$expireDate} will be expired.");
531
 
532
  /**
533
+ * Get all postnl shipments that have been confirmed over X days ago and who have not yet been shipped
534
+ * (shipping_phase other than 'collection')
535
  */
536
  $postnlShipmentCollection = Mage::getResourceModel('postnl_core/shipment_collection');
537
  $postnlShipmentCollection->addFieldToFilter(
551
  array('lt' => $expireDate),
552
  array('null' => true)
553
  )
554
+ )
555
+ ->addFieldToFilter(
556
+ 'shipment_id',
557
+ array(
558
+ 'notnull' => true
559
+ )
560
  );
561
 
562
  /**
577
  * Attempt to reset the shipment to a pre-confirmed status
578
  */
579
  try{
580
+ if (!$postnlShipment->getShipment(false)) {
581
+ continue;
582
+ }
583
+
584
  $helper->cronLog("Expiring confirmation of shipment #{$postnlShipment->getId()}");
585
  $postnlShipment->resetConfirmation()
586
+ ->setConfirmStatus($postnlShipment::CONFIRM_STATUS_CONFIRM_EXPIRED);
587
+
588
+ /**
589
+ * Generate new barcodes as the current ones have expired.
590
+ */
591
+ if ($postnlShipment->canGenerateBarcode()) {
592
+ $postnlShipment->generateBarcodes();
593
+ }
594
+ $postnlShipment->save();
595
  } catch (Exception $e) {
596
  $helper->logException($e);
597
  }
602
  }
603
 
604
  /**
605
+ * Send a track & trace e-mail to the customer.
606
  *
607
+ * @return $this
608
  */
609
  public function sendTrackAndTraceEmail()
610
  {
611
  $helper = Mage::helper('postnl');
612
 
613
  /**
614
+ * Check if the PostNL module is active.
615
  */
616
  if (!$helper->isEnabled()) {
617
  return $this;
620
  $helper->cronLog('SendTrackAndTraceEmail cron starting...');
621
 
622
  /**
623
+ * Check each storeview if sending track & trace emails is allowed.
624
  */
625
  $allowedStoreIds = array();
626
  foreach (array_keys(Mage::app()->getStores()) as $storeId) {
627
+ if (Mage::getStoreConfig(self::XPATH_SEND_TRACK_AND_TRACE_EMAIL, $storeId)) {
628
  $allowedStoreIds[] = $storeId;
629
  }
630
  }
640
  $postnlShipmentModelClass = Mage::getConfig()->getModelClassName('postnl_core/shipment');
641
  $confirmedStatus = $postnlShipmentModelClass::CONFIRM_STATUS_CONFIRMED;
642
 
643
+ $twentyMinutesAgo = new DateTime();
644
+ $twentyMinutesAgo->setTimestamp(Mage::getModel('core/date')->gmtTimestamp())
645
+ ->sub(new DateInterval('PT20M'));
646
+
647
+ $twentyMinutesAgo = $twentyMinutesAgo->format('Y-m-d H:i:s');
648
 
649
+ $helper->cronLog("Track and trace email will be sent for all shipments that were confirmed on or before " .
650
+ "{$twentyMinutesAgo}.");
651
 
652
  /**
653
+ * Get all postnl shipments that have been confirmed over 20 minutes ago whose track & trace e-mail has not yet
654
+ * been sent
655
  *
656
  * Resulting SQL:
657
  * SELECT `main_table` . *
675
  * )
676
  * )
677
  * )
678
+ * AND (
679
+ * shipment_id IS NOT NULL
680
+ * )
681
  */
682
  $postnlShipmentCollection = Mage::getResourceModel('postnl_core/shipment_collection');
683
  $postnlShipmentCollection->addFieldToFilter(
698
  array('null' => true),
699
  array('eq' => '0')
700
  )
701
+ )
702
+ ->addFieldToFilter(
703
+ 'shipment_id',
704
+ array(
705
+ 'notnull' => true
706
+ )
707
  );
708
 
709
  /**
720
  * Send the track and trace email for all shipments
721
  */
722
  foreach ($postnlShipmentCollection as $postnlShipment) {
723
+ if (!$postnlShipment->getShipment(false)) {
724
+ continue;
725
+ }
726
+
727
  /**
728
  * Check if sending the email is allowed for this shipment
729
  */
730
  $storeId = $postnlShipment->getStoreId();
731
  if (!in_array($storeId, $allowedStoreIds) || !$postnlShipment->canSendTrackAndTraceEmail()) {
732
+ $helper->cronLog(
733
+ "Sending the track and trace email is not allowed for shipment #{$postnlShipment->getId()}."
734
+ );
735
  continue;
736
  }
737
 
753
  }
754
 
755
  /**
756
+ * Deletes labels belonging to shipments that have been delivered as well as labels who have no associated
757
+ * shipments.
758
  *
759
+ * @return $this
760
  */
761
  public function removeOldLabels()
762
  {
772
  $helper->cronLog('RemoveOldLabels cron starting...');
773
 
774
  /**
775
+ * Get the PostNL Shipment class name for later use
776
  *
777
  * @var $postnlShipmentClass TIG_PostNL_Model_Core_Shipment
778
  */
809
  * Resulting query:
810
  * SELECT `main_table`.`label_id` , `postnl_shipment`.`shipping_phase`
811
  * FROM `tig_postnl_shipment_label` AS `main_table`
812
+ * LEFT JOIN `tig_postnl_shipment` AS `postnl_shipment`
813
+ * ON `main_table`.`parent_id` = `postnl_shipment`.`entity_id`
814
  * WHERE (
815
  * (
816
  * parent_id IS NULL
app/code/community/TIG/PostNL/Model/Core/Observer/SaveShipment.php CHANGED
@@ -59,20 +59,35 @@ class TIG_PostNL_Model_Core_Observer_SaveShipment
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;
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
+ $shippingOptions = $controller->getRequest()->getParam('postnl');
68
 
69
+ if (isset($shippingOptions['is_buspakje']) && $shippingOptions['is_buspakje'] == '1') {
70
+ /**
71
+ * Add the full data array to the registry. The PostNL shipment model will parse this and extract the
72
+ * buspakje option if it's valid.
73
+ */
74
+ Mage::register('postnl_product_option', $shippingOptions);
75
+
76
+ unset($shippingOptions['buspakje_options'], $shippingOptions['product_option']);
77
+ } elseif (isset($shippingOptions['product_option'])) {
78
+ /**
79
+ * Add the chosen shipping option. The PosTNL shipment model will check if it's valid.
80
+ */
81
+ Mage::register('postnl_product_option', $shippingOptions['product_option']);
82
+
83
+ unset($shippingOptions['buspakje_options'], $shippingOptions['product_option']);
84
  }
85
 
86
+ /**
87
+ * Add the remaining data as additional options.
88
+ */
89
+ if ($shippingOptions && !empty($shippingOptions)) {
90
+ Mage::register('postnl_additional_options', $shippingOptions);
91
  }
92
 
93
  return $this;
app/code/community/TIG/PostNL/Model/Core/Order.php CHANGED
@@ -38,35 +38,41 @@
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
  {
@@ -199,6 +205,65 @@ class TIG_PostNL_Model_Core_Order extends Mage_Core_Model_Abstract
199
  return $this;
200
  }
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  /**
203
  * Cancels the PostNL order.
204
  *
38
  *
39
  * Class TIG_PostNL_Model_Core_Order
40
  *
41
+ * @method string getConfirmDate()
42
+ * @method int getIsActive()
43
+ * @method string getToken()
44
+ * @method string getShipmentCosts()
45
+ * @method string getProductCode()
46
+ * @method int getIsPakjeGemak()
47
+ * @method int getIsCanceled()
48
+ * @method string getDeliveryDate()
49
+ * @method int getQuoteId()
50
+ * @method string getType()
51
+ * @method int getOrderId()
52
+ * @method int getEntityId()
53
+ * @method string getMobilePhoneNumber()
54
+ * @method int getIsPakketautomaat()
55
+ *
56
+ * @method TIG_PostNL_Model_Core_Order setIsPakketautomaat(int $value)
 
 
 
 
 
 
 
 
57
  * @method TIG_PostNL_Model_Core_Order setEntityId(int $value)
58
  * @method TIG_PostNL_Model_Core_Order setOrder(Mage_Sales_Model_Order $value)
59
  * @method TIG_PostNL_Model_Core_Order setQuote(Mage_Sales_Model_Quote $value)
60
+ * @method TIG_PostNL_Model_Core_Order setOrderId(int $value)
61
+ * @method TIG_PostNL_Model_Core_Order setType(string $value)
62
+ * @method TIG_PostNL_Model_Core_Order setQuoteId(int $value)
63
+ * @method TIG_PostNL_Model_Core_Order setDeliveryDate(string $value)
64
+ * @method TIG_PostNL_Model_Core_Order setIsCanceled(int $value)
65
+ * @method TIG_PostNL_Model_Core_Order setIsPakjeGemak(int $value)
66
+ * @method TIG_PostNL_Model_Core_Order setProductCode(string $value)
67
+ * @method TIG_PostNL_Model_Core_Order setShipmentCosts(string $value)
68
+ * @method TIG_PostNL_Model_Core_Order setToken(string $value)
69
+ * @method TIG_PostNL_Model_Core_Order setIsActive(int $value)
70
+ * @method TIG_PostNL_Model_Core_Order setConfirmDate(string $value)
71
+ * @method TIG_PostNL_Model_Core_Order setPakjeGemakAddress(mixed $value)
72
+ *
73
+ * @method boolean hasOrderId()
74
+ * @method boolean hasQuoteId()
75
+ * @method boolean hasPakjeGemakAddress()
76
  */
77
  class TIG_PostNL_Model_Core_Order extends Mage_Core_Model_Abstract
78
  {
205
  return $this;
206
  }
207
 
208
+ /**
209
+ * Gets a pakje_gemak address from either the order or the quote associated with this PostNL order.
210
+ *
211
+ * @return bool|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address
212
+ */
213
+ public function getPakjeGemakAddress()
214
+ {
215
+ if ($this->hasPakjeGemakAddress()) {
216
+ return $this->_getData('pakje_gemak_address');
217
+ }
218
+
219
+ $type = $this->getType();
220
+ if ($type != 'PG' && $type != 'PGE' && $type != 'PA') {
221
+ $this->setPakjeGemakAddress(false);
222
+
223
+ return false;
224
+ }
225
+
226
+ if ($this->hasOrderId()) {
227
+ $order = $this->getOrder();
228
+ $addresses = $order->getAddressesCollection();
229
+ } elseif ($this->hasQuoteId()) {
230
+ $quote = $this->getQuote();
231
+ $addresses = $quote->getAddressesCollection();
232
+ } else {
233
+ $this->setPakjeGemakAddress(false);
234
+
235
+ return false;
236
+ }
237
+
238
+ /**
239
+ * @var Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address $address
240
+ */
241
+ foreach ($addresses as $address) {
242
+ if ($address->getAddressType() == 'pakje_gemak' ) {
243
+ $this->setPakjeGemakAddress($address);
244
+
245
+ return $address;
246
+ }
247
+ }
248
+
249
+ $this->setPakjeGemakAddress(false);
250
+
251
+ return false;
252
+ }
253
+
254
+ /**
255
+ * @param Mage_Sales_Model_Order $order
256
+ *
257
+ * @return $this
258
+ */
259
+ public function loadByOrder(Mage_Sales_Model_Order $order)
260
+ {
261
+ $orderId = $order->getId();
262
+
263
+ $this->load($orderId, 'order_id');
264
+ return $this;
265
+ }
266
+
267
  /**
268
  * Cancels the PostNL order.
269
  *
app/code/community/TIG/PostNL/Model/Core/PackingSlip.php ADDED
@@ -0,0 +1,1495 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Core_PackingSlip setStoreId(int $value)
40
+ * @method TIG_PostNL_Model_Core_PackingSlip setItemColumns(array $value)
41
+ *
42
+ * @method int getStoreId()
43
+ *
44
+ * @method boolean hasItemColumns()
45
+ */
46
+ class TIG_PostNL_Model_Core_PackingSlip extends Mage_Sales_Model_Order_Pdf_Abstract
47
+ {
48
+ /**
49
+ * Xpath to packing slip configuration settings.
50
+ */
51
+ const XPATH_PACKING_SLIP_SETTINGS = 'postnl/packing_slip';
52
+
53
+ /**
54
+ * Xpath to the 'item_columns' configuration setting.
55
+ */
56
+ const XPATH_ITEM_COLUMNS = 'postnl/packing_slip/item_columns';
57
+
58
+ /**
59
+ * The height of a page's top and bottom margins.
60
+ */
61
+ const PAGE_TOP_HEIGHT = 815;
62
+ const PAGE_BOTTOM_HEIGHT = 15;
63
+
64
+ /**
65
+ * Y coordinate for right column elements.
66
+ *
67
+ * @var int|void
68
+ */
69
+ public $rightColumnY;
70
+
71
+ /**
72
+ * @var TIG_PostNL_Helper_Data
73
+ */
74
+ protected $_helper;
75
+
76
+ /**
77
+ * @var Mage_Core_Helper_Data
78
+ */
79
+ protected $_coreHelper;
80
+
81
+ /**
82
+ * @var Mage_Core_Helper_String
83
+ */
84
+ protected $_stringHelper;
85
+
86
+ /**
87
+ * @var array
88
+ */
89
+ protected $_config;
90
+
91
+ /**
92
+ * @param TIG_PostNL_Helper_Data $helper
93
+ *
94
+ * @return $this
95
+ */
96
+ public function setHelper($helper)
97
+ {
98
+ $this->_helper = $helper;
99
+
100
+ return $this;
101
+ }
102
+
103
+ /**
104
+ * @return TIG_PostNL_Helper_Data
105
+ */
106
+ public function getHelper()
107
+ {
108
+ return $this->_helper;
109
+ }
110
+
111
+ /**
112
+ * @param Mage_Core_Helper_Data $coreHelper
113
+ *
114
+ * @return $this
115
+ */
116
+ public function setCoreHelper($coreHelper)
117
+ {
118
+ $this->_coreHelper = $coreHelper;
119
+
120
+ return $this;
121
+ }
122
+
123
+ /**
124
+ * @return Mage_Core_Helper_Data
125
+ */
126
+ public function getCoreHelper()
127
+ {
128
+ return $this->_coreHelper;
129
+ }
130
+
131
+ /**
132
+ * @param Mage_Core_Helper_String $stringHelper
133
+ *
134
+ * @return $this
135
+ */
136
+ public function setStringHelper($stringHelper)
137
+ {
138
+ $this->_stringHelper = $stringHelper;
139
+
140
+ return $this;
141
+ }
142
+
143
+ /**
144
+ * @return Mage_Core_Helper_String
145
+ */
146
+ public function getStringHelper()
147
+ {
148
+ return $this->_stringHelper;
149
+ }
150
+
151
+ /**
152
+ * @param array $config
153
+ *
154
+ * @return $this
155
+ */
156
+ public function setConfig($config)
157
+ {
158
+ $this->_config = $config;
159
+
160
+ return $this;
161
+ }
162
+
163
+ /**
164
+ * @param string|null $key
165
+ *
166
+ * @return array
167
+ */
168
+ public function getConfig($key = null)
169
+ {
170
+ $config = $this->_config;
171
+
172
+ if (!is_null($key) && array_key_exists($key, $config)) {
173
+ return $config[$key];
174
+ }
175
+
176
+ return $config;
177
+ }
178
+
179
+ /**
180
+ * Gets the configured item columns sorted by position.
181
+ *
182
+ * @return mixed
183
+ */
184
+ public function getItemColumns()
185
+ {
186
+ if ($this->hasItemColumns()) {
187
+ return $this->_getData('item_columns');
188
+ }
189
+
190
+ $columns = Mage::getStoreConfig(self::XPATH_ITEM_COLUMNS, $this->getStoreId());
191
+ $columns = unserialize($columns);
192
+
193
+ $position = array();
194
+ foreach ($columns as $key => $row) {
195
+ $position[$key] = $row['position'];
196
+ }
197
+
198
+ array_multisort($position, SORT_ASC, $columns);
199
+
200
+ $this->setItemColumns($columns);
201
+ return $columns;
202
+ }
203
+
204
+ /**
205
+ * Constructor.
206
+ *
207
+ * @return void
208
+ */
209
+ protected function _construct()
210
+ {
211
+ $this->setHelper(Mage::helper('postnl'))
212
+ ->setCoreHelper(Mage::helper('core'))
213
+ ->setStringHelper(Mage::helper('core/string'));
214
+ }
215
+
216
+ /**
217
+ * Alias for createPdf().
218
+ *
219
+ * @param array $labels
220
+ * @param TIG_PostNL_Model_Core_Shipment|boolean $postnlShipment
221
+ * @param Zend_Pdf|boolean $mainPdf
222
+ *
223
+ * @return bool|Zend_Pdf
224
+ */
225
+ public function getPdf($labels = array(), $postnlShipment = false, $mainPdf = false)
226
+ {
227
+ if (!$postnlShipment || !$mainPdf) {
228
+ return false;
229
+ }
230
+
231
+ return $this->createPdf($labels, $postnlShipment, $mainPdf);
232
+ }
233
+
234
+ /**
235
+ * Create the full packing slip pdf. This will create an initial Zend_Pdf object with all the address and order info
236
+ * and then merge that with the shipping labels using Fpdi.
237
+ *
238
+ * @param array $labels
239
+ * @param TIG_PostNL_Model_Core_Shipment $postnlShipment
240
+ * @param Zend_Pdf $mainPdf
241
+ *
242
+ * @return Zend_Pdf
243
+ */
244
+ public function createPdf($labels, $postnlShipment, &$mainPdf)
245
+ {
246
+ $pdf = $this->_getPackingSlipPdf($postnlShipment);
247
+
248
+ $labelModel = Mage::getSingleton('postnl_core/label')
249
+ ->setLabelSize('A4')
250
+ ->setOutputMode('S');
251
+
252
+ /**
253
+ * @var TIG_PostNL_Model_Core_Shipment_Label $firstLabel
254
+ */
255
+ $labels = $labelModel->sortLabels($labels);
256
+ $firstLabel = current($labels);
257
+
258
+ if (!$firstLabel) {
259
+ return $pdf;
260
+ } elseif (
261
+ !$this->getConfig('show_label')
262
+ || $this->y < 421
263
+ || ($firstLabel->getLabelType() != 'Label'
264
+ && $firstLabel->getLabelType() != 'Label-combi'
265
+ && $firstLabel->getLabelType() != 'BusPakje'
266
+ && $firstLabel->getLabelType() != 'BusPakjeExtra'
267
+ )
268
+ ) {
269
+ foreach($pdf->pages as $page) {
270
+ $mainPdf->pages[] = clone $page;
271
+ }
272
+
273
+ $labelsString = $labelModel->createPdf($labels);
274
+
275
+ $labelPdf = Zend_Pdf::parse($labelsString);
276
+
277
+ foreach ($labelPdf->pages as $page) {
278
+ $mainPdf->pages[] = clone $page;
279
+ }
280
+ } else {
281
+ $packingSlipString = $pdf->render();
282
+ $labelsString = $labelModel->createPackingSlipLabel(array_shift($labels), $packingSlipString);
283
+
284
+ $pdf = Zend_Pdf::parse($labelsString);
285
+ foreach($pdf->pages as $page) {
286
+ $mainPdf->pages[] = clone $page;
287
+ }
288
+
289
+ if (count($labels) > 0) {
290
+ $labelModel->resetLabelCounter();
291
+ $additionalLabelsString = $labelModel->createPdf($labels);
292
+
293
+ $labelPdf = Zend_Pdf::parse($additionalLabelsString);
294
+
295
+ foreach ($labelPdf->pages as $page) {
296
+ $mainPdf->pages[] = clone $page;
297
+ }
298
+ }
299
+ }
300
+ return $mainPdf;
301
+ }
302
+
303
+ /**
304
+ * Builds the packing slip part of the final pdf.
305
+ *
306
+ * @param TIG_PostNL_Model_Core_Shipment $postnlShipment
307
+ *
308
+ * @return Zend_Pdf
309
+ */
310
+ protected function _getPackingSlipPdf($postnlShipment)
311
+ {
312
+ $shipment = $postnlShipment->getShipment();
313
+
314
+ /**
315
+ * Create a dummy invoice for the totals at the bottom of the packing slip.
316
+ */
317
+ $invoice = Mage::getModel('postnl_core/service')->initInvoice($shipment, true);
318
+ $storeId = $shipment->getStoreId();
319
+
320
+ /**
321
+ * Set the store ID and configuration settings.
322
+ */
323
+ $this->setStoreId($storeId);
324
+ $this->setConfig(Mage::getStoreConfig(self::XPATH_PACKING_SLIP_SETTINGS, $storeId));
325
+
326
+ $this->_beforeGetPdf();
327
+ $this->_initRenderer('postnl_packingslip');
328
+
329
+ $pdf = new Zend_Pdf();
330
+ $this->_setPdf($pdf);
331
+
332
+ $this->y = self::PAGE_TOP_HEIGHT;
333
+ $this->rightColumnY = self::PAGE_TOP_HEIGHT;
334
+
335
+ if ($shipment->getStoreId()) {
336
+ Mage::app()->getLocale()->emulate($storeId);
337
+ Mage::app()->setCurrentStore($storeId);
338
+ }
339
+ $page = $this->newPage();
340
+ $order = $shipment->getOrder();
341
+
342
+ /*
343
+ * Add upper pdf contents.
344
+ */
345
+ $this->_insertLogo($page)
346
+ ->_insertCompanyInfo($page, $storeId)
347
+ ->_insertCustomerId($page, $order->getCustomerId())
348
+ ->_insertOrderInfo($page, $order, $shipment)
349
+ ->_insertPaymentInfo($page, $order)
350
+ ->_insertOrderAddresses($page, $order)
351
+ ->_insertShipmentInfo($page, $order, $postnlShipment);
352
+
353
+ /**
354
+ * Make sure the lowest y coordinate is used to prevent elements from overlapping.
355
+ */
356
+ if ($this->rightColumnY < $this->y) {
357
+ $this->y = $this->rightColumnY;
358
+ }
359
+
360
+ /**
361
+ * Add shipment items table.
362
+ */
363
+ $this->_drawItemsHeader($page);
364
+
365
+ /**
366
+ * Add shipment items table body.
367
+ *
368
+ * @var Mage_Sales_Model_Order_Invoice_Item $item
369
+ */
370
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.9));
371
+ $items = $invoice->getAllItems();
372
+ foreach ($items as $item) {
373
+ if ($item->getOrderItem()->getParentItem()) {
374
+ continue;
375
+ }
376
+ /**
377
+ * Draw item
378
+ */
379
+ $this->_drawItem($item, $page, $order);
380
+ $page->drawLine(15, $this->y + 15, 580, $this->y + 15);
381
+ $page = end($pdf->pages);
382
+ }
383
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0));
384
+
385
+ /**
386
+ * Add shipment comment.
387
+ */
388
+ $this->_insertShipmentComment($page, $shipment);
389
+
390
+ /**
391
+ * Add totals.
392
+ */
393
+ $this->_insertTotals($page, $order, $invoice);
394
+
395
+ $this->_afterGetPdf();
396
+ if ($shipment->getStoreId()) {
397
+ Mage::app()->getLocale()->revert();
398
+ }
399
+ return $pdf;
400
+ }
401
+
402
+ /**
403
+ * Set font as regular.
404
+ *
405
+ * @param Zend_Pdf_Page $object
406
+ * @param int $size
407
+ *
408
+ * @return Zend_Pdf_Resource_Font
409
+ */
410
+ protected function _setFontRegular($object, $size = 8)
411
+ {
412
+ $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
413
+ $object->setFont($font, $size);
414
+
415
+ return $font;
416
+ }
417
+
418
+ /**
419
+ * Set font as bold.
420
+ *
421
+ * @param Zend_Pdf_Page $object
422
+ * @param int $size
423
+ *
424
+ * @return Zend_Pdf_Resource_Font
425
+ */
426
+ protected function _setFontBold($object, $size = 8)
427
+ {
428
+ $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
429
+ $object->setFont($font, $size);
430
+
431
+ return $font;
432
+ }
433
+
434
+ /**
435
+ * Set font as italic.
436
+ *
437
+ * @param Zend_Pdf_Page $object
438
+ * @param int $size
439
+ *
440
+ * @return Zend_Pdf_Resource_Font
441
+ */
442
+ protected function _setFontItalic($object, $size = 8)
443
+ {
444
+ $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC);
445
+ $object->setFont($font, $size);
446
+
447
+ return $font;
448
+ }
449
+
450
+ /**
451
+ * Insert logo to pdf page.
452
+ *
453
+ * @param Zend_Pdf_Page &$page
454
+ *
455
+ * @return $this
456
+ */
457
+ protected function _insertLogo(&$page)
458
+ {
459
+ if (!$this->y) {
460
+ $this->y = self::PAGE_TOP_HEIGHT;
461
+ }
462
+
463
+ $image = $this->getConfig('logo');
464
+ if (!$image) {
465
+ return $this;
466
+ }
467
+
468
+ $image = Mage::getBaseDir('media')
469
+ . DS
470
+ . 'TIG'
471
+ . DS
472
+ . 'PostNL'
473
+ . DS
474
+ . 'core'
475
+ . DS
476
+ . 'packing_slip_logo'
477
+ . DS
478
+ . $image;
479
+
480
+ if (!is_file($image)) {
481
+ return $this;
482
+ }
483
+
484
+ $image = Zend_Pdf_Image::imageWithPath($image);
485
+ $top = 827;
486
+ $widthLimit = 200;
487
+ $heightLimit = 34;
488
+ $width = $image->getPixelWidth();
489
+ $height = $image->getPixelHeight();
490
+
491
+ /**
492
+ * Calculate the image's height and width ratio and resize the image if needed.
493
+ */
494
+ $ratio = $width / $height;
495
+
496
+ if ($width > $widthLimit) {
497
+ $width = $widthLimit;
498
+ $height = $width / $ratio;
499
+ }
500
+
501
+ if ($height > $heightLimit) {
502
+ $height = $heightLimit;
503
+ $width = $height * $ratio;
504
+ }
505
+
506
+ if ($ratio == 1 && $height > $heightLimit) {
507
+ $height = $heightLimit;
508
+ $width = $widthLimit;
509
+ }
510
+
511
+ $y1 = $top - $height;
512
+ $y2 = $top;
513
+ $x1 = 15;
514
+ $x2 = $x1 + $width;
515
+
516
+ /**
517
+ * Draw the image.
518
+ */
519
+ $page->drawImage($image, $x1, $y1, $x2, $y2);
520
+
521
+ $this->y = $y1 - 14;
522
+
523
+ return $this;
524
+ }
525
+
526
+ /**
527
+ * Add company information to the pdf page. Company info is the company's contact address, CoC number and VAT
528
+ * number.
529
+ *
530
+ * @param Zend_Pdf_Page &$page
531
+ * @param null|int $store
532
+ *
533
+ * @return $this
534
+ */
535
+ protected function _insertCompanyInfo(&$page, $store = null)
536
+ {
537
+ if (!$this->getConfig('show_webshop_info')) {
538
+ return $this;
539
+ }
540
+
541
+ if (!$this->y) {
542
+ $this->y = self::PAGE_TOP_HEIGHT;
543
+ }
544
+
545
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
546
+ $this->_setFontRegular($page, 8);
547
+ $page->setLineWidth(0);
548
+
549
+ $top = $this->y;
550
+ $rightTop = $this->y;
551
+
552
+ foreach (explode("\n", Mage::getStoreConfig('sales/identity/address', $store)) as $value){
553
+ if (empty($value)) {
554
+ continue;
555
+ }
556
+
557
+ $value = preg_replace('/<br[^>]*>/i', "\n", $value);
558
+ $splitString = $this->getStringHelper()->str_split($value, 45, true, true);
559
+ foreach ($splitString as $_value) {
560
+ $page->drawText(
561
+ trim(
562
+ strip_tags($_value)
563
+ ),
564
+ 15,
565
+ $top,
566
+ 'UTF-8'
567
+ );
568
+ $top -= 10;
569
+ }
570
+ }
571
+
572
+ if ($this->getConfig('coc_number')) {
573
+ $page->drawText(
574
+ $this->getHelper()->__('CoC') . ' ' . $this->getConfig('coc_number'),
575
+ 165,
576
+ $rightTop,
577
+ 'UTF-8'
578
+ );
579
+ $rightTop -= 10;
580
+ }
581
+
582
+ if ($this->getConfig('vat_number')) {
583
+ $page->drawText(
584
+ $this->getHelper()->__('VAT') . ' ' . $this->getConfig('vat_number'),
585
+ 165,
586
+ $rightTop,
587
+ 'UTF-8'
588
+ );
589
+ $rightTop -= 10;
590
+ }
591
+
592
+ $top = ($top > $rightTop) ? $rightTop : $top;
593
+
594
+ $this->y = ($this->y > $top) ? $top : $this->y;
595
+
596
+ return $this;
597
+ }
598
+
599
+ /**
600
+ * Add order info.
601
+ *
602
+ * @param Zend_Pdf_Page &$page
603
+ * @param Mage_Sales_Model_Order $order
604
+ * @param Mage_Sales_Model_Order_Shipment $shipment
605
+ *
606
+ * @return $this
607
+ */
608
+ protected function _insertOrderInfo(&$page, $order, $shipment)
609
+ {
610
+ $top = $this->rightColumnY;
611
+
612
+ $font = $this->_setFontBold($page, 15);
613
+ $text = $this->getHelper()->__('Packing slip');
614
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 15);
615
+ $page->drawText(
616
+ $text,
617
+ $x,
618
+ $top,
619
+ 'UTF-8'
620
+ );
621
+
622
+ $top -= 20;
623
+
624
+ $this->rightColumnY = $top;
625
+
626
+ if (!$this->getConfig('show_order_info')) {
627
+ return $this;
628
+ }
629
+
630
+ $font = $this->_setFontRegular($page, 8);
631
+ $text = $this->getHelper()->__('Order') . ' # ' . $order->getIncrementId();
632
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 8);
633
+ $page->drawText(
634
+ $text,
635
+ $x,
636
+ $top,
637
+ 'UTF-8'
638
+ );
639
+
640
+ $top -= 10;
641
+
642
+ $text = $this->getHelper()->__('Shipment') . ' # ' . $shipment->getIncrementId();
643
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 8);
644
+ $page->drawText(
645
+ $text,
646
+ $x,
647
+ $top,
648
+ 'UTF-8'
649
+ );
650
+
651
+ $top -= 10;
652
+
653
+ $text = $this->getHelper()->__('Order date')
654
+ . ': '
655
+ . $this->getCoreHelper()->formatDate($order->getCreatedAtDate(), 'long', false);
656
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 8);
657
+ $page->drawText(
658
+ $text,
659
+ $x,
660
+ $top,
661
+ 'UTF-8'
662
+ );
663
+
664
+ $top -= 10;
665
+
666
+ $this->rightColumnY = $top;
667
+
668
+ return $this;
669
+ }
670
+
671
+ /**
672
+ * @param Zend_Pdf_Page &$page
673
+ * @param Mage_Sales_Model_Order $order
674
+ *
675
+ * @return $this
676
+ */
677
+ protected function _insertPaymentInfo(&$page, $order)
678
+ {
679
+ if (!$this->getConfig('show_payment_method')) {
680
+ return $this;
681
+ }
682
+
683
+ $this->rightColumnY -= 24;
684
+ $top = $this->rightColumnY;
685
+
686
+ $font = $this->_setFontBold($page, 8);
687
+ $text = $this->getHelper()->__('Payment method');
688
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 8);
689
+ $page->drawText(
690
+ $text,
691
+ $x,
692
+ $top,
693
+ 'UTF-8'
694
+ );
695
+
696
+ $top -= 10;
697
+
698
+ /**
699
+ * Payment info.
700
+ */
701
+ $paymentInfo = Mage::helper('payment')
702
+ ->getInfoBlock($order->getPayment())
703
+ ->setIsSecureMode(true)
704
+ ->toPdf();
705
+ $paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
706
+ $payment = explode('{{pdf_row_separator}}', $paymentInfo);
707
+ foreach ($payment as $key => $value){
708
+ if (strip_tags(trim($value)) == '') {
709
+ unset($payment[$key]);
710
+ }
711
+ }
712
+ reset($payment);
713
+
714
+ $font = $this->_setFontRegular($page, 8);
715
+ foreach ($payment as $value){
716
+ if (trim($value) != '') {
717
+ //Printing "Payment Method" lines
718
+ $value = preg_replace('/<br[^>]*>/i', "\n", $value);
719
+ foreach ($this->getStringHelper()->str_split($value, 45, true, true) as $_value) {
720
+ $text = strip_tags(trim($_value));
721
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 8);
722
+
723
+ $page->drawText(strip_tags(trim($_value)), $x, $top, 'UTF-8');
724
+ $top -= 10;
725
+ }
726
+ }
727
+ }
728
+
729
+ $this->rightColumnY = $top;
730
+
731
+ return $this;
732
+ }
733
+
734
+ /**
735
+ * @param Zend_Pdf_Page &$page
736
+ * @param Mage_Sales_Model_Order $order
737
+ * @param TIG_Postnl_Model_Core_Shipment $postnlShipment
738
+ *
739
+ * @return $this
740
+ */
741
+ protected function _insertShipmentInfo(&$page, $order, $postnlShipment)
742
+ {
743
+ if (!$this->getConfig('show_shipping_method')) {
744
+ return $this;
745
+ }
746
+
747
+ $this->rightColumnY -= 14;
748
+ $top = $this->rightColumnY;
749
+
750
+ $font = $this->_setFontBold($page, 8);
751
+ $text = $this->getHelper()->__('Shipping method');
752
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 8);
753
+ $page->drawText(
754
+ $text,
755
+ $x,
756
+ $top,
757
+ 'UTF-8'
758
+ );
759
+
760
+ $top -= 10;
761
+
762
+ $shippingMethod = $order->getShippingDescription();
763
+
764
+ $font = $this->_setFontRegular($page, 8);
765
+ $text = strip_tags(trim($shippingMethod))
766
+ . ' - '
767
+ . $order->formatPriceTxt($order->getShippingAmount() + $order->getShippingTaxAmount());
768
+ $x = 584 - $this->widthForStringUsingFontSize($text, $font, 8);
769
+ $page->drawText($text, $x, $top, 'UTF-8');
770
+
771
+ $top -= 10;
772
+
773
+ $deliveryDate = $postnlShipment->getDeliveryDate();
774
+ $text = $this->getCoreHelper()->formatDate($deliveryDate, 'short', false);
775
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 8);
776
+ $page->drawText($text, $x, $top, 'UTF-8');
777
+
778
+ $top -= 24;
779
+
780
+ $font = $this->_setFontBold($page, 8);
781
+ $text = $this->getHelper()->__('Ship order on');
782
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 8);
783
+ $page->drawText(
784
+ $text,
785
+ $x,
786
+ $top,
787
+ 'UTF-8'
788
+ );
789
+
790
+ $top -= 10;
791
+
792
+ if ($this->getConfig('show_shipping_date')) {
793
+ $font = $this->_setFontRegular($page, 8);
794
+ $confirmDate = $postnlShipment->getConfirmDate();
795
+ $text = $this->getCoreHelper()->formatDate($confirmDate, 'full', false);
796
+ $x = 580 - $this->widthForStringUsingFontSize($text, $font, 8);
797
+ $page->drawText(
798
+ $text,
799
+ $x,
800
+ $top,
801
+ 'UTF-8'
802
+ );
803
+
804
+ $top -= 10;
805
+ }
806
+
807
+ $this->rightColumnY = $top - 14;
808
+
809
+ return $this;
810
+ }
811
+
812
+ /**
813
+ * @param Zend_Pdf_Page &$page
814
+ * @param int|null $customerId
815
+ *
816
+ * @return $this
817
+ */
818
+ protected function _insertCustomerId(&$page, $customerId)
819
+ {
820
+ if (!$this->getConfig('show_customer_number') || !$customerId) {
821
+ return $this;
822
+ }
823
+
824
+ if (!$this->y) {
825
+ $this->y = self::PAGE_TOP_HEIGHT;
826
+ }
827
+
828
+ $this->_setFontBold($page, 8);
829
+ $page->setLineWidth(0);
830
+ $top = $this->y - 24;
831
+
832
+ $page->drawText(
833
+ $this->getHelper()->__('Customer number'),
834
+ 15,
835
+ $top,
836
+ 'UTF-8'
837
+ );
838
+ $top -= 10;
839
+
840
+ $this->_setFontRegular($page, 8);
841
+
842
+ $page->drawText(
843
+ $customerId,
844
+ 15,
845
+ $top,
846
+ 'UTF-8'
847
+ );
848
+
849
+ $this->y = ($this->y > $top) ? $top : $this->y;
850
+
851
+ return $this;
852
+ }
853
+
854
+ /**
855
+ * Add address info to the pdf page. A maximum of 3 addresses will be added: the billing address, shipping address
856
+ * and PakjeGemak address. Each can be enabled and disabled in the extension configuration.
857
+ *
858
+ * @param Zend_Pdf_Page &$page
859
+ * @param Mage_Sales_Model_Order $obj
860
+ *
861
+ * @return $this
862
+ *
863
+ * @throws TIG_PostNL_Exception
864
+ */
865
+ protected function _insertOrderAddresses(&$page, $obj)
866
+ {
867
+ $showBillingAddress = $this->getConfig('show_billing_address');
868
+ $showShippingAddress = $this->getConfig('show_shipping_address');
869
+ $showPakjegemakAddress = $this->getConfig('show_pakjegemak_address');
870
+
871
+ if (!$showBillingAddress && !$showShippingAddress && !$showPakjegemakAddress) {
872
+ return $this;
873
+ }
874
+
875
+ if ($obj instanceof Mage_Sales_Model_Order) {
876
+ $shipment = null;
877
+ $order = $obj;
878
+ } elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) {
879
+ $shipment = $obj;
880
+ $order = $shipment->getOrder();
881
+ } else {
882
+ throw new TIG_PostNL_Exception(
883
+ $this->getHelper()->__('No valid order available for packing slip.').
884
+ 'POSTNL-0168'
885
+ );
886
+ }
887
+
888
+ if (!$this->y) {
889
+ $this->y = self::PAGE_TOP_HEIGHT;
890
+ }
891
+
892
+ $top = $this->y - 14;
893
+
894
+ $this->_setFontBold($page, 8);
895
+
896
+ $addressX = 15;
897
+
898
+ $billingAddress = false;
899
+ $shippingAddress = false;
900
+ $pakjeGemakAddress = false;
901
+
902
+ if ($showBillingAddress) {
903
+ $billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf'));
904
+
905
+ $page->drawText($this->getHelper()->__('Billing address'), $addressX, ($top - 15), 'UTF-8');
906
+ $addressX += 150;
907
+ }
908
+
909
+ if ($showShippingAddress) {
910
+ $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf'));
911
+
912
+ $page->drawText($this->getHelper()->__('Shipping address'), $addressX, ($top - 15), 'UTF-8');
913
+ $addressX += 150;
914
+ }
915
+
916
+ if ($showPakjegemakAddress) {
917
+ /**
918
+ * @var Mage_Sales_Model_Order_Address $address
919
+ */
920
+ $addressesCollection = $order->getAddressesCollection();
921
+ foreach ($addressesCollection as $address) {
922
+ if ($address->getAddressType() != 'pakje_gemak') {
923
+ continue;
924
+ }
925
+
926
+ $pakjeGemakAddress = $this->_formatAddress($address->format('pdf'));
927
+
928
+ $page->drawText($this->getHelper()->__('Post office address'), $addressX, ($top - 15), 'UTF-8');
929
+ }
930
+ }
931
+
932
+ $this->_setFontRegular($page, 8);
933
+ $this->y = $top - 25;
934
+ $addressesStartY = $this->y;
935
+ $addressX = 15;
936
+
937
+ if ($showBillingAddress && $billingAddress) {
938
+ foreach ($billingAddress as $value){
939
+ if ($value !== '') {
940
+ foreach ($this->getStringHelper()->str_split($value, 20, true, true) as $part) {
941
+ $page->drawText(strip_tags(ltrim($part)), $addressX, $this->y, 'UTF-8');
942
+ $this->y -= 10;
943
+ }
944
+ }
945
+ }
946
+
947
+ $addressX += 150;
948
+ }
949
+
950
+ $addressesEndY = $this->y;
951
+
952
+ if ($showShippingAddress && $shippingAddress) {
953
+ $this->y = $addressesStartY;
954
+ foreach ($shippingAddress as $value){
955
+ if ($value!=='') {
956
+ foreach ($this->getStringHelper()->str_split($value, 20, true, true) as $part) {
957
+ $page->drawText(strip_tags(ltrim($part)), $addressX, $this->y, 'UTF-8');
958
+ $this->y -= 10;
959
+ }
960
+ }
961
+ }
962
+
963
+ $addressesEndY = min($addressesEndY, $this->y);
964
+ $this->y = $addressesEndY;
965
+
966
+ $addressX += 150;
967
+ }
968
+
969
+ if ($showPakjegemakAddress && $pakjeGemakAddress) {
970
+ $this->y = $addressesStartY;
971
+ foreach ($pakjeGemakAddress as $value){
972
+ if ($value!=='') {
973
+ $text = array();
974
+ foreach ($this->getStringHelper()->str_split($value, 20, true, true) as $part) {
975
+ $page->drawText(strip_tags(ltrim($part)), $addressX, $this->y, 'UTF-8');
976
+ $this->y -= 10;
977
+ }
978
+ }
979
+ }
980
+
981
+ $addressesEndY = min($addressesEndY, $this->y);
982
+ $this->y = $addressesEndY;
983
+ }
984
+
985
+ $this->y -= 14;
986
+
987
+ return $this;
988
+ }
989
+
990
+ /**
991
+ * Draw table header for product items.
992
+ *
993
+ * @param Zend_Pdf_Page &$page
994
+ *
995
+ * @return $this
996
+ */
997
+ protected function _drawItemsHeader(Zend_Pdf_Page &$page)
998
+ {
999
+ if (!$this->y) {
1000
+ $this->y = self::PAGE_TOP_HEIGHT;
1001
+ }
1002
+
1003
+ /*
1004
+ * Add table head.
1005
+ */
1006
+ $this->_setFontRegular($page, 8);
1007
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.9));
1008
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.9));
1009
+ $page->drawRectangle(15, $this->y, 580, $this->y-20);
1010
+ $this->y -= 13;
1011
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
1012
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0));
1013
+
1014
+ $columns = $this->getItemColumns();
1015
+
1016
+ $lines = array(
1017
+ array()
1018
+ );
1019
+
1020
+ $i = 0;
1021
+ $feed = 20;
1022
+ $previousFeed = 0;
1023
+ foreach ($columns as $column) {
1024
+ if ($i > 0) {
1025
+ $align = 'right';
1026
+ } else {
1027
+ $align = 'left';
1028
+ }
1029
+
1030
+ $feed += $previousFeed;
1031
+ $previousFeed = $column['width'];
1032
+
1033
+ $lines[0][] = array(
1034
+ 'text' => $this->getHelper()->__($column['title']),
1035
+ 'feed' => $feed,
1036
+ 'font' => 'bold',
1037
+ 'align' => $align,
1038
+ 'font_size' => 8,
1039
+ );
1040
+
1041
+ $i++;
1042
+ }
1043
+
1044
+ $lineBlock = array(
1045
+ 'lines' => $lines,
1046
+ 'height' => 20
1047
+ );
1048
+
1049
+ $this->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
1050
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
1051
+
1052
+ return $this;
1053
+ }
1054
+
1055
+ /**
1056
+ * Draw Item process
1057
+ *
1058
+ * @param Varien_Object|Mage_Sales_Model_Order_Shipment_item $item
1059
+ * @param Zend_Pdf_Page $page
1060
+ * @param Mage_Sales_Model_Order $order
1061
+ * @return Zend_Pdf_Page
1062
+ */
1063
+ protected function _drawItem(Varien_Object $item, Zend_Pdf_Page $page, Mage_Sales_Model_Order $order)
1064
+ {
1065
+ $orderItem = $item->getOrderItem();
1066
+ $type = $orderItem->getProductType();
1067
+ $renderer = $this->_getRenderer($type);
1068
+
1069
+ $this->renderItem($item, $page, $order, $renderer);
1070
+
1071
+ $transportObject = new Varien_Object(array('renderer_type_list' => array()));
1072
+ Mage::dispatchEvent(
1073
+ 'pdf_item_draw_after',
1074
+ array(
1075
+ 'transport_object' => $transportObject,
1076
+ 'entity_item' => $item
1077
+ )
1078
+ );
1079
+
1080
+ foreach ($transportObject->getData('renderer_type_list') as $type) {
1081
+ $renderer = $this->_getRenderer($type);
1082
+ if ($renderer) {
1083
+ $this->renderItem($orderItem, $page, $order, $renderer);
1084
+ }
1085
+ }
1086
+
1087
+ return $renderer->getPage();
1088
+ }
1089
+
1090
+ /**
1091
+ * Render item
1092
+ *
1093
+ * @param Varien_Object $item
1094
+ * @param Zend_Pdf_Page $page
1095
+ * @param Mage_Sales_Model_Order $order
1096
+ * @param Mage_Sales_Model_Order_Pdf_Items_Abstract $renderer
1097
+ *
1098
+ * @return Mage_Sales_Model_Order_Pdf_Abstract
1099
+ */
1100
+ public function renderItem(Varien_Object $item, Zend_Pdf_Page $page, Mage_Sales_Model_Order $order, $renderer)
1101
+ {
1102
+ $renderer->setOrder($order)
1103
+ ->setItem($item)
1104
+ ->setPdf($this)
1105
+ ->setPage($page)
1106
+ ->setItemColumns($this->getItemColumns())
1107
+ ->setRenderedModel($this)
1108
+ ->draw();
1109
+
1110
+ return $this;
1111
+ }
1112
+
1113
+ /**
1114
+ * Add shipment comment to the page.
1115
+ *
1116
+ * @param Zend_Pdf_Page &$page
1117
+ * @param Mage_Sales_Model_Order_Shipment $shipment
1118
+ *
1119
+ * @return $this
1120
+ */
1121
+ protected function _insertShipmentComment(&$page, $shipment)
1122
+ {
1123
+ if (!$this->getConfig('show_comment')) {
1124
+ return $this;
1125
+ }
1126
+
1127
+ $commentType = $this->getConfig('comment_type');
1128
+
1129
+ if ($commentType == 'static') {
1130
+ $commentText = $this->getStringHelper()->stripTags($this->getConfig('comment_text'));
1131
+ } else {
1132
+ $commentsCollection = $shipment->getCommentsCollection()
1133
+ ->addFieldToFilter('is_visible_on_front', array('eq' => 1));
1134
+
1135
+ $commentsCollection->getSelect()
1136
+ ->limit(1);
1137
+
1138
+ /**
1139
+ * @var Mage_Sales_Model_Order_Shipment_Comment $comment
1140
+ */
1141
+ $comment = $commentsCollection->getFirstItem();
1142
+ if (!$comment || !$comment->getId()) {
1143
+ return $this;
1144
+ }
1145
+
1146
+ $commentText = $comment->getComment();
1147
+ }
1148
+
1149
+ $top = $this->y;
1150
+
1151
+ $commentTextParts = $this->getStringHelper()->str_split($commentText, 70, true, true);
1152
+ $height = 12 * count($commentTextParts) + 10;
1153
+
1154
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.9));
1155
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.9));
1156
+ $page->drawRectangle(15, $top, 300, $top - $height);
1157
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
1158
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0));
1159
+
1160
+ $top -= 14;
1161
+ $this->_setFontItalic($page, 8);
1162
+
1163
+ foreach ($commentTextParts as $text) {
1164
+ $page->drawText(
1165
+ $text,
1166
+ 20,
1167
+ $top
1168
+ );
1169
+ $top -= 10;
1170
+ }
1171
+
1172
+ $this->_setFontRegular($page, 8);
1173
+
1174
+ return $this;
1175
+ }
1176
+
1177
+ /**
1178
+ * Adds totals to the page.
1179
+ *
1180
+ * @param Zend_Pdf_Page &$page
1181
+ * @param Mage_Sales_Model_Order $order
1182
+ * @param Mage_Sales_Model_Order_Invoice $invoice
1183
+ *
1184
+ * @return $this
1185
+ */
1186
+ protected function _insertTotals(&$page, $order, $invoice)
1187
+ {
1188
+ if (!$this->getConfig('show_totals')) {
1189
+ return $this;
1190
+ }
1191
+
1192
+ $totals = $this->_getTotalsList($order);
1193
+ $lineBlock = array(
1194
+ 'lines' => array(),
1195
+ 'height' => 15
1196
+ );
1197
+
1198
+ /**
1199
+ * @var Mage_Sales_Model_Order_Pdf_Total_Default $total
1200
+ */
1201
+ foreach ($totals as $total) {
1202
+ $total->setOrder($order)
1203
+ ->setSource($invoice);
1204
+
1205
+ if ($total->canDisplay()) {
1206
+ $total->setFontSize(10);
1207
+ foreach ($total->getTotalsForDisplay() as $totalData) {
1208
+ $label = array(
1209
+ 'text' => $totalData['label'],
1210
+ 'feed' => 495,
1211
+ 'align' => 'right',
1212
+ 'font_size' => 8,
1213
+ 'height' => 15,
1214
+ );
1215
+
1216
+ $value = array(
1217
+ 'text' => $totalData['amount'],
1218
+ 'feed' => 580,
1219
+ 'align' => 'right',
1220
+ 'font_size' => 8,
1221
+ 'height' => 15,
1222
+ );
1223
+
1224
+ if ($total->getSourceField() == 'grand_total') {
1225
+ $label['font'] = 'bold';
1226
+ $value['font'] = 'bold';
1227
+ }
1228
+
1229
+ $line = array($label, $value);
1230
+
1231
+ $lineBlock['lines'][] = $line;
1232
+ }
1233
+ }
1234
+ }
1235
+
1236
+ $this->y -= 4;
1237
+ $page = $this->drawLineBlocks($page, array($lineBlock));
1238
+
1239
+ return $this;
1240
+ }
1241
+
1242
+ /**
1243
+ * Draw lines.
1244
+ *
1245
+ * draw items array format:
1246
+ * lines array;array of line blocks (required)
1247
+ * shift int; full line height (optional)
1248
+ * height int;line spacing (default 10)
1249
+ *
1250
+ * line block has line columns array
1251
+ *
1252
+ * column array format
1253
+ * text string|array; draw text (required)
1254
+ * feed int; x position (required)
1255
+ * font string; font style, optional: bold, italic, regular
1256
+ * font_file string; path to font file (optional for use your custom font)
1257
+ * font_size int; font size (default 7)
1258
+ * align string; text align (also see feed parameter), optional left, right
1259
+ * height int;line spacing (default 10)
1260
+ * shift int;Vertical indentation. In addition to the line spacing
1261
+ *
1262
+ * @param Zend_Pdf_Page $page
1263
+ * @param array $draw
1264
+ * @param array $pageSettings
1265
+ *
1266
+ * @throws Mage_Core_Exception
1267
+ *
1268
+ * @return Zend_Pdf_Page
1269
+ */
1270
+ public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSettings = array())
1271
+ {
1272
+ foreach ($draw as $itemsProp) {
1273
+ if (!isset($itemsProp['lines']) || !is_array($itemsProp['lines'])) {
1274
+ Mage::throwException(
1275
+ Mage::helper('sales')->__('Invalid draw line data. Please define "lines" array.')
1276
+ );
1277
+ }
1278
+
1279
+ $this->_drawLineBlock($page, $pageSettings, $itemsProp);
1280
+ }
1281
+
1282
+ return $page;
1283
+ }
1284
+
1285
+ /**
1286
+ * Draw a single line.
1287
+ *
1288
+ * @param Zend_Pdf_Page $page
1289
+ * @param array $pageSettings
1290
+ * @param array $itemsProp
1291
+ *
1292
+ * @return $this
1293
+ *
1294
+ * @throws Zend_Pdf_Exception
1295
+ */
1296
+ protected function _drawLineBlock($page, $pageSettings, $itemsProp)
1297
+ {
1298
+ $lines = $itemsProp['lines'];
1299
+ $height = 10;
1300
+
1301
+ if (isset($itemsProp['height'])) {
1302
+ $height = $itemsProp['height'];
1303
+ }
1304
+
1305
+ if (!isset($itemsProp['shift']) || empty($itemsProp['shift'])) {
1306
+ $itemsProp['shift'] = $this->_getItemShift($lines, $height);
1307
+ }
1308
+
1309
+ if ($this->y - $itemsProp['shift'] < self::PAGE_BOTTOM_HEIGHT) {
1310
+ $page = $this->newPage($pageSettings);
1311
+ }
1312
+
1313
+ foreach ($lines as $line) {
1314
+ $maxHeight = 0;
1315
+ foreach ($line as $column) {
1316
+ $maxHeight = $this->_drawLineBlockColumn($page, $height, $maxHeight, $pageSettings, $column);
1317
+ }
1318
+ $this->y -= $maxHeight;
1319
+ }
1320
+
1321
+ return $this;
1322
+ }
1323
+
1324
+ /**
1325
+ * Calculates the shift of an item.
1326
+ *
1327
+ * @param array $lines
1328
+ * @param int $height
1329
+ *
1330
+ * @return int
1331
+ */
1332
+ protected function _getItemShift($lines, $height)
1333
+ {
1334
+ $shift = 0;
1335
+ foreach ($lines as $line) {
1336
+ $maxHeight = 0;
1337
+ foreach ($line as $column) {
1338
+ $lineSpacing = $height;
1339
+ if (isset($column['height']) && $column['height']) {
1340
+ $lineSpacing = $column['height'];
1341
+ }
1342
+
1343
+ if (isset($column['text']) && !is_array($column['text'])) {
1344
+ $column['text'] = array($column['text']);
1345
+ }
1346
+
1347
+ $top = 0;
1348
+ $textCount = count($column['text']);
1349
+ $top += ($lineSpacing * $textCount);
1350
+
1351
+ if ($top > $maxHeight) {
1352
+ $maxHeight = $top;
1353
+ }
1354
+ }
1355
+
1356
+ $shift += $maxHeight;
1357
+ }
1358
+
1359
+ return $shift;
1360
+ }
1361
+
1362
+ /**
1363
+ * Draw a column of a line block.
1364
+ *
1365
+ * @param Zend_Pdf_Page &$page
1366
+ * @param int $height
1367
+ * @param int $maxHeight
1368
+ * @param array $pageSettings
1369
+ * @param array $column
1370
+ *
1371
+ * @return int
1372
+ *
1373
+ * @throws Zend_Pdf_Exception
1374
+ */
1375
+ protected function _drawLineBlockColumn(&$page, $height, $maxHeight, $pageSettings, $column)
1376
+ {
1377
+ list($font, $fontSize) = $this->_setLineBlockColumnFont($page, $column);
1378
+
1379
+ if (!is_array($column['text'])) {
1380
+ $column['text'] = array($column['text']);
1381
+ }
1382
+
1383
+ $lineSpacing = $height;
1384
+ if (isset($column['height']) && !empty($column['height'])) {
1385
+ $lineSpacing = $column['height'];
1386
+ }
1387
+
1388
+ $top = 0;
1389
+ foreach ($column['text'] as $part) {
1390
+ $feed = $column['feed'];
1391
+ $shift = 0;
1392
+ $textAlign = 'left';
1393
+ $width = 0;
1394
+
1395
+ if (array_key_exists('shift', $column)) {
1396
+ $shift = $column['shift'];
1397
+ }
1398
+
1399
+ if (isset($column['align']) && !empty($column['align'])) {
1400
+ $textAlign = $column['align'];
1401
+ }
1402
+
1403
+ if (isset($column['width']) && !empty($column['width'])) {
1404
+ $width = $column['width'];
1405
+ }
1406
+
1407
+ $top += $shift;
1408
+
1409
+ if ($this->y - $lineSpacing - $shift < self::PAGE_BOTTOM_HEIGHT) {
1410
+ $page = $this->newPage($pageSettings);
1411
+ }
1412
+
1413
+ /**
1414
+ * If the text align is not the default 'left', we need to modify the feed parameter to match the
1415
+ * text's alignment.
1416
+ */
1417
+ if ($textAlign == 'right' && $width) {
1418
+ $feed = $this->getAlignRight($part, $feed, $width, $font, $fontSize);
1419
+ } elseif ($textAlign == 'right') {
1420
+ $feed = $feed - $this->widthForStringUsingFontSize($part, $font, $fontSize);
1421
+ } elseif ($textAlign == 'center') {
1422
+ $feed = $this->getAlignCenter($part, $feed, $width, $font, $fontSize);
1423
+ }
1424
+
1425
+ $page->drawText($part, $feed, ($this->y - $top), 'UTF-8');
1426
+ $top += $lineSpacing;
1427
+ }
1428
+
1429
+ if ($top > $maxHeight) {
1430
+ $maxHeight = $top;
1431
+ }
1432
+
1433
+ return $maxHeight;
1434
+ }
1435
+
1436
+ /**
1437
+ * Sets the page's font for a given column.
1438
+ *
1439
+ * @param Zend_Pdf_Page &$page
1440
+ * @param array $column
1441
+ *
1442
+ * @return array
1443
+ *
1444
+ * @throws Zend_Pdf_Exception
1445
+ */
1446
+ protected function _setLineBlockColumnFont(&$page, $column)
1447
+ {
1448
+ $fontSize = 8;
1449
+ if (isset($column['font_size']) && !empty($column['font_size'])) {
1450
+ $fontSize = $column['font_size'];
1451
+ }
1452
+
1453
+ if (isset($column['font_file']) && !empty($column['font_file'])) {
1454
+ $font = Zend_Pdf_Font::fontWithPath($column['font_file']);
1455
+ $page->setFont($font, $fontSize);
1456
+ } else {
1457
+ $fontStyle = 'regular';
1458
+ if (isset($column['font']) && !empty($column['font'])) {
1459
+ $fontStyle = $column['font'];
1460
+ }
1461
+
1462
+ if ($fontStyle == 'bold') {
1463
+ $font = $this->_setFontBold($page, $fontSize);
1464
+ } elseif ($fontStyle == 'italic') {
1465
+ $font = $this->_setFontItalic($page, $fontSize);
1466
+ } else {
1467
+ $font = $this->_setFontRegular($page, $fontSize);
1468
+ }
1469
+ }
1470
+
1471
+ $fontData = array($font, $fontSize);
1472
+ return $fontData;
1473
+ }
1474
+
1475
+ /**
1476
+ * Create new page and assign to PDF object.
1477
+ *
1478
+ * @param array $settings
1479
+ * @return Zend_Pdf_Page
1480
+ */
1481
+ public function newPage(array $settings = array())
1482
+ {
1483
+ $pageSize = Zend_Pdf_Page::SIZE_A4;
1484
+ if (isset($column['text']) && !empty($settings['page_size'])) {
1485
+ $pageSize = $settings['page_size'];
1486
+ }
1487
+
1488
+ $page = $this->_getPdf()->newPage($pageSize);
1489
+
1490
+ $this->_getPdf()->pages[] = $page;
1491
+ $this->y = self::PAGE_TOP_HEIGHT;
1492
+
1493
+ return $page;
1494
+ }
1495
+ }
app/code/community/TIG/PostNL/Model/Core/Packingslip/Pdf/Items/Invoice/Default.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 array getItemColumns()
40
+ * @method TIG_PostNL_Model_Core_Packingslip_Pdf_Items_Invoice_Default setItemColumns(array $value)
41
+ */
42
+ class TIG_PostNL_Model_Core_Packingslip_Pdf_Items_Invoice_Default extends Mage_Sales_Model_Order_Pdf_Items_Abstract
43
+ {
44
+ /**
45
+ * Draw item line.
46
+ */
47
+ public function draw()
48
+ {
49
+ /**
50
+ * @var Mage_Sales_Model_Order_Invoice_Item $item
51
+ */
52
+ $item = $this->getItem();
53
+ $pdf = $this->getPdf();
54
+ $page = $this->getPage();
55
+ $columns = $this->getItemColumns();
56
+
57
+ $lines = array(
58
+ array()
59
+ );
60
+
61
+ $i = 0;
62
+ $feed = 20;
63
+ $previousFeed = 0;
64
+ $nameFeed = 20;
65
+ foreach ($columns as $column) {
66
+ if ($i > 0) {
67
+ $align = 'right';
68
+ } else {
69
+ $align = 'left';
70
+ }
71
+
72
+ $feed += $previousFeed;
73
+ $previousFeed = $column['width'];
74
+
75
+ /**
76
+ * We need the feed of the name column later to add custom options.
77
+ */
78
+ if ($column['field'] == 'name') {
79
+ $nameFeed = $feed;
80
+ }
81
+
82
+ $value = $this->_getValue($item, $column['field']);
83
+
84
+ $lines[0][] = array(
85
+ 'text' => $value,
86
+ 'feed' => $feed,
87
+ 'align' => $align,
88
+ 'font_size' => 8,
89
+ );
90
+
91
+ $i++;
92
+ }
93
+
94
+ // Custom options
95
+ $options = $this->getItemOptions();
96
+ if ($options) {
97
+ foreach ($options as $option) {
98
+ $optionText = strip_tags($option['label']);
99
+
100
+ if ($option['value']) {
101
+ $printValue = isset($option['print_value'])
102
+ ? $option['print_value']
103
+ : strip_tags($option['value']);
104
+ $value = str_replace(', ', ' - ', $printValue);
105
+ $optionText .= ' - ' . $value;
106
+ }
107
+
108
+ // draw options
109
+ $lines[][] = array(
110
+ 'text' => Mage::helper('core/string')->str_split(strip_tags($optionText), 120, true, true),
111
+ 'font' => 'italic',
112
+ 'feed' => $nameFeed,
113
+ 'font_size' => 7,
114
+ 'shift' => -8,
115
+ );
116
+ }
117
+ }
118
+
119
+ $lineBlock = array(
120
+ 'lines' => $lines,
121
+ 'height' => 20
122
+ );
123
+
124
+ $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
125
+ $this->setPage($page);
126
+ }
127
+
128
+ /**
129
+ * Gets the formatted value for a specified field.
130
+ *
131
+ * @param Mage_Sales_Model_Order_Invoice_Item $item
132
+ * @param string $field
133
+ *
134
+ * @return string
135
+ */
136
+ protected function _getValue(Mage_Sales_Model_Order_Invoice_Item $item, $field)
137
+ {
138
+ switch ($field) {
139
+ case 'name':
140
+ $value = Mage::helper('core/string')->str_split($item->getName(), 60, true, true);
141
+ break;
142
+ case 'sku':
143
+ $value = Mage::helper('core/string')->str_split($this->getSku($item), 25);
144
+ break;
145
+ case 'price':
146
+ $value = $this->getOrder()->formatPriceTxt($item->getPrice());
147
+ break;
148
+ case 'qty':
149
+ $value = $item->getQty() * 1;
150
+ break;
151
+ case 'tax':
152
+ $value = $this->getOrder()->formatPriceTxt($item->getTaxAmount());
153
+ break;
154
+ case 'subtotal':
155
+ $value = $this->getOrder()->formatPriceTxt($item->getRowTotalInclTax());
156
+ break;
157
+ default:
158
+ $value = '';
159
+ break;
160
+ }
161
+
162
+ return $value;
163
+ }
164
+ }
app/code/community/TIG/PostNL/Model/Core/Resource/Order.php CHANGED
@@ -36,8 +36,11 @@
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');
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 TIG_PostNL_Model_Resource_Db_Abstract
40
  {
41
+ /**
42
+ * Initialize PostNL order model.
43
+ */
44
  public function _construct()
45
  {
46
  $this->_init('postnl_core/order', 'entity_id');
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment.php CHANGED
@@ -36,7 +36,7 @@
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
  {
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 TIG_PostNL_Model_Resource_Db_Abstract
40
  {
41
  public function _construct()
42
  {
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode.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_Resource_Shipment_Barcode extends Mage_Core_Model_Resource_Db_Abstract
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_Barcode extends Mage_Core_Model_Resource_Db_Abstract
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode/Collection.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_Resource_Shipment_Barcode_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
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_Barcode_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Collection.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_Resource_Shipment_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
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_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label.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_Resource_Shipment_Label extends Mage_Core_Model_Resource_Db_Abstract
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_Label extends Mage_Core_Model_Resource_Db_Abstract
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label/Collection.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_Resource_Shipment_Label_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
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_Label_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Status/History/Collection.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_Resource_Shipment_Status_History_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
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_Collection extends TIG_PostNL_Model_Resource_Db_Collection_Postnl
app/code/community/TIG/PostNL/Model/Core/Service.php ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Service
40
+ {
41
+ /**
42
+ * Registers an invoice based on a shipment.
43
+ *
44
+ * @param Mage_Sales_Model_Order_Shipment $shipment
45
+ *
46
+ * @return $this
47
+ *
48
+ * @throws TIG_PostNL_Exception
49
+ */
50
+ public function registerInvoiceFromShipment(Mage_Sales_Model_Order_Shipment $shipment)
51
+ {
52
+ /**
53
+ * Create and register the invoice.
54
+ */
55
+ $invoice = $this->initInvoice($shipment);
56
+ if (!$invoice) {
57
+ throw new TIG_PostNL_Exception(
58
+ Mage::helper('postnl')->__(
59
+ 'An error occurred while creating an invoice for this shipment.'
60
+ ),
61
+ 'POSTNL-0166'
62
+ );
63
+ }
64
+
65
+ $invoice->register();
66
+
67
+ $order = $invoice->getOrder();
68
+
69
+ $order->setIsInProcess(true);
70
+
71
+ /**
72
+ * Save all related objects (invoice, order and shipment).
73
+ */
74
+ $transactionSave = Mage::getModel('core/resource_transaction')
75
+ ->addObject($invoice)
76
+ ->addObject($order)
77
+ ->addObject($shipment);
78
+ $transactionSave->save();
79
+
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * Initialize invoice model instance.
85
+ *
86
+ * @param Mage_Sales_Model_Order_Shipment $shipment
87
+ * @param boolean $createDummyInvoice
88
+ *
89
+ * @return Mage_Sales_Model_Order_Invoice
90
+ *
91
+ * @throws TIG_PostNL_Exception
92
+ */
93
+ public function initInvoice(Mage_Sales_Model_Order_Shipment $shipment, $createDummyInvoice = false)
94
+ {
95
+ $order = $shipment->getOrder();
96
+
97
+ /**
98
+ * Check order existing.
99
+ */
100
+ if (!$order->getId()) {
101
+ throw new TIG_PostNL_Exception(
102
+ Mage::helper('postnl')->__('Unable to create an invoice for this shipment due to the order missing.'),
103
+ 'POSTNL-0164'
104
+ );
105
+ }
106
+ /**
107
+ * Check invoice create availability.
108
+ */
109
+ if (!$createDummyInvoice && !$order->canInvoice()) {
110
+ throw new TIG_PostNL_Exception(
111
+ Mage::helper('postnl')->__(
112
+ 'Unable to create an invoice for this shipment because the order cannot be invoiced.'
113
+ ),
114
+ 'POSTNL-0165'
115
+ );
116
+ }
117
+
118
+ /**
119
+ * Get an array of order items and their quantities to invoice.
120
+ */
121
+ $qtys = $this->_getItemQtys($shipment, $createDummyInvoice);
122
+
123
+ /**
124
+ * Create the invoice.
125
+ */
126
+ if (!$createDummyInvoice) {
127
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($qtys);
128
+ } else {
129
+ $invoice = $this->_prepareDummyInvoice($order, $qtys);
130
+ }
131
+
132
+ if (!$invoice->getTotalQty()) {
133
+ throw new TIG_PostNL_Exception(
134
+ Mage::helper('postnl')->__('Cannot create an invoice without products.'),
135
+ 'POSTNL-0162'
136
+ );
137
+ }
138
+
139
+ Mage::unregister('current_invoice');
140
+ Mage::register('current_invoice', $invoice);
141
+ return $invoice;
142
+ }
143
+
144
+ /**
145
+ * Prepares a dummy invoice. This invoice is identical to a regular invoice, except that none of the items will
146
+ * actually be invoiced.
147
+ *
148
+ * @param Mage_Sales_Model_Order $order
149
+ * @param array $qtys
150
+ *
151
+ * @return Mage_Sales_Model_Order_Invoice
152
+ */
153
+ protected function _prepareDummyInvoice($order, $qtys = array())
154
+ {
155
+ $serviceOrder = Mage::getModel('sales/service_order', $order);
156
+ if (method_exists($serviceOrder, 'updateLocaleNumbers')) {
157
+ Mage::getModel('sales/service_order', $order)
158
+ ->updateLocaleNumbers($qtys);
159
+ }
160
+
161
+ $convertor = Mage::getModel('sales/convert_order');
162
+
163
+ $dummyOrder = Mage::getModel('postnl_core/service_orderDummy');
164
+ $dummyOrder->setData($order->getData())
165
+ ->setSubtotalInvoiced(0)
166
+ ->setBaseSubtotalInvoiced(0)
167
+ ->setTaxInvoiced(0)
168
+ ->setHiddenTaxInvoiced(0)
169
+ ->setBaseTaxInvoiced(0)
170
+ ->setBaseHiddenTaxInvoiced(0);
171
+
172
+ $invoice = Mage::getModel('postnl_core/service_invoiceDummy');
173
+ $invoice->setOrder($dummyOrder)
174
+ ->setStoreId($dummyOrder->getStoreId())
175
+ ->setCustomerId($dummyOrder->getCustomerId())
176
+ ->setBillingAddressId($dummyOrder->getBillingAddressId())
177
+ ->setShippingAddressId($dummyOrder->getShippingAddressId());
178
+
179
+ Mage::helper('core')->copyFieldset('sales_convert_order', 'to_invoice', $order, $invoice);
180
+
181
+ /**
182
+ * @var Mage_Sales_Model_Order_Item $orderItem
183
+ */
184
+ $totalQty = 0;
185
+ foreach ($order->getAllItems() as $orderItem) {
186
+ $item = $convertor->itemToInvoiceItem($orderItem);
187
+
188
+ $qty = 0;
189
+ if ($orderItem->isDummy()) {
190
+ $qty = $orderItem->getQtyOrdered() ? $orderItem->getQtyOrdered() : 1;
191
+ } else if (!empty($qtys)) {
192
+ if (isset($qtys[$orderItem->getId()])) {
193
+ $qty = (float) $qtys[$orderItem->getId()];
194
+ }
195
+ } else {
196
+ $qty = $orderItem->getQtyToInvoice();
197
+ }
198
+
199
+ $orderItem->setQtyInvoiced(0)
200
+ ->setRowInvoiced(0)
201
+ ->setBaseRowInvoiced(0);
202
+
203
+ $totalQty += $qty;
204
+ $item->setData('qty', $qty);
205
+ $invoice->addItem($item);
206
+ }
207
+
208
+ $invoice->setTotalQty($totalQty);
209
+
210
+ $invoice->collectTotals();
211
+
212
+ return $invoice;
213
+ }
214
+
215
+ /**
216
+ * Get an array of order items and quantities that should be invoiced.
217
+ *
218
+ * @param Mage_Sales_Model_Order_Shipment $shipment
219
+ * @param boolean $createDummyInvoice
220
+ *
221
+ * @return array
222
+ *
223
+ * @throws TIG_PostNL_Exception
224
+ */
225
+ protected function _getItemQtys(Mage_Sales_Model_Order_Shipment $shipment, $createDummyInvoice = false)
226
+ {
227
+ $shipmentItems = $shipment->getAllItems();
228
+ $qtys = array();
229
+
230
+ /**
231
+ * @var Mage_Sales_Model_Order_Shipment_Item $item
232
+ */
233
+ foreach ($shipmentItems as $item) {
234
+ if (!$createDummyInvoice && !$item->getOrderItem()->canInvoice()) {
235
+ throw new TIG_PostNL_Exception(
236
+ Mage::helper('postnl')->__('Order item #%s could not be invoiced.', $item->getOrderItemId()),
237
+ 'POSTNL-0163'
238
+ );
239
+ }
240
+
241
+ $qtys[$item->getOrderItemId()] = $item->getQty();
242
+ }
243
+
244
+ return $qtys;
245
+ }
246
+ }
app/code/community/TIG/PostNL/Model/Core/Service/InvoiceDummy.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Service_InvoiceDummy extends Mage_Sales_Model_Order_Invoice
40
+ {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_dummy_invoice';
45
+
46
+ /**
47
+ * Overloaded save method to prevent the invoice from being accidentally saved.
48
+ *
49
+ * @return bool|Mage_Core_Model_Abstract
50
+ */
51
+ public function save()
52
+ {
53
+ return false;
54
+ }
55
+ }
app/code/community/TIG/PostNL/Model/Core/Service/OrderDummy.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Service_OrderDummy extends Mage_Sales_Model_Order
40
+ {
41
+ /**
42
+ * @var string
43
+ */
44
+ protected $_eventPrefix = 'postnl_dummy_order';
45
+
46
+ /**
47
+ * Overloaded getId() method to prevent other objects from being loaded that are linked to this dummy order.
48
+ *
49
+ * @return mixed|null
50
+ */
51
+ public function getId()
52
+ {
53
+ return null;
54
+ }
55
+
56
+ /**
57
+ * Overloaded save method to prevent the order from being accidentally saved.
58
+ *
59
+ * @return bool|Mage_Core_Model_Abstract
60
+ */
61
+ public function save()
62
+ {
63
+ return false;
64
+ }
65
+ }
app/code/community/TIG/PostNL/Model/Core/Shipment.php CHANGED
@@ -56,6 +56,9 @@
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
@@ -67,7 +70,6 @@
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()
@@ -81,10 +83,10 @@
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)
@@ -108,6 +110,14 @@
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()
@@ -123,16 +133,16 @@
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
  */
@@ -144,6 +154,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
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.
@@ -154,16 +165,38 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
154
  const SHIPPING_PHASE_DELIVERED = '4';
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';
@@ -206,6 +239,13 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
206
  */
207
  const ADDRESS_TYPE_PAKJEGEMAK = 'pakje_gemak';
208
 
 
 
 
 
 
 
 
209
  /**
210
  * Array of product codes that have extra cover.
211
  *
@@ -238,6 +278,20 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
238
  */
239
  protected $_process;
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  /**
242
  * Initialize the shipment
243
  */
@@ -251,18 +305,27 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
251
  ******************************************************************************************************************/
252
 
253
  /**
254
- * Retrieves a Mage_Sales_Model_Order_Shipment entity linked to the postnl shipment.
 
 
 
 
255
  *
256
- * @return Mage_Sales_Model_Order_Shipment | null
257
  */
258
- public function getShipment()
259
  {
260
  if ($this->hasShipment()) {
261
  return $this->_getData('shipment');
262
  }
263
 
264
  $shipmentId = $this->getShipmentId();
265
- if (!$shipmentId) {
 
 
 
 
 
266
  return null;
267
  }
268
 
@@ -275,6 +338,48 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
275
  return $shipment;
276
  }
277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  /**
279
  * Retrieves the linked Shipment's shipping address
280
  *
@@ -286,8 +391,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
286
  return $this->_getData('shipping_address');
287
  }
288
 
289
- $shipmentId = $this->getShipmentId();
290
- if (!$shipmentId && !$this->getShipment()) {
291
  return null;
292
  }
293
 
@@ -308,15 +412,15 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
308
  return $this->_getData('pakje_gemak_address');
309
  }
310
 
311
- $shipmentId = $this->getShipmentId();
312
- if (!$shipmentId && !$this->getShipment()) {
313
  return null;
314
  }
315
 
316
  /**
317
  * @var Mage_Sales_Model_Order_Address $address
318
  */
319
- $addresses = $this->getShipment()->getOrder()->getAddressesCollection();
320
  foreach ($addresses as $address) {
321
  if ($address->getAddressType() == self::ADDRESS_TYPE_PAKJEGEMAK) {
322
  $this->setPakjeGemakAddress($address);
@@ -340,7 +444,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
340
  return $this->_getData('store_id');
341
  }
342
 
343
- if ($this->getShipment()) {
344
  $storeId = $this->getShipment()->getStoreId();
345
 
346
  $this->setStoreId($storeId);
@@ -360,11 +464,11 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
360
  */
361
  public function getOrderId()
362
  {
363
- if ($this->hasOrderId()) {
364
  return $this->_getData('order_id');
365
  }
366
 
367
- $shipment = $this->getShipment();
368
  if (!$shipment || !$shipment->getOrderId()) {
369
  return null;
370
  }
@@ -375,14 +479,49 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
375
  return $orderId;
376
  }
377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
  /**
379
  * Gets a PostNL helper object
380
  *
381
  * @param string $type
382
  *
383
- * @return TIG_PostNL_Helper_Data|TIG_PostNL_Helper_Cif|TIG_PostNL_Helper_Carrier|TIG_PostNL_Helper_Checkout
384
- * |TIG_PostNL_Helper_AddressValidation|TIG_PostNL_Helper_DeliveryOptions|TIG_PostNL_Helper_Parcelware
385
- * |TIG_PostNL_Helper_Webservices|TIG_PostNL_Helper_Mijnpakket
386
  */
387
  public function getHelper($type = 'data')
388
  {
@@ -437,6 +576,23 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
437
  return $this->_extraCoverProductCodes;
438
  }
439
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
440
  /**
441
  * Get this shipment's product code. If no code is available, generate the code.
442
  *
@@ -455,12 +611,162 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
455
  }
456
 
457
  /**
458
- * gets all shipping labels associated with this shipment
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  *
460
  * @return array Array of TIG_PostNL_Model_Core_Shipment_Label objects
461
  */
462
  public function getLabels()
463
  {
 
 
 
 
464
  $labelCollection = Mage::getResourceModel('postnl_core/shipment_label_collection');
465
  $labelCollection->addFieldToFilter('parent_id', array('eq' => $this->getid()));
466
 
@@ -474,6 +780,8 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
474
  }
475
 
476
  $labels = $labelCollection->getItems();
 
 
477
  return $labels;
478
  }
479
 
@@ -526,7 +834,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
526
  *
527
  * @var TIG_PostNL_Helper_Cif $helper
528
  */
529
- $helper = $this->getHelper('cif');
530
  $weight = $helper->standardizeWeight(
531
  $weight,
532
  $this->getStoreId(),
@@ -550,7 +858,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
550
  /**
551
  * Check if this PostNL shipment has a linked Mage_Sales_Model_Order_Shipment object
552
  */
553
- $shipment = $this->getShipment();
554
  if (!$shipment) {
555
  return null;
556
  }
@@ -584,7 +892,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
584
  }
585
 
586
  /**
587
- * Gets the url for this shipment's main barcode
588
  *
589
  * @param boolean $forceNl
590
  *
@@ -611,7 +919,16 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
611
  $locale = Mage::getStoreConfig('general/locale/code', $this->getStoreId());
612
  $lang = substr($locale, 0, 2);
613
 
614
- $url = $helper->getBarcodeUrl($barcode, $this->getShippingAddress(), $lang, $forceNl);
 
 
 
 
 
 
 
 
 
615
 
616
  $this->setBarcodeUrl($url);
617
  return $url;
@@ -642,54 +959,73 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
642
  }
643
 
644
  /**
645
- * Gets the default product code for this shipment from the module's configuration
 
 
646
  *
647
  * @return string
648
  */
649
  public function getDefaultProductCode()
650
  {
 
 
 
 
651
  $storeId = $this->getStoreId();
652
 
 
 
653
  $xpath = false;
654
- if ($this->isPgeShipment()) {
655
- /**
656
- * PakjeGemak Express default option
657
- */
658
- $xpath = self::XPATH_DEFAULT_PGE_PRODUCT_OPTION;
659
- } elseif ($this->isAvondshipment()) {
660
- /**
661
- * Evening delivery default option
662
- */
663
- $xpath = self::XPATH_DEFAULT_EVENING_PRODUCT_OPTION;
664
- } elseif ($this->isPakjeGemakShipment()) {
665
- /**
666
- * PakjeGemak default option
667
- */
668
- $xpath = self::XPATH_DEFAULT_PAKJEGEMAK_PRODUCT_OPTION;
669
- } elseif ($this->isPakketautomaatShipment()) {
670
- /**
671
- * PakjeGemak default option
672
- */
673
- $xpath = self::XPATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION;
674
- } elseif ($this->isEuShipment()) {
675
- /**
676
- * EU default option
677
- */
678
- $xpath = self::XPATH_DEFAULT_EU_PRODUCT_OPTION;
679
- } elseif ($this->isGlobalShipment()) {
680
- /**
681
- * Global default option
682
- */
683
- $xpath = self::XPATH_DEFAULT_GLOBAL_PRODUCT_OPTION;
 
 
 
 
 
 
 
 
 
 
 
 
 
684
  }
685
 
686
  /**
687
  * If the shipment is not EU or global, it's dutch (AKA a 'standard' shipment)
688
- */
689
-
690
- /**
691
- * Dutch shipments may use an alternative default option when the shipment's base grandtotal exceeds a specified
692
- * amount.
693
  */
694
  $useAlternativeDefault = Mage::getStoreConfig(self::XPATH_USE_ALTERNATIVE_DEFAULT, $storeId);
695
  if (!$xpath && $useAlternativeDefault) {
@@ -713,11 +1049,77 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
713
  * standard default option
714
  */
715
  $productCode = Mage::getStoreConfig($xpath, $storeId);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
716
  $this->_checkProductCodeAllowed($productCode);
717
 
 
718
  return $productCode;
719
  }
720
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
721
  /**
722
  * Get a specific barcode for this shipment
723
  *
@@ -830,57 +1232,73 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
830
  * Gets allowed product codes for the current shipment.
831
  *
832
  * @return array
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
833
  *
834
  * @throws TIG_PostNL_Exception
835
  */
836
- public function getAllowedProductCodes()
837
  {
838
  $cifHelper = $this->getHelper('cif');
839
 
840
- /**
841
- * Please note the order of these checks as PakjeGemak, PakjeGemak Express, avond and pakketautomaat shipment
842
- * would all also be considered Dutch shipments.
843
- */
844
-
845
- if ($this->isPgeShipment()) {
846
- $allowedProductCodes = $cifHelper->getPgeProductCodes();
847
- return $allowedProductCodes;
848
- }
849
-
850
- if ($this->isAvondShipment()) {
851
- $allowedProductCodes = $cifHelper->getAvondProductCodes();
852
- return $allowedProductCodes;
853
- }
854
-
855
- if ($this->isPakjeGemakShipment()) {
856
- $allowedProductCodes = $cifHelper->getPakjeGemakProductCodes();
857
- return $allowedProductCodes;
858
- }
859
-
860
- if ($this->isPakketautomaatShipment()) {
861
- $allowedProductCodes = $cifHelper->getPakketautomaatProductCodes();
862
- return $allowedProductCodes;
863
- }
864
-
865
- if ($this->isDutchShipment()) {
866
- $allowedProductCodes = $cifHelper->getStandardProductCodes();
867
- return $allowedProductCodes;
868
- }
869
-
870
- if ($this->isEuShipment()) {
871
- $allowedProductCodes = $cifHelper->getEuProductCodes();
872
- return $allowedProductCodes;
873
- }
874
-
875
- if ($this->isGlobalShipment() && $cifHelper->isGlobalAllowed()) {
876
- $allowedProductCodes = $cifHelper->getGlobalProductCodes();
877
- return $allowedProductCodes;
878
- }
879
-
880
- /**
881
- * If no matches were found, return an empty array.
882
- */
883
- return array();
884
  }
885
 
886
  /**
@@ -895,7 +1313,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
895
  }
896
 
897
  /**
898
- * Try to get the delivery date fr a PostNL order.
899
  */
900
  $postnlOrder = $this->getPostnlOrder();
901
  if ($postnlOrder && $postnlOrder->getDeliveryDate()) {
@@ -905,12 +1323,51 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
905
  return $deliveryDate;
906
  }
907
 
 
 
 
 
 
 
 
 
 
 
908
  /**
909
  * If no delivery date is available, return null.
910
  */
911
  return null;
912
  }
913
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
914
  /*******************************************************************************************************************
915
  * SETTER METHODS
916
  ******************************************************************************************************************/
@@ -1057,9 +1514,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1057
  */
1058
  $postnlOrder = $this->getPostnlOrder();
1059
  if ($postnlOrder && $postnlOrder->getConfirmDate()) {
1060
- $confirmDate = strtotime($postnlOrder->getConfirmDate());
1061
 
1062
- $this->setData('confirm_date', $confirmDate);
1063
  return $this;
1064
  }
1065
 
@@ -1081,13 +1538,50 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1081
  /**
1082
  * Calculate the confirm based on the delivery date.
1083
  */
1084
- $deliveryTimeStamp = strtotime($deliveryDate);
1085
- $confirmDate = strtotime('-1 day', $deliveryTimeStamp);
1086
 
1087
  $this->setData('confirm_date', $confirmDate);
1088
  return $this;
1089
  }
1090
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1091
  /*******************************************************************************************************************
1092
  * HAS- METHODS
1093
  ******************************************************************************************************************/
@@ -1095,10 +1589,20 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1095
  /**
1096
  * Check if the shipment has any associated labels
1097
  *
 
 
1098
  * @return boolean
1099
  */
1100
- public function hasLabels()
1101
  {
 
 
 
 
 
 
 
 
1102
  $labelCollection = Mage::getResourceModel('postnl_core/shipment_label_collection');
1103
  $labelCollection->addFieldToFilter('parent_id', array('eq' => $this->getid()));
1104
 
@@ -1159,6 +1663,25 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1159
  return true;
1160
  }
1161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1162
  /*******************************************************************************************************************
1163
  * IS- AND CAN- METHODS
1164
  ******************************************************************************************************************/
@@ -1186,7 +1709,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1186
  return true;
1187
  }
1188
 
1189
- $shippingDestination = $this->getShippingAddress()->getCountryId();
 
 
 
 
 
1190
 
1191
  if ($shippingDestination == 'NL') {
1192
  return true;
@@ -1206,7 +1734,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1206
  return true;
1207
  }
1208
 
1209
- $shippingDestination = $this->getShippingAddress()->getCountryId();
 
 
 
 
 
1210
 
1211
  /**
1212
  * @var TIG_PostNL_Helper_Cif $helper
@@ -1294,7 +1827,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1294
  }
1295
 
1296
  /**
1297
- * Check if the currrent shipment is a PakjeGemak shipment.
1298
  *
1299
  * @return boolean
1300
  */
@@ -1368,14 +1901,42 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1368
  }
1369
 
1370
  /**
1371
- * Checks if this shipment is a COD shipment
1372
  *
1373
  * @return boolean
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1374
  *
1375
- * @todo implement this method
1376
  */
1377
  public function isCod()
1378
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
1379
  return false;
1380
  }
1381
 
@@ -1423,7 +1984,33 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1423
  */
1424
  public function canGenerateBarcode()
1425
  {
1426
- if (!$this->getShipmentId() && !$this->getShipment()) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1427
  return false;
1428
  }
1429
 
@@ -1447,7 +2034,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1447
  return false;
1448
  }
1449
 
1450
- if (!$this->getShipmentId() && !$this->getShipment()) {
1451
  return false;
1452
  }
1453
 
@@ -1462,13 +2049,17 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1462
  return false;
1463
  }
1464
 
 
 
 
 
1465
  return true;
1466
  }
1467
 
1468
  /**
1469
  * Checks if the current shipment is eligible for a shipping status update.
1470
  * Unconfirmed shipments, shipments whose labels are not yet printed or shipments that are already delivered are
1471
- * ineligible.
1472
  *
1473
  * @return boolean
1474
  */
@@ -1490,11 +2081,174 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1490
  return false;
1491
  }
1492
 
1493
- if (!$this->hasLabels()) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1494
  return false;
1495
  }
1496
 
1497
- if (!$this->getMainBarcode()) {
1498
  return false;
1499
  }
1500
 
@@ -1502,61 +2256,43 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1502
  }
1503
 
1504
  /**
1505
- * Checks if the current shipment is eligible for a complete shipping status update.
1506
- * For now the same conditions apply as a regular status update. This may change in a future update of the
1507
- * extension.
1508
- *
1509
- * @return boolean
1510
- *
1511
- * @see TIG_PostNL_Model_Core_Shipment::canUpdateShippingStatus()
1512
- */
1513
- public function canUpdateCompleteShippingStatus()
1514
- {
1515
- return $this->canUpdateShippingStatus();
1516
- }
1517
-
1518
- /**
1519
- * Checks if the current shipment can send a track & trace email to the customer.
1520
- *
1521
- * @param boolean $ignoreAlreadySent Flag to ignore the 'already sent' check
1522
- * @param boolean $ignoreConfig Flag to ignore the 'send_track_and_trace_email' config setting.
1523
  *
1524
- * @return boolean
1525
  */
1526
- public function canSendTrackAndTraceEmail($ignoreAlreadySent = false, $ignoreConfig = false)
1527
  {
1528
- if ($this->isLocked()) {
 
1529
  return false;
1530
  }
1531
 
1532
- if ($ignoreAlreadySent !== true && $this->getTrackAndTraceEmailSent()) {
 
 
 
 
 
1533
  return false;
1534
  }
1535
 
1536
- if ($ignoreConfig !== true) {
1537
- $storeId = $this->getStoreId();
1538
- $canSendTrackAndTrace = Mage::getStoreConfig(self::XPATH_SEND_TRACK_AND_TRACE_EMAIL, $storeId);
1539
- if (!$canSendTrackAndTrace) {
1540
- return false;
1541
- }
1542
  }
1543
 
1544
  return true;
1545
  }
1546
 
1547
  /**
1548
- * Checks if this shipment's confirmation status can be reset.
 
 
1549
  *
1550
  * @return boolean
1551
  */
1552
- public function canResetConfirmation()
1553
  {
1554
- $confirmStatus = $this->getConfirmStatus();
1555
- if ($confirmStatus == self::CONFIRM_STATUS_CONFIRM_EXPIRED) {
1556
- return false;
1557
- }
1558
-
1559
- if ($confirmStatus == self::CONFIRM_STATUS_UNCONFIRMED) {
1560
  return false;
1561
  }
1562
 
@@ -1569,7 +2305,30 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1569
  return false;
1570
  }
1571
 
1572
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1573
  }
1574
 
1575
  /*******************************************************************************************************************
@@ -1586,7 +2345,6 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1586
  $process = $this->getProcess();
1587
  $process->lockAndBlock();
1588
 
1589
- $this->isLocked();
1590
  $this->isLocked();
1591
  return $this;
1592
  }
@@ -1644,7 +2402,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1644
  Mage::dispatchEvent('postnl_shipment_generatebarcode_before', array('shipment' => $this));
1645
 
1646
  /**
1647
- * Generate and save the main barcode
1648
  */
1649
  $mainBarcode = $this->_generateBarcode();
1650
  $this->setMainBarcode($mainBarcode);
@@ -1655,7 +2413,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1655
  }
1656
 
1657
  /**
1658
- * If this shipment consists of a single parcel we only need the main barcode
1659
  */
1660
  if ($parcelCount < 2) {
1661
  Mage::dispatchEvent('postnl_shipment_generatebarcode_after', array('shipment' => $this));
@@ -1665,7 +2423,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1665
  }
1666
 
1667
  /**
1668
- * Generate a barcode for each parcel and save it
1669
  */
1670
  for ($i = 1; $i < $parcelCount; $i++) {
1671
  $barcode = $this->_generateBarcode();
@@ -1730,7 +2488,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1730
 
1731
  Mage::dispatchEvent('postnl_shipment_generatelabel_before', array('shipment' => $this));
1732
 
1733
- $parcelCount = $this->getparcelCount();
1734
  if (!$parcelCount) {
1735
  $parcelCount = $this->_calculateParcelCount();
1736
  }
@@ -1870,7 +2628,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1870
 
1871
  Mage::dispatchEvent('postnl_shipment_confirm_before', array('shipment' => $this));
1872
 
1873
- $parcelCount = $this->getparcelCount();
1874
  if (!$parcelCount) {
1875
  $parcelCount = $this->_calculateParcelCount();
1876
  }
@@ -1993,7 +2751,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
1993
  Mage::dispatchEvent('postnl_shipment_confirm_before', array('shipment' => $this));
1994
  Mage::dispatchEvent('postnl_shipment_confirmandgeneratelabel_before', array('shipment' => $this));
1995
 
1996
- $parcelCount = $this->getparcelCount();
1997
  if (!$parcelCount) {
1998
  $parcelCount = $this->_calculateParcelCount();
1999
  }
@@ -2075,7 +2833,15 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2075
  return $this;
2076
  }
2077
 
 
 
 
 
2078
  $this->setShippingPhase($currentPhase);
 
 
 
 
2079
 
2080
  Mage::dispatchEvent('postnl_shipment_updateshippingstatus_after', array('shipment' => $this));
2081
 
@@ -2115,7 +2881,15 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2115
  * Update the shipment's shipping phase
2116
  */
2117
  $currentPhase = $result->Status->CurrentPhaseCode;
 
 
 
 
2118
  $this->setShippingPhase($currentPhase);
 
 
 
 
2119
 
2120
  if (!isset($result->Events->CompleteStatusResponseEvent)) {
2121
  $this->unlock();
@@ -2184,6 +2958,13 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2184
  */
2185
  public function addTrackingCodeToShipment()
2186
  {
 
 
 
 
 
 
 
2187
  $shipment = $this->getShipment();
2188
  $barcode = $this->getMainBarcode();
2189
 
@@ -2401,6 +3182,10 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2401
  ->setLabel(base64_encode($label->Content))
2402
  ->setLabelType($labelType);
2403
 
 
 
 
 
2404
  $this->_addLabelToSave($postnlLabel);
2405
 
2406
  return $this;
@@ -2532,36 +3317,154 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2532
  return array_values($sortedHistory);
2533
  }
2534
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2535
  /*******************************************************************************************************************
2536
  * PRODUCT CODE METHODS
2537
  ******************************************************************************************************************/
2538
 
2539
  /**
2540
- * Gets the product code for this shipment. If specific options have been selected
2541
- * those will be used. Otherwise the default options will be used from system/config
2542
  *
2543
  * @return int
2544
  */
2545
  protected function _getProductCode()
2546
  {
2547
  /**
2548
- * Product options were set manually by the user
2549
  */
2550
  if (Mage::registry('postnl_product_option')) {
2551
  $productCode = Mage::registry('postnl_product_option');
 
 
 
 
 
2552
  $this->_checkProductCodeAllowed($productCode);
2553
 
2554
  return $productCode;
2555
  }
2556
 
2557
  /**
2558
- * Use default options
2559
  */
2560
  $productCode = $this->getDefaultProductCode();
2561
 
2562
  return $productCode;
2563
  }
2564
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2565
  /**
2566
  * Checks if a given product code is allowed for the current shipments. Throws an exception if not.
2567
  *
@@ -2580,7 +3483,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2580
  $allowedProductCodes = $this->getAllowedProductCodes();
2581
 
2582
  /**
2583
- * Check if the product code is allowed
2584
  */
2585
  if (!in_array($productCode, $allowedProductCodes)) {
2586
  throw new TIG_PostNL_Exception(
@@ -2590,7 +3493,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2590
  }
2591
 
2592
  /**
2593
- * Check if the product code is restricted to certain countries
2594
  */
2595
  $allowedCountries = $this->_isCodeRestricted($productCode);
2596
  if ($allowedCountries === false) {
@@ -2598,10 +3501,12 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2598
  }
2599
 
2600
  /**
2601
- * Check if the destination country of this shipment is allowed
2602
  */
2603
- $destination = $this->getShippingAddress()->getCountryId();
2604
- if (!in_array($destination, $allowedCountries)) {
 
 
2605
  throw new TIG_PostNL_Exception(
2606
  $cifHelper->__('Product code %s is not allowed for this shipment.', $productCode),
2607
  'POSTNL-0078'
@@ -2612,7 +3517,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2612
  }
2613
 
2614
  /**
2615
- * Checks if a given product code is only allowed for a specific country
2616
  *
2617
  * @param $code
2618
  *
@@ -2693,9 +3598,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2693
  protected function _calculateParcelCount()
2694
  {
2695
  /**
2696
- * Only NL shipments support multi-colli shipments
2697
  */
2698
- if (!$this->isDutchShipment()) {
2699
  return 1;
2700
  }
2701
 
@@ -2709,7 +3614,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2709
  *
2710
  * @var TIG_PostNL_Helper_Cif $helper
2711
  */
2712
- $helper = $this->getHelper('cif');
2713
  $weightPerParcel = Mage::getStoreConfig(self::XPATH_WEIGHT_PER_PARCEL, $this->getStoreId());
2714
  $weightPerParcel = $helper->standardizeWeight($weightPerParcel, $this->getStoreId());
2715
 
@@ -2721,6 +3626,99 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2721
  return $parcelCount;
2722
  }
2723
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2724
  /*******************************************************************************************************************
2725
  * RESET AND DELETE METHODS
2726
  ******************************************************************************************************************/
@@ -2735,10 +3733,17 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2735
  */
2736
  public function resetConfirmation($deleteLabels = true, $deleteTracks = true)
2737
  {
2738
- $this->setConfirmStatus(self::CONFIRM_STATUS_UNCONFIRMED) //set status to unconfirmed
 
 
 
 
 
 
2739
  ->setShippingPhase(false) //delete current shipping phase
2740
- ->setConfirmedAt(false) //delete 'confirmed at' date
2741
- ->deleteBarcodes() //delete all associated barcodes
 
2742
  ->deleteStatusHistory(); //delete all associated status history items
2743
 
2744
 
@@ -2764,6 +3769,10 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2764
  {
2765
  $shipment = $this->getShipment();
2766
 
 
 
 
 
2767
  /**
2768
  * @var Mage_Sales_Model_Order_Shipment_Track $track
2769
  */
@@ -2818,7 +3827,7 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2818
  }
2819
 
2820
  /**
2821
- * Deletes all status history items associated with this shipment
2822
  *
2823
  * @return $this
2824
  */
@@ -2838,7 +3847,30 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2838
  }
2839
 
2840
  /*******************************************************************************************************************
2841
- * BEFORE- AND AFTERSAVE METHODS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2842
  ******************************************************************************************************************/
2843
 
2844
  /**
@@ -2864,7 +3896,9 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2864
  /**
2865
  * Set confirm status.
2866
  */
2867
- if ($this->getConfirmStatus() === null) {
 
 
2868
  $this->setConfirmStatus(self::CONFIRM_STATUS_UNCONFIRMED);
2869
  }
2870
 
@@ -2908,17 +3942,28 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
2908
  }
2909
 
2910
  /**
2911
- * If this shipment is new, set it's created at date to the current timestamp.
2912
  */
2913
- if (!$this->getId()) {
2914
- $this->setCreatedAt($currentTimestamp);
2915
  }
2916
 
2917
- /**
2918
- * Always update the updated at timestamp to the current timestamp.
2919
- */
2920
- $this->setUpdatedAt($currentTimestamp);
2921
-
2922
  return parent::_beforeSave();
2923
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2924
  }
56
  * - postnl_shipment_updateshippingstatus_after
57
  * - postnl_shipment_updatecompleteshippingstatus_before
58
  * - postnl_shipment_updatecompleteshippingstatus_after
59
+ * - postnl_shipment_updateshippingphase_before
60
+ * - postnl_shipment_updateshippingphase_after
61
+ * - postnl_shipment_setshippingphase_*
62
  * - postnl_shipment_savelabels_before
63
  * - postnl_shipment_savelabels_after
64
  * - postnl_shipment_saveadditionaloptions_after
70
  * @method string|null getConfirmedStatus
71
  * @method string getStatusHistoryUpdatedAt()
72
  * @method string getConfirmStatus()
 
73
  * @method string getCreatedAt()
74
  * @method int getIsPakjeGemak()
75
  * @method string getConfirmDate()
83
  * @method int|null getShipmentId
84
  * @method int getLabelsPrinted()
85
  * @method bool|int getIsPakketautomaat()
86
+ * @method bool getIsBuspakjeShipment()
87
  *
88
  * @method TIG_PostNL_Model_Core_Shipment setLabelsPrinted(int $value)
89
  * @method TIG_PostNL_Model_Core_Shipment setTreatAsAbandoned(int $value)
 
90
  * @method TIG_PostNL_Model_Core_Shipment setTrackAndTraceEmailSent(int $value)
91
  * @method TIG_PostNL_Model_Core_Shipment setIsParcelwareExported(int $value)
92
  * @method TIG_PostNL_Model_Core_Shipment setEntityId(int $value)
110
  * @method TIG_PostNL_Model_Core_Shipment setLabelCollection(TIG_PostNL_Model_Core_Resource_Shipment_LabeL_Collection $value)
111
  * @method TIG_PostNL_Model_Core_Shipment setDeliveryDate(string $value)
112
  * @method TIG_PostNL_Model_Core_Shipment setIsPakketautomaat(bool $value)
113
+ * @method TIG_PostNL_Model_Core_Shipment setShipmentType(string $value)
114
+ * @method TIG_PostNL_Model_Core_Shipment setOrder(Mage_Sales_Model_Order $value)
115
+ * @method TIG_PostNL_Model_Core_Shipment setIsBuspakje(int $value)
116
+ * @method TIG_PostNL_Model_Core_Shipment setShipmentIncrementId(string $value)
117
+ * @method TIG_PostNL_Model_Core_Shipment setIsBuspakjeShipment(bool $value)
118
+ * @method TIG_PostNL_Model_Core_Shipment setDefaultProductCode(string $value)
119
+ * @method TIG_PostNL_Model_Core_Shipment setLabels(array $value)
120
+ * @method TIG_PostNL_Model_Core_Shipment setProductOption(string $value)
121
  *
122
  * @method bool hasBarcodeUrl()
123
  * @method bool hasPostnlOrder()
133
  * @method bool hasLabelCollection()
134
  * @method bool hasIsPakketautomaat()
135
  * @method bool hasDeliveryDate()
136
+ * @method bool hasShipmentType()
137
+ * @method bool hasOrder()
138
+ * @method bool hasMainBarcode()
139
+ * @method bool hasShipmentIncrementId()
140
+ * @method bool hasIsBuspakjeShipment()
141
+ * @method bool hasDefaultProductCode()
142
+ * @method bool hasProductOption()
143
  */
144
  class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
145
  {
 
 
 
 
 
 
 
146
  /**
147
  * Carrier code used by postnl.
148
  */
154
  const CONFIRM_STATUS_CONFIRMED = 'confirmed';
155
  const CONFIRM_STATUS_UNCONFIRMED = 'unconfirmed';
156
  const CONFIRM_STATUS_CONFIRM_EXPIRED = 'confirm_expired';
157
+ const CONFIRM_STATUS_BUSPAKJE = 'buspakje';
158
 
159
  /**
160
  * Possible shipping phases.
165
  const SHIPPING_PHASE_DELIVERED = '4';
166
  const SHIPPING_PHASE_NOT_APPLICABLE = '99';
167
 
168
+ /**
169
+ * Possible shipment types.
170
+ */
171
+ const SHIPMENT_TYPE_DOMESTIC = 'domestic';
172
+ const SHIPMENT_TYPE_DOMESTIC_COD = 'domestic_cod';
173
+ const SHIPMENT_TYPE_AVOND = 'avond';
174
+ const SHIPMENT_TYPE_AVOND_COD = 'avond_cod';
175
+ const SHIPMENT_TYPE_PG = 'pg';
176
+ const SHIPMENT_TYPE_PG_COD = 'pg_cod';
177
+ const SHIPMENT_TYPE_PGE = 'pge';
178
+ const SHIPMENT_TYPE_PGE_COD = 'pge_cod';
179
+ const SHIPMENT_TYPE_PA = 'pa';
180
+ const SHIPMENT_TYPE_EPS = 'eps';
181
+ const SHIPMENT_TYPE_GLOBALPACK = 'globalpack';
182
+ const SHIPMENT_TYPE_BUSPAKJE = 'buspakje';
183
+
184
  /**
185
  * Xpaths to default product options settings.
186
  */
187
  const XPATH_DEFAULT_STANDARD_PRODUCT_OPTION = 'postnl/cif_product_options/default_product_option';
188
+ const XPATH_DEFAULT_STANDARD_COD_PRODUCT_OPTION = 'postnl/cif_product_options/default_cod_product_option';
189
  const XPATH_DEFAULT_EVENING_PRODUCT_OPTION = 'postnl/cif_product_options/default_evening_product_option';
190
+ const XPATH_DEFAULT_EVENING_COD_PRODUCT_OPTION = 'postnl/cif_product_options/default_evening_cod_product_option';
191
  const XPATH_DEFAULT_PAKJEGEMAK_PRODUCT_OPTION = 'postnl/cif_product_options/default_pakjegemak_product_option';
192
+ const XPATH_DEFAULT_PAKJEGEMAK_COD_PRODUCT_OPTION = 'postnl/cif_product_options/default_pakjegemak_cod_product_option';
193
  const XPATH_DEFAULT_PGE_PRODUCT_OPTION = 'postnl/cif_product_options/default_pge_product_option';
194
+ const XPATH_DEFAULT_PGE_COD_PRODUCT_OPTION = 'postnl/cif_product_options/default_pge_cod_product_option';
195
  const XPATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION = 'postnl/cif_product_options/default_pakketautomaat_product_option';
196
  const XPATH_DEFAULT_EU_PRODUCT_OPTION = 'postnl/cif_product_options/default_eu_product_option';
197
+ const XPATH_DEFAULT_EU_BE_PRODUCT_OPTION = 'postnl/cif_product_options/default_eu_be_product_option';
198
  const XPATH_DEFAULT_GLOBAL_PRODUCT_OPTION = 'postnl/cif_product_options/default_global_product_option';
199
+ const XPATH_DEFAULT_BUSPAKJE_PRODUCT_OPTION = 'postnl/cif_product_options/default_buspakje_product_option';
200
  const XPATH_USE_ALTERNATIVE_DEFAULT = 'postnl/cif_product_options/use_alternative_default';
201
  const XPATH_ALTERNATIVE_DEFAULT_MAX_AMOUNT = 'postnl/cif_product_options/alternative_default_max_amount';
202
  const XPATH_ALTERNATIVE_DEFAULT_OPTION = 'postnl/cif_product_options/alternative_default_option';
239
  */
240
  const ADDRESS_TYPE_PAKJEGEMAK = 'pakje_gemak';
241
 
242
+ /**
243
+ * Prefix of model events names.
244
+ *
245
+ * @var string
246
+ */
247
+ protected $_eventPrefix = 'postnl_shipment';
248
+
249
  /**
250
  * Array of product codes that have extra cover.
251
  *
278
  */
279
  protected $_process;
280
 
281
+ /**
282
+ * For certain product codes a custom barcode is required.
283
+ *
284
+ * @var array
285
+ */
286
+ protected $_customBarcodes;
287
+
288
+ /**
289
+ * Flag to prevent this shipment from being saved.
290
+ *
291
+ * @var bool
292
+ */
293
+ protected $_preventSaving = false;
294
+
295
  /**
296
  * Initialize the shipment
297
  */
305
  ******************************************************************************************************************/
306
 
307
  /**
308
+ * Retrieves a Mage_Sales_Model_Order_Shipment entity linked to the PostNL shipment.
309
+ *
310
+ * @param boolean $throwException
311
+ *
312
+ * @return Mage_Sales_Model_Order_Shipment|null
313
  *
314
+ * @throws TIG_PostNL_Exception
315
  */
316
+ public function getShipment($throwException = true)
317
  {
318
  if ($this->hasShipment()) {
319
  return $this->_getData('shipment');
320
  }
321
 
322
  $shipmentId = $this->getShipmentId();
323
+ if (!$shipmentId && $throwException) {
324
+ throw new TIG_PostNL_Exception(
325
+ $this->getHelper()->__('No shipment found for PostNL shipment #%d.', $this->getId()),
326
+ 'POSTNL-0176'
327
+ );
328
+ } elseif (!$shipmentId) {
329
  return null;
330
  }
331
 
338
  return $shipment;
339
  }
340
 
341
+ /**
342
+ * Retrieves a Mage_Sales_Model_Order entity linked to this PostNL shipment.
343
+ *
344
+ * @param boolean $throwException
345
+ *
346
+ * @return Mage_Sales_Model_Order|null
347
+ *
348
+ * @throws TIG_PostNL_Exception
349
+ */
350
+ public function getOrder($throwException = true)
351
+ {
352
+ if ($this->hasOrder()) {
353
+ return $this->_getData('order');
354
+ }
355
+
356
+ /**
357
+ * Get the order ID belonging to this PostNL shipment. If no order ID is found, attempt to get it from the
358
+ * Magento shipment.
359
+ */
360
+ $orderId = $this->getOrderId();
361
+ if (!$orderId) {
362
+ $orderId = $this->getShipment()->getOrderId();
363
+ }
364
+
365
+ if (!$orderId && $throwException) {
366
+ throw new TIG_PostNL_Exception(
367
+ $this->getHelper()->__('No order found for PostNL shipment #%d.', $this->getId()),
368
+ 'POSTNL-0177'
369
+ );
370
+ } elseif (!$orderId) {
371
+ return null;
372
+ }
373
+
374
+ /**
375
+ * @var Mage_Sales_Model_Order $order
376
+ */
377
+ $order = Mage::getModel('sales/order')->load($orderId);
378
+
379
+ $this->setOrder($order);
380
+ return $order;
381
+ }
382
+
383
  /**
384
  * Retrieves the linked Shipment's shipping address
385
  *
391
  return $this->_getData('shipping_address');
392
  }
393
 
394
+ if (!$this->getShipment(false)) {
 
395
  return null;
396
  }
397
 
412
  return $this->_getData('pakje_gemak_address');
413
  }
414
 
415
+ $order = $this->getOrder(false);
416
+ if (!$order) {
417
  return null;
418
  }
419
 
420
  /**
421
  * @var Mage_Sales_Model_Order_Address $address
422
  */
423
+ $addresses = $order->getAddressesCollection();
424
  foreach ($addresses as $address) {
425
  if ($address->getAddressType() == self::ADDRESS_TYPE_PAKJEGEMAK) {
426
  $this->setPakjeGemakAddress($address);
444
  return $this->_getData('store_id');
445
  }
446
 
447
+ if ($this->getShipment(false)) {
448
  $storeId = $this->getShipment()->getStoreId();
449
 
450
  $this->setStoreId($storeId);
464
  */
465
  public function getOrderId()
466
  {
467
+ if ($this->hasOrderId() && $this->_getData('order_id')) {
468
  return $this->_getData('order_id');
469
  }
470
 
471
+ $shipment = $this->getShipment(false);
472
  if (!$shipment || !$shipment->getOrderId()) {
473
  return null;
474
  }
479
  return $orderId;
480
  }
481
 
482
+ /**
483
+ * Gets the increment ID of this shipment's Magento shipment if available.
484
+ *
485
+ * @return null|string
486
+ */
487
+ public function getShipmentIncrementId()
488
+ {
489
+ if ($this->hasShipmentIncrementId()) {
490
+ return $this->_getData('shipment_increment_id');
491
+ }
492
+
493
+ $shipment = $this->getShipment(false);
494
+ if (!$shipment || !$shipment->getIncrementId()) {
495
+ return null;
496
+ }
497
+
498
+ $incrementId = $shipment->getIncrementId();
499
+
500
+ $this->setShipmentIncrementId($incrementId);
501
+ return $incrementId;
502
+ }
503
+
504
+ /**
505
+ * Alias for TIG_PostNL_Model_Core_Shipment::getShipmentIncrementId().
506
+ *
507
+ * This method is not used internally. It is only provided for other developers who are used to calling
508
+ * getIncrementId() directly.
509
+ *
510
+ * @return null|string
511
+ */
512
+ public function getIncrementId()
513
+ {
514
+ return $this->getShipmentIncrementId();
515
+ }
516
+
517
  /**
518
  * Gets a PostNL helper object
519
  *
520
  * @param string $type
521
  *
522
+ * @return TIG_PosTNL_Helper_Data|TIG_PosTNL_Helper_Cif|TIG_PosTNL_Helper_Carrier|TIG_PosTNL_Helper_DeliveryOptions
523
+ * |TIG_PosTNL_Helper_AddressValidation|TIG_PosTNL_Helper_Checkout|TIG_PosTNL_Helper_Mijnpakket
524
+ * |TIG_PosTNL_Helper_Parcelware|TIG_PosTNL_Helper_Payment|TIG_PosTNL_Helper_Webservices
525
  */
526
  public function getHelper($type = 'data')
527
  {
576
  return $this->_extraCoverProductCodes;
577
  }
578
 
579
+ /**
580
+ * get an array of all product codes that need a custom barcode.
581
+ *
582
+ * @return array
583
+ */
584
+ public function getCustomBarcodes()
585
+ {
586
+ if ($this->_customBarcodes) {
587
+ return $this->_customBarcodes;
588
+ }
589
+
590
+ $customBarcodes = $this->getHelper()->getCustomBarcodes();
591
+
592
+ $this->_customBarcodes = $customBarcodes;
593
+ return $customBarcodes;
594
+ }
595
+
596
  /**
597
  * Get this shipment's product code. If no code is available, generate the code.
598
  *
611
  }
612
 
613
  /**
614
+ * Get the product option linked to this shipment's product code.
615
+ *
616
+ * @return string|null
617
+ */
618
+ public function getProductOption()
619
+ {
620
+ if ($this->hasProductOption()) {
621
+ return $this->_getData('product_option');
622
+ }
623
+
624
+ /**
625
+ * Get this shipment's product code.
626
+ */
627
+ $productCode = $this->getProductCode();
628
+ if (!$productCode) {
629
+ return null;
630
+ }
631
+
632
+ /**
633
+ * Get all product options.
634
+ */
635
+ $productOptions = Mage::getModel('postnl_core/system_config_source_allProductOptions')
636
+ ->getOptions(array(), true);
637
+
638
+ if (isset($productOptions[$productCode])) {
639
+ $productOption = $productOptions[$productCode];
640
+ } else {
641
+ $productOption = $productCode;
642
+ }
643
+
644
+ $this->setProductOption($productOption);
645
+ return $productOption;
646
+ }
647
+
648
+ /**
649
+ * Get the current shipment's type.
650
+ *
651
+ * @param boolean $checkBuspakje
652
+ *
653
+ * @return string
654
+ */
655
+ public function getShipmentType($checkBuspakje = true)
656
+ {
657
+ if ($this->hasShipmentType()) {
658
+ return $this->_getData('shipment_type');
659
+ }
660
+
661
+ if (!$this->getShipment(false)) {
662
+ return null;
663
+ }
664
+
665
+ $shipmentType = $this->_getShipmentType($checkBuspakje);
666
+
667
+ $this->setShipmentType($shipmentType);
668
+ return $shipmentType;
669
+ }
670
+
671
+ /**
672
+ * Determines the current shipment's shipment type based on several attributes, including shipping destination and
673
+ * payment method.
674
+ *
675
+ * @param boolean $checkBuspakje
676
+ *
677
+ * @return string
678
+ *
679
+ * @throws TIG_PostNL_Exception
680
+ */
681
+ protected function _getShipmentType($checkBuspakje = true)
682
+ {
683
+ if ($this->isCod()) {
684
+ if ($this->isPgeShipment()) {
685
+ return self::SHIPMENT_TYPE_PGE_COD;
686
+ }
687
+
688
+ if ($this->isAvondShipment()) {
689
+ return self::SHIPMENT_TYPE_AVOND_COD;
690
+ }
691
+
692
+ if ($this->isPakjeGemakShipment()) {
693
+ return self::SHIPMENT_TYPE_PG_COD;
694
+ }
695
+
696
+ if ($this->isDutchShipment()) {
697
+ return self::SHIPMENT_TYPE_DOMESTIC_COD;
698
+ }
699
+ }
700
+
701
+ if ($this->isPgeShipment()) {
702
+ return self::SHIPMENT_TYPE_PGE;
703
+ }
704
+
705
+ if ($this->isAvondShipment()) {
706
+ return self::SHIPMENT_TYPE_AVOND;
707
+ }
708
+
709
+ if ($this->isPakjeGemakShipment()) {
710
+ return self::SHIPMENT_TYPE_PG;
711
+ }
712
+
713
+ if ($this->isPakketautomaatShipment()) {
714
+ return self::SHIPMENT_TYPE_PA;
715
+ }
716
+
717
+ if ($checkBuspakje && $this->isBuspakjeShipment()) {
718
+ return self::SHIPMENT_TYPE_BUSPAKJE;
719
+ }
720
+
721
+ if ($this->isDutchShipment()) {
722
+ return self::SHIPMENT_TYPE_DOMESTIC;
723
+ }
724
+
725
+ if ($this->isEuShipment()) {
726
+ return self::SHIPMENT_TYPE_EPS;
727
+ }
728
+
729
+ if ($this->isGlobalShipment() && $this->getHelper('cif')->isGlobalAllowed()) {
730
+ return self::SHIPMENT_TYPE_GLOBALPACK;
731
+ }
732
+
733
+ throw new TIG_PostNL_Exception(
734
+ $this->getHelper()->__('No valid shipment type found for shipment #%s.', $this->getId()),
735
+ 'POSTNL-0167'
736
+ );
737
+ }
738
+
739
+ /**
740
+ * Returns the formatted shipping phase of the current shipment.
741
+ *
742
+ * @return null|string
743
+ */
744
+ public function getFormattedShippingPhase()
745
+ {
746
+ $shippingPhase = $this->getShippingPhase();
747
+ if (!$shippingPhase) {
748
+ return null;
749
+ }
750
+
751
+ $shippingPhases = $this->getHelper('cif')->getShippingPhases();
752
+ if (array_key_exists($shippingPhase, $shippingPhases)) {
753
+ return $shippingPhases[$shippingPhase];
754
+ }
755
+
756
+ return null;
757
+ }
758
+
759
+ /**
760
+ * Gets all shipping labels associated with this shipment
761
  *
762
  * @return array Array of TIG_PostNL_Model_Core_Shipment_Label objects
763
  */
764
  public function getLabels()
765
  {
766
+ if ($this->hasLabels(false)) {
767
+ return $this->_getData('labels');
768
+ }
769
+
770
  $labelCollection = Mage::getResourceModel('postnl_core/shipment_label_collection');
771
  $labelCollection->addFieldToFilter('parent_id', array('eq' => $this->getid()));
772
 
780
  }
781
 
782
  $labels = $labelCollection->getItems();
783
+
784
+ $this->setLabels($labels);
785
  return $labels;
786
  }
787
 
834
  *
835
  * @var TIG_PostNL_Helper_Cif $helper
836
  */
837
+ $helper = $this->getHelper();
838
  $weight = $helper->standardizeWeight(
839
  $weight,
840
  $this->getStoreId(),
858
  /**
859
  * Check if this PostNL shipment has a linked Mage_Sales_Model_Order_Shipment object
860
  */
861
+ $shipment = $this->getShipment(false);
862
  if (!$shipment) {
863
  return null;
864
  }
892
  }
893
 
894
  /**
895
+ * Gets the url for this shipment's main barcode.
896
  *
897
  * @param boolean $forceNl
898
  *
919
  $locale = Mage::getStoreConfig('general/locale/code', $this->getStoreId());
920
  $lang = substr($locale, 0, 2);
921
 
922
+ $url = '';
923
+ $pakjeGemakAddress = $this->getPakjeGemakAddress();
924
+ if ($pakjeGemakAddress) {
925
+ $url = $helper->getBarcodeUrl($barcode, $pakjeGemakAddress, $lang, $forceNl);
926
+ } else {
927
+ $shippingAddress = $this->getShippingAddress();
928
+ if ($shippingAddress) {
929
+ $url = $helper->getBarcodeUrl($barcode, $shippingAddress, $lang, $forceNl);
930
+ }
931
+ }
932
 
933
  $this->setBarcodeUrl($url);
934
  return $url;
959
  }
960
 
961
  /**
962
+ * Gets the default product code for this shipment from the module's configuration.
963
+ *
964
+ * @throws TIG_PostNL_Exception
965
  *
966
  * @return string
967
  */
968
  public function getDefaultProductCode()
969
  {
970
+ if ($this->hasDefaultProductCode()) {
971
+ return $this->_getData('default_product_code');
972
+ }
973
+
974
  $storeId = $this->getStoreId();
975
 
976
+ $shipmentType = $this->getShipmentType();
977
+
978
  $xpath = false;
979
+ switch ($shipmentType) {
980
+ case self::SHIPMENT_TYPE_DOMESTIC_COD:
981
+ $xpath = self::XPATH_DEFAULT_STANDARD_COD_PRODUCT_OPTION;
982
+ break;
983
+ case self::SHIPMENT_TYPE_AVOND:
984
+ $xpath = self::XPATH_DEFAULT_EVENING_PRODUCT_OPTION;
985
+ break;
986
+ case self::SHIPMENT_TYPE_AVOND_COD:
987
+ $xpath = self::XPATH_DEFAULT_EVENING_COD_PRODUCT_OPTION;
988
+ break;
989
+ case self::SHIPMENT_TYPE_PG:
990
+ $xpath = self::XPATH_DEFAULT_PAKJEGEMAK_PRODUCT_OPTION;
991
+ break;
992
+ case self::SHIPMENT_TYPE_PG_COD:
993
+ $xpath = self::XPATH_DEFAULT_PAKJEGEMAK_COD_PRODUCT_OPTION;
994
+ break;
995
+ case self::SHIPMENT_TYPE_PGE:
996
+ $xpath = self::XPATH_DEFAULT_PGE_PRODUCT_OPTION;
997
+ break;
998
+ case self::SHIPMENT_TYPE_PGE_COD:
999
+ $xpath = self::XPATH_DEFAULT_PGE_COD_PRODUCT_OPTION;
1000
+ break;
1001
+ case self::SHIPMENT_TYPE_PA:
1002
+ $xpath = self::XPATH_DEFAULT_PAKKETAUTOMAAT_PRODUCT_OPTION;
1003
+ break;
1004
+ case self::SHIPMENT_TYPE_EPS:
1005
+ $shippingAddress = $this->getShippingAddress();
1006
+ if ($this->getHelper()->canUseEpsBEOnlyOption($this->getStoreId())
1007
+ && $shippingAddress
1008
+ && $shippingAddress->getCountryId() == 'BE'
1009
+ ) {
1010
+ $xpath = self::XPATH_DEFAULT_EU_BE_PRODUCT_OPTION;
1011
+ } else {
1012
+ $xpath = self::XPATH_DEFAULT_EU_PRODUCT_OPTION;
1013
+ }
1014
+ break;
1015
+ case self::SHIPMENT_TYPE_GLOBALPACK:
1016
+ $xpath = self::XPATH_DEFAULT_GLOBAL_PRODUCT_OPTION;
1017
+ break;
1018
+ case self::SHIPMENT_TYPE_BUSPAKJE:
1019
+ $xpath = self::XPATH_DEFAULT_BUSPAKJE_PRODUCT_OPTION;
1020
+ break;
1021
+ //no default
1022
  }
1023
 
1024
  /**
1025
  * If the shipment is not EU or global, it's dutch (AKA a 'standard' shipment)
1026
+ *
1027
+ * Dutch shipments may use an alternative default option when the shipment's base grand total exceeds a
1028
+ * specified amount.
 
 
1029
  */
1030
  $useAlternativeDefault = Mage::getStoreConfig(self::XPATH_USE_ALTERNATIVE_DEFAULT, $storeId);
1031
  if (!$xpath && $useAlternativeDefault) {
1049
  * standard default option
1050
  */
1051
  $productCode = Mage::getStoreConfig($xpath, $storeId);
1052
+
1053
+ /**
1054
+ * If no default product code was found, try to use another product code that is available.
1055
+ */
1056
+ if (!$productCode) {
1057
+ $availableProductCodes = $this->getAllowedProductCodes();
1058
+
1059
+ /**
1060
+ * If no other product codes are available for this shipment type, throw an error.
1061
+ */
1062
+ if (empty($availableProductCodes)) {
1063
+ throw new TIG_PostNL_Exception(
1064
+ $this->getHelper()->__(
1065
+ "No default product options are available for this shipment. Please check that you have " .
1066
+ "correctly configured the available product options in the PostNL extension's configuration."
1067
+ ),
1068
+ 'POSTNL-0188'
1069
+ );
1070
+ }
1071
+
1072
+ $productCode = current($availableProductCodes);
1073
+
1074
+ /**
1075
+ * Add a warning message indicating that another product code was used and that the merchant should probably
1076
+ * check their configuration.
1077
+ *
1078
+ * @var TIG_PostNL_Helper_Data $helper
1079
+ */
1080
+ $helper = $this->getHelper();
1081
+ $helper->addSessionMessage(
1082
+ 'adminhtml',
1083
+ 'POSTNL-0189',
1084
+ 'warning',
1085
+ $helper->__(
1086
+ "The default product option was not available for this shipment, so another product option was " .
1087
+ "chosen. Please check if the default product options are configured correctly in the PostNL " .
1088
+ "extension's configuration."
1089
+ )
1090
+ );
1091
+ }
1092
+
1093
  $this->_checkProductCodeAllowed($productCode);
1094
 
1095
+ $this->setDefaultProductCode($productCode);
1096
  return $productCode;
1097
  }
1098
 
1099
+ /**
1100
+ * Gets this shipment's main barcode.
1101
+ *
1102
+ * @return string|null
1103
+ */
1104
+ public function getMainBarcode()
1105
+ {
1106
+ if ($this->hasMainBarcode()) {
1107
+ return $this->_getData('main_barcode');
1108
+ }
1109
+
1110
+ /**
1111
+ * Check if the current product code needs a custom barcode.
1112
+ */
1113
+ $customBarcodes = $this->getCustomBarcodes();
1114
+ $productCode = $this->getProductCode();
1115
+
1116
+ if (array_key_exists($productCode, $customBarcodes)) {
1117
+ return $customBarcodes[$productCode];
1118
+ }
1119
+
1120
+ return null;
1121
+ }
1122
+
1123
  /**
1124
  * Get a specific barcode for this shipment
1125
  *
1232
  * Gets allowed product codes for the current shipment.
1233
  *
1234
  * @return array
1235
+ */
1236
+ public function getAllowedProductCodes()
1237
+ {
1238
+ $allowedProductOptions = $this->getAllowedProductOptions();
1239
+
1240
+ $productCodes = array_keys($allowedProductOptions);
1241
+ return $productCodes;
1242
+ }
1243
+
1244
+ /**
1245
+ * Gets allowed product options for the current shipment.
1246
+ *
1247
+ * @param boolean $flat
1248
+ * @param boolean $checkBuspakje
1249
+ *
1250
+ * @return array
1251
  *
1252
  * @throws TIG_PostNL_Exception
1253
  */
1254
+ public function getAllowedProductOptions($flat = true, $checkBuspakje = false)
1255
  {
1256
  $cifHelper = $this->getHelper('cif');
1257
 
1258
+ $shipmentType = $this->getShipmentType($checkBuspakje);
1259
+ switch ($shipmentType) {
1260
+ case self::SHIPMENT_TYPE_DOMESTIC:
1261
+ $allowedProductCodes = $cifHelper->getStandardProductCodes($flat);
1262
+ break;
1263
+ case self::SHIPMENT_TYPE_DOMESTIC_COD:
1264
+ $allowedProductCodes = $cifHelper->getStandardCodProductCodes($flat);
1265
+ break;
1266
+ case self::SHIPMENT_TYPE_AVOND:
1267
+ $allowedProductCodes = $cifHelper->getAvondProductCodes($flat);
1268
+ break;
1269
+ case self::SHIPMENT_TYPE_AVOND_COD:
1270
+ $allowedProductCodes = $cifHelper->getAvondCodProductCodes($flat);
1271
+ break;
1272
+ case self::SHIPMENT_TYPE_PG:
1273
+ $allowedProductCodes = $cifHelper->getPakjeGemakProductCodes($flat);
1274
+ break;
1275
+ case self::SHIPMENT_TYPE_PG_COD:
1276
+ $allowedProductCodes = $cifHelper->getPakjeGemakCodProductCodes($flat);
1277
+ break;
1278
+ case self::SHIPMENT_TYPE_PGE:
1279
+ $allowedProductCodes = $cifHelper->getPgeProductCodes($flat);
1280
+ break;
1281
+ case self::SHIPMENT_TYPE_PGE_COD:
1282
+ $allowedProductCodes = $cifHelper->getPgeCodProductCodes($flat);
1283
+ break;
1284
+ case self::SHIPMENT_TYPE_PA:
1285
+ $allowedProductCodes = $cifHelper->getPakketautomaatProductCodes($flat);
1286
+ break;
1287
+ case self::SHIPMENT_TYPE_EPS:
1288
+ $allowedProductCodes = $cifHelper->getEuProductCodes($flat);
1289
+ break;
1290
+ case self::SHIPMENT_TYPE_GLOBALPACK:
1291
+ $allowedProductCodes = $cifHelper->getGlobalProductCodes($flat);
1292
+ break;
1293
+ case self::SHIPMENT_TYPE_BUSPAKJE:
1294
+ $allowedProductCodes = $cifHelper->getBuspakjeProductCodes($flat);
1295
+ break;
1296
+ default:
1297
+ $allowedProductCodes = array();
1298
+ break;
1299
+ }
1300
+
1301
+ return $allowedProductCodes;
1302
  }
1303
 
1304
  /**
1313
  }
1314
 
1315
  /**
1316
+ * Try to get the delivery date for a PostNL order.
1317
  */
1318
  $postnlOrder = $this->getPostnlOrder();
1319
  if ($postnlOrder && $postnlOrder->getDeliveryDate()) {
1323
  return $deliveryDate;
1324
  }
1325
 
1326
+ /**
1327
+ * @var TIG_PostNL_Helper_DeliveryOptions $helper
1328
+ */
1329
+ $helper = $this->getHelper('deliveryOptions');
1330
+ $deliveryDate = $helper->getDeliveryDate($this->getOrder()->getCreatedAt(), $this->getStoreId());
1331
+
1332
+ if ($deliveryDate) {
1333
+ return $deliveryDate;
1334
+ }
1335
+
1336
  /**
1337
  * If no delivery date is available, return null.
1338
  */
1339
  return null;
1340
  }
1341
 
1342
+ /**
1343
+ * Get whether this shipment is a buspakje shipment. If no value is set, calculate the correct value and set it.
1344
+ *
1345
+ * @return bool
1346
+ */
1347
+ public function getIsBuspakje()
1348
+ {
1349
+ $isBuspakje = $this->_getData('is_buspakje');
1350
+
1351
+ if (!is_null($isBuspakje)) {
1352
+ return $isBuspakje;
1353
+ }
1354
+
1355
+ $isBuspakje = $this->_getIsBuspakje();
1356
+
1357
+ $this->setIsBuspakje($isBuspakje);
1358
+ return $isBuspakje;
1359
+ }
1360
+
1361
+ /**
1362
+ * Getter for the '_preventSaving' class variable.
1363
+ *
1364
+ * @return bool
1365
+ */
1366
+ public function getPreventSaving()
1367
+ {
1368
+ return $this->_preventSaving;
1369
+ }
1370
+
1371
  /*******************************************************************************************************************
1372
  * SETTER METHODS
1373
  ******************************************************************************************************************/
1514
  */
1515
  $postnlOrder = $this->getPostnlOrder();
1516
  if ($postnlOrder && $postnlOrder->getConfirmDate()) {
1517
+ $confirmDate = new DateTime($postnlOrder->getConfirmDate());
1518
 
1519
+ $this->setData('confirm_date', $confirmDate->getTimestamp());
1520
  return $this;
1521
  }
1522
 
1538
  /**
1539
  * Calculate the confirm based on the delivery date.
1540
  */
1541
+ $deliveryDate = new DateTime($deliveryDate);
1542
+ $confirmDate = $deliveryDate->sub(new DateInterval('P1D'))->getTimestamp();
1543
 
1544
  $this->setData('confirm_date', $confirmDate);
1545
  return $this;
1546
  }
1547
 
1548
+ /**
1549
+ * Sets the current shipment's phase. Triggers an event if the phase is valid.
1550
+ *
1551
+ * @param mixed $phase
1552
+ *
1553
+ * @return $this
1554
+ */
1555
+ public function setShippingPhase($phase)
1556
+ {
1557
+ $this->setData('shipping_phase', $phase);
1558
+
1559
+ if (is_numeric($phase) && $phase != $this->getShippingPhase()) {
1560
+ $phases = $this->getHelper('cif')->getShippingPhaseCodes();
1561
+
1562
+ if (array_key_exists($phase, $phases)) {
1563
+ $phaseName = $phases[$phase];
1564
+ Mage::dispatchEvent('postnl_shipment_setshippingphase_' . $phaseName, array('shipment' => $this));
1565
+ }
1566
+ }
1567
+
1568
+ return $this;
1569
+ }
1570
+
1571
+ /**
1572
+ * Setter for the '_preventSaving' class variable.
1573
+ *
1574
+ * @param boolean $value
1575
+ *
1576
+ * @return $this
1577
+ */
1578
+ public function setPreventSaving($value)
1579
+ {
1580
+ $this->_preventSaving = (bool) $value;
1581
+
1582
+ return $this;
1583
+ }
1584
+
1585
  /*******************************************************************************************************************
1586
  * HAS- METHODS
1587
  ******************************************************************************************************************/
1589
  /**
1590
  * Check if the shipment has any associated labels
1591
  *
1592
+ * @param boolean $checkCollection
1593
+ *
1594
  * @return boolean
1595
  */
1596
+ public function hasLabels($checkCollection = true)
1597
  {
1598
+ if ($this->_getData('labels')) {
1599
+ return true;
1600
+ }
1601
+
1602
+ if (!$checkCollection) {
1603
+ return false;
1604
+ }
1605
+
1606
  $labelCollection = Mage::getResourceModel('postnl_core/shipment_label_collection');
1607
  $labelCollection->addFieldToFilter('parent_id', array('eq' => $this->getid()));
1608
 
1663
  return true;
1664
  }
1665
 
1666
+ /**
1667
+ * Checks if this shipment uses a custom barcode.
1668
+ *
1669
+ * @return bool
1670
+ */
1671
+ public function hasCustomBarcode()
1672
+ {
1673
+ $productCode = $this->getProductCode();
1674
+
1675
+ $customBarcodes = $this->getCustomBarcodes();
1676
+ $disallowedProductCodes = array_keys($customBarcodes);
1677
+
1678
+ if (in_array($productCode, $disallowedProductCodes)) {
1679
+ return true;
1680
+ }
1681
+
1682
+ return false;
1683
+ }
1684
+
1685
  /*******************************************************************************************************************
1686
  * IS- AND CAN- METHODS
1687
  ******************************************************************************************************************/
1709
  return true;
1710
  }
1711
 
1712
+ $shippingAddress = $this->getShippingAddress();
1713
+ if (!$shippingAddress) {
1714
+ return false;
1715
+ }
1716
+
1717
+ $shippingDestination = $shippingAddress->getCountryId();
1718
 
1719
  if ($shippingDestination == 'NL') {
1720
  return true;
1734
  return true;
1735
  }
1736
 
1737
+ $shippingAddress = $this->getShippingAddress();
1738
+ if (!$shippingAddress) {
1739
+ return false;
1740
+ }
1741
+
1742
+ $shippingDestination = $shippingAddress->getCountryId();
1743
 
1744
  /**
1745
  * @var TIG_PostNL_Helper_Cif $helper
1827
  }
1828
 
1829
  /**
1830
+ * Check if the current shipment is a PakjeGemak shipment.
1831
  *
1832
  * @return boolean
1833
  */
1901
  }
1902
 
1903
  /**
1904
+ * Check if this shipment is a buspakje shipment.
1905
  *
1906
  * @return boolean
1907
+ */
1908
+ public function isBuspakjeShipment()
1909
+ {
1910
+ if ($this->hasIsBuspakjeShipment()) {
1911
+ return $this->getIsBuspakjeShipment();
1912
+ }
1913
+
1914
+ $isBuspakje = $this->getIsBuspakje();
1915
+
1916
+ $this->setIsBuspakjeShipment($isBuspakje);
1917
+ return $isBuspakje;
1918
+ }
1919
+
1920
+ /**
1921
+ * Checks if this shipment is a COD shipment.
1922
  *
1923
+ * @return boolean
1924
  */
1925
  public function isCod()
1926
  {
1927
+ $codPaymentMethods = Mage::helper('postnl/payment')->getCodPaymentMethods();
1928
+
1929
+ /**
1930
+ * @var Mage_Sales_Model_Order_Payment $payment
1931
+ */
1932
+ $payment = Mage::getModel('sales/order_payment')
1933
+ ->load($this->getShipment()->getOrderId(), 'parent_id');
1934
+ $paymentMethod = $payment->getMethod();
1935
+
1936
+ if (in_array($paymentMethod, $codPaymentMethods)) {
1937
+ return true;
1938
+ }
1939
+
1940
  return false;
1941
  }
1942
 
1984
  */
1985
  public function canGenerateBarcode()
1986
  {
1987
+ if (!$this->getShipmentId() && !$this->getShipment(false)) {
1988
+ return false;
1989
+ }
1990
+
1991
+ if (!$this->canGenerateBarcodeForProductCode()) {
1992
+ return false;
1993
+ }
1994
+
1995
+ return true;
1996
+ }
1997
+
1998
+ /**
1999
+ * Checks whether a barcode may be generated for a given product code.
2000
+ *
2001
+ * @param bool|string|int $productCode
2002
+ *
2003
+ * @return bool
2004
+ */
2005
+ public function canGenerateBarcodeForProductCode($productCode = false)
2006
+ {
2007
+ if (!$productCode) {
2008
+ $productCode = $this->getProductCode();
2009
+ }
2010
+
2011
+ $customBarcodes = $this->getCustomBarcodes();
2012
+ $disallowedProductCodes = array_keys($customBarcodes);
2013
+ if (in_array($productCode, $disallowedProductCodes)) {
2014
  return false;
2015
  }
2016
 
2034
  return false;
2035
  }
2036
 
2037
+ if (!$this->getShipmentId() && !$this->getShipment(false)) {
2038
  return false;
2039
  }
2040
 
2049
  return false;
2050
  }
2051
 
2052
+ if ($this->hasCustomBarcode()) {
2053
+ return false;
2054
+ }
2055
+
2056
  return true;
2057
  }
2058
 
2059
  /**
2060
  * Checks if the current shipment is eligible for a shipping status update.
2061
  * Unconfirmed shipments, shipments whose labels are not yet printed or shipments that are already delivered are
2062
+ * ineligible. Also shipments which use a custom barcode are ineligible.
2063
  *
2064
  * @return boolean
2065
  */
2081
  return false;
2082
  }
2083
 
2084
+ if (!$this->hasLabels()) {
2085
+ return false;
2086
+ }
2087
+
2088
+ if (!$this->getMainBarcode()) {
2089
+ return false;
2090
+ }
2091
+
2092
+ $customBarcodes = $this->getCustomBarcodes();
2093
+ $productCode = $this->getProductCode();
2094
+
2095
+ if (array_key_exists($productCode, $customBarcodes)) {
2096
+ return false;
2097
+ }
2098
+
2099
+ return true;
2100
+ }
2101
+
2102
+ /**
2103
+ * Checks if the current shipment is eligible for a complete shipping status update.
2104
+ *
2105
+ * @return boolean
2106
+ */
2107
+ public function canUpdateCompleteShippingStatus()
2108
+ {
2109
+ if ($this->isLocked()) {
2110
+ return false;
2111
+ }
2112
+
2113
+ if (self::CONFIRM_STATUS_CONFIRMED != $this->getConfirmStatus()) {
2114
+ return false;
2115
+ }
2116
+
2117
+ if (!$this->getLabelsPrinted()) {
2118
+ return false;
2119
+ }
2120
+
2121
+ if (!$this->getMainBarcode()) {
2122
+ return false;
2123
+ }
2124
+
2125
+ $customBarcodes = $this->getCustomBarcodes();
2126
+ $productCode = $this->getProductCode();
2127
+
2128
+ if (array_key_exists($productCode, $customBarcodes)) {
2129
+ return false;
2130
+ }
2131
+
2132
+ return true;
2133
+ }
2134
+
2135
+ /**
2136
+ * Checks whether a tracking code may be added to this shipment.
2137
+ *
2138
+ * @return bool
2139
+ */
2140
+ public function canAddTrackingCode()
2141
+ {
2142
+ /**
2143
+ * If this shipment has a custom barcode, we can't add tracking info.
2144
+ */
2145
+ if ($this->hasCustomBarcode()) {
2146
+ return false;
2147
+ }
2148
+
2149
+ return true;
2150
+ }
2151
+
2152
+ /**
2153
+ * Checks if the current shipment can send a track & trace email to the customer.
2154
+ *
2155
+ * @param boolean $ignoreAlreadySent Flag to ignore the 'already sent' check
2156
+ * @param boolean $ignoreConfig Flag to ignore the 'send_track_and_trace_email' config setting.
2157
+ *
2158
+ * @return boolean
2159
+ */
2160
+ public function canSendTrackAndTraceEmail($ignoreAlreadySent = false, $ignoreConfig = false)
2161
+ {
2162
+ if ($this->isLocked()) {
2163
+ return false;
2164
+ }
2165
+
2166
+ /**
2167
+ * If the email is already sent, don't send it again.
2168
+ */
2169
+ if ($ignoreAlreadySent !== true && $this->getTrackAndTraceEmailSent()) {
2170
+ return false;
2171
+ }
2172
+
2173
+ /**
2174
+ * If we have no barcode, there is no point in sending the track and trace email.
2175
+ */
2176
+ if (!$this->getMainBarcode()) {
2177
+ return false;
2178
+ }
2179
+
2180
+ /**
2181
+ * If this shipment uses a custom barcode we can't send the track and trace email, because custom barcodes can't
2182
+ * be tracked.
2183
+ */
2184
+ if ($this->hasCustomBarcode()) {
2185
+ return false;
2186
+ }
2187
+
2188
+ /**
2189
+ * Make sure sending the email is allowed in the config.
2190
+ */
2191
+ if ($ignoreConfig !== true) {
2192
+ $storeId = $this->getStoreId();
2193
+ $canSendTrackAndTrace = Mage::getStoreConfig(self::XPATH_SEND_TRACK_AND_TRACE_EMAIL, $storeId);
2194
+ if (!$canSendTrackAndTrace) {
2195
+ return false;
2196
+ }
2197
+ }
2198
+
2199
+ return true;
2200
+ }
2201
+
2202
+ /**
2203
+ * Checks if this shipment's confirmation status can be reset.
2204
+ *
2205
+ * @return boolean
2206
+ */
2207
+ public function canResetConfirmation()
2208
+ {
2209
+ $confirmStatus = $this->getConfirmStatus();
2210
+ if ($confirmStatus == self::CONFIRM_STATUS_CONFIRM_EXPIRED) {
2211
+ return false;
2212
+ }
2213
+
2214
+ if ($confirmStatus == self::CONFIRM_STATUS_UNCONFIRMED) {
2215
+ return false;
2216
+ }
2217
+
2218
+ $shippingPhase = $this->getShippingPhase();
2219
+ if ($shippingPhase == self::SHIPPING_PHASE_COLLECTION
2220
+ || $shippingPhase == self::SHIPPING_PHASE_DELIVERED
2221
+ || $shippingPhase == self::SHIPPING_PHASE_DISTRIBUTION
2222
+ || $shippingPhase == self::SHIPPING_PHASE_SORTING
2223
+ ) {
2224
+ return false;
2225
+ }
2226
+
2227
+ return true;
2228
+ }
2229
+
2230
+ /**
2231
+ * Checks if the current shipment can be converted to a buspakje shipment.
2232
+ *
2233
+ * @return bool
2234
+ */
2235
+ public function canConvertShipmentToBuspakje()
2236
+ {
2237
+ $shipmentType = $this->getShipmentType();
2238
+ if ($shipmentType != self::SHIPMENT_TYPE_DOMESTIC) {
2239
+ return false;
2240
+ }
2241
+
2242
+ $shippingPhase = $this->getShippingPhase();
2243
+ if ($shippingPhase == self::SHIPPING_PHASE_COLLECTION
2244
+ || $shippingPhase == self::SHIPPING_PHASE_DELIVERED
2245
+ || $shippingPhase == self::SHIPPING_PHASE_DISTRIBUTION
2246
+ || $shippingPhase == self::SHIPPING_PHASE_SORTING
2247
+ ) {
2248
  return false;
2249
  }
2250
 
2251
+ if (!$this->getHelper()->canUseBuspakje()) {
2252
  return false;
2253
  }
2254
 
2256
  }
2257
 
2258
  /**
2259
+ * Checks if the current shipment can be converted to a package shipment.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2260
  *
2261
+ * @return bool
2262
  */
2263
+ public function canConvertShipmentToPackage()
2264
  {
2265
+ $shipmentType = $this->getShipmentType();
2266
+ if ($shipmentType != self::SHIPMENT_TYPE_BUSPAKJE) {
2267
  return false;
2268
  }
2269
 
2270
+ $shippingPhase = $this->getShippingPhase();
2271
+ if ($shippingPhase == self::SHIPPING_PHASE_COLLECTION
2272
+ || $shippingPhase == self::SHIPPING_PHASE_DELIVERED
2273
+ || $shippingPhase == self::SHIPPING_PHASE_DISTRIBUTION
2274
+ || $shippingPhase == self::SHIPPING_PHASE_SORTING
2275
+ ) {
2276
  return false;
2277
  }
2278
 
2279
+ if (!$this->getHelper()->canUseStandard()) {
2280
+ return false;
 
 
 
 
2281
  }
2282
 
2283
  return true;
2284
  }
2285
 
2286
  /**
2287
+ * Checks if the current shipment's product code may be changed.
2288
+ *
2289
+ * @param boolean $checkAvailableProductOptions
2290
  *
2291
  * @return boolean
2292
  */
2293
+ public function canChangeProductCode($checkAvailableProductOptions = true)
2294
  {
2295
+ if ($this->isConfirmed()) {
 
 
 
 
 
2296
  return false;
2297
  }
2298
 
2305
  return false;
2306
  }
2307
 
2308
+ if (!$checkAvailableProductOptions) {
2309
+ return true;
2310
+ }
2311
+
2312
+ /**
2313
+ * Get all available product options and this shipment's current product code.
2314
+ */
2315
+ $availableProductOptions = $this->getAllowedProductOptions();
2316
+ $productCode = $this->getProductCode();
2317
+
2318
+ if (count($availableProductOptions) === 1 && isset($availableProductOptions[$productCode])) {
2319
+ /**
2320
+ * If only 1 product option is available and it's the same as the current product code, then we can't change
2321
+ * it.
2322
+ */
2323
+ return false;
2324
+ } elseif (count($availableProductOptions)) {
2325
+ /**
2326
+ * If there are any available product options, then we can change it.
2327
+ */
2328
+ return true;
2329
+ }
2330
+
2331
+ return false;
2332
  }
2333
 
2334
  /*******************************************************************************************************************
2345
  $process = $this->getProcess();
2346
  $process->lockAndBlock();
2347
 
 
2348
  $this->isLocked();
2349
  return $this;
2350
  }
2402
  Mage::dispatchEvent('postnl_shipment_generatebarcode_before', array('shipment' => $this));
2403
 
2404
  /**
2405
+ * Generate and save the main barcode.
2406
  */
2407
  $mainBarcode = $this->_generateBarcode();
2408
  $this->setMainBarcode($mainBarcode);
2413
  }
2414
 
2415
  /**
2416
+ * If this shipment consists of a single parcel we only need the main barcode.
2417
  */
2418
  if ($parcelCount < 2) {
2419
  Mage::dispatchEvent('postnl_shipment_generatebarcode_after', array('shipment' => $this));
2423
  }
2424
 
2425
  /**
2426
+ * Generate a barcode for each parcel and save it.
2427
  */
2428
  for ($i = 1; $i < $parcelCount; $i++) {
2429
  $barcode = $this->_generateBarcode();
2488
 
2489
  Mage::dispatchEvent('postnl_shipment_generatelabel_before', array('shipment' => $this));
2490
 
2491
+ $parcelCount = $this->getParcelCount();
2492
  if (!$parcelCount) {
2493
  $parcelCount = $this->_calculateParcelCount();
2494
  }
2628
 
2629
  Mage::dispatchEvent('postnl_shipment_confirm_before', array('shipment' => $this));
2630
 
2631
+ $parcelCount = $this->getParcelCount();
2632
  if (!$parcelCount) {
2633
  $parcelCount = $this->_calculateParcelCount();
2634
  }
2751
  Mage::dispatchEvent('postnl_shipment_confirm_before', array('shipment' => $this));
2752
  Mage::dispatchEvent('postnl_shipment_confirmandgeneratelabel_before', array('shipment' => $this));
2753
 
2754
+ $parcelCount = $this->getParcelCount();
2755
  if (!$parcelCount) {
2756
  $parcelCount = $this->_calculateParcelCount();
2757
  }
2833
  return $this;
2834
  }
2835
 
2836
+ Mage::dispatchEvent(
2837
+ 'postnl_shipment_updateshippingphase_before',
2838
+ array('shipment' => $this, 'phase' => $currentPhase)
2839
+ );
2840
  $this->setShippingPhase($currentPhase);
2841
+ Mage::dispatchEvent(
2842
+ 'postnl_shipment_updateshippingphase_after',
2843
+ array('shipment' => $this, 'phase' => $currentPhase)
2844
+ );
2845
 
2846
  Mage::dispatchEvent('postnl_shipment_updateshippingstatus_after', array('shipment' => $this));
2847
 
2881
  * Update the shipment's shipping phase
2882
  */
2883
  $currentPhase = $result->Status->CurrentPhaseCode;
2884
+ Mage::dispatchEvent(
2885
+ 'postnl_shipment_updateshippingphase_before',
2886
+ array('shipment' => $this, 'phase' => $currentPhase)
2887
+ );
2888
  $this->setShippingPhase($currentPhase);
2889
+ Mage::dispatchEvent(
2890
+ 'postnl_shipment_updateshippingphase_after',
2891
+ array('shipment' => $this, 'phase' => $currentPhase)
2892
+ );
2893
 
2894
  if (!isset($result->Events->CompleteStatusResponseEvent)) {
2895
  $this->unlock();
2958
  */
2959
  public function addTrackingCodeToShipment()
2960
  {
2961
+ if (!$this->canAddTrackingCode()) {
2962
+ throw new TIG_PostNL_Exception(
2963
+ Mage::helper('postnl')->__('The addTrackingCodeToShipment action is currently unavailable.'),
2964
+ 'POSTNL-0180'
2965
+ );
2966
+ }
2967
+
2968
  $shipment = $this->getShipment();
2969
  $barcode = $this->getMainBarcode();
2970
 
3182
  ->setLabel(base64_encode($label->Content))
3183
  ->setLabelType($labelType);
3184
 
3185
+ $labels = $this->getLabels();
3186
+ $labels[] = $postnlLabel;
3187
+ $this->setLabels($labels);
3188
+
3189
  $this->_addLabelToSave($postnlLabel);
3190
 
3191
  return $this;
3317
  return array_values($sortedHistory);
3318
  }
3319
 
3320
+ /*******************************************************************************************************************
3321
+ * BUSPAKJE METHODS
3322
+ ******************************************************************************************************************/
3323
+
3324
+ /**
3325
+ * Calculate whether this shipment is a buspakje shipment.
3326
+ *
3327
+ * @return bool
3328
+ *
3329
+ * @throws TIG_PostNL_Exception
3330
+ */
3331
+ protected function _getIsBuspakje()
3332
+ {
3333
+ if (!$this->isDutchShipment()
3334
+ || $this->isPakketautomaatShipment()
3335
+ || $this->isPakjeGemakShipment()
3336
+ || $this->isCod()
3337
+ ) {
3338
+ return false;
3339
+ }
3340
+
3341
+ if (!$this->getHelper()->canUseBuspakje()) {
3342
+ return false;
3343
+ }
3344
+
3345
+ $shipmentItems = $this->getShipment()
3346
+ ->getItemsCollection();
3347
+
3348
+ /**
3349
+ * @var Mage_Sales_Model_Order_Shipment_Item $item
3350
+ */
3351
+ $orderItems = array();
3352
+ foreach ($shipmentItems as $item) {
3353
+ $orderItem = $item->getOrderItem();
3354
+
3355
+ if ($orderItem->getChildrenItems()) {
3356
+ $orderItems = array_merge($orderItems, $orderItem->getChildrenItems());
3357
+ continue;
3358
+ }
3359
+
3360
+ $orderItems[] = $orderItem;
3361
+ }
3362
+
3363
+ if (!$this->getHelper()->fitsAsBuspakje($orderItems)) {
3364
+ return false;
3365
+ }
3366
+
3367
+ return true;
3368
+ }
3369
+
3370
  /*******************************************************************************************************************
3371
  * PRODUCT CODE METHODS
3372
  ******************************************************************************************************************/
3373
 
3374
  /**
3375
+ * Gets the product code for this shipment. If specific options have been selected those will be used. Otherwise the
3376
+ * default options will be used from system/config
3377
  *
3378
  * @return int
3379
  */
3380
  protected function _getProductCode()
3381
  {
3382
  /**
3383
+ * Product options were set manually by the user.
3384
  */
3385
  if (Mage::registry('postnl_product_option')) {
3386
  $productCode = Mage::registry('postnl_product_option');
3387
+
3388
+ if (is_array($productCode)) {
3389
+ $productCode = $this->_extractProductCodeForType($productCode);
3390
+ }
3391
+
3392
  $this->_checkProductCodeAllowed($productCode);
3393
 
3394
  return $productCode;
3395
  }
3396
 
3397
  /**
3398
+ * Use default options.
3399
  */
3400
  $productCode = $this->getDefaultProductCode();
3401
 
3402
  return $productCode;
3403
  }
3404
 
3405
+ /**
3406
+ * Extracts a chosen product code from an array of product codes indexed by shipment type.
3407
+ *
3408
+ * @param array $codes
3409
+ *
3410
+ * @return string
3411
+ */
3412
+ protected function _extractProductCodeForType($codes)
3413
+ {
3414
+ $shipmentType = $this->getShipmentType(false);
3415
+
3416
+ /**
3417
+ * If this is a domestic shipment and the shipment has been marked as 'buspakje', update the shipment type. If
3418
+ * no buspakje field was entered or the field has a value of -1, automatically determine whether this shipment
3419
+ * is a buspakje shipment.
3420
+ */
3421
+ if ($shipmentType == self::SHIPMENT_TYPE_DOMESTIC
3422
+ && array_key_exists('is_buspakje', $codes)
3423
+ && $codes['is_buspakje'] == '1'
3424
+ ) {
3425
+ $isBuspakje = true;
3426
+ } elseif ($shipmentType == self::SHIPMENT_TYPE_DOMESTIC
3427
+ && (!array_key_exists('is_buspakje', $codes)
3428
+ || $codes['is_buspakje'] == '-1'
3429
+ )
3430
+ ) {
3431
+ $isBuspakje = $this->_getIsBuspakje();
3432
+ } else {
3433
+ $isBuspakje = false;
3434
+ }
3435
+
3436
+ /**
3437
+ * If this is a buspakje shipment, change the shipment type accordingly.
3438
+ */
3439
+ $this->setIsBuspakje($isBuspakje);
3440
+ if ($isBuspakje) {
3441
+ $shipmentType = self::SHIPMENT_TYPE_BUSPAKJE;
3442
+ $this->setShipmentType($shipmentType);
3443
+ }
3444
+
3445
+ /**
3446
+ * The merchant may choose to use the default product code for this shipment.
3447
+ */
3448
+ if (array_key_exists('use_default', $codes) && $codes['use_default'] == '1') {
3449
+ return $this->getDefaultProductCode();
3450
+ }
3451
+
3452
+ /**
3453
+ * Get the selected product code for the current shipment's shipment type.
3454
+ */
3455
+ $shipmentType .= '_options';
3456
+ if (array_key_exists($shipmentType, $codes)) {
3457
+ return $codes[$shipmentType];
3458
+ } elseif (array_key_exists('product_option', $codes)) {
3459
+ return $codes['product_option'];
3460
+ }
3461
+
3462
+ /**
3463
+ * If no code was found, use the default.
3464
+ */
3465
+ return $this->getDefaultProductCode();
3466
+ }
3467
+
3468
  /**
3469
  * Checks if a given product code is allowed for the current shipments. Throws an exception if not.
3470
  *
3483
  $allowedProductCodes = $this->getAllowedProductCodes();
3484
 
3485
  /**
3486
+ * Check if the product code is allowed.
3487
  */
3488
  if (!in_array($productCode, $allowedProductCodes)) {
3489
  throw new TIG_PostNL_Exception(
3493
  }
3494
 
3495
  /**
3496
+ * Check if the product code is restricted to certain countries.
3497
  */
3498
  $allowedCountries = $this->_isCodeRestricted($productCode);
3499
  if ($allowedCountries === false) {
3501
  }
3502
 
3503
  /**
3504
+ * Check if the destination country of this shipment is allowed.
3505
  */
3506
+ $shippingAddress = $this->getShippingAddress();
3507
+ if (!$shippingAddress
3508
+ || !in_array($shippingAddress->getCountryId(), $allowedCountries)
3509
+ ) {
3510
  throw new TIG_PostNL_Exception(
3511
  $cifHelper->__('Product code %s is not allowed for this shipment.', $productCode),
3512
  'POSTNL-0078'
3517
  }
3518
 
3519
  /**
3520
+ * Checks if a given product code is only allowed for a specific country.
3521
  *
3522
  * @param $code
3523
  *
3598
  protected function _calculateParcelCount()
3599
  {
3600
  /**
3601
+ * Only Dutch shipments that are not COD support multi-colli shipments
3602
  */
3603
+ if (!$this->isDutchShipment() || $this->isCod()) {
3604
  return 1;
3605
  }
3606
 
3614
  *
3615
  * @var TIG_PostNL_Helper_Cif $helper
3616
  */
3617
+ $helper = $this->getHelper();
3618
  $weightPerParcel = Mage::getStoreConfig(self::XPATH_WEIGHT_PER_PARCEL, $this->getStoreId());
3619
  $weightPerParcel = $helper->standardizeWeight($weightPerParcel, $this->getStoreId());
3620
 
3626
  return $parcelCount;
3627
  }
3628
 
3629
+ /*******************************************************************************************************************
3630
+ * CONVERSION METHODS
3631
+ ******************************************************************************************************************/
3632
+
3633
+ /**
3634
+ * Converts this shipment to a buspakje shipment.
3635
+ *
3636
+ * @return $this
3637
+ *
3638
+ * @throws TIG_PostNL_Exception
3639
+ */
3640
+ public function convertToBuspakje()
3641
+ {
3642
+ if (!$this->canConvertShipmentToBuspakje()) {
3643
+ throw new TIG_PostNL_Exception(
3644
+ $this->getHelper()->__('The convertToBuspakje action is currently unavailable.'),
3645
+ 'POSTNL-0191'
3646
+ );
3647
+ }
3648
+
3649
+ $this->_prepareForConversion()
3650
+ ->setShipmentType(self::SHIPMENT_TYPE_BUSPAKJE)
3651
+ ->setProductCode($this->_getProductCode())
3652
+ ->setIsBuspakje(true);
3653
+
3654
+ return $this;
3655
+ }
3656
+
3657
+ /**
3658
+ * Converts this shipment to a package shipment.
3659
+ *
3660
+ * @return $this
3661
+ *
3662
+ * @throws TIG_PostNL_Exception
3663
+ */
3664
+ public function convertToPackage()
3665
+ {
3666
+ if (!$this->canConvertShipmentToPackage()) {
3667
+ throw new TIG_PostNL_Exception(
3668
+ $this->getHelper()->__('The convertToPackage action is currently unavailable.'),
3669
+ 'POSTNL-0192'
3670
+ );
3671
+ }
3672
+
3673
+ $this->_prepareForConversion()
3674
+ ->setShipmentType(self::SHIPMENT_TYPE_DOMESTIC)
3675
+ ->setProductCode($this->_getProductCode())
3676
+ ->setIsBuspakje(false);
3677
+
3678
+ return $this;
3679
+ }
3680
+
3681
+ /**
3682
+ * Prepares this shipment for conversion to a different product code or shipment type.
3683
+ *
3684
+ * @return $this
3685
+ */
3686
+ protected function _prepareForConversion()
3687
+ {
3688
+ $this->deleteBarcodes()
3689
+ ->deleteLabels()
3690
+ ->deleteShipmentTracks()
3691
+ ->deleteStatusHistory()
3692
+ ->setConfirmStatus(self::CONFIRM_STATUS_UNCONFIRMED);
3693
+
3694
+ return $this;
3695
+ }
3696
+
3697
+ /**
3698
+ * Changes the current shipment's product code.
3699
+ *
3700
+ * @param string $productCode
3701
+ *
3702
+ * @return $this
3703
+ *
3704
+ * @throws TIG_PostNL_Exception
3705
+ */
3706
+ public function changeProductCode($productCode)
3707
+ {
3708
+ if (!$this->canChangeProductCode()) {
3709
+ throw new TIG_PostNL_Exception(
3710
+ $this->getHelper()->__('The changeProductCode action is currently unavailable.'),
3711
+ 'POSTNL-0193'
3712
+ );
3713
+ }
3714
+
3715
+ $this->_checkProductCodeAllowed($productCode);
3716
+
3717
+ $this->setProductCode($productCode);
3718
+
3719
+ return $this;
3720
+ }
3721
+
3722
  /*******************************************************************************************************************
3723
  * RESET AND DELETE METHODS
3724
  ******************************************************************************************************************/
3733
  */
3734
  public function resetConfirmation($deleteLabels = true, $deleteTracks = true)
3735
  {
3736
+ if (!$this->hasCustomBarcode()) {
3737
+ $confirmStatus = self::CONFIRM_STATUS_UNCONFIRMED;
3738
+ } else {
3739
+ $confirmStatus = self::CONFIRM_STATUS_BUSPAKJE;
3740
+ }
3741
+
3742
+ $this->setConfirmStatus($confirmStatus) //set status to unconfirmed
3743
  ->setShippingPhase(false) //delete current shipping phase
3744
+ ->setConfirmedAt(false); //delete 'confirmed at' date
3745
+
3746
+ $this->deleteBarcodes() //delete all associated barcodes
3747
  ->deleteStatusHistory(); //delete all associated status history items
3748
 
3749
 
3769
  {
3770
  $shipment = $this->getShipment();
3771
 
3772
+ if (!$shipment) {
3773
+ return $this;
3774
+ }
3775
+
3776
  /**
3777
  * @var Mage_Sales_Model_Order_Shipment_Track $track
3778
  */
3827
  }
3828
 
3829
  /**
3830
+ * Deletes all status history items associated with this shipment.
3831
  *
3832
  * @return $this
3833
  */
3847
  }
3848
 
3849
  /*******************************************************************************************************************
3850
+ * LOADING METHODS
3851
+ ******************************************************************************************************************/
3852
+
3853
+ /**
3854
+ * Loads this shipment by a Magento shipment.
3855
+ *
3856
+ * @param Mage_Sales_Model_Order_Shipment $shipment
3857
+ *
3858
+ * @return $this
3859
+ */
3860
+ public function loadByShipment(Mage_Sales_Model_Order_Shipment $shipment)
3861
+ {
3862
+ $shipmentId = $shipment->getId();
3863
+
3864
+ if (!$shipmentId) {
3865
+ return $this;
3866
+ }
3867
+
3868
+ $this->load($shipmentId, 'shipment_id');
3869
+ return $this;
3870
+ }
3871
+
3872
+ /*******************************************************************************************************************
3873
+ * SAVING METHODS
3874
  ******************************************************************************************************************/
3875
 
3876
  /**
3896
  /**
3897
  * Set confirm status.
3898
  */
3899
+ if ($this->getConfirmStatus() === null && $this->hasCustomBarcode()) {
3900
+ $this->setConfirmStatus(self::CONFIRM_STATUS_BUSPAKJE);
3901
+ } elseif ($this->getConfirmStatus() === null) {
3902
  $this->setConfirmStatus(self::CONFIRM_STATUS_UNCONFIRMED);
3903
  }
3904
 
3942
  }
3943
 
3944
  /**
3945
+ * If no order ID has been set, use the getOrderId() method. This will automatically set the order ID.
3946
  */
3947
+ if (!$this->_getData('order_id')) {
3948
+ $this->getOrderId();
3949
  }
3950
 
 
 
 
 
 
3951
  return parent::_beforeSave();
3952
  }
3953
+
3954
+ /**
3955
+ * Check if saving this shipment is allowed before actually saving the object.
3956
+ *
3957
+ * @return $this
3958
+ *
3959
+ * @throws Exception
3960
+ */
3961
+ public function save()
3962
+ {
3963
+ if ($this->getPreventSaving()) {
3964
+ return $this;
3965
+ }
3966
+
3967
+ return parent::save();
3968
+ }
3969
  }
app/code/community/TIG/PostNL/Model/Core/Shipment/Barcode.php CHANGED
@@ -66,7 +66,7 @@ class TIG_PostNL_Model_Core_Shipment_Barcode extends Mage_Core_Model_Abstract
66
  * @param $parentId
67
  * @param $barcodeNumber
68
  *
69
- * @return TIG_PostNL_Model_Core_Shipment_Barcode
70
  */
71
  public function loadByParentAndBarcodeNumber($parentId, $barcodeNumber)
72
  {
66
  * @param $parentId
67
  * @param $barcodeNumber
68
  *
69
+ * @return $this
70
  */
71
  public function loadByParentAndBarcodeNumber($parentId, $barcodeNumber)
72
  {
app/code/community/TIG/PostNL/Model/Core/Shipment/Label.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_Shipment_Label
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_Label
app/code/community/TIG/PostNL/Model/Core/Shipment/Process.php CHANGED
@@ -38,8 +38,14 @@
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
  /**
@@ -76,7 +82,7 @@ class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
76
  * Lock process without blocking.
77
  * This method allow protect multiple process running and fast lock validation.
78
  *
79
- * @return TIG_PostNL_Model_Core_Shipment_Process
80
  */
81
  public function lock()
82
  {
@@ -89,9 +95,9 @@ class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
89
  }
90
 
91
  /**
92
- * Lock and block process
93
  *
94
- * @return TIG_PostNL_Model_Core_Shipment_Process
95
  */
96
  public function lockAndBlock()
97
  {
@@ -104,9 +110,9 @@ class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
104
  }
105
 
106
  /**
107
- * Unlock process
108
  *
109
- * @return TIG_PostNL_Model_Core_Shipment_Process
110
  */
111
  public function unlock()
112
  {
38
  */
39
  class TIG_PostNL_Model_Core_Shipment_Process extends Mage_Index_Model_Process
40
  {
41
+ /**
42
+ * @var bool
43
+ */
44
  protected $_own = false;
45
 
46
+ /**
47
+ * @var null|boolean
48
+ */
49
  protected $_isLocked = null;
50
 
51
  /**
82
  * Lock process without blocking.
83
  * This method allow protect multiple process running and fast lock validation.
84
  *
85
+ * @return $this
86
  */
87
  public function lock()
88
  {
95
  }
96
 
97
  /**
98
+ * Lock and block process.
99
  *
100
+ * @return $this
101
  */
102
  public function lockAndBlock()
103
  {
110
  }
111
 
112
  /**
113
+ * Unlock process.
114
  *
115
+ * @return $this
116
  */
117
  public function unlock()
118
  {
app/code/community/TIG/PostNL/Model/Core/Shipment/Status/History.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_Shipment_Status_History
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_Status_History
app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/HourMinute.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Backend_HourMinute extends Mage_Core_Model_Config_Data
40
+ {
41
+ /**
42
+ * @return Mage_Core_Model_Abstract
43
+ */
44
+ protected function _beforeSave()
45
+ {
46
+ /**
47
+ * The value is an array with the selected hour and minute. We need to implode this so it conforms to the H:i:s
48
+ * format.
49
+ */
50
+ $value = $this->getValue();
51
+ $value = implode(':', $value) . ':00';
52
+
53
+ $this->setValue($value);
54
+
55
+ return parent::_beforeSave();
56
+ }
57
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/Image/Pdf.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Backend_Image_Pdf extends Mage_Adminhtml_Model_System_Config_Backend_Image_Pdf
40
+ {
41
+ /**
42
+ * Maximum size (in pixels).
43
+ */
44
+ const MAX_WIDTH = 900;
45
+ const MAX_HEIGHT = 100;
46
+
47
+ /**
48
+ * If an image was saved, make sure the image is not too large. If it is, resize it.
49
+ *
50
+ * @return Mage_Core_Model_Abstract
51
+ */
52
+ protected function _afterSave()
53
+ {
54
+ /**
55
+ * If we have no value, no new file was uploaded.
56
+ */
57
+ if (!$this->getValue()) {
58
+ return parent::_afterSave();
59
+ }
60
+
61
+ /**
62
+ * Locate the file and make sure it exists.
63
+ */
64
+ $uploadDir = $this->_getBaseUploadDir();
65
+ $fileName = $this->getValue();
66
+ $file = $uploadDir . DS . $fileName;
67
+
68
+ if (!file_exists($file)) {
69
+ return parent::_afterSave();
70
+ }
71
+
72
+ /**
73
+ * Load the image as a Varien_Image object.
74
+ */
75
+ $image = new Varien_Image($file);
76
+ $image->keepAspectRatio(true);
77
+ $image->keepTransparency(true);
78
+
79
+ /**
80
+ * Check the image's size and resize the image if necessary.
81
+ */
82
+ if ($image->getOriginalWidth() > self::MAX_WIDTH) {
83
+ $image->resize(self::MAX_WIDTH, self::MAX_HEIGHT);
84
+ $image->save($file);
85
+ } elseif ($image->getOriginalHeight() > self::MAX_HEIGHT) {
86
+ $image->resize(null, self::MAX_HEIGHT);
87
+ $image->save($file);
88
+ }
89
+
90
+ return parent::_afterSave();
91
+ }
92
+
93
+ /**
94
+ * Return path to directory for upload file without scope.
95
+ *
96
+ * @return string
97
+ *
98
+ * @throw Mage_Core_Exception
99
+ */
100
+ protected function _getBaseUploadDir()
101
+ {
102
+ /**
103
+ * @var $fieldConfig Varien_Simplexml_Element
104
+ */
105
+ $fieldConfig = $this->getFieldConfig();
106
+
107
+ if (empty($fieldConfig->upload_dir)) {
108
+ Mage::throwException(Mage::helper('catalog')->__('The base directory to upload file is not specified.'));
109
+ }
110
+
111
+ $uploadDir = (string)$fieldConfig->upload_dir;
112
+
113
+ $el = $fieldConfig->descend('upload_dir');
114
+
115
+ /**
116
+ * Take root from config
117
+ */
118
+ if (!empty($el['config'])) {
119
+ $uploadRoot = $this->_getUploadRoot((string)$el['config']);
120
+ $uploadDir = $uploadRoot . '/' . $uploadDir;
121
+ }
122
+
123
+ return $uploadDir;
124
+ }
125
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/ValidateDefaultOption.php CHANGED
@@ -94,18 +94,18 @@ class TIG_PostNL_Model_Core_System_Config_Backend_ValidateDefaultOption extends
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
  /**
@@ -131,9 +131,9 @@ class TIG_PostNL_Model_Core_System_Config_Backend_ValidateDefaultOption extends
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
  /**
94
  /**
95
  * Search for the label of the current field and translate it.
96
  */
97
+ $label = (string) $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
  /**
131
  /**
132
  * Set this field's value to null, as it's selected option is invalid.
133
  */
134
+ $this->setValue(false);
135
 
136
+ return false;
137
  }
138
 
139
  /**
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/AllProductOptions.php CHANGED
@@ -37,487 +37,302 @@
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
 
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
- * @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(
59
- 'standard_options' => array(
60
- 'label' => $helper->__('Domestic options'),
61
- 'value' => array(
62
- '3085' => array(
63
- 'value' => '3085',
64
- 'label' => $helper->__('Standard shipment'),
65
- ),
66
- /**
67
- * These are not currently implemented
68
- *
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
- ),
140
- 'pakjegemak_options' => array(
141
- 'label' => $helper->__('Post Office options'),
142
- 'value' => array(
143
- /**
144
- * These are not currently implemented
145
- *
146
- * @todo implement these options
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',
169
- 'label' => $helper->__('Post Office + Extra Cover'),
170
- 'isExtraCover' => true,
171
- ),
172
- '3544' => array(
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
- ),
189
- 'eu_options' => array(
190
- 'label' => $helper->__('EU options'),
191
- 'value' => array(
192
- '4952' => array(
193
- 'value' => '4952',
194
- 'label' => $helper->__('EU Pack Special Consumer (incl. signature)'),
195
- ),
196
- /**
197
- * This option has been removed since v1.1.4.
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,
205
- ),*/
206
- /**
207
- * These are not currently implemented
208
- *
209
- * @todo implement these options
210
- */
211
- /*'4950' => array(
212
- 'value' => '4950',
213
- 'label' => $helper->__('EU Pack Special (B2B)'),
214
- ),
215
- '4954' => array(
216
- 'value' => '4954',
217
- 'label' => $helper->__('EU Pack Special COD (Belgium and Luxembourg only)'),
218
- ),*/
219
- ),
220
- ),
221
- 'global_options' => array(
222
- 'label' => $helper->__('Global options'),
223
- 'value' => array(
224
- '4945' => array(
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
- ),
241
- );
242
 
 
243
  if ($helper->canUseEpsBEOnlyOption()) {
244
- $availableOptions['eu_options']['value']['4955'] = array(
245
  'value' => '4955',
246
  'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
247
  'isBelgiumOnly' => true,
 
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
- }
280
 
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
288
- */
289
- $availableOptions = array();
290
-
291
- /**
292
- * prepend the 'default' option
293
- */
294
- if ($withDefault === true) {
295
- $availableOptions[] = array(
296
- 'value' => 'default',
297
- 'label' => $helper->__('Use default'),
298
- );
299
- }
300
-
301
- /**
302
- * Get the list of supported product options from the shop's configuration
303
- */
304
- $supportedOptions = Mage::getStoreConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
305
- $supportedOptionsArray = explode(',', $supportedOptions);
306
- if ($canUseEpsBEOnly) {
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;
326
- }
327
-
328
- if (isset($option['isExtraCover']) && $withExtraCover !== true) {
329
- continue;
330
- }
331
-
332
- if ($codesOnly === true) {
333
- $availableOptions[] = $option['value'];
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;
355
- }
356
-
357
- if (isset($option['isExtraCover']) && $withExtraCover !== true) {
358
- continue;
359
- }
360
-
361
- if ($codesOnly === true) {
362
- $availableOptions[] = $option['value'];
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;
384
- }
385
-
386
- if (isset($option['isExtraCover']) && $withExtraCover !== true) {
387
- continue;
388
- }
389
-
390
- if ($codesOnly === true) {
391
- $availableOptions[] = $option['value'];
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)) {
409
- continue;
410
- }
411
-
412
- if (isset($option['isExtraCover']) && $withExtraCover !== true) {
413
- continue;
414
- }
415
-
416
- if ($codesOnly === true) {
417
- $availableOptions[] = $option['value'];
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
-
466
- /**
467
- * group all available options
468
- */
469
- if (!empty($availableStandardOptions)) {
470
- $availableOptions['standard_options'] = array(
471
- 'label' => $helper->__('Standard options'),
472
- 'value' => $availableStandardOptions,
473
- );
474
- }
475
-
476
- if (!empty($availablePakjeGemakOptions)) {
477
- $availableOptions['pakjegemak_options'] = array(
478
- 'label' => $helper->__('Post Office options'),
479
- 'value' => $availablePakjeGemakOptions,
480
- );
481
- }
482
-
483
- if (!empty($availableEuOptions)) {
484
- $availableOptions['eu_options'] = array(
485
- 'label' => $helper->__('EU options'),
486
- 'value' => $availableEuOptions,
487
- );
488
- }
489
-
490
- if (!empty($availableGlobalOptions)) {
491
- $availableOptions['global_options'] = array(
492
- 'label' => $helper->__('Global options'),
493
- 'value' => $availableGlobalOptions,
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
  *
@@ -525,88 +340,6 @@ class TIG_PostNL_Model_Core_System_Config_Source_AllProductOptions
525
  */
526
  public function getExtraCoverOptions($valuesOnly = false)
527
  {
528
- /**
529
- * Get all available options
530
- */
531
- $availableOptions = $this->getAvailableOptions(false, true);
532
-
533
- /**
534
- * Loop through each optGroup and then each option to see if any of them have the isExtraCover flag.
535
- * Add these to the array of extra cover options.
536
- */
537
- $extraCoverOptions = array();
538
- foreach ($availableOptions as $optionGroup) {
539
- foreach ($optionGroup['value'] as $option) {
540
- /**
541
- * Add the whole option (value, label and flags)
542
- */
543
- if (isset($option['isExtraCover'])
544
- && $option['isExtraCover']
545
- && $valuesOnly !== true
546
- ) {
547
- $extraCoverOptions[] = $option;
548
- continue;
549
- }
550
-
551
- /**
552
- * Only add the value
553
- */
554
- if (isset($option['isExtraCover'])
555
- && $option['isExtraCover']
556
- && $valuesOnly === true
557
- ) {
558
- $extraCoverOptions[] = $option['value'];
559
- continue;
560
- }
561
-
562
- continue;
563
- }
564
- }
565
-
566
- return $extraCoverOptions;
567
- }
568
-
569
- /**
570
- * Marks the default values in the option array
571
- *
572
- * @param array &$options
573
- *
574
- * @return array
575
- */
576
- protected function _markDefault(&$options)
577
- {
578
- $helper = Mage::helper('postnl/cif');
579
-
580
- /**
581
- * Get an array of all default options
582
- */
583
- $defaultOptions = $helper->getDefaultProductOptions();
584
-
585
-
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;
611
  }
612
  }
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
40
+ extends TIG_PostNL_Model_Core_System_Config_Source_ProductOptions_Abstract
41
  {
42
  /**
43
+ * @var array
44
  */
45
+ protected $_options = array(
46
+ '3085' => array(
47
+ 'value' => '3085',
48
+ 'label' => 'Standard shipment',
49
+ 'isExtraCover' => false,
50
+ 'isAvond' => false,
51
+ 'isCod' => false,
52
+ 'group' => 'standard_options',
53
+ ),
54
+ '3086' => array(
55
+ 'value' => '3086',
56
+ 'label' => 'COD',
57
+ 'isExtraCover' => false,
58
+ 'isAvond' => true,
59
+ 'isCod' => true,
60
+ 'group' => 'standard_options',
61
+ ),
62
+ '3091' => array(
63
+ 'value' => '3091',
64
+ 'label' => 'COD + Extra cover',
65
+ 'isExtraCover' => true,
66
+ 'isAvond' => true,
67
+ 'isCod' => true,
68
+ 'group' => 'standard_options',
69
+ ),
70
+ '3093' => array(
71
+ 'value' => '3093',
72
+ 'label' => 'COD + Return when not home',
73
+ 'isExtraCover' => false,
74
+ 'isAvond' => true,
75
+ 'isCod' => true,
76
+ 'group' => 'standard_options',
77
+ ),
78
+ '3097' => array(
79
+ 'value' => '3097',
80
+ 'label' => 'COD + Extra cover + Return when not home',
81
+ 'isExtraCover' => true,
82
+ 'isAvond' => true,
83
+ 'isCod' => true,
84
+ 'group' => 'standard_options',
85
+ ),
86
+ '3087' => array(
87
+ 'value' => '3087',
88
+ 'label' => 'Extra Cover',
89
+ 'isExtraCover' => true,
90
+ 'isAvond' => true,
91
+ 'isCod' => false,
92
+ 'group' => 'standard_options',
93
+ ),
94
+ '3094' => array(
95
+ 'value' => '3094',
96
+ 'label' => 'Extra cover + Return when not home',
97
+ 'isAvond' => true,
98
+ 'isExtraCover' => true,
99
+ 'isCod' => false,
100
+ 'group' => 'standard_options',
101
+ ),
102
+ '3189' => array(
103
+ 'value' => '3189',
104
+ 'label' => 'Signature on delivery',
105
+ 'isExtraCover' => false,
106
+ 'isAvond' => false,
107
+ 'isCod' => false,
108
+ 'group' => 'standard_options',
109
+ ),
110
+ '3089' => array(
111
+ 'value' => '3089',
112
+ 'label' => 'Signature on delivery + Delivery to stated address only',
113
+ 'isExtraCover' => false,
114
+ 'isAvond' => true,
115
+ 'isCod' => false,
116
+ 'group' => 'standard_options',
117
+ ),
118
+ '3389' => array(
119
+ 'value' => '3389',
120
+ 'label' => 'Signature on delivery + Return when not home',
121
+ 'isExtraCover' => false,
122
+ 'isAvond' => false,
123
+ 'isCod' => false,
124
+ 'group' => 'standard_options',
125
+ ),
126
+ '3096' => array(
127
+ 'value' => '3096',
128
+ 'label' => 'Signature on delivery + Deliver to stated address only + Return when not home',
129
+ 'isExtraCover' => false,
130
+ 'isAvond' => true,
131
+ 'isCod' => false,
132
+ 'group' => 'standard_options',
133
+ ),
134
+ '3090' => array(
135
+ 'value' => '3090',
136
+ 'label' => 'Delivery to neighbour + Return when not home',
137
+ 'isExtraCover' => false,
138
+ 'isAvond' => true,
139
+ 'isCod' => false,
140
+ 'group' => 'standard_options',
141
+ ),
142
+ '3385' => array(
143
+ 'value' => '3385',
144
+ 'label' => 'Deliver to stated address only',
145
+ 'isExtraCover' => false,
146
+ 'isAvond' => true,
147
+ 'isCod' => false,
148
+ 'group' => 'standard_options',
149
+ ),
150
+ '3390' => array(
151
+ 'value' => '3390',
152
+ 'label' => 'Deliver to stated address only + Return when not home',
153
+ 'isExtraCover' => false,
154
+ 'isAvond' => true,
155
+ 'isCod' => false,
156
+ 'group' => 'standard_options',
157
+ ),
158
+ '3535' => array(
159
+ 'value' => '3535',
160
+ 'label' => 'Post Office + COD',
161
+ 'isExtraCover' => false,
162
+ 'isPge' => false,
163
+ 'isCod' => true,
164
+ 'group' => 'pakjegemak_options',
165
+ ),
166
+ '3545' => array(
167
+ 'value' => '3545',
168
+ 'label' => 'Post Office + COD + Notification',
169
+ 'isExtraCover' => false,
170
+ 'isPge' => true,
171
+ 'isCod' => true,
172
+ 'group' => 'pakjegemak_options',
173
+ ),
174
+ '3536' => array(
175
+ 'value' => '3536',
176
+ 'label' => 'Post Office + COD + Extra Cover',
177
+ 'isExtraCover' => false,
178
+ 'isPge' => true,
179
+ 'isCod' => true,
180
+ 'group' => 'pakjegemak_options',
181
+ ),
182
+ '3546' => array(
183
+ 'value' => '3546',
184
+ 'label' => 'Post Office + COD + Extra Cover + Notification',
185
+ 'isExtraCover' => true,
186
+ 'isPge' => true,
187
+ 'isCod' => true,
188
+ 'group' => 'pakjegemak_options',
189
+ ),
190
+ '3534' => array(
191
+ 'value' => '3534',
192
+ 'label' => 'Post Office + Extra Cover',
193
+ 'isExtraCover' => true,
194
+ 'isPge' => false,
195
+ 'isCod' => false,
196
+ 'group' => 'pakjegemak_options',
197
+ ),
198
+ '3544' => array(
199
+ 'value' => '3544',
200
+ 'label' => 'Post Office + Extra Cover + Notification',
201
+ 'isExtraCover' => true,
202
+ 'isPge' => true,
203
+ 'isCod' => false,
204
+ 'group' => 'pakjegemak_options',
205
+ ),
206
+ '3533' => array(
207
+ 'value' => '3533',
208
+ 'label' => 'Post Office + Signature on Delivery',
209
+ 'isExtraCover' => false,
210
+ 'isPge' => false,
211
+ 'isCod' => false,
212
+ 'group' => 'pakjegemak_options',
213
+ ),
214
+ '3543' => array(
215
+ 'value' => '3543',
216
+ 'label' => 'Post Office + Signature on Delivery + Notification',
217
+ 'isExtraCover' => false,
218
+ 'isPge' => true,
219
+ 'isCod' => false,
220
+ 'group' => 'pakjegemak_options',
221
+ ),
222
+ '4952' => array(
223
+ 'value' => '4952',
224
+ 'label' => 'EU Pack Special Consumer (incl. signature)',
225
+ 'isExtraCover' => false,
226
+ 'group' => 'eu_options',
227
+ ),
228
+ /**
229
+ * This option has been removed since v1.1.4.
230
+ */
231
+ /*'4955' => array(
232
+ 'value' => '4955',
233
+ 'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
234
+ 'isBelgiumOnly' => true,
235
+ ),*/
236
+ /**
237
+ * These are not currently implemented.
238
+ */
239
+ /*'4950' => array(
240
+ 'value' => '4950',
241
+ 'label' => $helper->__('EU Pack Special (B2B)'),
242
+ ),
243
+ '4954' => array(
244
+ 'value' => '4954',
245
+ 'label' => $helper->__('EU Pack Special COD (Belgium and Luxembourg only)'),
246
+ ),*/
247
+ '4945' => array(
248
+ 'value' => '4945',
249
+ 'label' => 'GlobalPack',
250
+ 'isExtraCover' => true,
251
+ 'extraCover' => 200,
252
+ 'group' => 'global_options',
253
+ ),
254
+ '3553' => array(
255
+ 'value' => '3553',
256
+ 'label' => 'Parcel Dispenser',
257
+ 'isExtraCover' => false,
258
+ 'group' => 'pakketautomaat_options',
259
+ ),
260
+ '2828' => array(
261
+ 'value' => '2828',
262
+ 'label' => 'Letter Box Parcel',
263
+ 'isExtraCover' => false,
264
+ 'group' => 'buspakje_options',
265
+ ),
266
+ '2928' => array(
267
+ 'value' => '2928',
268
+ 'label' => 'Letter Box Parcel Extra',
269
+ 'isExtraCover' => false,
270
+ 'group' => 'buspakje_options',
271
+ ),
272
+ );
273
 
274
  /**
275
+ * @var array
276
+ */
277
+ protected $_groups = array(
278
+ 'standard_options' => 'Domestic options',
279
+ 'pakjegemak_options' => 'Post Office options',
280
+ 'eu_options' => 'EU options',
281
+ 'global_options' => 'Global options',
282
+ 'pakketautomaat_options' => 'Parcel Dispenser options',
283
+ 'buspakje_options' => 'Letter Box Parcel options',
284
+ );
285
+
286
+ /**
287
+ * Gets all possible options.
288
  *
289
+ * @param array $flags
290
+ * @param bool $asFlatArray
291
+ * @param bool $checkAvailable
292
  *
293
  * @return array
 
 
294
  */
295
+ public function getOptions($flags = array(), $asFlatArray = false, $checkAvailable = false)
296
  {
297
+ $options = parent::getOptions($flags, $asFlatArray, $checkAvailable);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
 
299
+ $helper = Mage::helper('postnl');
300
  if ($helper->canUseEpsBEOnlyOption()) {
301
+ $options['eu_options']['value']['4955'] = array(
302
  'value' => '4955',
303
  'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
304
  'isBelgiumOnly' => true,
305
+ 'isExtraCover' => false,
306
  );
307
  }
308
 
309
+ return $options;
310
  }
311
 
312
  /**
313
+ * Returns an option array for all possible PostNL product options.
 
 
 
 
 
 
 
 
 
 
314
  *
315
  * @return array
316
  */
317
+ public function toOptionArray()
318
+ {
319
+ $options = $this->getGroupedOptions();
 
 
 
 
 
 
 
 
320
 
321
  $helper = Mage::helper('postnl');
322
+ if ($helper->canUseEpsBEOnlyOption()) {
323
+ $options['eu_options']['value']['4955'] = array(
324
+ 'value' => '4955',
325
+ 'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
326
+ 'isBelgiumOnly' => true,
327
+ 'isExtraCover' => false,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  );
329
  }
330
 
331
+ return $options;
332
  }
333
 
334
  /**
335
+ * Get the list of available product options that have extra cover.
336
  *
337
  * @param bool $valuesOnly
338
  *
340
  */
341
  public function getExtraCoverOptions($valuesOnly = false)
342
  {
343
+ return $this->getOptions(array('isExtraCover' => true), $valuesOnly, true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  }
345
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/BuspakjeProductOptions.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_BuspakjeProductOptions
40
+ extends TIG_PostNL_Model_Core_System_Config_Source_ProductOptions_Abstract
41
+ {
42
+ /**
43
+ * @var array
44
+ */
45
+ protected $_options = array(
46
+ array(
47
+ 'value' => '2828',
48
+ 'label' => 'Letter Box Parcel',
49
+ ),
50
+ array(
51
+ 'value' => '2928',
52
+ 'label' => 'Letter Box Parcel Extra',
53
+ ),
54
+ );
55
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/CommentType.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_Core_System_Config_Source_CommentType
40
+ {
41
+ /**
42
+ * Returns an option array for comment type options
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
+ {
48
+ $helper = Mage::helper('postnl');
49
+ $options = array(
50
+ array(
51
+ 'value' => 'static',
52
+ 'label' => $helper->__('Pre-configured message'),
53
+ ),
54
+ array(
55
+ 'value' => 'shipment_comment',
56
+ 'label' => $helper->__('Last shipment comment'),
57
+ ),
58
+ );
59
+
60
+ return $options;
61
+ }
62
+ }
app/code/community/TIG/PostNL/Model/{DeliveryOptions → Core}/System/Config/Source/CutOffTime.php RENAMED
@@ -36,7 +36,7 @@
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_DeliveryOptions_System_Config_Source_CutOffTime
40
  {
41
  /**
42
  * Gets an option array for possible cut-off times.
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_CutOffTime
40
  {
41
  /**
42
  * Gets an option array for possible cut-off times.
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/DebugMode.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_DebugMode
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_DebugMode
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/Direction.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_Direction
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_Direction
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/EuProductOptions.php CHANGED
@@ -33,121 +33,45 @@
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_EuProductOptions
 
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
- * @todo implement COD and extra cover
52
  */
53
- public function toOptionArray()
54
  {
55
- $helper = Mage::helper('postnl');
56
- $availableOptions = array(
57
- array(
58
- 'value' => '4952',
59
- 'label' => $helper->__('EU Pack Special Consumer (incl. signature)'),
60
- ),
61
- /**
62
- * This option has been removed in v1.1.4
63
- *
64
- * @deprecated v1.1.2
65
- */
66
- /*array(
67
- 'value' => '4955',
68
- 'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
69
- 'isBelgiumOnly' => true,
70
- ),*/
71
- /**
72
- * These are not currently implemented
73
- *
74
- * @todo implement these options
75
- */
76
- /*
77
- array(
78
- 'value' => '4950',
79
- 'label' => $helper->__('EU Pack Special (B2B)'),
80
- ),
81
- array(
82
- 'value' => '4954',
83
- 'label' => $helper->__('EU Pack Special COD (Belgium and Luxembourg only)'),
84
- ),*/
85
- );
86
 
 
87
  if ($helper->canUseEpsBEOnlyOption()) {
88
- $availableOptions['4955'] = array(
89
  'value' => '4955',
90
  'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
91
  'isBelgiumOnly' => true,
 
92
  );
93
  }
94
 
95
- return $availableOptions;
96
- }
97
-
98
- /**
99
- * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
100
- *
101
- * @param boolean|int $storeId
102
- * @param boolean $codesOnly
103
- *
104
- * @return array
105
- */
106
- public function getAvailableOptions($storeId = false, $codesOnly = false)
107
- {
108
- if ($storeId === false) {
109
- $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
110
- }
111
-
112
- $helper = Mage::helper('postnl');
113
- $canUseEpsBEOnly = $helper->canUseEpsBEOnlyOption();
114
-
115
- $options = $this->toOptionArray();
116
-
117
- /**
118
- * Get a list of all possible options
119
- */
120
- $availableOptions = array();
121
-
122
- /**
123
- * Get the list of supported product options from the shop's configuration
124
- */
125
- $supportedOptions = Mage::getStoreConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
126
- $supportedOptionsArray = explode(',', $supportedOptions);
127
- if ($canUseEpsBEOnly) {
128
- $supportedOptionsArray[] = '4955';
129
- }
130
-
131
- /**
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
- }
142
-
143
- if ($codesOnly === true) {
144
- $availableOptions[] = $option['value'];
145
- continue;
146
- }
147
-
148
- $availableOptions[] = $option;
149
- }
150
-
151
- return $availableOptions;
152
  }
153
  }
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_EuProductOptions
40
+ extends TIG_PostNL_Model_Core_System_Config_Source_ProductOptions_Abstract
41
  {
42
  /**
43
+ * @var array
44
  */
45
+ protected $_options = array(
46
+ array(
47
+ 'value' => '4952',
48
+ 'label' => 'EU Pack Special Consumer (incl. signature)',
49
+ ),
50
+ );
51
 
52
  /**
53
+ * Gets all possible options.
54
  *
55
+ * @param array $flags
56
+ * @param bool $asFlatArray
57
+ * @param bool $checkAvailable
58
  *
59
+ * @return array
60
  */
61
+ public function getOptions($flags = array(), $asFlatArray = false, $checkAvailable = false)
62
  {
63
+ $options = parent::getOptions($flags, $asFlatArray, $checkAvailable);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
+ $helper = Mage::helper('postnl');
66
  if ($helper->canUseEpsBEOnlyOption()) {
67
+ $options['eu_options']['value']['4955'] = array(
68
  'value' => '4955',
69
  'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
70
  'isBelgiumOnly' => true,
71
+ 'isExtraCover' => false,
72
  );
73
  }
74
 
75
+ return $options;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalProductOptions.php CHANGED
@@ -37,78 +37,16 @@
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
 
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' => '4945',
57
- 'label' => $helper->__('GlobalPack'),
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)
74
- {
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
  }
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
40
+ extends TIG_PostNL_Model_Core_System_Config_Source_ProductOptions_Abstract
41
  {
42
  /**
43
+ * @var array
44
  */
45
+ protected $_options = array(
46
+ array(
47
+ 'value' => '4945',
48
+ 'label' => 'GlobalPack',
49
+ 'isExtraCover' => true,
50
+ ),
51
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalpackShipmentType.php CHANGED
@@ -37,7 +37,34 @@
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
  *
@@ -45,30 +72,6 @@ class TIG_PostNL_Model_Core_System_Config_Source_GlobalpackShipmentType
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
  }
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
+ extends TIG_PostNL_Model_Core_System_Config_Source_ProductOptions_Abstract
41
  {
42
+ /**
43
+ * @var array
44
+ */
45
+ protected $_options = array(
46
+ array(
47
+ 'value' => 'Gift',
48
+ 'label' => 'Gift',
49
+ ),
50
+ array(
51
+ 'value' => 'Documents',
52
+ 'label' => 'Documents',
53
+ ),
54
+ array(
55
+ 'value' => 'Commercial Goods',
56
+ 'label' => 'Commercial Goods',
57
+ ),
58
+ array(
59
+ 'value' => 'Commercial Sample',
60
+ 'label' => 'Commercial Sample',
61
+ ),
62
+ array(
63
+ 'value' => 'Returned Goods',
64
+ 'label' => 'Returned Goods',
65
+ ),
66
+ );
67
+
68
  /**
69
  * Returns an option array for possible GlobalPack shipment types.
70
  *
72
  */
73
  public function toOptionArray()
74
  {
75
+ return $this->getOptions();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/HourMinute.php ADDED
@@ -0,0 +1,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.
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_HourMinute
40
+ {
41
+ /**
42
+ * Gets an option array for possible hours and minutes.
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
+ {
48
+ $options = array(
49
+ 'hour' => array(),
50
+ 'minute' => array(),
51
+ );
52
+
53
+ for ($i = 0; $i < 24; $i++) {
54
+ $number = sprintf("%02d", $i);
55
+ $options['hour'][] = array(
56
+ 'value' => $number,
57
+ 'label' => $number,
58
+ );
59
+ }
60
+
61
+ for ($i = 0; $i < 12; $i++) {
62
+ $number = sprintf("%02d", $i * 5);
63
+ $options['minute'][] = array(
64
+ 'value' => $number,
65
+ 'label' => $number,
66
+ );
67
+ }
68
+
69
+ return $options;
70
+ }
71
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/LabelSize.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_LabelSize
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_LabelSize
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ManualAutomatic.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_Core_System_Config_Source_ManualAutomatic
40
+ {
41
+ /**
42
+ * Returns an option array with an 'automatic' and 'manual' option.
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
+ {
48
+ $helper = Mage::helper('postnl');
49
+ $options = array(
50
+ array(
51
+ 'value' => 'automatic',
52
+ 'label' => $helper->__('Automatic'),
53
+ ),
54
+ array(
55
+ 'value' => 'manual',
56
+ 'label' => $helper->__('Manual'),
57
+ ),
58
+ );
59
+
60
+ return $options;
61
+ }
62
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PackingSlipItemFields.php ADDED
@@ -0,0 +1,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.
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_PackingSlipItemFields
40
+ {
41
+ /**
42
+ * Returns an option array for all supported fields for the packing slip item columns.
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
+ {
48
+ $helper = Mage::helper('postnl');
49
+ $labelSizes = array(
50
+ array(
51
+ 'value' => 'name',
52
+ 'label' => $helper->__('Name')
53
+ ),
54
+ array(
55
+ 'value' => 'sku',
56
+ 'label' => $helper->__('Sku')
57
+ ),
58
+ array(
59
+ 'value' => 'price',
60
+ 'label' => $helper->__('Price')
61
+ ),
62
+ array(
63
+ 'value' => 'qty',
64
+ 'label' => $helper->__('Qty')
65
+ ),
66
+ array(
67
+ 'value' => 'tax',
68
+ 'label' => $helper->__('Vat')
69
+ ),
70
+ array(
71
+ 'value' => 'subtotal',
72
+ 'label' => $helper->__('Subtotal')
73
+ ),
74
+ );
75
+
76
+ return $labelSizes;
77
+ }
78
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakjeGemakProductOptions.php CHANGED
@@ -37,163 +37,125 @@
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
 
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
- * @todo implement COD
52
  */
53
  public function toOptionArray()
54
  {
55
- $helper = Mage::helper('postnl');
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',
82
- 'label' => $helper->__('Post Office + Extra Cover'),
83
- 'isExtraCover' => true,
84
- ),
85
- array(
86
- 'value' => '3544',
87
- 'label' => $helper->__('Post Office + Extra Cover + Notification'),
88
- 'isExtraCover' => true,
89
- 'isPge' => true,
90
- ),
91
- array(
92
- 'value' => '3533',
93
- 'label' => $helper->__('Post Office + Signature on Delivery')
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
  }
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
40
+ extends TIG_PostNL_Model_Core_System_Config_Source_ProductOptions_Abstract
41
  {
42
  /**
43
+ * @var array
44
  */
45
+ protected $_options = array(
46
+ array(
47
+ 'value' => '3534',
48
+ 'label' => 'Post Office + Extra Cover',
49
+ 'isExtraCover' => true,
50
+ 'isPge' => false,
51
+ 'isCod' => false,
52
+ ),
53
+ array(
54
+ 'value' => '3544',
55
+ 'label' => 'Post Office + Extra Cover + Notification',
56
+ 'isExtraCover' => true,
57
+ 'isPge' => true,
58
+ 'isCod' => false,
59
+ ),
60
+ array(
61
+ 'value' => '3533',
62
+ 'label' => 'Post Office + Signature on Delivery',
63
+ 'isExtraCover' => false,
64
+ 'isPge' => false,
65
+ 'isCod' => false,
66
+ ),
67
+ array(
68
+ 'value' => '3543',
69
+ 'label' => 'Post Office + Signature on Delivery + Notification',
70
+ 'isExtraCover' => false,
71
+ 'isPge' => true,
72
+ 'isCod' => false,
73
+ ),
74
+ array(
75
+ 'value' => '3535',
76
+ 'label' => 'Post Office + COD',
77
+ 'isExtraCover' => false,
78
+ 'isPge' => false,
79
+ 'isCod' => true,
80
+ ),
81
+ array(
82
+ 'value' => '3545',
83
+ 'label' => 'Post Office + COD + Notification',
84
+ 'isExtraCover' => false,
85
+ 'isPge' => true,
86
+ 'isCod' => true,
87
+ ),
88
+ array(
89
+ 'value' => '3536',
90
+ 'label' => 'Post Office + COD + Extra Cover',
91
+ 'isExtraCover' => false,
92
+ 'isPge' => false,
93
+ 'isCod' => true,
94
+ ),
95
+ array(
96
+ 'value' => '3546',
97
+ 'label' => 'Post Office + COD + Extra Cover + Notification',
98
+ 'isExtraCover' => false,
99
+ 'isPge' => true,
100
+ 'isCod' => true,
101
+ ),
102
+ );
103
 
104
  /**
105
+ * Returns an option array for all possible PostNL product options.
106
  *
107
  * @return array
 
 
108
  */
109
  public function toOptionArray()
110
  {
111
+ return $this->getOptions(array('isCod' => false));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  }
113
 
114
  /**
115
+ * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
116
  *
117
+ * @param boolean $flat
118
  *
119
  * @return array
120
  */
121
+ public function getAvailableOptions($flat = false)
122
  {
123
+ return $this->getOptions(array('isCod' => false), $flat, true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  }
125
 
126
  /**
127
+ * Get available COD options.
128
  *
129
+ * @param bool $flat
 
 
130
  *
131
  * @return array
132
  */
133
+ public function getAvailableCodOptions($flat = false)
134
  {
135
+ return $this->getOptions(array('isCod' => true), $flat, true);
136
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
+ /**
139
+ * Get available PGE options.
140
+ *
141
+ * @param bool $flat
142
+ *
143
+ * @return array
144
+ */
145
+ public function getAvailablePgeOptions($flat = false)
146
+ {
147
+ return $this->getOptions(array('isPge' => true, 'isCod' => false), $flat, true);
148
  }
149
 
150
  /**
151
+ * Get available PGE options that are also COD.
152
  *
153
+ * @param bool $flat
 
154
  *
155
  * @return array
156
  */
157
+ public function getAvailablePgeCodOptions($flat = false)
158
  {
159
+ return $this->getOptions(array('isPge' => true, 'isCod' => true), $flat, true);
160
  }
161
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakketautomaatProductOptions.php CHANGED
@@ -37,77 +37,15 @@
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
  }
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
+ extends TIG_PostNL_Model_Core_System_Config_Source_ProductOptions_Abstract
41
  {
42
  /**
43
+ * @var array
44
  */
45
+ protected $_options = array(
46
+ array(
47
+ 'value' => '3553',
48
+ 'label' => 'Parcel Dispenser',
49
+ ),
50
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ProductOptions/Abstract.php ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Model_Core_System_Config_Source_ProductOptions_Abstract
40
+ {
41
+ /**
42
+ * Xpath to supported options configuration setting
43
+ */
44
+ const XPATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
45
+
46
+ /**
47
+ * @var array
48
+ */
49
+ protected $_options = array();
50
+
51
+ /**
52
+ * @var array
53
+ */
54
+ protected $_groups = array();
55
+
56
+ /**
57
+ * Gets all possible product options matching an array of flags.
58
+ *
59
+ * @param array $flags
60
+ * @param boolean $asFlatArray
61
+ * @param boolean $checkAvailable
62
+ *
63
+ * @return array
64
+ */
65
+ public function getOptions($flags = array(), $asFlatArray = false, $checkAvailable = false)
66
+ {
67
+ $options = $this->_options;
68
+ if (!empty($flags)) {
69
+ foreach ($options as $key => $option) {
70
+ if (!$this->_optionMatchesFlags($option, $flags)) {
71
+ unset($options[$key]);
72
+ }
73
+ }
74
+ }
75
+
76
+ if ($checkAvailable) {
77
+ $this->_filterAvailable($options);
78
+ }
79
+
80
+ $this->_translateOptions($options);
81
+
82
+ if ($asFlatArray) {
83
+ $this->_flattenOptionArray($options);
84
+ }
85
+
86
+ return $options;
87
+ }
88
+
89
+ /**
90
+ * Gets product options grouped by their 'group' key.
91
+ *
92
+ * @param array $flags
93
+ * @param boolean $filterAvailable
94
+ *
95
+ * @return array
96
+ */
97
+ public function getGroupedOptions($flags = array(), $filterAvailable = false)
98
+ {
99
+ $options = $this->getOptions($flags, false, $filterAvailable);
100
+
101
+ if (empty($this->_groups)) {
102
+ return $options;
103
+ }
104
+
105
+ $groupedOptions = $this->_groupOptions($options);
106
+
107
+ return $groupedOptions;
108
+ }
109
+
110
+
111
+ /**
112
+ * Returns an option array for all possible PostNL product options
113
+ *
114
+ * @return array
115
+ */
116
+ public function toOptionArray()
117
+ {
118
+ return $this->getOptions();
119
+ }
120
+
121
+ /**
122
+ * Get a list of available options. This is a filtered/modified version of the array supplied by getOptions();
123
+ *
124
+ * @param boolean $flat
125
+ *
126
+ * @return array
127
+ */
128
+ public function getAvailableOptions($flat = false)
129
+ {
130
+ return $this->getOptions(array(), $flat, true);
131
+ }
132
+
133
+ /**
134
+ * Checks if an option array item is valid for a given array of flags.
135
+ *
136
+ * @param array $option
137
+ * @param array $flags
138
+ *
139
+ * @return bool
140
+ */
141
+ protected function _optionMatchesFlags($option, $flags)
142
+ {
143
+ foreach($flags as $key => $value) {
144
+ if (!array_key_exists($key, $option)) {
145
+ return false;
146
+ }
147
+
148
+ if ($option[$key] !== $value) {
149
+ return false;
150
+ }
151
+ }
152
+
153
+ return true;
154
+ }
155
+
156
+ /**
157
+ * Groups an array of options based on the 'group' key.
158
+ *
159
+ * @param $options
160
+ *
161
+ * @return array
162
+ */
163
+ protected function _groupOptions($options)
164
+ {
165
+ $helper = Mage::helper('postnl');
166
+ $groups = $this->_groups;
167
+
168
+ $sortedOptions = array();
169
+ foreach ($options as $key => $option) {
170
+ if (!array_key_exists('group', $option)) {
171
+ continue;
172
+ }
173
+
174
+ $group = $option['group'];
175
+ $sortedOptions[$group][$key] = $option;
176
+ }
177
+
178
+ $groupedOptions = array();
179
+ foreach ($groups as $group => $label) {
180
+ if (!array_key_exists($group, $sortedOptions)) {
181
+ continue;
182
+ }
183
+
184
+ $groupedOptions[$group] = array(
185
+ 'label' => $helper->__($label),
186
+ 'value' => $sortedOptions[$group],
187
+ );
188
+ }
189
+
190
+ return $groupedOptions;
191
+ }
192
+
193
+ /**
194
+ * Translates the labels of an option array.
195
+ *
196
+ * @param array $options
197
+ *
198
+ * @return array
199
+ */
200
+ protected function _translateOptions(array &$options)
201
+ {
202
+ $helper = Mage::helper('postnl');
203
+ foreach ($options as &$option) {
204
+ $option['label'] = $helper->__($option['label']);
205
+ }
206
+
207
+ return $options;
208
+ }
209
+
210
+ /**
211
+ * Filters the options based on options that are available.
212
+ *
213
+ * @param array $options
214
+ *
215
+ * @return array
216
+ */
217
+ protected function _filterAvailable(&$options)
218
+ {
219
+ $helper = Mage::helper('postnl');
220
+ $canUseEpsBEOnly = $helper->canUseEpsBEOnlyOption();
221
+
222
+ $storeId = Mage::app()->getStore()->getId();
223
+
224
+ /**
225
+ * Get the list of supported product options from the shop's configuration
226
+ */
227
+ $supportedOptions = Mage::getStoreConfig(self::XPATH_SUPPORTED_PRODUCT_OPTIONS, $storeId);
228
+ $supportedOptionsArray = explode(',', $supportedOptions);
229
+ if ($canUseEpsBEOnly) {
230
+ $supportedOptionsArray[] = '4955';
231
+ }
232
+
233
+ foreach ($options as $key => $option) {
234
+ $code = $option['value'];
235
+ if (!in_array($code, $supportedOptionsArray)) {
236
+ unset($options[$key]);
237
+ }
238
+ }
239
+
240
+ return $options;
241
+ }
242
+
243
+ /**
244
+ * Flattens an option array.
245
+ *
246
+ * @param array $options
247
+ *
248
+ * @return array
249
+ */
250
+ protected function _flattenOptionArray(&$options)
251
+ {
252
+ $flatArray = array();
253
+ foreach ($options as $option) {
254
+ $flatArray[$option['value']] = $option['label'];
255
+ }
256
+
257
+ $options = $flatArray;
258
+
259
+ return $options;
260
+ }
261
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ReferenceType.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_ReferenceType
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_ReferenceType
app/code/community/TIG/PostNL/Model/{DeliveryOptions → Core}/System/Config/Source/ShippingDuration.php RENAMED
@@ -36,7 +36,7 @@
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_DeliveryOptions_System_Config_Source_ShippingDuration
40
  {
41
  /**
42
  * Gets an option array for possible shipping durations.
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_ShippingDuration
40
  {
41
  /**
42
  * Gets an option array for possible shipping durations.
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ShippingMethods.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_ShippingMethods
40
+ {
41
+ /**
42
+ * Return an option array of carriers and shipping methods. If $isActiveOnlyFlag is set to true, only active
43
+ * carriers and their methods will be returned. {@inheritdoc}
44
+ *
45
+ * @param boolean $isMultiSelect
46
+ * @param boolean $isActiveOnlyFlag
47
+ *
48
+ * @return array
49
+ */
50
+ public function toOptionArray($isMultiSelect = false, $isActiveOnlyFlag = false)
51
+ {
52
+ $methods = array();
53
+
54
+ /**
55
+ * @var Mage_Shipping_Model_Carrier_Abstract $carrierModel
56
+ */
57
+ $carriers = Mage::getSingleton('shipping/config')->getAllCarriers();
58
+ foreach ($carriers as $carrierCode => $carrierModel) {
59
+ if ($isActiveOnlyFlag && !$carrierModel->isActive()) {
60
+ continue;
61
+ }
62
+
63
+ try {
64
+ $carrierMethods = $carrierModel->getAllowedMethods();
65
+ if (!$carrierMethods) {
66
+ continue;
67
+ }
68
+ } catch (Exception $e) {
69
+ Mage::helper('postnl')->logException($e);
70
+ continue;
71
+ }
72
+
73
+ $carrierTitle = Mage::getStoreConfig('carriers/'.$carrierCode.'/title');
74
+ $methods[$carrierCode] = array(
75
+ 'label' => $carrierTitle,
76
+ 'value' => array(),
77
+ );
78
+
79
+ foreach ($carrierMethods as $methodCode => $methodTitle) {
80
+ $methods[$carrierCode]['value'][] = array(
81
+ 'value' => $carrierCode . '_' . $methodCode,
82
+ 'label' => '[' . $carrierCode . '] ' . $methodTitle,
83
+ );
84
+ }
85
+ }
86
+
87
+ return $methods;
88
+ }
89
+
90
+ /**
91
+ * Get all options as a flat array.
92
+ *
93
+ * @param bool $isActiveOnlyFlag
94
+ *
95
+ * @return array
96
+ */
97
+ public function toArray($isActiveOnlyFlag = false)
98
+ {
99
+ $methods = array();
100
+
101
+ /**
102
+ * @var Mage_Shipping_Model_Carrier_Abstract $carrierModel
103
+ */
104
+ $carriers = Mage::getSingleton('shipping/config')->getAllCarriers();
105
+ foreach ($carriers as $carrierCode => $carrierModel) {
106
+ if ($isActiveOnlyFlag && !$carrierModel->isActive()) {
107
+ continue;
108
+ }
109
+
110
+ $carrierMethods = $carrierModel->getAllowedMethods();
111
+ if (!$carrierMethods) {
112
+ continue;
113
+ }
114
+
115
+ foreach ($carrierMethods as $methodCode => $methodTitle) {
116
+ $methods[] = $carrierCode . '_' . $methodCode;
117
+ }
118
+ }
119
+
120
+ return $methods;
121
+ }
122
+ }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StandardProductOptions.php CHANGED
@@ -37,101 +37,120 @@
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
 
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
- * @todo implement COD
52
  */
53
  public function toOptionArray()
54
  {
55
- $helper = Mage::helper('postnl');
56
- $availableOptions = array(
57
- array(
58
- 'value' => '3085',
59
- 'label' => $helper->__('Standard shipment'),
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
  /**
@@ -143,89 +162,66 @@ class TIG_PostNL_Model_Core_System_Config_Source_StandardProductOptions
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
  }
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
40
+ extends TIG_PostNL_Model_Core_System_Config_Source_ProductOptions_Abstract
41
  {
42
  /**
43
+ * @var array
44
  */
45
+ protected $_options = array(
46
+ array(
47
+ 'value' => '3085',
48
+ 'label' => 'Standard shipment',
49
+ 'isExtraCover' => false,
50
+ 'isAvond' => false,
51
+ 'isCod' => false,
52
+ ),
53
+ array(
54
+ 'value' => '3087',
55
+ 'label' => 'Extra Cover',
56
+ 'isExtraCover' => true,
57
+ 'isAvond' => true,
58
+ 'isCod' => false,
59
+ ),
60
+ array(
61
+ 'value' => '3094',
62
+ 'label' => 'Extra cover + Return when not home',
63
+ 'isExtraCover' => true,
64
+ 'isAvond' => true,
65
+ 'isCod' => false,
66
+ ),
67
+ array(
68
+ 'value' => '3189',
69
+ 'label' => 'Signature on delivery',
70
+ 'isExtraCover' => false,
71
+ 'isAvond' => false,
72
+ 'isCod' => false,
73
+ ),
74
+ array(
75
+ 'value' => '3089',
76
+ 'label' => 'Signature on delivery + Delivery to stated address only',
77
+ 'isExtraCover' => false,
78
+ 'isAvond' => true,
79
+ 'isCod' => false,
80
+ ),
81
+ array(
82
+ 'value' => '3389',
83
+ 'label' => 'Signature on delivery + Return when not home',
84
+ 'isExtraCover' => false,
85
+ 'isAvond' => false,
86
+ 'isCod' => false,
87
+ ),
88
+ array(
89
+ 'value' => '3096',
90
+ 'label' => 'Signature on delivery + Deliver to stated address only + Return when not home',
91
+ 'isExtraCover' => false,
92
+ 'isAvond' => true,
93
+ 'isCod' => false,
94
+ ),
95
+ array(
96
+ 'value' => '3090',
97
+ 'label' => 'Delivery to neighbour + Return when not home',
98
+ 'isExtraCover' => false,
99
+ 'isAvond' => false,
100
+ 'isCod' => false,
101
+ ),
102
+ array(
103
+ 'value' => '3385',
104
+ 'label' => 'Deliver to stated address only',
105
+ 'isExtraCover' => false,
106
+ 'isAvond' => true,
107
+ 'isCod' => false,
108
+ ),
109
+ array(
110
+ 'value' => '3390',
111
+ 'label' => 'Deliver to stated address only + Return when not home',
112
+ 'isExtraCover' => false,
113
+ 'isAvond' => true,
114
+ 'isCod' => false,
115
+ ),
116
+ array(
117
+ 'value' => '3086',
118
+ 'label' => 'COD',
119
+ 'isExtraCover' => false,
120
+ 'isAvond' => true,
121
+ 'isCod' => true,
122
+ ),
123
+ array(
124
+ 'value' => '3091',
125
+ 'label' => 'COD + Extra cover',
126
+ 'isExtraCover' => true,
127
+ 'isAvond' => true,
128
+ 'isCod' => true,
129
+ ),
130
+ array(
131
+ 'value' => '3093',
132
+ 'label' => 'COD + Return when not home',
133
+ 'isExtraCover' => false,
134
+ 'isAvond' => true,
135
+ 'isCod' => true,
136
+ ),
137
+ array(
138
+ 'value' => '3097',
139
+ 'label' => 'COD + Extra cover + Return when not home',
140
+ 'isExtraCover' => true,
141
+ 'isAvond' => true,
142
+ 'isCod' => true,
143
+ ),
144
+ );
145
 
146
  /**
147
+ * Gets an array of possible standard delivery product options.
148
  *
149
  * @return array
 
 
150
  */
151
  public function toOptionArray()
152
  {
153
+ return $this->getOptions(array('isCod' => false));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
  /**
162
  */
163
  public function getAvondOptions($asFlatArray = false)
164
  {
165
+ return $this->getOptions(array('isAvond' => true, 'isCod' => false), $asFlatArray);
166
+ }
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
+ /**
169
+ * Gets an array of possible evening delivery product options.
170
+ *
171
+ * @param boolean $asFlatArray
172
+ *
173
+ * @return array
174
+ */
175
+ public function getAvondCodOptions($asFlatArray = false)
176
+ {
177
+ return $this->getOptions(array('isAvond' => true, 'isCod' => true), $asFlatArray);
178
  }
179
 
180
  /**
181
  * Get a list of available options. This is a filtered/modified version of the array supplied by toOptionArray();
182
  *
183
+ * @param boolean $flat
 
 
184
  *
185
  * @return array
186
  */
187
+ public function getAvailableOptions($flat = false)
188
  {
189
+ return $this->getOptions(array('isCod' => false), $flat, true);
190
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
+ /**
193
+ * Alias for getAvailableOptions() with $cod = true.
194
+ *
195
+ * @param boolean $flat
196
+ *
197
+ * @return array
198
+ */
199
+ public function getAvailableCodOptions($flat = false)
200
+ {
201
+ return $this->getOptions(array('isCod' => true), $flat, true);
202
+ }
203
 
204
+ /**
205
+ * Get available avond options.
206
+ *
207
+ * @param boolean $flat
208
+ *
209
+ * @return array
210
+ */
211
+ public function getAvailableAvondOptions($flat = false)
212
+ {
213
+ return $this->getOptions(array('isAvond' => true, 'isCod' => false), $flat, true);
214
  }
215
 
216
  /**
217
+ * Get available avond options that are also COD.
218
  *
219
+ * @param boolean $flat
 
220
  *
221
  * @return array
222
  */
223
+ public function getAvailableAvondCodOptions($flat = false)
224
  {
225
+ return $this->getOptions(array('isAvond' => true, 'isCod' => true), $flat, true);
226
  }
227
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetField.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_StreetField
@@ -41,7 +41,7 @@ class TIG_PostNL_Model_Core_System_Config_Source_StreetField
41
  /**
42
  * XML path to community edition address lines configuration option
43
  */
44
- const XML_PATH_COMMUNITY_STREET_LINES = 'customer/address/street_lines';
45
 
46
  /**
47
  * @var null|array The resulting product option array
@@ -86,13 +86,13 @@ class TIG_PostNL_Model_Core_System_Config_Source_StreetField
86
  * Get the allowed number of address lines based on the current scope
87
  */
88
  if ($request->getParam('store')) {
89
- $lineCount = Mage::getStoreConfig(self::XML_PATH_COMMUNITY_STREET_LINES, $request->getParam('store'));
90
  } elseif ($request->getParam('website')) {
91
  $website = Mage::getModel('core/website')->load($request->getParam('website'), 'code');
92
- $lineCount = $website->getConfig(self::XML_PATH_COMMUNITY_STREET_LINES, $website->getId());
93
  } else {
94
  $lineCount = Mage::getStoreConfig(
95
- self::XML_PATH_COMMUNITY_STREET_LINES,
96
  Mage_Core_Model_App::ADMIN_STORE_ID
97
  );
98
  }
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_StreetField
41
  /**
42
  * XML path to community edition address lines configuration option
43
  */
44
+ const XPATH_COMMUNITY_STREET_LINES = 'customer/address/street_lines';
45
 
46
  /**
47
  * @var null|array The resulting product option array
86
  * Get the allowed number of address lines based on the current scope
87
  */
88
  if ($request->getParam('store')) {
89
+ $lineCount = Mage::getStoreConfig(self::XPATH_COMMUNITY_STREET_LINES, $request->getParam('store'));
90
  } elseif ($request->getParam('website')) {
91
  $website = Mage::getModel('core/website')->load($request->getParam('website'), 'code');
92
+ $lineCount = $website->getConfig(self::XPATH_COMMUNITY_STREET_LINES, $website->getId());
93
  } else {
94
  $lineCount = Mage::getStoreConfig(
95
+ self::XPATH_COMMUNITY_STREET_LINES,
96
  Mage_Core_Model_App::ADMIN_STORE_ID
97
  );
98
  }
app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetFieldWithDefault.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
 
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
 
app/code/community/TIG/PostNL/Model/DeliveryOptions/Cif.php CHANGED
@@ -51,10 +51,10 @@ class TIG_PostNL_Model_DeliveryOptions_Cif extends TIG_PostNL_Model_Core_Cif
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
  /**
@@ -92,7 +92,7 @@ class TIG_PostNL_Model_DeliveryOptions_Cif extends TIG_PostNL_Model_Core_Cif
92
  );
93
  }
94
 
95
- $shippingDuration = Mage::helper('postnl/deliveryoptions')->getShippingDuration($quote);
96
 
97
  $soapParams = array(
98
  'GetDeliveryDate' => array(
@@ -155,14 +155,15 @@ class TIG_PostNL_Model_DeliveryOptions_Cif extends TIG_PostNL_Model_Core_Cif
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
  );
@@ -420,10 +421,10 @@ class TIG_PostNL_Model_DeliveryOptions_Cif extends TIG_PostNL_Model_Core_Cif
420
  $helper = Mage::helper('postnl/deliveryOptions');
421
  if ($helper->canUsePakjeGemak()) {
422
  $deliveryOptions[] = self::PAKJEGEMAK_DELIVERY_OPTION;
423
- }
424
 
425
- if ($helper->canUsePakjeGemakExpress()) {
426
- $deliveryOptions[] = self::PAKJEGEMAK_EXPRESS_DELIVERY_OPTION;
 
427
  }
428
 
429
  if ($helper->canUsePakketAutomaat()) {
51
  /**
52
  * Config options used by the getDeliveryDate service.
53
  */
54
+ const XPATH_SHIPPING_DURATION = 'postnl/cif_labels_and_confirming/shipping_duration';
55
+ const XPATH_CUTOFF_TIME = 'postnl/cif_labels_and_confirming/cutoff_time';
56
+ const XPATH_ALLOW_SUNDAY_SORTING = 'postnl/cif_labels_and_confirming/allow_sunday_sorting';
57
+ const XPATH_SUNDAY_CUTOFF_TIME = 'postnl/cif_labels_and_confirming/sunday_cutoff_time';
58
  const XPATH_DELIVERY_DAYS_NUMBER = 'postnl/delivery_options/delivery_days_number';
59
 
60
  /**
92
  );
93
  }
94
 
95
+ $shippingDuration = Mage::helper('postnl/deliveryOptions')->getShippingDuration($quote);
96
 
97
  $soapParams = array(
98
  'GetDeliveryDate' => array(
155
  $maximumNumberOfDeliveryDays = (int) Mage::getStoreConfig(self::XPATH_DELIVERY_DAYS_NUMBER, $storeId);
156
  $maximumNumberOfDeliveryDays--;
157
 
158
+ $endDate = new DateTime($startDate);
159
+ $endDate->add(new DateInterval("P{$maximumNumberOfDeliveryDays}D"));
160
 
161
  $soapParams = array(
162
  'Timeframe' => array(
163
  'PostalCode' => $data['postcode'],
164
  'HouseNumber' => $data['housenumber'],
165
  'StartDate' => $startDate,
166
+ 'EndDate' => $endDate->format('d-m-Y'),
167
  ),
168
  'Message' => $this->_getMessage('')
169
  );
421
  $helper = Mage::helper('postnl/deliveryOptions');
422
  if ($helper->canUsePakjeGemak()) {
423
  $deliveryOptions[] = self::PAKJEGEMAK_DELIVERY_OPTION;
 
424
 
425
+ if ($helper->canUsePakjeGemakExpress()) {
426
+ $deliveryOptions[] = self::PAKJEGEMAK_EXPRESS_DELIVERY_OPTION;
427
+ }
428
  }
429
 
430
  if ($helper->canUsePakketAutomaat()) {
app/code/community/TIG/PostNL/Model/DeliveryOptions/Observer/UpdatePostnlOrder.php CHANGED
@@ -39,6 +39,9 @@
39
  class TIG_PostNL_Model_DeliveryOptions_Observer_UpdatePostnlOrder
40
  {
41
  /**
 
 
 
42
  * @param Varien_Event_Observer $observer
43
  *
44
  * @return $this
@@ -54,20 +57,6 @@ class TIG_PostNL_Model_DeliveryOptions_Observer_UpdatePostnlOrder
54
  */
55
  $order = $observer->getOrder();
56
 
57
- /**
58
- * Check if this order was placed using PostNL.
59
- */
60
- $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
61
- $shippingMethod = $order->getShippingMethod();
62
-
63
- /**
64
- * If this order was not placed with PostNL, remove any PakjeGemak addresses that may have been saved.
65
- */
66
- if (!in_array($shippingMethod, $postnlShippingMethods)) {
67
- $this->_removePakjeGemakAddress($order);
68
- return $this;
69
- }
70
-
71
  /**
72
  * Get the PostNL order associated with this order.
73
  *
@@ -76,12 +65,18 @@ class TIG_PostNL_Model_DeliveryOptions_Observer_UpdatePostnlOrder
76
  $postnlOrder = Mage::getModel('postnl_core/order')->load($order->getQuoteId(), 'quote_id');
77
 
78
  /**
79
- * If this order is not being shipped to the Netherlands, remove any PakjeGemak addresses that may have been
80
- * saved and delete the PostNL order.
 
 
 
 
 
81
  */
82
  $shippingCountry = $order->getShippingAddress()->getCountryId();
83
- if ($shippingCountry != 'NL') {
84
  $this->_removePakjeGemakAddress($order);
 
85
  $postnlOrder->delete();
86
  return $this;
87
  }
@@ -93,10 +88,45 @@ class TIG_PostNL_Model_DeliveryOptions_Observer_UpdatePostnlOrder
93
  return $this;
94
  }
95
 
96
- $postnlOrder->setOrderId($order->getId())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  ->setIsActive(false)
98
  ->save();
99
 
 
 
 
100
  if ($postnlOrder->getIsPakjeGemak() || $postnlOrder->getIsPakketautomaat()) {
101
  $this->copyPakjeGemakAddressToOrder($order);
102
  }
@@ -117,6 +147,14 @@ class TIG_PostNL_Model_DeliveryOptions_Observer_UpdatePostnlOrder
117
  * @var Mage_Sales_Model_Quote $quote
118
  */
119
  $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
 
 
 
 
 
 
 
 
120
  $quoteAddresses = $quote->getAllAddresses();
121
 
122
  /**
@@ -147,6 +185,15 @@ class TIG_PostNL_Model_DeliveryOptions_Observer_UpdatePostnlOrder
147
  $order->addAddress($orderAddress)
148
  ->save();
149
 
 
 
 
 
 
 
 
 
 
150
  /**
151
  * This is required for some PSP extensions which will not save the PakjeGemak address otherwise.
152
  *
39
  class TIG_PostNL_Model_DeliveryOptions_Observer_UpdatePostnlOrder
40
  {
41
  /**
42
+ * Updates the PostNL order after the order has been placed. Also copies the PakjeGemak quote address to the order
43
+ * as an order address or deletes it if it's no longer needed.
44
+ *
45
  * @param Varien_Event_Observer $observer
46
  *
47
  * @return $this
57
  */
58
  $order = $observer->getOrder();
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  /**
61
  * Get the PostNL order associated with this order.
62
  *
65
  $postnlOrder = Mage::getModel('postnl_core/order')->load($order->getQuoteId(), 'quote_id');
66
 
67
  /**
68
+ * Get all shipping methods that are considered to be PostNL.
69
+ */
70
+ $shippingMethod = $order->getShippingMethod();
71
+
72
+ /**
73
+ * If this order is not being shipped to the Netherlands or was not placed using PostNL, remove any PakjeGemak
74
+ * addresses that may have been saved and delete the PostNL order.
75
  */
76
  $shippingCountry = $order->getShippingAddress()->getCountryId();
77
+ if ($shippingCountry != 'NL' || !Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
78
  $this->_removePakjeGemakAddress($order);
79
+
80
  $postnlOrder->delete();
81
  return $this;
82
  }
88
  return $this;
89
  }
90
 
91
+ /**
92
+ * Update the order's shipment costs. If the order type is PGE or Avond, this will be a fee as configured in
93
+ * system > config. Otherwise it will be set to 0.
94
+ */
95
+ $fee = 0;
96
+ $type = $postnlOrder->getType();
97
+ if ($type == 'PGE' || $type == 'Avond') {
98
+ /**
99
+ * Check whether the shipping prices are entered with or without tax.
100
+ */
101
+ $includingTax = false;
102
+ if (Mage::getSingleton('tax/config')->shippingPriceIncludesTax()) {
103
+ $includingTax = true;
104
+ }
105
+
106
+ /**
107
+ * Calculate the correct fee based on the order type.
108
+ */
109
+ $type = $postnlOrder->getType();
110
+ if ($type == 'PGE') {
111
+ $fee = Mage::helper('postnl/deliveryOptions')
112
+ ->getExpressFee(false, $includingTax, false);
113
+ } elseif ($type == 'Avond') {
114
+ $fee = Mage::helper('postnl/deliveryOptions')
115
+ ->getEveningFee(false, $includingTax, false);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Update the PostNL order.
121
+ */
122
+ $postnlOrder->setShipmentCosts($fee)
123
+ ->setOrderId($order->getId())
124
  ->setIsActive(false)
125
  ->save();
126
 
127
+ /**
128
+ * Copy the PakjeGemak address to the order if this was a PakjeGemak order.
129
+ */
130
  if ($postnlOrder->getIsPakjeGemak() || $postnlOrder->getIsPakketautomaat()) {
131
  $this->copyPakjeGemakAddressToOrder($order);
132
  }
147
  * @var Mage_Sales_Model_Quote $quote
148
  */
149
  $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
150
+ if (!$quote || !$quote->getId()) {
151
+ $quote = $order->getQuote();
152
+ }
153
+
154
+ if (!$quote || !$quote->getId()) {
155
+ return $this;
156
+ }
157
+
158
  $quoteAddresses = $quote->getAllAddresses();
159
 
160
  /**
185
  $order->addAddress($orderAddress)
186
  ->save();
187
 
188
+ /**
189
+ * This is a fix for the order address missing a parent ID.
190
+ *
191
+ * @since v1.3.0
192
+ */
193
+ if (!$orderAddress->getParentId()) {
194
+ $orderAddress->setParentId($order->getId());
195
+ }
196
+
197
  /**
198
  * This is required for some PSP extensions which will not save the PakjeGemak address otherwise.
199
  *
app/code/community/TIG/PostNL/Model/DeliveryOptions/Product/Attribute/Source/ShippingDuration.php CHANGED
@@ -54,7 +54,7 @@ class TIG_PostNL_Model_DeliveryOptions_Product_Attribute_Source_ShippingDuration
54
 
55
  $options = array(
56
  array(
57
- 'label' => $helper->__('Use config'),
58
  'value' => ''
59
  ),
60
  array(
54
 
55
  $options = array(
56
  array(
57
+ 'label' => $helper->__('Use configuration value'),
58
  'value' => ''
59
  ),
60
  array(
app/code/community/TIG/PostNL/Model/DeliveryOptions/Service.php CHANGED
@@ -55,7 +55,7 @@ class TIG_PostNL_Model_DeliveryOptions_Service extends Varien_Object
55
  /**
56
  * Xpath for shipping duration setting.
57
  */
58
- const XPATH_SHIPPING_DURATION = 'postnl/delivery_options/shipping_duration';
59
 
60
  /**
61
  * Gets a PostNL Order. If none is set; load one.
@@ -133,13 +133,16 @@ class TIG_PostNL_Model_DeliveryOptions_Service extends Varien_Object
133
  return $this->_getData('confirm_date');
134
  }
135
 
136
- $deliveryDate = strtotime($deliveryDate);
137
- $deliveryDay = date('N');
138
 
139
- $shippingDuration = $this->getShippingDuration($deliveryDay);
140
- $confirmDate = strtotime("-{$shippingDuration} days", $deliveryDate);
 
 
141
 
142
- $confirmDate = date('Y-m-d', $confirmDate);
 
143
 
144
  $this->setConfirmDate($confirmDate);
145
  return $confirmDate;
55
  /**
56
  * Xpath for shipping duration setting.
57
  */
58
+ const XPATH_SHIPPING_DURATION = 'postnl/cif_labels_and_confirming/shipping_duration';
59
 
60
  /**
61
  * Gets a PostNL Order. If none is set; load one.
133
  return $this->_getData('confirm_date');
134
  }
135
 
136
+ $deliveryDate = new DateTime($deliveryDate);
137
+ $deliveryDay = $deliveryDate->format('N');
138
 
139
+ $shippingDuration = 1;
140
+ if ($deliveryDay == 1 && !Mage::helper('postnl/deliveryOptions')->canUseSundaySorting()) {
141
+ $shippingDuration++;
142
+ }
143
 
144
+ $confirmDate = $deliveryDate->sub(new DateInterval("P{$shippingDuration}D"));
145
+ $confirmDate = $confirmDate->format('Y-m-d');
146
 
147
  $this->setConfirmDate($confirmDate);
148
  return $confirmDate;
app/code/community/TIG/PostNL/Model/ExtensionControl/Feed.php CHANGED
@@ -41,8 +41,8 @@ class TIG_PostNL_Model_ExtensionControl_Feed extends Mage_AdminNotification_Mode
41
  /**
42
  * The XMl feed's url and protocol.
43
  */
44
- const XML_PATH_FEED_USE_HTTPS = 'postnl/advanced/feed_use_https';
45
- const XML_PATH_FEED_URL = 'postnl/advanced/feed_url';
46
 
47
  /**
48
  * Retrieve feed url.
@@ -58,12 +58,12 @@ class TIG_PostNL_Model_ExtensionControl_Feed extends Mage_AdminNotification_Mode
58
  $adminStoreId = Mage_Core_Model_App::ADMIN_STORE_ID;
59
 
60
  $scheme = 'http://';
61
- $useHttps = Mage::getStoreConfigFlag(self::XML_PATH_FEED_USE_HTTPS, $adminStoreId);
62
  if ($useHttps) {
63
  $scheme = 'https://';
64
  }
65
 
66
- $feedUrl = $scheme . Mage::getStoreConfig(self::XML_PATH_FEED_URL, $adminStoreId);
67
 
68
  $this->setFeedurl($feedUrl);
69
  return $feedUrl;
41
  /**
42
  * The XMl feed's url and protocol.
43
  */
44
+ const XPATH_FEED_USE_HTTPS = 'postnl/advanced/feed_use_https';
45
+ const XPATH_FEED_URL = 'postnl/advanced/feed_url';
46
 
47
  /**
48
  * Retrieve feed url.
58
  $adminStoreId = Mage_Core_Model_App::ADMIN_STORE_ID;
59
 
60
  $scheme = 'http://';
61
+ $useHttps = Mage::getStoreConfigFlag(self::XPATH_FEED_USE_HTTPS, $adminStoreId);
62
  if ($useHttps) {
63
  $scheme = 'https://';
64
  }
65
 
66
+ $feedUrl = $scheme . Mage::getStoreConfig(self::XPATH_FEED_URL, $adminStoreId);
67
 
68
  $this->setFeedurl($feedUrl);
69
  return $feedUrl;
app/code/community/TIG/PostNL/Model/ExtensionControl/Webservices.php CHANGED
@@ -51,34 +51,50 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
51
  /**
52
  * XML paths for security keys
53
  */
54
- const XML_PATH_EXTENSIONCONTROL_UNIQUE_KEY = 'postnl/general/unique_key';
55
- const XML_PATH_EXTENSIONCONTROL_PRIVATE_KEY = 'postnl/general/private_key';
56
 
57
  /**
58
  * XML paths for webshop activation settings
59
  */
60
- const XML_PATH_GENERAL_EMAIL = 'postnl/general/email';
61
- const XML_PATH_UNSECURE_BASE_URL = 'web/unsecure/base_url';
62
 
63
  /**
64
  * XML paths for setting statistics
65
  */
66
- const XML_PATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
67
- const XML_PATH_SPLIT_STREET = 'postnl/cif_address/split_street';
68
- const XML_PATH_CHECKOUT_ACTIVE = 'postnl/checkout/active';
69
- const XML_PATH_CHECKOUT_WEBSHOP_ID = 'postnl/cif/webshop_id';
70
- const XML_PATH_CONTACT_NAME = 'postnl/cif/contact_name';
71
- const XML_PATH_CUSTOMER_NUMBER = 'postnl/cif/customer_number';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  /**
74
  * XML path to extension activation setting
75
  */
76
- const XML_PATH_ACTIVE = 'postnl/general/active';
77
 
78
  /**
79
  * XML path to 'is_activated' flag
80
  */
81
- const XML_PATH_IS_ACTIVATED = 'postnl/general/is_activated';
82
 
83
  /**
84
  * Expected success response
@@ -234,9 +250,9 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
234
  /**
235
  * If a successful update has taken place we can confirm that the extension has been activated
236
  */
237
- $isActivated = Mage::getStoreConfig(self::XML_PATH_IS_ACTIVATED, Mage_Core_Model_App::ADMIN_STORE_ID);
238
  if (!$isActivated || $isActivated == '1') {
239
- Mage::getModel('core/config')->saveConfig(self::XML_PATH_IS_ACTIVATED, 2);
240
  }
241
 
242
  return $result;
@@ -291,23 +307,52 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
291
  */
292
  $websites = array();
293
  foreach (Mage::app()->getWebsites() as $website) {
294
- $extensionEnabled = $website->getConfig(self::XML_PATH_ACTIVE);
295
  if (!$extensionEnabled) {
296
  continue;
297
  }
298
 
299
  $websites[] = array(
300
- 'websiteId' => $website->getId(),
301
- 'hostName' => $this->_getHostName($website),
302
- 'amountOfShipments' => $this->_getAmountOfShipments($website),
303
- 'merchantName' => $this->_getMerchantName($website),
304
- 'lastOrderDate' => $this->_getLastOrderDate($website),
305
- 'settings' => array(
306
- 'globalShipping' => $this->_getUsesGlobalShipping($website),
307
- 'splitAddress' => $this->_getUsesSplitAddress($website),
308
- 'postnlCheckout' => $this->_getUsesPostnlCheckout($website),
309
- 'postnlCheckoutWebshopId' => $this->_getCheckoutWebshopId($website),
310
- 'customerNumber' => $this->_getCustomerNumber($website),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  ),
312
  );
313
  }
@@ -323,7 +368,7 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
323
  */
324
  protected function _getEmail()
325
  {
326
- $email = Mage::getStoreConfig(self::XML_PATH_GENERAL_EMAIL, Mage_Core_Model_App::ADMIN_STORE_ID);
327
 
328
  return $email;
329
  }
@@ -350,7 +395,7 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
350
  /**
351
  * Get the website's base URL
352
  */
353
- $baseUrl = $website->getConfig(self::XML_PATH_UNSECURE_BASE_URL, $website->getId());
354
 
355
  /**
356
  * Parse the URL and get the host name
@@ -368,7 +413,7 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
368
  */
369
  protected function _getUniqueKey()
370
  {
371
- $uniqueKey = Mage::getStoreConfig(self::XML_PATH_EXTENSIONCONTROL_UNIQUE_KEY, Mage_Core_Model_App::ADMIN_STORE_ID);
372
  $uniqueKey = Mage::helper('core')->decrypt($uniqueKey);
373
 
374
  $uniqueKey = trim($uniqueKey);
@@ -383,7 +428,10 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
383
  */
384
  protected function _getPrivateKey()
385
  {
386
- $privateKey = Mage::getStoreConfig(self::XML_PATH_EXTENSIONCONTROL_PRIVATE_KEY, Mage_Core_Model_App::ADMIN_STORE_ID);
 
 
 
387
  $privateKey = Mage::helper('core')->decrypt($privateKey);
388
 
389
  $privateKey = trim($privateKey);
@@ -395,10 +443,31 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
395
  * Get the number of PostNL shipments a specified website has sent
396
  *
397
  * @param Mage_Core_Model_Website $website
 
398
  *
399
  * @return int
400
  */
401
- protected function _getAmountOfShipments($website)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  {
403
  /**
404
  * Get a list of all storeIds associated with this website
@@ -418,8 +487,6 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
418
 
419
  $resource = Mage::getSingleton('core/resource');
420
 
421
- $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
422
-
423
  /**
424
  * Get the shipment collection
425
  */
@@ -435,15 +502,41 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
435
  array('order' => $resource->getTableName('sales/order')),
436
  '`main_table`.`order_id`=`order`.`entity_id`',
437
  array(
438
- 'shipping_method' => 'order.shipping_method',
439
  )
440
  );
441
 
442
- $shipmentCollection->addFieldToFilter('`shipping_method`', array('in' => $postnlShippingMethods))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
  ->addFieldToFilter('`main_table`.`store_id`', array('in' => $storeIds));
444
 
445
- $amountOfShipments = $shipmentCollection->getSize();
446
- return $amountOfShipments;
 
 
 
447
  }
448
 
449
  /**
@@ -522,7 +615,7 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
522
  */
523
  protected function _getMerchantName($website)
524
  {
525
- $name = $website->getConfig(self::XML_PATH_CONTACT_NAME);
526
 
527
  return $name;
528
  }
@@ -539,7 +632,7 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
539
  /**
540
  * Get a list of supported product options and a list of global product options
541
  */
542
- $supportedProductOptions = $website->getConfig(self::XML_PATH_SUPPORTED_PRODUCT_OPTIONS);
543
  $supportedProductOptions = explode(',', $supportedProductOptions);
544
 
545
  $globalProductOptions = Mage::helper('postnl/cif')->getGlobalProductCodes();
@@ -565,7 +658,7 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
565
  */
566
  protected function _getUsesSplitAddress($website)
567
  {
568
- $splitStreet = (bool) $website->getConfig(self::XML_PATH_SPLIT_STREET);
569
 
570
  return $splitStreet;
571
  }
@@ -579,7 +672,7 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
579
  */
580
  protected function _getUsesPostnlCheckout($website)
581
  {
582
- $checkoutActive = (bool) $website->getConfig(self::XML_PATH_CHECKOUT_ACTIVE);
583
 
584
  return $checkoutActive;
585
  }
@@ -593,7 +686,7 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
593
  */
594
  protected function _getCheckoutWebshopId($website)
595
  {
596
- $webshopId = $website->getConfig(self::XML_PATH_CHECKOUT_WEBSHOP_ID);
597
  $webshopId = Mage::helper('core')->decrypt($webshopId);
598
 
599
  return $webshopId;
@@ -608,8 +701,226 @@ class TIG_PostNL_Model_ExtensionControl_Webservices extends TIG_PostNL_Model_Ext
608
  */
609
  protected function _getCustomerNumber($website)
610
  {
611
- $webshopId = $website->getConfig(self::XML_PATH_CUSTOMER_NUMBER);
612
 
613
  return $webshopId;
614
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
615
  }
51
  /**
52
  * XML paths for security keys
53
  */
54
+ const XPATH_EXTENSIONCONTROL_UNIQUE_KEY = 'postnl/general/unique_key';
55
+ const XPATH_EXTENSIONCONTROL_PRIVATE_KEY = 'postnl/general/private_key';
56
 
57
  /**
58
  * XML paths for webshop activation settings
59
  */
60
+ const XPATH_GENERAL_EMAIL = 'postnl/general/email';
61
+ const XPATH_UNSECURE_BASE_URL = 'web/unsecure/base_url';
62
 
63
  /**
64
  * XML paths for setting statistics
65
  */
66
+ const XPATH_SUPPORTED_PRODUCT_OPTIONS = 'postnl/cif_product_options/supported_product_options';
67
+ const XPATH_SPLIT_STREET = 'postnl/cif_address/split_street';
68
+ const XPATH_CHECKOUT_ACTIVE = 'postnl/checkout/active';
69
+ const XPATH_CHECKOUT_WEBSHOP_ID = 'postnl/cif/webshop_id';
70
+ const XPATH_CONTACT_NAME = 'postnl/cif/contact_name';
71
+ const XPATH_CUSTOMER_NUMBER = 'postnl/cif/customer_number';
72
+ const XPATH_DELIVERY_OPTIONS_ACTIVE = 'postnl/delivery_options/delivery_options_active';
73
+ const XPATH_ENABLE_DELIVERY_DAYS = 'postnl/delivery_options/enable_delivery_days';
74
+ const XPATH_ENABLE_TIMEFRAMES = 'postnl/delivery_options/enable_timeframes';
75
+ const XPATH_ENABLE_EVENING_TIMEFRAMES = 'postnl/delivery_options/enable_evening_timeframes';
76
+ const XPATH_ENABLE_PAKJEGEMAK = 'postnl/delivery_options/enable_pakjegemak';
77
+ const XPATH_ENABLE_PAKKETAUTOMAAT_LOCATIONS = 'postnl/delivery_options/enable_pakketautomaat_locations';
78
+ const XPATH_ENABLE_PAKJEGEMAK_EXPRESS = 'postnl/delivery_options/enable_pakjegemak_express';
79
+ const XPATH_USE_BUSPAKJE = 'postnl/cif_labels_and_confirming/use_buspakje';
80
+ const XPATH_BUSPAKJE_CALCULATION_MODE = 'postnl/cif_labels_and_confirming/buspakje_calculation_mode';
81
+ const XPATH_COD_ACTIVE = 'payment/postnl_cod/active';
82
+ const XPATH_MIJNPAKKET_LOGIN_ACTIVE = 'postnl/delivery_options/mijnpakket_login_active';
83
+ const XPATH_USE_POSTCODE_CHECK = 'postnl/cif_address/use_postcode_check';
84
+ const XPATH_PARCELWARE_EXPORT_ACTIVE = 'postnl/parcelware_export/active';
85
+ const XPATH_SEND_TRACK_AND_TRACE_EMAIL = 'postnl/cif_labels_and_confirming/send_track_and_trace_email';
86
+ const XPATH_TRACK_AND_TRACE_EMAIL_TEMPLATE = 'postnl/cif_labels_and_confirming/track_and_trace_email_template';
87
+ const XPATH_SHOW_LABEL = 'postnl/packing_slip/show_label';
88
 
89
  /**
90
  * XML path to extension activation setting
91
  */
92
+ const XPATH_ACTIVE = 'postnl/general/active';
93
 
94
  /**
95
  * XML path to 'is_activated' flag
96
  */
97
+ const XPATH_IS_ACTIVATED = 'postnl/general/is_activated';
98
 
99
  /**
100
  * Expected success response
250
  /**
251
  * If a successful update has taken place we can confirm that the extension has been activated
252
  */
253
+ $isActivated = Mage::getStoreConfig(self::XPATH_IS_ACTIVATED, Mage_Core_Model_App::ADMIN_STORE_ID);
254
  if (!$isActivated || $isActivated == '1') {
255
+ Mage::getModel('core/config')->saveConfig(self::XPATH_IS_ACTIVATED, 2);
256
  }
257
 
258
  return $result;
307
  */
308
  $websites = array();
309
  foreach (Mage::app()->getWebsites() as $website) {
310
+ $extensionEnabled = $website->getConfig(self::XPATH_ACTIVE);
311
  if (!$extensionEnabled) {
312
  continue;
313
  }
314
 
315
  $websites[] = array(
316
+ 'websiteId' => $website->getId(),
317
+ 'hostName' => $this->_getHostName($website),
318
+ 'amountOfShipments' => $this->_getAmountOfShipments($website),
319
+ 'amountOfShipmentsStandard' => $this->_getAmountOfShipments($website, array('domestic')),
320
+ 'amountOfShipmentsPg' => $this->_getAmountOfShipments($website, array('pg')),
321
+ 'amountOfShipmentsPa' => $this->_getAmountOfShipments($website, array('pa')),
322
+ 'amountOfShipmentsPge' => $this->_getAmountOfShipments($website, array('pge')),
323
+ 'amountOfShipmentsAvond' => $this->_getAmountOfShipments($website, array('avond')),
324
+ 'amountOfShipmentsCod' => $this->_getAmountOfShipments(
325
+ $website,
326
+ array(
327
+ 'domestic_cod',
328
+ 'pg_cod',
329
+ 'pge_cod'
330
+ )
331
+ ),
332
+ 'amountOfShipmentsBuspakje' => $this->_getAmountOfShipments($website, array('buspakje')),
333
+ 'merchantName' => $this->_getMerchantName($website),
334
+ 'lastOrderDate' => $this->_getLastOrderDate($website),
335
+ 'settings' => array(
336
+ 'globalShipping' => $this->_getUsesGlobalShipping($website),
337
+ 'splitAddress' => $this->_getUsesSplitAddress($website),
338
+ 'postnlCheckout' => $this->_getUsesPostnlCheckout($website),
339
+ 'postnlCheckoutWebshopId' => $this->_getCheckoutWebshopId($website),
340
+ 'customerNumber' => $this->_getCustomerNumber($website),
341
+ 'useDeliveryOptions' => $this->_getUseDeliveryOptions($website),
342
+ 'useDeliveryDays' => $this->_getUseDeliveryDays($website),
343
+ 'useTimeframes' => $this->_getUseTimeframes($website),
344
+ 'useAvond' => $this->_getUseAvond($website),
345
+ 'usePg' => $this->_getUsePg($website),
346
+ 'usePa' => $this->_getUsePa($website),
347
+ 'usePge' => $this->_getUsePge($website),
348
+ 'modeBuspakje' => $this->_getBuspakjeCalcMode($website),
349
+ 'cod' => $this->_getCod($website),
350
+ 'useMijnpakketLog' => $this->_getUseMijnPakketLogin($website),
351
+ 'usePostcodeCheck' => $this->_getUsePostcodeCheck($website),
352
+ 'useParcelwareExport' => $this->_getUseParcelwareExport($website),
353
+ 'automaticallySendTrackAndTrace' => $this->_getUseSendTrackAndTrace($website),
354
+ 'modifiedTrackAndTrace' => $this->_getUseModifiedTrackAndTrace($website),
355
+ 'showShippingLabelOnPackingSlip' => $this->_getShowShippingLabelOnPackingSlip($website),
356
  ),
357
  );
358
  }
368
  */
369
  protected function _getEmail()
370
  {
371
+ $email = Mage::getStoreConfig(self::XPATH_GENERAL_EMAIL, Mage_Core_Model_App::ADMIN_STORE_ID);
372
 
373
  return $email;
374
  }
395
  /**
396
  * Get the website's base URL
397
  */
398
+ $baseUrl = $website->getConfig(self::XPATH_UNSECURE_BASE_URL, $website->getId());
399
 
400
  /**
401
  * Parse the URL and get the host name
413
  */
414
  protected function _getUniqueKey()
415
  {
416
+ $uniqueKey = Mage::getStoreConfig(self::XPATH_EXTENSIONCONTROL_UNIQUE_KEY, Mage_Core_Model_App::ADMIN_STORE_ID);
417
  $uniqueKey = Mage::helper('core')->decrypt($uniqueKey);
418
 
419
  $uniqueKey = trim($uniqueKey);
428
  */
429
  protected function _getPrivateKey()
430
  {
431
+ $privateKey = Mage::getStoreConfig(
432
+ self::XPATH_EXTENSIONCONTROL_PRIVATE_KEY,
433
+ Mage_Core_Model_App::ADMIN_STORE_ID
434
+ );
435
  $privateKey = Mage::helper('core')->decrypt($privateKey);
436
 
437
  $privateKey = trim($privateKey);
443
  * Get the number of PostNL shipments a specified website has sent
444
  *
445
  * @param Mage_Core_Model_Website $website
446
+ * @param array|boolean $shipmentTypes
447
  *
448
  * @return int
449
  */
450
+ protected function _getAmountOfShipments($website, $shipmentTypes = false)
451
+ {
452
+ if ($shipmentTypes !== false && !is_array($shipmentTypes)) {
453
+ $shipmentTypes = array($shipmentTypes);
454
+ }
455
+
456
+ $shipmentCollection = $this->_getShipmentCollection($website, $shipmentTypes);
457
+
458
+ $amountOfShipments = $shipmentCollection->getSize();
459
+ return $amountOfShipments;
460
+ }
461
+
462
+ /**
463
+ * Gets the shipment collection for a specified website.
464
+ *
465
+ * @param Mage_Core_Model_Website $website
466
+ * @param boolean|array $shipmentTypes
467
+ *
468
+ * @return Mage_Sales_Model_Resource_Order_Shipment_Collection
469
+ */
470
+ protected function _getShipmentCollection($website, $shipmentTypes = false)
471
  {
472
  /**
473
  * Get a list of all storeIds associated with this website
487
 
488
  $resource = Mage::getSingleton('core/resource');
489
 
 
 
490
  /**
491
  * Get the shipment collection
492
  */
502
  array('order' => $resource->getTableName('sales/order')),
503
  '`main_table`.`order_id`=`order`.`entity_id`',
504
  array(
505
+ 'shipping_method' => 'order.shipping_method',
506
  )
507
  );
508
 
509
+ if ($shipmentTypes) {
510
+ $select->joinLeft(
511
+ array('postnl_shipment' => $resource->getTableName('postnl_core/shipment')),
512
+ '`main_table`.`entity_id`=`postnl_shipment`.`shipment_id`',
513
+ array(
514
+ 'shipment_type' => 'postnl_shipment.shipment_type',
515
+ )
516
+ );
517
+ }
518
+
519
+ $postnlShippingMethods = Mage::helper('postnl/carrier')->getPostnlShippingMethods();
520
+ $postnlShippingMethodsRegex = '';
521
+ foreach ($postnlShippingMethods as $method) {
522
+ if ($postnlShippingMethodsRegex) {
523
+ $postnlShippingMethodsRegex .= '|';
524
+ } else {
525
+ $postnlShippingMethodsRegex .= '^';
526
+ }
527
+
528
+ $postnlShippingMethodsRegex .= "({$method})(_{0,1}[0-9]*)";
529
+ }
530
+
531
+ $postnlShippingMethodsRegex .= '$';
532
+ $shipmentCollection->addFieldToFilter('`order`.`shipping_method`', array('regexp' => $postnlShippingMethodsRegex))
533
  ->addFieldToFilter('`main_table`.`store_id`', array('in' => $storeIds));
534
 
535
+ if ($shipmentTypes) {
536
+ $shipmentCollection->addFieldToFilter('`shipment_type`', array('in', $shipmentTypes));
537
+ }
538
+
539
+ return $shipmentCollection;
540
  }
541
 
542
  /**
615
  */
616
  protected function _getMerchantName($website)
617
  {
618
+ $name = $website->getConfig(self::XPATH_CONTACT_NAME);
619
 
620
  return $name;
621
  }
632
  /**
633
  * Get a list of supported product options and a list of global product options
634
  */
635
+ $supportedProductOptions = $website->getConfig(self::XPATH_SUPPORTED_PRODUCT_OPTIONS);
636
  $supportedProductOptions = explode(',', $supportedProductOptions);
637
 
638
  $globalProductOptions = Mage::helper('postnl/cif')->getGlobalProductCodes();
658
  */
659
  protected function _getUsesSplitAddress($website)
660
  {
661
+ $splitStreet = (bool) $website->getConfig(self::XPATH_SPLIT_STREET);
662
 
663
  return $splitStreet;
664
  }
672
  */
673
  protected function _getUsesPostnlCheckout($website)
674
  {
675
+ $checkoutActive = (bool) $website->getConfig(self::XPATH_CHECKOUT_ACTIVE);
676
 
677
  return $checkoutActive;
678
  }
686
  */
687
  protected function _getCheckoutWebshopId($website)
688
  {
689
+ $webshopId = $website->getConfig(self::XPATH_CHECKOUT_WEBSHOP_ID);
690
  $webshopId = Mage::helper('core')->decrypt($webshopId);
691
 
692
  return $webshopId;
701
  */
702
  protected function _getCustomerNumber($website)
703
  {
704
+ $webshopId = $website->getConfig(self::XPATH_CUSTOMER_NUMBER);
705
 
706
  return $webshopId;
707
  }
708
+
709
+ /**
710
+ * Gets whether delivery options are used.
711
+ *
712
+ * @param Mage_Core_Model_Website $website
713
+ *
714
+ * @return boolean
715
+ */
716
+ protected function _getUseDeliveryOptions($website)
717
+ {
718
+ $useDeliveryoptions = (bool) $website->getConfig(self::XPATH_DELIVERY_OPTIONS_ACTIVE);
719
+
720
+ return $useDeliveryoptions;
721
+ }
722
+
723
+ /**
724
+ * Gets whether delivery days are used.
725
+ *
726
+ * @param Mage_Core_Model_Website $website
727
+ *
728
+ * @return boolean
729
+ */
730
+ protected function _getUseDeliveryDays($website)
731
+ {
732
+ $useDeliveryDays = (bool) $website->getConfig(self::XPATH_ENABLE_DELIVERY_DAYS);
733
+
734
+ return $useDeliveryDays;
735
+ }
736
+
737
+ /**
738
+ * Gets whether time frames are used.
739
+ *
740
+ * @param Mage_Core_Model_Website $website
741
+ *
742
+ * @return boolean
743
+ */
744
+ protected function _getUseTimeframes($website)
745
+ {
746
+ $useTimeframes = (bool) $website->getConfig(self::XPATH_ENABLE_TIMEFRAMES);
747
+
748
+ return $useTimeframes;
749
+ }
750
+
751
+ /**
752
+ * Gets whether evening delivery is used.
753
+ *
754
+ * @param Mage_Core_Model_Website $website
755
+ *
756
+ * @return boolean
757
+ */
758
+ protected function _getUseAvond($website)
759
+ {
760
+ $useAvond = (bool) $website->getConfig(self::XPATH_ENABLE_EVENING_TIMEFRAMES);
761
+
762
+ return $useAvond;
763
+ }
764
+
765
+ /**
766
+ * Gets whether PG is used.
767
+ *
768
+ * @param Mage_Core_Model_Website $website
769
+ *
770
+ * @return boolean
771
+ */
772
+ protected function _getUsePg($website)
773
+ {
774
+ $usePg = (bool) $website->getConfig(self::XPATH_ENABLE_PAKJEGEMAK);
775
+
776
+ return $usePg;
777
+ }
778
+
779
+ /**
780
+ * Gets whether PA is used.
781
+ *
782
+ * @param Mage_Core_Model_Website $website
783
+ *
784
+ * @return boolean
785
+ */
786
+ protected function _getUsePa($website)
787
+ {
788
+ $usePa = (bool) $website->getConfig(self::XPATH_ENABLE_PAKKETAUTOMAAT_LOCATIONS);
789
+
790
+ return $usePa;
791
+ }
792
+
793
+ /**
794
+ * Gets whether PGE is used.
795
+ *
796
+ * @param Mage_Core_Model_Website $website
797
+ *
798
+ * @return boolean
799
+ */
800
+ protected function _getUsePge($website)
801
+ {
802
+ $usePge = (bool) $website->getConfig(self::XPATH_ENABLE_PAKJEGEMAK_EXPRESS);
803
+
804
+ return $usePge;
805
+ }
806
+
807
+ /**
808
+ * Gets the buspakje calculation mode.
809
+ *
810
+ * @param Mage_Core_Model_Website $website
811
+ *
812
+ * @return string
813
+ */
814
+ protected function _getBuspakjeCalcMode($website)
815
+ {
816
+ $useBuspakje = (bool) $website->getConfig(self::XPATH_USE_BUSPAKJE);
817
+ if (!$useBuspakje) {
818
+ return 'off';
819
+ }
820
+
821
+ $buspakjeCalcMode = $website->getConfig(self::XPATH_BUSPAKJE_CALCULATION_MODE);
822
+
823
+ return $buspakjeCalcMode;
824
+ }
825
+
826
+ /**
827
+ * Gets whether PostNL COD is used.
828
+ *
829
+ * @param Mage_Core_Model_Website $website
830
+ *
831
+ * @return boolean
832
+ */
833
+ protected function _getCod($website)
834
+ {
835
+ $cod = (bool) $website->getConfig(self::XPATH_COD_ACTIVE);
836
+
837
+ return $cod;
838
+ }
839
+
840
+ /**
841
+ * Gets whether MijnPakket login is used.
842
+ *
843
+ * @param Mage_Core_Model_Website $website
844
+ *
845
+ * @return boolean
846
+ */
847
+ protected function _getUseMijnPakketLogin($website)
848
+ {
849
+ $useMijnPakketLogin = (bool) $website->getConfig(self::XPATH_MIJNPAKKET_LOGIN_ACTIVE);
850
+
851
+ return $useMijnPakketLogin;
852
+ }
853
+
854
+ /**
855
+ * Gets whether postcode check is active.
856
+ *
857
+ * @param Mage_Core_Model_Website $website
858
+ *
859
+ * @return boolean
860
+ */
861
+ protected function _getUsePostcodeCheck($website)
862
+ {
863
+ $usePostcodeCheck = (bool) $website->getConfig(self::XPATH_USE_POSTCODE_CHECK);
864
+
865
+ return $usePostcodeCheck;
866
+ }
867
+
868
+ /**
869
+ * Gets whether parcelware export is active.
870
+ *
871
+ * @param Mage_Core_Model_Website $website
872
+ *
873
+ * @return boolean
874
+ */
875
+ protected function _getUseParcelwareExport($website)
876
+ {
877
+ $useParcelwareExport = (bool) $website->getConfig(self::XPATH_PARCELWARE_EXPORT_ACTIVE);
878
+
879
+ return $useParcelwareExport;
880
+ }
881
+
882
+ /**
883
+ * Gets whether the track&trace email is sent automatically.
884
+ *
885
+ * @param Mage_Core_Model_Website $website
886
+ *
887
+ * @return boolean
888
+ */
889
+ protected function _getUseSendTrackAndTrace($website)
890
+ {
891
+ $useSendTrackAndTrace = (bool) $website->getConfig(self::XPATH_SEND_TRACK_AND_TRACE_EMAIL);
892
+
893
+ return $useSendTrackAndTrace;
894
+ }
895
+
896
+ /**
897
+ * Gets whether a modified track&trace email template is used.
898
+ *
899
+ * @param Mage_Core_Model_Website $website
900
+ *
901
+ * @return boolean
902
+ */
903
+ protected function _getUseModifiedTrackAndTrace($website)
904
+ {
905
+ $template = $website->getConfig(self::XPATH_TRACK_AND_TRACE_EMAIL_TEMPLATE);
906
+ if ($template != 'postnl_cif_labels_and_confirming_track_and_trace_email_template') {
907
+ return true;
908
+ }
909
+
910
+ return false;
911
+ }
912
+
913
+ /**
914
+ * Gets whether the packing slip includes the PostNl shipping label.
915
+ *
916
+ * @param Mage_Core_Model_Website $website
917
+ *
918
+ * @return boolean
919
+ */
920
+ protected function _getShowShippingLabelOnPackingSlip($website)
921
+ {
922
+ $showShippingLabel = (bool) $website->getConfig(self::XPATH_SHOW_LABEL);
923
+
924
+ return $showShippingLabel;
925
+ }
926
  }
app/code/community/TIG/PostNL/Model/Inbox.php CHANGED
@@ -36,154 +36,10 @@
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
- * The only reason this class exists is because the add() method and it's derivatives are only present since EE 1.12 and
40
- * CE 1.7. This class adds those methods in case they're missing. Each method will return it's parent if it exists to
41
- * ensure forwards compatibility.
42
  */
43
- class TIG_PostNL_Model_Inbox extends Mage_AdminNotification_Model_Inbox
44
  {
45
- /**
46
- * Add new message.
47
- *
48
- * @param int $severity
49
- * @param string $title
50
- * @param string|array $description
51
- * @param string $url
52
- * @param bool $isInternal
53
- *
54
- * @throws TIG_PostNL_Exception
55
- *
56
- * @return Mage_AdminNotification_Model_Inbox
57
- */
58
- public function add($severity, $title, $description, $url = '', $isInternal = true)
59
- {
60
- if ($this->_parentMethodExists($this, 'add')) {
61
- return parent::add($severity, $title, $description, $url, $isInternal);
62
- }
63
 
64
- if (!$this->getSeverities($severity)) {
65
- throw new TIG_PostNL_Exception(Mage::helper('postnl')->__('Wrong message type'), 'POSTNL-0087');
66
- }
67
-
68
- if (is_array($description)) {
69
- $description = '<ul><li>' . implode('</li><li>', $description) . '</li></ul>';
70
- }
71
-
72
- $date = date('Y-m-d H:i:s');
73
- $this->parse(
74
- array(
75
- array(
76
- 'severity' => $severity,
77
- 'date_added' => $date,
78
- 'title' => $title,
79
- 'description' => $description,
80
- 'url' => $url,
81
- 'internal' => $isInternal
82
- )
83
- )
84
- );
85
- return $this;
86
- }
87
-
88
- /**
89
- * Add critical severity message.
90
- *
91
- * @param string $title
92
- * @param string|array $description
93
- * @param string $url
94
- * @param bool $isInternal
95
- *
96
- * @return Mage_AdminNotification_Model_Inbox
97
- */
98
- public function addCritical($title, $description, $url = '', $isInternal = true)
99
- {
100
- if ($this->_parentMethodExists($this, 'addCritical')) {
101
- return parent::addCritical($title, $description, $url, $isInternal);
102
- }
103
-
104
- $this->add(self::SEVERITY_CRITICAL, $title, $description, $url, $isInternal);
105
- return $this;
106
- }
107
-
108
- /**
109
- * Add major severity message.
110
- *
111
- * @param string $title
112
- * @param string|array $description
113
- * @param string $url
114
- * @param bool $isInternal
115
- *
116
- * @return Mage_AdminNotification_Model_Inbox
117
- */
118
- public function addMajor($title, $description, $url = '', $isInternal = true)
119
- {
120
- if ($this->_parentMethodExists($this, 'addMajor')) {
121
- return parent::addMajor($title, $description, $url, $isInternal);
122
- }
123
-
124
- $this->add(self::SEVERITY_MAJOR, $title, $description, $url, $isInternal);
125
- return $this;
126
- }
127
-
128
- /**
129
- * Add minor severity message.
130
- *
131
- * @param string $title
132
- * @param string|array $description
133
- * @param string $url
134
- * @param bool $isInternal
135
- *
136
- * @return Mage_AdminNotification_Model_Inbox
137
- */
138
- public function addMinor($title, $description, $url = '', $isInternal = true)
139
- {
140
- if ($this->_parentMethodExists($this, 'addMinor')) {
141
- return parent::addMinor($title, $description, $url, $isInternal);
142
- }
143
-
144
- $this->add(self::SEVERITY_MINOR, $title, $description, $url, $isInternal);
145
- return $this;
146
- }
147
-
148
- /**
149
- * Add notice.
150
- *
151
- * @param string $title
152
- * @param string|array $description
153
- * @param string $url
154
- * @param bool $isInternal
155
- *
156
- * @return Mage_AdminNotification_Model_Inbox
157
- */
158
- public function addNotice($title, $description, $url = '', $isInternal = true)
159
- {
160
- if ($this->_parentMethodExists($this, 'addNotice')) {
161
- return parent::addNotice($title, $description, $url, $isInternal);
162
- }
163
-
164
- $this->add(self::SEVERITY_NOTICE, $title, $description, $url, $isInternal);
165
- return $this;
166
- }
167
-
168
- /**
169
- * Checks parent class to see if the specified method exists.
170
- *
171
- * @param object $object
172
- * @param string $method
173
- *
174
- * @return boolean
175
- */
176
- protected function _parentMethodExists($object, $method)
177
- {
178
- $parentClass = get_parent_class($object);
179
- if ($parentClass === false) {
180
- return false;
181
- }
182
-
183
- if (method_exists($parentClass, $method)) {
184
- return true;
185
- }
186
-
187
- return false;
188
- }
189
  }
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.3.0 This class has been moved to TIG_PostNL_Model_Admin_Inbox. 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_Inbox extends TIG_PostNL_Model_Admin_Inbox
43
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
app/code/community/TIG/PostNL/Model/Mijnpakket/Observer/Onepage.php DELETED
@@ -1,123 +0,0 @@
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 hasLoginBlockClass()
40
- * @method TIG_PostNL_Model_Mijnpakket_Observer_Onepage setLoginBlockClass(string $value)
41
- * @method boolean hasSuccessBlockClass()
42
- * @method TIG_PostNL_Model_Mijnpakket_Observer_Onepage setSuccessBlockClass(string $value)
43
- */
44
- class TIG_PostNL_Model_Mijnpakket_Observer_Onepage extends Varien_Object
45
- {
46
- /**
47
- * The block class that we want to edit.
48
- */
49
- const SUCCESS_BLOCK_NAME = 'checkout/onepage_success';
50
-
51
- /**
52
- * Xpath to the MijnPakket notification setting.
53
- */
54
- const XPATH_MIJNPAKKET_NOTIFICATION = 'postnl/delivery_options/mijnpakket_notification';
55
-
56
- /**
57
- * The new template.
58
- */
59
- const ACCOUNT_NOTIFICATION_TEMPLATE = 'TIG/PostNL/mijnpakket/onepage/success.phtml';
60
-
61
- /**
62
- * Gets the classname for the checkout success block that we want to alter.
63
- *
64
- * @return string
65
- */
66
- public function getSucessBlockClass()
67
- {
68
- if ($this->hasSuccessBlockClass()) {
69
- return $this->_getData('success_block_class');
70
- }
71
-
72
- $blockClass = Mage::getConfig()->getBlockClassName(self::SUCCESS_BLOCK_NAME);
73
-
74
- $this->setSuccessBlockClass($blockClass);
75
- return $blockClass;
76
- }
77
-
78
- /**
79
- * Replace the onepage checkout success template.
80
- *
81
- * @param Varien_Event_Observer $observer
82
- *
83
- * @return $this
84
- *
85
- * @event core_block_abstract_to_html_before
86
- *
87
- * @observer checkout_onepage_mijnpakket_success
88
- */
89
- public function addAccountNotification(Varien_Event_Observer $observer)
90
- {
91
- /**
92
- * Checks if the current block is the one we want to edit.
93
- *
94
- * Unfortunately there is no unique event for this block.
95
- *
96
- * @var Mage_Core_Block_Abstract $block
97
- */
98
- $block = $observer->getBlock();
99
- $blockClass = $this->getSucessBlockClass();
100
-
101
- if (!$block || !is_object($block) || get_class($block) != $blockClass) {
102
- return $this;
103
- }
104
-
105
- if (!Mage::helper('postnl/deliveryOptions')->canUseDeliveryOptions()) {
106
- return $this;
107
- }
108
-
109
- $storeId = Mage::app()->getStore()->getId();
110
- $canShowNotification = Mage::getStoreConfigFlag(self::XPATH_MIJNPAKKET_NOTIFICATION, $storeId);
111
-
112
- if (!$canShowNotification) {
113
- return $this;
114
- }
115
-
116
- /**
117
- * @var Mage_Checkout_Block_Onepage_Success $block
118
- */
119
- $block->setTemplate(self::ACCOUNT_NOTIFICATION_TEMPLATE);
120
-
121
- return $this;
122
- }
123
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/TIG/PostNL/Model/Parcelware/Export.php CHANGED
@@ -44,9 +44,9 @@ class TIG_PostNL_Model_Parcelware_Export extends TIG_PostNL_Model_Core_Cif
44
  /**
45
  * XML paths to Parcelware references
46
  */
47
- const XML_PATH_CONTRACT_REF_NR = 'postnl/parcelware_export/contract_ref_nr';
48
- const XML_PATH_CONTRACT_NAME = 'postnl/parcelware_export/contract_name';
49
- const XML_PATH_SENDER_REF_NR = 'postnl/parcelware_export/sender_ref_nr';
50
 
51
  /**
52
  * @var Mage_Core_Model_Resource_Transaction|void
@@ -362,7 +362,7 @@ class TIG_PostNL_Model_Parcelware_Export extends TIG_PostNL_Model_Core_Cif
362
  'Street' => $streetData['streetname'],
363
  'HouseNr' => $streetData['housenumber'],
364
  'HouseNrExt' => $streetData['housenumberExtension'],
365
- 'Zipcode' => $address->getPostcode(),
366
  'City' => $address->getCity(),
367
  'Countrycode' => $address->getCountryId(),
368
  'CustomerEmail' => $address->getEmail(),
@@ -411,7 +411,7 @@ class TIG_PostNL_Model_Parcelware_Export extends TIG_PostNL_Model_Core_Cif
411
  'PG_Street' => $streetData['streetname'],
412
  'PG_HouseNr' => $streetData['housenumber'],
413
  'PG_HouseNrExt' => $streetData['housenumberExtension'],
414
- 'PG_Zipcode' => $pakjeGemakAddress->getPostcode(),
415
  'PG_City' => $pakjeGemakAddress->getCity(),
416
  'PG_Countrycode' => $pakjeGemakAddress->getCountryId(),
417
  );
@@ -552,6 +552,8 @@ class TIG_PostNL_Model_Parcelware_Export extends TIG_PostNL_Model_Core_Cif
552
  $itemCount = 0;
553
  $items = $this->_sortCustomsItems($shipment->getAllItems());
554
 
 
 
555
  /**
556
  * @var Mage_Sales_Model_Order_Shipment_Item $item
557
  */
@@ -566,7 +568,7 @@ class TIG_PostNL_Model_Parcelware_Export extends TIG_PostNL_Model_Core_Cif
566
  /**
567
  * Calculate the item's weight in kg
568
  */
569
- $itemWeight = Mage::helper('postnl/cif')->standardizeWeight(
570
  $item->getWeight(),
571
  $this->getStoreId()
572
  );
@@ -594,7 +596,7 @@ class TIG_PostNL_Model_Parcelware_Export extends TIG_PostNL_Model_Core_Cif
594
  }
595
 
596
  /**
597
- * gets the numeric shipment type for this shipment.
598
  *
599
  * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
600
  *
@@ -727,7 +729,7 @@ class TIG_PostNL_Model_Parcelware_Export extends TIG_PostNL_Model_Core_Cif
727
  */
728
  protected function _getContractReference()
729
  {
730
- $contractReference = Mage::getStoreConfig(self::XML_PATH_CONTRACT_REF_NR, $this->getStoreId());
731
 
732
  return $contractReference;
733
  }
@@ -739,7 +741,7 @@ class TIG_PostNL_Model_Parcelware_Export extends TIG_PostNL_Model_Core_Cif
739
  */
740
  protected function _getContractName()
741
  {
742
- $contractName = Mage::getStoreConfig(self::XML_PATH_CONTRACT_NAME, $this->getStoreId());
743
 
744
  return $contractName;
745
  }
@@ -751,7 +753,7 @@ class TIG_PostNL_Model_Parcelware_Export extends TIG_PostNL_Model_Core_Cif
751
  */
752
  protected function _getSenderReference()
753
  {
754
- $senderReference = Mage::getStoreConfig(self::XML_PATH_SENDER_REF_NR, $this->getStoreId());
755
 
756
  return $senderReference;
757
  }
44
  /**
45
  * XML paths to Parcelware references
46
  */
47
+ const XPATH_CONTRACT_REF_NR = 'postnl/parcelware_export/contract_ref_nr';
48
+ const XPATH_CONTRACT_NAME = 'postnl/parcelware_export/contract_name';
49
+ const XPATH_SENDER_REF_NR = 'postnl/parcelware_export/sender_ref_nr';
50
 
51
  /**
52
  * @var Mage_Core_Model_Resource_Transaction|void
362
  'Street' => $streetData['streetname'],
363
  'HouseNr' => $streetData['housenumber'],
364
  'HouseNrExt' => $streetData['housenumberExtension'],
365
+ 'Zipcode' => str_replace(' ', '', $address->getPostcode()),
366
  'City' => $address->getCity(),
367
  'Countrycode' => $address->getCountryId(),
368
  'CustomerEmail' => $address->getEmail(),
411
  'PG_Street' => $streetData['streetname'],
412
  'PG_HouseNr' => $streetData['housenumber'],
413
  'PG_HouseNrExt' => $streetData['housenumberExtension'],
414
+ 'PG_Zipcode' => str_replace(' ', '', $pakjeGemakAddress->getPostcode()),
415
  'PG_City' => $pakjeGemakAddress->getCity(),
416
  'PG_Countrycode' => $pakjeGemakAddress->getCountryId(),
417
  );
552
  $itemCount = 0;
553
  $items = $this->_sortCustomsItems($shipment->getAllItems());
554
 
555
+ $helper = Mage::helper('postnl');
556
+
557
  /**
558
  * @var Mage_Sales_Model_Order_Shipment_Item $item
559
  */
568
  /**
569
  * Calculate the item's weight in kg
570
  */
571
+ $itemWeight = $helper->standardizeWeight(
572
  $item->getWeight(),
573
  $this->getStoreId()
574
  );
596
  }
597
 
598
  /**
599
+ * Gets the numeric shipment type for this shipment.
600
  *
601
  * @param TIG_PostnL_Model_Core_Shipment $postnlShipment
602
  *
729
  */
730
  protected function _getContractReference()
731
  {
732
+ $contractReference = Mage::getStoreConfig(self::XPATH_CONTRACT_REF_NR, $this->getStoreId());
733
 
734
  return $contractReference;
735
  }
741
  */
742
  protected function _getContractName()
743
  {
744
+ $contractName = Mage::getStoreConfig(self::XPATH_CONTRACT_NAME, $this->getStoreId());
745
 
746
  return $contractName;
747
  }
753
  */
754
  protected function _getSenderReference()
755
  {
756
+ $senderReference = Mage::getStoreConfig(self::XPATH_SENDER_REF_NR, $this->getStoreId());
757
 
758
  return $senderReference;
759
  }
app/code/community/TIG/PostNL/Model/Payment/Cod.php ADDED
@@ -0,0 +1,373 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Payment_Cod extends Mage_Payment_Model_Method_Abstract
40
+ {
41
+ /**
42
+ * Xpath to PostNL COD settings. N.B. the last part is missing.
43
+ */
44
+ const XPATH_COD_SETTINGS = 'postnl/cod';
45
+
46
+ /**
47
+ * Xpath to the PostNL COD fee setting.
48
+ */
49
+ const XPATH_COD_FEE = 'payment/postnl_cod/fee';
50
+
51
+ /**
52
+ * This payment method's unique code.
53
+ *
54
+ * @var string
55
+ */
56
+ protected $_code = 'postnl_cod';
57
+
58
+ /**
59
+ * Cash On Delivery form block path.
60
+ *
61
+ * @var string
62
+ */
63
+ protected $_formBlockType = 'postnl_payment/form_cod';
64
+
65
+ /**
66
+ * Cash on delivery info block path.
67
+ *
68
+ * @var string
69
+ */
70
+ protected $_infoBlockType = 'postnl_payment/info';
71
+
72
+ /**
73
+ * Payment Method features.
74
+ *
75
+ * @var boolean
76
+ */
77
+ protected $_isGateway = false;
78
+
79
+ /**
80
+ * @var boolean
81
+ */
82
+ protected $_canOrder = false;
83
+
84
+ /**
85
+ * @var boolean
86
+ */
87
+ protected $_canAuthorize = true;
88
+
89
+ /**
90
+ * @var boolean
91
+ */
92
+ protected $_canCapture = false;
93
+
94
+ /**
95
+ * @var boolean
96
+ */
97
+ protected $_canCapturePartial = false;
98
+
99
+ /**
100
+ * @var boolean
101
+ */
102
+ protected $_canCaptureOnce = false;
103
+
104
+ /**
105
+ * @var boolean
106
+ */
107
+ protected $_canRefund = false;
108
+
109
+ /**
110
+ * @var boolean
111
+ */
112
+ protected $_canRefundInvoicePartial = false;
113
+
114
+ /**
115
+ * @var boolean
116
+ */
117
+ protected $_canVoid = false;
118
+
119
+ /**
120
+ * @var boolean
121
+ */
122
+ protected $_canUseInternal = true;
123
+
124
+ /**
125
+ * @var boolean
126
+ */
127
+ protected $_canUseCheckout = true;
128
+
129
+ /**
130
+ * @var boolean
131
+ */
132
+ protected $_canUseForMultishipping = false;
133
+
134
+ /**
135
+ * @var boolean
136
+ */
137
+ protected $_isInitializeNeeded = false;
138
+
139
+ /**
140
+ * @var boolean
141
+ */
142
+ protected $_canFetchTransactionInfo = false;
143
+
144
+ /**
145
+ * @var boolean
146
+ */
147
+ protected $_canReviewPayment = false;
148
+
149
+ /**
150
+ * @var boolean
151
+ */
152
+ protected $_canCreateBillingAgreement = false;
153
+
154
+ /**
155
+ * @var boolean
156
+ */
157
+ protected $_canManageRecurringProfiles = false;
158
+
159
+ /**
160
+ * @var boolean
161
+ */
162
+
163
+ /**
164
+ * Get instructions text from config.
165
+ *
166
+ * @return string
167
+ */
168
+ public function getInstructions()
169
+ {
170
+ $instructions = trim($this->getConfigData('instructions'));
171
+
172
+ return $instructions;
173
+ }
174
+
175
+ /**
176
+ * Checks whether PostNL COD is available.
177
+ *
178
+ * @param Mage_Sales_Model_Quote|null $quote
179
+ *
180
+ * @return bool
181
+ */
182
+ public function isAvailable($quote = null)
183
+ {
184
+ $helper = Mage::helper('postnl/payment');
185
+
186
+ /**
187
+ * Make sure the quote is available.
188
+ */
189
+ if (is_null($quote)) {
190
+ $helper->log(
191
+ $helper->__('PostNL COD is not available, because the quote is empty.')
192
+ );
193
+ return false;
194
+ }
195
+
196
+ /**
197
+ * COD is not available for virtual shipments.
198
+ */
199
+ if ($quote->isVirtual()) {
200
+ $helper->log(
201
+ $helper->__('PostNL COD is not available, because the order is virtual.')
202
+ );
203
+ return false;
204
+ }
205
+
206
+ /**
207
+ * If COD is only available for PostNL shipping methods, we need to check if the shipping method is PostNL.
208
+ */
209
+ if (!(bool) $this->getConfigData('allow_for_non_postnl', $quote->getStoreId())) {
210
+ $shippingMethod = $quote->getShippingAddress()->getShippingMethod();
211
+
212
+ if (!Mage::helper('postnl/carrier')->isPostnlShippingMethod($shippingMethod)) {
213
+ $helper->log(
214
+ $helper->__('PostNL COD is not available, because the chosen shipping method is not PostNL.')
215
+ );
216
+ return false;
217
+ }
218
+ }
219
+
220
+ /**
221
+ * Make sure all required fields are entered.
222
+ */
223
+ $codSettings = Mage::getStoreConfig(self::XPATH_COD_SETTINGS, Mage::app()->getStore()->getId());
224
+
225
+ if (empty($codSettings['account_name'])
226
+ || empty($codSettings['iban'])
227
+ || empty($codSettings['bic'])
228
+ ) {
229
+ $helper->log(
230
+ $helper->__('PostNL COD is not available, because required fields are missing.')
231
+ );
232
+ return false;
233
+ }
234
+
235
+ /**
236
+ * Check that the shipping address isn't a P.O. box. Unfortunately we can only check this by checking if the
237
+ * street name contains the word 'postbus' (dutch for P.O. box).
238
+ */
239
+ $shippingAddress = $quote->getShippingAddress();
240
+ $fullStreet = $shippingAddress->getStreetFull();
241
+ if (stripos($fullStreet, 'postbus') !== false) {
242
+ $helper->log(
243
+ $helper->__('PostNL COD is not available, because the shipping address is a P.O. box.')
244
+ );
245
+ return false;
246
+ }
247
+
248
+ /**
249
+ * Check that the destination country is allowed.
250
+ */
251
+ if (!$this->canUseForCountry($shippingAddress->getCountry())) {
252
+ $helper->log(
253
+ $helper->__('PostNL COD is not available, because the shipping destination country is not allowed.')
254
+ );
255
+ return false;
256
+ }
257
+
258
+ /**
259
+ * Finally, perform Magento's own checks.
260
+ */
261
+ $parentIsAvailable = parent::isAvailable($quote);
262
+ if (!$parentIsAvailable) {
263
+ $helper->log(
264
+ $helper->__("PostNL COD is not available, because the base isAvailable() check returned 'false'")
265
+ );
266
+ }
267
+
268
+ return $parentIsAvailable;
269
+ }
270
+
271
+ /**
272
+ * Check whether payment method is applicable to quote.
273
+ * Purposed to allow use in controllers some logic that was implemented in blocks only before.
274
+ *
275
+ * Overloaded to expand the CHECK_USE_FOR_COUNTRY check with the shipping address.
276
+ *
277
+ * @param Mage_Sales_Model_Quote $quote
278
+ * @param int|null $checksBitMask
279
+ *
280
+ * @return bool
281
+ */
282
+ public function isApplicableToQuote($quote, $checksBitMask)
283
+ {
284
+ if ($checksBitMask & self::CHECK_USE_FOR_COUNTRY) {
285
+ if (!$this->canUseForCountry($quote->getBillingAddress()->getCountry())) {
286
+ return false;
287
+ }
288
+ if (!$this->canUseForCountry($quote->getShippingAddress()->getCountry())) {
289
+ return false;
290
+ }
291
+ }
292
+ if ($checksBitMask & self::CHECK_USE_FOR_CURRENCY) {
293
+ if (!$this->canUseForCurrency($quote->getStore()->getBaseCurrencyCode())) {
294
+ return false;
295
+ }
296
+ }
297
+ if ($checksBitMask & self::CHECK_USE_CHECKOUT) {
298
+ if (!$this->canUseCheckout()) {
299
+ return false;
300
+ }
301
+ }
302
+ if ($checksBitMask & self::CHECK_USE_FOR_MULTISHIPPING) {
303
+ if (!$this->canUseForMultishipping()) {
304
+ return false;
305
+ }
306
+ }
307
+ if ($checksBitMask & self::CHECK_USE_INTERNAL) {
308
+ if (!$this->canUseInternal()) {
309
+ return false;
310
+ }
311
+ }
312
+ if ($checksBitMask & self::CHECK_ORDER_TOTAL_MIN_MAX) {
313
+ $total = $quote->getBaseGrandTotal();
314
+ $minTotal = $this->getConfigData('min_order_total');
315
+ $maxTotal = $this->getConfigData('max_order_total');
316
+ if (!empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) {
317
+ return false;
318
+ }
319
+ }
320
+ if ($checksBitMask & self::CHECK_RECURRING_PROFILES) {
321
+ if (!$this->canManageRecurringProfiles() && $quote->hasRecurringItems()) {
322
+ return false;
323
+ }
324
+ }
325
+ if ($checksBitMask & self::CHECK_ZERO_TOTAL) {
326
+ $total = $quote->getBaseSubtotal() + $quote->getShippingAddress()->getBaseShippingAmount();
327
+ if ($total < 0.0001 && $this->getCode() != 'free'
328
+ && !($this->canManageRecurringProfiles() && $quote->hasRecurringItems())
329
+ ) {
330
+ return false;
331
+ }
332
+ }
333
+ return true;
334
+ }
335
+
336
+ /**
337
+ * Get the payment method title.
338
+ *
339
+ * @return string
340
+ */
341
+ public function getTitle()
342
+ {
343
+ $title = parent::getTitle();
344
+
345
+ if (Mage::helper('postnl')->isAdmin()) {
346
+ $adminSession = Mage::getSingleton('adminhtml/session_quote');
347
+ if ($adminSession && $adminSession->getStore() !== null) {
348
+ $store = $adminSession->getStore();
349
+ } else {
350
+ $store = Mage::app()->getStore();
351
+ }
352
+ } else {
353
+ $checkoutSession = Mage::getSingleton('checkout/session');
354
+ if ($checkoutSession && $checkoutSession->getQuote()) {
355
+ $store = $checkoutSession->getQuote()->getStore();
356
+ } else {
357
+ $store = Mage::app()->getStore();
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Get the fee from the config and convert and format it according to the chosen currency and locale.
363
+ */
364
+ $fee = Mage::getStoreConfig(self::XPATH_COD_FEE, $store);
365
+ $fee = $store->convertPrice($fee, true, false);
366
+
367
+ /**
368
+ * Replace any parameters in the title with the fee.
369
+ */
370
+ $title = sprintf($title, $fee);
371
+ return $title;
372
+ }
373
+ }
app/code/community/TIG/PostNL/Model/Payment/Observer/Cod.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Payment_Observer_Cod
40
+ {
41
+ /**
42
+ * Xpath to COD auto invoice setting.
43
+ */
44
+ const XPATH_COD_AUTO_INVOICE = 'postnl/cod/auto_invoice';
45
+
46
+ /**
47
+ * Automatically invoice a shipment after it has been delivered.
48
+ *
49
+ * @param Varien_Event_Observer $observer
50
+ *
51
+ * @return $this
52
+ *
53
+ * @event postnl_shipment_setshippingphase_delivered
54
+ *
55
+ * @observer postnl_cod_auto_invoice
56
+ */
57
+ public function autoInvoice(Varien_Event_Observer $observer)
58
+ {
59
+ /**
60
+ * @var TIG_PostNL_Model_Core_Shipment $shipment
61
+ */
62
+ $shipment = $observer->getShipment();
63
+
64
+ /**
65
+ * Auto invoicing is only allowed if the shipment has been delivered.
66
+ */
67
+ if ($shipment->getShippingPhase() != $shipment::SHIPPING_PHASE_DELIVERED) {
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * Get the order and check if we can invoice it.
73
+ */
74
+ $order = $shipment->getShipment()->getOrder();
75
+ if (!$order->canInvoice()) {
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * Check if the order was placed using a PostNL COD payment method.
81
+ */
82
+ $paymentMethod = $order->getPayment()->getMethod();
83
+
84
+ $helper = Mage::helper('postnl/payment');
85
+ $codPaymentMethods = $helper->getCodPaymentMethods();
86
+ if (!in_array($paymentMethod, $codPaymentMethods)) {
87
+ return $this;
88
+ }
89
+
90
+ /**
91
+ * Check if auto-invoicing is actually enabled.
92
+ */
93
+ $autoInvoiceEnabled = Mage::getStoreConfigFlag(self::XPATH_COD_AUTO_INVOICE, $order->getStoreId());
94
+ if (!$autoInvoiceEnabled) {
95
+ return $this;
96
+ }
97
+
98
+ try {
99
+ Mage::getModel('postnl_core/service')->registerInvoiceFromShipment($shipment->getShipment());
100
+ $order->addStatusHistoryComment(
101
+ $helper->__("This order has been automatically invoiced by the PostNL COD payment method.")
102
+ );
103
+ } catch (Exception $e) {
104
+ $helper->logException($e);
105
+ }
106
+
107
+ return $this;
108
+ }
109
+
110
+ /**
111
+ * Prevents the creation of partial shipments by comparing the total qty of the shipment with that of the order.
112
+ *
113
+ * Unfortunately partial shipments are not possible for orders placed using COD.
114
+ *
115
+ * @param Varien_Event_Observer $observer
116
+ *
117
+ * @return $this
118
+ *
119
+ * @throws TIG_PostNL_Exception
120
+ *
121
+ * @event sales_order_shipment_save_before
122
+ *
123
+ * @observer postnl_cod_prevent_partial_shipment
124
+ */
125
+ public function preventPartialShipment(Varien_Event_Observer $observer)
126
+ {
127
+ /**
128
+ * @var Mage_Sales_Model_Order_Shipment $shipment
129
+ * @var Mage_Sales_Model_Order $order
130
+ */
131
+ $shipment = $observer->getShipment();
132
+ $order = $shipment->getOrder();
133
+
134
+ /**
135
+ * Check if the order was placed using a PostNL COD payment method.
136
+ */
137
+ $paymentMethod = $order->getPayment()->getMethod();
138
+
139
+ $helper = Mage::helper('postnl/payment');
140
+ $codPaymentMethods = $helper->getCodPaymentMethods();
141
+ if (!in_array($paymentMethod, $codPaymentMethods)) {
142
+ return $this;
143
+ }
144
+
145
+ $shipmentQty = $shipment->getTotalQty();
146
+ $orderQty = 0;
147
+
148
+ /**
149
+ * @var Mage_Sales_Model_Order_Item $item
150
+ */
151
+ foreach ($order->getAllItems() as $item) {
152
+ if ($item->getParentItemId()) {
153
+ continue;
154
+ }
155
+
156
+ $orderQty += $item->getQtyOrdered();
157
+ }
158
+
159
+ if ($orderQty > $shipmentQty) {
160
+ throw new TIG_PostNL_Exception(
161
+ Mage::helper('postnl')->__(
162
+ 'It is not possible to create partial shipments for orders placed using PostNL COD. Please ' .
163
+ 'create only full shipments.'
164
+ ),
165
+ 'POSTNL-0179'
166
+ );
167
+ }
168
+
169
+ return $this;
170
+ }
171
+ }
app/code/community/TIG/PostNL/Model/Payment/Order/Creditmemo/Total/CodFee.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_Payment_Order_Creditmemo_Total_CodFee
40
+ extends TIG_PostNL_Model_Payment_Order_Creditmemo_Total_CodFee_Abstract
41
+ {
42
+ /**
43
+ * Xpath to the PostNL COD fee including tax setting.
44
+ */
45
+ const XPATH_COD_FEE_INCLUDING_TAX = 'tax/calculation/postnl_cod_fee_including_tax';
46
+
47
+ /**
48
+ * Get the COD fee total amount.
49
+ *
50
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
51
+ *
52
+ * @return $this
53
+ *
54
+ * @throws TIG_PostNL_Exception
55
+ */
56
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
57
+ {
58
+ $order = $creditmemo->getOrder();
59
+
60
+ $fee = $creditmemo->getPostnlCodFee();
61
+ $baseFee = $creditmemo->getBasePostnlCodFee();
62
+
63
+ /**
64
+ * If the creditmemo has a fee already, we only need to set the totals. This is the case for existing
65
+ * creditmemos that are being viewed.
66
+ */
67
+ if ($fee && $baseFee) {
68
+ $this->_updateCreditmemoTotals($creditmemo, $order, $fee, $baseFee);
69
+
70
+ return $this;
71
+ }
72
+
73
+ /**
74
+ * If we are currently in the backend and logged in, we need to check the POST parameters to see if any fee
75
+ * amount is to be refunded.
76
+ */
77
+ if (Mage::helper('postnl')->isAdmin() && Mage::getSingleton('admin/session')->isLoggedIn()) {
78
+ /**
79
+ * This is unfortunately the only way to determine the fee amount that needs to be refunded without
80
+ * rewriting a core class. If anybody knows of a better way, please let us know at
81
+ * servicedesk@totalinternetgroup.nl.
82
+ */
83
+ $creditmemoParameters = Mage::app()->getRequest()
84
+ ->getParam('creditmemo', array());
85
+
86
+ if (isset($creditmemoParameters['postnl_cod_fee'])
87
+ && $creditmemoParameters['postnl_cod_fee'] !== null
88
+ && $creditmemoParameters['postnl_cod_fee'] !== ''
89
+ ) {
90
+ $this->_updateCreditmemoTotalsFromParams($creditmemo, $order, $creditmemoParameters);
91
+
92
+ return $this;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * If none of the above are true, we are creating a new creditmemo and need to show the fee amounts that may be
98
+ * refunded (if any).
99
+ */
100
+ $fee = $order->getPostnlCodFee() - $order->getPostnlCodFeeRefunded();
101
+ $baseFee = $order->getBasePostnlCodFee() - $order->getBasePostnlCodFeeRefunded();
102
+
103
+ if ($fee && $baseFee) {
104
+ $this->_updateCreditmemoTotals($creditmemo, $order, $fee, $baseFee);
105
+
106
+ return $this;
107
+ }
108
+
109
+ return $this;
110
+ }
111
+
112
+ /**
113
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
114
+ * @param Mage_Sales_Model_Order $order
115
+ * @param float $fee
116
+ * @param float $baseFee
117
+ *
118
+ * @return $this
119
+ */
120
+ protected function _updateCreditmemoTotals(Mage_Sales_Model_Order_Creditmemo $creditmemo,
121
+ Mage_Sales_Model_Order $order, $fee, $baseFee)
122
+ {
123
+ $creditmemo->setPostnlCodFee($fee)
124
+ ->setBasePostnlCodFee($baseFee)
125
+ ->setGrandTotal($creditmemo->getGrandTotal() + $fee)
126
+ ->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseFee);
127
+
128
+ $order->setPostnlCodFeeRefunded($order->getPostnlCodFeeRefunded() + $fee)
129
+ ->setBasePostnlCodFeeRefunded($order->getBasePostnlCodFeeRefunded() + $baseFee);
130
+
131
+ return $this;
132
+ }
133
+
134
+ /**
135
+ * Update the creditmemo's totals based on POST params.
136
+ *
137
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
138
+ * @param Mage_Sales_Model_Order $order
139
+ * @param array $creditmemoParameters
140
+ *
141
+ * @return $this
142
+ *
143
+ * @throws TIG_PostNL_Exception
144
+ */
145
+ protected function _updateCreditmemoTotalsFromParams(Mage_Sales_Model_Order_Creditmemo $creditmemo,
146
+ Mage_Sales_Model_Order $order, array $creditmemoParameters)
147
+ {
148
+ /**
149
+ * Get the fee amounts that are to be refunded.
150
+ */
151
+ $baseFee = (float) $creditmemoParameters['postnl_cod_fee'];
152
+
153
+ /**
154
+ * If the fee was entered incl. tax calculate the fee without tax.
155
+ */
156
+ if ($this->getFeeIsInclTax($order->getStore())) {
157
+ $baseFee = $this->_getCodFeeExclTax($baseFee, $order);
158
+ }
159
+
160
+ /**
161
+ * Get the order's COD fee amounts.
162
+ */
163
+ $orderFee = $order->getPostnlCodFee();
164
+ $orderFeeRefunded = $order->getPostnlCodFeeRefunded();
165
+ $orderBaseFee = $order->getBasePostnlCodFee();
166
+ $orderBaseFeeRefunded = $order->getBasePostnlCodFeeRefunded();
167
+
168
+ /**
169
+ * If the total amount refunded exceeds the available fee amount, we have a rounding error. Modify the fee
170
+ * amounts accordingly.
171
+ */
172
+ $totalBaseFee = $baseFee - $orderBaseFee - $orderBaseFeeRefunded;
173
+ if ($totalBaseFee < 0.0001 && $totalBaseFee > -0.0001) {
174
+ $baseFee = $orderBaseFee - $orderBaseFeeRefunded;
175
+ }
176
+
177
+ $fee = $baseFee * $order->getBaseToOrderRate();
178
+
179
+ $totalFee = $fee - $orderFee - $orderFeeRefunded;
180
+ if ($totalFee < 0.0001 && $totalFee > -0.0001) {
181
+ $fee = $orderFee - $orderFeeRefunded;
182
+ }
183
+
184
+ if (round($orderBaseFeeRefunded + $baseFee, 4) > $orderBaseFee) {
185
+ throw new TIG_PostNL_Exception(
186
+ Mage::helper('postnl')->__(
187
+ 'Maximum PostNL COD fee amount available to refunds is %s.',
188
+ $order->formatPriceTxt(
189
+ $orderBaseFee - $orderBaseFeeRefunded
190
+ )
191
+ ),
192
+ 'POSTNL-0178'
193
+ );
194
+ }
195
+
196
+ /**
197
+ * Update the creditmemo totals with the new amounts.
198
+ */
199
+ $creditmemo->setPostnlCodFee($fee)
200
+ ->setBasePostnlCodFee($baseFee)
201
+ ->setGrandTotal($creditmemo->getGrandTotal() + $fee)
202
+ ->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseFee);
203
+
204
+ $order->setPostnlCodFeeRefunded($orderFeeRefunded + $fee)
205
+ ->setBasePostnlCodFeeRefunded($orderBaseFeeRefunded + $baseFee);
206
+
207
+ return $this;
208
+ }
209
+
210
+ /**
211
+ * Gets the configured PostNL COD fee excl. tax for a given quote.
212
+ *
213
+ * @param float $fee
214
+ * @param Mage_Sales_Model_Order $order
215
+ *
216
+ * @return float|int
217
+ */
218
+ protected function _getCodFeeExclTax($fee, Mage_Sales_Model_Order $order)
219
+ {
220
+
221
+ /**
222
+ * Build a tax request to calculate the fee tax.
223
+ */
224
+ $taxRequest = $this->_getCodFeeTaxRequest($order);
225
+
226
+ if (!$taxRequest) {
227
+ return $fee;
228
+ }
229
+
230
+ /**
231
+ * Get the tax rate for the request.
232
+ */
233
+ $taxRate = $this->_getCodFeeTaxRate($taxRequest);
234
+
235
+ if (!$taxRate || $taxRate <= 0) {
236
+ return $fee;
237
+ }
238
+
239
+ /**
240
+ * Remove the tax from the fee.
241
+ */
242
+ $feeTax = $this->_getCodFeeTax($order->getShippingAddress(), $taxRate, $fee, true);
243
+ $fee -= $feeTax;
244
+
245
+ return $fee;
246
+ }
247
+ }
app/code/community/TIG/PostNL/Model/Payment/Order/Creditmemo/Total/CodFee/Abstract.php ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Model_Payment_Order_Creditmemo_Total_CodFee_Abstract
40
+ extends Mage_Sales_Model_Order_Creditmemo_Total_Tax
41
+ {
42
+ /**
43
+ * Xpath to the PostNL COD fee setting.
44
+ */
45
+ const XPATH_COD_FEE = 'payment/postnl_cod/fee';
46
+
47
+ /**
48
+ * Xpath to PostNL COD fee tax class.
49
+ */
50
+ const XPATH_COD_TAX_CLASS = 'tax/classes/postnl_cod_fee';
51
+
52
+ /**
53
+ * Xpath to the PostNL COD fee including tax setting.
54
+ */
55
+ const XPATH_COD_FEE_INCLUDING_TAX = 'tax/calculation/postnl_cod_fee_including_tax';
56
+
57
+ /**
58
+ * @return Mage_Tax_Model_Calculation
59
+ */
60
+ public function getTaxCalculation()
61
+ {
62
+ $taxCalculation = $this->_calculator;
63
+ if ($taxCalculation) {
64
+ return $taxCalculation;
65
+ }
66
+
67
+ $taxCalculation = Mage::getSingleton('tax/calculation');
68
+
69
+ $this->setTaxCalculation($taxCalculation);
70
+ return $taxCalculation;
71
+ }
72
+
73
+ /**
74
+ * @param Mage_Tax_Model_Calculation $taxCalculation
75
+ *
76
+ * @return $this
77
+ */
78
+ public function setTaxCalculation(Mage_Tax_Model_Calculation $taxCalculation)
79
+ {
80
+ $this->_calculator = $taxCalculation;
81
+
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Get whether the PostNL COD fee is incl. tax.
87
+ *
88
+ * @param int|Mage_Core_Model_Store|null $store
89
+ *
90
+ * @return bool
91
+ */
92
+ public function getFeeIsInclTax($store = null)
93
+ {
94
+ if (is_null($store)) {
95
+ $storeId = Mage::app()->getStore()->getId();
96
+ } elseif ($store instanceof Mage_Core_Model_Store) {
97
+ $storeId = $store->getId();
98
+ } else {
99
+ $storeId = $store;
100
+ }
101
+
102
+ return Mage::getStoreConfigFlag(self::XPATH_COD_FEE_INCLUDING_TAX, $storeId);
103
+ }
104
+
105
+ /**
106
+ * Get the tax request object for the current quote.
107
+ *
108
+ * @param Mage_Sales_Model_Order $order
109
+ *
110
+ * @return bool|Varien_Object
111
+ */
112
+ protected function _getCodFeeTaxRequest(Mage_Sales_Model_Order $order)
113
+ {
114
+ $store = $order->getStore();
115
+ $codTaxClass = Mage::getStoreConfig(self::XPATH_COD_TAX_CLASS, $store);
116
+
117
+ /**
118
+ * If no tax class is configured for the COD fee, there is no tax to be calculated.
119
+ */
120
+ if (!$codTaxClass) {
121
+ return false;
122
+ }
123
+
124
+ $taxCalculation = $this->getTaxCalculation();
125
+ $customerTaxClass = $order->getCustomerTaxClassId();
126
+ $shippingAddress = $order->getShippingAddress();
127
+ $billingAddress = $order->getBillingAddress();
128
+
129
+ $request = $taxCalculation->getRateRequest(
130
+ $shippingAddress,
131
+ $billingAddress,
132
+ $customerTaxClass,
133
+ $store
134
+ );
135
+
136
+ $request->setProductClassId($codTaxClass);
137
+
138
+ return $request;
139
+ }
140
+
141
+ /**
142
+ * Get the tax rate based on the previously created tax request.
143
+ *
144
+ * @param Varien_Object $request
145
+ *
146
+ * @return float
147
+ */
148
+ protected function _getCodFeeTaxRate($request)
149
+ {
150
+ $rate = $this->getTaxCalculation()->getRate($request);
151
+
152
+ return $rate;
153
+ }
154
+
155
+ /**
156
+ * Get the fee tax based on the shipping address and tax rate.
157
+ *
158
+ * @param Mage_Customer_Model_Address_Abstract $address
159
+ * @param float $taxRate
160
+ * @param float|null $fee
161
+ * @param boolean $isInclTax
162
+ *
163
+ * @return float
164
+ */
165
+ protected function _getCodFeeTax($address, $taxRate, $fee = null, $isInclTax = false)
166
+ {
167
+ if (is_null($fee)) {
168
+ $fee = (float) $address->getPostnlCodFee();
169
+ }
170
+
171
+ $taxCalculation = $this->getTaxCalculation();
172
+
173
+ $feeTax = $taxCalculation->calcTaxAmount(
174
+ $fee,
175
+ $taxRate,
176
+ $isInclTax,
177
+ false
178
+ );
179
+
180
+ return $feeTax;
181
+ }
182
+
183
+ /**
184
+ * Get the base fee tax based on the shipping address and tax rate.
185
+ *
186
+ * @param Mage_Customer_Model_Address_Abstract $address
187
+ * @param float $taxRate
188
+ * @param float|null $fee
189
+ * @param boolean $isInclTax
190
+ *
191
+ * @return float
192
+ */
193
+ protected function _getBaseCodFeeTax($address, $taxRate, $fee = null, $isInclTax = false)
194
+ {
195
+ if (is_null($fee)) {
196
+ $fee = (float) $address->getBasePostnlCodFee();
197
+ }
198
+
199
+ $taxCalculation = $this->getTaxCalculation();
200
+
201
+ $baseFeeTax = $taxCalculation->calcTaxAmount(
202
+ $fee,
203
+ $taxRate,
204
+ $isInclTax,
205
+ false
206
+ );
207
+
208
+ return $baseFeeTax;
209
+ }
210
+ }
app/code/community/TIG/PostNL/Model/Payment/Order/Creditmemo/Total/CodFeeTax.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
+ class TIG_PostNL_Model_Payment_Order_Creditmemo_Total_CodFeeTax
40
+ extends TIG_PostNL_Model_Payment_Order_Creditmemo_Total_CodFee_Abstract
41
+ {
42
+ /**
43
+ * Get the COD fee tax total amount.
44
+ *
45
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
46
+ *
47
+ * @return $this
48
+ */
49
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
50
+ {
51
+ $order = $creditmemo->getOrder();
52
+
53
+ $feeTax = $creditmemo->getPostnlCodFeeTax();
54
+ $baseFeeTax = $creditmemo->getBasePostnlCodFeeTax();
55
+
56
+ /**
57
+ * If a creditmemo already has a fee tax, we only need to update the totals.
58
+ */
59
+ if ($feeTax && $baseFeeTax) {
60
+ $creditmemo->setPostnlCodFeeTax($feeTax)
61
+ ->setBasePostnlCodFeeTax($baseFeeTax)
62
+ ->setTaxAmount($creditmemo->getTaxAmount() + $feeTax)
63
+ ->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseFeeTax)
64
+ ->setGrandTotal($creditmemo->getGrandTotal() + $feeTax)
65
+ ->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseFeeTax);
66
+
67
+ $order->setPostnlCodFeeTaxRefunded($order->getPostnlCodFeeTaxRefunded() + $feeTax)
68
+ ->setBasePostnlCodFeeTaxRefunded($order->getBasePostnlCodFeeTaxRefunded() + $baseFeeTax);
69
+
70
+ return $this;
71
+ }
72
+
73
+ /**
74
+ * If the creditmemo has a fee, but no fee tax, we need to calculate the fee tax.
75
+ */
76
+ $fee = $creditmemo->getPostnlCodFee();
77
+ $baseFee = $creditmemo->getBasePostnlCodFee();
78
+
79
+ if ($fee && $baseFee) {
80
+ /**
81
+ * First we need to determine what percentage of the fee is being refunded. We need to refund the same
82
+ * percentage of fee tax.
83
+ */
84
+ $totalBaseFee = $order->getBasePostnlCodFee();
85
+ $ratio = $baseFee / $totalBaseFee;
86
+
87
+ /**
88
+ * Calculate the fee and base fee tax based on the same ratio.
89
+ */
90
+ $totalBaseFeeTax = $order->getBasePostnlCodFeeTax();
91
+ $baseFeeTax = $totalBaseFeeTax * $ratio;
92
+
93
+ $totalFeeTax = $order->getPostnlCodFeeTax();
94
+ $feeTax = $totalFeeTax * $ratio;
95
+
96
+ /**
97
+ * If the total amount refunded exceeds the available fee tax amount, we have a rounding error. Modify the
98
+ * fee tax amounts accordingly.
99
+ */
100
+ $totalBaseFeeTax = $baseFeeTax - $order->getBasePostnlCodFeeTax()
101
+ - $order->getBasePostnlCodFeeTaxRefunded();
102
+ if ($totalBaseFeeTax < 0.0001 && $totalBaseFeeTax > -0.0001) {
103
+ $baseFeeTax = $order->getBasePostnlCodFeeTax() - $order->getBasePostnlCodFeeTaxRefunded();
104
+ }
105
+
106
+ $totalFeeTax = $feeTax - $order->getPostnlCodFeeTax() - $order->getPostnlCodFeeTaxRefunded();
107
+ if ($totalFeeTax < 0.0001 && $totalFeeTax > -0.0001) {
108
+ $feeTax = $order->getPostnlCodFeeTax() - $order->getPostnlCodFeeTaxRefunded();
109
+ }
110
+
111
+ /**
112
+ * Update the creditmemo totals.
113
+ */
114
+ $creditmemo->setPostnlCodFeeTax($feeTax)
115
+ ->setBasePostnlCodFeeTax($baseFeeTax)
116
+ ->setTaxAmount($creditmemo->getTaxAmount() + $feeTax)
117
+ ->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseFeeTax)
118
+ ->setGrandTotal($creditmemo->getGrandTotal() + $feeTax)
119
+ ->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseFeeTax);
120
+
121
+ $order->setPostnlCodFeeTaxRefunded($order->getPostnlCodFeeTaxRefunded() + $feeTax)
122
+ ->setBasePostnlCodFeeTaxRefunded($order->getBasePostnlCodFeeTaxRefunded() + $baseFeeTax);
123
+
124
+ return $this;
125
+ }
126
+
127
+ return $this;
128
+ }
129
+ }
app/code/community/TIG/PostNL/Model/Payment/Order/Invoice/Total/CodFee.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Payment_Order_Invoice_Total_CodFee extends Mage_Sales_Model_Order_Invoice_Total_Abstract
40
+ {
41
+ /**
42
+ * @param Mage_Sales_Model_Order_Invoice $invoice
43
+ *
44
+ * @return $this
45
+ */
46
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
47
+ {
48
+ $order = $invoice->getOrder();
49
+
50
+ /**
51
+ * The COD fee is always added to the first invoice, so if this order already has invoices, we don't have to add
52
+ * anything.
53
+ */
54
+ if ($order->hasInvoices()) {
55
+ return $this;
56
+ }
57
+
58
+ /**
59
+ * Get the COD fee amounts.
60
+ */
61
+ $fee = $order->getPostnlCodFee();
62
+ $baseFee = $order->getBasePostnlCodFee();
63
+
64
+ /**
65
+ * If no COD fee is set, there is nothing to add/
66
+ */
67
+ if ($fee < 0.01 || $baseFee < 0.01) {
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * Add the COD fee amounts to the invoice and update the amounts for the order.
73
+ */
74
+ $grandTotal = $invoice->getGrandTotal();
75
+ $baseGrandTotal = $invoice->getBaseGrandTotal();
76
+
77
+ $invoice->setPostnlCodFee($fee)
78
+ ->setBasePostnlCodFee($baseFee)
79
+ ->setGrandTotal($grandTotal + $fee)
80
+ ->setBaseGrandTotal($baseGrandTotal + $baseFee);
81
+
82
+ $order->setPostnlCodFeeInvoiced($fee)
83
+ ->setBasePostnlCodFeeInvoiced($baseFee);
84
+
85
+ return $this;
86
+ }
87
+ }
app/code/community/TIG/PostNL/Model/Payment/Order/Invoice/Total/CodFeeTax.php ADDED
@@ -0,0 +1,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.
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_Payment_Order_Invoice_Total_CodFeeTax extends Mage_Sales_Model_Order_Invoice_Total_Abstract
40
+ {
41
+ /**
42
+ * @param Mage_Sales_Model_Order_Invoice $invoice
43
+ *
44
+ * @return $this
45
+ */
46
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
47
+ {
48
+ $order = $invoice->getOrder();
49
+
50
+ /**
51
+ * The COD fee tax is always added to the first invoice, so if this order already has invoices, we don't have to
52
+ * add anything.
53
+ */
54
+ if ($order->hasInvoices()) {
55
+ return $this;
56
+ }
57
+
58
+ /**
59
+ * Get the COD fee tax amounts.
60
+ */
61
+ $feeTax = $order->getPostnlCodFeeTax();
62
+ $baseFeeTax = $order->getBasePostnlCodFeeTax();
63
+
64
+ /**
65
+ * If no COD fee tax is set, there is nothing to add/
66
+ */
67
+ if ($feeTax < 0.01 || $baseFeeTax < 0.01) {
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * Add the COD fee tax amounts to the invoice.
73
+ */
74
+ $invoice->setPostnlCodFeeTax($feeTax)
75
+ ->setBasePostnlCodFeeTax($baseFeeTax)
76
+ ->setTaxAmount($invoice->getTaxAmount() + $feeTax)
77
+ ->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseFeeTax);
78
+
79
+ /**
80
+ * For all versions except 1.13.0.X and 1.8.0.X we need to add the COD fee tax to the grand total amounts.
81
+ */
82
+ $helper = Mage::helper('postnl');
83
+ if (
84
+ ($helper->isEnterprise()
85
+ && (version_compare(Mage::getVersion(), '1.13.1.0', '>=')
86
+ || version_compare(Mage::getVersion(), '1.13.0.0', '<')
87
+ )
88
+ )
89
+ || (!$helper->isEnterprise()
90
+ && (version_compare(Mage::getVersion(), '1.8.1.0', '>=')
91
+ || version_compare(Mage::getVersion(), '1.8.0.0', '<')
92
+ )
93
+ )
94
+ ) {
95
+ $invoice->setGrandTotal($invoice->getGrandTotal() + $feeTax)
96
+ ->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseFeeTax);
97
+ }
98
+
99
+ /**
100
+ * Update the order's COD fee tax amounts.
101
+ */
102
+ $order->setPostnlCodFeeTaxInvoiced($feeTax)
103
+ ->setBasePostnlCodFeeTaxInvoiced($baseFeeTax);
104
+
105
+ return $this;
106
+ }
107
+ }
app/code/community/TIG/PostNL/Model/Payment/Order/Invoice/Total/Subtotal.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
+ class TIG_PostNL_Model_Payment_Order_Invoice_Total_Subtotal extends Mage_Sales_Model_Order_Invoice_Total_Subtotal
40
+ {
41
+ /**
42
+ * Collect invoice subtotal.
43
+ *
44
+ * @param Mage_Sales_Model_Order_Invoice $invoice
45
+ *
46
+ * @return $this
47
+ */
48
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
49
+ {
50
+ $subtotal = 0;
51
+ $baseSubtotal = 0;
52
+ $subtotalInclTax= 0;
53
+ $baseSubtotalInclTax = 0;
54
+
55
+ $order = $invoice->getOrder();
56
+
57
+ /**
58
+ * @var Mage_Sales_Model_Order_Invoice_Item $item
59
+ */
60
+ foreach ($invoice->getAllItems() as $item) {
61
+ if ($item->getOrderItem()->isDummy()) {
62
+ continue;
63
+ }
64
+
65
+ $item->calcRowTotal();
66
+
67
+ $subtotal += $item->getRowTotal();
68
+ $baseSubtotal += $item->getBaseRowTotal();
69
+ $subtotalInclTax += $item->getRowTotalInclTax();
70
+ $baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
71
+ }
72
+
73
+ $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced();
74
+ $baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced();
75
+
76
+ $allowedSubtotalInclTax = $allowedSubtotal
77
+ + $order->getHiddenTaxAmount()
78
+ + $order->getTaxAmount()
79
+ - $order->getTaxInvoiced()
80
+ - $order->getHiddenTaxInvoiced();
81
+
82
+ $baseAllowedSubtotalInclTax = $baseAllowedSubtotal
83
+ + $order->getBaseHiddenTaxAmount()
84
+ + $order->getBaseTaxAmount()
85
+ - $order->getBaseTaxInvoiced()
86
+ - $order->getBaseHiddenTaxInvoiced();
87
+
88
+ /**
89
+ * Check if shipping tax calculation and PostNL COD fee tax is included to current invoice.
90
+ *
91
+ * @var Mage_Sales_Model_Order_Invoice $previousInvoice
92
+ */
93
+ $includeShippingTax = true;
94
+ $includeCodFeeTax = true;
95
+ foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
96
+ if ($previousInvoice->isCanceled()) {
97
+ continue;
98
+ }
99
+
100
+ if ($previousInvoice->getShippingAmount()) {
101
+ $includeShippingTax = false;
102
+ }
103
+
104
+ if ($previousInvoice->getPostnlCodFeeTax()) {
105
+ $includeCodFeeTax = false;
106
+ }
107
+ }
108
+
109
+ if ($includeShippingTax) {
110
+ $allowedSubtotalInclTax -= $order->getShippingTaxAmount();
111
+ $baseAllowedSubtotalInclTax -= $order->getBaseShippingTaxAmount();
112
+ } else {
113
+ $allowedSubtotalInclTax += $order->getShippingHiddenTaxAmount();
114
+ $baseAllowedSubtotalInclTax += $order->getBaseShippingHiddenTaxAmount();
115
+ }
116
+
117
+ if ($includeCodFeeTax) {
118
+ $allowedSubtotalInclTax -= $order->getPostnlCodFeeTax();
119
+ $baseAllowedSubtotalInclTax -= $order->getBasePostnlCodFeeTax();
120
+ }
121
+
122
+ if ($invoice->isLast()) {
123
+ $subtotal = $allowedSubtotal;
124
+ $baseSubtotal = $baseAllowedSubtotal;
125
+ $subtotalInclTax = $allowedSubtotalInclTax;
126
+ $baseSubtotalInclTax = $baseAllowedSubtotalInclTax;
127
+ } else {
128
+ $subtotal = min($allowedSubtotal, $subtotal);
129
+ $baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
130
+ $subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
131
+ $baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);
132
+ }
133
+
134
+ $invoice->setSubtotal($subtotal);
135
+ $invoice->setBaseSubtotal($baseSubtotal);
136
+ $invoice->setSubtotalInclTax($subtotalInclTax);
137
+ $invoice->setBaseSubtotalInclTax($baseSubtotalInclTax);
138
+
139
+ $invoice->setGrandTotal($invoice->getGrandTotal() + $subtotal);
140
+ $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseSubtotal);
141
+ return $this;
142
+ }
143
+ }
app/code/community/TIG/PostNL/Model/Payment/Order/Pdf/Total/CodFee.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 int|string getFontSize()
40
+ * @method Mage_Sales_Model_Order getOrder()
41
+ * @method string getAmountPrefix()
42
+ * @method string getTitle()
43
+ * @method Mage_Sales_Model_Abstract getSource()
44
+ */
45
+ class TIG_PostNL_Model_Payment_Order_Pdf_Total_CodFee extends Mage_Sales_Model_Order_Pdf_Total_Default
46
+ {
47
+ /**
48
+ * Display modes for the PostNL COD fee.
49
+ */
50
+ const DISPLAY_MODE_EXCL = 1;
51
+ const DISPLAY_MODE_INCL = 2;
52
+ const DISPLAY_MODE_BOTH = 3;
53
+
54
+ /**
55
+ * Xpath to the PostNL COD fee display mode setting.
56
+ */
57
+ const XPATH_DISPLAY_MODE_COD_FEE = 'tax/sales_display/postnl_cod_fee';
58
+
59
+ /**
60
+ * Get the PostNL COD fee total amounts to display on the pdf.
61
+ *
62
+ * @return array
63
+ */
64
+ public function getTotalsForDisplay()
65
+ {
66
+ $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
67
+
68
+ $totals = array();
69
+
70
+ $displayMode = $this->getDisplayMode();
71
+ $baseLabel = Mage::helper('postnl/payment')->getPostnlCodFeeLabel($this->getOrder()->getStoreId());
72
+
73
+ /**
74
+ * Get the fee excl. tax.
75
+ */
76
+ if ($displayMode === self::DISPLAY_MODE_EXCL || $displayMode === self::DISPLAY_MODE_BOTH) {
77
+ /**
78
+ * Get the amount excl. tax and format it.
79
+ */
80
+ $amount = $this->getAmount();
81
+ $formattedAmount = $this->getOrder()->formatPriceTxt($amount);
82
+ if ($this->getAmountPrefix()) {
83
+ $formattedAmount = $this->getAmountPrefix() . $formattedAmount;
84
+ }
85
+
86
+ /**
87
+ * Determine the label.
88
+ */
89
+ $label = $baseLabel;
90
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
91
+ $label .= ' (' . $this->getTaxLabel(false) . ')';
92
+ }
93
+ $label .= ':';
94
+
95
+ /**
96
+ * Add the total amount.
97
+ */
98
+ $totals[] = array(
99
+ 'amount' => $formattedAmount,
100
+ 'label' => $label,
101
+ 'font_size' => $fontSize
102
+ );
103
+ }
104
+
105
+ /**
106
+ * Get the fee incl. tax.
107
+ */
108
+ if ($displayMode === self::DISPLAY_MODE_INCL || $displayMode === self::DISPLAY_MODE_BOTH) {
109
+ /**
110
+ * Get the amount incl. tax and format it.
111
+ */
112
+ $amount = $this->getAmount() + $this->getSource()->getPostnlCodFeeTax();
113
+ $formattedAmount = $this->getOrder()->formatPriceTxt($amount);
114
+ if ($this->getAmountPrefix()) {
115
+ $formattedAmount = $this->getAmountPrefix() . $formattedAmount;
116
+ }
117
+
118
+ /**
119
+ * Determine the label.
120
+ */
121
+ $label = $baseLabel;
122
+ if ($displayMode === self::DISPLAY_MODE_BOTH) {
123
+ $label .= ' (' . $this->getTaxLabel(true) . ')';
124
+ }
125
+ $label .= ':';
126
+
127
+ /**
128
+ * Add the total amount.
129
+ */
130
+ $totals[] = array(
131
+ 'amount' => $formattedAmount,
132
+ 'label' => $label,
133
+ 'font_size' => $fontSize
134
+ );
135
+ }
136
+
137
+ return $totals;
138
+ }
139
+
140
+ /**
141
+ * Get the display mode for the PostNL COD fee.
142
+ *
143
+ * @return int
144
+ */
145
+ public function getDisplayMode()
146
+ {
147
+ $displayMode = (int) Mage::getStoreConfig(self::XPATH_DISPLAY_MODE_COD_FEE, $this->getOrder()->getStoreId());
148
+
149
+ return $displayMode;
150
+ }
151
+
152
+ /**
153
+ * Get the tax label for either incl. or excl. tax.
154
+ *
155
+ * @param boolean $inclTax
156
+ *
157
+ * @return string
158
+ */
159
+ public function getTaxLabel($inclTax = false)
160
+ {
161
+ $taxLabel = Mage::helper('tax')->getIncExcText($inclTax, $this->getOrder()->getStoreId());
162
+
163
+ return $taxLabel;
164
+ }
165
+ }
app/code/community/TIG/PostNL/Model/Payment/Order/Pdf/Total/Grandtotal.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Mage_Sales_Model_Order getOrder()
40
+ * @method Mage_Sales_Model_Order|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo getSource()
41
+ * @method int|string getFontSize()
42
+ * @method string getAmountPrefix()
43
+ */
44
+ class TIG_PostNL_Model_Payment_Order_Pdf_Total_Grandtotal extends Mage_Tax_Model_Sales_Pdf_Grandtotal
45
+ {
46
+ /**
47
+ * Get array of arrays with tax information for display in PDF
48
+ * array(
49
+ * $index => array(
50
+ * 'amount' => $amount,
51
+ * 'label' => $label,
52
+ * 'font_size'=> $font_size
53
+ * )
54
+ * )
55
+ * @return array
56
+ */
57
+ public function getFullTaxInfo()
58
+ {
59
+ $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
60
+
61
+ if (method_exists($this, '_getCalculatedTaxes')) {
62
+ $taxClassAmount = $this->_getCalculatedTaxes();
63
+ } else {
64
+ $taxClassAmount = Mage::helper('tax')->getCalculatedTaxes($this->getOrder());
65
+ }
66
+
67
+ if (method_exists($this, '_getShippingTax')) {
68
+ $shippingTax = $this->_getShippingTax();
69
+ } else {
70
+ $shippingTax = Mage::helper('tax')->getShippingTax($this->getOrder());
71
+ }
72
+
73
+ $taxClassAmount = array_merge($taxClassAmount, $shippingTax);
74
+
75
+ /**
76
+ * Add the COD fee tax info.
77
+ */
78
+ $taxClassAmount = Mage::helper('postnl/payment')->addPostnlCodFeeTaxInfo(
79
+ $taxClassAmount,
80
+ $this->getSource(),
81
+ $this->getOrder()
82
+ );
83
+
84
+ if (!empty($taxClassAmount)) {
85
+ foreach ($taxClassAmount as &$tax) {
86
+ $percent = $tax['percent'] ? ' (' . $tax['percent']. '%)' : '';
87
+ $tax['amount'] = $this->getAmountPrefix() . $this->getOrder()->formatPriceTxt($tax['tax_amount']);
88
+ $tax['label'] = $this->_getTaxHelper()->__($tax['title']) . $percent . ':';
89
+ $tax['font_size'] = $fontSize;
90
+ }
91
+ } else {
92
+ $fullInfo = $this->_getFullRateInfo();
93
+ $tax_info = array();
94
+
95
+ if ($fullInfo) {
96
+ foreach ($fullInfo as $info) {
97
+ if (isset($info['hidden']) && $info['hidden']) {
98
+ continue;
99
+ }
100
+
101
+ $_amount = $info['amount'];
102
+
103
+ foreach ($info['rates'] as $rate) {
104
+ $percent = $rate['percent'] ? ' (' . $rate['percent']. '%)' : '';
105
+
106
+ $tax_info[] = array(
107
+ 'amount' => $this->getAmountPrefix() . $this->getOrder()->formatPriceTxt($_amount),
108
+ 'label' => $this->_getTaxHelper()->__($rate['title']) . $percent . ':',
109
+ 'font_size' => $fontSize
110
+ );
111
+ }
112
+ }
113
+ }
114
+ $taxClassAmount = $tax_info;
115
+ }
116
+
117
+ return $taxClassAmount;
118
+ }
119
+
120
+ /**
121
+ * @return Mage_Tax_Helper_Data
122
+ */
123
+ protected function _getTaxHelper()
124
+ {
125
+ return Mage::helper('tax');
126
+ }
127
+ }
app/code/community/TIG/PostNL/Model/Payment/Order/Pdf/Total/Tax.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Mage_Sales_Model_Order getOrder()
40
+ * @method Mage_Sales_Model_Order|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo getSource()
41
+ * @method int|string getFontSize()
42
+ * @method string getAmountPrefix()
43
+ */
44
+ class TIG_PostNL_Model_Payment_Order_Pdf_Total_Tax extends Mage_Tax_Model_Sales_Pdf_Tax
45
+ {
46
+ /**
47
+ * Get array of arrays with tax information for display in PDF
48
+ * array(
49
+ * $index => array(
50
+ * 'amount' => $amount,
51
+ * 'label' => $label,
52
+ * 'font_size'=> $font_size
53
+ * )
54
+ * )
55
+ * @return array
56
+ */
57
+ public function getFullTaxInfo()
58
+ {
59
+ $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
60
+
61
+ if (method_exists($this, '_getCalculatedTaxes')) {
62
+ $taxClassAmount = $this->_getCalculatedTaxes();
63
+ } else {
64
+ $taxClassAmount = Mage::helper('tax')->getCalculatedTaxes($this->getOrder());
65
+ }
66
+
67
+ if (method_exists($this, '_getShippingTax')) {
68
+ $shippingTax = $this->_getShippingTax();
69
+ } else {
70
+ $shippingTax = Mage::helper('tax')->getShippingTax($this->getOrder());
71
+ }
72
+
73
+ $taxClassAmount = array_merge($taxClassAmount, $shippingTax);
74
+
75
+ /**
76
+ * Add the COD fee tax info.
77
+ */
78
+ $taxClassAmount = Mage::helper('postnl/payment')->addPostnlCodFeeTaxInfo(
79
+ $taxClassAmount,
80
+ $this->getSource(),
81
+ $this->getOrder()
82
+ );
83
+
84
+ if (!empty($taxClassAmount)) {
85
+ foreach ($taxClassAmount as &$tax) {
86
+ $percent = $tax['percent'] ? ' (' . $tax['percent']. '%)' : '';
87
+ $tax['amount'] = $this->getAmountPrefix() . $this->getOrder()->formatPriceTxt($tax['tax_amount']);
88
+ $tax['label'] = $this->_getTaxHelper()->__($tax['title']) . $percent . ':';
89
+ $tax['font_size'] = $fontSize;
90
+ }
91
+ } else {
92
+ $fullInfo = $this->_getFullRateInfo();
93
+ $tax_info = array();
94
+
95
+ if ($fullInfo) {
96
+ foreach ($fullInfo as $info) {
97
+ if (isset($info['hidden']) && $info['hidden']) {
98
+ continue;
99
+ }
100
+
101
+ $_amount = $info['amount'];
102
+
103
+ foreach ($info['rates'] as $rate) {
104
+ $percent = $rate['percent'] ? ' (' . $rate['percent']. '%)' : '';
105
+
106
+ $tax_info[] = array(
107
+ 'amount' => $this->getAmountPrefix() . $this->getOrder()->formatPriceTxt($_amount),
108
+ 'label' => $this->_getTaxHelper()->__($rate['title']) . $percent . ':',
109
+ 'font_size' => $fontSize
110
+ );
111
+ }
112
+ }
113
+ }
114
+ $taxClassAmount = $tax_info;
115
+ }
116
+
117
+ return $taxClassAmount;
118
+ }
119
+
120
+ /**
121
+ * @return Mage_Tax_Helper_Data
122
+ */
123
+ protected function _getTaxHelper()
124
+ {
125
+ return Mage::helper('tax');
126
+ }
127
+ }
app/code/community/TIG/PostNL/Model/Payment/Quote/Address/Total/CodFee.php ADDED
@@ -0,0 +1,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.
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_Payment_Quote_Address_Total_CodFee
40
+ extends TIG_PostNL_Model_Payment_Quote_Address_Total_CodFee_Abstract
41
+ {
42
+ /**
43
+ * Xpath to Idev's OneStepCheckout's 'display_tax_included' setting.
44
+ */
45
+ const XPATH_ONESTEPCHECKOUT_DISPLAY_TAX_INCLUDED = 'onestepcheckout/general/display_tax_included';
46
+
47
+ /**
48
+ * Module name used by OneStepCheckout.
49
+ */
50
+ const ONESTEPCHECKOUT_MODULE_NAME = 'onestepcheckout';
51
+
52
+ /**
53
+ * The code of this 'total'.
54
+ *
55
+ * @var string
56
+ */
57
+ protected $_totalCode = 'postnl_cod_fee';
58
+
59
+ /**
60
+ * Collect the PostNL COD fee for the given address.
61
+ *
62
+ * @param Mage_Sales_Model_Quote_Address $address
63
+ *
64
+ * @return $this
65
+ */
66
+ public function collect(Mage_Sales_Model_Quote_Address $address)
67
+ {
68
+ /**
69
+ * We can only add the fee to the shipping address.
70
+ */
71
+ if ($address->getAddressType() != 'shipping') {
72
+ return $this;
73
+ }
74
+
75
+ $quote = $address->getQuote();
76
+ $store = $quote->getStore();
77
+
78
+ if (!$quote->getId()) {
79
+ return $this;
80
+ }
81
+
82
+ $items = $address->getAllItems();
83
+ if (!count($items)) {
84
+ return $this;
85
+ }
86
+
87
+ /**
88
+ * First, reset the fee amounts to 0 for this address and the quote.
89
+ */
90
+ $address->setPostnlCodFee(0)
91
+ ->setBasePostnlCodFee(0);
92
+
93
+ $quote->setPostnlCodFee(0)
94
+ ->setBasePostnlCodFee(0);
95
+
96
+ /**
97
+ * Check if the order was placed using a PostNL COD payment method.
98
+ */
99
+ $paymentMethod = $quote->getPayment()->getMethod();
100
+
101
+ $helper = Mage::helper('postnl/payment');
102
+ $codPaymentMethods = $helper->getCodPaymentMethods();
103
+ if (!in_array($paymentMethod, $codPaymentMethods)) {
104
+ return $this;
105
+ }
106
+
107
+ /**
108
+ * Get the fee amount.
109
+ */
110
+ $baseFee = $this->_getCodFee($quote);
111
+ if ($baseFee <= 0) {
112
+ return $this;
113
+ }
114
+
115
+ /**
116
+ * Convert the fee to the base fee amount.
117
+ */
118
+ $fee = $store->convertPrice($baseFee);
119
+
120
+ /**
121
+ * Set the fee for the address and quote.
122
+ */
123
+ $address->setPostnlCodFee($fee)
124
+ ->setBasePostnlCodFee($baseFee);
125
+
126
+ $quote->setPostnlCodFee($fee)
127
+ ->setBasePostnlCodFee($baseFee);
128
+
129
+ /**
130
+ * Update the address' grand total amounts.
131
+ */
132
+ $address->setBaseGrandTotal($address->getBaseGrandTotal() + $baseFee);
133
+ $address->setGrandTotal($address->getGrandTotal() + $fee);
134
+
135
+ return $this;
136
+ }
137
+
138
+ /**
139
+ * Fetch the fee.
140
+ *
141
+ * @param Mage_Sales_Model_Quote_Address $address
142
+ *
143
+ * @return $this
144
+ */
145
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
146
+ {
147
+ $amount = $address->getPostnlCodFee();
148
+
149
+ if ($amount <= 0) {
150
+ return $this;
151
+ }
152
+
153
+ $storeId = $address->getQuote()->getStoreId();
154
+
155
+ /**
156
+ * Add the COD fee tax for OSC if the 'display_tax_included' setting is turned on.
157
+ */
158
+ if (Mage::app()->getRequest()->getModuleName() == self::ONESTEPCHECKOUT_MODULE_NAME
159
+ && Mage::getStoreConfigFlag(self::XPATH_ONESTEPCHECKOUT_DISPLAY_TAX_INCLUDED, $storeId)
160
+ ) {
161
+ $amount += $address->getPostnlCodFeeTax();
162
+ }
163
+
164
+ $address->addTotal(
165
+ array(
166
+ 'code' => $this->getCode(),
167
+ 'title' => Mage::helper('postnl/payment')->getPostnlCodFeeLabel($storeId),
168
+ 'value' => $amount,
169
+ )
170
+ );
171
+
172
+ return $this;
173
+ }
174
+
175
+ /**
176
+ * Gets the configured PostNL COD fee excl. tax for a given quote.
177
+ *
178
+ * @param Mage_Sales_Model_Quote $quote
179
+ *
180
+ * @return float|int
181
+ */
182
+ protected function _getCodFee(Mage_Sales_Model_Quote $quote)
183
+ {
184
+ $storeId = $quote->getStoreId();
185
+
186
+ /**
187
+ * Get the fee as configured by the merchant.
188
+ */
189
+ $fee = (float) Mage::getStoreConfig(self::XPATH_COD_FEE, $storeId);
190
+ if ($fee <= 0) {
191
+ return 0;
192
+ }
193
+
194
+ /**
195
+ * If the fee is entered without tax, return the fee amount. Otherwise, we need to calculate and remove the tax.
196
+ */
197
+ $feeIsIncludingTax = $this->getFeeIsInclTax($storeId);
198
+ if (!$feeIsIncludingTax) {
199
+ return $fee;
200
+ }
201
+
202
+ /**
203
+ * Build a tax request to calculate the fee tax.
204
+ */
205
+ $taxRequest = $this->_getCodFeeTaxRequest($quote);
206
+
207
+ if (!$taxRequest) {
208
+ return $fee;
209
+ }
210
+
211
+ /**
212
+ * Get the tax rate for the request.
213
+ */
214
+ $taxRate = $this->_getCodFeeTaxRate($taxRequest);
215
+
216
+ if (!$taxRate || $taxRate <= 0) {
217
+ return $fee;
218
+ }
219
+
220
+ /**
221
+ * Rem