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
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
- app/code/community/TIG/PostNL/Block/Adminhtml/CronNotification.php +6 -4
- app/code/community/TIG/PostNL/Block/Adminhtml/LogNotification.php +129 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Items/Column/Qty.php +109 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Create/Totals/CodFee.php +105 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Creditmemo/Create/CodFee.php +172 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Creditmemo/Totals/CodFee.php +142 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Invoice/Totals/CodFee.php +139 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/ProductOptions.php +1 -1
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/Create/ShipmentOptions.php +121 -18
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/DeliveryOptions.php +246 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/ShippingStatus.php +4 -1
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tab/StatusHistory.php +1 -1
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Shipment/View/Tabs.php +31 -22
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/Totals/CodFee.php +131 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Sales/Order/View/DeliveryOptions.php +176 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form.php +39 -12
- app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ActivateButton.php +2 -2
- app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/ConfigCheck.php +3 -3
- app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/HourMinute.php +236 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/System/Config/Form/Field/PackingSlipItemColumns.php +175 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Action.php +17 -6
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Barcode.php +13 -7
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmDate.php +34 -23
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ConfirmStatus.php +29 -14
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/DeliveryDate.php +6 -4
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/OrderConfirmDate.php +149 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/OrderConfirmStatus.php +112 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/OrderType.php +98 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShipmentType.php +4 -124
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingDescription.php +2 -3
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/ShippingPhase.php +12 -5
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/Type/Abstract.php +413 -0
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Column/Renderer/YesNo.php +2 -3
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Massaction/{LabelStartPos.php → Item/Additional/LabelStartPos.php} +2 -1
- app/code/community/TIG/PostNL/Block/Adminhtml/Widget/Grid/Massaction/Item/Additional/ProductOptions.php +61 -0
- app/code/community/TIG/PostNL/Block/Checkout/Cart/Js.php +5 -5
- app/code/community/TIG/PostNL/Block/Core/JsTranslate.php +1 -1
- app/code/community/TIG/PostNL/Block/DeliveryOptions/Checkout/DeliveryOptions.php +50 -14
- app/code/community/TIG/PostNL/Block/DeliveryOptions/Js.php +14 -0
- app/code/community/TIG/PostNL/Block/Mijnpakket/AccountNotification.php +6 -13
- app/code/community/TIG/PostNL/Block/Mijnpakket/OrderSuccessJs.php +2 -2
- app/code/community/TIG/PostNL/Block/Payment/Checkout/Total/CodFee.php +105 -0
- app/code/community/TIG/PostNL/Block/Payment/Form/Cod.php +123 -0
- app/code/community/TIG/PostNL/Block/Payment/Info.php +61 -0
- app/code/community/TIG/PostNL/Block/Payment/Sales/Order/Creditmemo/Totals/CodFee.php +141 -0
- app/code/community/TIG/PostNL/Block/Payment/Sales/Order/Invoice/Totals/CodFee.php +134 -0
- app/code/community/TIG/PostNL/Block/Payment/Sales/Order/Totals/CodFee.php +131 -0
- app/code/community/TIG/PostNL/Controller/Adminhtml/Shipment.php +631 -0
- app/code/community/TIG/PostNL/Exception.php +4 -6
- app/code/community/TIG/PostNL/Helper/AddressValidation.php +20 -20
- app/code/community/TIG/PostNL/Helper/Carrier.php +116 -10
- app/code/community/TIG/PostNL/Helper/Checkout.php +10 -10
- app/code/community/TIG/PostNL/Helper/Cif.php +272 -225
- app/code/community/TIG/PostNL/Helper/Data.php +660 -174
- app/code/community/TIG/PostNL/Helper/DeliveryOptions.php +1482 -203
- app/code/community/TIG/PostNL/Helper/Mijnpakket.php +40 -12
- app/code/community/TIG/PostNL/Helper/Parcelware.php +11 -7
- app/code/community/TIG/PostNL/Helper/Payment.php +301 -0
- app/code/community/TIG/PostNL/Helper/Webservices.php +11 -11
- app/code/community/TIG/PostNL/Model/AddressValidation/Cendris.php +1 -1
- app/code/community/TIG/PostNL/Model/AddressValidation/Observer/AddressBook.php +1 -1
- app/code/community/TIG/PostNL/Model/AddressValidation/Observer/OneStepCheckout.php +1 -1
- app/code/community/TIG/PostNL/Model/AddressValidation/Observer/Onepage.php +2 -2
- app/code/community/TIG/PostNL/Model/Admin/Inbox.php +189 -0
- app/code/community/TIG/PostNL/Model/Admin/Logging/Handler/Postnl.php +6 -2
- app/code/community/TIG/PostNL/Model/Adminhtml/Form/Element/Checkbox.php +89 -0
- app/code/community/TIG/PostNL/Model/Adminhtml/Observer/OrderGrid.php +802 -60
- app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentGrid.php +188 -180
- app/code/community/TIG/PostNL/Model/Adminhtml/Observer/ShipmentView.php +160 -44
- app/code/community/TIG/PostNL/Model/Adminhtml/Observer/SystemConfig.php +104 -0
- app/code/community/TIG/PostNL/Model/Adminhtml/Support/Logs.php +178 -0
- app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/OrderGridColumns.php +70 -0
- app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/OrderGridMassaction.php +70 -0
- app/code/community/TIG/PostNL/Model/Adminhtml/System/Config/Source/ShipmentGridMassaction.php +9 -1
- app/code/community/TIG/PostNL/Model/Carrier/Postnl.php +24 -74
- app/code/community/TIG/PostNL/Model/Carrier/Quote/Address/Total/Shipping.php +237 -0
- app/code/community/TIG/PostNL/Model/Checkout/Cif.php +29 -29
- app/code/community/TIG/PostNL/Model/Checkout/Observer/Order.php +1 -1
- app/code/community/TIG/PostNL/Model/Checkout/Observer/Shipment.php +1 -1
- app/code/community/TIG/PostNL/Model/Checkout/Service.php +41 -39
- app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/ActivePaymentMethods.php +1 -1
- app/code/community/TIG/PostNL/Model/Checkout/System/Config/Source/CmsPage.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Cache.php +39 -17
- app/code/community/TIG/PostNL/Model/Core/Cif.php +253 -176
- app/code/community/TIG/PostNL/Model/Core/Cif/Abstract.php +40 -17
- app/code/community/TIG/PostNL/Model/Core/Cif/Exception.php +17 -5
- app/code/community/TIG/PostNL/Model/Core/Label.php +433 -191
- app/code/community/TIG/PostNL/Model/Core/Observer/Barcode.php +10 -8
- app/code/community/TIG/PostNL/Model/Core/Observer/Cache.php +9 -0
- app/code/community/TIG/PostNL/Model/Core/Observer/Cron.php +117 -44
- app/code/community/TIG/PostNL/Model/Core/Observer/SaveShipment.php +23 -8
- app/code/community/TIG/PostNL/Model/Core/Order.php +91 -26
- app/code/community/TIG/PostNL/Model/Core/PackingSlip.php +1495 -0
- app/code/community/TIG/PostNL/Model/Core/Packingslip/Pdf/Items/Invoice/Default.php +164 -0
- app/code/community/TIG/PostNL/Model/Core/Resource/Order.php +4 -1
- app/code/community/TIG/PostNL/Model/Core/Resource/Shipment.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Barcode/Collection.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Collection.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Label/Collection.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Resource/Shipment/Status/History/Collection.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Service.php +246 -0
- app/code/community/TIG/PostNL/Model/Core/Service/InvoiceDummy.php +55 -0
- app/code/community/TIG/PostNL/Model/Core/Service/OrderDummy.php +65 -0
- app/code/community/TIG/PostNL/Model/Core/Shipment.php +1242 -197
- app/code/community/TIG/PostNL/Model/Core/Shipment/Barcode.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Shipment/Label.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/Shipment/Process.php +11 -5
- app/code/community/TIG/PostNL/Model/Core/Shipment/Status/History.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/HourMinute.php +57 -0
- app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/Image/Pdf.php +125 -0
- app/code/community/TIG/PostNL/Model/Core/System/Config/Backend/ValidateDefaultOption.php +9 -9
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/AllProductOptions.php +265 -532
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/BuspakjeProductOptions.php +55 -0
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/CommentType.php +62 -0
- app/code/community/TIG/PostNL/Model/{DeliveryOptions → Core}/System/Config/Source/CutOffTime.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/DebugMode.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/Direction.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/EuProductOptions.php +20 -96
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalProductOptions.php +9 -71
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/GlobalpackShipmentType.php +28 -25
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/HourMinute.php +71 -0
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/LabelSize.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ManualAutomatic.php +62 -0
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PackingSlipItemFields.php +78 -0
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakjeGemakProductOptions.php +85 -123
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/PakketautomaatProductOptions.php +8 -70
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ProductOptions/Abstract.php +261 -0
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ReferenceType.php +1 -1
- app/code/community/TIG/PostNL/Model/{DeliveryOptions → Core}/System/Config/Source/ShippingDuration.php +1 -1
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/ShippingMethods.php +122 -0
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StandardProductOptions.php +145 -149
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetField.php +5 -5
- app/code/community/TIG/PostNL/Model/Core/System/Config/Source/StreetFieldWithDefault.php +1 -1
- app/code/community/TIG/PostNL/Model/DeliveryOptions/Cif.php +11 -10
- app/code/community/TIG/PostNL/Model/DeliveryOptions/Observer/UpdatePostnlOrder.php +65 -18
- app/code/community/TIG/PostNL/Model/DeliveryOptions/Product/Attribute/Source/ShippingDuration.php +1 -1
- app/code/community/TIG/PostNL/Model/DeliveryOptions/Service.php +9 -6
- app/code/community/TIG/PostNL/Model/ExtensionControl/Feed.php +4 -4
- app/code/community/TIG/PostNL/Model/ExtensionControl/Webservices.php +354 -43
- app/code/community/TIG/PostNL/Model/Inbox.php +3 -147
- app/code/community/TIG/PostNL/Model/Mijnpakket/Observer/Onepage.php +0 -123
- app/code/community/TIG/PostNL/Model/Parcelware/Export.php +12 -10
- app/code/community/TIG/PostNL/Model/Payment/Cod.php +373 -0
- app/code/community/TIG/PostNL/Model/Payment/Observer/Cod.php +171 -0
- app/code/community/TIG/PostNL/Model/Payment/Order/Creditmemo/Total/CodFee.php +247 -0
- app/code/community/TIG/PostNL/Model/Payment/Order/Creditmemo/Total/CodFee/Abstract.php +210 -0
- app/code/community/TIG/PostNL/Model/Payment/Order/Creditmemo/Total/CodFeeTax.php +129 -0
- app/code/community/TIG/PostNL/Model/Payment/Order/Invoice/Total/CodFee.php +87 -0
- app/code/community/TIG/PostNL/Model/Payment/Order/Invoice/Total/CodFeeTax.php +107 -0
- app/code/community/TIG/PostNL/Model/Payment/Order/Invoice/Total/Subtotal.php +143 -0
- app/code/community/TIG/PostNL/Model/Payment/Order/Pdf/Total/CodFee.php +165 -0
- app/code/community/TIG/PostNL/Model/Payment/Order/Pdf/Total/Grandtotal.php +127 -0
- app/code/community/TIG/PostNL/Model/Payment/Order/Pdf/Total/Tax.php +127 -0
- app/code/community/TIG/PostNL/Model/Payment/Quote/Address/Total/CodFee.php +221 -0
|
@@ -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 |
-
$
|
| 114 |
-
$
|
| 115 |
-
$lastExecutionTimestamp = strtotime($lastExecutionTime);
|
| 116 |
Â
|
| 117 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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
|
| 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 |
Â
*/
|
|
@@ -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->
|
| 54 |
-
return $this->
|
| 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->
|
| 71 |
-
return $this->
|
| 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 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 84 |
Â
*
|
| 85 |
Â
* @return string
|
| 86 |
Â
*/
|
| 87 |
Â
public function getDefaultProductOption()
|
| 88 |
Â
{
|
| 89 |
-
if ($this->
|
| 90 |
-
return $this->
|
| 91 |
Â
}
|
| 92 |
Â
|
| 93 |
Â
$shipment = $this->getShipment();
|
| 94 |
Â
|
| 95 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 96 |
Â
|
| 97 |
Â
$this->setDefaultProductOption($productOption);
|
| 98 |
Â
return $productOption;
|
| 99 |
Â
}
|
| 100 |
Â
|
| 101 |
Â
/**
|
| 102 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 143 |
Â
*
|
| 144 |
-
* @return
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
|
| 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 |
Â
|
|
@@ -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 |
+
}
|
|
@@ -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 |
Â
*/
|
|
@@ -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
|
| 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 |
Â
*/
|
|
@@ -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(
|
| 67 |
-
'
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 72 |
Â
|
| 73 |
Â
/**
|
| 74 |
-
*
|
|
Â
|
|
|
Â
|
|
| 75 |
Â
*/
|
| 76 |
-
$
|
| 77 |
-
$postnlShipment = Mage::getModel('postnl_core/shipment')->
|
| 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(
|
| 89 |
-
'
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
'
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 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();
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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.
|
| 48 |
-
const MINIMUM_ENTERPRISE_VERSION_COMPATIBILITY = '1.12.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
|
| 71 |
-
* can only depend on a field that is in the same fieldset or in a fieldset that is already initialized. An
|
| 72 |
-
* We have fieldset_a containing field_a. We also have fieldset_b containing field_b. If field_a depends on
|
| 73 |
-
* is not possible. When field_a is initialized, fieldset_b and therefore field_b, will not yet have
|
| 74 |
-
* will not be available.
|
| 75 |
Â
*
|
| 76 |
-
* We have split the initialization of fieldsets and fields. This way Magento will first initialize all fieldsets
|
| 77 |
-
* init all fields. So when field_a is initialized, fieldset_b is already available and the dependency will
|
|
Â
|
|
| 78 |
Â
*
|
| 79 |
-
* @return
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
|
Â
|
|
| 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];
|
|
@@ -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
|
| 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::
|
| 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 {
|
|
@@ -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
|
| 54 |
-
const
|
| 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::
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
-
*
|
| 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 (
|
| 126 |
Â
&& $action['is_postnl']
|
| 127 |
-
&& !
|
| 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 |
Â
|
|
@@ -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 (!
|
| 67 |
-
return
|
| 68 |
Â
}
|
| 69 |
Â
|
| 70 |
Â
/**
|
| 71 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
}
|
|
@@ -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
|
| 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 (!
|
| 60 |
-
return
|
| 61 |
Â
}
|
| 62 |
Â
|
| 63 |
-
$value
|
| 64 |
-
$
|
|
Â
|
|
| 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 (
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 77 |
Â
$confirmDate = new DateTime($value);
|
| 78 |
-
$
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 79 |
Â
|
| 80 |
Â
/**
|
| 81 |
-
*
|
| 82 |
Â
*/
|
| 83 |
-
$diff
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 84 |
Â
|
| 85 |
Â
/**
|
| 86 |
-
* Check if it should be confirmed tomorrow
|
| 87 |
Â
*/
|
| 88 |
-
if ($
|
| 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', $
|
| 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 |
Â
}
|
|
@@ -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 (!
|
| 62 |
-
return
|
| 63 |
Â
}
|
| 64 |
Â
|
| 65 |
Â
/**
|
| 66 |
Â
* Check if any data is available
|
| 67 |
Â
*/
|
| 68 |
-
$
|
| 69 |
-
if (is_null($
|
| 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 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 81 |
Â
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
return $value;
|
| 85 |
Â
}
|
| 86 |
Â
|
| 87 |
-
$
|
| 88 |
Â
|
| 89 |
-
return $
|
| 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 |
Â
}
|
|
@@ -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 (!
|
| 60 |
-
return
|
| 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 |
-
$
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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
|
| 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 (!
|
| 70 |
Â
return '';
|
| 71 |
Â
}
|
| 72 |
Â
|
|
@@ -78,119 +69,8 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShipmentType
|
|
| 78 |
Â
return '';
|
| 79 |
Â
}
|
| 80 |
Â
|
| 81 |
-
$
|
| 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 |
Â
}
|
|
@@ -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 (!
|
| 63 |
-
return
|
| 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 |
Â
/**
|
|
@@ -48,17 +48,24 @@ class TIG_PostNL_Block_Adminhtml_Widget_Grid_Column_Renderer_ShippingPhase
|
|
| 48 |
Â
*/
|
| 49 |
Â
public function render(Varien_Object $row)
|
| 50 |
Â
{
|
| 51 |
-
$
|
| 52 |
Â
|
| 53 |
-
if (empty($
|
| 54 |
Â
return '';
|
| 55 |
Â
}
|
| 56 |
Â
|
|
Â
|
|
|
Â
|
|
| 57 |
Â
$shippingPhases = Mage::helper('postnl/cif')->getShippingPhases();
|
| 58 |
-
|
| 59 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 60 |
Â
}
|
|
Â
|
|
| 61 |
Â
|
| 62 |
-
return
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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 (!
|
| 62 |
-
return
|
| 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 |
Â
/**
|
|
@@ -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
|
|
Â
|
|
| 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
|
|
@@ -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 |
+
}
|
|
@@ -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
|
| 61 |
Â
|
| 62 |
Â
/**
|
| 63 |
Â
* XML path of show_summary_page setting
|
| 64 |
Â
*/
|
| 65 |
-
const
|
| 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::
|
| 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::
|
| 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 |
Â
|
|
@@ -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
|
| 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 |
Â
{
|
|
@@ -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
|
| 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 |
-
$
|
| 216 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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
|
| 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
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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 |
Â
*
|
|
@@ -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 |
Â
}
|
|
@@ -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 |
-
|
| 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
|
| 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 =
|
| 305 |
-
$params['birthDate'] = $dob;
|
| 306 |
Â
}
|
| 307 |
Â
|
| 308 |
Â
/**
|
| 309 |
-
* If we have a mobile
|
| 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 |
Â
*/
|
|
@@ -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
|
| 58 |
Â
*
|
| 59 |
Â
* @return string
|
| 60 |
Â
*/
|
| 61 |
Â
protected function _tohtml()
|
| 62 |
Â
{
|
| 63 |
Â
$helper = Mage::helper('postnl/mijnpakket');
|
| 64 |
-
if (!$helper->
|
| 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 |
Â
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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
|
| 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 |
Â
}
|
|
@@ -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
|
| 45 |
Â
|
| 46 |
Â
/**
|
| 47 |
Â
* Constants containing XML paths to cif address configuration options
|
| 48 |
Â
*/
|
| 49 |
-
const
|
| 50 |
-
const
|
| 51 |
-
const
|
| 52 |
-
const
|
| 53 |
-
const
|
| 54 |
Â
|
| 55 |
Â
/**
|
| 56 |
Â
* XML paths to flags that determine which environment allows the postcode check functionality
|
| 57 |
Â
*/
|
| 58 |
-
const
|
| 59 |
-
const
|
| 60 |
Â
|
| 61 |
Â
/**
|
| 62 |
Â
* XML paths that control some features of postcode check
|
| 63 |
Â
*/
|
| 64 |
-
const
|
| 65 |
-
const
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 316 |
Â
break;
|
| 317 |
Â
case 'addressbook':
|
| 318 |
-
$environmentAllowed = Mage::getStoreConfigFlag(self::
|
| 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;
|
|
@@ -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)
|
| 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
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 65 |
Â
|
| 66 |
Â
/**
|
| 67 |
Â
* Array of possible PostNL shipping methods
|
| 68 |
Â
*
|
| 69 |
Â
* @var array
|
| 70 |
Â
*/
|
| 71 |
-
protected $_postnlShippingMethods
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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::
|
| 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 |
Â
/**
|
|
@@ -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
|
| 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
|
| 51 |
Â
|
| 52 |
Â
/**
|
| 53 |
Â
* XML path to test / live mode setting
|
| 54 |
Â
*/
|
| 55 |
-
const
|
| 56 |
Â
|
| 57 |
Â
/**
|
| 58 |
Â
* XML path for config options used to determine whether or not PostNL Checkout is available
|
| 59 |
Â
*/
|
| 60 |
-
const
|
| 61 |
-
const
|
| 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::
|
| 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::
|
| 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 =
|
| 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::
|
| 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::
|
| 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'
|
|
@@ -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
|
| 64 |
Â
*/
|
| 65 |
-
const
|
| 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
|
| 76 |
Â
|
| 77 |
Â
/**
|
| 78 |
Â
* XML paths to default product options settings
|
| 79 |
Â
*/
|
| 80 |
-
const
|
| 81 |
-
const
|
| 82 |
-
const
|
| 83 |
-
const
|
| 84 |
Â
|
| 85 |
Â
/**
|
| 86 |
-
* Regular expression used to split
|
| 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
|
| 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
|
| 232 |
Â
*
|
| 233 |
Â
* @return array
|
| 234 |
Â
*/
|
| 235 |
-
public function getStandardProductCodes($
|
| 236 |
Â
{
|
| 237 |
Â
$standardProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
|
| 238 |
-
return $standardProductCodes->getAvailableOptions($
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 239 |
Â
}
|
| 240 |
Â
|
| 241 |
Â
/**
|
| 242 |
Â
* Get an array of evening delivery product codes.
|
| 243 |
Â
*
|
| 244 |
-
* @param
|
| 245 |
Â
*
|
| 246 |
Â
* @return array
|
| 247 |
Â
*/
|
| 248 |
-
public function getAvondProductCodes($
|
| 249 |
Â
{
|
| 250 |
Â
$pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_standardProductOptions');
|
| 251 |
-
return $pakjeGemakProductCodes->getAvailableAvondOptions($
|
| 252 |
Â
}
|
| 253 |
Â
|
| 254 |
Â
/**
|
| 255 |
-
* Get an array of
|
| 256 |
Â
*
|
| 257 |
-
* @param
|
| 258 |
Â
*
|
| 259 |
Â
* @return array
|
| 260 |
Â
*/
|
| 261 |
-
public function
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 262 |
Â
{
|
| 263 |
Â
$pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
|
| 264 |
-
return $pakjeGemakProductCodes->
|
| 265 |
Â
}
|
| 266 |
Â
|
| 267 |
Â
/**
|
| 268 |
Â
* Get an array of PakjeGemak Express product codes.
|
| 269 |
Â
*
|
| 270 |
-
* @param
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 271 |
Â
*
|
| 272 |
Â
* @return array
|
| 273 |
Â
*/
|
| 274 |
-
public function
|
| 275 |
Â
{
|
| 276 |
Â
$pakjeGemakProductCodes = Mage::getSingleton('postnl_core/system_config_source_pakjeGemakProductOptions');
|
| 277 |
-
return $pakjeGemakProductCodes->
|
| 278 |
Â
}
|
| 279 |
Â
|
| 280 |
Â
/**
|
| 281 |
-
* Get an array of pakketautomaat product codes
|
| 282 |
Â
*
|
| 283 |
-
* @param
|
| 284 |
Â
*
|
| 285 |
Â
* @return array
|
| 286 |
Â
*/
|
| 287 |
-
public function getPakketautomaatProductCodes($
|
| 288 |
Â
{
|
| 289 |
Â
$pakketautomaatProductCodes = Mage::getSingleton(
|
| 290 |
Â
'postnl_core/system_config_source_pakketautomaatProductOptions'
|
| 291 |
Â
);
|
| 292 |
-
return $pakketautomaatProductCodes->getAvailableOptions($
|
| 293 |
Â
}
|
| 294 |
Â
|
| 295 |
Â
/**
|
| 296 |
-
* Get an array of eu product codes
|
| 297 |
Â
*
|
| 298 |
-
* @param
|
| 299 |
Â
*
|
| 300 |
Â
* @return array
|
| 301 |
Â
*/
|
| 302 |
-
public function getEuProductCodes($
|
| 303 |
Â
{
|
| 304 |
Â
$euProductCodes = Mage::getSingleton('postnl_core/system_config_source_euProductOptions');
|
| 305 |
-
return $euProductCodes->getAvailableOptions($
|
| 306 |
Â
}
|
| 307 |
Â
|
| 308 |
Â
/**
|
| 309 |
-
* Get an array of global product codes
|
| 310 |
Â
*
|
| 311 |
-
* @param
|
| 312 |
Â
*
|
| 313 |
Â
* @return array
|
| 314 |
Â
*/
|
| 315 |
-
public function getGlobalProductCodes($
|
| 316 |
Â
{
|
| 317 |
Â
$globalProductCodes = Mage::getSingleton('postnl_core/system_config_source_globalProductOptions');
|
| 318 |
-
return $globalProductCodes->getAvailableOptions($
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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::
|
| 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 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
$
|
| 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
|
| 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::
|
| 643 |
-
$defaultEuOption = Mage::getStoreConfig(self::
|
| 644 |
-
$defaultGlobalOption = Mage::getStoreConfig(self::
|
| 645 |
Â
$defaultPakketautomaatOption = Mage::getStoreConfig(
|
| 646 |
-
self::
|
| 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 |
-
*
|
| 681 |
Â
*/
|
| 682 |
Â
$weight = $postnlShipment->getTotalWeight(true);
|
| 683 |
Â
|
| 684 |
Â
/**
|
| 685 |
-
*
|
| 686 |
Â
*/
|
| 687 |
-
$weightPerParcel = Mage::getStoreConfig(self::
|
| 688 |
Â
$weightPerParcel = $this->standardizeWeight($weightPerParcel, $shipment->getStoreId());
|
| 689 |
Â
|
| 690 |
Â
/**
|
| 691 |
-
*
|
| 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 |
-
*
|
| 786 |
-
*
|
| 787 |
-
*
|
| 788 |
-
*
|
| 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 |
-
*
|
| 884 |
-
*
|
| 885 |
-
*
|
| 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
|
| 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
|
| 967 |
Â
*/
|
| 968 |
Â
if (empty($streetname) || empty($housenumber)) {
|
| 969 |
Â
return false;
|
| 970 |
Â
}
|
| 971 |
Â
|
| 972 |
Â
/**
|
| 973 |
-
* Split the
|
| 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
|
| 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
|
| 1010 |
Â
*
|
| 1011 |
-
* @param string $fullStreet The full
|
| 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
|
| 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
|
| 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 = "
|
|
Â
|
|
| 1111 |
Â
. $requestXml
|
| 1112 |
-
.
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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 .=
|
| 1149 |
-
|
| 1150 |
-
|
| 1151 |
-
|
| 1152 |
-
|
| 1153 |
-
|
|
Â
|
|
|
Â
|
|
| 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;
|
|
@@ -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
|
| 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
|
| 75 |
Â
|
| 76 |
Â
/**
|
| 77 |
Â
* XML path to the test mode allowed config option.
|
| 78 |
Â
*/
|
| 79 |
-
const
|
| 80 |
Â
|
| 81 |
Â
/**
|
| 82 |
Â
* XML path to debug mode config option.
|
| 83 |
Â
*/
|
| 84 |
-
const
|
| 85 |
Â
|
| 86 |
Â
/**
|
| 87 |
Â
* XML path to 'is_activated' flag.
|
| 88 |
Â
*/
|
| 89 |
-
const
|
| 90 |
Â
|
| 91 |
Â
/**
|
| 92 |
Â
* XML path to 'show_error_details_in_frontend' flag.
|
| 93 |
Â
*/
|
| 94 |
-
const
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 95 |
Â
|
| 96 |
Â
/**
|
| 97 |
-
*
|
| 98 |
Â
*/
|
| 99 |
-
const
|
| 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 |
-
|
| 117 |
-
|
|
Â
|
|
|
Â
|
|
| 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 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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::
|
| 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 (!
|
| 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(
|
| 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(
|
| 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(
|
| 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(
|
| 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(
|
| 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(
|
| 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(
|
| 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(
|
| 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 '
|
| 586 |
-
$aclPath = '
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 587 |
Â
break;
|
| 588 |
-
case '
|
| 589 |
-
$aclPath = 'postnl/shipment/actions/
|
| 590 |
Â
break;
|
| 591 |
-
case '
|
| 592 |
-
$aclPath = 'postnl/shipment/actions/
|
| 593 |
Â
break;
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 594 |
Â
case 'send_track_and_trace':
|
| 595 |
-
$aclPath = 'postnl/shipment/actions/
|
| 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::
|
| 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::
|
| 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::
|
| 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
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 756 |
Â
*/
|
| 757 |
-
$postnlShippingMethodEnabled =
|
| 758 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
$
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 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::
|
| 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 |
-
*
|
|
Â
|
|
|
Â
|
|
| 1022 |
Â
*/
|
| 1023 |
Â
if ($this->isSystemConfig() || $this->isLoggingEnabled()) {
|
| 1024 |
Â
/**
|
| 1025 |
-
*
|
| 1026 |
-
* fields exactly are missing.
|
| 1027 |
Â
*
|
| 1028 |
Â
* @var Varien_Simplexml_Element $section
|
| 1029 |
Â
*/
|
| 1030 |
Â
$configFields = Mage::getSingleton('adminhtml/config');
|
| 1031 |
-
$
|
| 1032 |
-
$section = $sections->postnl;
|
| 1033 |
Â
}
|
| 1034 |
Â
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 1035 |
Â
foreach ($requiredFields as $requiredField) {
|
| 1036 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 1037 |
Â
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 1038 |
Â
if ($value !== null && $value !== '') {
|
| 1039 |
Â
continue;
|
| 1040 |
Â
}
|
| 1041 |
Â
|
| 1042 |
-
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
| 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' => $
|
| 1059 |
Â
);
|
|
Â
|
|
|
Â
|
|
| 1060 |
Â
|
| 1061 |
-
|
| 1062 |
-
|
|
Â
|
|
| 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
|
| 1170 |
Â
*
|
| 1171 |
Â
* @see Mage::log
|
| 1172 |
Â
*/
|
| 1173 |
Â
public function log($message, $level = null, $file = null, $forced = false, $isError = false)
|
| 1174 |
Â
{
|
| 1175 |
-
if ($isError === true
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 1176 |
Â
return $this;
|
| 1177 |
-
} elseif ($isError !== true
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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
|
| 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
|
| 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
|
| 1375 |
Â
*
|
| 1376 |
-
* @return
|
| 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
|
| 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 |
-
|
| 1577 |
-
|
| 1578 |
-
|
| 1579 |
-
|
| 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::
|
| 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 |
Â
|
|
@@ -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
|
| 59 |
-
const
|
| 60 |
-
const
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 156 |
Â
*
|
| 157 |
Â
* @param null|string $orderDate
|
| 158 |
Â
* @param null|int $storeId
|
|
Â
|
|
| 159 |
Â
*
|
| 160 |
-
* @return bool|string
|
| 161 |
Â
*/
|
| 162 |
-
public function
|
| 163 |
Â
{
|
| 164 |
-
if (
|
| 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 =
|
| 174 |
-
$
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 175 |
Â
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 176 |
Â
if ($deliveryDay == 1 && !Mage::helper('postnl/deliveryOptions')->canUseSundaySorting()) {
|
| 177 |
-
$
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 178 |
Â
}
|
| 179 |
Â
|
| 180 |
-
$deliveryDate =
|
| 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->
|
| 215 |
-
|
|
Â
|
|
|
Â
|
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
$
|
|
Â
|
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 '
|
|
Â
|
|
|
Â
|
|
| 449 |
Â
*
|
| 450 |
Â
* @return boolean
|
| 451 |
Â
*/
|
| 452 |
-
public function canUsePakketAutomaat()
|
| 453 |
Â
{
|
| 454 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 455 |
Â
|
| 456 |
Â
if ($cache && $cache->hasPostnlDeliveryOptionsCanUsePakketAutomaat()) {
|
| 457 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 458 |
Â
}
|
| 459 |
Â
|
| 460 |
Â
$allowed = $this->_canUsePakketAutomaat();
|
| 461 |
Â
|
| 462 |
Â
if ($cache) {
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 463 |
Â
$cache->setPostnlDeliveryOptionsCanUsePakketAutomaat($allowed)
|
| 464 |
Â
->saveCache();
|
| 465 |
Â
}
|
|
Â
|
|
|
Â
|
|
| 466 |
Â
return $allowed;
|
| 467 |
Â
}
|
| 468 |
Â
|
| 469 |
Â
/**
|
| 470 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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(
|
| 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
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 496 |
Â
*
|
| 497 |
-
* @
|
|
Â
|
|
|
Â
|
|
| 498 |
Â
*/
|
| 499 |
-
public function
|
| 500 |
Â
{
|
| 501 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 502 |
Â
|
| 503 |
-
|
| 504 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 505 |
Â
}
|
| 506 |
Â
|
| 507 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 508 |
Â
|
| 509 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 510 |
Â
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
return $allowed;
|
| 516 |
Â
}
|
| 517 |
Â
|
| 518 |
Â
/**
|
| 519 |
-
* Checks if
|
| 520 |
Â
*
|
| 521 |
-
* @
|
|
Â
|
|
|
Â
|
|
| 522 |
Â
*/
|
| 523 |
-
public function
|
| 524 |
Â
{
|
| 525 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 526 |
Â
|
| 527 |
-
|
| 528 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 529 |
Â
}
|
| 530 |
Â
|
| 531 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 532 |
Â
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
->saveCache();
|
| 536 |
-
}
|
| 537 |
-
return $allowed;
|
| 538 |
Â
}
|
| 539 |
Â
|
| 540 |
Â
/**
|
| 541 |
-
* Checks
|
| 542 |
Â
*
|
| 543 |
-
* @
|
|
Â
|
|
|
Â
|
|
| 544 |
Â
*/
|
| 545 |
-
|
| 546 |
Â
{
|
| 547 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 548 |
Â
|
| 549 |
-
|
| 550 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 551 |
Â
}
|
| 552 |
Â
|
| 553 |
-
|
| 554 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 555 |
Â
return false;
|
| 556 |
Â
}
|
| 557 |
Â
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
$
|
| 562 |
-
|
| 563 |
-
$
|
| 564 |
-
|
| 565 |
Â
|
| 566 |
-
|
|
Â
|
|
| 567 |
Â
}
|
| 568 |
Â
|
| 569 |
Â
/**
|
| 570 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 571 |
Â
*
|
| 572 |
Â
* @return bool
|
| 573 |
Â
*/
|
| 574 |
-
public function
|
| 575 |
Â
{
|
| 576 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 577 |
Â
|
| 578 |
-
|
| 579 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 580 |
Â
}
|
| 581 |
Â
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 585 |
Â
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 589 |
Â
}
|
| 590 |
Â
|
| 591 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 592 |
Â
}
|
| 593 |
Â
|
| 594 |
Â
/**
|
| 595 |
-
*
|
|
Â
|
|
|
Â
|
|
| 596 |
Â
*
|
| 597 |
-
* @param Mage_Sales_Model_Quote
|
| 598 |
Â
*
|
| 599 |
-
* @return
|
| 600 |
Â
*/
|
| 601 |
-
public function
|
| 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 |
-
*
|
|
Â
|
|
| 622 |
Â
*/
|
| 623 |
-
|
| 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
|
| 637 |
Â
*/
|
| 638 |
-
if ($
|
| 639 |
-
|
| 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 |
-
*
|
| 652 |
Â
*/
|
| 653 |
-
if (!$this->
|
| 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
|
| 669 |
Â
*/
|
| 670 |
-
if (
|
| 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
|
| 701 |
-
* such products.
|
| 702 |
Â
*/
|
| 703 |
-
$
|
| 704 |
-
|
| 705 |
-
$
|
| 706 |
-
|
| 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,
|
| 720 |
-
return
|
| 721 |
Â
}
|
| 722 |
Â
|
| 723 |
Â
/**
|
| 724 |
-
*
|
|
Â
|
|
|
Â
|
|
| 725 |
Â
*
|
| 726 |
Â
* @param Mage_Sales_Model_Quote $quote
|
| 727 |
Â
*
|
| 728 |
-
* @return
|
| 729 |
Â
*/
|
| 730 |
-
public function
|
| 731 |
Â
{
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 735 |
Â
}
|
| 736 |
Â
|
| 737 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 738 |
Â
return false;
|
| 739 |
Â
}
|
| 740 |
Â
|
| 741 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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::
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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(
|
|
@@ -39,15 +39,36 @@
|
|
| 39 |
Â
class TIG_PostNL_Helper_Mijnpakket extends TIG_PostNL_Helper_Data
|
| 40 |
Â
{
|
| 41 |
Â
/**
|
| 42 |
-
*
|
| 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 |
-
*
|
| 99 |
Â
*
|
| 100 |
-
* @
|
| 101 |
-
*
|
| 102 |
-
* @return string
|
| 103 |
Â
*/
|
| 104 |
-
public function
|
| 105 |
Â
{
|
| 106 |
-
$
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 107 |
Â
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
$initials .= substr($name, 0, 1) . '.';
|
| 111 |
Â
}
|
| 112 |
Â
|
| 113 |
-
$
|
| 114 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
}
|
|
@@ -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
|
| 45 |
Â
|
| 46 |
Â
/**
|
| 47 |
Â
* XML path to the active/inactive setting
|
| 48 |
Â
*/
|
| 49 |
-
const
|
| 50 |
Â
|
| 51 |
Â
/**
|
| 52 |
Â
* XML path to the customer code setting.
|
| 53 |
Â
*/
|
| 54 |
-
const
|
| 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
|
| 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::
|
| 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::
|
| 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::
|
| 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;
|
|
@@ -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 |
+
}
|
|
@@ -45,18 +45,18 @@ class TIG_PostNL_Helper_Webservices extends TIG_PostNL_Helper_Data
|
|
| 45 |
Â
/**
|
| 46 |
Â
* XML paths for security keys
|
| 47 |
Â
*/
|
| 48 |
-
const
|
| 49 |
-
const
|
| 50 |
Â
|
| 51 |
Â
/**
|
| 52 |
Â
* XML path to updateStatistics on/off switch
|
| 53 |
Â
*/
|
| 54 |
-
const
|
| 55 |
Â
|
| 56 |
Â
/**
|
| 57 |
Â
* XML path to receiveUpdates on/off switch
|
| 58 |
Â
*/
|
| 59 |
-
const
|
| 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::
|
| 91 |
Â
} else {
|
| 92 |
Â
/**
|
| 93 |
Â
* otherwise, check if ending statistics was enabled in default settings
|
| 94 |
Â
*/
|
| 95 |
-
$sendStatistics = Mage::getStoreConfigFlag(self::
|
| 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::
|
| 106 |
-
$uniqueKey = Mage::getStoreConfig(self::
|
| 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::
|
| 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
|
| 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
|
| 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 |
Â
*/
|
|
@@ -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)
|
| 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
|
|
@@ -73,7 +73,7 @@ class TIG_PostNL_Model_AddressValidation_Observer_AddressBook extends Varien_Obj
|
|
| 73 |
Â
*
|
| 74 |
Â
* @param Varien_Event_Observer $observer
|
| 75 |
Â
*
|
| 76 |
-
* @return
|
| 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 |
Â
*
|
|
@@ -81,7 +81,7 @@ class TIG_PostNL_Model_AddressValidation_Observer_OneStepCheckout extends Varien
|
|
| 81 |
Â
*
|
| 82 |
Â
* @param Varien_Event_Observer $observer
|
| 83 |
Â
*
|
| 84 |
-
* @return
|
| 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 |
Â
*
|
|
@@ -93,7 +93,7 @@ class TIG_PostNL_Model_AddressValidation_Observer_Onepage extends Varien_Object
|
|
| 93 |
Â
*
|
| 94 |
Â
* @param Varien_Event_Observer $observer
|
| 95 |
Â
*
|
| 96 |
-
* @return
|
| 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
|
| 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 |
Â
*
|
|
@@ -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 |
+
}
|
|
@@ -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(
|
|
Â
|
|
|
Â
|
|
| 54 |
Â
|
| 55 |
Â
return true;
|
| 56 |
Â
}
|
| 57 |
Â
|
| 58 |
Â
if ($request->getParam('order_ids')) {
|
| 59 |
-
$eventModel->setInfo(
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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
|
| 72 |
Â
|
| 73 |
Â
/**
|
| 74 |
-
* XML path to
|
| 75 |
Â
*/
|
| 76 |
-
const
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
*
|
| 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(
|
| 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'
|
| 162 |
Â
)
|
| 163 |
Â
);
|
| 164 |
Â
|
| 165 |
Â
/**
|
| 166 |
-
* Join
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
$
|
| 272 |
Â
'header' => $helper->__('Shipment type'),
|
| 273 |
Â
'align' => 'left',
|
| 274 |
Â
'index' => 'country_id',
|
| 275 |
Â
'type' => 'options',
|
| 276 |
-
'renderer' => 'postnl_adminhtml/
|
| 277 |
-
'width' => '
|
| 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 |
-
$
|
| 292 |
-
|
| 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
|
|
Â
|
|
| 298 |
Â
*/
|
| 299 |
-
if (
|
| 300 |
-
$
|
| 301 |
-
$
|
| 302 |
-
$
|
| 303 |
Â
}
|
| 304 |
Â
|
| 305 |
Â
$block->addColumnAfter(
|
| 306 |
Â
'country_id',
|
| 307 |
-
$
|
| 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 (
|
| 331 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 332 |
Â
}
|
| 333 |
Â
|
| 334 |
Â
/**
|
| 335 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 336 |
Â
*/
|
| 337 |
Â
$massActionData = array(
|
| 338 |
Â
'label'=> $helper->__('PostNL - Create Shipments'),
|
| 339 |
Â
'url' => Mage::helper('adminhtml')->getUrl('postnl_admin/adminhtml_shipment/massCreateShipments'),
|
| 340 |
Â
);
|
| 341 |
Â
|
| 342 |
-
$
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 343 |
Â
|
| 344 |
Â
if ($showOptions) {
|
|
Â
|
|
|
Â
|
|
| 345 |
Â
/**
|
| 346 |
-
* Add another dropdown containing the possible product options
|
|
Â
|
|
| 347 |
Â
*/
|
| 348 |
-
$
|
| 349 |
-
'
|
| 350 |
-
'name'
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 351 |
Â
'type' => 'select',
|
| 352 |
Â
'class' => 'required-entry',
|
| 353 |
Â
'label' => $helper->__('Product options'),
|
| 354 |
-
'values' =>
|
| 355 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 356 |
Â
),
|
| 357 |
Â
);
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 358 |
Â
}
|
| 359 |
Â
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 360 |
Â
/**
|
| 361 |
-
*
|
| 362 |
Â
*/
|
| 363 |
-
$
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
);
|
| 368 |
Â
|
| 369 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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(
|
| 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($
|
| 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($
|
| 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
|
| 405 |
-
* @param array $filter Array of filters to be added
|
| 406 |
Â
*
|
| 407 |
Â
* @return $this
|
| 408 |
Â
*/
|
| 409 |
-
protected function _filterCollection($
|
| 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
|
| 427 |
-
* @param Mage_Adminhtml_Block_Widget_Grid_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 |
-
$
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
*
|
| 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($
|
| 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);
|
|
@@ -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
|
| 74 |
Â
|
| 75 |
Â
/**
|
| 76 |
Â
* XML path to default selected mass action setting
|
| 77 |
Â
*/
|
| 78 |
-
const
|
| 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::
|
| 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(
|
| 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 |
-
*
|
|
Â
|
|
| 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 |
-
|
| 213 |
-
|
| 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 |
-
'
|
| 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(
|
| 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' => '
|
| 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(
|
| 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
|
|
Â
|
|
| 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' => '
|
| 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 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
|
Â
|
|
|
Â
|
|
| 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 ($
|
| 606 |
-
&& date('Ymd', $dateModel->gmtTimestamp()) == date('Ymd', strtotime($origValue))
|
| 607 |
-
) {
|
| 608 |
Â
return 'grid-severity-major';
|
| 609 |
Â
}
|
| 610 |
Â
|
| 611 |
-
if ($
|
| 612 |
-
&& $dateModel->gmtTimestamp() > strtotime($origValue)
|
| 613 |
-
) {
|
| 614 |
Â
return 'grid-severity-critical';
|
| 615 |
Â
}
|
| 616 |
Â
|
| 617 |
-
|
| 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'
|
| 757 |
-
'url'
|
| 758 |
Â
);
|
| 759 |
Â
|
| 760 |
Â
$printOptions = array(
|
| 761 |
-
'label'
|
| 762 |
-
'url'
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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()
|
| 783 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 784 |
Â
|
| 785 |
Â
$printAdditional->setData(
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 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::
|
| 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
|
| 827 |
-
$
|
| 828 |
-
$
|
|
Â
|
|
| 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(
|
| 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($
|
| 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($
|
| 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($
|
| 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($
|
| 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);
|
|
@@ -50,7 +50,7 @@ class TIG_PostNL_Model_Adminhtml_Observer_ShipmentView
|
|
| 50 |
Â
*
|
| 51 |
Â
* @param Varien_Event_Observer $observer
|
| 52 |
Â
*
|
| 53 |
-
* @return
|
| 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 |
-
|
| 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(
|
| 151 |
-
'
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 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(
|
| 168 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 169 |
Â
"deleteConfirm('"
|
| 170 |
Â
. $helper->__('Are you sure you want to send PostNL tracking information to the customer?')
|
| 171 |
Â
. "', '" . $resendTrackAndTraceUrl . "')"
|
| 172 |
Â
);
|
| 173 |
Â
}
|
| 174 |
Â
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
Â
|
|
| 184 |
Â
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 195 |
Â
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
Â
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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'),
|
|
@@ -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
|
| 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::
|
| 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 |
-
|
| 505 |
-
|
| 506 |
-
|
|
Â
|
|
|
Â
|
|
| 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(
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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
|
| 47 |
Â
|
| 48 |
Â
/**
|
| 49 |
Â
* XML paths for various options
|
| 50 |
Â
*/
|
| 51 |
-
const
|
| 52 |
-
const
|
| 53 |
-
const
|
| 54 |
-
const
|
| 55 |
-
const
|
| 56 |
-
const
|
| 57 |
-
const
|
| 58 |
-
const
|
| 59 |
-
const
|
| 60 |
-
const
|
| 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
|
| 67 |
Â
|
| 68 |
Â
/**
|
| 69 |
Â
* XML paths for shipment reference info
|
| 70 |
Â
*/
|
| 71 |
-
const
|
| 72 |
-
const
|
| 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::
|
| 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::
|
| 408 |
Â
if ($newsletterSubscription) {
|
| 409 |
Â
$communicationOptions[] = array(
|
| 410 |
Â
'Code' => 'NEWS',
|
| 411 |
Â
);
|
| 412 |
Â
}
|
| 413 |
Â
|
| 414 |
-
$remark = Mage::getStoreConfigFlag(self::
|
| 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::
|
| 460 |
Â
if ($useMobile) {
|
| 461 |
Â
$optional['MobileNumber'] = 'True';
|
| 462 |
Â
}
|
| 463 |
Â
|
| 464 |
-
$useDob = Mage::getStoreConfigFlag(self::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 706 |
-
$foreignAddress = Mage::getStoreConfigFlag(self::
|
| 707 |
-
$priceOverview = Mage::getStoreConfigFlag(self::
|
| 708 |
-
$agreeConditions = Mage::getStoreConfigFlag(self::
|
| 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::
|
| 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::
|
| 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(
|
|
@@ -43,7 +43,7 @@ class TIG_PostNL_Model_Checkout_Observer_Order
|
|
| 43 |
Â
*
|
| 44 |
Â
* @param Varien_Event_Observer $observer
|
| 45 |
Â
*
|
| 46 |
-
* @return
|
| 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 |
Â
*
|
|
@@ -45,7 +45,7 @@ class TIG_PostNL_Model_Checkout_Observer_Shipment
|
|
| 45 |
Â
*
|
| 46 |
Â
* @param Varien_Event_Observer $observer
|
| 47 |
Â
*
|
| 48 |
-
* @return
|
| 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 |
Â
*
|
|
@@ -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
|
| 49 |
Â
|
| 50 |
Â
/**
|
| 51 |
Â
* Constants containing XML paths to cif address configuration options
|
| 52 |
Â
*/
|
| 53 |
-
const
|
| 54 |
-
const
|
| 55 |
-
const
|
| 56 |
-
const
|
| 57 |
-
const
|
| 58 |
-
const
|
| 59 |
-
const
|
| 60 |
-
const
|
| 61 |
-
const
|
| 62 |
-
const
|
| 63 |
-
const
|
| 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
|
| 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
|
| 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
|
| 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
|
| 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::
|
| 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
|
| 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::
|
| 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
|
| 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::
|
| 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::
|
| 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
|
| 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(
|
| 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
|
| 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
|
| 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::
|
| 764 |
-
$departmentField = Mage::getStoreConfig(self::
|
| 765 |
-
$doorcodeField = Mage::getStoreConfig(self::
|
| 766 |
-
$floorField = Mage::getStoreConfig(self::
|
| 767 |
-
$areaField = Mage::getStoreConfig(self::
|
| 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::
|
| 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::
|
| 873 |
-
$housenumberField = Mage::getStoreCOnfig(self::
|
| 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::
|
| 884 |
Â
if (!$splitHousenumber) {
|
| 885 |
Â
$housenumber = $addressData->Huisnummer . ' ' . $addressData->HuisnummerExt;
|
| 886 |
Â
$streetData[$housenumberField] = $housenumber;
|
| 887 |
Â
} else {
|
| 888 |
-
$housenumberExtensionField = Mage::getStoreConfig(self::
|
| 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
|
| 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::
|
| 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
|
| 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 |
Â
{
|
|
@@ -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)
|
| 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
|
|
@@ -58,7 +58,7 @@ class TIG_PostNL_Model_Checkout_System_Config_Source_CmsPage
|
|
| 58 |
Â
*
|
| 59 |
Â
* @param array $options
|
| 60 |
Â
*
|
| 61 |
-
* @return
|
| 62 |
Â
*/
|
| 63 |
Â
public function setOptions($options)
|
| 64 |
Â
{
|
| 58 |
Â
*
|
| 59 |
Â
* @param array $options
|
| 60 |
Â
*
|
| 61 |
+
* @return $this
|
| 62 |
Â
*/
|
| 63 |
Â
public function setOptions($options)
|
| 64 |
Â
{
|
|
@@ -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)
|
| 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
|
| 107 |
Â
*/
|
| 108 |
-
protected $_cacheId
|
| 109 |
Â
|
| 110 |
Â
/**
|
| 111 |
Â
* Flag whether or not the cache may be used.
|
| 112 |
Â
*
|
| 113 |
Â
* @var null|boolean
|
| 114 |
Â
*/
|
| 115 |
-
protected $_canUseCache
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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->
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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(
|
| 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 |
-
|
| 277 |
-
Mage::app()->cleanCache(self::CACHE_TAG);
|
| 278 |
Â
|
| 279 |
-
|
| 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 |
Â
}
|
|
@@ -58,64 +58,64 @@
|
|
| 58 |
Â
class TIG_PostNL_Model_Core_Cif extends TIG_PostNL_Model_Core_Cif_Abstract
|
| 59 |
Â
{
|
| 60 |
Â
/**
|
| 61 |
-
* Constants containing
|
| 62 |
Â
*/
|
| 63 |
-
const
|
| 64 |
-
const
|
| 65 |
-
const
|
| 66 |
-
const
|
| 67 |
-
const
|
| 68 |
Â
|
| 69 |
Â
/**
|
| 70 |
-
* Constants containing
|
| 71 |
Â
*/
|
| 72 |
-
const
|
| 73 |
-
const
|
| 74 |
-
const
|
| 75 |
-
const
|
| 76 |
-
const
|
| 77 |
-
const
|
| 78 |
Â
|
| 79 |
Â
/**
|
| 80 |
-
* Constants containing
|
| 81 |
Â
*/
|
| 82 |
-
const
|
| 83 |
-
const
|
| 84 |
-
const
|
| 85 |
-
const
|
| 86 |
-
const
|
| 87 |
-
const
|
| 88 |
-
const
|
| 89 |
-
const
|
| 90 |
-
const
|
| 91 |
Â
|
| 92 |
Â
/**
|
| 93 |
-
*
|
| 94 |
Â
*/
|
| 95 |
-
const
|
| 96 |
Â
|
| 97 |
Â
/**
|
| 98 |
-
*
|
| 99 |
Â
*
|
| 100 |
Â
* N.B. missing last part so this will return an array of all fields.
|
| 101 |
Â
*/
|
| 102 |
-
const
|
| 103 |
Â
|
| 104 |
Â
/**
|
| 105 |
-
*
|
| 106 |
Â
*
|
| 107 |
Â
* N.B. missing last part so this will return an array of all fields.
|
| 108 |
Â
*/
|
| 109 |
-
const
|
| 110 |
Â
|
| 111 |
-
|
| 112 |
-
*
|
| 113 |
Â
*/
|
| 114 |
-
const
|
| 115 |
-
const
|
| 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 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 128 |
Â
*/
|
| 129 |
-
const
|
|
Â
|
|
|
Â
|
|
| 130 |
Â
|
| 131 |
Â
/**
|
| 132 |
-
*
|
| 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
|
| 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 |
-
|
| 529 |
-
|
| 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 |
-
|
| 617 |
-
|
| 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 |
-
|
| 733 |
-
|
| 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 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 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
|
| 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::
|
| 827 |
-
$parcelWeight = Mage::helper('postnl
|
| 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 =
|
| 852 |
-
$deliveryDate =
|
| 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 |
-
|
| 864 |
-
|
| 865 |
Â
'Dimension' => array(
|
| 866 |
-
|
| 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 |
-
|
| 879 |
-
|
| 880 |
-
|
| 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-
|
| 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 |
-
|
| 928 |
-
|
| 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
|
| 996 |
-
*
|
| 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::
|
| 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::
|
| 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 |
-
*
|
| 1032 |
-
*
|
| 1033 |
Â
*/
|
| 1034 |
-
$returnAddress = Mage::getStoreConfig(self::
|
| 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
|
|
Â
|
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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,
|
| 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 =
|
| 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::
|
| 1432 |
Â
$this->getStoreId()
|
| 1433 |
Â
);
|
| 1434 |
Â
$sortingDirection = Mage::getStoreConfig(
|
| 1435 |
-
self::
|
| 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()->
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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::
|
| 1485 |
Â
return '000000';
|
| 1486 |
Â
}
|
| 1487 |
Â
|
| 1488 |
Â
if ($this->hasHSTariffAttribute()) {
|
| 1489 |
Â
$hsTariffAttribute = $this->getHSTariffAttribute();
|
| 1490 |
Â
} else {
|
| 1491 |
-
$hsTariffAttribute = Mage::getStoreConfig(self::
|
| 1492 |
Â
$this->setHSTariffAttribute($hsTariffAttribute);
|
| 1493 |
Â
}
|
| 1494 |
Â
|
| 1495 |
-
$
|
| 1496 |
-
|
| 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::
|
| 1523 |
Â
$storeId
|
| 1524 |
Â
);
|
| 1525 |
Â
$this->setCountryOfOriginAttribute($countryOfOriginAttribute);
|
| 1526 |
Â
}
|
| 1527 |
Â
|
| 1528 |
-
$
|
| 1529 |
-
|
| 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
|
| 1536 |
-
|
|
Â
|
|
| 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::
|
| 1561 |
Â
$this->setCustomsValueAttribute($customsValueAttribute);
|
| 1562 |
Â
}
|
| 1563 |
Â
|
| 1564 |
-
$
|
| 1565 |
-
|
| 1566 |
-
->getDataUsingMethod($customsValueAttribute);
|
| 1567 |
Â
|
| 1568 |
Â
if (empty($customsValue)) {
|
|
Â
|
|
| 1569 |
Â
throw new TIG_PostNL_Exception(
|
| 1570 |
-
Mage::helper('postnl')->__(
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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::
|
| 1594 |
Â
$this->setCustomsDescriptionAttribute($descriptionAttribute);
|
| 1595 |
Â
}
|
| 1596 |
Â
|
| 1597 |
-
$
|
| 1598 |
-
|
| 1599 |
-
->getDataUsingMethod($descriptionAttribute);
|
| 1600 |
Â
|
| 1601 |
Â
if (empty($description)) {
|
|
Â
|
|
| 1602 |
Â
throw new TIG_PostNL_Exception(
|
| 1603 |
Â
Mage::helper('postnl')->__(
|
| 1604 |
-
'Missing customs description for product
|
| 1605 |
-
|
|
Â
|
|
| 1606 |
Â
),
|
| 1607 |
-
'POSTNL-
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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
|
| 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::
|
| 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
|
| 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::
|
| 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::
|
| 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 |
-
|
| 1882 |
-
|
| 1883 |
-
|
| 1884 |
-
|
| 1885 |
-
|
| 1886 |
-
|
| 1887 |
-
|
| 1888 |
-
|
| 1889 |
-
|
| 1890 |
-
|
| 1891 |
-
|
| 1892 |
-
|
| 1893 |
-
|
| 1894 |
-
|
| 1895 |
-
|
| 1896 |
-
|
| 1897 |
-
|
| 1898 |
-
|
| 1899 |
-
|
| 1900 |
-
|
| 1901 |
-
|
| 1902 |
-
|
| 1903 |
-
|
| 1904 |
-
|
| 1905 |
-
|
| 1906 |
-
|
| 1907 |
-
|
| 1908 |
-
|
| 1909 |
-
|
| 1910 |
-
|
| 1911 |
-
|
| 1912 |
-
|
| 1913 |
-
|
| 1914 |
-
|
| 1915 |
-
|
| 1916 |
-
|
| 1917 |
-
|
| 1918 |
-
|
| 1919 |
-
|
| 1920 |
-
|
| 1921 |
-
|
| 1922 |
-
|
| 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 |
Â
}
|
|
@@ -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
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
|
| 608 |
-
|
| 609 |
-
|
|
Â
|
|
|
Â
|
|
| 610 |
Â
|
| 611 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
}
|
|
@@ -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)
|
| 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
|
| 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
|
| 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
|
| 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
|
| 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 |
Â
{
|
|
@@ -41,16 +41,23 @@
|
|
| 41 |
Â
class TIG_PostNL_Model_Core_Label extends Varien_Object
|
| 42 |
Â
{
|
| 43 |
Â
/**
|
| 44 |
-
*
|
|
Â
|
|
| 45 |
Â
*/
|
| 46 |
-
const TEMP_LABEL_FILENAME
|
|
Â
|
|
| 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
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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
|
| 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
|
| 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::
|
| 156 |
Â
|
| 157 |
Â
$this->setLabelSize($labelSize);
|
| 158 |
Â
return $labelSize;
|
| 159 |
Â
}
|
| 160 |
Â
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 161 |
Â
/**
|
| 162 |
Â
* Reset the counter to 0
|
| 163 |
Â
*
|
| 164 |
-
* @return
|
| 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
|
| 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
|
| 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
|
|
Â
|
|
| 210 |
Â
*
|
| 211 |
-
* @param
|
|
Â
|
|
| 212 |
Â
*
|
| 213 |
-
* @return
|
| 214 |
Â
*
|
| 215 |
Â
* @see TIG_PostNL_Fpdf
|
| 216 |
Â
* @see TIG_PostNL_Fpdi
|
| 217 |
Â
*
|
| 218 |
-
* @link http://www.fpdf.org/
|
| 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',
|
| 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 |
-
*
|
| 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) >
|
| 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 |
-
$
|
|
Â
|
|
| 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/
|
| 315 |
Â
*/
|
| 316 |
-
$tempFilename = $this->_saveTempLabel($label
|
| 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'
|
| 325 |
-
|
| 326 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
}
|
|
Â
|
|
|
Â
|
|
| 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 |
-
|
| 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 |
-
|
| 418 |
-
|
| 419 |
-
|
|
Â
|
|
| 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
|
| 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,
|
| 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
|
| 489 |
Â
*/
|
| 490 |
Â
protected function _destroyTempLabels()
|
| 491 |
Â
{
|
| 492 |
Â
$tempFilesSaved = $this->getTempFilesSaved();
|
| 493 |
Â
foreach ($tempFilesSaved as $tempFile) {
|
| 494 |
-
|
|
Â
|
|
|
Â
|
|
| 495 |
Â
}
|
| 496 |
Â
|
| 497 |
Â
return $this;
|
| 498 |
Â
}
|
| 499 |
Â
|
| 500 |
Â
/**
|
| 501 |
-
* Sorts labels by label type. First all labels of the 'Label'
|
| 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 |
-
|
| 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'
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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 |
-
*
|
| 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 =
|
| 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 |
Â
|
|
@@ -43,7 +43,7 @@ class TIG_PostNL_Model_Core_Observer_Barcode
|
|
| 43 |
Â
*
|
| 44 |
Â
* @param Varien_Event_Observer $observer
|
| 45 |
Â
*
|
| 46 |
-
* @return
|
| 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 (!
|
| 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
|
| 125 |
-
*
|
| 126 |
-
*
|
| 127 |
Â
*/
|
| 128 |
Â
try {
|
| 129 |
-
$postnlShipment->saveAdditionalShippingOptions()
|
| 130 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
}
|
|
@@ -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');
|
|
@@ -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
|
| 45 |
Â
|
| 46 |
Â
/**
|
| 47 |
Â
* XML path to confirmation expire time setting
|
| 48 |
Â
*/
|
| 49 |
-
const
|
| 50 |
Â
|
| 51 |
Â
/**
|
| 52 |
Â
* XML path to setting that determines whether or not to send track and trace emails
|
| 53 |
Â
*/
|
| 54 |
-
const
|
| 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 |
-
*
|
| 61 |
-
*
|
| 62 |
-
*
|
| 63 |
-
* being overburdened or the server running out of harddrive space.
|
| 64 |
Â
*
|
| 65 |
-
* @return
|
| 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(
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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(
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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
|
| 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
|
| 289 |
-
* Only
|
| 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
|
| 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.
|
|
Â
|
|
| 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
|
| 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 =
|
| 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
|
| 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(
|
| 492 |
-
|
| 493 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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 |
-
|
| 543 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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::
|
| 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 =
|
| 593 |
-
$twentyMinutesAgo
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 594 |
Â
|
| 595 |
-
$helper->cronLog("Track and trace email will be sent for all shipments that were confirmed on or before
|
|
Â
|
|
| 596 |
Â
|
| 597 |
Â
/**
|
| 598 |
-
* Get all postnl shipments that have been confirmed over 20 minutes ago whose track & trace e-mail has not yet
|
|
Â
|
|
| 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(
|
|
Â
|
|
|
Â
|
|
| 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
|
|
Â
|
|
| 686 |
Â
*
|
| 687 |
-
* @return
|
| 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
|
| 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`
|
|
Â
|
|
| 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
|
|
@@ -59,20 +59,35 @@ class TIG_PostNL_Model_Core_Observer_SaveShipment
|
|
| 59 |
Â
}
|
| 60 |
Â
|
| 61 |
Â
/**
|
| 62 |
-
*
|
| 63 |
Â
*
|
| 64 |
Â
* @var Mage_Core_Controller_Varien_Front $controller
|
| 65 |
Â
*/
|
| 66 |
-
$controller
|
| 67 |
-
$
|
| 68 |
Â
|
| 69 |
-
if ($
|
| 70 |
-
|
| 71 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 72 |
Â
}
|
| 73 |
Â
|
| 74 |
-
|
| 75 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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;
|
|
@@ -38,35 +38,41 @@
|
|
| 38 |
Â
*
|
| 39 |
Â
* Class TIG_PostNL_Model_Core_Order
|
| 40 |
Â
*
|
| 41 |
-
* @method string
|
| 42 |
-
* @method
|
| 43 |
-
* @method
|
| 44 |
-
* @method
|
| 45 |
-
* @method string
|
| 46 |
-
* @method
|
| 47 |
-
* @method
|
| 48 |
-
* @method
|
| 49 |
-
* @method
|
| 50 |
-
* @method
|
| 51 |
-
* @method int
|
| 52 |
-
* @method
|
| 53 |
-
* @method
|
| 54 |
-
* @method
|
| 55 |
-
*
|
| 56 |
-
* @method TIG_PostNL_Model_Core_Order
|
| 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
|
| 69 |
-
* @method TIG_PostNL_Model_Core_Order
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
*
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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
|
| 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');
|
|
@@ -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
|
| 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 |
Â
{
|
|
@@ -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)
|
| 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
|
|
@@ -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)
|
| 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
|
|
@@ -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)
|
| 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
|
|
@@ -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)
|
| 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
|
|
@@ -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)
|
| 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
|
|
@@ -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)
|
| 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
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 255 |
Â
*
|
| 256 |
-
* @
|
| 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 |
-
|
| 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 |
-
$
|
| 312 |
-
if (!$
|
| 313 |
Â
return null;
|
| 314 |
Â
}
|
| 315 |
Â
|
| 316 |
Â
/**
|
| 317 |
Â
* @var Mage_Sales_Model_Order_Address $address
|
| 318 |
Â
*/
|
| 319 |
-
$addresses = $
|
| 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
|
| 384 |
-
* |
|
| 385 |
-
* |
|
| 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 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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(
|
| 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 =
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 837 |
Â
{
|
| 838 |
Â
$cifHelper = $this->getHelper('cif');
|
| 839 |
Â
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
return
|
| 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
|
| 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 =
|
| 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 |
-
$
|
| 1085 |
-
$confirmDate =
|
| 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 |
-
$
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
$
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 1298 |
Â
*
|
| 1299 |
Â
* @return boolean
|
| 1300 |
Â
*/
|
|
@@ -1368,14 +1901,42 @@ class TIG_PostNL_Model_Core_Shipment extends Mage_Core_Model_Abstract
|
|
| 1368 |
Â
}
|
| 1369 |
Â
|
| 1370 |
Â
/**
|
| 1371 |
-
*
|
| 1372 |
Â
*
|
| 1373 |
Â
* @return boolean
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 1374 |
Â
*
|
| 1375 |
-
* @
|
| 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->
|
| 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
|
| 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
|
| 1525 |
Â
*/
|
| 1526 |
-
public function
|
| 1527 |
Â
{
|
| 1528 |
-
|
|
Â
|
|
| 1529 |
Â
return false;
|
| 1530 |
Â
}
|
| 1531 |
Â
|
| 1532 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 1533 |
Â
return false;
|
| 1534 |
Â
}
|
| 1535 |
Â
|
| 1536 |
-
if (
|
| 1537 |
-
|
| 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
|
|
Â
|
|
|
Â
|
|
| 1549 |
Â
*
|
| 1550 |
Â
* @return boolean
|
| 1551 |
Â
*/
|
| 1552 |
-
public function
|
| 1553 |
Â
{
|
| 1554 |
-
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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->
|
| 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->
|
| 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->
|
| 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 |
-
*
|
| 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 |
-
$
|
| 2604 |
-
if (
|
|
Â
|
|
|
Â
|
|
| 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
|
| 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(
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 2739 |
Â
->setShippingPhase(false) //delete current shipping phase
|
| 2740 |
-
->setConfirmedAt(false) //delete 'confirmed at' date
|
| 2741 |
-
|
|
Â
|
|
| 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 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 2912 |
Â
*/
|
| 2913 |
-
if (!$this->
|
| 2914 |
-
$this->
|
| 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 |
Â
}
|
|
@@ -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
|
| 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 |
Â
{
|
|
@@ -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)
|
| 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
|
|
@@ -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
|
| 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
|
| 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
|
| 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 |
Â
{
|
|
@@ -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)
|
| 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
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 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(
|
| 135 |
Â
|
| 136 |
-
return
|
| 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 |
Â
/**
|
|
@@ -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 |
-
*
|
| 43 |
Â
*/
|
| 44 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 45 |
Â
|
| 46 |
Â
/**
|
| 47 |
-
*
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 48 |
Â
*
|
| 49 |
-
* @param
|
|
Â
|
|
|
Â
|
|
| 50 |
Â
*
|
| 51 |
Â
* @return array
|
| 52 |
-
*
|
| 53 |
-
* @todo implement COD
|
| 54 |
Â
*/
|
| 55 |
-
public function
|
| 56 |
Â
{
|
| 57 |
-
$
|
| 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 |
-
$
|
| 245 |
Â
'value' => '4955',
|
| 246 |
Â
'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
|
| 247 |
Â
'isBelgiumOnly' => true,
|
|
Â
|
|
| 248 |
Â
);
|
| 249 |
Â
}
|
| 250 |
Â
|
| 251 |
-
return $
|
| 252 |
Â
}
|
| 253 |
Â
|
| 254 |
Â
/**
|
| 255 |
-
*
|
| 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
|
| 270 |
-
|
| 271 |
-
$
|
| 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 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 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 $
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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
|
| 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.
|
|
@@ -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)
|
| 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
|
|
@@ -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)
|
| 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
|
|
@@ -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)
|
| 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 |
-
*
|
| 43 |
Â
*/
|
| 44 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 45 |
Â
|
| 46 |
Â
/**
|
| 47 |
-
*
|
| 48 |
Â
*
|
| 49 |
-
* @
|
|
Â
|
|
|
Â
|
|
| 50 |
Â
*
|
| 51 |
-
* @
|
| 52 |
Â
*/
|
| 53 |
-
public function
|
| 54 |
Â
{
|
| 55 |
-
$
|
| 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 |
-
$
|
| 89 |
Â
'value' => '4955',
|
| 90 |
Â
'label' => $helper->__('EU Pack Standard (Belgium only, no signature)'),
|
| 91 |
Â
'isBelgiumOnly' => true,
|
|
Â
|
|
| 92 |
Â
);
|
| 93 |
Â
}
|
| 94 |
Â
|
| 95 |
-
return $
|
| 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 |
Â
}
|
|
@@ -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 |
-
*
|
| 43 |
Â
*/
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 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 |
Â
}
|
|
@@ -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 |
-
$
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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)
|
| 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
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
-
*
|
| 43 |
Â
*/
|
| 44 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
$
|
| 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 |
-
*
|
| 107 |
Â
*
|
| 108 |
-
* @param boolean $
|
| 109 |
Â
*
|
| 110 |
Â
* @return array
|
| 111 |
Â
*/
|
| 112 |
-
public function
|
| 113 |
Â
{
|
| 114 |
-
|
| 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
|
| 134 |
Â
*
|
| 135 |
-
* @param
|
| 136 |
-
* @param boolean $codesOnly
|
| 137 |
-
* @param boolean $isPge
|
| 138 |
Â
*
|
| 139 |
Â
* @return array
|
| 140 |
Â
*/
|
| 141 |
-
public function
|
| 142 |
Â
{
|
| 143 |
-
|
| 144 |
-
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 185 |
Â
}
|
| 186 |
Â
|
| 187 |
Â
/**
|
| 188 |
-
*
|
| 189 |
Â
*
|
| 190 |
-
* @param bool $
|
| 191 |
-
* @param bool $codesOnly
|
| 192 |
Â
*
|
| 193 |
Â
* @return array
|
| 194 |
Â
*/
|
| 195 |
-
public function
|
| 196 |
Â
{
|
| 197 |
-
return $this->
|
| 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 |
Â
}
|
|
@@ -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 |
-
*
|
| 43 |
Â
*/
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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)
|
| 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
|
|
@@ -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
|
| 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.
|
|
@@ -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 |
+
}
|
|
@@ -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 |
-
*
|
| 43 |
Â
*/
|
| 44 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 45 |
Â
|
| 46 |
Â
/**
|
| 47 |
-
*
|
| 48 |
Â
*
|
| 49 |
Â
* @return array
|
| 50 |
-
*
|
| 51 |
-
* @todo implement COD
|
| 52 |
Â
*/
|
| 53 |
Â
public function toOptionArray()
|
| 54 |
Â
{
|
| 55 |
-
$
|
| 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 |
-
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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
|
| 168 |
-
* @param boolean $codesOnly
|
| 169 |
-
* @param boolean $isAvond
|
| 170 |
Â
*
|
| 171 |
Â
* @return array
|
| 172 |
Â
*/
|
| 173 |
-
public function getAvailableOptions($
|
| 174 |
Â
{
|
| 175 |
-
|
| 176 |
-
|
| 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 |
-
|
| 214 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 215 |
Â
|
| 216 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 217 |
Â
}
|
| 218 |
Â
|
| 219 |
Â
/**
|
| 220 |
-
*
|
| 221 |
Â
*
|
| 222 |
-
* @param
|
| 223 |
-
* @param bool $codesOnly
|
| 224 |
Â
*
|
| 225 |
Â
* @return array
|
| 226 |
Â
*/
|
| 227 |
-
public function
|
| 228 |
Â
{
|
| 229 |
-
return $this->
|
| 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 |
Â
}
|
|
@@ -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)
|
| 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
|
| 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::
|
| 90 |
Â
} elseif ($request->getParam('website')) {
|
| 91 |
Â
$website = Mage::getModel('core/website')->load($request->getParam('website'), 'code');
|
| 92 |
-
$lineCount = $website->getConfig(self::
|
| 93 |
Â
} else {
|
| 94 |
Â
$lineCount = Mage::getStoreConfig(
|
| 95 |
-
self::
|
| 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 |
Â
}
|
|
@@ -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)
|
| 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 |
Â
|
|
@@ -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/
|
| 55 |
-
const XPATH_CUTOFF_TIME = 'postnl/
|
| 56 |
-
const XPATH_ALLOW_SUNDAY_SORTING = 'postnl/
|
| 57 |
-
const XPATH_SUNDAY_CUTOFF_TIME = 'postnl/
|
| 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/
|
| 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 =
|
|
Â
|
|
| 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 |
-
|
| 426 |
-
|
|
Â
|
|
| 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()) {
|
|
@@ -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 |
-
*
|
| 80 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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 |
Â
*
|
|
@@ -54,7 +54,7 @@ class TIG_PostNL_Model_DeliveryOptions_Product_Attribute_Source_ShippingDuration
|
|
| 54 |
Â
|
| 55 |
Â
$options = array(
|
| 56 |
Â
array(
|
| 57 |
-
'label' => $helper->__('Use
|
| 58 |
Â
'value' => ''
|
| 59 |
Â
),
|
| 60 |
Â
array(
|
| 54 |
Â
|
| 55 |
Â
$options = array(
|
| 56 |
Â
array(
|
| 57 |
+
'label' => $helper->__('Use configuration value'),
|
| 58 |
Â
'value' => ''
|
| 59 |
Â
),
|
| 60 |
Â
array(
|
|
@@ -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/
|
| 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 =
|
| 137 |
-
$deliveryDay =
|
| 138 |
Â
|
| 139 |
-
$shippingDuration =
|
| 140 |
-
|
|
Â
|
|
|
Â
|
|
| 141 |
Â
|
| 142 |
-
$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;
|
|
@@ -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
|
| 45 |
-
const
|
| 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::
|
| 62 |
Â
if ($useHttps) {
|
| 63 |
Â
$scheme = 'https://';
|
| 64 |
Â
}
|
| 65 |
Â
|
| 66 |
-
$feedUrl = $scheme . Mage::getStoreConfig(self::
|
| 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;
|
|
@@ -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
|
| 55 |
-
const
|
| 56 |
Â
|
| 57 |
Â
/**
|
| 58 |
Â
* XML paths for webshop activation settings
|
| 59 |
Â
*/
|
| 60 |
-
const
|
| 61 |
-
const
|
| 62 |
Â
|
| 63 |
Â
/**
|
| 64 |
Â
* XML paths for setting statistics
|
| 65 |
Â
*/
|
| 66 |
-
const
|
| 67 |
-
const
|
| 68 |
-
const
|
| 69 |
-
const
|
| 70 |
-
const
|
| 71 |
-
const
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 72 |
Â
|
| 73 |
Â
/**
|
| 74 |
Â
* XML path to extension activation setting
|
| 75 |
Â
*/
|
| 76 |
-
const
|
| 77 |
Â
|
| 78 |
Â
/**
|
| 79 |
Â
* XML path to 'is_activated' flag
|
| 80 |
Â
*/
|
| 81 |
-
const
|
| 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::
|
| 238 |
Â
if (!$isActivated || $isActivated == '1') {
|
| 239 |
-
Mage::getModel('core/config')->saveConfig(self::
|
| 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::
|
| 295 |
Â
if (!$extensionEnabled) {
|
| 296 |
Â
continue;
|
| 297 |
Â
}
|
| 298 |
Â
|
| 299 |
Â
$websites[] = array(
|
| 300 |
-
'websiteId'
|
| 301 |
-
'hostName'
|
| 302 |
-
'amountOfShipments'
|
| 303 |
-
'
|
| 304 |
-
'
|
| 305 |
-
'
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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::
|
| 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::
|
| 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::
|
| 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(
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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'
|
| 439 |
Â
)
|
| 440 |
Â
);
|
| 441 |
Â
|
| 442 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 443 |
Â
->addFieldToFilter('`main_table`.`store_id`', array('in' => $storeIds));
|
| 444 |
Â
|
| 445 |
-
|
| 446 |
-
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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::
|
| 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 |
Â
}
|
|
@@ -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 |
-
*
|
| 40 |
-
*
|
| 41 |
-
* ensure forwards compatibility.
|
| 42 |
Â
*/
|
| 43 |
-
class TIG_PostNL_Model_Inbox extends
|
| 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 |
Â
}
|
|
@@ -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 |
-
}
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
@@ -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
|
| 48 |
-
const
|
| 49 |
-
const
|
| 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 =
|
| 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 |
-
*
|
| 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::
|
| 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::
|
| 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::
|
| 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 |
Â
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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 |
+
}
|
|
@@ -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
|
