bpost - Version 1.0.0

Version Notes

Added translate Files and Emails

Download this release

Release Info

Developer PHPro
Extension bpost
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (138) hide show
  1. app/code/community/Bpost/ShM/.DS_Store +0 -0
  2. app/code/community/Bpost/ShM/Block/Adminhtml/Sales/AllOrders.php +14 -0
  3. app/code/community/Bpost/ShM/Block/Adminhtml/Sales/AllOrders/Grid.php +58 -0
  4. app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Grid.php +240 -0
  5. app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Grid/Renderer/Dropdate/Dateformat.php +17 -0
  6. app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Grid/Renderer/Label/Download.php +25 -0
  7. app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Order/View/Tab/Returnbarcode.php +137 -0
  8. app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Order/View/Tab/Returnlabels.php +220 -0
  9. app/code/community/Bpost/ShM/Block/Adminhtml/Sales/PendingOrders.php +18 -0
  10. app/code/community/Bpost/ShM/Block/Adminhtml/Sales/PendingOrders/Grid.php +62 -0
  11. app/code/community/Bpost/ShM/Block/Adminhtml/Shipping/Carrier/Bpost/Tablerate/Homedelivery/Grid.php +119 -0
  12. app/code/community/Bpost/ShM/Block/Adminhtml/Shipping/Carrier/Bpost/Tablerate/International/Grid.php +119 -0
  13. app/code/community/Bpost/ShM/Block/Adminhtml/Shipping/Carrier/Bpost/Tablerate/Parcellocker/Grid.php +119 -0
  14. app/code/community/Bpost/ShM/Block/Adminhtml/Shipping/Carrier/Bpost/Tablerate/Pickuppoint/Grid.php +119 -0
  15. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Api/Import/Countries.php +29 -0
  16. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Choose.php +26 -0
  17. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Hour.php +43 -0
  18. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Info.php +22 -0
  19. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Logo.php +39 -0
  20. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Subheader.php +16 -0
  21. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Tablerates/Export/Homedelivery.php +30 -0
  22. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Tablerates/Export/International.php +30 -0
  23. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Tablerates/Export/Parcellocker.php +30 -0
  24. app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Tablerates/Export/Pickuppoint.php +30 -0
  25. app/code/community/Bpost/ShM/Block/Carrier/Bpost.php +124 -0
  26. app/code/community/Bpost/ShM/Controller/.DS_Store +0 -0
  27. app/code/community/Bpost/ShM/Controller/ShM/Order.php +169 -0
  28. app/code/community/Bpost/ShM/Helper/Data.php +838 -0
  29. app/code/community/Bpost/ShM/Helper/Returnlabel.php +46 -0
  30. app/code/community/Bpost/ShM/Helper/System/Config.php +49 -0
  31. app/code/community/Bpost/ShM/Model/.DS_Store +0 -0
  32. app/code/community/Bpost/ShM/Model/Adminhtml/Bpostgrid.php +469 -0
  33. app/code/community/Bpost/ShM/Model/Adminhtml/Observer.php +210 -0
  34. app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Backend/Shipping/Tablerates/Homedelivery.php +11 -0
  35. app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Backend/Shipping/Tablerates/International.php +11 -0
  36. app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Backend/Shipping/Tablerates/Parcellocker.php +11 -0
  37. app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Backend/Shipping/Tablerates/Pickuppoint.php +11 -0
  38. app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Source/Datecomment.php +30 -0
  39. app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Source/Shipping.php +52 -0
  40. app/code/community/Bpost/ShM/Model/Api.php +265 -0
  41. app/code/community/Bpost/ShM/Model/Api/Abstract.php +267 -0
  42. app/code/community/Bpost/ShM/Model/Api/Domcreator.php +697 -0
  43. app/code/community/Bpost/ShM/Model/Country.php +23 -0
  44. app/code/community/Bpost/ShM/Model/Holidays.php +23 -0
  45. app/code/community/Bpost/ShM/Model/Observer.php +360 -0
  46. app/code/community/Bpost/ShM/Model/Resource/Country.php +31 -0
  47. app/code/community/Bpost/ShM/Model/Resource/Country/Collection.php +54 -0
  48. app/code/community/Bpost/ShM/Model/Resource/Holidays.php +23 -0
  49. app/code/community/Bpost/ShM/Model/Resource/Holidays/Collection.php +40 -0
  50. app/code/community/Bpost/ShM/Model/Resource/Returnlabel.php +23 -0
  51. app/code/community/Bpost/ShM/Model/Resource/Returnlabel/Collection.php +23 -0
  52. app/code/community/Bpost/ShM/Model/Resource/Tablerates/Homedelivery.php +421 -0
  53. app/code/community/Bpost/ShM/Model/Resource/Tablerates/Homedelivery/Collection.php +95 -0
  54. app/code/community/Bpost/ShM/Model/Resource/Tablerates/International.php +423 -0
  55. app/code/community/Bpost/ShM/Model/Resource/Tablerates/International/Collection.php +95 -0
  56. app/code/community/Bpost/ShM/Model/Resource/Tablerates/Parcellocker.php +421 -0
  57. app/code/community/Bpost/ShM/Model/Resource/Tablerates/Parcellocker/Collection.php +95 -0
  58. app/code/community/Bpost/ShM/Model/Resource/Tablerates/Pickuppoint.php +421 -0
  59. app/code/community/Bpost/ShM/Model/Resource/Tablerates/Pickuppoint/Collection.php +95 -0
  60. app/code/community/Bpost/ShM/Model/Returnlabel.php +122 -0
  61. app/code/community/Bpost/ShM/Model/Shipping/Carrier/BpostShM.php +332 -0
  62. app/code/community/Bpost/ShM/Model/Shipping/Geocode.php +136 -0
  63. app/code/community/Bpost/ShM/Model/Shipping/Rate/Result.php +11 -0
  64. app/code/community/Bpost/ShM/Model/System/Config/Source/Country.php +27 -0
  65. app/code/community/Bpost/ShM/Model/System/Config/Source/Product.php +44 -0
  66. app/code/community/Bpost/ShM/Model/System/Config/Source/Ratetypes.php +44 -0
  67. app/code/community/Bpost/ShM/Model/System/Config/Source/Weightunit.php +47 -0
  68. app/code/community/Bpost/ShM/Model/Tablerates/Homedelivery.php +9 -0
  69. app/code/community/Bpost/ShM/Model/Tablerates/International.php +9 -0
  70. app/code/community/Bpost/ShM/Model/Tablerates/Parcellocker.php +9 -0
  71. app/code/community/Bpost/ShM/Model/Tablerates/Pickuppoint.php +9 -0
  72. app/code/community/Bpost/ShM/controllers/Adminhtml/Bpost/ShM/AllOrdersController.php +64 -0
  73. app/code/community/Bpost/ShM/controllers/Adminhtml/Bpost/ShM/ConfigController.php +146 -0
  74. app/code/community/Bpost/ShM/controllers/Adminhtml/Bpost/ShM/DownloadController.php +122 -0
  75. app/code/community/Bpost/ShM/controllers/Adminhtml/Bpost/ShM/PendingOrdersController.php +41 -0
  76. app/code/community/Bpost/ShM/controllers/AjaxController.php +147 -0
  77. app/code/community/Bpost/ShM/etc/adminhtml.xml +71 -0
  78. app/code/community/Bpost/ShM/etc/config.xml +397 -0
  79. app/code/community/Bpost/ShM/etc/system.xml +1179 -0
  80. app/code/community/Bpost/ShM/sql/.DS_Store +0 -0
  81. app/code/community/Bpost/ShM/sql/bpost_shm_setup/install-0.0.1.php +30 -0
  82. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.1-0.0.2.php +27 -0
  83. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.10-0.1.0.php +18 -0
  84. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.2-0.0.3.php +27 -0
  85. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.3-0.0.4.php +36 -0
  86. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.4-0.0.5.php +19 -0
  87. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.5-0.0.6.php +23 -0
  88. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.6-0.0.7.php +16 -0
  89. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.7-0.0.8.php +39 -0
  90. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.8-0.0.9.php +18 -0
  91. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.9-0.0.10.php +31 -0
  92. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.0-0.1.1.php +18 -0
  93. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.1-0.1.2.php +18 -0
  94. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.2-0.1.3.php +24 -0
  95. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.3-0.1.4.php +66 -0
  96. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.4-0.1.5.php +19 -0
  97. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.5-0.1.6.php +19 -0
  98. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.6-0.1.7.php +17 -0
  99. app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.7-0.1.8.php +14 -0
  100. app/design/adminhtml/default/default/layout/bpost/shm.xml +71 -0
  101. app/design/adminhtml/default/default/template/bpost/empty.phtml +15 -0
  102. app/design/adminhtml/default/default/template/bpost/informationpopup.phtml +15 -0
  103. app/design/adminhtml/default/default/template/bpost/screenshotpopup.phtml +1 -0
  104. app/design/adminhtml/default/default/template/bpost/widget/grid/massaction.phtml +86 -0
  105. app/design/frontend/base/default/layout/bpost/shm.xml +34 -0
  106. app/design/frontend/base/default/template/bpost/shm/append_bpost_shippingmethod.phtml +93 -0
  107. app/design/frontend/base/default/template/bpost/shm/gmapsapi.phtml +7 -0
  108. app/etc/modules/zBpost_ShM.xml +9 -0
  109. app/locale/en_US/Bpost_ShM.csv +228 -0
  110. app/locale/en_US/template/email/bpost/errorhandling_create_order.html +17 -0
  111. app/locale/en_US/template/email/bpost/returnlabel.html +42 -0
  112. app/locale/nl_NL/Bpost_ShM.csv +244 -0
  113. js/bpost/.DS_Store +0 -0
  114. js/bpost/shm/adminhtml/informationpopup.js +110 -0
  115. js/bpost/shm/checkout.js +956 -0
  116. js/bpost/shm/onestepcheckout_shipping.js +233 -0
  117. package.xml +18 -0
  118. skin/adminhtml/default/default/css/bpost/informationpopup.css +26 -0
  119. skin/adminhtml/default/default/images/bpost/ajax-loader-red.gif +0 -0
  120. skin/adminhtml/default/default/images/bpost/bpost_logo_RGB72_L.png +0 -0
  121. skin/adminhtml/default/default/images/bpost/bpost_logo_RGB72_M.png +0 -0
  122. skin/adminhtml/default/default/images/bpost/btn_close.png +0 -0
  123. skin/adminhtml/default/default/images/bpost/ce-screenshot.png +0 -0
  124. skin/adminhtml/default/default/images/bpost/ee-screenshot.png +0 -0
  125. skin/adminhtml/default/default/images/bpost/pdf_icon.png +0 -0
  126. skin/frontend/base/default/css/bpost/checkout.css +575 -0
  127. skin/frontend/base/default/images/bpost/ajax-loader-button.gif +0 -0
  128. skin/frontend/base/default/images/bpost/ajax-loader-wheel.gif +0 -0
  129. skin/frontend/base/default/images/bpost/bpost_logo_RGB72_L.png +0 -0
  130. skin/frontend/base/default/images/bpost/bpost_logo_RGB72_M.png +0 -0
  131. skin/frontend/base/default/images/bpost/bpost_sym_RGB72_S.png +0 -0
  132. skin/frontend/base/default/images/bpost/btn_close.png +0 -0
  133. skin/frontend/base/default/images/bpost/icon-close.png +0 -0
  134. skin/frontend/base/default/images/bpost/icon-info.png +0 -0
  135. skin/frontend/base/default/images/bpost/location_parcellocker_default.png +0 -0
  136. skin/frontend/base/default/images/bpost/location_postoffice_default.png +0 -0
  137. skin/frontend/base/default/images/bpost/location_postpoint_default.png +0 -0
  138. skin/frontend/base/default/js/bpost/onestepcheckout.js +106 -0
app/code/community/Bpost/ShM/.DS_Store ADDED
Binary file
app/code/community/Bpost/ShM/Block/Adminhtml/Sales/AllOrders.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_Sales_AllOrders extends Mage_Adminhtml_Block_Widget_Grid_Container{
3
+ /**
4
+ *
5
+ */
6
+ public function __construct()
7
+ {
8
+ $this->_blockGroup = 'bpost_shm';
9
+ $this->_controller = 'adminhtml_sales_allOrders';
10
+ $this->_headerText = Mage::helper('bpost_shm')->__('All bposts orders');
11
+ parent::__construct();
12
+ $this->_removeButton('add');
13
+ }
14
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Sales/AllOrders/Grid.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Bpost_ShM_Block_Adminhtml_Sales_AllOrders_Grid extends Bpost_ShM_Block_Adminhtml_Sales_Grid
4
+ {
5
+ /**
6
+ * Constructs the grid and sets basic parameters.
7
+ */
8
+ public function __construct()
9
+ {
10
+ parent::__construct();
11
+ $this->setId('bpost_shm_grid');
12
+ $this->setDefaultSort('created_at');
13
+ $this->setDefaultDir('DESC');
14
+ $this->setSaveParametersInSession(true);
15
+ }
16
+
17
+ /**
18
+ * prepare collection to use for the grid.
19
+ *
20
+ * @return $this
21
+ */
22
+ protected function _prepareCollection()
23
+ {
24
+ $collection = Mage::getResourceModel('sales/order_grid_collection');
25
+ $collection->getSelect()->join(Mage::getConfig()->getTablePrefix() . 'sales_flat_order as sfo', 'sfo.entity_id=`main_table`.entity_id', array(
26
+ 'shipping_method' => 'shipping_method',
27
+ 'total_qty_ordered' => 'ROUND(total_qty_ordered,0)',
28
+ 'bpost_label_exported' => 'bpost_label_exported',
29
+ 'bpost_label_exists' => 'bpost_label_exists',
30
+ 'bpost_drop_date' => 'bpost_drop_date',
31
+ 'bpost_status' => 'bpost_status',
32
+ 'state' => 'state'
33
+ ));
34
+ $collection->addAttributeToFilter('shipping_method', array('like' => '%bpost%'));
35
+ $this->setCollection($collection);
36
+
37
+ parent::_prepareCollection();
38
+
39
+ Mage::dispatchEvent('bpost_shm_prepare_grid_collection_after', array('collection' => $collection));
40
+ return $this;
41
+ }
42
+
43
+
44
+
45
+ /**
46
+ * Generate rowurl.
47
+ *
48
+ * @param $row
49
+ * @return string
50
+ */
51
+ public function getRowUrl($row)
52
+ {
53
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
54
+ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId(), 'bpostReturn' => '1'));
55
+ }
56
+ return false;
57
+ }
58
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Grid.php ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Block_Adminhtml_Sales_Grid
5
+ */
6
+ class Bpost_ShM_Block_Adminhtml_Sales_Grid extends Mage_Adminhtml_Block_Widget_Grid
7
+ {
8
+
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+ $this->setUseAjax(true);
13
+ }
14
+
15
+ /**
16
+ * @return Mage_Adminhtml_Block_Widget_Grid|void
17
+ */
18
+ protected function _prepareCollection(){
19
+ //bugfix collection getSize function
20
+ //trigger getSize before group statement will set the correct collection size
21
+ $this->getCollection()->getSize();
22
+
23
+ if ($this->getCollection()) {
24
+ $this->getCollection()->addExpressionFieldToSelect('shipping_customer_name', "IF(shipping_method='bpostshm_bpost_international', CONCAT('International: ', shipping_name), shipping_name)" ,'shipping_customer_name');
25
+ $this->getCollection()->getSelect()->joinLeft(Mage::getConfig()->getTablePrefix() . 'sales_flat_shipment as sfs', 'sfs.order_id=`main_table`.entity_id', array(
26
+ 'bpost_label_path' => 'bpost_label_path',
27
+ ))->group('main_table.entity_id');
28
+ }
29
+
30
+ parent::_prepareCollection();
31
+ }
32
+
33
+ /**
34
+ * prepare columns used in the grid.
35
+ *
36
+ * @return $this
37
+ */
38
+ protected function _prepareColumns()
39
+ {
40
+ $helper = Mage::helper('bpost_shm');
41
+
42
+ $this->addColumn('real_order_id', array(
43
+ 'header' => $helper->__('Order #'),
44
+ 'width' => '80px',
45
+ 'type' => 'text',
46
+ 'index' => 'increment_id',
47
+ 'filter_index' => 'main_table.increment_id'
48
+ ));
49
+
50
+ if (!Mage::app()->isSingleStoreMode()) {
51
+ $this->addColumn('store_id', array(
52
+ 'header' => $helper->__('Purchased From (Store)'),
53
+ 'index' => 'store_id',
54
+ 'type' => 'store',
55
+ 'store_view' => true,
56
+ 'display_deleted' => true,
57
+ 'filter_index' => 'sfo.store_id'
58
+ ));
59
+ }
60
+ $this->addColumn('created_at', array(
61
+ 'header' => $helper->__('Purchased On'),
62
+ 'index' => 'created_at',
63
+ 'type' => 'datetime',
64
+ 'width' => '100px',
65
+ 'filter_index' => 'main_table.created_at'
66
+ ));
67
+
68
+ $this->addColumn('billing_name', array(
69
+ 'header' => $helper->__('Bill to Name'),
70
+ 'index' => 'billing_name',
71
+ 'filter_index' => 'main_table.billing_name'
72
+ ));
73
+
74
+ $this->addColumn('shipping_name', array(
75
+ 'header' => $helper->__('Ship to Name'),
76
+ 'index' => 'shipping_customer_name',
77
+ 'filter_condition_callback' => array($this, '_shippingNameFilter'),
78
+ ));
79
+
80
+ $this->addColumn('grand_total', array(
81
+ 'header' => $helper->__('G.T. (Purchased)'),
82
+ 'index' => 'grand_total',
83
+ 'type' => 'currency',
84
+ 'currency' => 'order_currency_code',
85
+ 'filter_index' => 'main_table.grand_total'
86
+ ));
87
+
88
+ $this->addColumn('total_qty_ordered', array(
89
+ 'header' => $helper->__('# of Items'),
90
+ 'type' => 'int',
91
+ 'index' => 'total_qty_ordered',
92
+ 'width' => '100px',
93
+ ));
94
+
95
+ $this->addColumn('status', array(
96
+ 'header' => $helper->__('Status'),
97
+ 'index' => 'status',
98
+ 'type' => 'options',
99
+ 'width' => '70px',
100
+ 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
101
+ 'filter_index' => 'main_table.status'
102
+ ));
103
+
104
+ $this->addColumn('bpost_status', array(
105
+ 'header' => $helper->__('bpost status'),
106
+ 'index' => 'bpost_status',
107
+ 'type' => 'text',
108
+ 'width' => '100px'
109
+ ));
110
+
111
+ $this->addColumn('bpost_label_exists', array(
112
+ 'header' => $helper->__('Label download'),
113
+ 'index' => 'bpost_label_exists',
114
+ 'width' => '100px',
115
+ 'renderer' => 'bpost_shm/adminhtml_sales_grid_renderer_label_download',
116
+ 'type' => 'options',
117
+ 'options' => array('1' => 'Yes', '0' => 'No'),
118
+ 'filter_index' => 'sfo.bpost_label_exists'
119
+ ));
120
+
121
+ if (Mage::getStoreConfig('shipping/bpost_shm/display_delivery_date')) {
122
+ $this->addColumn('bpost_drop_date', array(
123
+ 'header' => $helper->__('Drop date'),
124
+ 'index' => 'bpost_drop_date',
125
+ 'type' => 'date',
126
+ 'width' => '100px',
127
+ 'renderer' => 'bpost_shm/adminhtml_sales_grid_renderer_dropdate_dateformat'
128
+ ));
129
+ }
130
+
131
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
132
+ $this->addColumn('action',
133
+ array(
134
+ 'header' => $helper->__('Action'),
135
+ 'width' => '50px',
136
+ 'type' => 'action',
137
+ 'getter' => 'getId',
138
+ 'actions' => array(
139
+ array(
140
+ 'caption' => $helper->__('View'),
141
+ 'url' => array('base' => '*/sales_order/view', 'params' => array('bpostReturn' => '2')),
142
+ 'field' => 'order_id',
143
+ )
144
+ ),
145
+ 'filter' => false,
146
+ 'sortable' => false,
147
+ 'index' => 'stores',
148
+ 'is_system' => true,
149
+ ));
150
+ }
151
+
152
+ return parent::_prepareColumns();
153
+ }
154
+
155
+ /**
156
+ * Gets grid url for callbacks.
157
+ *
158
+ * @return string
159
+ */
160
+ public function getGridUrl()
161
+ {
162
+ return $this->getUrl('*/*/grid', array('_current' => true));
163
+ }
164
+
165
+ /**
166
+ * Prepares Massactions for the grid.
167
+ *
168
+ * @return $this
169
+ */
170
+ protected function _prepareMassaction()
171
+ {
172
+ $this->setMassactionIdField('`main_table`.entity_id');
173
+ $massaActionBlock = $this->getMassactionBlock();
174
+ $massaActionBlock->setFormFieldName('entity_id');
175
+
176
+ $massaActionBlock->addItem('generateAndComplete', array(
177
+ 'label' => Mage::helper('bpost_shm')->__('Generate Label and Complete'),
178
+ 'url' => $this->getUrl('*/*/ajaxGenerateAndComplete'),
179
+ ));
180
+
181
+ $massaActionBlock->addItem('dowloadAllUndownloaded', array(
182
+ 'label' => Mage::helper('bpost_shm')->__('Download all undownloaded'),
183
+ 'url' => $this->getUrl('*/*/dowloadAllUndownloaded'),
184
+ ));
185
+ return $this;
186
+ }
187
+
188
+ /**
189
+ * Prepare grid massaction block
190
+ *
191
+ * @return Mage_Adminhtml_Block_Widget_Grid
192
+ */
193
+ protected function _prepareMassactionBlock()
194
+ {
195
+ $massActionJsObjectName = $this->getHtmlId()."_massactionJsObject";
196
+ $gridJsObjectName = $this->getHtmlId()."JsObject";
197
+ $massActionBlock = $this->getLayout()->createBlock($this->getMassactionBlockName());
198
+
199
+ $buttonHtml = $this->getLayout()
200
+ ->createBlock('adminhtml/widget_button')
201
+ ->setData(array(
202
+ 'label' => Mage::helper('bpost_shm')->__('Submit'),
203
+ 'onclick' => "generateAndComplete('".$massActionJsObjectName."','".$gridJsObjectName."')",
204
+ ))->toHtml();
205
+
206
+ $this->setChild('massaction', $massActionBlock
207
+ ->setSubmitButtonHtml($buttonHtml)
208
+ ->setUseAjax(true)
209
+ ->setTemplate("bpost/widget/grid/massaction.phtml")
210
+ );
211
+
212
+ $this->_prepareMassaction();
213
+
214
+ if($this->getMassactionBlock()->isAvailable()) {
215
+ $this->_prepareMassactionColumn();
216
+ }
217
+
218
+ return $this;
219
+ }
220
+
221
+
222
+ /**
223
+ * @param $collection
224
+ * @param $column
225
+ * @return $this
226
+ */
227
+ protected function _shippingNameFilter($collection, $column)
228
+ {
229
+ if (!$value = $column->getFilter()->getValue()) {
230
+ return $this;
231
+ }
232
+
233
+ $this->getCollection()->getSelect()->where(
234
+ "IF(shipping_method='bpostshm_bpost_international', CONCAT('International: ', shipping_name), shipping_name) like ?"
235
+ , "%$value%"
236
+ );
237
+
238
+ return $this;
239
+ }
240
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Grid/Renderer/Dropdate/Dateformat.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_Sales_Grid_Renderer_Dropdate_Dateformat extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
3
+ {
4
+ public function render(Varien_Object $row)
5
+ {
6
+ $value = $row->getData($this->getColumn()->getIndex());
7
+ $returnValue = $value;
8
+ $now = date('Y-m-d');
9
+ if($value == $now){
10
+ $returnValue = '<strong>'.$value.'</strong>';
11
+ }
12
+ elseif($value < $now){
13
+ $returnValue = '<span style="color:red;">'.$value.'</span>';
14
+ }
15
+ return $returnValue;
16
+ }
17
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Grid/Renderer/Label/Download.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Block_Adminhtml_Sales_Grid_Renderer_Label_Download
5
+ */
6
+ class Bpost_ShM_Block_Adminhtml_Sales_Grid_Renderer_Label_Download extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
7
+ {
8
+ /**
9
+ * @param Varien_Object $row
10
+ * @return string
11
+ * function renders a label download link
12
+ */
13
+ public function render(Varien_Object $row)
14
+ {
15
+ $helper = Mage::helper("adminhtml");
16
+
17
+ if(!$row->getBpostLabelExists() || !$row->getBpostLabelPath() || $row->getBpostLabelPath() == ""){
18
+ return $helper->__("No");
19
+ }
20
+
21
+ $returnValue = '<a href="'.$helper->getUrl("*/bpost_shM_download/label", array("order_id" => $row->getId())).'"><img src="'.Mage::getDesign()->getSkinUrl('images/bpost/pdf_icon.png').'" alt="download label"/></a>';
22
+
23
+ return $returnValue;
24
+ }
25
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Order/View/Tab/Returnbarcode.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @subpackage Shipping
6
+ * @author PHPro (info@phpro.be)
7
+ */
8
+
9
+ /**
10
+ * Class Bpost_ShM_Block_Adminhtml_Sales_Order_View_Tab_Returnbarcode
11
+ */
12
+ class Bpost_ShM_Block_Adminhtml_Sales_Order_View_Tab_Returnbarcode
13
+ extends Mage_Adminhtml_Block_Widget_Grid
14
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface{
15
+
16
+ /**
17
+ * Constructs the block
18
+ *
19
+ */
20
+ public function __construct(){
21
+ parent::__construct();
22
+ $this->setId('bpost_returnbarcode_grid');
23
+ $this->setDefaultDir('DESC');
24
+ $this->setSaveParametersInSession(true);
25
+ $this->setUseAjax(true);
26
+
27
+ $textString = "This order did not (yet) generate labels which automatically returned return label barcodes. This feature might not be actived. Please refer to the documentation and your Shipping Settings under 'System > Configuration > Sales' for more information.";
28
+ $this->_emptyText = Mage::helper('adminhtml')->__($textString);
29
+ }
30
+
31
+ /**
32
+ * prepare collection to use for the grid.
33
+ *
34
+ * @return $this
35
+ */
36
+ protected function _prepareCollection()
37
+ {
38
+ $collection = Mage::getModel('sales/order_shipment')
39
+ ->getCollection()
40
+ ->addFieldToFilter('order_id',array('eq' => $this->getOrder()->getId()))
41
+ ->addFieldToFilter('bpost_return_barcode',array('notnull'=>1));
42
+ $this->setCollection($collection);
43
+ parent::_prepareCollection();
44
+ return $this;
45
+ }
46
+ /**
47
+ * prepare columns used in the grid.
48
+ *
49
+ * @return $this
50
+ */
51
+ protected function _prepareColumns()
52
+ {
53
+ $helper = Mage::helper('bpost_shm');
54
+
55
+ $this->addColumn('increment_id', array(
56
+ 'header' => $helper->__('Shipment'),
57
+ 'type' => 'text',
58
+ 'index' => 'increment_id',
59
+ 'filter_index' => 'main_table.increment_id'
60
+ ));
61
+
62
+ $this->addColumn('returnbarcode', array(
63
+ 'header' => $helper->__('Barcode #'),
64
+ 'type' => 'text',
65
+ 'index' => 'bpost_return_barcode',
66
+ 'filter_index' => 'main_table.bpost_return_barcode'
67
+ ));
68
+
69
+ return parent::_prepareColumns();
70
+ }
71
+
72
+ /**
73
+ * Gets grid url for callbacks.
74
+ *
75
+ * @return string
76
+ */
77
+ public function getGridUrl()
78
+ {
79
+ return $this->getUrl('*/*/grid', array('_current' => true));
80
+ }
81
+
82
+ /**
83
+ * Generate rowurl.
84
+ *
85
+ * @param $row
86
+ * @return string
87
+ */
88
+ public function getRowUrl($row)
89
+ {
90
+ return false;
91
+ }
92
+
93
+ /**
94
+ * Returns tab label.
95
+ *
96
+ * @return string
97
+ */
98
+ public function getTabLabel() {
99
+ return Mage::helper('bpost_shm')->__('bpost Return Barcodes');
100
+ }
101
+
102
+ /**
103
+ * Returns tab title.
104
+ *
105
+ * @return string
106
+ */
107
+ public function getTabTitle() {
108
+ return Mage::helper('bpost_shm')->__('bpost Return Barcodes');
109
+ }
110
+
111
+ /**
112
+ * Checks if tab can be shown.
113
+ *
114
+ * @return bool
115
+ */
116
+ public function canShowTab() {
117
+ return true;
118
+ }
119
+
120
+ /**
121
+ * Checks if the tab has to be hidden.
122
+ *
123
+ * @return bool
124
+ */
125
+ public function isHidden() {
126
+ return false;
127
+ }
128
+
129
+ /**
130
+ * Returns the order object.
131
+ *
132
+ * @return mixed
133
+ */
134
+ public function getOrder(){
135
+ return Mage::registry('current_order');
136
+ }
137
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Sales/Order/View/Tab/Returnlabels.php ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ /**
11
+ * Class Bpost_ShM_Block_Adminhtml_Sales_Order_View_Tab_Returnlabels_Returnlabels
12
+ */
13
+ class Bpost_ShM_Block_Adminhtml_Sales_Order_View_Tab_Returnlabels
14
+ extends Mage_Adminhtml_Block_Widget_Grid
15
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface{
16
+
17
+ /**
18
+ * Constructs the block
19
+ *
20
+ */
21
+ protected function _construct()
22
+ {
23
+ $this->setId('bpost_returnlabel_grid');
24
+ $this->setDefaultDir('DESC');
25
+ $this->setSaveParametersInSession(true);
26
+ $this->setUseAjax(true);
27
+ }
28
+
29
+ /**
30
+ * prepare collection to use for the grid.
31
+ *
32
+ * @return $this
33
+ */
34
+ protected function _prepareCollection()
35
+ {
36
+ $collection = Mage::getModel('bpost_shm/returnlabel')
37
+ ->getCollection()
38
+ ->addFieldToFilter('order_id',array('eq' => $this->getOrder()->getId()));
39
+
40
+ $this->setCollection($collection);
41
+ parent::_prepareCollection();
42
+ return $this;
43
+ }
44
+
45
+ /**
46
+ * prepare columns used in the grid.
47
+ *
48
+ * @return $this
49
+ */
50
+ protected function _prepareColumns()
51
+ {
52
+ $helper = Mage::helper('bpost_shm');
53
+
54
+ $mediaUrl = Mage::getBaseUrl("media");
55
+ if(substr($mediaUrl, -1) == DS){
56
+ $mediaUrl = substr($mediaUrl, 0, -1);
57
+ }
58
+
59
+ $this->addColumn('date_created', array(
60
+ 'header' => $helper->__('Date Created'),
61
+ 'type' => 'text',
62
+ 'index' => 'date_created',
63
+ 'filter_index' => 'main_table.date_created'
64
+ ));
65
+
66
+ $this->addColumn('label_barcode', array(
67
+ 'header' => $helper->__('Label Barcode #'),
68
+ 'type' => 'text',
69
+ 'index' => 'label_barcode',
70
+ 'filter_index' => 'main_table.label_barcode'
71
+ ));
72
+
73
+ $this->addColumn('label_pdf_path', array(
74
+ 'header' => $helper->__('Filepath'),
75
+ 'index' => 'label_pdf_path',
76
+ 'filter_index' => 'main_table.label_pdf_path'
77
+ ));
78
+
79
+ $this->addColumn('Download', array(
80
+ 'header' => $helper->__('Action'),
81
+ 'type' => 'action',
82
+ 'getter' => 'getLabelPdfPath',
83
+ 'actions' => array(
84
+ array(
85
+ 'caption' => Mage::helper('catalog')->__('Download'),
86
+ 'url' => $mediaUrl.Bpost_ShM_Model_Returnlabel::MEDIA_RETURNLABEL_PATH .'$label_pdf_path',
87
+ 'target' => '_blank',
88
+ )
89
+ ),
90
+ 'filter' => false,
91
+ 'sortable' => false,
92
+ 'index' => 'label_pdf_path',
93
+ ));
94
+
95
+ $this->addColumn('Email', array(
96
+ 'header' => $helper->__('Email'),
97
+ 'type' => 'action',
98
+ 'getter' => 'getId',
99
+ 'actions' => array(
100
+ array(
101
+ 'caption' => Mage::helper('catalog')->__('Send Email'),
102
+ 'url' => array(
103
+ 'base'=>'adminhtml/bpost_shM_allOrders/sendEmail',
104
+ ),
105
+ 'field'=> 'return_id'
106
+ )
107
+ ),
108
+ 'filter' => false,
109
+ 'sortable' => false,
110
+ 'index' => '',
111
+ ));
112
+
113
+ return parent::_prepareColumns();
114
+ }
115
+
116
+ public function _afterToHtml($html)
117
+ {
118
+ $suphtml = "";
119
+ $returnSessionValue = Mage::getSingleton('core/session')->getBpostReturn();
120
+ $returnParam = Mage::app()->getRequest()->getParam('bpostReturn');
121
+
122
+ if($returnParam || $returnSessionValue){
123
+
124
+ if(!$returnParam && !$returnSessionValue){
125
+ $returnParam = 1;
126
+ }elseif($returnSessionValue){
127
+ $returnParam = $returnSessionValue;
128
+ }
129
+
130
+ if(!$returnSessionValue){
131
+ Mage::getSingleton('core/session')->setBpostReturn($returnParam);
132
+ }
133
+
134
+ if($returnParam == 1){
135
+ $url = Mage::helper("adminhtml")->getUrl("adminhtml/bpost_shM_allOrders");
136
+ }else{
137
+ $url = Mage::helper("adminhtml")->getUrl("adminhtml/bpost_shM_PendingOrders");
138
+ }
139
+
140
+ $suphtml = '
141
+ <script type="text/javascript">
142
+ document.observe("dom:loaded", function (evt) {
143
+ $$(".form-buttons .back")[0].observe("click", function () {
144
+ setLocation("'.$url.'");
145
+ evt.preventDefault();
146
+ });
147
+ });
148
+ </script>';
149
+ }
150
+
151
+
152
+ return $suphtml .$html;
153
+ }
154
+
155
+ /**
156
+ * Gets grid url for callbacks.
157
+ *
158
+ * @return string
159
+ */
160
+ public function getGridUrl()
161
+ {
162
+ return $this->getUrl('*/*/grid', array('_current' => true));
163
+ }
164
+
165
+ /**
166
+ * Generate rowurl.
167
+ *
168
+ * @param $row
169
+ * @return string
170
+ */
171
+ public function getRowUrl($row)
172
+ {
173
+ return false;
174
+ }
175
+
176
+ /**
177
+ * Returns tab label.
178
+ *
179
+ * @return string
180
+ */
181
+ public function getTabLabel() {
182
+ return Mage::helper('bpost_shm')->__('bpost Return Labels');
183
+ }
184
+
185
+ /**
186
+ * Returns tab title.
187
+ *
188
+ * @return string
189
+ */
190
+ public function getTabTitle() {
191
+ return Mage::helper('bpost_shm')->__('bpost Return Labels');
192
+ }
193
+
194
+ /**
195
+ * Checks if tab can be shown.
196
+ *
197
+ * @return bool
198
+ */
199
+ public function canShowTab() {
200
+ return true;
201
+ }
202
+
203
+ /**
204
+ * Checks if the tab has to be hidden.
205
+ *
206
+ * @return bool
207
+ */
208
+ public function isHidden() {
209
+ return false;
210
+ }
211
+
212
+ /**
213
+ * Returns the order object.
214
+ *
215
+ * @return mixed
216
+ */
217
+ public function getOrder(){
218
+ return Mage::registry('current_order');
219
+ }
220
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Sales/PendingOrders.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Block_Adminhtml_Sales_PendingOrders
5
+ */
6
+ class Bpost_ShM_Block_Adminhtml_Sales_PendingOrders extends Mage_Adminhtml_Block_Widget_Grid_Container{
7
+ /**
8
+ *
9
+ */
10
+ public function __construct()
11
+ {
12
+ $this->_blockGroup = 'bpost_shm';
13
+ $this->_controller = 'adminhtml_sales_pendingOrders';
14
+ $this->_headerText = Mage::helper('bpost_shm')->__('Pending bpost orders');
15
+ parent::__construct();
16
+ $this->_removeButton('add');
17
+ }
18
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Sales/PendingOrders/Grid.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Bpost_ShM_Block_Adminhtml_Sales_PendingOrders_Grid extends Bpost_ShM_Block_Adminhtml_Sales_Grid
4
+ {
5
+ /**
6
+ * Constructs the grid and sets basic parameters.
7
+ */
8
+ public function __construct()
9
+ {
10
+ parent::__construct();
11
+ $this->setId('bpost_shm_grid');
12
+ $this->setDefaultSort('created_at');
13
+ $this->setDefaultDir('DESC');
14
+ $this->setSaveParametersInSession(true);
15
+ }
16
+
17
+ /**
18
+ * prepare collection to use for the grid.
19
+ *
20
+ * @return $this
21
+ */
22
+ protected function _prepareCollection()
23
+ {
24
+ $collection = Mage::getResourceModel('sales/order_grid_collection');
25
+ $collection->getSelect()->join(Mage::getConfig()->getTablePrefix() . 'sales_flat_order as sfo', 'sfo.entity_id=`main_table`.entity_id', array(
26
+ 'shipping_method' => 'shipping_method',
27
+ 'total_qty_ordered' => 'ROUND(total_qty_ordered,0)',
28
+ 'bpost_label_exported' => 'bpost_label_exported',
29
+ 'bpost_label_exists' => 'bpost_label_exists',
30
+ 'bpost_drop_date' => 'bpost_drop_date',
31
+ 'bpost_status' => 'bpost_status',
32
+ 'state' => 'state'
33
+ ));
34
+ $collection->addAttributeToFilter('shipping_method', array('like' => '%bpost%'));
35
+ $collection->addAttributeToFilter('main_table.status', array('nin' => array('complete', 'closed', 'canceled')));
36
+
37
+ $this->setCollection($collection);
38
+ parent::_prepareCollection();
39
+
40
+ if (Mage::getStoreConfig('shipping/bpost_shm/display_delivery_date')) {
41
+ $this->_setCollectionOrder($this->_columns['bpost_drop_date']);
42
+ }
43
+
44
+ Mage::dispatchEvent('bpost_shm_prepare_grid_collection_after', array('collection' => $collection));
45
+ return $this;
46
+ }
47
+
48
+
49
+ /**
50
+ * Generate rowurl.
51
+ *
52
+ * @param $row
53
+ * @return string
54
+ */
55
+ public function getRowUrl($row)
56
+ {
57
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
58
+ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId(), 'bpostReturn' => '2'));
59
+ }
60
+ return false;
61
+ }
62
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Shipping/Carrier/Bpost/Tablerate/Homedelivery/Grid.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_Shipping_Carrier_Bpost_Tablerate_Homedelivery_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
+ {
4
+ /**
5
+ * Website filter
6
+ *
7
+ * @var int
8
+ */
9
+ protected $_websiteId;
10
+
11
+ /**
12
+ * Condition filter
13
+ *
14
+ * @var string
15
+ */
16
+ protected $_conditionName;
17
+
18
+
19
+ /**
20
+ *
21
+ */
22
+ public function __construct()
23
+ {
24
+ parent::__construct();
25
+ $this->setId('shippingHomedeliveryTablerateGrid');
26
+ $this->_exportPageSize = 10000;
27
+ }
28
+
29
+ /**
30
+ * @return Mage_Adminhtml_Block_Widget_Grid
31
+ */
32
+ protected function _prepareCollection()
33
+ {
34
+ $collection = Mage::getResourceModel('bpost_shm/tablerates_homedelivery_collection');
35
+ $collection->setConditionFilter($this->getConditionName())
36
+ ->setWebsiteFilter($this->getWebsiteId());
37
+
38
+ $this->setCollection($collection);
39
+
40
+ return parent::_prepareCollection();
41
+ }
42
+
43
+ /**
44
+ * @return string
45
+ */
46
+ public function getConditionName()
47
+ {
48
+ return $this->_conditionName;
49
+ }
50
+
51
+ /**
52
+ * @param $name
53
+ * @return $this
54
+ */
55
+ public function setConditionName($name)
56
+ {
57
+ $this->_conditionName = $name;
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * @return int|mixed
63
+ */
64
+ public function getWebsiteId()
65
+ {
66
+ if (is_null($this->_websiteId)) {
67
+ $this->_websiteId = Mage::app()->getWebsite()->getId();
68
+ }
69
+ return $this->_websiteId;
70
+ }
71
+
72
+ /**
73
+ * @param $websiteId
74
+ * @return $this
75
+ */
76
+ public function setWebsiteId($websiteId)
77
+ {
78
+ $this->_websiteId = Mage::app()->getWebsite($websiteId)->getId();
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * @return $this
84
+ */
85
+ protected function _prepareColumns()
86
+ {
87
+ $this->addColumn('dest_country', array(
88
+ 'header' => Mage::helper('bpost_shm')->__('Country'),
89
+ 'index' => 'dest_country',
90
+ 'default' => '*',
91
+ ));
92
+
93
+ $this->addColumn('dest_region', array(
94
+ 'header' => Mage::helper('bpost_shm')->__('Region/State'),
95
+ 'index' => 'dest_region',
96
+ 'default' => '*',
97
+ ));
98
+
99
+ $this->addColumn('dest_zip', array(
100
+ 'header' => Mage::helper('bpost_shm')->__('Zip/Postal Code'),
101
+ 'index' => 'dest_zip',
102
+ 'default' => '*',
103
+ ));
104
+
105
+ $label = Mage::getSingleton('shipping/carrier_tablerate')
106
+ ->getCode('condition_name_short', $this->getConditionName());
107
+ $this->addColumn('condition_value', array(
108
+ 'header' => $label,
109
+ 'index' => 'condition_value',
110
+ ));
111
+
112
+ $this->addColumn('price', array(
113
+ 'header' => Mage::helper('bpost_shm')->__('Shipping Price'),
114
+ 'index' => 'price',
115
+ ));
116
+
117
+ return parent::_prepareColumns();
118
+ }
119
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Shipping/Carrier/Bpost/Tablerate/International/Grid.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_Shipping_Carrier_Bpost_Tablerate_International_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
+ {
4
+ /**
5
+ * Website filter
6
+ *
7
+ * @var int
8
+ */
9
+ protected $_websiteId;
10
+
11
+ /**
12
+ * Condition filter
13
+ *
14
+ * @var string
15
+ */
16
+ protected $_conditionName;
17
+
18
+
19
+ /**
20
+ *
21
+ */
22
+ public function __construct()
23
+ {
24
+ parent::__construct();
25
+ $this->setId('shippingInternationalTablerateGrid');
26
+ $this->_exportPageSize = 10000;
27
+ }
28
+
29
+ /**
30
+ * @return Mage_Adminhtml_Block_Widget_Grid
31
+ */
32
+ protected function _prepareCollection()
33
+ {
34
+ $collection = Mage::getResourceModel('bpost_shm/tablerates_international_collection');
35
+ $collection->setConditionFilter($this->getConditionName())
36
+ ->setWebsiteFilter($this->getWebsiteId());
37
+
38
+ $this->setCollection($collection);
39
+
40
+ return parent::_prepareCollection();
41
+ }
42
+
43
+ /**
44
+ * @return string
45
+ */
46
+ public function getConditionName()
47
+ {
48
+ return $this->_conditionName;
49
+ }
50
+
51
+ /**
52
+ * @param $name
53
+ * @return $this
54
+ */
55
+ public function setConditionName($name)
56
+ {
57
+ $this->_conditionName = $name;
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * @return int|mixed
63
+ */
64
+ public function getWebsiteId()
65
+ {
66
+ if (is_null($this->_websiteId)) {
67
+ $this->_websiteId = Mage::app()->getWebsite()->getId();
68
+ }
69
+ return $this->_websiteId;
70
+ }
71
+
72
+ /**
73
+ * @param $websiteId
74
+ * @return $this
75
+ */
76
+ public function setWebsiteId($websiteId)
77
+ {
78
+ $this->_websiteId = Mage::app()->getWebsite($websiteId)->getId();
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * @return $this
84
+ */
85
+ protected function _prepareColumns()
86
+ {
87
+ $this->addColumn('dest_country', array(
88
+ 'header' => Mage::helper('bpost_shm')->__('Country'),
89
+ 'index' => 'dest_country',
90
+ 'default' => '*',
91
+ ));
92
+
93
+ $this->addColumn('dest_region', array(
94
+ 'header' => Mage::helper('bpost_shm')->__('Region/State'),
95
+ 'index' => 'dest_region',
96
+ 'default' => '*',
97
+ ));
98
+
99
+ $this->addColumn('dest_zip', array(
100
+ 'header' => Mage::helper('bpost_shm')->__('Zip/Postal Code'),
101
+ 'index' => 'dest_zip',
102
+ 'default' => '*',
103
+ ));
104
+
105
+ $label = Mage::getSingleton('shipping/carrier_tablerate')
106
+ ->getCode('condition_name_short', $this->getConditionName());
107
+ $this->addColumn('condition_value', array(
108
+ 'header' => $label,
109
+ 'index' => 'condition_value',
110
+ ));
111
+
112
+ $this->addColumn('price', array(
113
+ 'header' => Mage::helper('bpost_shm')->__('Shipping Price'),
114
+ 'index' => 'price',
115
+ ));
116
+
117
+ return parent::_prepareColumns();
118
+ }
119
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Shipping/Carrier/Bpost/Tablerate/Parcellocker/Grid.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_Shipping_Carrier_Bpost_Tablerate_Parcellocker_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
+ {
4
+ /**
5
+ * Website filter
6
+ *
7
+ * @var int
8
+ */
9
+ protected $_websiteId;
10
+
11
+ /**
12
+ * Condition filter
13
+ *
14
+ * @var string
15
+ */
16
+ protected $_conditionName;
17
+
18
+
19
+ /**
20
+ *
21
+ */
22
+ public function __construct()
23
+ {
24
+ parent::__construct();
25
+ $this->setId('shippingParcellockerTablerateGrid');
26
+ $this->_exportPageSize = 10000;
27
+ }
28
+
29
+ /**
30
+ * @return Mage_Adminhtml_Block_Widget_Grid
31
+ */
32
+ protected function _prepareCollection()
33
+ {
34
+ $collection = Mage::getResourceModel('bpost_shm/tablerates_parcellocker_collection');
35
+ $collection->setConditionFilter($this->getConditionName())
36
+ ->setWebsiteFilter($this->getWebsiteId());
37
+
38
+ $this->setCollection($collection);
39
+
40
+ return parent::_prepareCollection();
41
+ }
42
+
43
+ /**
44
+ * @return string
45
+ */
46
+ public function getConditionName()
47
+ {
48
+ return $this->_conditionName;
49
+ }
50
+
51
+ /**
52
+ * @param $name
53
+ * @return $this
54
+ */
55
+ public function setConditionName($name)
56
+ {
57
+ $this->_conditionName = $name;
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * @return int|mixed
63
+ */
64
+ public function getWebsiteId()
65
+ {
66
+ if (is_null($this->_websiteId)) {
67
+ $this->_websiteId = Mage::app()->getWebsite()->getId();
68
+ }
69
+ return $this->_websiteId;
70
+ }
71
+
72
+ /**
73
+ * @param $websiteId
74
+ * @return $this
75
+ */
76
+ public function setWebsiteId($websiteId)
77
+ {
78
+ $this->_websiteId = Mage::app()->getWebsite($websiteId)->getId();
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * @return $this
84
+ */
85
+ protected function _prepareColumns()
86
+ {
87
+ $this->addColumn('dest_country', array(
88
+ 'header' => Mage::helper('bpost_shm')->__('Country'),
89
+ 'index' => 'dest_country',
90
+ 'default' => '*',
91
+ ));
92
+
93
+ $this->addColumn('dest_region', array(
94
+ 'header' => Mage::helper('bpost_shm')->__('Region/State'),
95
+ 'index' => 'dest_region',
96
+ 'default' => '*',
97
+ ));
98
+
99
+ $this->addColumn('dest_zip', array(
100
+ 'header' => Mage::helper('bpost_shm')->__('Zip/Postal Code'),
101
+ 'index' => 'dest_zip',
102
+ 'default' => '*',
103
+ ));
104
+
105
+ $label = Mage::getSingleton('shipping/carrier_tablerate')
106
+ ->getCode('condition_name_short', $this->getConditionName());
107
+ $this->addColumn('condition_value', array(
108
+ 'header' => $label,
109
+ 'index' => 'condition_value',
110
+ ));
111
+
112
+ $this->addColumn('price', array(
113
+ 'header' => Mage::helper('bpost_shm')->__('Shipping Price'),
114
+ 'index' => 'price',
115
+ ));
116
+
117
+ return parent::_prepareColumns();
118
+ }
119
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/Shipping/Carrier/Bpost/Tablerate/Pickuppoint/Grid.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_Shipping_Carrier_Bpost_Tablerate_Pickuppoint_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
+ {
4
+ /**
5
+ * Website filter
6
+ *
7
+ * @var int
8
+ */
9
+ protected $_websiteId;
10
+
11
+ /**
12
+ * Condition filter
13
+ *
14
+ * @var string
15
+ */
16
+ protected $_conditionName;
17
+
18
+
19
+ /**
20
+ *
21
+ */
22
+ public function __construct()
23
+ {
24
+ parent::__construct();
25
+ $this->setId('shippingPickuppointTablerateGrid');
26
+ $this->_exportPageSize = 10000;
27
+ }
28
+
29
+ /**
30
+ * @return Mage_Adminhtml_Block_Widget_Grid
31
+ */
32
+ protected function _prepareCollection()
33
+ {
34
+ $collection = Mage::getResourceModel('bpost_shm/tablerates_pickuppoint_collection');
35
+ $collection->setConditionFilter($this->getConditionName())
36
+ ->setWebsiteFilter($this->getWebsiteId());
37
+
38
+ $this->setCollection($collection);
39
+
40
+ return parent::_prepareCollection();
41
+ }
42
+
43
+ /**
44
+ * @return string
45
+ */
46
+ public function getConditionName()
47
+ {
48
+ return $this->_conditionName;
49
+ }
50
+
51
+ /**
52
+ * @param $name
53
+ * @return $this
54
+ */
55
+ public function setConditionName($name)
56
+ {
57
+ $this->_conditionName = $name;
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * @return int|mixed
63
+ */
64
+ public function getWebsiteId()
65
+ {
66
+ if (is_null($this->_websiteId)) {
67
+ $this->_websiteId = Mage::app()->getWebsite()->getId();
68
+ }
69
+ return $this->_websiteId;
70
+ }
71
+
72
+ /**
73
+ * @param $websiteId
74
+ * @return $this
75
+ */
76
+ public function setWebsiteId($websiteId)
77
+ {
78
+ $this->_websiteId = Mage::app()->getWebsite($websiteId)->getId();
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * @return $this
84
+ */
85
+ protected function _prepareColumns()
86
+ {
87
+ $this->addColumn('dest_country', array(
88
+ 'header' => Mage::helper('bpost_shm')->__('Country'),
89
+ 'index' => 'dest_country',
90
+ 'default' => '*',
91
+ ));
92
+
93
+ $this->addColumn('dest_region', array(
94
+ 'header' => Mage::helper('bpost_shm')->__('Region/State'),
95
+ 'index' => 'dest_region',
96
+ 'default' => '*',
97
+ ));
98
+
99
+ $this->addColumn('dest_zip', array(
100
+ 'header' => Mage::helper('bpost_shm')->__('Zip/Postal Code'),
101
+ 'index' => 'dest_zip',
102
+ 'default' => '*',
103
+ ));
104
+
105
+ $label = Mage::getSingleton('shipping/carrier_tablerate')
106
+ ->getCode('condition_name_short', $this->getConditionName());
107
+ $this->addColumn('condition_value', array(
108
+ 'header' => $label,
109
+ 'index' => 'condition_value',
110
+ ));
111
+
112
+ $this->addColumn('price', array(
113
+ 'header' => Mage::helper('bpost_shm')->__('Shipping Price'),
114
+ 'index' => 'price',
115
+ ));
116
+
117
+ return parent::_prepareColumns();
118
+ }
119
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Api/Import/Countries.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Block_Adminhtml_System_Config_Form_Api_Import_Countries
5
+ */
6
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Api_Import_Countries
7
+ extends Mage_Adminhtml_Block_System_Config_Form_Field implements Varien_Data_Form_Element_Renderer_Interface
8
+ {
9
+ /**
10
+ * @param Varien_Data_Form_Element_Abstract $element
11
+ * @return mixed
12
+ */
13
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ $buttonBlock = Mage::app()->getLayout()->createBlock('adminhtml/widget_button');
16
+ $url = Mage::helper('adminhtml')->getUrl("adminhtml/bpost_shM_config/importCountriesByApi");
17
+
18
+ $data = array(
19
+ 'label' => Mage::helper('adminhtml')->__('Import'),
20
+ 'onclick' => 'setLocation(\'' . $url . '\')',
21
+ 'class' => '',
22
+ 'id' => 'carriers_international_countries_import'
23
+ );
24
+
25
+ $html = $buttonBlock->setData($data)->toHtml();
26
+
27
+ return $html;
28
+ }
29
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Choose.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Choose
5
+ */
6
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Choose extends Mage_Adminhtml_Block_System_Config_Form_Field
7
+ {
8
+
9
+ /**
10
+ * Set choose delivery date value to No when display delivery date is set to no
11
+ *
12
+ * @param Varien_Data_Form_Element_Abstract $element
13
+ * @return parent
14
+ */
15
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
16
+ {
17
+ $configHelper = Mage::helper("bpost_shm/system_config");
18
+ $displayDeliveryDate = (bool)$configHelper->getBpostShippingConfig("display_delivery_date", Mage::app()->getStore()->getId());
19
+
20
+ if(!$displayDeliveryDate) {
21
+ $element->setValue(0);
22
+ }
23
+
24
+ return parent::_getElementHtml($element);
25
+ }
26
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Hour.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Hour
5
+ */
6
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Hour extends Mage_Adminhtml_Block_System_Config_Form_Field
7
+ {
8
+
9
+ /**
10
+ * @param Varien_Data_Form_Element_Abstract $element
11
+ * we use the standard time element but with no seconds
12
+ * @return string
13
+ */
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $value = $element->getEscapedValue().",00";
17
+ $element->setValue($value);
18
+
19
+ $html = $element->getElementHtml();
20
+
21
+ $dom = new DOMDocument();
22
+ $dom->loadHTML($html);
23
+
24
+ $secondsElement = $dom->getElementsByTagName('select')->item(2);
25
+
26
+ if(!$secondsElement){
27
+ //return the original html
28
+ return $html;
29
+ }
30
+
31
+ $secondsElement->parentNode->removeChild($secondsElement);
32
+
33
+ //check if we have
34
+ //remove last : character
35
+ $html = $dom->saveHTML();
36
+
37
+ if( ( $pos = strrpos( $html , ":" ) ) !== false ) {
38
+ $html = substr_replace( $html , "" , $pos , 1 );
39
+ }
40
+
41
+ return $html;
42
+ }
43
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Info.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Info
5
+ */
6
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Info extends Mage_Adminhtml_Block_System_Config_Form_Field
7
+ {
8
+ /**
9
+ * Enter description here...
10
+ *
11
+ * @param Varien_Data_Form_Element_Abstract $element
12
+ * @return string
13
+ */
14
+ public function render(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $telephone = "02/201 11 11";
17
+ $url = "http://bpost.freshdesk.com/solution/articles/174847";
18
+ $html = "<tr><td colspan='4'>".Mage::helper("bpost_shm")->__("You need a user account from bpost to use this module. Call %s for more information.", $telephone)." <a target='_blank' href='$url'>".$url."</a></td></tr>";
19
+
20
+ return $html;
21
+ }
22
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Logo.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Logo
5
+ */
6
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Logo extends Mage_Adminhtml_Block_System_Config_Form_Field
7
+ {
8
+
9
+ /**
10
+ * @param Varien_Data_Form_Element_Abstract $element
11
+ * @return string
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ $bpostLogoMessage = Mage::helper('bpost_shm')->__('Click here for more information');
16
+ $popupUrl = "'" . $this->getUrl('adminhtml/bpost_shM_config/informationpopup') . "'";
17
+ $html = '<a class="bpostInfo" href="#" onclick="openPopup(' . $popupUrl . ',600,400);">';
18
+ $html .= '<span>' . $bpostLogoMessage . '</span> ';
19
+ $html .= '</a>';
20
+ return $html;
21
+ }
22
+
23
+ /**
24
+ * Enter description here...
25
+ *
26
+ * @param Varien_Data_Form_Element_Abstract $element
27
+ * @return string
28
+ */
29
+ public function render(Varien_Data_Form_Element_Abstract $element)
30
+ {
31
+ $html = '';
32
+ $elementHtml = $this->_getElementHtml($element);
33
+ $html .= '<td class="value" colspan="4">';
34
+ $html .= $elementHtml;
35
+ $html .= '</td>';
36
+
37
+ return $html;
38
+ }
39
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Field/Subheader.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Subheader
5
+ */
6
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Field_Subheader extends Mage_Adminhtml_Block_System_Config_Form_Field
7
+ {
8
+
9
+ public function render(Varien_Data_Form_Element_Abstract $element)
10
+ {
11
+ $label = $element->getLabelHtml();
12
+ $html = '<tr><td colspan="4" class="subheader value">'.Mage::helper("bpost_shm")->__($label).'</td></tr>';
13
+
14
+ return $html;
15
+ }
16
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Tablerates/Export/Homedelivery.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Tablerates_Export_Homedelivery
3
+ extends Mage_Adminhtml_Block_System_Config_Form_Field implements Varien_Data_Form_Element_Renderer_Interface
4
+ {
5
+ /**
6
+ * @param Varien_Data_Form_Element_Abstract $element
7
+ * @return mixed
8
+ */
9
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
10
+ {
11
+ $buttonBlock = Mage::app()->getLayout()->createBlock('adminhtml/widget_button');
12
+
13
+ $params = array(
14
+ 'website' => $buttonBlock->getRequest()->getParam('website'),
15
+ 'method' => 'homedelivery',
16
+ 'filename' => 'bpost_homedelivery_tablerates.csv'
17
+ );
18
+
19
+ $data = array(
20
+ 'label' => Mage::helper('adminhtml')->__('Export CSV'),
21
+ 'onclick' => 'setLocation(\'' . Mage::helper('adminhtml')->getUrl("adminhtml/bpost_shM_config/exportTablerates", $params) . 'conditionName/\' + $(\'carriers_bpost_homedelivery_condition_name\').value + \'/bpost_homedelivery_tablerates.csv\' )',
22
+ 'class' => '',
23
+ 'id' => 'carriers_homedelivery_tablerates_export'
24
+ );
25
+
26
+ $html = $buttonBlock->setData($data)->toHtml();
27
+
28
+ return $html;
29
+ }
30
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Tablerates/Export/International.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Tablerates_Export_International
3
+ extends Mage_Adminhtml_Block_System_Config_Form_Field implements Varien_Data_Form_Element_Renderer_Interface
4
+ {
5
+ /**
6
+ * @param Varien_Data_Form_Element_Abstract $element
7
+ * @return mixed
8
+ */
9
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
10
+ {
11
+ $buttonBlock = Mage::app()->getLayout()->createBlock('adminhtml/widget_button');
12
+
13
+ $params = array(
14
+ 'website' => $buttonBlock->getRequest()->getParam('website'),
15
+ 'method' => 'international',
16
+ 'filename' => 'bpost_international_tablerates.csv'
17
+ );
18
+
19
+ $data = array(
20
+ 'label' => Mage::helper('adminhtml')->__('Export CSV'),
21
+ 'onclick' => 'setLocation(\'' . Mage::helper('adminhtml')->getUrl("adminhtml/bpost_shM_config/exportTablerates", $params) . 'conditionName/\' + $(\'carriers_bpost_international_condition_name\').value)',
22
+ 'class' => '',
23
+ 'id' => 'carriers_international_tablerates_export'
24
+ );
25
+
26
+ $html = $buttonBlock->setData($data)->toHtml();
27
+
28
+ return $html;
29
+ }
30
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Tablerates/Export/Parcellocker.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Tablerates_Export_Parcellocker
3
+ extends Mage_Adminhtml_Block_System_Config_Form_Field implements Varien_Data_Form_Element_Renderer_Interface
4
+ {
5
+ /**
6
+ * @param Varien_Data_Form_Element_Abstract $element
7
+ * @return mixed
8
+ */
9
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
10
+ {
11
+ $buttonBlock = Mage::app()->getLayout()->createBlock('adminhtml/widget_button');
12
+
13
+ $params = array(
14
+ 'website' => $buttonBlock->getRequest()->getParam('website'),
15
+ 'method' => 'parcellocker',
16
+ 'filename' => 'bpost_parcellocker_tablerates.csv'
17
+ );
18
+
19
+ $data = array(
20
+ 'label' => Mage::helper('adminhtml')->__('Export CSV'),
21
+ 'onclick' => 'setLocation(\'' . Mage::helper('adminhtml')->getUrl("adminhtml/bpost_shM_config/exportTablerates", $params) . 'conditionName/\' + $(\'carriers_bpost_parcellocker_condition_name\').value)',
22
+ 'class' => '',
23
+ 'id' => 'carriers_parcellocker_tablerates_export'
24
+ );
25
+
26
+ $html = $buttonBlock->setData($data)->toHtml();
27
+
28
+ return $html;
29
+ }
30
+ }
app/code/community/Bpost/ShM/Block/Adminhtml/System/Config/Form/Tablerates/Export/Pickuppoint.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Block_Adminhtml_System_Config_Form_Tablerates_Export_Pickuppoint
3
+ extends Mage_Adminhtml_Block_System_Config_Form_Field implements Varien_Data_Form_Element_Renderer_Interface
4
+ {
5
+ /**
6
+ * @param Varien_Data_Form_Element_Abstract $element
7
+ * @return mixed
8
+ */
9
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
10
+ {
11
+ $buttonBlock = Mage::app()->getLayout()->createBlock('adminhtml/widget_button');
12
+
13
+ $params = array(
14
+ 'website' => $buttonBlock->getRequest()->getParam('website'),
15
+ 'method' => 'pickuppoint',
16
+ 'filename' => 'bpost_pickuppoint_tablerates.csv'
17
+ );
18
+
19
+ $data = array(
20
+ 'label' => Mage::helper('adminhtml')->__('Export CSV'),
21
+ 'onclick' => 'setLocation(\'' . Mage::helper('adminhtml')->getUrl("adminhtml/bpost_shM_config/exportTablerates", $params) . 'conditionName/\' + $(\'carriers_bpost_pickuppoint_condition_name\').value + \'/bpost_pickuppoint_tablerates.csv\' )',
22
+ 'class' => '',
23
+ 'id' => 'carriers_pickuppoint_tablerates_export'
24
+ );
25
+
26
+ $html = $buttonBlock->setData($data)->toHtml();
27
+
28
+ return $html;
29
+ }
30
+ }
app/code/community/Bpost/ShM/Block/Carrier/Bpost.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Block_Carrier_Bpost
13
+ */
14
+ class Bpost_ShM_Block_Carrier_Bpost extends Mage_Core_Block_Template
15
+ {
16
+ /**
17
+ * Returns a settings array used during checkout
18
+ *
19
+ * @return array
20
+ */
21
+ public function getSettings()
22
+ {
23
+ $bpostHelper = Mage::helper('bpost_shm');
24
+ $configHelper = Mage::helper("bpost_shm/system_config");
25
+ $settings = array(
26
+ "monday" => $bpostHelper->__('Monday'),
27
+ "tuesday" => $bpostHelper->__('Tuesday'),
28
+ "wednesday" => $bpostHelper->__('Wednesday'),
29
+ "thursday" => $bpostHelper->__('Thursday'),
30
+ "friday" => $bpostHelper->__('Friday'),
31
+ "saturday" => $bpostHelper->__('Saturday'),
32
+ "sunday" => $bpostHelper->__('Sunday'),
33
+ "closed" => $bpostHelper->__('Closed'),
34
+ "select_text" => $bpostHelper->__('Click here to choose a bpost pick-up point.'),
35
+ "select_text_parcel_locker" => $bpostHelper->__('Click here to choose a bpost parcel locker point.'),
36
+ "change_text" => $bpostHelper->__('Click here to change the bpost pick-up point.'),
37
+ "change_text_parcel_locker" => $bpostHelper->__('Click here to change the bpost parcel locker point.'),
38
+ "label_filter" => $bpostHelper->__("Filter"),
39
+ "label_select" => $bpostHelper->__("Select"),
40
+ "label_postcode" => $bpostHelper->__("Type in a location"),
41
+ "label_loading" => $bpostHelper->__("Please wait. Loading bpost map based on your address"),
42
+ "notifications_text_pickup_point" => $bpostHelper->__("How do you want to be notified when your parcel is available in the pick-up point?"),
43
+ "notifications_text_parcel_locker" => $bpostHelper->__("How do you want to be notified when your parcel is available in the parcel locker?"),
44
+ "notifications_sms_pickup_point" => $bpostHelper->__("via SMS"),
45
+ "notifications_sms_parcel_locker" => $bpostHelper->__("send additional SMS notification"),
46
+ "notifications_email" => $bpostHelper->__("via E-mail"),
47
+ "no_telephone_number" => $bpostHelper->__("no telephone number found, please fill in a number in the shipping address"),
48
+ "no_points_found" => $bpostHelper->__("No points could be found. Please use the filter above or drag the map to get a better result."),
49
+ "imgpath" => DS . "skin" . DS . "frontend" . DS . "base" . DS . "default" . DS . "images" . DS . "bpost" . DS,
50
+ "base_url" => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true),
51
+ "datepicker_display" => (bool)$configHelper->getBpostShippingConfig("display_delivery_date", Mage::app()->getStore()->getId()),
52
+ "datepicker_choose" => (bool)$configHelper->getBpostShippingConfig("choose_delivery_date", Mage::app()->getStore()->getId()),
53
+ "datepicker_text" => $bpostHelper->__("Select your preferred delivery date"),
54
+ "datepicker_delivery_date_text" => $bpostHelper->__("Delivery Date"),
55
+ "datepicker_saturday_delivery_text" => $bpostHelper->__("I don't want my parcel to be delivered on a Saturday"),
56
+ "datepicker_saturday_delivery_cost" => $bpostHelper->__("(extra cost Saturday delivery: %s EUR)"),
57
+ "datepicker_saturday_homedelivery" => (bool)$configHelper->getBpostCarriersConfig("saturday_delivery", "bpost_homedelivery", Mage::app()->getStore()->getId()),
58
+ "datepicker_saturday_pickuppoint" => (bool)$configHelper->getBpostCarriersConfig("saturday_delivery", "bpost_pickuppoint", Mage::app()->getStore()->getId()),
59
+ "datepicker_saturday_parcellocker" => (bool)$configHelper->getBpostCarriersConfig("saturday_delivery", "bpost_parcellocker", Mage::app()->getStore()->getId()),
60
+ "datepicker_days" => $this->getShippingDates(),
61
+ "onestepcheckout_active" => $bpostHelper->getIsOnestepCheckout(),
62
+ "onestepcheckout_shipping_address_error" => $bpostHelper->__("Please select a postcode or city first.")
63
+ );
64
+
65
+ return $settings;
66
+ }
67
+
68
+ /**
69
+ * Returns the quote's shipping address telephone number
70
+ *
71
+ * @return string
72
+ */
73
+ public function getBpostNotificationSms()
74
+ {
75
+ return Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getTelephone();
76
+ }
77
+
78
+ /**
79
+ * Returns the quote's shipping address e-mail address
80
+ *
81
+ * @return string
82
+ */
83
+ public function getBpostNotificationEmail()
84
+ {
85
+ return Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getEmail();
86
+ }
87
+
88
+ /**
89
+ * Returns the current shipping method
90
+ *
91
+ * @return string
92
+ */
93
+ public function getCurrentShippingMethod()
94
+ {
95
+ return Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();
96
+ }
97
+
98
+ /**
99
+ * Returns the delivery date array
100
+ *
101
+ * @return array
102
+ */
103
+ public function getShippingDates()
104
+ {
105
+ return Mage::helper('bpost_shm')->getBpostShippingDates();
106
+ }
107
+
108
+ /*
109
+ * This method retrieves the fixed saturday delivery cost
110
+ *
111
+ * @return string|bool
112
+ */
113
+ public function getSaturdayDeliveryCost()
114
+ {
115
+ $configHelper = Mage::helper("bpost_shm/system_config");
116
+ $saturdayDeliveryCost = $configHelper->getBpostShippingConfig("saturday_delivery_cost", Mage::app()->getStore()->getId());
117
+
118
+ if(!empty($saturdayDeliveryCost) && $saturdayDeliveryCost > 0) {
119
+ return $saturdayDeliveryCost;
120
+ }
121
+
122
+ return false;
123
+ }
124
+ }
app/code/community/Bpost/ShM/Controller/.DS_Store ADDED
Binary file
app/code/community/Bpost/ShM/Controller/ShM/Order.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ class Bpost_ShM_Controller_ShM_Order extends Mage_Adminhtml_Controller_Action
10
+ {
11
+ //we use this class for functions that will be used more than one time
12
+ //all orders and pending orders are extending this one
13
+
14
+ /**
15
+ * Generates a label and completes the shipment.
16
+ * This is called by the action in the order grid dropdown.
17
+ * By ajax call
18
+ */
19
+ public function ajaxGenerateAndCompleteAction(){
20
+ $ajaxResult = array('messages' => '');
21
+
22
+ ini_set('max_execution_time', 120);
23
+ $orderIds = $this->getRequest()->getParam('entity_id');
24
+ $counter = 0;
25
+ $gridModel = Mage::getModel('bpost_shm/adminhtml_bpostgrid');
26
+
27
+ $messages = array("success" => array(), "error" => array(), "notice" => array());
28
+
29
+
30
+ if (!is_array($orderIds)) {
31
+ try {
32
+ $gridModel->generateAndCompleteOrder($orderIds);
33
+
34
+ if(!is_object(Mage::getSingleton('core/session')->getMessages()->getLastAddedMessage())){
35
+ $message = Mage::helper('bpost_shm')->__("Your label has been generated and statuses have been changed.");
36
+ $messages["success"][] = $message;
37
+ $ajaxResult['status'] = 'success';
38
+ }
39
+ } catch (Exception $e) {
40
+ Mage::helper('bpost_shm')->log($e->getMessage(), Zend_Log::ERR);
41
+ $message = Mage::helper('bpost_shm')->__("Your selected order is not ready to be shipped or has already been shipped, operation canceled.");
42
+ $messages["error"][] = $message;
43
+ }
44
+ }else {
45
+
46
+ try {
47
+ foreach ($orderIds as $orderId) {
48
+ try {
49
+ $counter += $gridModel->generateAndCompleteOrder($orderId);
50
+ } catch (Exception $e) {
51
+ Mage::helper('bpost_shm')->log($e->getMessage(), Zend_Log::ERR);
52
+ $messages["error"][] = $e->getMessage();
53
+ }
54
+ }
55
+
56
+ if($counter > 0){
57
+ $message = Mage::helper('bpost_shm')->__("%s label(s) have been generated and statuses have been changed.", $counter);
58
+ $messages["success"][] = $message;
59
+ }
60
+ } catch (Exception $e) {
61
+ Mage::helper('bpost_shm')->log($e->getMessage(), Zend_Log::ERR);
62
+ $message = Mage::helper('bpost_shm')->__("Some of the selected orders are not ready to be shipped or have already been shipped, operation canceled.");
63
+ $messages["error"][] = $message;
64
+ }
65
+ }
66
+
67
+ try {
68
+ //we save our grid transaction
69
+ $gridModel->saveTransaction();
70
+ }catch (Exception $e){
71
+ Mage::helper('bpost_shm')->log($e->getMessage(), Zend_Log::ERR);
72
+ $message = Mage::helper('bpost_shm')->__($e->getMessage());
73
+ $messages["error"][] = $message;
74
+ }
75
+
76
+
77
+ //first check if we have already messages in this request
78
+ //if so, add these to the messages array
79
+ foreach(Mage::getSingleton('core/session')->getMessages()->getItems() as $currentSessionMessage){
80
+ switch($currentSessionMessage->getType()){
81
+ case "notice":
82
+ $messages["notice"][] = $currentSessionMessage->getCode();
83
+ break;
84
+
85
+ case "error":
86
+ $messages["error"][] = $currentSessionMessage->getCode();
87
+ break;
88
+
89
+ case "success":
90
+ $messages["success"][] = $currentSessionMessage->getCode();
91
+ break;
92
+ }
93
+ }
94
+
95
+ $ajaxResult["messages"] = $messages;
96
+
97
+ //remove messages from session
98
+ Mage::getSingleton('core/session')->getMessages(true);
99
+
100
+ $this->getResponse()->setBody ( Zend_Json::encode($ajaxResult) );
101
+ }
102
+
103
+
104
+ /**
105
+ * Zips all undownloaded labels and gives downloadlink.
106
+ */
107
+ public function dowloadAllUndownloadedAction()
108
+ {
109
+ $orderIds = $this->getRequest()->getParam('entity_id');
110
+ try {
111
+ $fileName = Mage::getModel('bpost_shm/adminhtml_bpostgrid')->processUndownloadedLabels($orderIds);
112
+
113
+ if (!$fileName) {
114
+ $message = Mage::helper('bpost_shm')->__('No undownloaded labels found.');
115
+ Mage::getSingleton('core/session')->addError($message);
116
+ $this->_redirect('*/*/index');
117
+ } else {
118
+
119
+ //check for .zip files
120
+ //if zip, do not render
121
+ if(substr($fileName, -4) == ".zip"){
122
+ $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . Bpost_ShM_Model_Adminhtml_Bpostgrid::MEDIA_LABEL_PATH."zips".DS.$fileName;
123
+ }else{
124
+ $url = $this->getUrl("*/*/download", array("file_name" => $fileName));
125
+ }
126
+
127
+ $message = Mage::helper('bpost_shm')->__('Successfully exported order(s). Download the file here: %s',
128
+ ' <a id="downloadzip" href="'
129
+ . $url . '" target="_blank">'
130
+ . $fileName . '</a>');
131
+
132
+ Mage::getSingleton('core/session')->addSuccess($message);
133
+ $this->_redirect('*/*/index');
134
+ }
135
+
136
+ }catch (Exception $e){
137
+ Mage::helper('bpost_shm')->log($e->getMessage(), Zend_Log::ERR);
138
+ $message = Mage::helper('bpost_shm')->__("The file(s) could not be downloaded, please check your bpost logs.");
139
+ Mage::getSingleton('core/session')->addError($message);
140
+ $this->_redirect('*/*/index');
141
+ }
142
+ }
143
+
144
+
145
+ /**
146
+ * Download responseAction for the zip
147
+ */
148
+ public function downloadAction()
149
+ {
150
+ $fileName = $this->getRequest()->getParam('file_name');
151
+
152
+ if(substr($fileName, -4) == ".zip"){
153
+ $fileName = "zips".DS.$fileName;
154
+ }
155
+
156
+ $fileLocation = Mage::getBaseDir('media') . Bpost_ShM_Model_Adminhtml_Bpostgrid::MEDIA_LABEL_PATH. $fileName;
157
+ $ioFile = new Varien_Io_File();
158
+
159
+ if ($ioFile->fileExists($fileLocation)) {
160
+ $file = Zend_Pdf::load($fileLocation);
161
+ $this->_prepareDownloadResponse($fileName, $file->render());
162
+ } else {
163
+ $message = Mage::helper('bpost_shm')->__("The requested file does not exist, it is either removed or not readable.");
164
+ $this->_getSession()->addError($message);
165
+ $this->_redirect('*/*/index');
166
+ }
167
+ }
168
+ }
169
+
app/code/community/Bpost/ShM/Helper/Data.php ADDED
@@ -0,0 +1,838 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Helper_Data
13
+ */
14
+ class Bpost_ShM_Helper_Data extends Mage_Core_Helper_Abstract
15
+ {
16
+ /**
17
+ * Standard shm logging
18
+ *
19
+ * @param $message
20
+ * @param $level
21
+ * @param $storeId
22
+ */
23
+ public function log($message, $level, $storeId = 0)
24
+ {
25
+ $configHelper = Mage::helper("bpost_shm/system_config");
26
+ $allowedLogLevel = $configHelper->getBpostShippingConfig("log_level", $storeId);
27
+
28
+ //first check if logging is enabled
29
+ if ($configHelper->isLoggingEnabled()) {
30
+ if ($level <= $allowedLogLevel) {
31
+ Mage::log($message, $level, 'bpost.log');
32
+ }
33
+ }
34
+ }
35
+
36
+ /**
37
+ * API logging if something goes wrong
38
+ *
39
+ * @param $message
40
+ * @param $level
41
+ * @param $translate
42
+ * @param $storeId
43
+ */
44
+ public function ApiLog($message, $level, $translate = true, $storeId = 0)
45
+ {
46
+ $configHelper = Mage::helper("bpost_shm/system_config");
47
+ $allowedLogLevel = $configHelper->getBpostShippingConfig("api_log_level", $storeId);
48
+
49
+ //first check if API logging is enabled
50
+ if ($configHelper->isApiLoggingEnabled()) {
51
+ if ($level <= $allowedLogLevel) {
52
+ if($translate){
53
+ Mage::log($this->__($message), $level, "bpost-api.log");
54
+ }else{
55
+ Mage::log($message, $level, "bpost-api.log");
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Function checks if we have more address lines
63
+ * If so, we use address 2 as housenumber
64
+ * Else we need to get housenumber from the single address line
65
+ *
66
+ * @param $address
67
+ * @return $address
68
+ */
69
+ public function formatAddress($address)
70
+ {
71
+ $address->setData("bpost_name", $address->getFirstname() . " " . $address->getLastname());
72
+ $address->setData("bpost_company", $address->getCompany());
73
+
74
+ //we assume that street 3 will be box number - not necessary
75
+ if ($address->getStreet3()) {
76
+ $address->setData("box_number", $address->getStreet3());
77
+ }
78
+
79
+ if ($address->getStreet2()) {
80
+ if($address->getData("company") && $address->getData("company") != ""){
81
+ $address->setData("bpost_company", $address->getData("bpost_name") . " (" . $address->getData("company") . ")");
82
+ }else{
83
+ $address->setData("bpost_company", $address->getData("bpost_name"));
84
+ }
85
+
86
+ $address->setData("bpost_name", $address->getStreet2());
87
+ }
88
+
89
+ $address->setData("bpost_house_number", ",");
90
+ $address->setData("bpost_street", $address->getStreet1());
91
+
92
+ return $address;
93
+ }
94
+
95
+ /**
96
+ * Validate the postal code
97
+ *
98
+ * @param $country_id
99
+ * @param $postcode
100
+ * @return regex|string
101
+ */
102
+ public function validatePostcode($country_id, $postcode)
103
+ {
104
+ $zipValidationRules = array(
105
+ 'LT' => array('99999', '/^(\d{5})$/'),
106
+ 'LU' => array('9999', '/^(\d{4})$/'),
107
+ 'BE' => array('9999', '/^(\d{4})$/'),
108
+ 'LV' => array('9999', '/^(\d{4})$/'),
109
+ 'MT' => array('AAA 9999', '/[A-Z]{3} [0-9]{4}/'),
110
+ 'NL' => array('9999 AA', '/[0-9]{4} [A-Z]{2}/'),
111
+ 'PL' => array('99999', '/^(\d{5})$/'),
112
+ 'PT' => array('9999999', '/^([0-9]){7}$/'),
113
+ 'RO' => array('999999', '/^(\d{6})$/'),
114
+ 'SE' => array('999 99', '/^(\d{3} \d{2})$/'),
115
+ 'SI' => array('9999', '/^(\d{4})$/'),
116
+ 'SK' => array('999 99', '/^(\d{3} \d{2})$/'),
117
+ 'AT' => array('9999', '/^(\d{4})$/'),
118
+ 'BG' => array('9999', '/^(\d{4})$/'),
119
+ 'CZ' => array('999 99', '/^[0-9]{3} [0-9]{2}$/'),
120
+ 'DE' => array('99999', '/^(\d{5})$/'),
121
+ 'DK' => array('9999', '/^(\d{4})$/'),
122
+ 'EE' => array('99999', '/^(\d{5})$/'),
123
+ 'ES' => array('99999', '/^(\d{5})$/'),
124
+ 'FI' => array('99999', '/^(\d{5})$/'),
125
+ 'FR' => array('99999', '/^(\d{5})$/'),
126
+ 'GR' => array('999 99', '/^(\d{3}) \d{2}$/'),
127
+ 'HR' => array('99999', '/^(\d{5})$/'),
128
+ 'HU' => array('9999', '/^(\d{4})$/'),
129
+ 'IT' => array('99999', '/^(\d{5})$/')
130
+ );
131
+ if (array_key_exists($country_id, $zipValidationRules)) {
132
+ $validationRegex = $zipValidationRules[$country_id][1];
133
+ $validationFormat = $zipValidationRules[$country_id][0];
134
+
135
+ if (!preg_match($validationRegex, $postcode)) {
136
+ return $validationFormat;
137
+ }
138
+ }
139
+ return 'passed';
140
+ }
141
+
142
+ /**
143
+ * Creates new IO object and inputs base 64 pdf string fetched from webservice.
144
+ *
145
+ * @param $pdfString
146
+ * @param $folder
147
+ * @param $name
148
+ *
149
+ * @return string
150
+ */
151
+ public function generatePdfAndSave($pdfString, $folder, $name)
152
+ {
153
+ $hash = bin2hex(mcrypt_create_iv(5, MCRYPT_DEV_URANDOM));
154
+ $name = $name . "-" . $hash;
155
+
156
+ $io = new Varien_Io_File();
157
+ $io->setAllowCreateFolders(true);
158
+ $io->open(array('path' => Mage::getBaseDir('media') . "/bpost/" . $folder));
159
+ $io->streamOpen($name . '.pdf', 'w+');
160
+ $io->streamLock(true);
161
+ $io->streamWrite($pdfString);
162
+ $io->streamUnlock();
163
+ $io->streamClose();
164
+ return $name;
165
+ }
166
+
167
+ /**
168
+ * Function returns the locale code by order
169
+ *
170
+ * @param $order
171
+ * @param $useExceptionLanguages
172
+ * @return string
173
+ */
174
+ public function getLocaleByOrder($order, $useExceptionLanguages = false)
175
+ {
176
+ $exceptionLanguages = array("DE");
177
+
178
+ $store = $order->getStore()->getId();
179
+ $locale = Mage::getStoreConfig("general/locale/code", $store);
180
+ $locale = strtoupper(substr($locale, 0, 2));
181
+
182
+ switch ($locale) {
183
+ case "NL":
184
+ case "FR":
185
+ case "EN":
186
+ return $locale;
187
+ break;
188
+
189
+ default:
190
+ if ($useExceptionLanguages && in_array($locale, $exceptionLanguages)) {
191
+ return $locale;
192
+ }
193
+
194
+ return "EN";
195
+ break;
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Function parses the create label API response in a readable format
201
+ *
202
+ * @param $response
203
+ * @return array
204
+ */
205
+ public function parseLabelApiResponse($response, $order){
206
+ $xml = simplexml_load_string($response->getBody());
207
+ $shippingMethod = $order->getShippingMethod();
208
+ $returnArray = array();
209
+ $returnArray["barcodeString"] = array();
210
+
211
+ //international delivery can have more label elements (instead of one with multiple barcodes), so we have to loop
212
+ foreach($xml->label as $label){
213
+ $responseBarcodeArray = (array)$label->barcode;
214
+
215
+ //we check for barcodes
216
+ //for national delivery
217
+ //barcodes ending on 030 -> regular barcode
218
+ //barcodes ending on 050 -> return barcode
219
+
220
+ //for international delivery
221
+ //barcodes starting with CD -> regular barcode, no return
222
+
223
+ //international delivery has other barcodes
224
+ //check on barcode count label
225
+ //if more than 1 -> national, otherwise international
226
+
227
+ foreach($responseBarcodeArray as $responseBarcode){
228
+ $responseBarcode = (string)$responseBarcode;
229
+
230
+ $firstTwoCharacters = substr($responseBarcode, 0, 2);
231
+ $lastThreeCharacters = substr($responseBarcode, -3);
232
+
233
+ switch($shippingMethod){
234
+ case "bpostshm_bpost_international":
235
+ if(in_array($firstTwoCharacters, array("CD","EE","CE")) && $lastThreeCharacters != '134'){
236
+ $returnArray["barcodeString"][] = $responseBarcode;
237
+ }else{
238
+ if(!isset($returnArray["returnBarcodeString"])){
239
+ $returnArray["returnBarcodeString"] = array();
240
+ }
241
+ $returnArray["returnBarcodeString"][] = $responseBarcode;
242
+ }
243
+ break;
244
+
245
+ default:
246
+ if($lastThreeCharacters == "050"){
247
+ if(!isset($returnArray["returnBarcodeString"])){
248
+ $returnArray["returnBarcodeString"] = array();
249
+ }
250
+ $returnArray["returnBarcodeString"][] = $responseBarcode;
251
+ }else{
252
+ $returnArray["barcodeString"][] = $responseBarcode;
253
+ }
254
+ break;
255
+ }
256
+ }
257
+
258
+ $pdfString = $label->bytes;
259
+
260
+ //we use the Zend_XmlRpc_Value_Base64 for decoding our string
261
+ $zendXmlRpc = new Zend_XmlRpc_Value_Base64($pdfString, true);
262
+ $pdfString = $zendXmlRpc->getValue();
263
+
264
+ if(!isset($returnArray["pdfString"])){
265
+ $returnArray["pdfString"] = array();
266
+ $returnArray["pdfString"][] = $pdfString;
267
+ }else{
268
+ $returnArray["pdfString"][] = $pdfString;
269
+ }
270
+ }
271
+
272
+ //make sure the index barcode string isset
273
+ if(empty($returnArray["barcodeString"])){
274
+ $returnArray["barcodeString"][] = $order->getBpostReference();
275
+ }
276
+
277
+ return $returnArray;
278
+ }
279
+
280
+ /**
281
+ * API function returns the bpost status
282
+ *
283
+ * @param $order
284
+ * @return boolean|string
285
+ */
286
+ public function getBpostStatus($order){
287
+ $apiModel = Mage::getModel("bpost_shm/api", true);
288
+ $apiResponse = $apiModel->retrieveOrderDetails($order);
289
+
290
+ if(!$apiResponse){
291
+ return false;
292
+ }
293
+
294
+ $xml = simplexml_load_string($apiResponse->getBody());
295
+ $statuses = array();
296
+
297
+ foreach($xml->box as $box){
298
+ if($box->barcode){
299
+ $statuses[(string)$box->barcode] = (string)$box->status;
300
+ }
301
+ }
302
+
303
+ if(empty($statuses)){
304
+ return false;
305
+ }
306
+
307
+ return $statuses;
308
+ }
309
+
310
+ /**
311
+ * Gets all spots from bpost webservice based on shipping address or coordinates
312
+ *
313
+ * @param $params
314
+ * @return mixed
315
+ */
316
+ public function getBpostSpots($params = array())
317
+ {
318
+ $request = Mage::app()->getRequest();
319
+ $bpostHelper = Mage::helper("bpost_shm");
320
+ $bpostGmapsFilter = $request->getPost("bpost-gmaps-filter");
321
+ $latitude = $request->getPost("lat");
322
+ $longitude = $request->getPost("lng");
323
+ $apiModel = Mage::getModel('bpost_shm/api', true);
324
+ $latLng = false;
325
+ $pointType = 3;
326
+
327
+ if(isset($params["pointType"])){
328
+ $pointType = $params["pointType"];
329
+ }
330
+
331
+ if(strlen($bpostGmapsFilter) > 0 || ($latitude && $longitude)) {
332
+ // Use google geocoding to get spots
333
+ if($bpostGmapsFilter) {
334
+ // Call map with filtered result
335
+ $geoCode = Mage::getModel("bpost_shm/shipping_geocode")->callGoogleMaps($bpostGmapsFilter);
336
+ } else {
337
+ // Call map with coordinates
338
+ $geoCode = Mage::getModel("bpost_shm/shipping_geocode")->callGoogleMaps(false, $latitude, $longitude);
339
+ }
340
+
341
+ if ($geoCode) {
342
+ $address = array();
343
+ $address['street'] = '';
344
+ $address['number'] = '';
345
+ $address['zone'] = $geoCode->getPostalCode();
346
+
347
+ $latLng = $geoCode->getLatLng();
348
+ }
349
+ } else {
350
+
351
+ if($bpostHelper->getIsOnestepCheckout()){
352
+ if(isset($params["address_id"]) && $params["address_id"] != null){
353
+ //load customer address and use
354
+ $shippingAddress = Mage::getModel("customer/address")->load($params["address_id"]);
355
+ }else{
356
+ $shippingAddress = Mage::getModel("customer/address");
357
+
358
+ if(isset($params["city"]) && $params["city"] != ""){
359
+ $shippingAddress->setCity($params["city"]);
360
+ }
361
+
362
+ if(isset($params["postcode"]) && $params["postcode"] != ""){
363
+ $shippingAddress->setPostcode($params["postcode"]);
364
+ }
365
+
366
+ if(isset($params["street"]) && $params["street"] != ""){
367
+ $shippingAddress->setStreet($params["street"]);
368
+ }
369
+ }
370
+ }else{
371
+ // Get shipping address from quote object
372
+ $shippingAddress = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
373
+ }
374
+
375
+ $searchString = $shippingAddress->getStreet(1).', '.$shippingAddress->getPostcode().', '.$shippingAddress->getCountry();
376
+ $geoCode = Mage::getModel("bpost_shm/shipping_geocode")->callGoogleMaps($searchString);
377
+ $latLng = $geoCode->getLatLng();
378
+
379
+ $address = $this->formatShippingAddress($shippingAddress);
380
+ }
381
+
382
+ try{
383
+ $spots['poiList'] = $apiModel->getNearestServicePoints($address, $pointType);
384
+ $spots['coordinates'] = $latLng;
385
+ }catch (Exception $e){
386
+ $bpostHelper->log("Webservice: not expected result returned:" . $e->getMessage(), Zend_Log::WARN);
387
+ $spots = false;
388
+ $spots['poiList'] = false;
389
+ $spots['coordinates'] = $latLng;
390
+ }
391
+
392
+ return $spots;
393
+ }
394
+
395
+ /**
396
+ * Gets opening hours of a specific bpost spot
397
+ *
398
+ * @param $id
399
+ * @param $type
400
+ * @return mixed
401
+ */
402
+ public function getBpostOpeningHours($id, $type) {
403
+ $cache = Mage::app()->getCache();
404
+ $key = 'bpost-shm-opening-hours-spotid-' . $id . '-type-' . $type;
405
+
406
+ if(!$data = $cache->load($key)) {
407
+ $apiCall = Mage::getModel('bpost_shm/api', true)->getServicePointDetails($id, $type);
408
+
409
+ $data = serialize($apiCall);
410
+ //set cache lifetime to null (infinite) as it should only be cleared by changing the rule
411
+ $cache->save(urlencode($data), $key, array("bpost_shm"), 86400);
412
+ } else {
413
+ $apiCall = unserialize(urldecode($data));
414
+ }
415
+
416
+ return $apiCall;
417
+ }
418
+
419
+ /**
420
+ * Formats the shipping address into a formatted array
421
+ *
422
+ * @param $address
423
+ * @return array
424
+ */
425
+ public function formatShippingAddress($address){
426
+ $formattedAddress = array();
427
+ $number = explode(",", $address->getStreet(1));
428
+
429
+ if (is_numeric($number[0])) {
430
+ $replace = array($number[0], ",");
431
+ if ($address->getStreet(1) != "") {
432
+ $street = str_replace($replace, array('', ''), $address->getStreet(1));
433
+ }
434
+ $formattedAddress['street'] = trim($street);
435
+ $formattedAddress['number'] = trim($number[0]);
436
+ } else {
437
+ if ($address->getStreet(1) != "") {
438
+ $number = explode(" ", $address->getStreet(1));
439
+ $street = str_replace(end($number), "", $address->getStreet(1));
440
+ }
441
+
442
+ if (preg_match('~[0-9]~', end($number))) {
443
+ $formattedAddress['street'] = $street;
444
+ $formattedAddress['number'] = end($number);
445
+ } else {
446
+ if ($address->getStreet(1) != "") {
447
+ $formattedAddress['street'] = $address->getStreet(1);
448
+ }
449
+ }
450
+ }
451
+
452
+ if ($address->getStreet(2) != "") {
453
+ $formattedAddress['street'] = $address->getStreet(1);
454
+ $formattedAddress['number'] = ",";
455
+ }
456
+
457
+ $formattedAddress['street'] = trim($formattedAddress['street']);
458
+ $formattedAddress['zone'] = $address->getPostcode() ?: $address->getCity();
459
+ $formattedAddress['postcode'] = $address->getPostcode();
460
+ $formattedAddress['city'] = $address->getCity();
461
+
462
+ return $formattedAddress;
463
+ }
464
+
465
+ /**
466
+ * @return string
467
+ */
468
+ public function getMagentoWindowCssItemType(){
469
+ if (Mage::getVersion() < '1.7' || Mage::getVersion() < '1.9' && Mage::getEdition() == 'Community' || Mage::getVersion() < '1.14' && Mage::getEdition() == 'Enterprise') {
470
+ return 'js_css';
471
+ } else {
472
+ return 'skin_css';
473
+ }
474
+ }
475
+
476
+ /**
477
+ * @return string
478
+ */
479
+ public function getMageWindowCss()
480
+ {
481
+ if (Mage::getVersion() < '1.7' || Mage::getVersion() < '1.9' && Mage::getEdition() == 'Community' || Mage::getVersion() < '1.14' && Mage::getEdition() == 'Enterprise') {
482
+ return 'prototype/windows/themes/magento.css';
483
+ } else {
484
+ return 'lib/prototype/windows/themes/magento.css';
485
+ }
486
+ }
487
+
488
+ /**
489
+ * Function gives filename by path, alternative for basename (GrumPHP)
490
+ *
491
+ * @param $path
492
+ * @return array
493
+ */
494
+ public function getFileNameByPath($path){
495
+ $fileName = explode("/", $path);
496
+ $fileName = $fileName[(count($fileName)-1)];
497
+
498
+ return $fileName;
499
+ }
500
+
501
+ /**
502
+ * Returns all valid delivery dates
503
+ *
504
+ * @param $closedOn
505
+ * @return array
506
+ */
507
+ public function getBpostShippingDates($closedOn = false)
508
+ {
509
+ //quote object
510
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
511
+ $grandTotal = $quote->getGrandTotal();
512
+
513
+ //bpost helper
514
+ $helper = Mage::helper('bpost_shm');
515
+
516
+ //get config values
517
+ $configHelper = Mage::helper("bpost_shm/system_config");
518
+ $displayDeliveryDate = (bool)$configHelper->getBpostShippingConfig("display_delivery_date", Mage::app()->getStore()->getId());
519
+ $chooseDeliveryDate = (bool)$configHelper->getBpostShippingConfig("choose_delivery_date", Mage::app()->getStore()->getId());
520
+ $daysBetweenOrderAndShipment = $configHelper->getBpostShippingConfig("days_between_order_and_shipment", Mage::app()->getStore()->getId());
521
+ $nrOfDeliveryDaysShown = $configHelper->getBpostShippingConfig("nr_of_delivery_days_shown", Mage::app()->getStore()->getId());
522
+ $nextDayDeliveryAllowedTill = $configHelper->getBpostShippingConfig("next_day_delivery_allowed_till", Mage::app()->getStore()->getId());
523
+
524
+ //get the Magento date model
525
+ $dateModel = Mage::getSingleton('core/date');
526
+
527
+ //days to add counter, will always be 1 since delivery is never on the same day
528
+ $daysToStart = 1;
529
+
530
+ //add a day if the current time surpasses the time treshold
531
+ $time = $dateModel->date('H,i');
532
+
533
+ if($nextDayDeliveryAllowedTill <= $time && substr($nextDayDeliveryAllowedTill, 0, 5) != '00,00') {
534
+ $daysToStart = 2;
535
+ }
536
+
537
+ //get the current date
538
+ $currentDate = $dateModel->date();
539
+
540
+ //define all bpost shipping methods
541
+ $shippingMethods = array(
542
+ 'bpost_homedelivery' => false,
543
+ 'bpost_pickuppoint' => false,
544
+ 'bpost_parcellocker' => false
545
+ );
546
+
547
+ foreach ($shippingMethods as $method => $value) {
548
+ //get saturday delivery flags
549
+ $saturdayDelivery = (bool)$configHelper->getBpostCarriersConfig("saturday_delivery", $method, Mage::app()->getStore()->getId());
550
+ $saturdayDeliveryFrom = $this->formatSaturdayDeliveryCost($configHelper->getBpostCarriersConfig("saturday_delivery_from", $method, Mage::app()->getStore()->getId()));
551
+
552
+ //don't allow saturday delivery if saturday delivery 'yes' and 'as from' amount not exceeded
553
+ if($grandTotal < $saturdayDeliveryFrom) {
554
+ $saturdayDelivery = false;
555
+ }
556
+
557
+ $extraDays = $daysToStart;
558
+ //add total days between order and shipment
559
+ $totalDays = $extraDays + $daysBetweenOrderAndShipment;
560
+
561
+ //loop over days checking for the first valid day
562
+ for($i = 1; $i <= $totalDays; $i++) {
563
+ $nextDate = $dateModel->date("Y-m-d", strtotime($currentDate.' +'.$i.' days'));
564
+
565
+ if(!$this->_isValidDeliveryDate($nextDate, $saturdayDelivery, $method, $closedOn)) {
566
+ $totalDays++;
567
+ }
568
+ }
569
+
570
+ $startDate = $dateModel->date("Y-m-d", strtotime($currentDate.' +'.$totalDays.' days'));
571
+
572
+ //customer gets a date from the system
573
+ if($displayDeliveryDate && !$chooseDeliveryDate) {
574
+ $shippingMethods[$method] = array(
575
+ 'date' => $this->_formatDeliveryDate($startDate),
576
+ 'date_format' => $helper->__($this->_formatDeliveryDate($startDate, 'l'))." ".$this->_formatDeliveryDate($startDate, 'd/m'),
577
+ 'is_saturday' => $this->_isSaturday($startDate),
578
+ 'next_date' => $this->_getNextDeliveryDate($startDate),
579
+ 'next_date_format' => $helper->__($this->_getNextDeliveryDate($startDate, 'l'))." ".$this->_getNextDeliveryDate($startDate, 'd/m')
580
+ );
581
+ //customer can choose own date
582
+ } else if($displayDeliveryDate && $chooseDeliveryDate) {
583
+ $days = array();
584
+ $addedDays = 0;
585
+
586
+ for($i = 0; $i < $nrOfDeliveryDaysShown; $i++) {
587
+ //add starting date to array
588
+ if($i == 0) {
589
+ $days[$i] = array(
590
+ 'date' => $startDate,
591
+ 'date_format' => $helper->__($this->_formatDeliveryDate($startDate, 'l')).'<span>'.$this->_formatDeliveryDate($startDate, 'j')." ".strtolower($helper->__($this->_formatDeliveryDate($startDate, 'F'))).'</span>'
592
+ );
593
+ //move to next day
594
+ } else {
595
+ $addedDays++;
596
+ $nextDate = $dateModel->date("Y-m-d", strtotime($startDate.' +'.$addedDays.' days'));
597
+
598
+ $validDate = false;
599
+ while($validDate == false) {
600
+ if($this->_isValidDeliveryDate($nextDate, $saturdayDelivery, $method, $closedOn)) {
601
+ $validDate = true;
602
+ } else {
603
+ $addedDays++;
604
+ $nextDate = $dateModel->date("Y-m-d", strtotime($startDate.' +'.$addedDays.' days'));
605
+ }
606
+ }
607
+
608
+ $days[$i] = array(
609
+ 'date' => $nextDate,
610
+ 'date_format' => $helper->__($this->_formatDeliveryDate($nextDate, 'l')).'<span>'.$this->_formatDeliveryDate($nextDate, 'j')." ".strtolower($helper->__($this->_formatDeliveryDate($nextDate, 'F'))).'</span>'
611
+ );
612
+ }
613
+ }
614
+
615
+ $shippingMethods[$method] = $days;
616
+ }
617
+ }
618
+
619
+ return $shippingMethods;
620
+ }
621
+
622
+
623
+ /**
624
+ * @return date
625
+ */
626
+ public function getPrevDeliveryDate($deliveryDate){
627
+ $dateModel = Mage::getModel("core/date");
628
+ $days = 1;
629
+ $validDate = false;
630
+ $previousWeekday = $dateModel->date('Y-m-d', strtotime($deliveryDate.' -'.$days.' weekdays'));
631
+
632
+ while($validDate == false) {
633
+ if($this->_isValidDeliveryDate($previousWeekday)) {
634
+ $validDate = true;
635
+ } else {
636
+ $days++;
637
+ $previousWeekday = $dateModel->date('Y-m-d', strtotime($deliveryDate.' -'.$days.' weekdays'));
638
+ }
639
+ }
640
+
641
+ return $previousWeekday;
642
+ }
643
+
644
+
645
+ /**
646
+ * Returns the next first valid delivery date
647
+ *
648
+ * @param $date
649
+ * @param $format
650
+ * @return array
651
+ */
652
+ protected function _getNextDeliveryDate($date, $format = "Y-m-d") {
653
+ $dateModel = Mage::getSingleton('core/date');
654
+ $nextDate = false;
655
+
656
+ if($this->_isSaturday($date)) {
657
+ //add a weekday so we end up on monday
658
+ $extraWeekDays = 1;
659
+ $nextDate = $dateModel->date("Y-m-d", strtotime("$date +$extraWeekDays weekdays"));
660
+
661
+ //check for holidays (monday will most likely not be a saturday or a sunday, and holidays sadly don't take a week)
662
+ $validDeliveryDate = false;
663
+ while($validDeliveryDate == false) {
664
+ if($this->_isValidDeliveryDate($nextDate)) {
665
+ $validDeliveryDate = true;
666
+ } else {
667
+ $extraWeekDays++;
668
+ $nextDate = $dateModel->date("Y-m-d", strtotime("$date +$extraWeekDays weekdays"));
669
+ }
670
+ }
671
+
672
+ $nextDate = $this->_formatDeliveryDate($nextDate, $format);
673
+ }
674
+
675
+ return $nextDate;
676
+ }
677
+
678
+
679
+ protected function _isValidDeliveryDate($deliveryDate, $saturdayAllowed = false, $method = false, $closedOn = false) {
680
+ if($this->_isHoliday($deliveryDate)) {
681
+ return false;
682
+ }
683
+ if($this->_isSunday($deliveryDate)) {
684
+ return false;
685
+ }
686
+ if(!$saturdayAllowed && $this->_isSaturday($deliveryDate)) {
687
+ return false;
688
+ }
689
+ if($method == 'bpost_pickuppoint') {
690
+ //check if pick-up point is open on this day
691
+ if(is_array($closedOn)) {
692
+ $day = $this->_formatDeliveryDate($deliveryDate, 'l');
693
+
694
+ if(in_array($day, $closedOn)) {
695
+ return false;
696
+ }
697
+ }
698
+ }
699
+ return true;
700
+ }
701
+
702
+
703
+ /**
704
+ * Check if date is on a saturday
705
+ *
706
+ * @param $date
707
+ * @return bool
708
+ */
709
+ protected function _isSaturday($date)
710
+ {
711
+ $dateModel = Mage::getSingleton('core/date');
712
+
713
+ return ($dateModel->date('N', strtotime($date)) == 6);
714
+ }
715
+
716
+ /**
717
+ * Check if date is on a sunday
718
+ *
719
+ * @param $date
720
+ * @return bool
721
+ */
722
+ protected function _isSunday($date)
723
+ {
724
+ $dateModel = Mage::getSingleton('core/date');
725
+
726
+ return ($dateModel->date('N', strtotime($date)) == 7);
727
+ }
728
+
729
+ /**
730
+ * Check if date is a holiday (according to Belgian holidays)
731
+ *
732
+ * @param $date
733
+ * @return bool
734
+ */
735
+ protected function _isHoliday($date)
736
+ {
737
+ $holidays = Mage::getModel('bpost_shm/holidays')->getCollection()->getHolidays();
738
+
739
+ if(in_array($date, $holidays)) {
740
+ return true;
741
+ }
742
+
743
+ return false;
744
+ }
745
+
746
+
747
+ /**
748
+ * Format the delivery date to any format (default: Y-m-d)
749
+ *
750
+ * @param $date
751
+ * @param $format
752
+ * @return date
753
+ */
754
+ protected function _formatDeliveryDate($date, $format = "Y-m-d") {
755
+ $dateModel = Mage::getSingleton('core/date');
756
+
757
+ return $dateModel->date($format, strtotime($date));
758
+ }
759
+
760
+ /**
761
+ * Format the saturday delivery cost
762
+ *
763
+ * @param $value
764
+ * @return bool|float
765
+ */
766
+ public function formatSaturdayDeliveryCost($value)
767
+ {
768
+ $value = str_replace(',', '.', $value);
769
+ if (!is_numeric($value)) {
770
+ return false;
771
+ }
772
+ $value = (float)sprintf('%.4F', $value);
773
+ if ($value < 0.0000) {
774
+ return false;
775
+ }
776
+ return $value;
777
+ }
778
+
779
+ /**
780
+ * Check if on Onestepcheckout page or if Onestepcheckout is the refferer
781
+ *
782
+ * @return bool
783
+ */
784
+ public function getIsOnestepCheckout()
785
+ {
786
+ if (strpos(Mage::helper("core/url")->getCurrentUrl(), 'onestepcheckout') !== false || strpos(Mage::app()->getRequest()->getHeader('referer'), 'onestepcheckout') !== false) {
787
+ return true;
788
+ }
789
+
790
+ return false;
791
+ }
792
+
793
+ /**
794
+ * Calculates total weight of a shipment.
795
+ *
796
+ * @param $shipment
797
+ * @return int
798
+ */
799
+ public function calculateTotalShippingWeight($shipment)
800
+ {
801
+ $weight = 0;
802
+ $shipmentItems = $shipment->getAllItems();
803
+ foreach ($shipmentItems as $shipmentItem) {
804
+ $orderItem = $shipmentItem->getOrderItem();
805
+ if (!$orderItem->getParentItemId()) {
806
+ $weight = $weight + ($shipmentItem->getWeight() * $shipmentItem->getQty());
807
+ }
808
+ }
809
+
810
+ return $weight;
811
+ }
812
+
813
+
814
+ /**
815
+ * @param $shipments
816
+ * @return int
817
+ */
818
+ public function processShipmentsWeight($order)
819
+ {
820
+ $bpostHelper = Mage::helper("bpost_shm/system_config");
821
+ $weightUnit = $bpostHelper->getBpostShippingConfig("weight_unit");
822
+
823
+ $totalShipmentsWeight = 0;
824
+
825
+ $shipmentCollection = Mage::getModel("sales/order_shipment")->getCollection()
826
+ ->addFieldToFilter("order_id", $order->getId());
827
+
828
+ foreach ($shipmentCollection as $shipment){
829
+ if ($weightUnit == "") {
830
+ $totalShipmentsWeight += $shipment->getTotalWeight() * 100;
831
+ } else {
832
+ $totalShipmentsWeight += $shipment->getTotalWeight() * $weightUnit;
833
+ }
834
+ }
835
+
836
+ return $totalShipmentsWeight;
837
+ }
838
+ }
app/code/community/Bpost/ShM/Helper/Returnlabel.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Helper_Returnlabel
13
+ */
14
+ class Bpost_ShM_Helper_Returnlabel extends Mage_Core_Helper_Abstract
15
+ {
16
+ /**
17
+ * @param $orderId
18
+ * function returns the nr of returnlabels an order has.
19
+ * unfortunately, we must do this with collection count
20
+ */
21
+ public function getOrderReturnlabelsCount($orderId){
22
+ $returnLabelCollection = Mage::getModel("bpost_shm/returnlabel");
23
+ $collection = $returnLabelCollection->getCollection()->addFieldToFilter("order_id", $orderId);
24
+
25
+ return $collection->count();
26
+ }
27
+
28
+
29
+ /**
30
+ * @param $order
31
+ * @param $parsedLabelResponse
32
+ * @return string
33
+ * function returns the barcode by parsed label response
34
+ * make sures we return an unique name
35
+ * if no barcode is returned (probably never)
36
+ */
37
+ public function getBarcodeByLabelResponse($order, $parsedLabelResponse){
38
+ if(!isset($parsedLabelResponse["returnBarcodeString"]) || $parsedLabelResponse["returnBarcodeString"][0] == ""){
39
+ $barcode = "no-barcode-".$order->getIncrementId();
40
+ }else{
41
+ $barcode = $parsedLabelResponse["returnBarcodeString"][0];
42
+ }
43
+
44
+ return $barcode;
45
+ }
46
+ }
app/code/community/Bpost/ShM/Helper/System/Config.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ class Bpost_ShM_Helper_System_Config extends Mage_Core_Helper_Abstract
10
+ {
11
+
12
+ /**
13
+ * @param $code
14
+ * @param int $storeId
15
+ * @return mixed
16
+ * function returns the configured value by system code
17
+ */
18
+ public function getBpostShippingConfig($code, $storeId = 0){
19
+ $value = Mage::getStoreConfig("shipping/bpost_shm/$code", $storeId);
20
+
21
+ if($code == "passphrase"){
22
+ $value = Mage::helper('core')->decrypt($value);
23
+ }
24
+
25
+ return $value;
26
+ }
27
+
28
+ /**
29
+ * @param $code
30
+ * @param int $storeId
31
+ * @return mixed
32
+ * function returns the configured carrier value by system code
33
+ */
34
+ public function getBpostCarriersConfig($code, $carrier, $storeId = 0){
35
+ return Mage::getStoreConfig("carriers/$carrier/$code", $storeId);
36
+ }
37
+
38
+
39
+ //we create separate functions for config values that are called a lot
40
+ //...
41
+
42
+ public function isApiLoggingEnabled($storeId = 0){
43
+ return (bool)$this->getBpostShippingConfig("enable_log_api", $storeId);
44
+ }
45
+
46
+ public function isLoggingEnabled($storeId = 0){
47
+ return (bool)$this->getBpostShippingConfig("enable_log", $storeId);
48
+ }
49
+ }
app/code/community/Bpost/ShM/Model/.DS_Store ADDED
Binary file
app/code/community/Bpost/ShM/Model/Adminhtml/Bpostgrid.php ADDED
@@ -0,0 +1,469 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ class Bpost_ShM_Model_Adminhtml_Bpostgrid extends Varien_Event_Observer{
10
+
11
+ const MEDIA_LABEL_PATH = "/bpost/orderlabels/";
12
+ protected $_transaction = null;
13
+ protected $_addReturnLabels = false;
14
+ protected $_returnBarcodeArray = array();
15
+ protected $_barcodeArray = array();
16
+
17
+
18
+ /**
19
+ * Generates and completes an order, reference: generateAndCompleteAction.
20
+ * @param $order
21
+ * @return bool
22
+ */
23
+ public function generateAndCompleteOrder($orderId)
24
+ {
25
+ $order = Mage::getModel('sales/order')->load($orderId);
26
+ $shipmentCollection = $order->getShipmentsCollection();
27
+ $collectionCount = $shipmentCollection->count();
28
+ $shipment = false;
29
+
30
+ $retryAutomatedShipment = false;
31
+ if($collectionCount == 1 && $shipmentCollection->getFirstItem()->getBpostShipmentAutomated() == 1){
32
+ $retryAutomatedShipment = true;
33
+ }
34
+
35
+ if ($collectionCount > 0 && !$order->getBpostLabelExists() && !$retryAutomatedShipment) {
36
+ return $this->_processAvailableShipments($order);
37
+
38
+ } elseif (!$order->getBpostLabelExists()) {
39
+
40
+ if($retryAutomatedShipment){
41
+ $shipment = $shipmentCollection->getFirstItem();
42
+ }
43
+ return $this->_createBpostShipment($order, $shipment);
44
+ } else {
45
+ $message = Mage::helper('bpost_shm')->__("The order with id %s is not ready to be shipped or has already been shipped.", $order->getIncrementId());
46
+ Mage::getSingleton('core/session')->addNotice($message);
47
+ return false;
48
+ }
49
+ }
50
+
51
+
52
+ /**
53
+ * @param $order
54
+ * @return bool
55
+ */
56
+ protected function _processAvailableShipments(&$order)
57
+ {
58
+ $configHelper = Mage::helper('bpost_shm/system_config');
59
+ $bpostHelper = Mage::helper('bpost_shm');
60
+
61
+ $this->_addReturnLabels = (bool)$configHelper->getBpostShippingConfig("automatic_retour_labels", $order->getStoreId());
62
+ $locale = strtolower($bpostHelper->getLocaleByOrder($order, true));
63
+
64
+ $trackCollection = Mage::getResourceModel('sales/order_shipment_track_collection')
65
+ ->addFieldToFilter('order_id', $order->getId())
66
+ ->addFieldToFilter('carrier_code', 'bpostshm');
67
+
68
+
69
+ if ($trackCollection->count() > 0) {
70
+ $counter = 0;
71
+
72
+ $shipmentsArray = array();
73
+ foreach ($trackCollection as $tracker) {
74
+ if (!array_key_exists($tracker->getParentId(), $shipmentsArray)) {
75
+ $shipmentsArray[$tracker->getParentId()] = Mage::getResourceModel('sales/order_shipment_collection')->addFieldToFilter('entity_id', $tracker->getParentId())->setPageSize(1)->getFirstItem();
76
+ }
77
+
78
+ //first we create a bpost order
79
+ Mage::log("creating order");
80
+ $this->_createBpostOrder($order);
81
+ $counter++;
82
+ }
83
+
84
+ $pdfBaseName = $this->_generateLabelAndReturnLabelIfEnabled($order);
85
+
86
+ if (!$pdfBaseName) {
87
+ $message = Mage::helper('bpost_shm')->__("Something went wrong while processing order #%s, please check your error logs.", $order->getIncrementId());
88
+ Mage::getSingleton('core/session')->addError($message);
89
+ return false;
90
+ }
91
+
92
+ $tmpCounter = 0;
93
+ foreach ($trackCollection as $tracker) {
94
+ $shipment = $shipmentsArray[$tracker->getParentId()];
95
+ $label = $this->_parseLabelData($order, $tmpCounter);
96
+ $barcode = $label['barcode'];
97
+
98
+ try {
99
+ if (array_key_exists('returnBarcode', $label)) {
100
+ $shipment->setBpostReturnBarcode($label['returnBarcode']);
101
+ }
102
+
103
+ $shipment->setBpostLabelPath($pdfBaseName);
104
+ $shipment->setBpostTrackingUrl('<a target="_blank" href="' . Bpost_ShM_Model_Shipping_Carrier_BpostShM::SHIPMENT_TRACK_DOMAIN."etr/light/performSearch.do?searchByItemCode=true&oss_language=" . $locale . "&itemCodes=" . $order->getIncrementId() . '">' . Mage::helper('bpost_shm')->__('Track this shipment') . '</a>');
105
+ $tracker->setData("number", $barcode);
106
+
107
+ //add data to transaction
108
+ $this->_getTransaction()
109
+ ->addObject($shipment)
110
+ ->addObject($tracker);
111
+
112
+ } catch (Exception $e) {
113
+ Mage::helper('bpost_shm')->log($e->getMessage(), Zend_Log::ERR);
114
+ continue;
115
+ }
116
+
117
+ $tmpCounter++;
118
+ }
119
+
120
+ $order->addStatusHistoryComment(Mage::helper('bpost_shm')->__('Shipped with bpost generateLabelAndComplete'), true);
121
+
122
+ if($this->_addReturnLabels){
123
+ $order->setBpostReturnLabelExists(true);
124
+ }
125
+
126
+ $order->setBpostLabelExists(true);
127
+ $this->_getTransaction()->addObject($order);
128
+
129
+ return $counter;
130
+ } else {
131
+ $message = Mage::helper('bpost_shm')->__("The order with id %s only has non-bpost shipments.", $order->getIncrementId());
132
+ Mage::getSingleton('core/session')->addNotice($message);
133
+ return false;
134
+ }
135
+ }
136
+
137
+
138
+ /**
139
+ * @param $order
140
+ * @return bool
141
+ */
142
+ protected function _createBpostShipment(&$order, $shipment = false)
143
+ {
144
+ $configHelper = Mage::helper('bpost_shm/system_config');
145
+ $bpostHelper = Mage::helper('bpost_shm');
146
+
147
+ $this->_addReturnLabels = (bool)$configHelper->getBpostShippingConfig("automatic_retour_labels", $order->getStoreId());
148
+ $locale = strtolower($bpostHelper->getLocaleByOrder($order, true));
149
+
150
+ if(!$shipment){
151
+ $shipment = $order->prepareShipment();
152
+ $shipment->register()->setBpostShipmentAutomated(true)->save();
153
+ }
154
+
155
+ $weight = Mage::helper('bpost_shm')->calculateTotalShippingWeight($shipment);
156
+ $shipment->setTotalWeight($weight);
157
+
158
+ //first create the bpost order
159
+ $this->_createBpostOrder($order);
160
+
161
+ //then create label for order
162
+ $pdfBaseName = $this->_generateLabelAndReturnLabelIfEnabled($order);
163
+ $label = $this->_parseLabelData($order);
164
+ $barcode = $label['barcode'];
165
+
166
+ if (!$pdfBaseName) {
167
+ $message = Mage::helper('bpost_shm')->__("Something went wrong while processing order #%s, please check your error logs.", $order->getIncrementId());
168
+ Mage::getSingleton('core/session')->addError($message);
169
+ return false;
170
+ } else {
171
+ if (array_key_exists('returnBarcode', $label)) {
172
+ $shipment->setBpostReturnBarcode($label['returnBarcode']);
173
+ }
174
+ $shipment->setBpostLabelPath($pdfBaseName);
175
+ $shipment->setBpostTrackingUrl('<a target="_blank" href="' . Bpost_ShM_Model_Shipping_Carrier_BpostShM::SHIPMENT_TRACK_DOMAIN."etr/light/performSearch.do?searchByItemCode=true&oss_language=" . $locale . "&itemCodes=" . $order->getIncrementId() . '">' . Mage::helper('bpost_shm')->__('Track this shipment') . '</a>');
176
+ $order->setIsInProcess(true);
177
+ $order->addStatusHistoryComment(Mage::helper('bpost_shm')->__('Shipped with bpost generateLabelAndComplete'), true);
178
+ $order->setBpostLabelExists(true);
179
+
180
+ if($this->_addReturnLabels){
181
+ $order->setBpostReturnLabelExists(true);
182
+ }
183
+
184
+ $tracker = Mage::getModel('sales/order_shipment_track')
185
+ ->setShipment($shipment)
186
+ ->setData('title', 'bpost')
187
+ ->setData('number', $barcode)
188
+ ->setData('carrier_code', "bpostshm")
189
+ ->setData('order_id', $shipment->getData('order_id'));
190
+
191
+ try {
192
+ //save all objects in 1 transaction
193
+ //add data to the current transaction
194
+ $this->_getTransaction()
195
+ ->addObject($shipment)
196
+ ->addObject($order)
197
+ ->addObject($tracker);
198
+ } catch (Exception $e) {
199
+ Mage::helper('bpost_shm')->log($e->getMessage(), Zend_Log::ERR);
200
+ }
201
+
202
+ return 1;
203
+ }
204
+ }
205
+
206
+
207
+ /**
208
+ * @param $labelData
209
+ * function parses label data and returns it
210
+ */
211
+ protected function _parseLabelData($order, $barcodeIndex = 0){
212
+ $bpostHelper = Mage::helper('bpost_shm');
213
+
214
+ $returnData = array();
215
+ $locale = $bpostHelper->getLocaleByOrder($order, true);
216
+
217
+ $returnData["locale"] = $locale;
218
+
219
+ if(!isset($this->_barcodeArray[$barcodeIndex])){
220
+ $returnData["barcode"] = "no-barcode";
221
+ }else{
222
+ $returnData["barcode"] = $this->_barcodeArray[$barcodeIndex];
223
+ }
224
+
225
+ //check if the barcode index isset
226
+ //if so, a return barcode is available
227
+ if(isset($this->_returnBarcodeArray[$barcodeIndex])){
228
+ $returnData["returnBarcode"] = $this->_returnBarcodeArray[$barcodeIndex];
229
+ }
230
+
231
+ return $returnData;
232
+ }
233
+
234
+
235
+ /**
236
+ * function generates bpost API order
237
+ * @param $order
238
+ * @throws Mage_Core_Exception
239
+ */
240
+ protected function _createBpostOrder(&$order){
241
+ $bpostHelper = Mage::helper("bpost_shm");
242
+
243
+ $webserviceModel = Mage::getModel("bpost_shm/api", true);
244
+ $response = $webserviceModel->createOrder($order);
245
+
246
+ if(!$response){
247
+ Mage::throwException($bpostHelper->__("Error while creating a bpost order for Magento order #%s. Please check your API log.", $order->getIncrementId()));
248
+ }
249
+
250
+ if(!$order->getBpostReference()){
251
+ $order->setBpostReference($order->getIncrementId());
252
+ }
253
+ }
254
+
255
+
256
+
257
+ /**
258
+ * Generates a shipment label and saves it on the harddisk.
259
+ *
260
+ * @param $order
261
+ * @param $shipment
262
+ * @return mixed
263
+ */
264
+ protected function _generateLabelAndReturnLabelIfEnabled(&$order){
265
+ $bpostHelper = Mage::helper("bpost_shm");
266
+ $pdfName = null;
267
+
268
+ $webserviceModel = Mage::getModel("bpost_shm/api", true);
269
+ $responseLabelWebserviceCallback = $webserviceModel->createLabelByOrder($order, $this->_addReturnLabels);
270
+
271
+ if ($responseLabelWebserviceCallback) {
272
+ $parsedResponse = $bpostHelper->parseLabelApiResponse($responseLabelWebserviceCallback, $order);
273
+
274
+ if(empty($parsedResponse) || !isset($parsedResponse["pdfString"])){
275
+ $message = $bpostHelper->__("No label response received for Magento order #%s.", $order->getIncrementId());
276
+ $bpostHelper->log($message, Zend_Log::ERR);
277
+ return false;
278
+ }
279
+
280
+ $this->_barcodeArray = $parsedResponse["barcodeString"];
281
+
282
+ if(array_key_exists("returnBarcodeString", $parsedResponse)) {
283
+ $this->_returnBarcodeArray = $parsedResponse["returnBarcodeString"];
284
+ }
285
+
286
+ //loop array and save pdf files
287
+ $loopNr = 0;
288
+ $pdfName = "";
289
+ foreach($parsedResponse["pdfString"] as $pdfString){
290
+ if($loopNr){
291
+ $pdfName .= ":";
292
+ }
293
+
294
+ $pdfName .= $bpostHelper->generatePdfAndSave($pdfString, "orderlabels", $order->getIncrementId());
295
+ $pdfName .= ".pdf";
296
+
297
+ if($this->_addReturnLabels){
298
+ $order->setBpostReturnLabelExists(true);
299
+ }
300
+
301
+ $loopNr++;
302
+ }
303
+
304
+ return $pdfName;
305
+ }
306
+
307
+ return false;
308
+ }
309
+
310
+
311
+ /**
312
+ * function returns the current transaction
313
+ */
314
+ protected function _getTransaction(){
315
+ if(is_null($this->_transaction)){
316
+ $this->_transaction = Mage::getModel('core/resource_transaction');
317
+ }
318
+
319
+ return $this->_transaction;
320
+ }
321
+
322
+
323
+ /**
324
+ * function will save the current transaction
325
+ */
326
+ public function saveTransaction(){
327
+ //make sure we have an object first before saving it
328
+ if(is_object($this->_transaction)){
329
+ $this->_transaction->save();
330
+ }
331
+ }
332
+
333
+
334
+ /**
335
+ * Processes the undownloadable labels. (set mark and zip)
336
+ *
337
+ * @param $orderIds
338
+ * @return bool|string
339
+ */
340
+ public function processUndownloadedLabels($orderIds)
341
+ {
342
+ $file = new Varien_Io_File();
343
+ $labelPdfArray = array();
344
+ $i = 0;
345
+ foreach ($orderIds as $orderId) {
346
+ $order = Mage::getModel('sales/order')->load($orderId);
347
+ $exported = false;
348
+
349
+ if (!$order->getBpostLabelExported()) {
350
+ $shippingCollection = Mage::getResourceModel('sales/order_shipment_collection')
351
+ ->setOrderFilter($order)
352
+ ->load();
353
+
354
+ if (count($shippingCollection)) {
355
+ foreach ($shippingCollection as $shipment) {
356
+ if($shipment->getBpostLabelPath() != "" && !$exported){
357
+ $labelPaths = explode(":", $shipment->getBpostLabelPath());
358
+ foreach($labelPaths as $labelPath){
359
+ $filePath = Mage::getBaseDir('media') . self::MEDIA_LABEL_PATH . $labelPath;
360
+ if($file->fileExists($filePath)){
361
+ $labelPdfArray[] = $filePath;
362
+ $exported = true;
363
+ }
364
+ }
365
+ }
366
+ }
367
+
368
+ if ($exported) {
369
+ $shippingCollection->setDataToAll("bpost_label_exported", true);
370
+ $order->setBpostLabelExported(true);
371
+ }
372
+
373
+ $shippingCollection->save();
374
+ $order->save();
375
+ }
376
+ } else {
377
+ $i++;
378
+ }
379
+ }
380
+
381
+ if (!count($labelPdfArray)) {
382
+ return false;
383
+ }
384
+ if ($i > 0) {
385
+ $message = Mage::helper('bpost_shm')->__('%s orders already had downloaded labels.', $i);
386
+ Mage::getSingleton('core/session')->addNotice($message);
387
+ }
388
+
389
+ $generated_name = date("Y_m_d_H_i_s") . "_undownloaded.zip";
390
+
391
+ $file = new Varien_Io_File();
392
+ $file->checkAndCreateFolder(Mage::getBaseDir('media') . self::MEDIA_LABEL_PATH."zips/");
393
+
394
+ return $this->_zipLabelPdfArray($labelPdfArray, $generated_name, true, true);
395
+ }
396
+
397
+
398
+ /**
399
+ * Zips the labels.
400
+ *
401
+ * @param array $files
402
+ * @param string $generated_name
403
+ * @param bool $overwrite
404
+ * @return bool|string
405
+ */
406
+ protected function _zipLabelPdfArray($files = array(), $generated_name = '', $overwrite = false, $mergePdfFiles = false)
407
+ {
408
+ $destination = Mage::getBaseDir('media') . self::MEDIA_LABEL_PATH."zips/" . $generated_name;
409
+ $varienFile = new Varien_Io_File();
410
+ $bpostHelper = Mage::helper("bpost_shm");
411
+
412
+
413
+ if ($varienFile->fileExists($destination) && !$overwrite) {
414
+ return false;
415
+ }
416
+
417
+ $valid_files = array();
418
+ $pdfMerged = new Zend_Pdf();
419
+
420
+ if (is_array($files)) {
421
+ foreach ($files as $file) {
422
+ if ($varienFile->fileExists($file)) {
423
+ $valid_files[] = $file;
424
+
425
+ if ($mergePdfFiles) {
426
+ $tmpPdf = Zend_Pdf::load($file);
427
+ foreach ($tmpPdf->pages as $page) {
428
+ $clonedPage = clone $page;
429
+ $pdfMerged->pages[] = $clonedPage;
430
+ }
431
+ }
432
+ }
433
+ }
434
+
435
+ //save new pdf file is necessary
436
+ if($mergePdfFiles){
437
+ $mergedPdfName = $bpostHelper->generatePdfAndSave($pdfMerged->render(), "orderlabels", "merged");
438
+ $mergedPdfName = $mergedPdfName.".pdf";
439
+
440
+ if($mergedPdfName){
441
+ $valid_files = array($mergedPdfName);
442
+ }
443
+ }
444
+
445
+ $validFilesCount = count($valid_files);
446
+ if ($validFilesCount && $validFilesCount > 1) {
447
+ $zip = new ZipArchive();
448
+
449
+ if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
450
+ return false;
451
+ }
452
+
453
+ foreach ($valid_files as $file) {
454
+ $fileName = $bpostHelper->getFileNameByPath($file);
455
+ $zip->addFile($file, $fileName);
456
+ }
457
+
458
+ $zip->close();
459
+ return $generated_name;
460
+ } elseif($validFilesCount) {
461
+ //we return the pdf path instead of creating a zip file
462
+ $pdfName = $valid_files[0];
463
+ return $pdfName;
464
+ }
465
+
466
+ return false;
467
+ }
468
+ }
469
+ }
app/code/community/Bpost/ShM/Model/Adminhtml/Observer.php ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Model_Adminhtml_Observer
5
+ */
6
+ class Bpost_ShM_Model_Adminhtml_Observer extends Varien_Event_Observer
7
+ {
8
+ /**
9
+ * @param $observer
10
+ * @return bool
11
+ */
12
+ public function core_block_abstract_to_html_before($observer)
13
+ {
14
+ if(Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager') && !Mage::getSingleton('adminhtml/session')->getOldExtensionMessageShown() && Mage::helper('adminhtml')->getCurrentUserId() != "") {
15
+ $popupMessage = Mage::helper('bpost_shm')->__('Please remove or disable the old bpost extension prior to the installation of the new one.');
16
+ Mage::getSingleton('adminhtml/session')->addNotice($popupMessage);
17
+ Mage::getSingleton('adminhtml/session')->setOldExtensionMessageShown(true);
18
+ }
19
+
20
+ $block = $observer->getBlock();
21
+
22
+ //add download bpost label on shipment view page
23
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Shipment_View && $block->getRequest()->getControllerName() == "sales_order_shipment") {
24
+ $shipment = Mage::registry('current_shipment');
25
+ $shipmentId = $shipment->getId();
26
+ $order = Mage::getModel('sales/order')->load($shipment->getOrderId());
27
+
28
+ if (strpos($order->getShippingMethod(), 'bpost') !== false && ($shipment->getBpostLabelPath() && $shipment->getBpostLabelExported())) {
29
+ $block->addButton('download', array(
30
+ 'label' => Mage::helper('bpost_shm')->__('Download bpost label'),
31
+ 'onclick' => 'setLocation(\'' . Mage::helper("adminhtml")->getUrl('adminhtml/bpost_shM_download/label/shipment_id/' . $shipmentId) .'\')',
32
+ 'class' => 'scalable save',
33
+ ), 1, 0);
34
+ }
35
+ }
36
+
37
+ //add bpost return label on order view page
38
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View && $block->getRequest()->getControllerName() == "sales_order") {
39
+ $order = Mage::registry('current_order');
40
+
41
+ if(strpos($order->getShippingMethod(), 'bpostshm') !== false){
42
+ $block->addButton('download', array(
43
+ 'label' => Mage::helper('bpost_shm')->__('bpost Return Label'),
44
+ 'onclick' => 'setLocation(\'' . Mage::helper("adminhtml")->getUrl('adminhtml/bpost_shM_download/returnLabel/order_id/' . $order->getId()) .'\')',
45
+ 'class' => 'scalable save',
46
+ ), 1, 0);
47
+ }
48
+ }
49
+
50
+ //add extra tab return barcodes on order view page
51
+ //removed on bpost's request
52
+
53
+ /*
54
+ if($block instanceof Mage_Adminhtml_Block_Sales_Order_View_Tabs){
55
+ $order = $block->getOrder();
56
+
57
+ if(strpos($order->getShippingMethod(), 'bpost') !== false){
58
+ $block->addTab('order_view_tab_bpostreturnbarcodetab', array(
59
+ 'label' => Mage::helper('bpost_shm')->__('bpost Return Barcodes'),
60
+ 'title' => Mage::helper('bpost_shm')->__('bpost Return Barcodes'),
61
+ 'after' => "order_view_tab_bpostreturnlabeltab",
62
+ 'content' => $block->getLayout()->createBlock('bpost_shm/adminhtml_sales_order_view_tab_returnbarcode', 'bpost_returnbarcode_grid')->toHtml()
63
+ ));
64
+
65
+ $block->setActiveTab("order_info");
66
+ }
67
+ }
68
+ */
69
+
70
+ return false;
71
+ }
72
+
73
+
74
+ /**
75
+ * @param $observer
76
+ * @return bool
77
+ */
78
+ public function bpost_shm_prepare_grid_collection_after($observer){
79
+ $collection = $observer->getCollection();
80
+ $transaction = Mage::getModel('core/resource_transaction');
81
+
82
+ //we only need to update the bpost status for orders that does not have the status “pending“, “completed”, “closed” or “cancelled”
83
+ $stateArray = array(
84
+ Mage_Sales_Model_Order::STATE_NEW,
85
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
86
+ Mage_Sales_Model_Order::STATE_CLOSED,
87
+ Mage_Sales_Model_Order::STATE_COMPLETE,
88
+ Mage_Sales_Model_Order::STATE_CANCELED,
89
+ );
90
+
91
+ $collection->addAttributeToSelect('bpost_reference');
92
+ $bpostHelper = Mage::helper("bpost_shm");
93
+
94
+ //loop collection and get statuses
95
+ foreach($collection as $order){
96
+ if(in_array($order->getState(), $stateArray)){
97
+ continue;
98
+ }
99
+
100
+ $dataChanged = false;
101
+ $orderStatus = false;
102
+
103
+ if($order->getBpostReference()){
104
+ try{
105
+ $bpostShipmentStatuses = $bpostHelper->getBpostStatus($order);
106
+
107
+ if(!$bpostShipmentStatuses){
108
+ continue;
109
+ }
110
+
111
+ $trackCollection = Mage::getResourceModel('sales/order_shipment_track_collection')
112
+ ->addFieldToFilter('order_id', $order->getId())
113
+ ->addFieldToFilter('carrier_code', 'bpostshm');
114
+
115
+
116
+ //extra count check
117
+ //normally not necessary. If the bpost reference exists a shipment track must exists too.
118
+ if($trackCollection->count() == 0){
119
+ continue;
120
+ }
121
+
122
+ foreach($trackCollection as $track){
123
+ $trackNumber = $track->getTrackNumber();
124
+
125
+ if($trackNumber && isset($bpostShipmentStatuses[$trackNumber])){
126
+ $status = $bpostShipmentStatuses[$trackNumber];
127
+ $shipment = $track->getShipment();
128
+ $shipment->setBpostStatus($status);
129
+ $transaction->addObject($shipment);
130
+
131
+ if($orderStatus && $status != $orderStatus){
132
+ $orderStatus = "multiple_statuses";
133
+ }elseif(!$orderStatus){
134
+ $orderStatus = $status;
135
+ }
136
+
137
+ $dataChanged = true;
138
+ }
139
+ }
140
+
141
+ $order->setBpostStatus($orderStatus);
142
+
143
+ //we use a transaction for saving our data
144
+ //need to save shipment and order
145
+ if($dataChanged){
146
+ $transaction->addObject($order);
147
+
148
+ //save transaction
149
+ $transaction->save();
150
+ }
151
+ }catch(Exception $e){
152
+ Mage::helper("bpost_shm")->ApiLog($e->getMessage(), Zend_Log::ERR);
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+
159
+ /**
160
+ * @param $observer
161
+ */
162
+ public function sales_order_shipment_grid_collection_load_before($observer){
163
+ //join data from sale_flat_shipment to sale_flat_shipment_grid
164
+ $collection = $observer->getOrderShipmentGridCollection();
165
+ $collection->addFieldToSelect("bpost_status");
166
+ }
167
+
168
+
169
+ /**
170
+ * @param $observer
171
+ * @return $this
172
+ * function triggered when saving shipping settings bpost module
173
+ * checks if authentication is valid
174
+ */
175
+ public function admin_system_config_changed_section_shipping($observer)
176
+ {
177
+ /** @var Bpost_ShM_Model_Api $api */
178
+ $session = Mage::getSingleton("adminhtml/session");
179
+ $configHelper = Mage::helper("bpost_shm/system_config");
180
+
181
+ try{
182
+ $api = Mage::getModel( 'bpost_shm/api', true );
183
+ $apiResponse = $api->getProductConfig();
184
+
185
+ if(!$apiResponse) {
186
+ Mage::throwException("Failed to authenticate with bpost, please check your credentials.");
187
+ }
188
+
189
+ $session->addSuccess($configHelper->__("Successfully authenticated with bpost."));
190
+ }catch(Exception $e){
191
+ $session->addError($configHelper->__($e->getMessage()));
192
+ }
193
+
194
+ return $this;
195
+ }
196
+
197
+ /**
198
+ * Calculate and set the weight on the shipping to pass it to the webservice after a standard shipment save.
199
+ *
200
+ * @param $observer
201
+ */
202
+ public function sales_order_shipment_save_before($observer)
203
+ {
204
+ $shipment = $observer->getEvent()->getShipment();
205
+ if (!$shipment->hasId() && !$shipment->getTotalWeight()) {
206
+ $weight = Mage::helper('bpost_shm')->calculateTotalShippingWeight($shipment);
207
+ $shipment->setTotalWeight($weight);
208
+ }
209
+ }
210
+ }
app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Backend/Shipping/Tablerates/Homedelivery.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Adminhtml_System_Config_Backend_Shipping_Tablerates_Homedelivery extends Mage_Core_Model_Config_Data
3
+ {
4
+ /**
5
+ * Call the uploadAndImport function from the homedelivery tablerate recourcemodel.
6
+ */
7
+ public function _afterSave()
8
+ {
9
+ Mage::getResourceModel('bpost_shm/tablerates_homedelivery')->uploadAndImport($this);
10
+ }
11
+ }
app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Backend/Shipping/Tablerates/International.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Adminhtml_System_Config_Backend_Shipping_Tablerates_International extends Mage_Core_Model_Config_Data
3
+ {
4
+ /**
5
+ * Call the uploadAndImport function from the international tablerate recourcemodel.
6
+ */
7
+ public function _afterSave()
8
+ {
9
+ Mage::getResourceModel('bpost_shm/tablerates_international')->uploadAndImport($this);
10
+ }
11
+ }
app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Backend/Shipping/Tablerates/Parcellocker.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Adminhtml_System_Config_Backend_Shipping_Tablerates_Parcellocker extends Mage_Core_Model_Config_Data
3
+ {
4
+ /**
5
+ * Call the uploadAndImport function from the parcellocker tablerate recourcemodel.
6
+ */
7
+ public function _afterSave()
8
+ {
9
+ Mage::getResourceModel('bpost_shm/tablerates_parcellocker')->uploadAndImport($this);
10
+ }
11
+ }
app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Backend/Shipping/Tablerates/Pickuppoint.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Adminhtml_System_Config_Backend_Shipping_Tablerates_Pickuppoint extends Mage_Core_Model_Config_Data
3
+ {
4
+ /**
5
+ * Call the uploadAndImport function from the pickuppoint tablerate recourcemodel.
6
+ */
7
+ public function _afterSave()
8
+ {
9
+ Mage::getResourceModel('bpost_shm/tablerates_pickuppoint')->uploadAndImport($this);
10
+ }
11
+ }
app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Source/Datecomment.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ /**
11
+ * Class Bpost_ShM_Model_Adminhtml_System_Config_Source_Datecomment
12
+ */
13
+ class Bpost_ShM_Model_Adminhtml_System_Config_Source_Datecomment extends Mage_Core_Model_Config_Data
14
+ {
15
+
16
+ public function getCommentText(Mage_Core_Model_Config_Element $element, $currentValue)
17
+ {
18
+ $bpostHelper = Mage::helper("bpost_shm");
19
+ $popupUrl = "'" . Mage::helper("adminhtml")->getUrl('adminhtml/bpost_shM_config/screenshotpopup') . "'";
20
+
21
+ $html = $bpostHelper->__("Displays calculated delivery date in the frontend:");
22
+ $html .= "<br/>";
23
+ $html .= '<a href="#" onclick="openPopup(' . $popupUrl . ',400,600);">';
24
+ $html .= '<span>' . $bpostHelper->__("Example") . '</span> ';
25
+ $html .= '</a>';
26
+
27
+ return $html;
28
+ }
29
+
30
+ }
app/code/community/Bpost/ShM/Model/Adminhtml/System/Config/Source/Shipping.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ class Bpost_ShM_Model_Adminhtml_System_Config_Source_Shipping
10
+ {
11
+
12
+ /**
13
+ * standard option array function
14
+ * if no function is added to the source model, this function will be called
15
+ */
16
+ public function toOptionArray(){
17
+
18
+ }
19
+
20
+ /**
21
+ * @return array
22
+ * function returns the available label sizes
23
+ */
24
+ public function getLabelSizesOptionsArray(){
25
+ return array("a4" => "A4", "a6" => "A6");
26
+ }
27
+
28
+ /**
29
+ * @return array
30
+ */
31
+ public function nrOfDeliveryDaysShownOptionsArray(){
32
+ return array(2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7);
33
+ }
34
+
35
+ /**
36
+ * @return array
37
+ * function returns an array with all available log levels
38
+ */
39
+ public function getLogLevels(){
40
+ return array(0 => "Emergency", 1 => "Alert", 2 => "Critical", 3 => "Error", 4 => "Warning", 5 => "Notice", 6 => "Informational", 7 => "Debug");
41
+ }
42
+
43
+
44
+ /**
45
+ * @return array
46
+ */
47
+ public function getCountries(){
48
+ return array("BE" => Mage::helper("bpost_shm")->__("Belgium"));
49
+ }
50
+
51
+
52
+ }
app/code/community/Bpost/ShM/Model/Api.php ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ class Bpost_ShM_Model_Api extends Bpost_ShM_Model_Api_Abstract
12
+ {
13
+ /**
14
+ * function returns the product configuration for a specific customer
15
+ */
16
+ public function getProductConfig(){
17
+ $path = $this->_accountId.DS."productconfig";
18
+ $headers = array("Accept:application/vnd.bpost.shm-productConfiguration-v3.1+XML");
19
+
20
+ $response = $this->_call($path, $headers);
21
+ return $response;
22
+ }
23
+
24
+
25
+ /**
26
+ * @param $order
27
+ * @param bool $shipment
28
+ * @return bool|Zend_Http_Response
29
+ *
30
+ * function returns the API response of creating a RETURN label
31
+ * this response can be passed to the parse label response helper function
32
+ * and later on be saved
33
+ */
34
+ public function createReturnLabel($order){
35
+ //first we need to create a return order
36
+ //otherwise no label can be created
37
+ $response = $this->createOrder($order, true);
38
+
39
+ if(!$response) {
40
+ return false;
41
+ }
42
+
43
+ //now we create the label
44
+ return $this->createLabelByOrder($order);
45
+ }
46
+
47
+
48
+ /**
49
+ * @param $order
50
+ * @param bool $shipment
51
+ * @param bool $returnOrder
52
+ * @return bool|Zend_Http_Response
53
+ * @throws Mage_Core_Exception
54
+ * function creates an order/label for bpost orders
55
+ */
56
+
57
+ public function createOrder($order, $returnOrder = false){
58
+ $path = $this->_accountId.DS."orders";
59
+ $headers = array("Content-Type:application/vnd.bpost.shm-order-v3.3+XML");
60
+
61
+ $shippingMethod = $order->getShippingMethod();
62
+
63
+ //check to make sure we only handle bpost orders
64
+ if(!$returnOrder && strpos($shippingMethod,"bpost_") === false){
65
+ Mage::throwException("Only orders with delivery method 'bpost_*' can be send to bpost.");
66
+ }
67
+
68
+ //now we create a new dom element
69
+ //we use the domcreator class for this
70
+ $domCreator = Mage::getModel("bpost_shm/api_domcreator", true);
71
+ $document = $domCreator->getCreateOrderDomDocument($order, $returnOrder);
72
+
73
+ $errorHandlingData = array("request_name" => "createOrder", "order_id" => $order->getIncrementId());
74
+ $response = $this->_call($path, $headers, $errorHandlingData, "post", $document);
75
+
76
+ return $response;
77
+ }
78
+
79
+
80
+ /**
81
+ * @param bool $order
82
+ * @param bool $withReturnLabels
83
+ * @param string $format
84
+ * @return bool|Zend_Http_Response
85
+ * function calls the createLabelByShipmentOrInBulk function with reference prefix empty
86
+ */
87
+ public function createLabelByOrder($order, $withReturnLabels = false, $format = "pdf"){
88
+ return $this->createLabelByShipmentOrInBulk($order, $withReturnLabels, $format, "");
89
+ }
90
+
91
+
92
+ /**
93
+ * @param $shipmentOrOrderObject
94
+ * @param bool $withReturnLabels
95
+ * @param string $format
96
+ * @return bool|Zend_Http_Response
97
+ * function returns the API response of creating a label (with or without return label)
98
+ * this response can be passed to the parse label response helper function
99
+ * and later on be saved
100
+
101
+ * if no shipment is given, we will download in bulk
102
+ */
103
+ public function createLabelByShipmentOrInBulk($shipmentOrOrderObject = false, $withReturnLabels = false, $format = "pdf", $referencePrefix = "S"){
104
+ if($format === "pdf"){
105
+ $headers = array("Content-Type:application/vnd.bpost.shm-labelRequest-v3+XML","Accept:application/vnd.bpost.shm-label-pdf-v3+XML");
106
+ }else{
107
+ $headers = array("Content-Type:application/vnd.bpost.shm-labelRequest-v3+XML","Accept:application/vnd.bpost.shm-label-image-v3+XML");
108
+ }
109
+
110
+ $configHelper = Mage::helper("bpost_shm/system_config");
111
+
112
+ if($shipmentOrOrderObject){
113
+ $storeId = $shipmentOrOrderObject->getStoreId();
114
+ $referenceId = $referencePrefix.$shipmentOrOrderObject->getIncrementId();
115
+
116
+ if($shipmentOrOrderObject->getNewReference()){
117
+ $referenceId = $shipmentOrOrderObject->getNewReference();
118
+ }
119
+
120
+ $labelFormat = strtoupper($configHelper->getBpostShippingConfig("label_format", $storeId));
121
+ $path = $this->_accountId.DS."orders".DS.$referenceId.DS."labels".DS.$labelFormat;
122
+ }else{
123
+ $labelFormat = strtoupper($configHelper->getBpostShippingConfig("label_format"));
124
+ $path = $this->_accountId.DS."orders".DS."labels".DS.$labelFormat;
125
+ }
126
+
127
+ if($withReturnLabels){
128
+ $path .= DS."withReturnLabels";
129
+ }
130
+
131
+ $errorHandlingData = array("request_name" => "createLabel");
132
+ $response = $this->_call($path, $headers, $errorHandlingData);
133
+
134
+ return $response;
135
+ }
136
+
137
+
138
+ /**
139
+ * @param $order
140
+ * API function returns order details by reference
141
+ * @return mixed
142
+ */
143
+ public function retrieveOrderDetails($order){
144
+ $headers = array("Accept:application/vnd.bpost.shm-order-v3.3+XML");
145
+ $referenceId = $order->getIncrementId();
146
+
147
+ $path = $this->_accountId.DS."orders".DS.$referenceId;
148
+ $errorHandlingData = array("request_name" => "orderDetails");
149
+
150
+ $response = $this->_call($path, $headers, $errorHandlingData);
151
+ return $response;
152
+ }
153
+
154
+
155
+ /**
156
+ * GEO6 webservice call
157
+ * function delivers the nearest bpost pick-up points to a location given as argument.
158
+ * @param $addressData
159
+ * addressData = array that contains: street, number & zone
160
+ * street
161
+ * number
162
+ * zone: can be postcode or city
163
+ * @param $type
164
+ * type:
165
+ * Type 1 = Post Office
166
+ * Type 2 = Post Point
167
+ * Type 4 = bpack 24/7
168
+ * for example type 3 = type1 & type2
169
+ * @param $limit
170
+ * limit: max number of service points you want to get
171
+ * @param $language
172
+ * language nl or fr
173
+ * @return bool|Zend_Http_Response
174
+ */
175
+ public function getNearestServicePoints($addressData = array(), $type = "3", $limit = 10, $language = false){
176
+ $function = "search";
177
+ $format = "xml";
178
+
179
+ if(!array_key_exists("zone", $addressData)){
180
+ Mage::throwException("Your address data must contain a zone index (can be a postcode or city).");
181
+ }
182
+
183
+ $language = $this->_getCurrentLanguage($language);
184
+
185
+ $params = array("Type" => $type, "Limit" => $limit, "Language" => $language, "Function" => $function, "Format" => $format);
186
+ //fixing PEBKAC issue (see Confluence)
187
+ //$params["Street"] = $addressData["street"];
188
+ //$params["Number"] = $addressData["number"];
189
+ $params["Zone"] = $addressData["zone"];
190
+ $response = $this->_callTaxipostApi($params);
191
+
192
+ return $response->getBody();
193
+ }
194
+
195
+
196
+
197
+
198
+ /**
199
+ * GEO6 webservice call
200
+ * delivers the details for a bpost pick-up point referred to by its identifier.
201
+ * @param $servicePointId
202
+ * identifier
203
+ * @param $type
204
+ * type:
205
+ * Type 1 = Post Office
206
+ * Type 2 = Post Point
207
+ * Type 4 = bpack 24/7
208
+ * for example type 3 = type1 & type2
209
+ * @param $language
210
+ * language nl or fr
211
+ * @return bool|Zend_Http_Response
212
+ */
213
+ public function getServicePointDetails($servicePointId, $type = "3", $language = false){
214
+ $format = "xml";
215
+
216
+ $language = $this->_getCurrentLanguage($language);
217
+
218
+ $params = array("Type" => $type, "Format" => $format, "Language" => $language, "Function" => "info", "Id" => $servicePointId);
219
+ $response = $this->_callTaxipostApi($params);
220
+
221
+ return $response->getBody();
222
+ }
223
+
224
+
225
+ /**
226
+ * GEO6 webservice call
227
+ * delivers the details for a bpost Corner referred to by its identifier, presented in an HTML page.
228
+ * @param $servicePointId
229
+ * identifier
230
+ * @param $type
231
+ * type:
232
+ * Type 1 = Post Office
233
+ * Type 2 = Post Point
234
+ * Type 4 = bpack 24/7
235
+ * for example type 3 = type1 & type2
236
+ * @param $language
237
+ * language nl or fr
238
+ * @return bool|Zend_Http_Response
239
+ */
240
+ public function getServicePointPage($servicePointId, $type = "3", $language = false){
241
+ $language = $this->_getCurrentLanguage($language);
242
+
243
+ $params = array("Type" => $type, "Language" => $language, "Function" => "page", "Id" => $servicePointId);
244
+ $response = $this->_callTaxipostApi($params);
245
+
246
+ return $response->getBody();
247
+ }
248
+
249
+
250
+ /**
251
+ * @return string
252
+ */
253
+ protected function _getCurrentLanguage($language = false){
254
+
255
+ if(!$language) {
256
+ $language = strtolower(substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2));
257
+ }
258
+
259
+ if($language != "nl" && $language != "fr"){
260
+ $language = "fr";
261
+ }
262
+
263
+ return $language;
264
+ }
265
+ }
app/code/community/Bpost/ShM/Model/Api/Abstract.php ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ class Bpost_ShM_Model_Api_Abstract extends Mage_Core_Model_Abstract
11
+ {
12
+ const API_PATH_PREFIX = '/services/shm';
13
+ const API_URI_TAXIPOST_BASE = "http://taxipost.geo6.be";
14
+ const API_TAXIPOST_APPID = "A001";
15
+ const API_TAXIPOST_PARTNER = "999999";
16
+
17
+ protected $_apiUriBase;
18
+ protected $_accountId;
19
+ protected $_passphrase;
20
+ protected $_initialized = false;
21
+ protected $_bpostConfigHelper;
22
+ protected $_path = "";
23
+
24
+ /**
25
+ * Http client that is curently used.
26
+ *
27
+ * @var Zend_Http_Client
28
+ * @access protected
29
+ */
30
+ protected $_httpClient;
31
+
32
+ /**
33
+ * Authorization key
34
+ *
35
+ * @var string
36
+ * @access protected
37
+ */
38
+ protected $_authorization;
39
+
40
+
41
+ //constructor
42
+ public function __construct($initialize = false){
43
+
44
+ //first we set the helper as variable
45
+ //easier to access it
46
+ $this->_bpostConfigHelper = Mage::helper("bpost_shm/system_config");
47
+
48
+ //check if we need to initialize immediately
49
+ if($initialize){
50
+ $this->initialize();
51
+ }
52
+ }
53
+
54
+
55
+ //we set the api domain, account id and passphrase
56
+ public function initialize(){
57
+ $configHelper = Mage::helper("bpost_shm/system_config");
58
+
59
+ $this->_apiUriBase = $configHelper->getBpostShippingConfig("api_url");
60
+ $this->_accountId = $this->_bpostConfigHelper->getBpostShippingConfig("accountid");
61
+ $this->_passphrase = $this->_bpostConfigHelper->getBpostShippingConfig("passphrase");
62
+ $this->_authorization = base64_encode($this->_accountId . ':' . $this->_passphrase);
63
+ $this->_initialized = true;
64
+ }
65
+
66
+ /**
67
+ * @return bool
68
+ * function checks if the current object is initialized or not
69
+ */
70
+ public function getIsInitialized(){
71
+ if($this->_initialized){
72
+ return true;
73
+ }
74
+
75
+ return false;
76
+ }
77
+
78
+ /**
79
+ * Returns a REST client we can use for connecting to the webservice.
80
+ * @param array $headers
81
+ *
82
+ * @return Zend_Rest_Client
83
+ */
84
+ protected function _getRestClient($headers = null){
85
+ try{
86
+ //first make sure the current model is initialized
87
+ if(!$this->getIsInitialized()){
88
+ Mage::throwException('Please initialize your API model first by calling the initialize() function.');
89
+ }
90
+
91
+ $restClient = new Zend_Rest_Client($this->_apiUriBase);
92
+ $this->_httpClient = new Zend_Http_Client($this->_apiUriBase, array('useragent' => 'Magento, with bpost Shipping Manager module.'));
93
+ $this->_httpClient->setHeaders('Authorization', 'Basic ' . $this->_authorization);
94
+
95
+ if ($headers) {
96
+ $this->_httpClient->setHeaders($headers);
97
+ }
98
+
99
+ $restClient->setHttpClient($this->_httpClient);
100
+ return $restClient;
101
+ }catch(Exception $e){
102
+ Mage::helper("bpost_shm")->ApiLog($e->getMessage(), Zend_Log::ERR);
103
+ }
104
+ }
105
+
106
+
107
+ /**
108
+ * Returns a Http client we can use for connecting to the taxipost webservice.
109
+ * @param array $headers
110
+ *
111
+ * @return Zend_Http_Client
112
+ */
113
+ protected function _getTaxipostHttpClient($urlExtension = false){
114
+ try{
115
+ $url = self::API_URI_TAXIPOST_BASE;
116
+
117
+ if($urlExtension){
118
+ $url .= DS.$urlExtension;
119
+ }
120
+
121
+ $httpClient = new Zend_Http_Client($url, array('useragent' => 'Magento, with bpost Shipping Manager module.'));
122
+
123
+ return $httpClient;
124
+ }catch(Exception $e){
125
+ Mage::helper("bpost_shm")->ApiLog($e->getMessage(), Zend_Log::ERR);
126
+ }
127
+ }
128
+
129
+
130
+ /**
131
+ * @param $path
132
+ * @param $headers
133
+ * function sends request
134
+ */
135
+ protected function _call($path, $headers, $errorHandlingData = array(), $action = "get", $document = null){
136
+ $bpostHelper = Mage::helper("bpost_shm");
137
+ $path = self::API_PATH_PREFIX.DS.$path;
138
+ $restClient = $this->_getRestClient($headers);
139
+
140
+ $bpostHelper->ApiLog("HEADERS:", Zend_Log::DEBUG, false);
141
+ $bpostHelper->ApiLog("\n".implode("\n", $headers), Zend_Log::DEBUG, false);
142
+
143
+ $bpostHelper->ApiLog("PATH:", Zend_Log::DEBUG,false);
144
+ $bpostHelper->ApiLog($path, Zend_Log::DEBUG, false);
145
+
146
+
147
+ if($restClient){
148
+ if($action === "get"){
149
+ $response = $restClient->restGet($path);
150
+ }else{
151
+ $data = trim($document->saveXml());
152
+ $bpostHelper->ApiLog("DATA:", Zend_Log::DEBUG, false);
153
+ $bpostHelper->ApiLog($data, Zend_Log::DEBUG, false);
154
+
155
+ $httpClient = $restClient->getHttpClient();
156
+ $httpClient->setRawData($data, 'text/xml');
157
+ $httpClient->getUri()->setPath($path);
158
+
159
+ $response = $httpClient->request('POST');
160
+ }
161
+
162
+ try{
163
+ $bpostHelper->ApiLog("RESPONSE:", Zend_Log::DEBUG, false);
164
+ $bpostHelper->ApiLog($response, Zend_Log::DEBUG, false);
165
+
166
+ $this->_checkApiResponse($path, $response);
167
+
168
+ return $response;
169
+ }catch (Exception $e){
170
+ $errorMessage = $e->getMessage();
171
+
172
+ //we first check if we need to do something with this error
173
+ $this->_errorHandling($errorHandlingData, $errorMessage);
174
+
175
+ $bpostHelper->ApiLog("ERROR:", Zend_Log::ERR, false);
176
+ $bpostHelper->ApiLog($errorMessage, Zend_Log::ERR);
177
+ return false;
178
+ }
179
+ }
180
+ }
181
+
182
+
183
+ /**
184
+ * @param $params
185
+ * function calls the taxipost api (for GE06 calls)
186
+ */
187
+ protected function _callTaxipostApi($params){
188
+ $urlExtension = "Locator";
189
+ $params["Partner"] = self::API_TAXIPOST_PARTNER;
190
+ $params["AppId"] = self::API_TAXIPOST_APPID;
191
+
192
+ $httpClient = $this->_getTaxipostHttpClient($urlExtension);
193
+ $httpClient->setParameterGet($params);
194
+ $response = $httpClient->request('GET');
195
+
196
+ try{
197
+ $this->_checkApiResponse($httpClient->getLastRequest(), $response);
198
+
199
+ return $response;
200
+ }catch (Exception $e){
201
+ $errorMessage = $e->getMessage();
202
+
203
+ Mage::helper("bpost_shm")->ApiLog($errorMessage, Zend_Log::ERR);
204
+ return false;
205
+ }
206
+ }
207
+
208
+
209
+ //function checks if we need to do something with this error
210
+ //for example sending an email
211
+ protected function _errorHandling($errorHandlingData, $errorMessage){
212
+ $configHelper = Mage::helper("bpost_shm/system_config");
213
+
214
+ if(!empty($errorHandlingData) && isset($errorHandlingData["request_name"])){
215
+
216
+ switch($errorHandlingData["request_name"]){
217
+ case "createOrder":
218
+ //only send error email if 'use Magento to manage labels' is false
219
+ $manageLabelsWithMagento = $configHelper->getBpostShippingConfig("manage_labels_with_magento");
220
+
221
+ if(!$manageLabelsWithMagento){
222
+ //require email template, add error message, and send it to the shopmanager
223
+ $receiver = Mage::getStoreConfig('trans_email/ident_general/email');
224
+ $receiverName = Mage::getStoreConfig('trans_email/ident_general/name');
225
+
226
+ if($receiver && $receiver != ""){
227
+ $emailTemplate = Mage::getModel('core/email_template')->loadDefault('bpost_shm_errorhandling_create_order_email_template');
228
+
229
+ //Create an array of email variables
230
+ $emailVars = array();
231
+ $orderId = $errorHandlingData["order_id"];
232
+
233
+ $emailVars["order_id"] = $orderId;
234
+ $emailVars["receiver_name"] = " ".$receiverName;
235
+ $emailVars["error_message"] = $errorMessage;
236
+
237
+ $emailTemplate->setTemplateSubject(Mage::helper('bpost_shm')->__('Error creating bpost order'));
238
+ $emailTemplate->setSenderName("Magento - bpost shipping manager");
239
+
240
+ //send mail to yourself from, to
241
+ $emailTemplate->setSenderEmail($receiver);
242
+
243
+ if($emailTemplate->send(array($receiver), null, $emailVars)){
244
+ Mage::helper("bpost_shm")->ApiLog("Error email sent", Zend_Log::DEBUG);
245
+ }
246
+ }
247
+ }
248
+ break;
249
+ }
250
+ }
251
+ }
252
+
253
+
254
+ /**
255
+ * @param Zend_Http_Response $response
256
+ * function checks response for errors
257
+ */
258
+ protected static function _checkApiResponse($path = "", Zend_Http_Response $response){
259
+ if ($response->isError()) {
260
+ if ($response->getStatus() == 401) {
261
+ Mage::throwException('401 Unauthorized: the account id or/and pass-phrase are not set correctly.');
262
+ }
263
+
264
+ Mage::throwException(sprintf('Request path: %s - Invalid response status code (HTTP/%s %s %s) - response body: %s', $path, $response->getVersion(), $response->getStatus(), $response->getMessage(), $response->getBody()));
265
+ }
266
+ }
267
+ }
app/code/community/Bpost/ShM/Model/Api/Domcreator.php ADDED
@@ -0,0 +1,697 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Bpost_ShM_Model_Api_Domcreator extends Bpost_ShM_Model_Api_Abstract
4
+ {
5
+ protected $_xmlnsValue = "http://schema.post.be/shm/deepintegration/v3/national";
6
+ protected $_xmlnsCommonValue = "http://schema.post.be/shm/deepintegration/v3/common";
7
+ protected $_xmlnsTnsValue = "http://schema.post.be/shm/deepintegration/v3/";
8
+ protected $_xmlnsInternationalValue = "http://schema.post.be/shm/deepintegration/v3/international";
9
+ protected $_xmlnsXsiValue = "http://www.w3.org/2001/XMLSchema-instance";
10
+ protected $_xsiSchemaLocationValue = "http://schema.post.be/shm/deepintegration/v3/";
11
+
12
+ protected $_shippingAddress;
13
+ protected $_billingAddress;
14
+
15
+ /**
16
+ * @param Mage_Sales_Model_Order $order
17
+ * function builds the necessary DOM document and returns it
18
+ * this result will be used in the API calls as post data
19
+ */
20
+ public function getCreateOrderDomDocument($order, $returnOrder = false){
21
+ //initialize helper
22
+ $configHelper = Mage::helper("bpost_shm/system_config");
23
+ $bpostHelper = Mage::helper("bpost_shm");
24
+ $shippingMethod = $order->getShippingMethod();
25
+
26
+ //get sender
27
+ $senderData = new Varien_Object();
28
+ $senderData->setBpostName($configHelper->getBpostShippingConfig("sender_name"));
29
+ $senderData->setBpostCompany($configHelper->getBpostShippingConfig("sender_company"));
30
+ $senderData->setBpostStreet($configHelper->getBpostShippingConfig("sender_streetname"));
31
+ $senderData->setBpostHouseNumber($configHelper->getBpostShippingConfig("sender_streetnumber"));
32
+ $senderData->setBoxNumber($configHelper->getBpostShippingConfig("sender_boxnumber"));
33
+ $senderData->setPostcode($configHelper->getBpostShippingConfig("sender_postal_code"));
34
+ $senderData->setCity($configHelper->getBpostShippingConfig("sender_city"));
35
+ $senderData->setCountryId($configHelper->getBpostShippingConfig("sender_country"));
36
+ $senderData->setEmail($configHelper->getBpostShippingConfig("sender_email"));
37
+ $senderData->setTelephone($configHelper->getBpostShippingConfig("sender_phonenumber"));
38
+
39
+ //get receiver
40
+ $this->_shippingAddress = $order->getShippingAddress();
41
+ $this->_shippingAddress = $bpostHelper->formatAddress($this->_shippingAddress);
42
+ $this->_billingAddress = $order->getBillingAddress();
43
+
44
+ //if return order, we switch the sender and receiver data
45
+ if($returnOrder){
46
+ $tmpShippingAddress = $this->_shippingAddress;
47
+ $this->_shippingAddress = $senderData;
48
+ $senderData = $tmpShippingAddress;
49
+ $senderData->setBpostName($this->_billingAddress->getFirstname()." ".$this->_billingAddress->getLastname());
50
+
51
+ if($shippingMethod != "bpostshm_bpost_international"){
52
+ //we force shipping to 'bpostshm_bpost_homedelivery' method because we are creating a return order
53
+ $shippingMethod = "bpostshm_bpost_homedelivery";
54
+ }
55
+ }
56
+
57
+ $document = new DOMDocument('1.0','UTF-8');
58
+ $document->formatOutput = true;
59
+ $orderElement = $document->createElement('tns:order');
60
+
61
+ //we add the extra attributes to the order element
62
+ $xmlnsAttribute = $document->createAttribute("xmlns");
63
+ $xmlnsAttribute->value = $this->_xmlnsValue;
64
+
65
+ $xmlnsCommonAttribute = $document->createAttribute("xmlns:common");
66
+ $xmlnsCommonAttribute->value = $this->_xmlnsCommonValue;
67
+
68
+ $xmlnsTnsAttribute = $document->createAttribute("xmlns:tns");
69
+ $xmlnsTnsAttribute->value = $this->_xmlnsTnsValue;
70
+
71
+ $xmlnsInternationalAttribute = $document->createAttribute("xmlns:international");
72
+ $xmlnsInternationalAttribute->value = $this->_xmlnsInternationalValue;
73
+
74
+ $xmlnsXsiAttribute = $document->createAttribute("xmlns:xsi");
75
+ $xmlnsXsiAttribute->value = $this->_xmlnsXsiValue;
76
+
77
+ $xsiSchemaLocationValue = $document->createAttribute("xsi:schemaLocation");
78
+ $xsiSchemaLocationValue->value = $this->_xsiSchemaLocationValue;
79
+
80
+ $orderElement->appendChild($xmlnsAttribute);
81
+ $orderElement->appendChild($xmlnsCommonAttribute);
82
+ $orderElement->appendChild($xmlnsTnsAttribute);
83
+ $orderElement->appendChild($xmlnsInternationalAttribute);
84
+ $orderElement->appendChild($xmlnsXsiAttribute);
85
+ $orderElement->appendChild($xsiSchemaLocationValue);
86
+ //end adding order attributes
87
+
88
+ $document->appendChild($orderElement);
89
+
90
+ //add order elements
91
+ $accountId = $document->createElement('tns:accountId');
92
+ $accountId->appendChild($document->createTextNode($this->_accountId));
93
+ $orderElement->appendChild($accountId);
94
+
95
+ $reference = $document->createElement('tns:reference');
96
+ $referenceId = $order->getIncrementId();
97
+
98
+ $items = $order->getAllItems();
99
+ $reference->appendChild($document->createTextNode($referenceId));
100
+ $orderElement->appendChild($reference);
101
+
102
+ //calculate weight
103
+ $totalShipmentsWeight = $bpostHelper->processShipmentsWeight($order);
104
+
105
+ //we add all order items to the document
106
+ foreach ($items as $item) {
107
+ if ($item->getParentItem()) {
108
+ continue;
109
+ }
110
+
111
+ $nbOfItems = $document->createElement('tns:nbOfItems');
112
+ $nbOfItems->appendChild($document->createTextNode((int)$item->getQtyOrdered()));
113
+
114
+ $text = $document->createElement('tns:text');
115
+ $text->appendChild($document->createTextNode($item->getName()));
116
+
117
+ $orderLine = $document->createElement('tns:orderLine');
118
+ $orderLine->appendChild($text);
119
+ $orderLine->appendChild($nbOfItems);
120
+ $orderElement->appendChild($orderLine);
121
+ }
122
+
123
+ $weightInGrams = round($totalShipmentsWeight);
124
+
125
+ if(!$weightInGrams){
126
+ $weightInGrams = 1;
127
+ }
128
+
129
+ if(($shippingMethod == "bpostshm_bpost_parcellocker" || $shippingMethod == "bpostshm_bpost_international") && $weightInGrams < 10){
130
+ $weightInGrams = 10;
131
+ }
132
+ //end weight
133
+
134
+ $senderName = $document->createElement('common:name');
135
+ $senderName->appendChild($document->createTextNode($senderData->getBpostName()));
136
+
137
+ $senderCompany = $document->createElement('common:company');
138
+ $senderCompany->appendChild($document->createTextNode($senderData->getBpostCompany()));
139
+ //sender address fields here
140
+ $addressStreetName = $document->createElement('common:streetName');
141
+ $addressStreetName->appendChild($document->createTextNode($senderData->getBpostStreet()));
142
+
143
+ $addressNumber = $document->createElement('common:number');
144
+ $addressNumber->appendChild($document->createTextNode($senderData->getBpostHouseNumber()));
145
+
146
+ //only add element if available
147
+ $boxNumber = $configHelper->getBpostShippingConfig($senderData->getBoxNumber());
148
+
149
+ if($boxNumber && $boxNumber != ''){
150
+ $addressBox = $document->createElement('common:box');
151
+ $addressBox->appendChild($document->createTextNode($boxNumber));
152
+ }
153
+
154
+ $addressPostalCode = $document->createElement('common:postalCode');
155
+ $addressPostalCode->appendChild($document->createTextNode($senderData->getPostcode()));
156
+
157
+ $addressLocality = $document->createElement('common:locality');
158
+ $addressLocality->appendChild($document->createTextNode($senderData->getCity()));
159
+
160
+ $addressCountryCode = $document->createElement('common:countryCode');
161
+ $addressCountryCode->appendChild($document->createTextNode($senderData->getCountryId()));
162
+ //end sender address fields
163
+
164
+ //add fields to address
165
+ $senderAddress = $document->createElement('common:address');
166
+ $senderAddress->appendChild($addressStreetName);
167
+ $senderAddress->appendChild($addressNumber);
168
+
169
+ if(isset($addressBox)){
170
+ $senderAddress->appendChild($addressBox);
171
+ }
172
+
173
+ $senderAddress->appendChild($addressPostalCode);
174
+ $senderAddress->appendChild($addressLocality);
175
+ $senderAddress->appendChild($addressCountryCode);
176
+
177
+ $senderEmail = $document->createElement('common:emailAddress');
178
+ $senderEmail->appendChild($document->createTextNode($senderData->getEmail()));
179
+
180
+ $senderPhoneNumber = $document->createElement('common:phoneNumber');
181
+ $senderPhoneNumber->appendChild($document->createTextNode($senderData->getTelephone()));
182
+
183
+ //add all sender info to the sender element
184
+ $sender = $document->createElement('tns:sender');
185
+ $sender->appendChild($senderName);
186
+ $sender->appendChild($senderCompany);
187
+ $sender->appendChild($senderAddress);
188
+ $sender->appendChild($senderEmail);
189
+ $sender->appendChild($senderPhoneNumber);
190
+
191
+ //we create the box element
192
+ $box = $document->createElement('tns:box');
193
+ $box->appendChild($sender);
194
+
195
+ //add the national or international box element tags
196
+ if($shippingMethod != "bpostshm_bpost_international"){
197
+ $nationalBoxElements = $this->_getNationalBoxElements($document, $order, $returnOrder, $weightInGrams, $shippingMethod);
198
+ $box->appendChild($nationalBoxElements);
199
+ }else{
200
+ $internationalBoxElements = $this->_getInternationalBoxElements($document, $order, $returnOrder, $weightInGrams);
201
+ $box->appendChild($internationalBoxElements);
202
+ }
203
+
204
+ //we do the same for additionalCustomerReference
205
+ //Free text. If not submitted, it will indicate the channel used for creating this order. Best used by integrators to indicate the origin of the order.
206
+
207
+ $additionalCustomerReference = $document->createElement('tns:additionalCustomerReference');
208
+ $additionalCustomerReference->appendChild($document->createTextNode("Magento_".Mage::getVersion()));
209
+ $box->appendChild($additionalCustomerReference);
210
+
211
+ //finally we add the box element to the order element
212
+ $orderElement->appendChild($box);
213
+
214
+ //we save the xml so we can check the file
215
+ return $document;
216
+ }
217
+
218
+ //function adds the national box element tags based on the shipping method
219
+ protected function _getNationalBoxElements(DOMDocument $document, $order, $returnOrder, $weightInGrams, $shippingMethod){
220
+ $bpostHelper = Mage::helper("bpost_shm");
221
+ $configHelper = Mage::helper("bpost_shm/system_config");
222
+ $nationalBox = $document->createElement('tns:nationalBox');
223
+ $manageLabelsWithMagento = $configHelper->getBpostShippingConfig("manage_labels_with_magento");
224
+
225
+ $requestedDeliveryDate = false;
226
+ $dropDate = new DateTime($order->getBpostDropDate());
227
+ $currentDate = new DateTime();
228
+
229
+ if($dropDate && $dropDate > $currentDate) {
230
+ $requestedDeliveryDate = $document->createElement('requestedDeliveryDate');
231
+ $requestedDeliveryDate->appendChild($document->createTextNode($order->getBpostDropDate()));
232
+ }
233
+
234
+ //add product
235
+ $product = $document->createElement('product');
236
+
237
+ //add options
238
+ $options = $document->createElement('options');
239
+
240
+ //add weight
241
+ $weight = $document->createElement('weight');
242
+ $weight->appendChild($document->createTextNode($weightInGrams));
243
+
244
+ //add address variables
245
+ $streetName = $document->createElement('common:streetName');
246
+ $streetNumber = $document->createElement('common:number');
247
+ $streetPostalCode = $document->createElement('common:postalCode');
248
+ $locality = $document->createElement('common:locality');
249
+ $countryCode = $document->createElement('common:countryCode');
250
+
251
+ //add receiver info
252
+ $receiverName = $document->createElement('receiverName');
253
+ $receiverCompany = $document->createElement('receiverCompany');
254
+ $receiverCompany->appendChild($document->createTextNode($this->_shippingAddress->getCompany()));
255
+
256
+ //we use the receivername from billing address instead of shipping address
257
+ //this way we have the customer name and not the pickup point name
258
+ $receiverName->appendChild($document->createTextNode($this->_billingAddress->getFirstname()." ".$this->_billingAddress->getLastname()));
259
+
260
+ switch($shippingMethod){
261
+ case "bpostshm_bpost_homedelivery":
262
+ if(!$returnOrder){
263
+ $product->appendChild($document->createTextNode("bpack 24h Pro"));
264
+
265
+ //then get config the option settings
266
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_homedelivery", "second_presentation", "automaticSecondPresentation");
267
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_homedelivery", "insurance", "insured");
268
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_homedelivery", "signature", "signed");
269
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_homedelivery", "saturday_delivery", "saturdayDelivery");
270
+
271
+ }else{
272
+ $product->appendChild($document->createTextNode("bpack Easy Retour"));
273
+ }
274
+
275
+ //add receiver info
276
+ $receiverName = $document->createElement('common:name');
277
+ $receiverName->appendChild($document->createTextNode($this->_shippingAddress->getBpostName()));
278
+
279
+ $receiverCompany = $document->createElement('common:company');
280
+ $receiverCompany->appendChild($document->createTextNode($this->_shippingAddress->getBpostCompany()));
281
+
282
+ $receiverEmailAddress = $document->createElement('common:emailAddress');
283
+ $receiverEmailAddress->appendChild($document->createTextNode($this->_shippingAddress->getEmail()));
284
+
285
+ $receiverPhoneNumber = $document->createElement('common:phoneNumber');
286
+ $receiverPhoneNumber->appendChild($document->createTextNode($this->_shippingAddress->getTelephone()));
287
+
288
+ //we add the receiver address data
289
+ $streetName->appendChild($document->createTextNode($this->_shippingAddress->getBpostStreet()));
290
+ $streetNumber->appendChild($document->createTextNode($this->_shippingAddress->getBpostHouseNumber()));
291
+
292
+ $streetPostalCode->appendChild($document->createTextNode($this->_shippingAddress->getPostcode()));
293
+ $locality->appendChild($document->createTextNode($this->_shippingAddress->getCity()));
294
+ $countryCode->appendChild($document->createTextNode($this->_shippingAddress->getCountryId()));
295
+
296
+ $receiverAddress = $document->createElement('common:address');
297
+ $receiverAddress->appendChild($streetName);
298
+ $receiverAddress->appendChild($streetNumber);
299
+
300
+ //only add element if available
301
+ if($this->_shippingAddress->getBoxNumber()){
302
+ $streetBox = $document->createElement('common:box');
303
+ $streetBox->appendChild($document->createTextNode($this->_shippingAddress->getBoxNumber()));
304
+ $receiverAddress->appendChild($streetBox);
305
+ }
306
+
307
+ $receiverAddress->appendChild($streetPostalCode);
308
+ $receiverAddress->appendChild($locality);
309
+ $receiverAddress->appendChild($countryCode);
310
+
311
+ $receiver = $document->createElement('receiver');
312
+ $receiver->appendChild($receiverName);
313
+ $receiver->appendChild($receiverCompany);
314
+ $receiver->appendChild($receiverAddress);
315
+ $receiver->appendChild($receiverEmailAddress);
316
+ $receiver->appendChild($receiverPhoneNumber);
317
+ //end receiver
318
+
319
+ $atHome = $document->createElement('atHome');
320
+ $atHome->appendChild($product);
321
+
322
+ if($options->hasChildNodes()){
323
+ $atHome->appendChild($options);
324
+ }
325
+
326
+ $atHome->appendChild($weight);
327
+ $atHome->appendChild($receiver);
328
+
329
+ if($requestedDeliveryDate){
330
+ $atHome->appendChild($requestedDeliveryDate);
331
+ }
332
+
333
+ $nationalBox->appendChild($atHome);
334
+ break;
335
+
336
+ case "bpostshm_bpost_pickuppoint":
337
+ if(!$order->getBpostPickuplocationId()){
338
+ //only throw error in backend
339
+ if($manageLabelsWithMagento){
340
+ Mage::throwException("No pickup location order data found.");
341
+ }
342
+ }
343
+
344
+ $product->appendChild($document->createTextNode("bpack@bpost"));
345
+
346
+ //add the notification options
347
+ //check if bpost notification sms or mail isset
348
+ if($order->getBpostNotificationSms() || $order->getBpostNotificationEmail()){
349
+ if($order->getBpostNotificationSms()){
350
+ $options->appendChild($this->_addNotificationMessageOption($document, $order, "keepMeInformed", "sms"));
351
+ }else{
352
+ $options->appendChild($this->_addNotificationMessageOption($document, $order, "keepMeInformed"));
353
+ }
354
+ }
355
+
356
+ //then get the config option settings
357
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_pickuppoint", "insurance", "insured");
358
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_pickuppoint", "saturday_delivery", "saturdayDelivery");
359
+
360
+ $formattedShippingAddress = $bpostHelper->formatShippingAddress($this->_shippingAddress);
361
+
362
+ $pugoId = $document->createElement('pugoId');
363
+ $pugoId->appendChild($document->createTextNode($order->getBpostPickuplocationId()));
364
+
365
+ $pugoName = $document->createElement('pugoName');
366
+ $pugoName->appendChild($document->createTextNode($this->_shippingAddress->getLastname()));
367
+
368
+ //Address tags
369
+ $streetName->appendChild($document->createTextNode($formattedShippingAddress["street"]));
370
+ $streetNumber->appendChild($document->createTextNode($formattedShippingAddress["number"]));
371
+
372
+ $streetPostalCode->appendChild($document->createTextNode($formattedShippingAddress["postcode"]));
373
+ $locality->appendChild($document->createTextNode($formattedShippingAddress["city"]));
374
+ $countryCode->appendChild($document->createTextNode($this->_shippingAddress->getCountryId()));
375
+
376
+ $pugoAddress = $document->createElement('pugoAddress');
377
+ $pugoAddress->appendChild($streetName);
378
+ $pugoAddress->appendChild($streetNumber);
379
+ $pugoAddress->appendChild($streetPostalCode);
380
+ $pugoAddress->appendChild($locality);
381
+ $pugoAddress->appendChild($countryCode);
382
+ //end address tags
383
+
384
+ $atBpost = $document->createElement('atBpost');
385
+ $atBpost->appendChild($product);
386
+
387
+ if($options->hasChildNodes()){
388
+ $atBpost->appendChild($options);
389
+ }
390
+
391
+ $atBpost->appendChild($weight);
392
+ $atBpost->appendChild($pugoId);
393
+ $atBpost->appendChild($pugoName);
394
+ $atBpost->appendChild($pugoAddress);
395
+ $atBpost->appendChild($receiverName);
396
+ $atBpost->appendChild($receiverCompany);
397
+
398
+ if($requestedDeliveryDate) {
399
+ $atBpost->appendChild($requestedDeliveryDate);
400
+ }
401
+
402
+ $nationalBox->appendChild($atBpost);
403
+
404
+ break;
405
+
406
+ case "bpostshm_bpost_parcellocker":
407
+
408
+ if(!$order->getBpostPickuplocationId()){
409
+ //only throw error in backend
410
+ if($manageLabelsWithMagento){
411
+ Mage::throwException("No parcel locker data found.");
412
+ }
413
+ }
414
+
415
+ $product->appendChild($document->createTextNode("bpack 24h Pro"));
416
+
417
+ //then get the config option settings
418
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_parcellocker", "insurance", "insured");
419
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_parcellocker", "saturday_delivery", "saturdayDelivery");
420
+
421
+ $formattedShippingAddress = $bpostHelper->formatShippingAddress($this->_shippingAddress);
422
+
423
+ $parcelsDepotId = $document->createElement('parcelsDepotId');
424
+ $parcelsDepotId->appendChild($document->createTextNode($order->getBpostPickuplocationId()));
425
+
426
+ $parcelsDepotName = $document->createElement('parcelsDepotName');
427
+ $parcelsDepotName->appendChild($document->createTextNode($this->_shippingAddress->getLastname()));
428
+
429
+ //Address tags
430
+ $streetName->appendChild($document->createTextNode($formattedShippingAddress["street"]));
431
+ $streetNumber->appendChild($document->createTextNode($formattedShippingAddress["number"]));
432
+
433
+ $streetPostalCode->appendChild($document->createTextNode($formattedShippingAddress["postcode"]));
434
+ $locality->appendChild($document->createTextNode($formattedShippingAddress["city"]));
435
+ $countryCode->appendChild($document->createTextNode($this->_shippingAddress->getCountryId()));
436
+
437
+ $parcelsDepotAddress = $document->createElement('parcelsDepotAddress');
438
+ $parcelsDepotAddress->appendChild($streetName);
439
+ $parcelsDepotAddress->appendChild($streetNumber);
440
+ $parcelsDepotAddress->appendChild($streetPostalCode);
441
+ $parcelsDepotAddress->appendChild($locality);
442
+ $parcelsDepotAddress->appendChild($countryCode);
443
+ //end address tags
444
+
445
+ //add unregistered element
446
+ $unregistered = $document->createElement('unregistered');
447
+
448
+ //message language
449
+ //we take the locale from the store where the order is placed from
450
+ $locale = $bpostHelper->getLocaleByOrder($order);
451
+ $messageLanguage = $document->createElement('language');
452
+ $messageLanguage->appendChild($document->createTextNode($locale));
453
+
454
+ $email = $document->createElement('emailAddress');
455
+ $email->appendChild($document->createTextNode($this->_shippingAddress->getEmail()));
456
+
457
+ //Indication if this user has reduced mobility Y/N
458
+ //comes from frontend
459
+ $reducedMobilityZone = $document->createElement('reducedMobilityZone');
460
+ $unregistered->appendChild($messageLanguage);
461
+
462
+ if($order->getBpostNotificationSms()){
463
+ $mobilePhone = $document->createElement('mobilePhone');
464
+ $mobilePhone->appendChild($document->createTextNode($this->_shippingAddress->getTelephone()));
465
+ $unregistered->appendChild($mobilePhone);
466
+ }
467
+
468
+ $unregistered->appendChild($email);
469
+
470
+ if($order->getBpostReducedMobility()){
471
+ $unregistered->appendChild($reducedMobilityZone);
472
+ }
473
+ //end unregistered element
474
+
475
+ $at247 = $document->createElement('at24-7');
476
+ $at247->appendChild($product);
477
+
478
+ if($options->hasChildNodes()){
479
+ $at247->appendChild($options);
480
+ }
481
+
482
+ $at247->appendChild($weight);
483
+ $at247->appendChild($parcelsDepotId);
484
+ $at247->appendChild($parcelsDepotName);
485
+ $at247->appendChild($parcelsDepotAddress);
486
+
487
+ //add unregistered element
488
+ $at247->appendChild($unregistered);
489
+ $at247->appendChild($receiverName);
490
+ $at247->appendChild($receiverCompany);
491
+
492
+ $nationalBox->appendChild($at247);
493
+ break;
494
+ }
495
+
496
+ return $nationalBox;
497
+ }
498
+
499
+ //function adds the international box element tags
500
+ protected function _getInternationalBoxElements(DOMDocument $document, $order, $returnOrder, $weightInGrams){
501
+ $configHelper = Mage::helper("bpost_shm/system_config");
502
+ $storeId = $order->getStoreId();
503
+
504
+ //start creating xml
505
+ $internationalBox = $document->createElement('tns:internationalBox');
506
+ $internationalWrapper = $document->createElement('international:international');
507
+
508
+ if(!$returnOrder){
509
+ $productType = $configHelper->getBpostCarriersConfig("product", "bpost_international", $storeId);
510
+ ($productType == 0 ? $productType = "bpack World Business" : $productType = "bpack World Express Pro");
511
+ }else{
512
+ $productType = "bpack World Easy Return";
513
+ }
514
+
515
+ //add product
516
+ $internationalProduct = $document->createElement('international:product');
517
+ $internationalProduct->appendChild($document->createTextNode($productType));
518
+
519
+ //add options
520
+ $options = $document->createElement('international:options');
521
+
522
+ //not possible yet, maybe in feature
523
+ if($productType == "bpack Europe Business"){
524
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_international", "second_presentation", "automaticSecondPresentation");
525
+ }
526
+
527
+ $options = $this->_checkIfOptionIsValid($document, $options, $order, "bpost_international", "insurance", "insured");
528
+
529
+ //add receiver info
530
+ $receiverName = $document->createElement('common:name');
531
+ $receiverName->appendChild($document->createTextNode($this->_shippingAddress->getBpostName()));
532
+
533
+ $receiverCompany = $document->createElement('common:company');
534
+ $receiverCompany->appendChild($document->createTextNode($this->_shippingAddress->getBpostCompany()));
535
+
536
+ $receiverEmailAddress = $document->createElement('common:emailAddress');
537
+ $receiverEmailAddress->appendChild($document->createTextNode($this->_shippingAddress->getEmail()));
538
+
539
+ $receiverPhoneNumber = $document->createElement('common:phoneNumber');
540
+ $receiverPhoneNumber->appendChild($document->createTextNode($this->_shippingAddress->getTelephone()));
541
+
542
+ //add address info
543
+ $streetName = $document->createElement('common:streetName');
544
+ $streetName->appendChild($document->createTextNode($this->_shippingAddress->getBpostStreet()));
545
+
546
+ $streetNumber = $document->createElement('common:number');
547
+ $streetNumber->appendChild($document->createTextNode($this->_shippingAddress->getBpostHouseNumber()));
548
+
549
+ $streetPostalCode = $document->createElement('common:postalCode');
550
+ $streetPostalCode->appendChild($document->createTextNode($this->_shippingAddress->getPostcode()));
551
+
552
+ $locality = $document->createElement('common:locality');
553
+ $locality->appendChild($document->createTextNode($this->_shippingAddress->getCity()));
554
+
555
+ $countryCode = $document->createElement('common:countryCode');
556
+ $countryCode->appendChild($document->createTextNode($this->_shippingAddress->getCountryId()));
557
+
558
+ $receiverAddress = $document->createElement('common:address');
559
+ $receiverAddress->appendChild($streetName);
560
+ $receiverAddress->appendChild($streetNumber);
561
+
562
+ //only add element if available
563
+ if($this->_shippingAddress->getBoxNumber()){
564
+ $streetBox = $document->createElement('common:box');
565
+ $streetBox->appendChild($document->createTextNode($this->_shippingAddress->getBoxNumber()));
566
+ $receiverAddress->appendChild($streetBox);
567
+ }
568
+
569
+ $receiverAddress->appendChild($streetPostalCode);
570
+ $receiverAddress->appendChild($locality);
571
+ $receiverAddress->appendChild($countryCode);
572
+ //end address info
573
+
574
+ //add receiver
575
+ $receiver = $document->createElement('international:receiver');
576
+
577
+ $receiver->appendChild($receiverName);
578
+ $receiver->appendChild($receiverCompany);
579
+ $receiver->appendChild($receiverAddress);
580
+ $receiver->appendChild($receiverEmailAddress);
581
+ $receiver->appendChild($receiverPhoneNumber);
582
+
583
+ //create weight element
584
+ $weight = $document->createElement('international:parcelWeight');
585
+ $weight->appendChild($document->createTextNode($weightInGrams));
586
+
587
+ //create customsInfo element
588
+ $customsInfo = $document->createElement('international:customsInfo');
589
+
590
+ //create customsInfo child elements
591
+ $parcelValue = $document->createElement('international:parcelValue');
592
+ $parcelValue->appendChild($document->createTextNode(($order->getGrandTotal()*100)));
593
+
594
+ $contentDescription = $document->createElement('international:contentDescription');
595
+ $contentDescription->appendChild($document->createTextNode("no description"));
596
+
597
+ $shipmentType = $document->createElement('international:shipmentType');
598
+ $shipmentType->appendChild($document->createTextNode("OTHER"));
599
+
600
+ $parcelReturnInstructions = $document->createElement('international:parcelReturnInstructions');
601
+ $parcelReturnInstructions->appendChild($document->createTextNode("RTS"));
602
+
603
+ $privateAddress = $document->createElement('international:privateAddress');
604
+ $privateAddress->appendChild($document->createTextNode("false"));
605
+
606
+ $customsInfo->appendChild($parcelValue);
607
+ $customsInfo->appendChild($contentDescription);
608
+ $customsInfo->appendChild($shipmentType);
609
+ $customsInfo->appendChild($parcelReturnInstructions);
610
+ $customsInfo->appendChild($privateAddress);
611
+ //end customsInfo element
612
+
613
+ //add elements to the international wrapper
614
+ $internationalWrapper->appendChild($internationalProduct);
615
+
616
+ if($options->hasChildNodes()){
617
+ $internationalWrapper->appendChild($options);
618
+ }
619
+
620
+ $internationalWrapper->appendChild($receiver);
621
+ $internationalWrapper->appendChild($weight);
622
+ $internationalWrapper->appendChild($customsInfo);
623
+
624
+ $internationalBox->appendChild($internationalWrapper);
625
+ return $internationalBox;
626
+ }
627
+
628
+ /**
629
+ * function checks if the an option is active / valid
630
+ * and add it's if necessary
631
+ */
632
+ protected function _checkIfOptionIsValid(DOMDocument $document, $options, $order, $carrier, $configName, $bpostValue){
633
+ $helper = Mage::helper("bpost_shm/system_config");
634
+ $storeId = $order->getStoreId();
635
+ $option = $helper->getBpostCarriersConfig($configName, $carrier, $storeId);
636
+
637
+ if($bpostValue == "saturdayDelivery" && $order->getBpostDisableSaturdayDelivery()){
638
+ return $options;
639
+ }
640
+
641
+ if($option){
642
+ $optionFrom = $helper->getBpostCarriersConfig($configName."_from", $carrier, $storeId);
643
+ $addOption = false;
644
+
645
+ if($optionFrom && $optionFrom > 0){
646
+ if($order->getGrandTotal() >= $optionFrom){
647
+ $addOption = true;
648
+ }
649
+ }else{
650
+ $addOption = true;
651
+ }
652
+
653
+ if($addOption){
654
+ $option = $document->createElement("common:$bpostValue");
655
+
656
+ //check for insurance option
657
+ //if so, we need to add an extra child
658
+ if($bpostValue == "insured"){
659
+ $insuranceElement = $document->createElement("common:basicInsurance");
660
+ $option->appendChild($insuranceElement);
661
+ }
662
+
663
+ $options->appendChild($option);
664
+ }
665
+ }
666
+
667
+ return $options;
668
+ }
669
+
670
+ /**
671
+ * function adds a notification child element to the options element
672
+ */
673
+ protected function _addNotificationMessageOption(DOMDocument $document, $order, $notificationType, $communicationBy = "email"){
674
+ $bpostHelper = Mage::helper("bpost_shm");
675
+
676
+ $notificationElement = $document->createElement("common:$notificationType");
677
+ $language = $bpostHelper->getLocaleByOrder($order, true);
678
+
679
+ $shippingAddress = $order->getShippingAddress();
680
+
681
+ $languageAttribute = $document->createAttribute("language");
682
+ $languageAttribute->value = $language;
683
+ $notificationElement->appendChild($languageAttribute);
684
+
685
+ if($communicationBy === "email"){
686
+ $childElement = $document->createElement("common:emailAddress");
687
+ $childElement->appendChild($document->createTextNode($shippingAddress->getEmail()));
688
+ }else{
689
+ $childElement = $document->createElement("common:mobilePhone");
690
+ $childElement->appendChild($document->createTextNode($shippingAddress->getTelephone()));
691
+ }
692
+
693
+ $notificationElement->appendChild($childElement);
694
+
695
+ return $notificationElement;
696
+ }
697
+ }
app/code/community/Bpost/ShM/Model/Country.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Country
13
+ */
14
+ class Bpost_ShM_Model_Country extends Mage_Core_Model_Abstract
15
+ {
16
+ /**
17
+ * Initialise the model.
18
+ */
19
+ protected function _construct()
20
+ {
21
+ $this->_init("bpost_shm/country");
22
+ }
23
+ }
app/code/community/Bpost/ShM/Model/Holidays.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Holidays
13
+ */
14
+ class Bpost_ShM_Model_Holidays extends Mage_Core_Model_Abstract
15
+ {
16
+ /**
17
+ * Initialise the model.
18
+ */
19
+ protected function _construct()
20
+ {
21
+ $this->_init("bpost_shm/holidays");
22
+ }
23
+ }
app/code/community/Bpost/ShM/Model/Observer.php ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Observer
13
+ */
14
+ class Bpost_ShM_Model_Observer extends Varien_Event_Observer
15
+ {
16
+ /**
17
+ * @param $observer
18
+ * @return $this
19
+ */
20
+ public function core_block_abstract_to_html_after($observer)
21
+ {
22
+ $checkoutSession = Mage::getSingleton('checkout/session');
23
+ $quote = $checkoutSession->getQuote();
24
+
25
+ if ($observer->getBlock() instanceof Mage_Checkout_Block_Onepage_Shipping_Method_Available) {
26
+ $availablerates = $observer->getBlock()->getShippingRates();
27
+
28
+ if (array_key_exists("bpostshm", $availablerates)) {
29
+ //get HTML
30
+ $html = $observer->getTransport()->getHtml();
31
+
32
+ //add logo to carrier
33
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true);
34
+ $logo = $baseUrl . 'skin/frontend/base/default/images/bpost/bpost_sym_RGB72_S.png';
35
+ $html = str_replace('<dt>bpost</dt>', '<dt><img src="'.$logo.'" class="bpost-carrier-logo" />bpost</dt>', $html);
36
+ //if onestepcheckout dd's are used instead of dt's
37
+ $html = str_replace('<dd>bpost</dd>', '<dd><img src="'.$logo.'" class="bpost-carrier-logo" />bpost</dd>', $html);
38
+
39
+ //intercept html and append block
40
+ $html .= Mage::app()->getLayout()->createBlock("bpost_shm/carrier_bpost")->setQuote($quote)->setTemplate("bpost/shm/append_bpost_shippingmethod.phtml")->toHtml();
41
+ //set HTML
42
+ $observer->getTransport()->setHtml($html);
43
+ }
44
+ }
45
+
46
+ if ($observer->getBlock() instanceof Mage_Checkout_Block_Onepage_Payment_Methods) {
47
+ if (Mage::getSingleton('checkout/session')->getBpostReloadProgress()) {
48
+ $html = $observer->getTransport()->getHtml();
49
+ $html .= "<script>checkout.reloadProgressBlock('shipping');</script>";
50
+ $observer->getTransport()->setHtml($html);
51
+ Mage::getSingleton('checkout/session')->unsBpostReloadProgress();
52
+ }
53
+ }
54
+
55
+ return $this;
56
+ }
57
+
58
+ /**
59
+ * Observe shipping address and create alternative shipping address in the session. (we select only the necessary data to keep the object small)
60
+ *
61
+ * @param $observer
62
+ * @return $this
63
+ */
64
+ public function controller_action_postdispatch_checkout_onepage_saveAddress($observer)
65
+ {
66
+ $checkoutSession = Mage::getSingleton('checkout/session');
67
+ $shippingAddress = $checkoutSession->getQuote()->getShippingAddress();
68
+ if (((bool)$shippingAddress->getSameAsBilling() &&
69
+ $observer->getEvent()->getName() == "controller_action_postdispatch_checkout_onepage_saveBilling") ||
70
+ $observer->getEvent()->getName() == "controller_action_postdispatch_checkout_onepage_saveShipping") {
71
+
72
+ $bpostOriginalShippingAddress = new Varien_Object();
73
+ $street = $shippingAddress->getStreet(1);
74
+
75
+ if($shippingAddress->getStreet(2) && $shippingAddress->getStreet(2) != ""){
76
+ $street .= "\n" . $shippingAddress->getStreet(2);
77
+ }
78
+
79
+ $bpostOriginalShippingAddress
80
+ ->setFirstname($shippingAddress->getFirstname())
81
+ ->setLastname($shippingAddress->getLastname())
82
+ ->setCompany($shippingAddress->getCompany())
83
+ ->setStreet($street)
84
+ ->setCity($shippingAddress->getCity())
85
+ ->setRegion($shippingAddress->getRegion())
86
+ ->setPostcode($shippingAddress->getPostcode())
87
+ ->setCountryId($shippingAddress->getCountryId())
88
+ ->setTelephone($shippingAddress->getTelephone())
89
+ ->setFax($shippingAddress->getFax());
90
+
91
+ if($shippingAddress->getAddressId() != "" && $shippingAddress->hasAddressId()){
92
+ $bpostOriginalShippingAddress->setAddressId($shippingAddress->getAddressId());
93
+ }
94
+
95
+ $checkoutSession->setBpostOriginalShippingAddress($bpostOriginalShippingAddress);
96
+ }
97
+ return $this;
98
+ }
99
+
100
+ /**
101
+ * Reset saturday delivery option so rate calculation doesn't show saturday incl. shipping rates
102
+ *
103
+ * @param $observer
104
+ * @return $this
105
+ */
106
+ public function controller_action_predispatch_checkout_onepage_saveAddress($observer)
107
+ {
108
+ $checkoutSession = Mage::getSingleton('checkout/session');
109
+
110
+ //always reset the saturday delivery option so we don't see multiplied rates
111
+ $checkoutSession->getQuote()->setBpostDisableSaturdayDelivery(true);
112
+
113
+ return $this;
114
+ }
115
+
116
+ /**
117
+ * Change shipping address if needed, save previous shipping method, add progress bar reload flag.
118
+ *
119
+ * @param $observer
120
+ * @return $this
121
+ */
122
+ public function checkout_controller_onepage_save_shipping_method($observer)
123
+ {
124
+ //init all necessary data
125
+ $checkoutSession = Mage::getSingleton('checkout/session');
126
+ $quote = $checkoutSession->getQuote();
127
+ $address = $quote->getShippingAddress();
128
+
129
+ //get the bpost data
130
+ $params = Mage::app()->getRequest()->getPost();
131
+
132
+ //add notifications to quote
133
+ if($address->getShippingMethod() == "bpostshm_bpost_pickuppoint"){
134
+ if(isset($params["notification"])){
135
+ if($params["notification"] == "email"){
136
+ $quote->setBpostNotificationEmail($address->getEmail());
137
+ $quote->setBpostNotificationSms("");
138
+
139
+ }else{
140
+ $quote->setBpostNotificationSms($address->getTelephone());
141
+ $quote->setBpostNotificationEmail("");
142
+ }
143
+ }
144
+ }elseif($address->getShippingMethod() == "bpostshm_bpost_parcellocker"){
145
+ if(isset($params["parcel-notification"])){
146
+ $quote->setBpostNotificationSms($address->getTelephone());
147
+ }else{
148
+ $quote->setBpostNotificationSms("");
149
+ $quote->setBpostNotificationEmail("");
150
+ }
151
+
152
+ //check for reduced mobility
153
+ if(isset($params["reduced-mobility"])){
154
+ $quote->setBpostReducedMobility(true);
155
+ }else{
156
+ $quote->setBpostReducedMobility(false);
157
+ }
158
+ }
159
+
160
+ //set the delivery date in the quote
161
+ if(isset($params["bpost"]["deliverydate"])) {
162
+ if($address->getShippingMethod() != "bpostshm_bpost_international" && $params["bpost"]["deliverydate"] != ""){
163
+ $bpostHelper = Mage::helper("bpost_shm");
164
+
165
+ $deliveryDate = $params["bpost"]["deliverydate"];
166
+ $dropdate = $bpostHelper->getPrevDeliveryDate($deliveryDate);
167
+
168
+ $quote->setBpostDropDate($dropdate);
169
+ $quote->setBpostDeliveryDate($deliveryDate);
170
+ }
171
+ }
172
+
173
+ //if all necessary fields are filled in.
174
+ $validShippingMethods = array("bpostshm_bpost_pickuppoint", "bpostshm_bpost_parcellocker");
175
+
176
+ if (in_array($address->getShippingMethod(), $validShippingMethods) && $params["bpost"]["id"] && $params["bpost"]["name"] && $params["bpost"]["street"]
177
+ && $params["bpost"]["city"] && $params["bpost"]["postcode"]
178
+ ) {
179
+ //set it in the quote
180
+ $quote->setBpostPickuplocationId($params["bpost"]["id"]);
181
+
182
+ if($address->getShippingMethod() == "bpostshm_bpost_pickuppoint") {
183
+ $firstname = "bpost pick-up point: ";
184
+ } elseif($address->getShippingMethod() == "bpostshm_bpost_parcellocker") {
185
+ $firstname = "bpost parcel locker: ";
186
+ }
187
+
188
+ //now set the current address to the bpost-spot
189
+ $address->unsetAddressId()
190
+ ->setSaveInAddressBook(0)
191
+ ->setFirstname($firstname)
192
+ ->setLastname($params["bpost"]["name"])
193
+ ->setStreet($params["bpost"]["street"])
194
+ ->setCity($params["bpost"]["city"])
195
+ ->setPostcode($params["bpost"]["postcode"])
196
+ ->save();
197
+ } else {
198
+ //revert to original shipping address if no pickup point or parcel locker is chosen
199
+ if($checkoutSession->hasBpostOriginalShippingAddress()) {
200
+ $originalAddress = $checkoutSession->getBpostOriginalShippingAddress();
201
+ $address->unsetAddressId()
202
+ ->setSaveInAddressBook(0)
203
+ ->setFirstname($originalAddress->getFirstname())
204
+ ->setLastname($originalAddress->getLastname())
205
+ ->setStreet($originalAddress->getStreet())
206
+ ->setCity($originalAddress->getCity())
207
+ ->setPostcode($originalAddress->getPostcode())
208
+ ->save();
209
+ }
210
+ }
211
+
212
+ //set saturday delivery option flag so shipping prices incl. saturday delivery are calculated
213
+ if(isset($params['bpost_saturday_delivery']) && !$params['bpost_saturday_delivery']) {
214
+ $quote->setBpostDisableSaturdayDelivery(false);
215
+ } elseif(isset($params['bpost_saturday_delivery']) && $params['bpost_saturday_delivery']) {
216
+ $quote->setBpostDisableSaturdayDelivery(true);
217
+ }
218
+
219
+ //re-collect our rates
220
+ $address->setCollectShippingRates(true);
221
+
222
+ //add a flag for progress reload
223
+ $checkoutSession->setBpostReloadProgress(true);
224
+
225
+ //set this so we know what the previous method was.
226
+ $checkoutSession->setAlternativeShippingMethod($address->getShippingMethod());
227
+
228
+ return $this;
229
+ }
230
+
231
+ /**
232
+ * @param $observer
233
+ * @return $this
234
+ */
235
+ public function checkout_submit_all_after($observer){
236
+ $checkoutSession = Mage::getSingleton('checkout/session');
237
+ $quote = $checkoutSession->getQuote();
238
+ $order = $observer->getEvent()->getOrder();
239
+
240
+ $configHelper = Mage::helper("bpost_shm/system_config");
241
+
242
+ if($quote->getShippingAddress()->getShippingMethod()){
243
+ $displayDeliveryDates = $configHelper->getBpostShippingConfig("display_delivery_date", Mage::app()->getStore()->getId());
244
+ $order->setBpostPickuplocationId($quote->getBpostPickuplocationId());
245
+
246
+ if($displayDeliveryDates) {
247
+ $order->setBpostDisableSaturdayDelivery($quote->getBpostDisableSaturdayDelivery());
248
+ }
249
+
250
+ $order->save();
251
+ }
252
+
253
+ //function checks if manage labels with Magento is disabled
254
+ //if so, we need to call the create order api function
255
+ $manageLabelsWithMagento = $configHelper->getBpostShippingConfig("manage_labels_with_magento");
256
+
257
+ if(!$manageLabelsWithMagento){
258
+ $apiModel = Mage::getModel("bpost_shm/api", true);
259
+ $apiModel->createOrder($order);
260
+ $order->setBpostReference($order->getIncrementId())->save();
261
+ }
262
+
263
+ return $this;
264
+ }
265
+
266
+ /**
267
+ * function sets default data on our quote
268
+ * we need to do this for the onestepcheckout
269
+ */
270
+ public function sales_quote_collect_totals_before($observer){
271
+ $checkoutSession = Mage::getSingleton('checkout/session');
272
+ $quote = $checkoutSession->getQuote();
273
+
274
+ $params = Mage::app()->getRequest()->getParams();
275
+ $originalRatePrices = $checkoutSession->getOriginalRatePrices();
276
+
277
+ if(isset($params["shipping_method"]) && $originalRatePrices){
278
+ $bpostConfigHelper = Mage::helper("bpost_shm/system_config");
279
+ $bpostHelper = Mage::helper("bpost_shm");
280
+
281
+ $groups = $quote->getShippingAddress()->getGroupedAllShippingRates();
282
+ foreach ($groups as $code => $_rates){
283
+ foreach ($_rates as $_rate){
284
+
285
+ if($_rate->getCode() == $params["shipping_method"] && isset($originalRatePrices[$params["shipping_method"]])){
286
+ $saturdayDeliveryCost = $bpostHelper->formatSaturdayDeliveryCost($bpostConfigHelper->getBpostShippingConfig("saturday_delivery_cost", Mage::app()->getStore()->getId()));
287
+
288
+ if(isset($params["disable_saturday_delivery"]) && $params["disable_saturday_delivery"] == 1){
289
+ //check if the option saturday delivery is active for the current shipping method
290
+ if($quote->getBpostSaturdayCostApplied()){
291
+ //remove extra cost
292
+ $_rate->setPrice($originalRatePrices[$params["shipping_method"]]);
293
+ $_rate->setSaturdayDelivery(0);
294
+ $quote->setBpostDisableSaturdayDelivery(true);
295
+ $quote->setBpostSaturdayCostApplied(false);
296
+ }
297
+
298
+ }elseif(isset($params["disable_saturday_delivery"]) && $params["disable_saturday_delivery"] == 0){
299
+ if(!$quote->getBpostSaturdayCostApplied()){
300
+ //add extra cost
301
+ $_rate->setPrice($originalRatePrices[$params["shipping_method"]]+$saturdayDeliveryCost);
302
+ $_rate->setSaturdayDelivery(1);
303
+ //make sure the original prices are applied
304
+ $quote->setBpostDisableSaturdayDelivery(false);
305
+ $quote->setBpostSaturdayCostApplied(true);
306
+ }
307
+ }
308
+
309
+ $_rate->save();
310
+ }
311
+ }
312
+ }
313
+
314
+ $quote->getShippingAddress()->setCollectShippingrates(true)->save();
315
+ }
316
+
317
+
318
+ if(Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links', $quote->getStore())) {
319
+ if (Mage::getSingleton('customer/session')->isLoggedIn() && (!$quote->getBpostNotificationSms() || !$quote->getBpostNotificationEmail())) {
320
+ $customer = $quote->getCustomer();
321
+
322
+ if(!$quote->getBpostNotificationEmail()){
323
+ $email = $customer->getEmail();
324
+ $quote->getShippingAddress()->setEmail($email);
325
+ }
326
+
327
+ if(!$quote->getBpostNotificationSms()){
328
+ $currentPrimaryShipping = $customer->getPrimaryShippingAddress();
329
+ if(is_object($currentPrimaryShipping)){
330
+ $telephone = $currentPrimaryShipping->getTelephone();
331
+ $quote->getShippingAddress()->setTelephone($telephone);
332
+ }
333
+ }
334
+ }
335
+ }
336
+
337
+ return $this;
338
+ }
339
+
340
+ public function controller_action_predispatch_onestepcheckout_index_index($observer){
341
+ $checkoutSession = Mage::getSingleton('checkout/session');
342
+ $quote = $checkoutSession->getQuote();
343
+ $shippingMethod = $quote->getShippingAddress()->getShippingMethod();
344
+ $shippingMethod = str_replace('bpostshm_', '', $shippingMethod);
345
+
346
+ $bpostConfigHelper = Mage::helper("bpost_shm/system_config");
347
+ $saturdayDeliveryActive = $bpostConfigHelper->getBpostCarriersConfig("saturday_delivery", $shippingMethod, Mage::app()->getStore()->getId());
348
+
349
+ if($saturdayDeliveryActive !== 0){
350
+ //always reset the saturday delivery option so we don't see multiplied rates
351
+ $quote->setBpostDisableSaturdayDelivery(false);
352
+ $quote->setBpostSaturdayCostApplied(true);
353
+ }else{
354
+ $quote->setBpostDisableSaturdayDelivery(true);
355
+ $quote->setBpostSaturdayCostApplied(false);
356
+ }
357
+
358
+ return $this;
359
+ }
360
+ }
app/code/community/Bpost/ShM/Model/Resource/Country.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Resource_Country
13
+ */
14
+ class Bpost_ShM_Model_Resource_Country extends Mage_Core_Model_Mysql4_Abstract
15
+ {
16
+ /**
17
+ * Sets model primary key.
18
+ */
19
+ protected function _construct()
20
+ {
21
+ $this->_init("bpost_shm/bpost_country", "country_id");
22
+ }
23
+
24
+ /**
25
+ * we truncate our table
26
+ */
27
+ public function truncateTable(){
28
+ $this->_getWriteAdapter()->query('TRUNCATE TABLE '.$this->getMainTable());
29
+ return $this;
30
+ }
31
+ }
app/code/community/Bpost/ShM/Model/Resource/Country/Collection.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Resource_Country_Collection
13
+ */
14
+ class Bpost_ShM_Model_Resource_Country_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
15
+ {
16
+ /**
17
+ * Initialises the model, the abstract file will render a collection from it.
18
+ */
19
+ public function _construct()
20
+ {
21
+ $this->_init("bpost_shm/country");
22
+ }
23
+
24
+
25
+ /**
26
+ * Convert collection items to select options array
27
+ *
28
+ * @return array
29
+ */
30
+ public function toOptionArray()
31
+ {
32
+ $options = $this->_toOptionArray('country_id', 'country_code');
33
+ $sort = array();
34
+
35
+ foreach ($options as $data) {
36
+ $name = Mage::app()->getLocale()->getCountryTranslation($data['label']);
37
+ if (!empty($name)) {
38
+ $sort[$name] = $data['label'];
39
+ }
40
+ }
41
+
42
+ Mage::helper('core/string')->ksortMultibyte($sort);
43
+
44
+ $options = array();
45
+ foreach ($sort as $label => $value) {
46
+ $options[] = array(
47
+ 'value' => $value,
48
+ 'label' => $label
49
+ );
50
+ }
51
+
52
+ return $options;
53
+ }
54
+ }
app/code/community/Bpost/ShM/Model/Resource/Holidays.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Resource_Holidays
13
+ */
14
+ class Bpost_ShM_Model_Resource_Holidays extends Mage_Core_Model_Mysql4_Abstract
15
+ {
16
+ /**
17
+ * Sets model primary key.
18
+ */
19
+ protected function _construct()
20
+ {
21
+ $this->_init("bpost_shm/bpost_holidays", "holiday_id");
22
+ }
23
+ }
app/code/community/Bpost/ShM/Model/Resource/Holidays/Collection.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Resource_Holidays_Collection
13
+ */
14
+ class Bpost_ShM_Model_Resource_Holidays_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
15
+ {
16
+ /**
17
+ * Initialises the model, the abstract file will render a collection from it.
18
+ */
19
+ public function _construct()
20
+ {
21
+ $this->_init("bpost_shm/holidays");
22
+ }
23
+
24
+ /**
25
+ * Convert collection items to array with holidays
26
+ *
27
+ * @return array
28
+ */
29
+ public function getHolidays()
30
+ {
31
+ $options = $this->_toOptionArray('holiday_id', 'date');
32
+ $dates = array();
33
+
34
+ foreach ($options as $record) {
35
+ $dates[] = date('Y-m-d', strtotime($record['label']));
36
+ }
37
+
38
+ return $dates;
39
+ }
40
+ }
app/code/community/Bpost/ShM/Model/Resource/Returnlabel.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Resource_Returnlabel
13
+ */
14
+ class Bpost_ShM_Model_Resource_Returnlabel extends Mage_Core_Model_Mysql4_Abstract
15
+ {
16
+ /**
17
+ * Sets model primary key.
18
+ */
19
+ protected function _construct()
20
+ {
21
+ $this->_init("bpost_shm/returnlabel", "label_id");
22
+ }
23
+ }
app/code/community/Bpost/ShM/Model/Resource/Returnlabel/Collection.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Resource_Returnlabel_Collection
13
+ */
14
+ class Bpost_ShM_Model_Resource_Returnlabel_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
15
+ {
16
+ /**
17
+ * Initialises the model, the abstract file will render a collection from it.
18
+ */
19
+ public function _construct()
20
+ {
21
+ $this->_init("bpost_shm/returnlabel");
22
+ }
23
+ }
app/code/community/Bpost/ShM/Model/Resource/Tablerates/Homedelivery.php ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Resource_Tablerates_Homedelivery extends Mage_Core_Model_Resource_Db_Abstract{
3
+
4
+ /**
5
+ * Website Id selected in scope.
6
+ *
7
+ * @var int
8
+ */
9
+ protected $_importWebsiteId = 0;
10
+
11
+ /**
12
+ * Array to fill with possible errors.
13
+ *
14
+ * @var array
15
+ */
16
+ protected $_importErrors = array();
17
+
18
+ /**
19
+ * Number of rows imported.
20
+ *
21
+ * @var int
22
+ */
23
+ protected $_importedRows = 0;
24
+
25
+ /**
26
+ * Conversion.
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_importUniqueHash = array();
31
+
32
+ /**
33
+ * Conversion.
34
+ *
35
+ * @var
36
+ */
37
+ protected $_importIso2Countries;
38
+
39
+ /**
40
+ * Conversion.
41
+ *
42
+ * @var
43
+ */
44
+ protected $_importIso3Countries;
45
+
46
+ /**
47
+ * Regions to import.
48
+ *
49
+ * @var
50
+ */
51
+ protected $_importRegions;
52
+
53
+ /**
54
+ * Condition name selected in sysconfig.
55
+ *
56
+ * @var
57
+ */
58
+ protected $_importConditionName;
59
+
60
+ /**
61
+ * Full name of condition selected in sysconfig.
62
+ *
63
+ * @var array
64
+ */
65
+ protected $_conditionFullNames = array();
66
+
67
+
68
+ /**
69
+ * Initialise the model.
70
+ */
71
+ protected function _construct()
72
+ {
73
+ $this->_init("bpost_shm/bpost_tablerates_homedelivery", "pk");
74
+ }
75
+
76
+
77
+ /**
78
+ * Fetch rate from the table for selected shipping address.
79
+ *
80
+ * @param Mage_Shipping_Model_Rate_Request $request
81
+ * @return array
82
+ */
83
+ public function getRate(Mage_Shipping_Model_Rate_Request $request)
84
+ {
85
+ $adapter = $this->_getReadAdapter();
86
+ $bind = array(
87
+ ':website_id' => (int) $request->getWebsiteId(),
88
+ ':country_id' => $request->getDestCountryId(),
89
+ ':region_id' => (int) $request->getDestRegionId(),
90
+ ':postcode' => $request->getDestPostcode()
91
+ );
92
+ $select = $adapter->select()
93
+ ->from($this->getMainTable())
94
+ ->where('website_id = :website_id')
95
+ ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'condition_value DESC'))
96
+ ->limit(1);
97
+
98
+ // Render destination condition
99
+ $orWhere = '(' . implode(') OR (', array(
100
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
101
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",
102
+
103
+ // Handle asterix in dest_zip field
104
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = '*'",
105
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
106
+ "dest_country_id = '0' AND dest_region_id = :region_id AND dest_zip = '*'",
107
+ "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*'",
108
+
109
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
110
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
111
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
112
+ )) . ')';
113
+ $select->where($orWhere);
114
+
115
+ // Render condition by condition name
116
+ if (is_array($request->getConditionName())) {
117
+ $orWhere = array();
118
+ $i = 0;
119
+ foreach ($request->getConditionName() as $conditionName) {
120
+ $bindNameKey = sprintf(':condition_name_%d', $i);
121
+ $bindValueKey = sprintf(':condition_value_%d', $i);
122
+ $orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})";
123
+ $bind[$bindNameKey] = $conditionName;
124
+ $bind[$bindValueKey] = $request->getData($conditionName);
125
+ $i++;
126
+ }
127
+
128
+ if ($orWhere) {
129
+ $select->where(implode(' OR ', $orWhere));
130
+ }
131
+ } else {
132
+ $bind[':condition_name'] = $request->getConditionName();
133
+ $bind[':condition_value'] = $request->getData($request->getConditionName());
134
+
135
+ $select->where('condition_name = :condition_name');
136
+ $select->where('condition_value <= :condition_value');
137
+ }
138
+
139
+ $result = $adapter->fetchRow($select, $bind);
140
+ // Normalize destination zip code
141
+ if ($result && $result['dest_zip'] == '*') {
142
+ $result['dest_zip'] = '';
143
+ }
144
+ return $result;
145
+ }
146
+
147
+
148
+ /**
149
+ * Upload and import table rates csv.
150
+ *
151
+ * @param Varien_Object $object
152
+ * @return $this
153
+ */
154
+ public function uploadAndImport(Varien_Object $object)
155
+ {
156
+ if (empty($_FILES['groups']['tmp_name']['bpost_homedelivery']['fields']['import_homedelivery']['value'])) {
157
+ return $this;
158
+ }
159
+
160
+ $csvFile = $_FILES['groups']['tmp_name']['bpost_homedelivery']['fields']['import_homedelivery']['value'];
161
+ $website = Mage::app()->getWebsite($object->getScopeId());
162
+
163
+ $this->_importWebsiteId = (int)$website->getId();
164
+ $this->_importUniqueHash = array();
165
+ $this->_importErrors = array();
166
+ $this->_importedRows = 0;
167
+
168
+ $io = new Varien_Io_File();
169
+ $info = pathinfo($csvFile);
170
+ $io->open(array('path' => $info['dirname']));
171
+ $io->streamOpen($info['basename'], 'r');
172
+
173
+ // check and skip headers
174
+ $headers = $io->streamReadCsv();
175
+ if ($headers === false || count($headers) < 5) {
176
+ $io->streamClose();
177
+ Mage::throwException(Mage::helper('bpost_shm')->__('Invalid Table Rates File Format'));
178
+ }
179
+ if ($object->getData('groups/bpost_homedelivery/fields/condition_name/inherit') == '1') {
180
+ $conditionName = (string)Mage::getConfig()->getNode('default/carriers/bpost_homedelivery/condition_name');
181
+ } else {
182
+ $conditionName = $object->getData('groups/bpost_homedelivery/fields/condition_name/value');
183
+ }
184
+ $this->_importConditionName = $conditionName;
185
+ $adapter = $this->_getWriteAdapter();
186
+ $adapter->beginTransaction();
187
+
188
+ try {
189
+ $rowNumber = 1;
190
+ $importData = array();
191
+
192
+ $this->_loadDirectoryCountries();
193
+ $this->_loadDirectoryRegions();
194
+
195
+ // delete old data by website and condition name
196
+ $condition = array(
197
+ 'website_id = ?' => $this->_importWebsiteId,
198
+ 'condition_name = ?' => $this->_importConditionName
199
+ );
200
+ $adapter->delete($this->getMainTable(), $condition);
201
+
202
+ while (false !== ($csvLine = $io->streamReadCsv())) {
203
+ $rowNumber ++;
204
+
205
+ if (empty($csvLine)) {
206
+ continue;
207
+ }
208
+
209
+ $row = $this->_getImportRow($csvLine, $rowNumber);
210
+ if ($row !== false) {
211
+ $importData[] = $row;
212
+ }
213
+
214
+ if (count($importData) == 5000) {
215
+ $this->_saveImportData($importData);
216
+ $importData = array();
217
+ }
218
+ }
219
+ $this->_saveImportData($importData);
220
+ $io->streamClose();
221
+ } catch (Mage_Core_Exception $e) {
222
+ $adapter->rollback();
223
+ $io->streamClose();
224
+ Mage::throwException($e->getMessage());
225
+ } catch (Exception $e) {
226
+ $adapter->rollback();
227
+ $io->streamClose();
228
+ Mage::helper('bpost_shm')->log($e,Zend_Log::ERR);
229
+ Mage::throwException(Mage::helper('bpost_shm')->__('An error occurred while importing table rates.'));
230
+ }
231
+
232
+ $adapter->commit();
233
+
234
+ if ($this->_importErrors) {
235
+ $error = Mage::helper('bpost_shm')->__('File has not been imported. See the following list of errors: %s', implode(" \n", $this->_importErrors));
236
+ Mage::throwException($error);
237
+ }
238
+
239
+ return $this;
240
+ }
241
+
242
+ /**
243
+ * Load directory countries.
244
+ *
245
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate
246
+ */
247
+ protected function _loadDirectoryCountries()
248
+ {
249
+ if (!is_null($this->_importIso2Countries) && !is_null($this->_importIso3Countries)) {
250
+ return $this;
251
+ }
252
+
253
+ $this->_importIso2Countries = array();
254
+ $this->_importIso3Countries = array();
255
+
256
+ /** @var $collection Mage_Directory_Model_Resource_Country_Collection */
257
+ $collection = Mage::getResourceModel('directory/country_collection');
258
+ foreach ($collection->getData() as $row) {
259
+ $this->_importIso2Countries[$row['iso2_code']] = $row['country_id'];
260
+ $this->_importIso3Countries[$row['iso3_code']] = $row['country_id'];
261
+ }
262
+
263
+ return $this;
264
+ }
265
+
266
+ /**
267
+ * Load directory regions.
268
+ *
269
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate
270
+ */
271
+ protected function _loadDirectoryRegions()
272
+ {
273
+ if (!is_null($this->_importRegions)) {
274
+ return $this;
275
+ }
276
+
277
+ $this->_importRegions = array();
278
+
279
+ /** @var $collection Mage_Directory_Model_Resource_Region_Collection */
280
+ $collection = Mage::getResourceModel('directory/region_collection');
281
+ foreach ($collection->getData() as $row) {
282
+ $this->_importRegions[$row['country_id']][$row['code']] = (int)$row['region_id'];
283
+ }
284
+
285
+ return $this;
286
+ }
287
+
288
+ /**
289
+ * Return import condition full name by condition name code.
290
+ *
291
+ * @param string $conditionName
292
+ * @return string
293
+ */
294
+ protected function _getConditionFullName($conditionName)
295
+ {
296
+ if (!isset($this->_conditionFullNames[$conditionName])) {
297
+ $name = Mage::getSingleton('shipping/carrier_tablerate')->getCode('condition_name_short', $conditionName);
298
+ $this->_conditionFullNames[$conditionName] = $name;
299
+ }
300
+ return $this->_conditionFullNames[$conditionName];
301
+ }
302
+
303
+ /**
304
+ * Validate row for import and return table rate array or false.
305
+ * Error will be add to _importErrors array.
306
+ *
307
+ * @param array $row
308
+ * @param int $rowNumber
309
+ * @return array|false
310
+ */
311
+ protected function _getImportRow($row, $rowNumber = 0)
312
+ {
313
+ // validate row
314
+ if (count($row) < 5) {
315
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Table Rates format in the Row #%s', $rowNumber);
316
+ return false;
317
+ }
318
+
319
+ // strip whitespace from the beginning and end of each row
320
+ foreach ($row as $k => $v) {
321
+ $row[$k] = trim($v);
322
+ }
323
+
324
+ // validate country
325
+ if (isset($this->_importIso2Countries[$row[0]])){
326
+ $countryId = $this->_importIso2Countries[$row[0]];
327
+ } elseif (isset($this->_importIso3Countries[$row[0]])) {
328
+ $countryId = $this->_importIso3Countries[$row[0]];
329
+ } elseif ($row[0] == '*' || $row[0] == '') {
330
+ $countryId = '0';
331
+ } else {
332
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Country "%s" in the Row #%s.', $row[0], $rowNumber);
333
+ return false;
334
+ }
335
+
336
+ // validate region
337
+ if ($countryId != '0' && isset($this->_importRegions[$countryId][$row[1]])) {
338
+ $regionId = $this->_importRegions[$countryId][$row[1]];
339
+ } elseif ($row[1] == '*' || $row[1] == '') {
340
+ $regionId = 0;
341
+ } else {
342
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Region/State "%s" in the Row #%s.', $row[1], $rowNumber);
343
+ return false;
344
+ }
345
+
346
+ // detect zip code
347
+ if ($row[2] == '*' || $row[2] == '') {
348
+ $zipCode = '*';
349
+ } else {
350
+ $zipCode = $row[2];
351
+ }
352
+
353
+ // validate condition value
354
+ $value = $this->_parseDecimalValue($row[3]);
355
+ if ($value === false) {
356
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid %s "%s" in the Row #%s.', $this->_getConditionFullName($this->_importConditionName), $row[3], $rowNumber);
357
+ return false;
358
+ }
359
+
360
+ // validate price
361
+ $price = $this->_parseDecimalValue($row[4]);
362
+ if ($price === false) {
363
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Shipping Price "%s" in the Row #%s.', $row[4], $rowNumber);
364
+ return false;
365
+ }
366
+
367
+ // protect from duplicate
368
+ $hash = sprintf("%s-%d-%s-%F", $countryId, $regionId, $zipCode, $value);
369
+ if (isset($this->_importUniqueHash[$hash])) {
370
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Duplicate Row #%s (Country "%s", Region/State "%s", Zip "%s" and Value "%s").', $rowNumber, $row[0], $row[1], $zipCode, $value);
371
+ return false;
372
+ }
373
+ $this->_importUniqueHash[$hash] = true;
374
+
375
+ return array(
376
+ $this->_importWebsiteId, // website_id
377
+ $countryId, // dest_country_id
378
+ $regionId, // dest_region_id,
379
+ $zipCode, // dest_zip
380
+ $this->_importConditionName,// condition_name,
381
+ $value, // condition_value
382
+ $price // price
383
+ );
384
+ }
385
+
386
+ /**
387
+ * Save all import data.
388
+ *
389
+ * @param array $data
390
+ * @return $this
391
+ */
392
+ protected function _saveImportData(array $data)
393
+ {
394
+ if (!empty($data)) {
395
+ $columns = array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip',
396
+ 'condition_name', 'condition_value', 'price');
397
+ $this->_getWriteAdapter()->insertArray($this->getMainTable(), $columns, $data);
398
+ $this->_importedRows += count($data);
399
+ }
400
+
401
+ return $this;
402
+ }
403
+
404
+ /**
405
+ * Conversion.
406
+ *
407
+ * @param $value
408
+ * @return bool|float
409
+ */
410
+ protected function _parseDecimalValue($value)
411
+ {
412
+ if (!is_numeric($value)) {
413
+ return false;
414
+ }
415
+ $value = (float)sprintf('%.4F', $value);
416
+ if ($value < 0.0000) {
417
+ return false;
418
+ }
419
+ return $value;
420
+ }
421
+ }
app/code/community/Bpost/ShM/Model/Resource/Tablerates/Homedelivery/Collection.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Resource_Tablerates_Homedelivery_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
3
+ {
4
+ /**
5
+ * main table name
6
+ *
7
+ * @deprecated since 1.4.1.0
8
+ * @var string
9
+ */
10
+ protected $_shipTable;
11
+
12
+ /**
13
+ * directory/country table name
14
+ *
15
+ * @var string
16
+ */
17
+ protected $_countryTable;
18
+
19
+ /**
20
+ * directory/country_region table name
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_regionTable;
25
+
26
+ /**
27
+ * Define resource model and item
28
+ *
29
+ */
30
+ protected function _construct()
31
+ {
32
+ $this->_init('bpost_shm/tablerates_homedelivery');
33
+ $this->_shipTable = $this->getMainTable();
34
+ $this->_countryTable = $this->getTable('directory/country');
35
+ $this->_regionTable = $this->getTable('directory/country_region');
36
+ }
37
+
38
+ /**
39
+ * Initialize select, add country iso3 code and region name
40
+ *
41
+ * @return void
42
+ */
43
+ public function _initSelect()
44
+ {
45
+ parent::_initSelect();
46
+
47
+ $this->_select
48
+ ->joinLeft(
49
+ array('country_table' => $this->_countryTable),
50
+ 'country_table.country_id = main_table.dest_country_id',
51
+ array('dest_country' => 'iso3_code'))
52
+ ->joinLeft(
53
+ array('region_table' => $this->_regionTable),
54
+ 'region_table.region_id = main_table.dest_region_id',
55
+ array('dest_region' => 'code'));
56
+
57
+ $this->addOrder('dest_country', self::SORT_ORDER_ASC);
58
+ $this->addOrder('dest_region', self::SORT_ORDER_ASC);
59
+ $this->addOrder('dest_zip', self::SORT_ORDER_ASC);
60
+ $this->addOrder('condition_value', self::SORT_ORDER_ASC);
61
+ }
62
+
63
+ /**
64
+ * Add website filter to collection
65
+ *
66
+ * @param int $websiteId
67
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
68
+ */
69
+ public function setWebsiteFilter($websiteId)
70
+ {
71
+ return $this->addFieldToFilter('website_id', $websiteId);
72
+ }
73
+
74
+ /**
75
+ * Add condition name (code) filter to collection
76
+ *
77
+ * @param string $conditionName
78
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
79
+ */
80
+ public function setConditionFilter($conditionName)
81
+ {
82
+ return $this->addFieldToFilter('condition_name', $conditionName);
83
+ }
84
+
85
+ /**
86
+ * Add country filter to collection
87
+ *
88
+ * @param string $countryId
89
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
90
+ */
91
+ public function setCountryFilter($countryId)
92
+ {
93
+ return $this->addFieldToFilter('dest_country_id', $countryId);
94
+ }
95
+ }
app/code/community/Bpost/ShM/Model/Resource/Tablerates/International.php ADDED
@@ -0,0 +1,423 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Resource_Tablerates_International extends Mage_Core_Model_Resource_Db_Abstract{
3
+
4
+ /**
5
+ * Website Id selected in scope.
6
+ *
7
+ * @var int
8
+ */
9
+ protected $_importWebsiteId = 0;
10
+
11
+ /**
12
+ * Array to fill with possible errors.
13
+ *
14
+ * @var array
15
+ */
16
+ protected $_importErrors = array();
17
+
18
+ /**
19
+ * Number of rows imported.
20
+ *
21
+ * @var int
22
+ */
23
+ protected $_importedRows = 0;
24
+
25
+ /**
26
+ * Conversion.
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_importUniqueHash = array();
31
+
32
+ /**
33
+ * Conversion.
34
+ *
35
+ * @var
36
+ */
37
+ protected $_importIso2Countries;
38
+
39
+ /**
40
+ * Conversion.
41
+ *
42
+ * @var
43
+ */
44
+ protected $_importIso3Countries;
45
+
46
+ /**
47
+ * Regions to import.
48
+ *
49
+ * @var
50
+ */
51
+ protected $_importRegions;
52
+
53
+ /**
54
+ * Condition name selected in sysconfig.
55
+ *
56
+ * @var
57
+ */
58
+ protected $_importConditionName;
59
+
60
+ /**
61
+ * Full name of condition selected in sysconfig.
62
+ *
63
+ * @var array
64
+ */
65
+ protected $_conditionFullNames = array();
66
+
67
+
68
+ /**
69
+ * Initialise the model.
70
+ */
71
+ protected function _construct()
72
+ {
73
+ $this->_init("bpost_shm/bpost_tablerates_international", "pk");
74
+ }
75
+
76
+
77
+ /**
78
+ * Fetch rate from the table for selected shipping address.
79
+ *
80
+ * @param Mage_Shipping_Model_Rate_Request $request
81
+ * @return array
82
+ */
83
+ public function getRate(Mage_Shipping_Model_Rate_Request $request)
84
+ {
85
+ $adapter = $this->_getReadAdapter();
86
+ $bind = array(
87
+ ':website_id' => (int) $request->getWebsiteId(),
88
+ ':country_id' => $request->getDestCountryId(),
89
+ ':region_id' => (int) $request->getDestRegionId(),
90
+ ':postcode' => $request->getDestPostcode()
91
+ );
92
+ $select = $adapter->select()
93
+ ->from($this->getMainTable())
94
+ ->where('website_id = :website_id')
95
+ ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'condition_value DESC'))
96
+ ->limit(1);
97
+
98
+ // Render destination condition
99
+ $orWhere = '(' . implode(') OR (', array(
100
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
101
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",
102
+
103
+ // Handle asterix in dest_zip field
104
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = '*'",
105
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
106
+ "dest_country_id = '0' AND dest_region_id = :region_id AND dest_zip = '*'",
107
+ "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*'",
108
+
109
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
110
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
111
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
112
+ )) . ')';
113
+ $select->where($orWhere);
114
+
115
+ // Render condition by condition name
116
+ if (is_array($request->getConditionName())) {
117
+ $orWhere = array();
118
+ $i = 0;
119
+ foreach ($request->getConditionName() as $conditionName) {
120
+ $bindNameKey = sprintf(':condition_name_%d', $i);
121
+ $bindValueKey = sprintf(':condition_value_%d', $i);
122
+ $orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})";
123
+ $bind[$bindNameKey] = $conditionName;
124
+ $bind[$bindValueKey] = $request->getData($conditionName);
125
+ $i++;
126
+ }
127
+
128
+ if ($orWhere) {
129
+ $select->where(implode(' OR ', $orWhere));
130
+ }
131
+ } else {
132
+ $bind[':condition_name'] = $request->getConditionName();
133
+ $bind[':condition_value'] = $request->getData($request->getConditionName());
134
+
135
+ $select->where('condition_name = :condition_name');
136
+ $select->where('condition_value <= :condition_value');
137
+ }
138
+
139
+ $result = $adapter->fetchRow($select, $bind);
140
+
141
+ // Normalize destination zip code
142
+ if ($result && $result['dest_zip'] == '*') {
143
+ $result['dest_zip'] = '';
144
+ }
145
+
146
+ return $result;
147
+ }
148
+
149
+
150
+ /**
151
+ * Upload and import table rates csv.
152
+ *
153
+ * @param Varien_Object $object
154
+ * @return $this
155
+ */
156
+ public function uploadAndImport(Varien_Object $object)
157
+ {
158
+ if (empty($_FILES['groups']['tmp_name']['bpost_international']['fields']['import_international']['value'])) {
159
+ return $this;
160
+ }
161
+
162
+ $csvFile = $_FILES['groups']['tmp_name']['bpost_international']['fields']['import_international']['value'];
163
+ $website = Mage::app()->getWebsite($object->getScopeId());
164
+
165
+ $this->_importWebsiteId = (int)$website->getId();
166
+ $this->_importUniqueHash = array();
167
+ $this->_importErrors = array();
168
+ $this->_importedRows = 0;
169
+
170
+ $io = new Varien_Io_File();
171
+ $info = pathinfo($csvFile);
172
+ $io->open(array('path' => $info['dirname']));
173
+ $io->streamOpen($info['basename'], 'r');
174
+
175
+ // check and skip headers
176
+ $headers = $io->streamReadCsv();
177
+ if ($headers === false || count($headers) < 5) {
178
+ $io->streamClose();
179
+ Mage::throwException(Mage::helper('bpost_shm')->__('Invalid Table Rates File Format'));
180
+ }
181
+ if ($object->getData('groups/bpost_international/fields/condition_name/inherit') == '1') {
182
+ $conditionName = (string)Mage::getConfig()->getNode('default/carriers/bpost_international/condition_name');
183
+ } else {
184
+ $conditionName = $object->getData('groups/bpost_international/fields/condition_name/value');
185
+ }
186
+ $this->_importConditionName = $conditionName;
187
+ $adapter = $this->_getWriteAdapter();
188
+ $adapter->beginTransaction();
189
+
190
+ try {
191
+ $rowNumber = 1;
192
+ $importData = array();
193
+
194
+ $this->_loadDirectoryCountries();
195
+ $this->_loadDirectoryRegions();
196
+
197
+ // delete old data by website and condition name
198
+ $condition = array(
199
+ 'website_id = ?' => $this->_importWebsiteId,
200
+ 'condition_name = ?' => $this->_importConditionName
201
+ );
202
+ $adapter->delete($this->getMainTable(), $condition);
203
+
204
+ while (false !== ($csvLine = $io->streamReadCsv())) {
205
+ $rowNumber ++;
206
+
207
+ if (empty($csvLine)) {
208
+ continue;
209
+ }
210
+
211
+ $row = $this->_getImportRow($csvLine, $rowNumber);
212
+ if ($row !== false) {
213
+ $importData[] = $row;
214
+ }
215
+
216
+ if (count($importData) == 5000) {
217
+ $this->_saveImportData($importData);
218
+ $importData = array();
219
+ }
220
+ }
221
+ $this->_saveImportData($importData);
222
+ $io->streamClose();
223
+ } catch (Mage_Core_Exception $e) {
224
+ $adapter->rollback();
225
+ $io->streamClose();
226
+ Mage::throwException($e->getMessage());
227
+ } catch (Exception $e) {
228
+ $adapter->rollback();
229
+ $io->streamClose();
230
+ Mage::helper('bpost_shm')->log($e,Zend_Log::ERR);
231
+ Mage::throwException(Mage::helper('bpost_shm')->__('An error occurred while importing table rates.'));
232
+ }
233
+
234
+ $adapter->commit();
235
+
236
+ if ($this->_importErrors) {
237
+ $error = Mage::helper('bpost_shm')->__('File has not been imported. See the following list of errors: %s', implode(" \n", $this->_importErrors));
238
+ Mage::throwException($error);
239
+ }
240
+
241
+ return $this;
242
+ }
243
+
244
+ /**
245
+ * Load directory countries.
246
+ *
247
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate
248
+ */
249
+ protected function _loadDirectoryCountries()
250
+ {
251
+ if (!is_null($this->_importIso2Countries) && !is_null($this->_importIso3Countries)) {
252
+ return $this;
253
+ }
254
+
255
+ $this->_importIso2Countries = array();
256
+ $this->_importIso3Countries = array();
257
+
258
+ /** @var $collection Mage_Directory_Model_Resource_Country_Collection */
259
+ $collection = Mage::getResourceModel('directory/country_collection');
260
+ foreach ($collection->getData() as $row) {
261
+ $this->_importIso2Countries[$row['iso2_code']] = $row['country_id'];
262
+ $this->_importIso3Countries[$row['iso3_code']] = $row['country_id'];
263
+ }
264
+
265
+ return $this;
266
+ }
267
+
268
+ /**
269
+ * Load directory regions.
270
+ *
271
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate
272
+ */
273
+ protected function _loadDirectoryRegions()
274
+ {
275
+ if (!is_null($this->_importRegions)) {
276
+ return $this;
277
+ }
278
+
279
+ $this->_importRegions = array();
280
+
281
+ /** @var $collection Mage_Directory_Model_Resource_Region_Collection */
282
+ $collection = Mage::getResourceModel('directory/region_collection');
283
+ foreach ($collection->getData() as $row) {
284
+ $this->_importRegions[$row['country_id']][$row['code']] = (int)$row['region_id'];
285
+ }
286
+
287
+ return $this;
288
+ }
289
+
290
+ /**
291
+ * Return import condition full name by condition name code.
292
+ *
293
+ * @param string $conditionName
294
+ * @return string
295
+ */
296
+ protected function _getConditionFullName($conditionName)
297
+ {
298
+ if (!isset($this->_conditionFullNames[$conditionName])) {
299
+ $name = Mage::getSingleton('shipping/carrier_tablerate')->getCode('condition_name_short', $conditionName);
300
+ $this->_conditionFullNames[$conditionName] = $name;
301
+ }
302
+ return $this->_conditionFullNames[$conditionName];
303
+ }
304
+
305
+ /**
306
+ * Validate row for import and return table rate array or false.
307
+ * Error will be add to _importErrors array.
308
+ *
309
+ * @param array $row
310
+ * @param int $rowNumber
311
+ * @return array|false
312
+ */
313
+ protected function _getImportRow($row, $rowNumber = 0)
314
+ {
315
+ // validate row
316
+ if (count($row) < 5) {
317
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Table Rates format in the Row #%s', $rowNumber);
318
+ return false;
319
+ }
320
+
321
+ // strip whitespace from the beginning and end of each row
322
+ foreach ($row as $k => $v) {
323
+ $row[$k] = trim($v);
324
+ }
325
+
326
+ // validate country
327
+ if (isset($this->_importIso2Countries[$row[0]])){
328
+ $countryId = $this->_importIso2Countries[$row[0]];
329
+ } elseif (isset($this->_importIso3Countries[$row[0]])) {
330
+ $countryId = $this->_importIso3Countries[$row[0]];
331
+ } elseif ($row[0] == '*' || $row[0] == '') {
332
+ $countryId = '0';
333
+ } else {
334
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Country "%s" in the Row #%s.', $row[0], $rowNumber);
335
+ return false;
336
+ }
337
+
338
+ // validate region
339
+ if ($countryId != '0' && isset($this->_importRegions[$countryId][$row[1]])) {
340
+ $regionId = $this->_importRegions[$countryId][$row[1]];
341
+ } elseif ($row[1] == '*' || $row[1] == '') {
342
+ $regionId = 0;
343
+ } else {
344
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Region/State "%s" in the Row #%s.', $row[1], $rowNumber);
345
+ return false;
346
+ }
347
+
348
+ // detect zip code
349
+ if ($row[2] == '*' || $row[2] == '') {
350
+ $zipCode = '*';
351
+ } else {
352
+ $zipCode = $row[2];
353
+ }
354
+
355
+ // validate condition value
356
+ $value = $this->_parseDecimalValue($row[3]);
357
+ if ($value === false) {
358
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid %s "%s" in the Row #%s.', $this->_getConditionFullName($this->_importConditionName), $row[3], $rowNumber);
359
+ return false;
360
+ }
361
+
362
+ // validate price
363
+ $price = $this->_parseDecimalValue($row[4]);
364
+ if ($price === false) {
365
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Shipping Price "%s" in the Row #%s.', $row[4], $rowNumber);
366
+ return false;
367
+ }
368
+
369
+ // protect from duplicate
370
+ $hash = sprintf("%s-%d-%s-%F", $countryId, $regionId, $zipCode, $value);
371
+ if (isset($this->_importUniqueHash[$hash])) {
372
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Duplicate Row #%s (Country "%s", Region/State "%s", Zip "%s" and Value "%s").', $rowNumber, $row[0], $row[1], $zipCode, $value);
373
+ return false;
374
+ }
375
+ $this->_importUniqueHash[$hash] = true;
376
+
377
+ return array(
378
+ $this->_importWebsiteId, // website_id
379
+ $countryId, // dest_country_id
380
+ $regionId, // dest_region_id,
381
+ $zipCode, // dest_zip
382
+ $this->_importConditionName,// condition_name,
383
+ $value, // condition_value
384
+ $price // price
385
+ );
386
+ }
387
+
388
+ /**
389
+ * Save all import data.
390
+ *
391
+ * @param array $data
392
+ * @return $this
393
+ */
394
+ protected function _saveImportData(array $data)
395
+ {
396
+ if (!empty($data)) {
397
+ $columns = array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip',
398
+ 'condition_name', 'condition_value', 'price');
399
+ $this->_getWriteAdapter()->insertArray($this->getMainTable(), $columns, $data);
400
+ $this->_importedRows += count($data);
401
+ }
402
+
403
+ return $this;
404
+ }
405
+
406
+ /**
407
+ * Conversion.
408
+ *
409
+ * @param $value
410
+ * @return bool|float
411
+ */
412
+ protected function _parseDecimalValue($value)
413
+ {
414
+ if (!is_numeric($value)) {
415
+ return false;
416
+ }
417
+ $value = (float)sprintf('%.4F', $value);
418
+ if ($value < 0.0000) {
419
+ return false;
420
+ }
421
+ return $value;
422
+ }
423
+ }
app/code/community/Bpost/ShM/Model/Resource/Tablerates/International/Collection.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Resource_Tablerates_International_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
3
+ {
4
+ /**
5
+ * main table name
6
+ *
7
+ * @deprecated since 1.4.1.0
8
+ * @var string
9
+ */
10
+ protected $_shipTable;
11
+
12
+ /**
13
+ * directory/country table name
14
+ *
15
+ * @var string
16
+ */
17
+ protected $_countryTable;
18
+
19
+ /**
20
+ * directory/country_region table name
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_regionTable;
25
+
26
+ /**
27
+ * Define resource model and item
28
+ *
29
+ */
30
+ protected function _construct()
31
+ {
32
+ $this->_init('bpost_shm/tablerates_international');
33
+ $this->_shipTable = $this->getMainTable();
34
+ $this->_countryTable = $this->getTable('directory/country');
35
+ $this->_regionTable = $this->getTable('directory/country_region');
36
+ }
37
+
38
+ /**
39
+ * Initialize select, add country iso3 code and region name
40
+ *
41
+ * @return void
42
+ */
43
+ public function _initSelect()
44
+ {
45
+ parent::_initSelect();
46
+
47
+ $this->_select
48
+ ->joinLeft(
49
+ array('country_table' => $this->_countryTable),
50
+ 'country_table.country_id = main_table.dest_country_id',
51
+ array('dest_country' => 'iso3_code'))
52
+ ->joinLeft(
53
+ array('region_table' => $this->_regionTable),
54
+ 'region_table.region_id = main_table.dest_region_id',
55
+ array('dest_region' => 'code'));
56
+
57
+ $this->addOrder('dest_country', self::SORT_ORDER_ASC);
58
+ $this->addOrder('dest_region', self::SORT_ORDER_ASC);
59
+ $this->addOrder('dest_zip', self::SORT_ORDER_ASC);
60
+ $this->addOrder('condition_value', self::SORT_ORDER_ASC);
61
+ }
62
+
63
+ /**
64
+ * Add website filter to collection
65
+ *
66
+ * @param int $websiteId
67
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
68
+ */
69
+ public function setWebsiteFilter($websiteId)
70
+ {
71
+ return $this->addFieldToFilter('website_id', $websiteId);
72
+ }
73
+
74
+ /**
75
+ * Add condition name (code) filter to collection
76
+ *
77
+ * @param string $conditionName
78
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
79
+ */
80
+ public function setConditionFilter($conditionName)
81
+ {
82
+ return $this->addFieldToFilter('condition_name', $conditionName);
83
+ }
84
+
85
+ /**
86
+ * Add country filter to collection
87
+ *
88
+ * @param string $countryId
89
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
90
+ */
91
+ public function setCountryFilter($countryId)
92
+ {
93
+ return $this->addFieldToFilter('dest_country_id', $countryId);
94
+ }
95
+ }
app/code/community/Bpost/ShM/Model/Resource/Tablerates/Parcellocker.php ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Resource_Tablerates_Parcellocker extends Mage_Core_Model_Resource_Db_Abstract{
3
+
4
+ /**
5
+ * Website Id selected in scope.
6
+ *
7
+ * @var int
8
+ */
9
+ protected $_importWebsiteId = 0;
10
+
11
+ /**
12
+ * Array to fill with possible errors.
13
+ *
14
+ * @var array
15
+ */
16
+ protected $_importErrors = array();
17
+
18
+ /**
19
+ * Number of rows imported.
20
+ *
21
+ * @var int
22
+ */
23
+ protected $_importedRows = 0;
24
+
25
+ /**
26
+ * Conversion.
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_importUniqueHash = array();
31
+
32
+ /**
33
+ * Conversion.
34
+ *
35
+ * @var
36
+ */
37
+ protected $_importIso2Countries;
38
+
39
+ /**
40
+ * Conversion.
41
+ *
42
+ * @var
43
+ */
44
+ protected $_importIso3Countries;
45
+
46
+ /**
47
+ * Regions to import.
48
+ *
49
+ * @var
50
+ */
51
+ protected $_importRegions;
52
+
53
+ /**
54
+ * Condition name selected in sysconfig.
55
+ *
56
+ * @var
57
+ */
58
+ protected $_importConditionName;
59
+
60
+ /**
61
+ * Full name of condition selected in sysconfig.
62
+ *
63
+ * @var array
64
+ */
65
+ protected $_conditionFullNames = array();
66
+
67
+
68
+ /**
69
+ * Initialise the model.
70
+ */
71
+ protected function _construct()
72
+ {
73
+ $this->_init("bpost_shm/bpost_tablerates_parcellocker", "pk");
74
+ }
75
+
76
+
77
+ /**
78
+ * Fetch rate from the table for selected shipping address.
79
+ *
80
+ * @param Mage_Shipping_Model_Rate_Request $request
81
+ * @return array
82
+ */
83
+ public function getRate(Mage_Shipping_Model_Rate_Request $request)
84
+ {
85
+ $adapter = $this->_getReadAdapter();
86
+ $bind = array(
87
+ ':website_id' => (int) $request->getWebsiteId(),
88
+ ':country_id' => $request->getDestCountryId(),
89
+ ':region_id' => (int) $request->getDestRegionId(),
90
+ ':postcode' => $request->getDestPostcode()
91
+ );
92
+ $select = $adapter->select()
93
+ ->from($this->getMainTable())
94
+ ->where('website_id = :website_id')
95
+ ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'condition_value DESC'))
96
+ ->limit(1);
97
+
98
+ // Render destination condition
99
+ $orWhere = '(' . implode(') OR (', array(
100
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
101
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",
102
+
103
+ // Handle asterix in dest_zip field
104
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = '*'",
105
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
106
+ "dest_country_id = '0' AND dest_region_id = :region_id AND dest_zip = '*'",
107
+ "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*'",
108
+
109
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
110
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
111
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
112
+ )) . ')';
113
+ $select->where($orWhere);
114
+
115
+ // Render condition by condition name
116
+ if (is_array($request->getConditionName())) {
117
+ $orWhere = array();
118
+ $i = 0;
119
+ foreach ($request->getConditionName() as $conditionName) {
120
+ $bindNameKey = sprintf(':condition_name_%d', $i);
121
+ $bindValueKey = sprintf(':condition_value_%d', $i);
122
+ $orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})";
123
+ $bind[$bindNameKey] = $conditionName;
124
+ $bind[$bindValueKey] = $request->getData($conditionName);
125
+ $i++;
126
+ }
127
+
128
+ if ($orWhere) {
129
+ $select->where(implode(' OR ', $orWhere));
130
+ }
131
+ } else {
132
+ $bind[':condition_name'] = $request->getConditionName();
133
+ $bind[':condition_value'] = $request->getData($request->getConditionName());
134
+
135
+ $select->where('condition_name = :condition_name');
136
+ $select->where('condition_value <= :condition_value');
137
+ }
138
+
139
+ $result = $adapter->fetchRow($select, $bind);
140
+ // Normalize destination zip code
141
+ if ($result && $result['dest_zip'] == '*') {
142
+ $result['dest_zip'] = '';
143
+ }
144
+ return $result;
145
+ }
146
+
147
+
148
+ /**
149
+ * Upload and import table rates csv.
150
+ *
151
+ * @param Varien_Object $object
152
+ * @return $this
153
+ */
154
+ public function uploadAndImport(Varien_Object $object)
155
+ {
156
+ if (empty($_FILES['groups']['tmp_name']['bpost_parcellocker']['fields']['import_parcellocker']['value'])) {
157
+ return $this;
158
+ }
159
+
160
+ $csvFile = $_FILES['groups']['tmp_name']['bpost_parcellocker']['fields']['import_parcellocker']['value'];
161
+ $website = Mage::app()->getWebsite($object->getScopeId());
162
+
163
+ $this->_importWebsiteId = (int)$website->getId();
164
+ $this->_importUniqueHash = array();
165
+ $this->_importErrors = array();
166
+ $this->_importedRows = 0;
167
+
168
+ $io = new Varien_Io_File();
169
+ $info = pathinfo($csvFile);
170
+ $io->open(array('path' => $info['dirname']));
171
+ $io->streamOpen($info['basename'], 'r');
172
+
173
+ // check and skip headers
174
+ $headers = $io->streamReadCsv();
175
+ if ($headers === false || count($headers) < 5) {
176
+ $io->streamClose();
177
+ Mage::throwException(Mage::helper('bpost_shm')->__('Invalid Table Rates File Format'));
178
+ }
179
+ if ($object->getData('groups/bpost_parcellocker/fields/condition_name/inherit') == '1') {
180
+ $conditionName = (string)Mage::getConfig()->getNode('default/carriers/bpost_parcellocker/condition_name');
181
+ } else {
182
+ $conditionName = $object->getData('groups/bpost_parcellocker/fields/condition_name/value');
183
+ }
184
+ $this->_importConditionName = $conditionName;
185
+ $adapter = $this->_getWriteAdapter();
186
+ $adapter->beginTransaction();
187
+
188
+ try {
189
+ $rowNumber = 1;
190
+ $importData = array();
191
+
192
+ $this->_loadDirectoryCountries();
193
+ $this->_loadDirectoryRegions();
194
+
195
+ // delete old data by website and condition name
196
+ $condition = array(
197
+ 'website_id = ?' => $this->_importWebsiteId,
198
+ 'condition_name = ?' => $this->_importConditionName
199
+ );
200
+ $adapter->delete($this->getMainTable(), $condition);
201
+
202
+ while (false !== ($csvLine = $io->streamReadCsv())) {
203
+ $rowNumber ++;
204
+
205
+ if (empty($csvLine)) {
206
+ continue;
207
+ }
208
+
209
+ $row = $this->_getImportRow($csvLine, $rowNumber);
210
+ if ($row !== false) {
211
+ $importData[] = $row;
212
+ }
213
+
214
+ if (count($importData) == 5000) {
215
+ $this->_saveImportData($importData);
216
+ $importData = array();
217
+ }
218
+ }
219
+ $this->_saveImportData($importData);
220
+ $io->streamClose();
221
+ } catch (Mage_Core_Exception $e) {
222
+ $adapter->rollback();
223
+ $io->streamClose();
224
+ Mage::throwException($e->getMessage());
225
+ } catch (Exception $e) {
226
+ $adapter->rollback();
227
+ $io->streamClose();
228
+ Mage::helper('bpost_shm')->log($e,Zend_Log::ERR);
229
+ Mage::throwException(Mage::helper('bpost_shm')->__('An error occurred while importing table rates.'));
230
+ }
231
+
232
+ $adapter->commit();
233
+
234
+ if ($this->_importErrors) {
235
+ $error = Mage::helper('bpost_shm')->__('File has not been imported. See the following list of errors: %s', implode(" \n", $this->_importErrors));
236
+ Mage::throwException($error);
237
+ }
238
+
239
+ return $this;
240
+ }
241
+
242
+ /**
243
+ * Load directory countries.
244
+ *
245
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate
246
+ */
247
+ protected function _loadDirectoryCountries()
248
+ {
249
+ if (!is_null($this->_importIso2Countries) && !is_null($this->_importIso3Countries)) {
250
+ return $this;
251
+ }
252
+
253
+ $this->_importIso2Countries = array();
254
+ $this->_importIso3Countries = array();
255
+
256
+ /** @var $collection Mage_Directory_Model_Resource_Country_Collection */
257
+ $collection = Mage::getResourceModel('directory/country_collection');
258
+ foreach ($collection->getData() as $row) {
259
+ $this->_importIso2Countries[$row['iso2_code']] = $row['country_id'];
260
+ $this->_importIso3Countries[$row['iso3_code']] = $row['country_id'];
261
+ }
262
+
263
+ return $this;
264
+ }
265
+
266
+ /**
267
+ * Load directory regions.
268
+ *
269
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate
270
+ */
271
+ protected function _loadDirectoryRegions()
272
+ {
273
+ if (!is_null($this->_importRegions)) {
274
+ return $this;
275
+ }
276
+
277
+ $this->_importRegions = array();
278
+
279
+ /** @var $collection Mage_Directory_Model_Resource_Region_Collection */
280
+ $collection = Mage::getResourceModel('directory/region_collection');
281
+ foreach ($collection->getData() as $row) {
282
+ $this->_importRegions[$row['country_id']][$row['code']] = (int)$row['region_id'];
283
+ }
284
+
285
+ return $this;
286
+ }
287
+
288
+ /**
289
+ * Return import condition full name by condition name code.
290
+ *
291
+ * @param string $conditionName
292
+ * @return string
293
+ */
294
+ protected function _getConditionFullName($conditionName)
295
+ {
296
+ if (!isset($this->_conditionFullNames[$conditionName])) {
297
+ $name = Mage::getSingleton('shipping/carrier_tablerate')->getCode('condition_name_short', $conditionName);
298
+ $this->_conditionFullNames[$conditionName] = $name;
299
+ }
300
+ return $this->_conditionFullNames[$conditionName];
301
+ }
302
+
303
+ /**
304
+ * Validate row for import and return table rate array or false.
305
+ * Error will be add to _importErrors array.
306
+ *
307
+ * @param array $row
308
+ * @param int $rowNumber
309
+ * @return array|false
310
+ */
311
+ protected function _getImportRow($row, $rowNumber = 0)
312
+ {
313
+ // validate row
314
+ if (count($row) < 5) {
315
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Table Rates format in the Row #%s', $rowNumber);
316
+ return false;
317
+ }
318
+
319
+ // strip whitespace from the beginning and end of each row
320
+ foreach ($row as $k => $v) {
321
+ $row[$k] = trim($v);
322
+ }
323
+
324
+ // validate country
325
+ if (isset($this->_importIso2Countries[$row[0]])){
326
+ $countryId = $this->_importIso2Countries[$row[0]];
327
+ } elseif (isset($this->_importIso3Countries[$row[0]])) {
328
+ $countryId = $this->_importIso3Countries[$row[0]];
329
+ } elseif ($row[0] == '*' || $row[0] == '') {
330
+ $countryId = '0';
331
+ } else {
332
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Country "%s" in the Row #%s.', $row[0], $rowNumber);
333
+ return false;
334
+ }
335
+
336
+ // validate region
337
+ if ($countryId != '0' && isset($this->_importRegions[$countryId][$row[1]])) {
338
+ $regionId = $this->_importRegions[$countryId][$row[1]];
339
+ } elseif ($row[1] == '*' || $row[1] == '') {
340
+ $regionId = 0;
341
+ } else {
342
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Region/State "%s" in the Row #%s.', $row[1], $rowNumber);
343
+ return false;
344
+ }
345
+
346
+ // detect zip code
347
+ if ($row[2] == '*' || $row[2] == '') {
348
+ $zipCode = '*';
349
+ } else {
350
+ $zipCode = $row[2];
351
+ }
352
+
353
+ // validate condition value
354
+ $value = $this->_parseDecimalValue($row[3]);
355
+ if ($value === false) {
356
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid %s "%s" in the Row #%s.', $this->_getConditionFullName($this->_importConditionName), $row[3], $rowNumber);
357
+ return false;
358
+ }
359
+
360
+ // validate price
361
+ $price = $this->_parseDecimalValue($row[4]);
362
+ if ($price === false) {
363
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Shipping Price "%s" in the Row #%s.', $row[4], $rowNumber);
364
+ return false;
365
+ }
366
+
367
+ // protect from duplicate
368
+ $hash = sprintf("%s-%d-%s-%F", $countryId, $regionId, $zipCode, $value);
369
+ if (isset($this->_importUniqueHash[$hash])) {
370
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Duplicate Row #%s (Country "%s", Region/State "%s", Zip "%s" and Value "%s").', $rowNumber, $row[0], $row[1], $zipCode, $value);
371
+ return false;
372
+ }
373
+ $this->_importUniqueHash[$hash] = true;
374
+
375
+ return array(
376
+ $this->_importWebsiteId, // website_id
377
+ $countryId, // dest_country_id
378
+ $regionId, // dest_region_id,
379
+ $zipCode, // dest_zip
380
+ $this->_importConditionName,// condition_name,
381
+ $value, // condition_value
382
+ $price // price
383
+ );
384
+ }
385
+
386
+ /**
387
+ * Save all import data.
388
+ *
389
+ * @param array $data
390
+ * @return $this
391
+ */
392
+ protected function _saveImportData(array $data)
393
+ {
394
+ if (!empty($data)) {
395
+ $columns = array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip',
396
+ 'condition_name', 'condition_value', 'price');
397
+ $this->_getWriteAdapter()->insertArray($this->getMainTable(), $columns, $data);
398
+ $this->_importedRows += count($data);
399
+ }
400
+
401
+ return $this;
402
+ }
403
+
404
+ /**
405
+ * Conversion.
406
+ *
407
+ * @param $value
408
+ * @return bool|float
409
+ */
410
+ protected function _parseDecimalValue($value)
411
+ {
412
+ if (!is_numeric($value)) {
413
+ return false;
414
+ }
415
+ $value = (float)sprintf('%.4F', $value);
416
+ if ($value < 0.0000) {
417
+ return false;
418
+ }
419
+ return $value;
420
+ }
421
+ }
app/code/community/Bpost/ShM/Model/Resource/Tablerates/Parcellocker/Collection.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Resource_Tablerates_Parcellocker_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
3
+ {
4
+ /**
5
+ * main table name
6
+ *
7
+ * @deprecated since 1.4.1.0
8
+ * @var string
9
+ */
10
+ protected $_shipTable;
11
+
12
+ /**
13
+ * directory/country table name
14
+ *
15
+ * @var string
16
+ */
17
+ protected $_countryTable;
18
+
19
+ /**
20
+ * directory/country_region table name
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_regionTable;
25
+
26
+ /**
27
+ * Define resource model and item
28
+ *
29
+ */
30
+ protected function _construct()
31
+ {
32
+ $this->_init('bpost_shm/tablerates_parcellocker');
33
+ $this->_shipTable = $this->getMainTable();
34
+ $this->_countryTable = $this->getTable('directory/country');
35
+ $this->_regionTable = $this->getTable('directory/country_region');
36
+ }
37
+
38
+ /**
39
+ * Initialize select, add country iso3 code and region name
40
+ *
41
+ * @return void
42
+ */
43
+ public function _initSelect()
44
+ {
45
+ parent::_initSelect();
46
+
47
+ $this->_select
48
+ ->joinLeft(
49
+ array('country_table' => $this->_countryTable),
50
+ 'country_table.country_id = main_table.dest_country_id',
51
+ array('dest_country' => 'iso3_code'))
52
+ ->joinLeft(
53
+ array('region_table' => $this->_regionTable),
54
+ 'region_table.region_id = main_table.dest_region_id',
55
+ array('dest_region' => 'code'));
56
+
57
+ $this->addOrder('dest_country', self::SORT_ORDER_ASC);
58
+ $this->addOrder('dest_region', self::SORT_ORDER_ASC);
59
+ $this->addOrder('dest_zip', self::SORT_ORDER_ASC);
60
+ $this->addOrder('condition_value', self::SORT_ORDER_ASC);
61
+ }
62
+
63
+ /**
64
+ * Add website filter to collection
65
+ *
66
+ * @param int $websiteId
67
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
68
+ */
69
+ public function setWebsiteFilter($websiteId)
70
+ {
71
+ return $this->addFieldToFilter('website_id', $websiteId);
72
+ }
73
+
74
+ /**
75
+ * Add condition name (code) filter to collection
76
+ *
77
+ * @param string $conditionName
78
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
79
+ */
80
+ public function setConditionFilter($conditionName)
81
+ {
82
+ return $this->addFieldToFilter('condition_name', $conditionName);
83
+ }
84
+
85
+ /**
86
+ * Add country filter to collection
87
+ *
88
+ * @param string $countryId
89
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
90
+ */
91
+ public function setCountryFilter($countryId)
92
+ {
93
+ return $this->addFieldToFilter('dest_country_id', $countryId);
94
+ }
95
+ }
app/code/community/Bpost/ShM/Model/Resource/Tablerates/Pickuppoint.php ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Resource_Tablerates_Pickuppoint extends Mage_Core_Model_Resource_Db_Abstract{
3
+
4
+ /**
5
+ * Website Id selected in scope.
6
+ *
7
+ * @var int
8
+ */
9
+ protected $_importWebsiteId = 0;
10
+
11
+ /**
12
+ * Array to fill with possible errors.
13
+ *
14
+ * @var array
15
+ */
16
+ protected $_importErrors = array();
17
+
18
+ /**
19
+ * Number of rows imported.
20
+ *
21
+ * @var int
22
+ */
23
+ protected $_importedRows = 0;
24
+
25
+ /**
26
+ * Conversion.
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_importUniqueHash = array();
31
+
32
+ /**
33
+ * Conversion.
34
+ *
35
+ * @var
36
+ */
37
+ protected $_importIso2Countries;
38
+
39
+ /**
40
+ * Conversion.
41
+ *
42
+ * @var
43
+ */
44
+ protected $_importIso3Countries;
45
+
46
+ /**
47
+ * Regions to import.
48
+ *
49
+ * @var
50
+ */
51
+ protected $_importRegions;
52
+
53
+ /**
54
+ * Condition name selected in sysconfig.
55
+ *
56
+ * @var
57
+ */
58
+ protected $_importConditionName;
59
+
60
+ /**
61
+ * Full name of condition selected in sysconfig.
62
+ *
63
+ * @var array
64
+ */
65
+ protected $_conditionFullNames = array();
66
+
67
+
68
+ /**
69
+ * Initialise the model.
70
+ */
71
+ protected function _construct()
72
+ {
73
+ $this->_init("bpost_shm/bpost_tablerates_pickuppoint", "pk");
74
+ }
75
+
76
+
77
+ /**
78
+ * Fetch rate from the table for selected shipping address.
79
+ *
80
+ * @param Mage_Shipping_Model_Rate_Request $request
81
+ * @return array
82
+ */
83
+ public function getRate(Mage_Shipping_Model_Rate_Request $request)
84
+ {
85
+ $adapter = $this->_getReadAdapter();
86
+ $bind = array(
87
+ ':website_id' => (int) $request->getWebsiteId(),
88
+ ':country_id' => $request->getDestCountryId(),
89
+ ':region_id' => (int) $request->getDestRegionId(),
90
+ ':postcode' => $request->getDestPostcode()
91
+ );
92
+ $select = $adapter->select()
93
+ ->from($this->getMainTable())
94
+ ->where('website_id = :website_id')
95
+ ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'condition_value DESC'))
96
+ ->limit(1);
97
+
98
+ // Render destination condition
99
+ $orWhere = '(' . implode(') OR (', array(
100
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
101
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",
102
+
103
+ // Handle asterix in dest_zip field
104
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = '*'",
105
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
106
+ "dest_country_id = '0' AND dest_region_id = :region_id AND dest_zip = '*'",
107
+ "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*'",
108
+
109
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
110
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
111
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
112
+ )) . ')';
113
+ $select->where($orWhere);
114
+
115
+ // Render condition by condition name
116
+ if (is_array($request->getConditionName())) {
117
+ $orWhere = array();
118
+ $i = 0;
119
+ foreach ($request->getConditionName() as $conditionName) {
120
+ $bindNameKey = sprintf(':condition_name_%d', $i);
121
+ $bindValueKey = sprintf(':condition_value_%d', $i);
122
+ $orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})";
123
+ $bind[$bindNameKey] = $conditionName;
124
+ $bind[$bindValueKey] = $request->getData($conditionName);
125
+ $i++;
126
+ }
127
+
128
+ if ($orWhere) {
129
+ $select->where(implode(' OR ', $orWhere));
130
+ }
131
+ } else {
132
+ $bind[':condition_name'] = $request->getConditionName();
133
+ $bind[':condition_value'] = $request->getData($request->getConditionName());
134
+
135
+ $select->where('condition_name = :condition_name');
136
+ $select->where('condition_value <= :condition_value');
137
+ }
138
+
139
+ $result = $adapter->fetchRow($select, $bind);
140
+ // Normalize destination zip code
141
+ if ($result && $result['dest_zip'] == '*') {
142
+ $result['dest_zip'] = '';
143
+ }
144
+ return $result;
145
+ }
146
+
147
+
148
+ /**
149
+ * Upload and import table rates csv.
150
+ *
151
+ * @param Varien_Object $object
152
+ * @return $this
153
+ */
154
+ public function uploadAndImport(Varien_Object $object)
155
+ {
156
+ if (empty($_FILES['groups']['tmp_name']['bpost_pickuppoint']['fields']['import_pickuppoint']['value'])) {
157
+ return $this;
158
+ }
159
+
160
+ $csvFile = $_FILES['groups']['tmp_name']['bpost_pickuppoint']['fields']['import_pickuppoint']['value'];
161
+ $website = Mage::app()->getWebsite($object->getScopeId());
162
+
163
+ $this->_importWebsiteId = (int)$website->getId();
164
+ $this->_importUniqueHash = array();
165
+ $this->_importErrors = array();
166
+ $this->_importedRows = 0;
167
+
168
+ $io = new Varien_Io_File();
169
+ $info = pathinfo($csvFile);
170
+ $io->open(array('path' => $info['dirname']));
171
+ $io->streamOpen($info['basename'], 'r');
172
+
173
+ // check and skip headers
174
+ $headers = $io->streamReadCsv();
175
+ if ($headers === false || count($headers) < 5) {
176
+ $io->streamClose();
177
+ Mage::throwException(Mage::helper('bpost_shm')->__('Invalid Table Rates File Format'));
178
+ }
179
+ if ($object->getData('groups/bpost_pickuppoint/fields/condition_name/inherit') == '1') {
180
+ $conditionName = (string)Mage::getConfig()->getNode('default/carriers/bpost_pickuppoint/condition_name');
181
+ } else {
182
+ $conditionName = $object->getData('groups/bpost_pickuppoint/fields/condition_name/value');
183
+ }
184
+ $this->_importConditionName = $conditionName;
185
+ $adapter = $this->_getWriteAdapter();
186
+ $adapter->beginTransaction();
187
+
188
+ try {
189
+ $rowNumber = 1;
190
+ $importData = array();
191
+
192
+ $this->_loadDirectoryCountries();
193
+ $this->_loadDirectoryRegions();
194
+
195
+ // delete old data by website and condition name
196
+ $condition = array(
197
+ 'website_id = ?' => $this->_importWebsiteId,
198
+ 'condition_name = ?' => $this->_importConditionName
199
+ );
200
+ $adapter->delete($this->getMainTable(), $condition);
201
+
202
+ while (false !== ($csvLine = $io->streamReadCsv())) {
203
+ $rowNumber ++;
204
+
205
+ if (empty($csvLine)) {
206
+ continue;
207
+ }
208
+
209
+ $row = $this->_getImportRow($csvLine, $rowNumber);
210
+ if ($row !== false) {
211
+ $importData[] = $row;
212
+ }
213
+
214
+ if (count($importData) == 5000) {
215
+ $this->_saveImportData($importData);
216
+ $importData = array();
217
+ }
218
+ }
219
+ $this->_saveImportData($importData);
220
+ $io->streamClose();
221
+ } catch (Mage_Core_Exception $e) {
222
+ $adapter->rollback();
223
+ $io->streamClose();
224
+ Mage::throwException($e->getMessage());
225
+ } catch (Exception $e) {
226
+ $adapter->rollback();
227
+ $io->streamClose();
228
+ Mage::helper('bpost_shm')->log($e,Zend_Log::ERR);
229
+ Mage::throwException(Mage::helper('bpost_shm')->__('An error occurred while importing table rates.'));
230
+ }
231
+
232
+ $adapter->commit();
233
+
234
+ if ($this->_importErrors) {
235
+ $error = Mage::helper('bpost_shm')->__('File has not been imported. See the following list of errors: %s', implode(" \n", $this->_importErrors));
236
+ Mage::throwException($error);
237
+ }
238
+
239
+ return $this;
240
+ }
241
+
242
+ /**
243
+ * Load directory countries.
244
+ *
245
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate
246
+ */
247
+ protected function _loadDirectoryCountries()
248
+ {
249
+ if (!is_null($this->_importIso2Countries) && !is_null($this->_importIso3Countries)) {
250
+ return $this;
251
+ }
252
+
253
+ $this->_importIso2Countries = array();
254
+ $this->_importIso3Countries = array();
255
+
256
+ /** @var $collection Mage_Directory_Model_Resource_Country_Collection */
257
+ $collection = Mage::getResourceModel('directory/country_collection');
258
+ foreach ($collection->getData() as $row) {
259
+ $this->_importIso2Countries[$row['iso2_code']] = $row['country_id'];
260
+ $this->_importIso3Countries[$row['iso3_code']] = $row['country_id'];
261
+ }
262
+
263
+ return $this;
264
+ }
265
+
266
+ /**
267
+ * Load directory regions.
268
+ *
269
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate
270
+ */
271
+ protected function _loadDirectoryRegions()
272
+ {
273
+ if (!is_null($this->_importRegions)) {
274
+ return $this;
275
+ }
276
+
277
+ $this->_importRegions = array();
278
+
279
+ /** @var $collection Mage_Directory_Model_Resource_Region_Collection */
280
+ $collection = Mage::getResourceModel('directory/region_collection');
281
+ foreach ($collection->getData() as $row) {
282
+ $this->_importRegions[$row['country_id']][$row['code']] = (int)$row['region_id'];
283
+ }
284
+
285
+ return $this;
286
+ }
287
+
288
+ /**
289
+ * Return import condition full name by condition name code.
290
+ *
291
+ * @param string $conditionName
292
+ * @return string
293
+ */
294
+ protected function _getConditionFullName($conditionName)
295
+ {
296
+ if (!isset($this->_conditionFullNames[$conditionName])) {
297
+ $name = Mage::getSingleton('shipping/carrier_tablerate')->getCode('condition_name_short', $conditionName);
298
+ $this->_conditionFullNames[$conditionName] = $name;
299
+ }
300
+ return $this->_conditionFullNames[$conditionName];
301
+ }
302
+
303
+ /**
304
+ * Validate row for import and return table rate array or false.
305
+ * Error will be add to _importErrors array.
306
+ *
307
+ * @param array $row
308
+ * @param int $rowNumber
309
+ * @return array|false
310
+ */
311
+ protected function _getImportRow($row, $rowNumber = 0)
312
+ {
313
+ // validate row
314
+ if (count($row) < 5) {
315
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Table Rates format in the Row #%s', $rowNumber);
316
+ return false;
317
+ }
318
+
319
+ // strip whitespace from the beginning and end of each row
320
+ foreach ($row as $k => $v) {
321
+ $row[$k] = trim($v);
322
+ }
323
+
324
+ // validate country
325
+ if (isset($this->_importIso2Countries[$row[0]])){
326
+ $countryId = $this->_importIso2Countries[$row[0]];
327
+ } elseif (isset($this->_importIso3Countries[$row[0]])) {
328
+ $countryId = $this->_importIso3Countries[$row[0]];
329
+ } elseif ($row[0] == '*' || $row[0] == '') {
330
+ $countryId = '0';
331
+ } else {
332
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Country "%s" in the Row #%s.', $row[0], $rowNumber);
333
+ return false;
334
+ }
335
+
336
+ // validate region
337
+ if ($countryId != '0' && isset($this->_importRegions[$countryId][$row[1]])) {
338
+ $regionId = $this->_importRegions[$countryId][$row[1]];
339
+ } elseif ($row[1] == '*' || $row[1] == '') {
340
+ $regionId = 0;
341
+ } else {
342
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Region/State "%s" in the Row #%s.', $row[1], $rowNumber);
343
+ return false;
344
+ }
345
+
346
+ // detect zip code
347
+ if ($row[2] == '*' || $row[2] == '') {
348
+ $zipCode = '*';
349
+ } else {
350
+ $zipCode = $row[2];
351
+ }
352
+
353
+ // validate condition value
354
+ $value = $this->_parseDecimalValue($row[3]);
355
+ if ($value === false) {
356
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid %s "%s" in the Row #%s.', $this->_getConditionFullName($this->_importConditionName), $row[3], $rowNumber);
357
+ return false;
358
+ }
359
+
360
+ // validate price
361
+ $price = $this->_parseDecimalValue($row[4]);
362
+ if ($price === false) {
363
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Invalid Shipping Price "%s" in the Row #%s.', $row[4], $rowNumber);
364
+ return false;
365
+ }
366
+
367
+ // protect from duplicate
368
+ $hash = sprintf("%s-%d-%s-%F", $countryId, $regionId, $zipCode, $value);
369
+ if (isset($this->_importUniqueHash[$hash])) {
370
+ $this->_importErrors[] = Mage::helper('bpost_shm')->__('Duplicate Row #%s (Country "%s", Region/State "%s", Zip "%s" and Value "%s").', $rowNumber, $row[0], $row[1], $zipCode, $value);
371
+ return false;
372
+ }
373
+ $this->_importUniqueHash[$hash] = true;
374
+
375
+ return array(
376
+ $this->_importWebsiteId, // website_id
377
+ $countryId, // dest_country_id
378
+ $regionId, // dest_region_id,
379
+ $zipCode, // dest_zip
380
+ $this->_importConditionName,// condition_name,
381
+ $value, // condition_value
382
+ $price // price
383
+ );
384
+ }
385
+
386
+ /**
387
+ * Save all import data.
388
+ *
389
+ * @param array $data
390
+ * @return $this
391
+ */
392
+ protected function _saveImportData(array $data)
393
+ {
394
+ if (!empty($data)) {
395
+ $columns = array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip',
396
+ 'condition_name', 'condition_value', 'price');
397
+ $this->_getWriteAdapter()->insertArray($this->getMainTable(), $columns, $data);
398
+ $this->_importedRows += count($data);
399
+ }
400
+
401
+ return $this;
402
+ }
403
+
404
+ /**
405
+ * Conversion.
406
+ *
407
+ * @param $value
408
+ * @return bool|float
409
+ */
410
+ protected function _parseDecimalValue($value)
411
+ {
412
+ if (!is_numeric($value)) {
413
+ return false;
414
+ }
415
+ $value = (float)sprintf('%.4F', $value);
416
+ if ($value < 0.0000) {
417
+ return false;
418
+ }
419
+ return $value;
420
+ }
421
+ }
app/code/community/Bpost/ShM/Model/Resource/Tablerates/Pickuppoint/Collection.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Resource_Tablerates_Pickuppoint_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
3
+ {
4
+ /**
5
+ * main table name
6
+ *
7
+ * @deprecated since 1.4.1.0
8
+ * @var string
9
+ */
10
+ protected $_shipTable;
11
+
12
+ /**
13
+ * directory/country table name
14
+ *
15
+ * @var string
16
+ */
17
+ protected $_countryTable;
18
+
19
+ /**
20
+ * directory/country_region table name
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_regionTable;
25
+
26
+ /**
27
+ * Define resource model and item
28
+ *
29
+ */
30
+ protected function _construct()
31
+ {
32
+ $this->_init('bpost_shm/tablerates_pickuppoint');
33
+ $this->_shipTable = $this->getMainTable();
34
+ $this->_countryTable = $this->getTable('directory/country');
35
+ $this->_regionTable = $this->getTable('directory/country_region');
36
+ }
37
+
38
+ /**
39
+ * Initialize select, add country iso3 code and region name
40
+ *
41
+ * @return void
42
+ */
43
+ public function _initSelect()
44
+ {
45
+ parent::_initSelect();
46
+
47
+ $this->_select
48
+ ->joinLeft(
49
+ array('country_table' => $this->_countryTable),
50
+ 'country_table.country_id = main_table.dest_country_id',
51
+ array('dest_country' => 'iso3_code'))
52
+ ->joinLeft(
53
+ array('region_table' => $this->_regionTable),
54
+ 'region_table.region_id = main_table.dest_region_id',
55
+ array('dest_region' => 'code'));
56
+
57
+ $this->addOrder('dest_country', self::SORT_ORDER_ASC);
58
+ $this->addOrder('dest_region', self::SORT_ORDER_ASC);
59
+ $this->addOrder('dest_zip', self::SORT_ORDER_ASC);
60
+ $this->addOrder('condition_value', self::SORT_ORDER_ASC);
61
+ }
62
+
63
+ /**
64
+ * Add website filter to collection
65
+ *
66
+ * @param int $websiteId
67
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
68
+ */
69
+ public function setWebsiteFilter($websiteId)
70
+ {
71
+ return $this->addFieldToFilter('website_id', $websiteId);
72
+ }
73
+
74
+ /**
75
+ * Add condition name (code) filter to collection
76
+ *
77
+ * @param string $conditionName
78
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
79
+ */
80
+ public function setConditionFilter($conditionName)
81
+ {
82
+ return $this->addFieldToFilter('condition_name', $conditionName);
83
+ }
84
+
85
+ /**
86
+ * Add country filter to collection
87
+ *
88
+ * @param string $countryId
89
+ * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
90
+ */
91
+ public function setCountryFilter($countryId)
92
+ {
93
+ return $this->addFieldToFilter('dest_country_id', $countryId);
94
+ }
95
+ }
app/code/community/Bpost/ShM/Model/Returnlabel.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Returnlabel
13
+ */
14
+ class Bpost_ShM_Model_Returnlabel extends Mage_Core_Model_Abstract
15
+ {
16
+ const MEDIA_RETURNLABEL_PATH = "/bpost/";
17
+
18
+ /**
19
+ * Initialise the model.
20
+ */
21
+ protected function _construct()
22
+ {
23
+ $this->_init("bpost_shm/returnlabel");
24
+ }
25
+
26
+
27
+ /**
28
+ * Gets label from webservice, saves it and returns the saved id.
29
+ *
30
+ * @param $orderId
31
+ * @return int
32
+ */
33
+ public function generateLabelAndSave($orderId)
34
+ {
35
+ $order = Mage::getModel('sales/order')->load($orderId);
36
+ $bpostHelper = Mage::helper("bpost_shm");
37
+ $bpostReturnLabelHelper = Mage::helper("bpost_shm/returnlabel");
38
+
39
+ //check for return order
40
+ $returnlabelResponse = Mage::getModel('bpost_shm/api', true)->createReturnLabel($order);
41
+
42
+ if(!$returnlabelResponse){
43
+ Mage::throwException("Failed to create a return label. Please check your error logs.");
44
+ }
45
+
46
+ $parsedLabelResponse = $bpostHelper->parseLabelApiResponse($returnlabelResponse, $order);
47
+
48
+ //make sure we save with an unique name
49
+ //if no barcode is returned (probably never)
50
+ $barcode = $bpostReturnLabelHelper->getBarcodeByLabelResponse($order, $parsedLabelResponse);
51
+
52
+ foreach($parsedLabelResponse["pdfString"] as $pdfString){
53
+ //convertstring to pdf and save
54
+ $pdfname = $bpostHelper->generatePdfAndSave($pdfString, "returnlabel", $barcode);
55
+ }
56
+
57
+ $returnLabelObject = new Bpost_ShM_Model_Returnlabel;
58
+ $returnLabelObject
59
+ ->setLabelBarcode($barcode)
60
+ ->setLabelPdfPath("returnlabel/$pdfname.pdf")
61
+ ->setOrderId($orderId)
62
+ ->setDateCreated(time());
63
+
64
+ $order->setBpostReturnLabelExists(true);
65
+
66
+ //we start a transaction
67
+ //we save multiple objects
68
+ $transactionSave = Mage::getModel('core/resource_transaction')
69
+ ->addObject($returnLabelObject)
70
+ ->addObject($order)
71
+ ->save();
72
+
73
+ return $returnLabelObject->getId();
74
+ }
75
+
76
+ /**
77
+ * Sends email with custom bpost email and attached the pdf
78
+ *
79
+ * @param $order
80
+ * @param $returnId
81
+ * @return $this
82
+ */
83
+ public function sendEmail($returnId)
84
+ {
85
+ $file = new Varien_Io_File();
86
+ $bpostHelper = Mage::helper("bpost_shm");
87
+ $translate = Mage::getSingleton('core/translate');
88
+ $translate->setTranslateInline(false);
89
+ $returnLabel = Mage::getModel('bpost_shm/returnlabel')->load($returnId);
90
+ $order = Mage::getModel('sales/order')->load($returnLabel->getOrderId());
91
+ $billingAddress = $order->getBillingAddress();
92
+ $pdf_attachment = $returnLabel->getLabelPdfPath();
93
+
94
+ $templateVars = array('returnlabel' => $returnLabel, 'order' => $order, 'store' => Mage::app()->getStore($order->getStoreId()));
95
+ $transactionalEmail = Mage::getModel('core/email_template')->setDesignConfig(array('area' => 'frontend', 'store' => $order->getStoreId()));
96
+
97
+ $filePath = Mage::getBaseDir('media') . self::MEDIA_RETURNLABEL_PATH . $pdf_attachment;
98
+ $pdfFileParser = Zend_Pdf::load($filePath);
99
+
100
+ if (!empty($pdf_attachment) && $file->fileExists($filePath)) {
101
+ $fileName = $bpostHelper->getFileNameByPath($pdf_attachment);
102
+ $transactionalEmail->getMail()
103
+ ->createAttachment(
104
+ $pdfFileParser->render(),
105
+ Zend_Mime::TYPE_OCTETSTREAM,
106
+ Zend_Mime::DISPOSITION_ATTACHMENT,
107
+ Zend_Mime::ENCODING_BASE64,
108
+ $fileName
109
+ );
110
+ }
111
+
112
+ $transactionalEmail->sendTransactional('bpost_returnlabel_email_template',
113
+ array('name' => Mage::getStoreConfig('trans_email/ident_support/name'),
114
+ 'email' => Mage::getStoreConfig('trans_email/ident_support/email')),
115
+ $billingAddress->getEmail(),
116
+ $billingAddress->getFirstname() . " " . $billingAddress->getLastname(),
117
+ $templateVars);
118
+
119
+ $translate->setTranslateInline(true);
120
+ return $billingAddress->getEmail();
121
+ }
122
+ }
app/code/community/Bpost/ShM/Model/Shipping/Carrier/BpostShM.php ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Shipping_Carrier_BpostShM
13
+ */
14
+ class Bpost_ShM_Model_Shipping_Carrier_BpostShM extends Mage_Shipping_Model_Carrier_Abstract
15
+ implements Mage_Shipping_Model_Carrier_Interface
16
+ {
17
+ const SHIPMENT_TRACK_DOMAIN = "http://track.bpost.be/";
18
+
19
+ protected $_code = 'bpostshm';
20
+ protected $_isFixed = true;
21
+
22
+ /**
23
+ * Edited collectRates function for bpost carriers
24
+ *
25
+ * @param Mage_Shipping_Model_Rate_Request $request
26
+ * @return bool|Mage_Shipping_Model_Rate_Result|null
27
+ */
28
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
29
+ {
30
+ $numberOfDisabledShippingMethods = 0;
31
+ $result = Mage::getModel('bpost_shm/shipping_rate_result');
32
+
33
+ $helper = Mage::helper("bpost_shm");
34
+ $configHelper = Mage::helper("bpost_shm/system_config");
35
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
36
+ $ratePriceByMethod = array();
37
+
38
+ foreach ($this->getAllowedMethods() as $shippingMethodCode => $shippingMethodName) {
39
+ if (!$this->getBpostConfigData('active', $shippingMethodCode) || !$this->checkAvailableBpostShipCountries($request, $shippingMethodCode)) {
40
+ $numberOfDisabledShippingMethods++;
41
+ continue;
42
+ }
43
+
44
+ $method = Mage::getModel('shipping/rate_result_method');
45
+ if (!$this->getBpostConfigData('rate_type', $shippingMethodCode)) {
46
+ $price = $this->getBpostConfigData('flat_rate_price', $shippingMethodCode);
47
+ if ($request->getFreeShipping() === true ||
48
+ ($this->getBpostConfigData('free_shipping', $shippingMethodCode) &&
49
+ $request->getPackageValue() >= $this->getBpostConfigData('free_shipping_from', $shippingMethodCode))) {
50
+ $price = 0;
51
+ }
52
+ } else {
53
+ $freeQty = 0;
54
+ if ($request->getAllItems()) {
55
+ $freePackageValue = 0;
56
+ foreach ($request->getAllItems() as $item) {
57
+ if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
58
+ continue;
59
+ }
60
+
61
+ if ($item->getHasChildren() && $item->isShipSeparately()) {
62
+ foreach ($item->getChildren() as $child) {
63
+ if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
64
+ $freeShipping = is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0;
65
+ $freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
66
+ }
67
+ }
68
+ } elseif ($item->getFreeShipping()) {
69
+ $freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0;
70
+ $freeQty += $item->getQty() - $freeShipping;
71
+ $freePackageValue += $item->getBaseRowTotal();
72
+ }
73
+ }
74
+ $oldValue = $request->getPackageValue();
75
+ $request->setPackageValue($oldValue - $freePackageValue);
76
+ }
77
+
78
+ if ($freePackageValue) {
79
+ $request->setPackageValue($request->getPackageValue() - $freePackageValue);
80
+ }
81
+
82
+ $conditionName = $this->getBpostConfigData('condition_name', $shippingMethodCode);
83
+ $request->setConditionName($conditionName ? $conditionName : $this->_default_condition_name);
84
+
85
+ $oldWeight = $request->getPackageWeight();
86
+ $oldQty = $request->getPackageQty();
87
+
88
+ $request->setPackageWeight($request->getFreeMethodWeight());
89
+ $request->setPackageQty($oldQty - $freeQty);
90
+
91
+ $rate = $this->getRate($request, $shippingMethodCode);
92
+
93
+ $request->setPackageWeight($oldWeight);
94
+ $request->setPackageQty($oldQty);
95
+
96
+ if (!empty($rate) && $rate['price'] >= 0) {
97
+ if ($request->getFreeShipping() === true ||
98
+ ($request->getPackageQty() == $freeQty) ||
99
+ ($this->getBpostConfigData('free_shipping', $shippingMethodCode) &&
100
+ $request->getPackageValue() >= $this->getBpostConfigData('free_shipping_from', $shippingMethodCode))
101
+ ) {
102
+ $price = 0;
103
+ } else {
104
+ $price = $rate['price'];
105
+ }
106
+ } elseif (empty($rate) && $request->getFreeShipping() === true) {
107
+ $request->setPackageValue($freePackageValue);
108
+ $request->setPackageQty($freeQty);
109
+ $rate = $this->getRate($request, $shippingMethodCode);
110
+
111
+ if (!empty($rate) && $rate['price'] >= 0) {
112
+ $price = 0;
113
+ }
114
+ } else {
115
+ $result->append($this->_getCarriersErrorMessage($shippingMethodCode));
116
+ continue;
117
+ }
118
+ }
119
+
120
+ $postCodeValidationResult = Mage::helper('bpost_shm')->validatePostcode($request->getDestCountryId(), $request->getDestPostcode());
121
+ if(($shippingMethodCode == 'bpost_homedelivery' || $shippingMethodCode == 'bpost_international') && $postCodeValidationResult != 'passed'){
122
+ $error = Mage::getModel('shipping/rate_result_error');
123
+ $error->setCarrier($this->_code);
124
+ $error->setCarrierTitle('Bpost ShippingManager');
125
+ $error->setData('error_message', Mage::helper('bpost_shm')->__('The Bpost shipping method "%s" is not available because your postal code is not correct.' .
126
+ ' For your country the format should be like "%s". Please correct the postal code in your shipping address.',$shippingMethodName, $postCodeValidationResult));
127
+ $result->append($error);
128
+ continue;
129
+ }
130
+
131
+ $saturdayDeliveryCost = $helper->formatSaturdayDeliveryCost($configHelper->getBpostShippingConfig("saturday_delivery_cost", Mage::app()->getStore()->getId()));
132
+ $saturdayDeliveryActiveByCarrier = $helper->formatSaturdayDeliveryCost($configHelper->getBpostCarriersConfig("saturday_delivery", $shippingMethodCode, Mage::app()->getStore()->getId()));
133
+ $ratePriceByMethod[$this->_code."_".$shippingMethodCode] = $price;
134
+
135
+ if(!$quote->getBpostDisableSaturdayDelivery() && $saturdayDeliveryActiveByCarrier) {
136
+ $shippingDates = $helper->getBpostShippingDates();
137
+ if(isset($shippingDates[$shippingMethodCode]) && $shippingDates[$shippingMethodCode]["is_saturday"] == 1){
138
+ $price = $price + $saturdayDeliveryCost;
139
+ $quote->setBpostSaturdayCostApplied(true)->save();
140
+ }
141
+ }
142
+
143
+ $method->setCarrier($this->_code);
144
+ $method->setMethod($shippingMethodCode);
145
+ $method->setMethodTitle($this->getBpostConfigData('name', $shippingMethodCode));
146
+ $method->setCarrierTitle('Bpost');
147
+ $method->setPrice($price);
148
+ $method->setCost($price);
149
+ $result->append($method);
150
+ }
151
+
152
+ if ($numberOfDisabledShippingMethods == 4) {
153
+ return false;
154
+ }
155
+
156
+ $checkoutSession = Mage::getSingleton('checkout/session');
157
+ $checkoutSession->setOriginalRatePrices($ratePriceByMethod);
158
+
159
+ return $result;
160
+ }
161
+
162
+ /**
163
+ * Function returns the current shipping method's error object
164
+ *
165
+ * @param $shippingMethodCode
166
+ * @return Mage_Shipping_Model_Rate_Result_Error
167
+ */
168
+ protected function _getCarriersErrorMessage($shippingMethodCode){
169
+ $error = Mage::getModel('shipping/rate_result_error');
170
+ $msg = Mage::getStoreConfig("carriers/$shippingMethodCode/specificerrmsg");
171
+
172
+ if($msg && $msg != ''){
173
+ $error->setData("error_message", $msg);
174
+ }
175
+
176
+ $error->setCarrier($this->_code);
177
+ $error->setCarrierTitle($this->getBpostConfigData('title', $shippingMethodCode));
178
+
179
+ return $error;
180
+ }
181
+
182
+ /**
183
+ * Get allowed bpost methods
184
+ *
185
+ * @return array
186
+ */
187
+ public function getAllowedMethods()
188
+ {
189
+ $allowedMethods = array(
190
+ 'bpost_homedelivery' => Mage::getStoreConfig('carriers/bpost_homedelivery/name', $this->getStore()),
191
+ 'bpost_international' => Mage::getStoreConfig('carriers/bpost_international/name', $this->getStore()),
192
+ 'bpost_parcellocker' => Mage::getStoreConfig('carriers/bpost_parcellocker/name', $this->getStore()),
193
+ 'bpost_pickuppoint' => Mage::getStoreConfig('carriers/bpost_pickuppoint/name', $this->getStore())
194
+ );
195
+
196
+ return $allowedMethods;
197
+ }
198
+
199
+ /**
200
+ * Get system config carrier information
201
+ *
202
+ * @param $field
203
+ * @param $code
204
+ * @return string
205
+ */
206
+ public function getBpostConfigData($field, $code)
207
+ {
208
+ if (empty($code)) {
209
+ return false;
210
+ }
211
+ $path = 'carriers/' . $code . '/' . $field;
212
+ return Mage::getStoreConfig($path, $this->getStore());
213
+ }
214
+
215
+ /**
216
+ * Get tracking result object.
217
+ *
218
+ * @param string $tracking_number
219
+ * @return Mage_Shipping_Model_Tracking_Result $tracking_result
220
+ */
221
+ public function getTrackingInfo($tracking_number)
222
+ {
223
+ $tracking_result = $this->getTracking($tracking_number);
224
+
225
+ if ($tracking_result instanceof Mage_Shipping_Model_Tracking_Result) {
226
+ $trackings = $tracking_result->getAllTrackings();
227
+ if (is_array($trackings) && count($trackings) > 0) {
228
+ return $trackings[0];
229
+ }
230
+ }
231
+ return false;
232
+ }
233
+
234
+ /**
235
+ * Get tracking Url
236
+ *
237
+ * @param string $tracking_number
238
+ * @return Mage_Shipping_Model_Tracking_Result
239
+ */
240
+ public function getTracking($tracking_number)
241
+ {
242
+ $collection = Mage::getResourceModel('sales/order_shipment_track_collection')
243
+ ->addFieldToFilter('track_number', $tracking_number)
244
+ ->addAttributeToSelect("order_id")
245
+ ->join('sales/order', 'order_id=`sales/order`.entity_id', array('increment_id'=>'increment_id', 'shipping_description' => 'shipping_description'), null,'left');
246
+ $orderId = $collection->getFirstItem()->getIncrementId();
247
+ $carrierTitle = $collection->getFirstItem()->getShippingDescription();
248
+ $tracking_result = Mage::getModel('shipping/tracking_result');
249
+ $tracking_status = Mage::getModel('shipping/tracking_result_status');
250
+ $localeExploded = explode('_', Mage::app()->getLocale()->getLocaleCode());
251
+ $tracking_status->setCarrier($this->_code);
252
+ $tracking_status->setCarrierTitle($carrierTitle);
253
+ $tracking_status->setTracking($tracking_number);
254
+
255
+ $trackDomainUrl = self::SHIPMENT_TRACK_DOMAIN;
256
+ $tracking_status->addData(
257
+ array(
258
+ 'status' => '<a target="_blank" href="'.$trackDomainUrl.'etr/light/performSearch.do?searchByCustomerReference=true&oss_language=' . $localeExploded[0] . '&customerReference=' . $orderId . '"><img src="' . Mage::getDesign()->getSkinUrl('images/bpost/bpost_logo_RGB72_M.png') . '" /> <br />' . Mage::helper('bpost_shm')->__('Click here to track your bpost shipments.') . '</a>'
259
+ )
260
+ );
261
+ $tracking_result->append($tracking_status);
262
+
263
+ return $tracking_result;
264
+ }
265
+
266
+ /**
267
+ * Make tracking available for Bpost shippingmethods.
268
+ *
269
+ * @return bool
270
+ */
271
+ public function isTrackingAvailable()
272
+ {
273
+ return true;
274
+ }
275
+
276
+ /**
277
+ * Make shipping labels not available as we provided our own method.
278
+ *
279
+ * @return bool
280
+ */
281
+ public function isShippingLabelsAvailable()
282
+ {
283
+ return false;
284
+ }
285
+
286
+ /**
287
+ * Check for available bpost shipping countries
288
+ *
289
+ * @param $request
290
+ * @param $shippingMethodCode
291
+ * @return bool
292
+ */
293
+ public function checkAvailableBpostShipCountries(Mage_Shipping_Model_Rate_Request $request, $shippingMethodCode)
294
+ {
295
+ $speCountriesAllow = (int)$this->getBpostConfigData('sallowspecific', $shippingMethodCode);
296
+ $bpostHelper = Mage::helper("bpost_shm/system_config");
297
+ $countryId = $request->getDestCountryId();
298
+
299
+ if ($speCountriesAllow == 1){
300
+ $allowedCountries = $bpostHelper->getBpostCarriersConfig("specificcountry", "bpost_international");
301
+ $availableCountries = explode(',',$allowedCountries);
302
+
303
+ if (!empty($availableCountries) && in_array($countryId, $availableCountries)) {
304
+ return true;
305
+ } else {
306
+ return false;
307
+ }
308
+ }
309
+
310
+ //we check on national shipping country Belgium
311
+ if(($shippingMethodCode === "bpost_homedelivery" ||
312
+ $shippingMethodCode === "bpost_parcellocker" ||
313
+ $shippingMethodCode === "bpost_pickuppoint") &&
314
+ $countryId != "BE"){
315
+ return false;
316
+ }
317
+
318
+ return true;
319
+ }
320
+
321
+ /**
322
+ * Get rate object for specific shipping method
323
+ *
324
+ * @param $request
325
+ * @param $shippingMethodCode
326
+ * @return array
327
+ */
328
+ public function getRate($request, $shippingMethodCode)
329
+ {
330
+ return Mage::getResourceModel('bpost_shm/tablerates_' . str_replace('bpost_','',$shippingMethodCode))->getRate($request);
331
+ }
332
+ }
app/code/community/Bpost/ShM/Model/Shipping/Geocode.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PHPro
5
+ *
6
+ * @package Bpost
7
+ * @subpackage ShM
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ /**
12
+ * Class Bpost_ShM_Model_Shipping_Geocode
13
+ */
14
+ class Bpost_ShM_Model_Shipping_Geocode
15
+ {
16
+ protected $address_line;
17
+ /**
18
+ * @var Bpost_ShM_Helper_Data
19
+ */
20
+ protected $success = false;
21
+ protected $xml;
22
+
23
+ /**
24
+ * Make the call to google geocode
25
+ * @param $gMapsAddress
26
+ * @param $latitude
27
+ * @param $longitude
28
+ * @return $this|boolean
29
+ */
30
+ public function callGoogleMaps($gMapsAddress, $latitude = false, $longitude = false)
31
+ {
32
+ $configHelper = Mage::helper("bpost_shm/system_config");
33
+ $key = $configHelper->getBpostShippingConfig("server_api_key");
34
+
35
+ if($gMapsAddress) {
36
+ $this->address_line = $gMapsAddress;
37
+ $url = 'https://maps.googleapis.com/maps/api/geocode/xml?address=' . urlencode($gMapsAddress);
38
+ } else {
39
+ $coords = $latitude.','.$longitude;
40
+ $this->address_line = $coords;
41
+ $url = 'https://maps.googleapis.com/maps/api/geocode/xml?latlng=' . urlencode($coords);
42
+ }
43
+ $url .= '&language=nl';
44
+ if($key) {
45
+ $url .= '&key='.$key;
46
+ }
47
+ try{
48
+ $xml = simplexml_load_file($url);
49
+ switch($xml->status){
50
+ case "OK":
51
+ $this->success = true;
52
+ $this->xml = $xml;
53
+ Mage::helper('bpost_shm')->log("Geocode: OK ".$this->address_line." to xml" ,Zend_Log::DEBUG);
54
+ return $this;
55
+ break;
56
+ case "ZERO_RESULTS":
57
+ Mage::helper('bpost_shm')->log("Geocode: no results found for ".$this->address_line,Zend_Log::DEBUG);
58
+ return false;
59
+ break;
60
+ case "OVER_QUERY_LIMIT":
61
+ Mage::helper('bpost_shm')->log("Geocode: Over Query Limit. check your api console",Zend_Log::WARN);
62
+ return false;
63
+ break;
64
+ case "REQUEST_DENIED":
65
+ Mage::helper('bpost_shm')->log("Geocode: Request denied",Zend_Log::WARN);
66
+ return false;
67
+ break;
68
+ case "INVALID_REQUEST":
69
+ Mage::helper('bpost_shm')->log("Geocode: invalid request , address missing?",Zend_Log::WARN);
70
+ return false;
71
+ break;
72
+ case "UNKNOWN_ERROR":
73
+ Mage::helper('bpost_shm')->log("Geocode: unknown Error",Zend_Log::WARN);
74
+ return false;
75
+ break;
76
+ default:
77
+ Mage::helper('bpost_shm')->log("Geocode: unknown Status",Zend_Log::WARN);
78
+ return false;
79
+ break;
80
+ }
81
+ }catch (Exception $e){
82
+ Mage::helper('bpost_shm')->log("Geocode: ". $e->getMessage() ,Zend_Log::ERR);
83
+ return false;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Extract useful address information from the geocode xml
89
+ * @return string|boolean
90
+ */
91
+ protected function _extractFromAdress($components, $type)
92
+ {
93
+ foreach ($components->address_component as $component) {
94
+ if($component->type == $type) {
95
+ return $component->long_name;
96
+ }
97
+ }
98
+ return false;
99
+ }
100
+
101
+ /**
102
+ * Get the coordinates from the xml
103
+ * @return array|boolean
104
+ */
105
+ public function getLatLng()
106
+ {
107
+ if($this->success){
108
+ $lat = (string)$this->xml->result[0]->geometry->location->lat;
109
+ $lng = (string)$this->xml->result[0]->geometry->location->lng;
110
+
111
+ if(isset($lat) && isset($lng)) {
112
+ return array('lat' => $lat, 'lng' => $lng);
113
+ }
114
+ }
115
+ return false;
116
+ }
117
+
118
+ /**
119
+ * Get the postal code/city from the xml
120
+ * @return string|boolean
121
+ */
122
+ public function getPostalCode()
123
+ {
124
+ if($this->success){
125
+ $postalCode = $this->_extractFromAdress($this->xml->result[0], 'postal_code');
126
+ $locality = $this->_extractFromAdress($this->xml->result[0], 'locality');
127
+
128
+ if($postalCode) {
129
+ return (string)$postalCode;
130
+ } elseif($locality) {
131
+ return (string)$locality;
132
+ }
133
+ }
134
+ return false;
135
+ }
136
+ }
app/code/community/Bpost/ShM/Model/Shipping/Rate/Result.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Shipping_Rate_Result extends Mage_Shipping_Model_Rate_Result
3
+ {
4
+ /**
5
+ * we create an empty sort function
6
+ * this way our shipping rates will keep their sort order
7
+ */
8
+ public function sortRatesByPrice(){
9
+ return;
10
+ }
11
+ }
app/code/community/Bpost/ShM/Model/System/Config/Source/Country.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ /**
10
+ * Class Bpost_ShM_Model_System_Config_Source_Country
11
+ */
12
+ class Bpost_ShM_Model_System_Config_Source_Country
13
+ {
14
+ protected $_options;
15
+
16
+ public function toOptionArray()
17
+ {
18
+ if (!$this->_options) {
19
+ $this->_options = Mage::getResourceModel('bpost_shm/country_collection')->loadData()->toOptionArray(false);
20
+ }
21
+
22
+ $options = $this->_options;
23
+
24
+ return $options;
25
+ }
26
+
27
+ }
app/code/community/Bpost/ShM/Model/System/Config/Source/Product.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ /**
10
+ * Class Bpost_ShM_Model_System_Config_Source_Ratetypes
11
+ */
12
+ class Bpost_ShM_Model_System_Config_Source_Product
13
+ {
14
+ /**
15
+ * Options getter.
16
+ * Returns an option array for Shipping cost handler.
17
+ *
18
+ * @return array
19
+ *
20
+ */
21
+ public function toOptionArray()
22
+ {
23
+ return array(
24
+ array('value' => 1, 'label' => Mage::helper('bpost_shm')->__('World Express Pro')),
25
+ array('value' => 0, 'label' => Mage::helper('bpost_shm')->__('World Business')),
26
+ );
27
+ }
28
+
29
+ /**
30
+ * Get options in "key-value" format.
31
+ * Returns an array for Shipping cost handler. (Magento basically expects both functions)
32
+ *
33
+ * @return array
34
+ *
35
+ */
36
+ public function toArray()
37
+ {
38
+ return array(
39
+ 0 => Mage::helper('bpost_shm')->__('World Business'),
40
+ 1 => Mage::helper('bpost_shm')->__('World Express Pro'),
41
+ );
42
+ }
43
+
44
+ }
app/code/community/Bpost/ShM/Model/System/Config/Source/Ratetypes.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ /**
10
+ * Class Bpost_ShM_Model_System_Config_Source_Ratetypes
11
+ */
12
+ class Bpost_ShM_Model_System_Config_Source_Ratetypes
13
+ {
14
+ /**
15
+ * Options getter.
16
+ * Returns an option array for Shipping cost handler.
17
+ *
18
+ * @return array
19
+ *
20
+ */
21
+ public function toOptionArray()
22
+ {
23
+ return array(
24
+ array('value' => 1, 'label' => Mage::helper('bpost_shm')->__('Table Rates')),
25
+ array('value' => 0, 'label' => Mage::helper('bpost_shm')->__('Flat Rate')),
26
+ );
27
+ }
28
+
29
+ /**
30
+ * Get options in "key-value" format.
31
+ * Returns an array for Shipping cost handler. (Magento basically expects both functions)
32
+ *
33
+ * @return array
34
+ *
35
+ */
36
+ public function toArray()
37
+ {
38
+ return array(
39
+ 0 => Mage::helper('bpost_shm')->__('Flat Rate'),
40
+ 1 => Mage::helper('bpost_shm')->__('Table Rates'),
41
+ );
42
+ }
43
+
44
+ }
app/code/community/Bpost/ShM/Model/System/Config/Source/Weightunit.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @subpackage Shipping
6
+ * @category Checkout
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ /**
11
+ * Class Bpost_ShM_Model_System_Config_Source_Weightunit
12
+ */
13
+ class Bpost_ShM_Model_System_Config_Source_Weightunit
14
+ {
15
+ /**
16
+ * Options getter.
17
+ * Returns an option array for unit weight to pass to the webservice.
18
+ *
19
+ * @return array
20
+ *
21
+ */
22
+ public function toOptionArray()
23
+ {
24
+ return array(
25
+ array('value' => 1000, 'label' => Mage::helper('bpost_shm')->__('kg')),
26
+ array('value' => 1, 'label' => Mage::helper('bpost_shm')->__('g')),
27
+ array('value' => 453.592, 'label' => Mage::helper('bpost_shm')->__('lb')),
28
+ );
29
+ }
30
+
31
+ /**
32
+ * Get options in "key-value" format.
33
+ * Returns an array for unit weight to pass to the webservice. (Magento basically expects both functions)
34
+ *
35
+ * @return array
36
+ *
37
+ */
38
+ public function toArray()
39
+ {
40
+ return array(
41
+ '1000' => Mage::helper('bpost_shm')->__('kg'),
42
+ '1' => Mage::helper('bpost_shm')->__('g'),
43
+ '453.592' => Mage::helper('bpost_shm')->__('lb')
44
+ );
45
+ }
46
+
47
+ }
app/code/community/Bpost/ShM/Model/Tablerates/Homedelivery.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Tablerates_Homedelivery extends Mage_Core_Model_Abstract{
3
+
4
+ protected function _construct()
5
+ {
6
+ $this->_init('bpost_shm/tablerates_homedelivery');
7
+ }
8
+
9
+ }
app/code/community/Bpost/ShM/Model/Tablerates/International.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Tablerates_International extends Mage_Core_Model_Abstract{
3
+
4
+ protected function _construct()
5
+ {
6
+ $this->_init('bpost_shm/tablerates_international');
7
+ }
8
+
9
+ }
app/code/community/Bpost/ShM/Model/Tablerates/Parcellocker.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Tablerates_Parcellocker extends Mage_Core_Model_Abstract{
3
+
4
+ protected function _construct()
5
+ {
6
+ $this->_init('bpost_shm/tablerates_parcellocker');
7
+ }
8
+
9
+ }
app/code/community/Bpost/ShM/Model/Tablerates/Pickuppoint.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Model_Tablerates_Pickuppoint extends Mage_Core_Model_Abstract{
3
+
4
+ protected function _construct()
5
+ {
6
+ $this->_init('bpost_shm/tablerates_pickuppoint');
7
+ }
8
+
9
+ }
app/code/community/Bpost/ShM/controllers/Adminhtml/Bpost/ShM/AllOrdersController.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Adminhtml_Bpost_ShM_AllOrdersController extends Bpost_ShM_Controller_ShM_Order
3
+ {
4
+ /**
5
+ * Load indexpage of this controller.
6
+ */
7
+ public function indexAction()
8
+ {
9
+ Mage::getSingleton('core/session')->setBpostReturn(0);
10
+ $this->_title($this->__('bpost'))->_title($this->__('Bpost Orders'));
11
+ $this->loadLayout();
12
+ $this->_setActiveMenu('sales/bpost_all_orders');
13
+ $this->_addContent($this->getLayout()->createBlock('bpost_shm/adminhtml_sales_allOrders'));
14
+ $this->renderLayout();
15
+ }
16
+
17
+ /**
18
+ * Load the grid.
19
+ */
20
+ public function gridAction()
21
+ {
22
+ $this->loadLayout();
23
+ $this->getResponse()->setBody(
24
+ $this->getLayout()->createBlock('bpost_shm/adminhtml_sales_allOrders_grid')->toHtml()
25
+ );
26
+ }
27
+
28
+ protected function _isAllowed()
29
+ {
30
+ $configHelper = Mage::helper("bpost_shm/system_config");
31
+ $manageLabelsWithMagento = $configHelper->getBpostShippingConfig("manage_labels_with_magento");
32
+
33
+ if(!$manageLabelsWithMagento){
34
+ $this->_getSession()->addNotice('Please enable the "Use Magento to manage labels" setting first under "system -> configuration -> shipping settings -> Bpost Shipping Manager" if you want to use this functionality.');
35
+ return false;
36
+ }
37
+
38
+ return Mage::getSingleton('admin/session')->isAllowed('sales/bpost_all_orders');
39
+ }
40
+
41
+
42
+ /**
43
+ * Call this to send an email with the bpost template.
44
+ * This calls the model to handle emails the magento way.
45
+ * Logs all errors in try catch.
46
+ */
47
+ public function sendEmailAction()
48
+ {
49
+ $returnId = $this->getRequest()->getParam('return_id');
50
+ try {
51
+ $email = Mage::getModel('bpost_shm/returnlabel')->sendEmail($returnId);
52
+ } catch (Exception $e) {
53
+ Mage::getSingleton('core/session')->addError($e->getMessage());
54
+ $this->_redirectReferer();
55
+ return $this;
56
+ }
57
+ $message = Mage::helper('bpost_shm')->__("The email with return label has been sent to %s.", $email);
58
+ Mage::getSingleton('core/session')->addSuccess($message);
59
+ $this->_redirectReferer();
60
+ return $this;
61
+ }
62
+
63
+ }
64
+
app/code/community/Bpost/ShM/controllers/Adminhtml/Bpost/ShM/ConfigController.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Adminhtml_Bpost_ShM_ConfigController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ /**
5
+ * renders the bpost information popup
6
+ */
7
+ public function informationPopupAction(){
8
+ $this->loadLayout();
9
+ $this->renderLayout();
10
+ }
11
+
12
+ /**
13
+ * renders the bpost grid information popup when labels are generated
14
+ */
15
+ public function gridInformationPopupAction(){
16
+ $this->loadLayout();
17
+ $this->renderLayout();
18
+ }
19
+
20
+ /**
21
+ * action is used in for showing an example screenshot of how the module will look like.
22
+ */
23
+ public function screenshotPopupAction(){
24
+ $this->loadLayout();
25
+
26
+ //because Mage::getEdition will not work in all Magento versions,
27
+ //we simple check on the filepath enterprise
28
+ //if exists, enterprise is running
29
+
30
+ $appPath = Mage::getBaseDir('app');
31
+ $enterprisePath = $appPath.DS."code".DS."core".DS."Enterprise";
32
+
33
+ $ioFile = new Varien_Io_File();
34
+ try{
35
+ $ioFile->cd($enterprisePath);
36
+
37
+ //get enterprise screenshot
38
+ $imagePath = Mage::getDesign()->getSkinUrl("images/bpost/ee-screenshot.png");
39
+ }catch(Exception $e){
40
+ //get community screenshot
41
+ $imagePath = Mage::getDesign()->getSkinUrl("images/bpost/ce-screenshot.png");
42
+ }
43
+
44
+ $data = array("image_path" => $imagePath, "width" => "600px");
45
+
46
+ $this->getLayout()->getBlock("screenshot.popup")->setData($data);
47
+ $this->renderLayout();
48
+ }
49
+
50
+ /**
51
+ * @throws Mage_Core_Exception
52
+ */
53
+ public function exportTableratesAction(){
54
+ $request = $this->getRequest();
55
+ $fileName = $request->getParam('filename');
56
+
57
+ /** @var $gridBlock Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid */
58
+ $gridBlock = $this->getLayout()->createBlock('bpost_shm/adminhtml_shipping_carrier_bpost_tablerate_' . $request->getParam('method') . '_grid');
59
+ $website = Mage::app()->getWebsite($this->getRequest()->getParam('website'));
60
+ if ($this->getRequest()->getParam('conditionName')) {
61
+ $conditionName = $this->getRequest()->getParam('conditionName');
62
+ } else {
63
+ $conditionName = $website->getConfig('carriers/bpost_parcellocker/table_rate_condition');
64
+ }
65
+ $gridBlock->setWebsiteId($website->getId())->setConditionName($conditionName);
66
+ $content = $gridBlock->getCsvFile();
67
+ $this->_prepareDownloadResponse($fileName, $content);
68
+ }
69
+
70
+
71
+ /**
72
+ * checks if authentication is valid and updates the country codes for international shipping
73
+ */
74
+ public function importCountriesByApiAction(){
75
+
76
+ $session = Mage::getSingleton("adminhtml/session");
77
+ $configHelper = Mage::helper("bpost_shm/system_config");
78
+
79
+ try{
80
+ /** @var Bpost_ShM_Model_Api $api */
81
+ $api = Mage::getModel( 'bpost_shm/api', true );
82
+ $apiResponse = $api->getProductConfig();
83
+
84
+ if(!$apiResponse) {
85
+ Mage::throwException("Failed to authenticate with bpost, please check your credentials.");
86
+ }
87
+
88
+ $xml = simplexml_load_string($apiResponse->getBody());
89
+ $product = $configHelper->getBpostCarriersConfig("product", "bpost_international", 0);
90
+
91
+ if(!$product){
92
+ $product = "bpack World Business";
93
+ }else{
94
+ $product = "bpack World Express Pro";
95
+ }
96
+
97
+ $countryCodes = array();
98
+ foreach ($xml->deliveryMethod as $deliveryMethodData) {
99
+ if($deliveryMethodData->product["name"] == $product){
100
+
101
+ $productData = $deliveryMethodData->product;
102
+ foreach($productData->price as $priceData){
103
+ $countryCode = (string)$priceData["countryIso2Code"];
104
+ $countryCodes[] = $countryCode;
105
+ }
106
+ }
107
+ }
108
+
109
+ if(!empty($countryCodes)){
110
+ $countryModel = Mage::getModel("bpost_shm/country");
111
+ $countryResourceModel = Mage::getResourceModel('bpost_shm/country');
112
+ $countryCollection = $countryModel->getCollection();
113
+
114
+ //we truncate our table first by calling our own truncate function
115
+ $countryResourceModel->truncateTable();
116
+
117
+ //then we populate bpost_country with our last data
118
+ foreach($countryCodes as $countryCode){
119
+ $itemModel = Mage::getModel("bpost_shm/country");
120
+ $itemModel->setData(array("country_code" => $countryCode));
121
+ $countryCollection->addItem($itemModel);
122
+ }
123
+
124
+ $countryCollection->save();
125
+
126
+ }else{
127
+ $session->addNotice($configHelper->__("No bpost product configuration found for %s. Please check your bpost shipping manager for international delivery.", $product));
128
+ }
129
+
130
+ $session->addSuccess($configHelper->__("Successfully authenticated with bpost."));
131
+ }catch(Exception $e){
132
+ $session->addError($configHelper->__($e->getMessage()));
133
+ }
134
+
135
+ $this->_redirect("adminhtml/system_config/edit", array("section" => "carriers"));
136
+ }
137
+
138
+
139
+ /**
140
+ * @return bool
141
+ */
142
+ protected function _isAllowed()
143
+ {
144
+ return Mage::getSingleton('admin/session')->isAllowed('system/config_bpost_shm');
145
+ }
146
+ }
app/code/community/Bpost/ShM/controllers/Adminhtml/Bpost/ShM/DownloadController.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Bpost_ShM_Adminhtml_Bpost_ShM_DownloadController
5
+ */
6
+ class Bpost_ShM_Adminhtml_Bpost_ShM_DownloadController extends Mage_Adminhtml_Controller_Action
7
+ {
8
+
9
+ /**
10
+ * Fetches the label and puts it in a download response.
11
+ */
12
+ public function labelAction()
13
+ {
14
+ $request = $this->getRequest();
15
+ $orderId = $request->getParam('order_id');
16
+ $ioFile = new Varien_Io_File();
17
+ $bpostMediaFilePath = Mage::getBaseDir('media') . Bpost_ShM_Model_Adminhtml_Bpostgrid::MEDIA_LABEL_PATH;
18
+ $shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection');
19
+
20
+ $order = false;
21
+ $pdfDownloadName = "";
22
+
23
+ if($orderId){
24
+ //get shipments by order
25
+ $order = Mage::getModel("sales/order")->load($orderId);
26
+ $pdfDownloadName = $order->getIncrementId().".pdf";
27
+
28
+ $shipmentCollection->addFieldToFilter('order_id', $orderId);
29
+ $shipmentCollection->addFieldToFilter('bpost_label_path', array("neq" => ""));
30
+ }else{
31
+ $shipmentId = $request->getParam('shipment_id');
32
+ $shipmentCollection->addFieldToFilter('entity_id', $shipmentId);
33
+ }
34
+
35
+ $pdfMerged = new Zend_Pdf();
36
+ $shipment = $shipmentCollection->getFirstItem();
37
+
38
+ $merged = false;
39
+ if(!$order){
40
+ $order = $shipment->getOrder();
41
+ }
42
+
43
+ if(!$orderId){
44
+ $pdfDownloadName = $shipment->getIncrementId().".pdf";
45
+
46
+ if ($shipment->getBpostLabelPath() == "") {
47
+ $message = Mage::helper('bpost_shm')->__("No label generated yet - please perform the ‘Generate Label and Complete’ action from the overview.");
48
+ Mage::getSingleton('core/session')->addError($message);
49
+ $this->_redirect('*/sales_order_shipment/view/' , array('shipment_id' => $shipmentId));
50
+ return;
51
+ }
52
+ }
53
+
54
+ if ($shipment->getBpostLabelPath() != "") {
55
+ $pdfNames = explode(":", $shipment->getBpostLabelPath());
56
+
57
+ foreach($pdfNames as $pdfName){
58
+ $pdfPath = $bpostMediaFilePath . $pdfName;
59
+
60
+ if($ioFile->fileExists($pdfPath)){
61
+ $tmpPdf = Zend_Pdf::load($pdfPath);
62
+
63
+ foreach ($tmpPdf->pages as $page) {
64
+ $clonedPage = clone $page;
65
+ $pdfMerged->pages[] = $clonedPage;
66
+ }
67
+
68
+ $merged = true;
69
+ }
70
+ }
71
+ }
72
+
73
+ if($merged){
74
+ $shipmentCollection->setDataToAll("bpost_label_exported", true);
75
+ $shipmentCollection->save();
76
+ }
77
+
78
+ if(!count($pdfMerged->pages)) {
79
+ $this->_getSession()->addError("Pdf(s) could not be found.");
80
+ $this->_redirectUrl($this->_getRefererUrl());
81
+ return;
82
+ }else{
83
+ $order->setBpostLabelExported(1)->save();
84
+ }
85
+
86
+ $this->_prepareDownloadResponse($pdfDownloadName, $pdfMerged->render(), 'application/pdf');
87
+ }
88
+
89
+
90
+ /**
91
+ * return label action creates a return label
92
+ */
93
+ public function returnLabelAction(){
94
+
95
+ try{
96
+ $orderId = $this->getRequest()->getParam('order_id');
97
+ $bpostHelper = Mage::helper('bpost_shm');
98
+
99
+ if(!$orderId){
100
+ Mage::throwException('No order id found to process.');
101
+ }
102
+
103
+ $returnLabelModel = Mage::getModel('bpost_shm/returnlabel');
104
+ $returnLabelModel->generateLabelAndSave($orderId);
105
+
106
+ $this->_getSession()->addSuccess($bpostHelper->__("Your return has been generated and is available under -bpost Return labels- in this order."));
107
+ }catch(Exception $e){
108
+ $this->_getSession()->addError($bpostHelper->__($e->getMessage()));
109
+ }
110
+
111
+ $this->_redirect('*/sales_order/view', array('order_id' => $orderId));
112
+ }
113
+
114
+
115
+ /**
116
+ * @return mixed
117
+ */
118
+ protected function _isAllowed()
119
+ {
120
+ return Mage::getSingleton('admin/session')->isAllowed('sales/bpost_download_labels');
121
+ }
122
+ }
app/code/community/Bpost/ShM/controllers/Adminhtml/Bpost/ShM/PendingOrdersController.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_Adminhtml_Bpost_ShM_PendingOrdersController extends Bpost_ShM_Controller_ShM_Order
3
+ {
4
+ /**
5
+ * Load indexpage of this controller.
6
+ */
7
+ public function indexAction()
8
+ {
9
+ Mage::getSingleton('core/session')->setBpostReturn(0);
10
+ $this->_title($this->__('bpost'))->_title($this->__('Bpost Orders'));
11
+ $this->loadLayout();
12
+ $this->_setActiveMenu('sales/bpost_pending_orders');
13
+ $this->_addContent($this->getLayout()->createBlock('bpost_shm/adminhtml_sales_pendingOrders'));
14
+ $this->renderLayout();
15
+ }
16
+
17
+ /**
18
+ * Load the grid.
19
+ */
20
+ public function gridAction()
21
+ {
22
+ $this->loadLayout();
23
+ $this->getResponse()->setBody(
24
+ $this->getLayout()->createBlock('bpost_shm/adminhtml_sales_pendingOrders_grid')->toHtml()
25
+ );
26
+ }
27
+
28
+ protected function _isAllowed()
29
+ {
30
+ $configHelper = Mage::helper("bpost_shm/system_config");
31
+ $manageLabelsWithMagento = $configHelper->getBpostShippingConfig("manage_labels_with_magento");
32
+
33
+ if(!$manageLabelsWithMagento){
34
+ $this->_getSession()->addNotice('Please enable the "Use Magento to manage labels" setting first under "system -> configuration -> shipping settings -> Bpost Shipping Manager" if you want to use this functionality.');
35
+ return false;
36
+ }
37
+
38
+ return Mage::getSingleton('admin/session')->isAllowed('sales/bpost_pending_orders');
39
+ }
40
+ }
41
+
app/code/community/Bpost/ShM/controllers/AjaxController.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShM_AjaxController extends Mage_Core_Controller_Front_Action {
3
+
4
+ public function indexAction() {
5
+ $this->loadLayout();
6
+ $this->renderLayout();
7
+ }
8
+
9
+ /**
10
+ * Return a list of all bpost spots
11
+ */
12
+ public function getwindowAction() {
13
+ $request = $this->getRequest();
14
+ $isAjax = $request->isAjax();
15
+
16
+ if ($isAjax) {
17
+ $params = $request->getParams();
18
+
19
+ if(isset($params["pointType"])){
20
+ $apiCall = Mage::helper("bpost_shm")->getBpostSpots($params);
21
+ }else{
22
+ //make call and check if it returns an error.
23
+ $apiCall = Mage::helper("bpost_shm")->getBpostSpots();
24
+ }
25
+
26
+ $error = array();
27
+ $xml = simplexml_load_string($apiCall['poiList']);
28
+ $coordinates = $apiCall['coordinates'];
29
+
30
+ try{
31
+ $poiList = $xml->PoiList;
32
+ }catch (Exception $e){
33
+ Mage::helper("bpost_shm")->log("Webservice: not expected result returned:" . $e->getMessage(), Zend_Log::WARN);
34
+ $poiList = "";
35
+ $error[] = Mage::helper('bpost_shm')->__("Sorry, there was a problem contacting bpost, please contact the store owner for support.");
36
+ }
37
+
38
+ $payloadFull = array("error" => $error, "poilist" => $poiList, "coordinates" => $coordinates);
39
+ $this->getResponse()->setHeader('Content-type', 'application/json');
40
+ $this->getResponse()->setBody(json_encode($payloadFull));
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Return opening hours of a bpost spot
46
+ */
47
+ public function gethoursAction() {
48
+ $request = $this->getRequest();
49
+ $isAjax = $request->isAjax();
50
+
51
+ if ($isAjax) {
52
+ $error = array();
53
+ $params = $request->getParams();
54
+
55
+ $id = isset($params["id"]) && is_numeric($params["id"]) ? $params["id"] : false;
56
+ $type = isset($params["type"]) && is_numeric($params["type"]) ? $params["type"] : false;
57
+ $spots = isset($params["spots"]) ? json_decode($params["spots"]) : false;
58
+
59
+ if($id && $type) {
60
+ $apiCall = Mage::helper('bpost_shm')->getBpostOpeningHours($id, $type);
61
+
62
+ $xml = simplexml_load_string($apiCall);
63
+
64
+ try {
65
+ $openingHours = $xml->Poi->Record->Hours;
66
+ } catch (Exception $e) {
67
+ Mage::helper("bpost_shm")->log("Webservice: not expected result returned:" . $e->getMessage(), Zend_Log::WARN);
68
+ $openingHours = "";
69
+ $error[] = Mage::helper('bpost_shm')->__("Sorry, there was a problem contacting bpost, please contact the store owner for support.");
70
+ }
71
+
72
+ $payloadFull = array("error" => $error, "hours" => $openingHours);
73
+
74
+ } elseif(is_array($spots)) {
75
+ foreach ($spots as $spot) {
76
+ $id = $spot->id;
77
+ $type = $spot->type;
78
+
79
+ $apiCall = Mage::helper('bpost_shm')->getBpostOpeningHours($id, $type);
80
+
81
+ $xml = simplexml_load_string($apiCall);
82
+
83
+ try {
84
+ $openingHours = $xml->Poi->Record->Hours;
85
+ } catch (Exception $e) {
86
+ Mage::helper("bpost_shm")->log("Webservice: not expected result returned:" . $e->getMessage(), Zend_Log::WARN);
87
+ $openingHours = "";
88
+ $error[] = Mage::helper('bpost_shm')->__("Sorry, there was a problem contacting bpost, please contact the store owner for support.");
89
+ }
90
+
91
+ $payloadFull[$id] = array("error" => $error, "hours" => $openingHours);
92
+ }
93
+ }
94
+
95
+ $this->getResponse()->setHeader('Content-type', 'application/json');
96
+ $this->getResponse()->setBody(json_encode($payloadFull));
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Return opening dates of a bpost spot
102
+ */
103
+ public function getdatesAction() {
104
+ $request = $this->getRequest();
105
+ $isAjax = $request->isAjax();
106
+
107
+ if ($isAjax) {
108
+ $id = $request->getPost("id");
109
+ $type = $request->getPost("type");
110
+
111
+ if(($id && $type)) {
112
+ $apiCall = Mage::helper('bpost_shm')->getBpostOpeningHours($id, $type);
113
+ $error = array();
114
+ $weekDays = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
115
+ $closedOn = array();
116
+
117
+ $xml = simplexml_load_string($apiCall);
118
+
119
+ try{
120
+ $openingHours = $xml->Poi->Record->Hours;
121
+
122
+ foreach($weekDays as $weekDay) {
123
+ $day = $openingHours->$weekDay;
124
+
125
+ if($day) {
126
+ if(empty($day->AMOpen[0]) && empty($day->AMClose[0]) && empty($day->PMOpen[0]) && empty($day->PMClose[0])) {
127
+ //assume the point is closed for the day
128
+ array_push($closedOn, $weekDay);
129
+ }
130
+ }
131
+ }
132
+
133
+ $shippingDates = Mage::helper('bpost_shm')->getBpostShippingDates($closedOn);
134
+
135
+ }catch (Exception $e){
136
+ Mage::helper("bpost_shm")->log("Webservice: not expected result returned:" . $e->getMessage(), Zend_Log::WARN);
137
+ $shippingDates = "";
138
+ $error[] = Mage::helper('bpost_shm')->__("Sorry, there was a problem contacting bpost, please contact the store owner for support.");
139
+ }
140
+
141
+ $payloadFull = array("error" => $error, "dates" => $shippingDates);
142
+ $this->getResponse()->setHeader('Content-type', 'application/json');
143
+ $this->getResponse()->setBody(json_encode($payloadFull));
144
+ }
145
+ }
146
+ }
147
+ }
app/code/community/Bpost/ShM/etc/adminhtml.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <sales>
5
+ <children>
6
+ <bpost_orders module="bpost_shm" translate="title">
7
+ <title>bpost Orders</title>
8
+ <sort_order>15</sort_order>
9
+ <children>
10
+ <bpost_all_orders>
11
+ <title>All bpost orders</title>
12
+ <sort_order>1</sort_order>
13
+ <action>adminhtml/bpost_shM_allOrders/index</action>
14
+ </bpost_all_orders>
15
+ <bpost_pending_orders>
16
+ <title>Pending bpost orders</title>
17
+ <sort_order>2</sort_order>
18
+ <action>adminhtml/bpost_shM_pendingOrders/index</action>
19
+ </bpost_pending_orders>
20
+ </children>
21
+ </bpost_orders>
22
+ </children>
23
+ </sales>
24
+ </menu>
25
+ <acl>
26
+ <resources>
27
+ <all>
28
+ <title>Allow Everything</title>
29
+ </all>
30
+ <admin>
31
+ <children>
32
+ <sales>
33
+ <children>
34
+ <bpost_orders translate="title">
35
+ <title>Bpost orders</title>
36
+ <sort_order>1</sort_order>
37
+ <children>
38
+ <bpost_all_orders>
39
+ <title>All bpost orders</title>
40
+ <sort_order>1</sort_order>
41
+ </bpost_all_orders>
42
+ <bpost_pending_orders>
43
+ <title>Pending bpost orders</title>
44
+ <sort_order>1</sort_order>
45
+ </bpost_pending_orders>
46
+ <bpost_download_labels>
47
+ <title>Download bpost labels</title>
48
+ <sort_order>1</sort_order>
49
+ </bpost_download_labels>
50
+ </children>
51
+ </bpost_orders>
52
+ </children>
53
+ </sales>
54
+
55
+ <system>
56
+ <children>
57
+ <config>
58
+ <children>
59
+ <bpost_shm translate="title" module="bpost_shm">
60
+ <title>Bpost - Shipping Manager</title>
61
+ <sort_order>1</sort_order>
62
+ </bpost_shm>
63
+ </children>
64
+ </config>
65
+ </children>
66
+ </system>
67
+ </children>
68
+ </admin>
69
+ </resources>
70
+ </acl>
71
+ </config>
app/code/community/Bpost/ShM/etc/config.xml ADDED
@@ -0,0 +1,397 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Bpost_ShM>
5
+ <version>0.1.8</version>
6
+ </Bpost_ShM>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <bpost_shm>
11
+ <class>Bpost_ShM_Block</class>
12
+ </bpost_shm>
13
+ </blocks>
14
+
15
+ <models>
16
+ <bpost_shm>
17
+ <class>Bpost_ShM_Model</class>
18
+ <resourceModel>bpost_shm_resource</resourceModel>
19
+ </bpost_shm>
20
+ <bpost_shm_resource>
21
+ <class>Bpost_ShM_Model_Resource</class>
22
+ <entities>
23
+ <bpost_tablerates_homedelivery>
24
+ <table>bpost_tablerates_homedelivery</table>
25
+ </bpost_tablerates_homedelivery>
26
+
27
+ <bpost_tablerates_international>
28
+ <table>bpost_tablerates_international</table>
29
+ </bpost_tablerates_international>
30
+
31
+ <bpost_tablerates_pickuppoint>
32
+ <table>bpost_tablerates_pickuppoint</table>
33
+ </bpost_tablerates_pickuppoint>
34
+
35
+ <bpost_tablerates_parcellocker>
36
+ <table>bpost_tablerates_parcellocker</table>
37
+ </bpost_tablerates_parcellocker>
38
+
39
+ <returnlabel>
40
+ <table>bpost_shipping_returnlabel</table>
41
+ </returnlabel>
42
+
43
+ <bpost_country>
44
+ <table>bpost_country</table>
45
+ </bpost_country>
46
+
47
+ <bpost_holidays>
48
+ <table>bpost_holidays</table>
49
+ </bpost_holidays>
50
+ </entities>
51
+ </bpost_shm_resource>
52
+ </models>
53
+
54
+ <resources>
55
+ <bpost_shm_setup>
56
+ <setup>
57
+ <module>Bpost_ShM</module>
58
+ </setup>
59
+ <connection>
60
+ <use>core_setup</use>
61
+ </connection>
62
+ </bpost_shm_setup>
63
+ <bpost_shm_write>
64
+ <connection>
65
+ <use>core_write</use>
66
+ </connection>
67
+ </bpost_shm_write>
68
+ <bpost_shm_read>
69
+ <connection>
70
+ <use>core_read</use>
71
+ </connection>
72
+ </bpost_shm_read>
73
+ </resources>
74
+
75
+ <helpers>
76
+ <bpost_shm>
77
+ <class>Bpost_ShM_Helper</class>
78
+ </bpost_shm>
79
+ </helpers>
80
+
81
+ <template>
82
+ <email>
83
+ <bpost_shm_errorhandling_create_order_email_template translate="label" module="bpost_shm">
84
+ <label>bpost - errorhandling create order</label>
85
+ <file>bpost/errorhandling_create_order.html</file>
86
+ <type>html</type>
87
+ </bpost_shm_errorhandling_create_order_email_template>
88
+
89
+ <bpost_returnlabel_email_template translate="label" module="bpost_shm">
90
+ <label>bpost - returnlabel Email</label>
91
+ <file>bpost/returnlabel.html</file>
92
+ <type>html</type>
93
+ </bpost_returnlabel_email_template>
94
+ </email>
95
+ </template>
96
+
97
+ <fieldsets>
98
+ <sales_convert_quote>
99
+ <bpost_notification_sms><to_order>*</to_order></bpost_notification_sms>
100
+ <bpost_notification_email><to_order>*</to_order></bpost_notification_email>
101
+ <bpost_reduced_mobility><to_order>*</to_order></bpost_reduced_mobility>
102
+ <bpost_delivery_date><to_order>*</to_order></bpost_delivery_date>
103
+ <bpost_drop_date><to_order>*</to_order></bpost_drop_date>
104
+ </sales_convert_quote>
105
+
106
+ <sales_convert_order>
107
+ <bpost_notification_sms><to_quote>*</to_quote></bpost_notification_sms>
108
+ <bpost_notification_email><to_quote>*</to_quote></bpost_notification_email>
109
+ <bpost_reduced_mobility><to_quote>*</to_quote></bpost_reduced_mobility>
110
+ <bpost_delivery_date><to_quote>*</to_quote></bpost_delivery_date>
111
+ <bpost_drop_date><to_quote>*</to_quote></bpost_drop_date>
112
+ </sales_convert_order>
113
+ </fieldsets>
114
+ </global>
115
+
116
+ <frontend>
117
+ <translate>
118
+ <modules>
119
+ <Bpost_ShM>
120
+ <files>
121
+ <default>Bpost_ShM.csv</default>
122
+ </files>
123
+ </Bpost_ShM>
124
+ </modules>
125
+ </translate>
126
+ <layout>
127
+ <updates>
128
+ <bpost_shm>
129
+ <file>bpost/shm.xml</file>
130
+ </bpost_shm>
131
+ </updates>
132
+ </layout>
133
+ <routers>
134
+ <bpost_shm>
135
+ <use>standard</use>
136
+ <args>
137
+ <module>Bpost_ShM</module>
138
+ <frontName>bpost</frontName>
139
+ </args>
140
+ </bpost_shm>
141
+ </routers>
142
+ <events>
143
+ <core_block_abstract_to_html_after>
144
+ <observers>
145
+ <bpost_shm_core_block_abstract_to_html_after>
146
+ <class>bpost_shm/observer</class>
147
+ <method>core_block_abstract_to_html_after</method>
148
+ </bpost_shm_core_block_abstract_to_html_after>
149
+ </observers>
150
+ </core_block_abstract_to_html_after>
151
+
152
+ <controller_action_predispatch_onestepcheckout_index_index>
153
+ <observers>
154
+ <bpost_shm_controller_action_predispatch_onestepcheckout_index_index>
155
+ <class>bpost_shm/observer</class>
156
+ <method>controller_action_predispatch_onestepcheckout_index_index</method>
157
+ </bpost_shm_controller_action_predispatch_onestepcheckout_index_index>
158
+ </observers>
159
+ </controller_action_predispatch_onestepcheckout_index_index>
160
+
161
+ <controller_action_predispatch_checkout_onepage_saveBilling>
162
+ <observers>
163
+ <bpost_shm_controller_action_predispatch_checkout_onepage_saveBilling>
164
+ <class>bpost_shm/observer</class>
165
+ <method>controller_action_predispatch_checkout_onepage_saveAddress</method>
166
+ </bpost_shm_controller_action_predispatch_checkout_onepage_saveBilling>
167
+ </observers>
168
+ </controller_action_predispatch_checkout_onepage_saveBilling>
169
+
170
+ <controller_action_predispatch_checkout_onepage_saveShipping>
171
+ <observers>
172
+ <bpost_shm_controller_action_predispatch_checkout_onepage_saveShipping>
173
+ <class>bpost_shm/observer</class>
174
+ <method>controller_action_predispatch_checkout_onepage_saveAddress</method>
175
+ </bpost_shm_controller_action_predispatch_checkout_onepage_saveShipping>
176
+ </observers>
177
+ </controller_action_predispatch_checkout_onepage_saveShipping>
178
+
179
+ <controller_action_postdispatch_checkout_onepage_saveBilling>
180
+ <observers>
181
+ <bpost_shm_controller_action_postdispatch_checkout_onepage_saveBilling>
182
+ <class>bpost_shm/observer</class>
183
+ <method>controller_action_postdispatch_checkout_onepage_saveAddress</method>
184
+ </bpost_shm_controller_action_postdispatch_checkout_onepage_saveBilling>
185
+ </observers>
186
+ </controller_action_postdispatch_checkout_onepage_saveBilling>
187
+
188
+ <controller_action_postdispatch_checkout_onepage_saveShipping>
189
+ <observers>
190
+ <bpost_shm_controller_action_postdispatch_checkout_onepage_saveShipping>
191
+ <class>bpost_shm/observer</class>
192
+ <method>controller_action_postdispatch_checkout_onepage_saveAddress</method>
193
+ </bpost_shm_controller_action_postdispatch_checkout_onepage_saveShipping>
194
+ </observers>
195
+ </controller_action_postdispatch_checkout_onepage_saveShipping>
196
+
197
+ <controller_action_postdispatch_onestepcheckout_ajax_save_billing>
198
+ <observers>
199
+ <bpost_shm_controller_action_postdispatch_onestepcheckout_ajax_save_billing>
200
+ <class>bpost_shm/observer</class>
201
+ <method>controller_action_postdispatch_checkout_onepage_saveAddress</method>
202
+ </bpost_shm_controller_action_postdispatch_onestepcheckout_ajax_save_billing>
203
+ </observers>
204
+ </controller_action_postdispatch_onestepcheckout_ajax_save_billing>
205
+
206
+ <checkout_controller_onepage_save_shipping_method>
207
+ <observers>
208
+ <bpost_shm_checkout_controller_onepage_save_shipping_method>
209
+ <class>bpost_shm/observer</class>
210
+ <method>checkout_controller_onepage_save_shipping_method</method>
211
+ </bpost_shm_checkout_controller_onepage_save_shipping_method>
212
+ </observers>
213
+ </checkout_controller_onepage_save_shipping_method>
214
+
215
+ <checkout_submit_all_after>
216
+ <observers>
217
+ <bpost_shm_checkout_submit_all_after>
218
+ <class>bpost_shm/observer</class>
219
+ <method>checkout_submit_all_after</method>
220
+ </bpost_shm_checkout_submit_all_after>
221
+ </observers>
222
+ </checkout_submit_all_after>
223
+
224
+ <sales_quote_collect_totals_before>
225
+ <observers>
226
+ <bpost_shm_set_address_defaults>
227
+ <type>model</type>
228
+ <class>bpost_shm/observer</class>
229
+ <method>sales_quote_collect_totals_before</method>
230
+ </bpost_shm_set_address_defaults>
231
+ </observers>
232
+ </sales_quote_collect_totals_before>
233
+ </events>
234
+ </frontend>
235
+ <adminhtml>
236
+ <translate>
237
+ <modules>
238
+ <Bpost_ShM>
239
+ <files>
240
+ <default>Bpost_ShM.csv</default>
241
+ </files>
242
+ </Bpost_ShM>
243
+ </modules>
244
+ </translate>
245
+ <layout>
246
+ <updates>
247
+ <bpost_shm>
248
+ <file>bpost/shm.xml</file>
249
+ </bpost_shm>
250
+ </updates>
251
+ </layout>
252
+ <events>
253
+ <core_block_abstract_to_html_before>
254
+ <observers>
255
+ <bpost_shm_core_block_abstract_to_html_before>
256
+ <class>bpost_shm/adminhtml_observer</class>
257
+ <method>core_block_abstract_to_html_before</method>
258
+ </bpost_shm_core_block_abstract_to_html_before>
259
+ </observers>
260
+ </core_block_abstract_to_html_before>
261
+
262
+ <admin_system_config_changed_section_shipping>
263
+ <observers>
264
+ <bpost_shm_admin_system_config_changed_section_shipping>
265
+ <class>bpost_shm/adminhtml_observer</class>
266
+ <method>admin_system_config_changed_section_shipping</method>
267
+ </bpost_shm_admin_system_config_changed_section_shipping>
268
+ </observers>
269
+ </admin_system_config_changed_section_shipping>
270
+
271
+ <bpost_shm_prepare_grid_collection_after>
272
+ <observers>
273
+ <bpost_shm_prepare_grid_collection_after>
274
+ <class>bpost_shm/adminhtml_observer</class>
275
+ <method>bpost_shm_prepare_grid_collection_after</method>
276
+ </bpost_shm_prepare_grid_collection_after>
277
+ </observers>
278
+ </bpost_shm_prepare_grid_collection_after>
279
+
280
+ <sales_order_shipment_grid_collection_load_before>
281
+ <observers>
282
+ <bpost_shm_order_shipment_grid_collection_load_before>
283
+ <class>bpost_shm/adminhtml_observer</class>
284
+ <method>sales_order_shipment_grid_collection_load_before</method>
285
+ </bpost_shm_order_shipment_grid_collection_load_before>
286
+ </observers>
287
+ </sales_order_shipment_grid_collection_load_before>
288
+
289
+ <sales_order_shipment_save_before>
290
+ <observers>
291
+ <bpost_shm_sales_order_shipment_save_before>
292
+ <class>bpost_shm/adminhtml_observer</class>
293
+ <method>sales_order_shipment_save_before</method>
294
+ <type>model</type>
295
+ </bpost_shm_sales_order_shipment_save_before>
296
+ </observers>
297
+ </sales_order_shipment_save_before>
298
+ </events>
299
+ </adminhtml>
300
+ <admin>
301
+ <routers>
302
+ <adminhtml>
303
+ <args>
304
+ <modules>
305
+ <bpost_shm before="Mage_Adminhtml">Bpost_ShM_Adminhtml</bpost_shm>
306
+ </modules>
307
+ </args>
308
+ </adminhtml>
309
+ </routers>
310
+ </admin>
311
+ <default>
312
+ <carriers>
313
+ <bpostshm>
314
+ <active>1</active>
315
+ <model>bpost_shm/shipping_carrier_bpostShM</model>
316
+ <title>bpost</title>
317
+ <name>bpost</name>
318
+ <showmethod>1</showmethod>
319
+ </bpostshm>
320
+ <bpost_homedelivery>
321
+ <active>1</active>
322
+ <title>bpost</title>
323
+ <name>Home delivery</name>
324
+ <free_shipping>0</free_shipping>
325
+ <rate_type>0</rate_type>
326
+ <flat_rate_price>0</flat_rate_price>
327
+ <sort_order>0</sort_order>
328
+ <showmethod>1</showmethod>
329
+ <second_presentation>0</second_presentation>
330
+ <insurance>0</insurance>
331
+ <signature>0</signature>
332
+ <saturday_delivery>0</saturday_delivery>
333
+ <sort_order>1</sort_order>
334
+ <showmethod>1</showmethod>
335
+ <specificerrmsg>Bpost homedelivery is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
336
+ </bpost_homedelivery>
337
+ <bpost_international>
338
+ <active>1</active>
339
+ <title>bpost</title>
340
+ <name>International</name>
341
+ <sort_order>10</sort_order>
342
+ <rate_type>0</rate_type>
343
+ <flat_rate_price>0</flat_rate_price>
344
+ <showmethod>1</showmethod>
345
+ <sallowspecific>1</sallowspecific>
346
+ <product>0</product>
347
+ <insurance>0</insurance>
348
+ <specificerrmsg>Bpost international is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
349
+ </bpost_international>
350
+ <bpost_pickuppoint>
351
+ <active>1</active>
352
+ <title>bpost</title>
353
+ <name>Pick-up point</name>
354
+ <rate_type>0</rate_type>
355
+ <flat_rate_price>0</flat_rate_price>
356
+ <showmethod>1</showmethod>
357
+ <insurance>0</insurance>
358
+ <sort_order>20</sort_order>
359
+ <saturday_delivery>0</saturday_delivery>
360
+ <specificerrmsg>Bpost pick-up-point is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
361
+ </bpost_pickuppoint>
362
+ <bpost_parcellocker>
363
+ <active>1</active>
364
+ <title>bpost</title>
365
+ <name>Parcel locker</name>
366
+ <rate_type>0</rate_type>
367
+ <flat_rate_price>0</flat_rate_price>
368
+ <showmethod>1</showmethod>
369
+ <insurance>0</insurance>
370
+ <sort_order>30</sort_order>
371
+ <saturday_delivery>0</saturday_delivery>
372
+ <specificerrmsg>Bpost parcel locker is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
373
+ </bpost_parcellocker>
374
+ </carriers>
375
+ <shipping>
376
+ <bpost_shm>
377
+ <api_log_level>3</api_log_level>
378
+ <log_level>3</log_level>
379
+ <enable_log_api>1</enable_log_api>
380
+ <enable_log>1</enable_log>
381
+ <api_url>https://testapi.bpost.be</api_url>
382
+ <frontend_api_url>https://shippingmanager.bpost.be/ShmFrontEnd/start</frontend_api_url>
383
+ <sender_country>BE</sender_country>
384
+ <manage_labels_with_magento>1</manage_labels_with_magento>
385
+ <label_format>A4</label_format>
386
+ <automatic_retour_labels>0</automatic_retour_labels>
387
+ <automatic_track_and_trace_information>1</automatic_track_and_trace_information>
388
+ <display_delivery_date>0</display_delivery_date>
389
+ <choose_delivery_date>0</choose_delivery_date>
390
+ <nr_of_delivery_days_shown>5</nr_of_delivery_days_shown>
391
+ <next_day_delivery_allowed_till>17,00,00</next_day_delivery_allowed_till>
392
+ <days_between_order_and_shipment>0</days_between_order_and_shipment>
393
+ <weight_unit>1</weight_unit>
394
+ </bpost_shm>
395
+ </shipping>
396
+ </default>
397
+ </config>
app/code/community/Bpost/ShM/etc/system.xml ADDED
@@ -0,0 +1,1179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <shipping>
5
+ <groups>
6
+ <bpost_shm translate="label" module="bpost_shm">
7
+ <label>bpost Shipping Manager</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>10</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>0</show_in_store>
13
+ <fields>
14
+
15
+ <info_text translate="label">
16
+ <label>Info text</label>
17
+ <frontend_type>text</frontend_type>
18
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_info</frontend_model>
19
+ <sort_order>0</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ </info_text>
24
+
25
+ <logo translate="label">
26
+ <label>Logo</label>
27
+ <frontend_type>text</frontend_type>
28
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_logo</frontend_model>
29
+ <sort_order>5</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ </logo>
34
+
35
+ <accountid translate="label,comment">
36
+ <label>Account id</label>
37
+ <frontend_type>text</frontend_type>
38
+ <sort_order>10</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>0</show_in_store>
42
+ <comment><![CDATA[Your 6 digits bpost account ID used for the Shipping Manager.<br/><a target='_blank' href='http://bpost.freshdesk.com/solution/articles/4000061189'>http://bpost.freshdesk.com/solution/articles/4000061189</a>]]></comment>
43
+ </accountid>
44
+
45
+ <passphrase translate="label,comment">
46
+ <label>Passphrase</label>
47
+ <frontend_type>password</frontend_type>
48
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
49
+ <sort_order>20</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>0</show_in_store>
53
+ <comment><![CDATA[The passphrase you entered in bpost Shipping Manager back-office application. This is not the password used to access bpost portal.]]></comment>
54
+ </passphrase>
55
+
56
+ <api_url translate="label,comment">
57
+ <label>API url</label>
58
+ <frontend_type>text</frontend_type>
59
+ <sort_order>30</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>0</show_in_store>
63
+ <comment><![CDATA[Do not modify this setting if you are not 100% sure of what you are doing.]]></comment>
64
+ </api_url>
65
+
66
+
67
+ <sender_name translate="label,comment">
68
+ <label>Sender name</label>
69
+ <frontend_type>text</frontend_type>
70
+ <sort_order>60</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>0</show_in_store>
74
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
75
+ </sender_name>
76
+
77
+ <sender_company translate="label,comment">
78
+ <label>Sender company</label>
79
+ <frontend_type>text</frontend_type>
80
+ <sort_order>70</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>0</show_in_store>
84
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
85
+ </sender_company>
86
+
87
+ <sender_streetname translate="label,comment">
88
+ <label>Sender streetname</label>
89
+ <frontend_type>text</frontend_type>
90
+ <sort_order>80</sort_order>
91
+ <show_in_default>1</show_in_default>
92
+ <show_in_website>1</show_in_website>
93
+ <show_in_store>0</show_in_store>
94
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
95
+ </sender_streetname>
96
+
97
+ <sender_streetnumber translate="label,comment">
98
+ <label>Sender streetnumber</label>
99
+ <frontend_type>text</frontend_type>
100
+ <sort_order>90</sort_order>
101
+ <show_in_default>1</show_in_default>
102
+ <show_in_website>1</show_in_website>
103
+ <show_in_store>0</show_in_store>
104
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
105
+ </sender_streetnumber>
106
+
107
+ <sender_boxnumber translate="label,comment">
108
+ <label>Sender boxnumber</label>
109
+ <frontend_type>text</frontend_type>
110
+ <sort_order>100</sort_order>
111
+ <show_in_default>1</show_in_default>
112
+ <show_in_website>1</show_in_website>
113
+ <show_in_store>0</show_in_store>
114
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
115
+ </sender_boxnumber>
116
+
117
+ <sender_postal_code translate="label,comment">
118
+ <label>Sender postal code</label>
119
+ <frontend_type>text</frontend_type>
120
+ <sort_order>110</sort_order>
121
+ <show_in_default>1</show_in_default>
122
+ <show_in_website>1</show_in_website>
123
+ <show_in_store>0</show_in_store>
124
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
125
+ </sender_postal_code>
126
+
127
+ <sender_city translate="label,comment">
128
+ <label>Sender city</label>
129
+ <frontend_type>text</frontend_type>
130
+ <sort_order>120</sort_order>
131
+ <show_in_default>1</show_in_default>
132
+ <show_in_website>1</show_in_website>
133
+ <show_in_store>0</show_in_store>
134
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
135
+ </sender_city>
136
+
137
+ <sender_country translate="label,comment">
138
+ <label>Sender country</label>
139
+ <frontend_type>select</frontend_type>
140
+ <source_model>bpost_shm/adminhtml_system_config_source_shipping::getCountries</source_model>
141
+ <sort_order>130</sort_order>
142
+ <show_in_default>1</show_in_default>
143
+ <show_in_website>1</show_in_website>
144
+ <show_in_store>0</show_in_store>
145
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
146
+ </sender_country>
147
+
148
+ <sender_email translate="label,comment">
149
+ <label>Sender email</label>
150
+ <frontend_type>text</frontend_type>
151
+ <sort_order>140</sort_order>
152
+ <show_in_default>1</show_in_default>
153
+ <show_in_website>1</show_in_website>
154
+ <show_in_store>0</show_in_store>
155
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
156
+ </sender_email>
157
+
158
+ <sender_phonenumber translate="label,comment">
159
+ <label>Sender phonenumber</label>
160
+ <frontend_type>text</frontend_type>
161
+ <sort_order>150</sort_order>
162
+ <show_in_default>1</show_in_default>
163
+ <show_in_website>1</show_in_website>
164
+ <show_in_store>0</show_in_store>
165
+ <comment><![CDATA[Used in the webservice calls.]]></comment>
166
+ </sender_phonenumber>
167
+
168
+ <manage_labels_with_magento translate="label,comment">
169
+ <label>Use Magento to manage labels</label>
170
+ <frontend_type>select</frontend_type>
171
+ <source_model>adminhtml/system_config_source_yesno</source_model>
172
+ <sort_order>160</sort_order>
173
+ <show_in_default>1</show_in_default>
174
+ <show_in_website>0</show_in_website>
175
+ <show_in_store>0</show_in_store>
176
+ <comment><![CDATA[If you enable this option, labels are generated directly within Magento. It is not needed to use the bpost Shipping Manager for these tasks. Pop-ups must be enabled in your browser, in order to view the printed labels. Click <a href='http://bpost.freshdesk.com/solution/articles/4000061188' target='_blank'>here</a> to learn more about this option.]]></comment>
177
+ </manage_labels_with_magento>
178
+
179
+
180
+ <label_format translate="label,comment">
181
+ <label>Label format</label>
182
+ <frontend_type>select</frontend_type>
183
+ <source_model>bpost_shm/adminhtml_system_config_source_shipping::getLabelSizesOptionsArray</source_model>
184
+ <sort_order>170</sort_order>
185
+ <show_in_default>1</show_in_default>
186
+ <show_in_website>1</show_in_website>
187
+ <show_in_store>0</show_in_store>
188
+ <depends>
189
+ <manage_labels_with_magento>1</manage_labels_with_magento>
190
+ </depends>
191
+ <comment><![CDATA[Choose between A6 or A4 format]]></comment>
192
+ </label_format>
193
+
194
+ <automatic_retour_labels translate="label">
195
+ <label>Automatic retour labels</label>
196
+ <frontend_type>select</frontend_type>
197
+ <source_model>adminhtml/system_config_source_yesno</source_model>
198
+ <sort_order>180</sort_order>
199
+ <show_in_default>1</show_in_default>
200
+ <show_in_website>1</show_in_website>
201
+ <show_in_store>0</show_in_store>
202
+ <depends>
203
+ <manage_labels_with_magento>1</manage_labels_with_magento>
204
+ </depends>
205
+ <comment><![CDATA[If you enable this option, a retour label is automatically added and printed when generating labels. If disabled, you are able to manually create retour labels.]]></comment>
206
+ </automatic_retour_labels>
207
+
208
+ <automatic_track_and_trace_information translate="label,comment">
209
+ <label>Automatic track and trace information</label>
210
+ <frontend_type>select</frontend_type>
211
+ <source_model>adminhtml/system_config_source_yesno</source_model>
212
+ <sort_order>190</sort_order>
213
+ <show_in_default>1</show_in_default>
214
+ <show_in_website>1</show_in_website>
215
+ <show_in_store>0</show_in_store>
216
+ <depends>
217
+ <manage_labels_with_magento>1</manage_labels_with_magento>
218
+ </depends>
219
+ <comment><![CDATA[If you enable this option, the bpost Track & Trace link will be added in the Magento mail templates. It is always possible to manually send these emails.<br/><a href='http://bpost.freshdesk.com/solution/articles/4000061636' target='_blank'>http://bpost.freshdesk.com/solution/articles/4000061636</a>]]></comment>
220
+ </automatic_track_and_trace_information>
221
+
222
+ <display_delivery_date translate="label,comment">
223
+ <label>Display delivery date</label>
224
+ <frontend_type>select</frontend_type>
225
+ <source_model>adminhtml/system_config_source_yesno</source_model>
226
+ <sort_order>200</sort_order>
227
+ <show_in_default>1</show_in_default>
228
+ <show_in_website>1</show_in_website>
229
+ <show_in_store>0</show_in_store>
230
+ <comment><![CDATA[Displays calculated delivery date]]></comment>
231
+ <comment>
232
+ <model>bpost_shm/adminhtml_system_config_source_datecomment</model>
233
+ </comment>
234
+ </display_delivery_date>
235
+
236
+ <days_between_order_and_shipment translate="label">
237
+ <label>Days between order and shipment</label>
238
+ <frontend_type>text</frontend_type>
239
+ <sort_order>210</sort_order>
240
+ <show_in_default>1</show_in_default>
241
+ <show_in_website>1</show_in_website>
242
+ <show_in_store>0</show_in_store>
243
+ <depends><display_delivery_date>1</display_delivery_date></depends>
244
+ </days_between_order_and_shipment>
245
+
246
+ <choose_delivery_date translate="label,comment">
247
+ <label>Choose delivery date</label>
248
+ <frontend_type>select</frontend_type>
249
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_choose</frontend_model>
250
+ <source_model>adminhtml/system_config_source_yesno</source_model>
251
+ <sort_order>220</sort_order>
252
+ <show_in_default>1</show_in_default>
253
+ <show_in_website>1</show_in_website>
254
+ <show_in_store>0</show_in_store>
255
+ <depends><display_delivery_date>1</display_delivery_date></depends>
256
+ <comment><![CDATA[Allow customer to choose their delivery date]]></comment>
257
+ </choose_delivery_date>
258
+
259
+ <nr_of_delivery_days_shown translate="label">
260
+ <label>Number of delivery days shown</label>
261
+ <frontend_type>select</frontend_type>
262
+ <source_model>bpost_shm/adminhtml_system_config_source_shipping::nrOfDeliveryDaysShownOptionsArray</source_model>
263
+ <sort_order>230</sort_order>
264
+ <show_in_default>1</show_in_default>
265
+ <show_in_website>1</show_in_website>
266
+ <show_in_store>0</show_in_store>
267
+ <depends>
268
+ <display_delivery_date>1</display_delivery_date>
269
+ <choose_delivery_date>1</choose_delivery_date>
270
+ </depends>
271
+ </nr_of_delivery_days_shown>
272
+
273
+ <next_day_delivery_allowed_till translate="label,comment">
274
+ <label>Next day delivery allowed till</label>
275
+ <frontend_type>time</frontend_type>
276
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_hour</frontend_model>
277
+ <sort_order>240</sort_order>
278
+ <show_in_default>1</show_in_default>
279
+ <show_in_website>1</show_in_website>
280
+ <show_in_store>0</show_in_store>
281
+ <comment><![CDATA[If the order is placed after this cut-off time, an extra day is added to the displayed date. Order placed = end of checkout.]]></comment>
282
+ <depends>
283
+ <display_delivery_date>1</display_delivery_date>
284
+ </depends>
285
+ </next_day_delivery_allowed_till>
286
+
287
+ <saturday_delivery_cost translate="label,comment">
288
+ <label>Saturday delivery cost</label>
289
+ <frontend_type>text</frontend_type>
290
+ <sort_order>250</sort_order>
291
+ <show_in_default>1</show_in_default>
292
+ <show_in_website>1</show_in_website>
293
+ <show_in_store>0</show_in_store>
294
+ <comment><![CDATA[Additional fee when using saturday delivery option, e.g.: 4.95.]]></comment>
295
+ </saturday_delivery_cost>
296
+
297
+ <weight_unit translate="label,comment">
298
+ <label>Weight unit</label>
299
+ <frontend_type>select</frontend_type>
300
+ <source_model>bpost_shm/system_config_source_weightunit</source_model>
301
+ <sort_order>255</sort_order>
302
+ <show_in_default>1</show_in_default>
303
+ <show_in_website>1</show_in_website>
304
+ <show_in_store>0</show_in_store>
305
+ <comment>Used to calculate the weight before sending it to bpost</comment>
306
+ </weight_unit>
307
+
308
+ <browser_api_key translate="label,comment">
309
+ <label>Google browser API key</label>
310
+ <frontend_type>text</frontend_type>
311
+ <sort_order>260</sort_order>
312
+ <show_in_default>1</show_in_default>
313
+ <show_in_website>1</show_in_website>
314
+ <show_in_store>0</show_in_store>
315
+ <comment><![CDATA[bpost uses Google Maps API to display the map in the frontend. <strong>
Note:</strong> This is optional if you will not meet the usage limits. Visit Google’s online documentation for more information.]]></comment>
316
+ </browser_api_key>
317
+
318
+ <server_api_key translate="label,comment">
319
+ <label>Google server API key</label>
320
+ <frontend_type>text</frontend_type>
321
+ <sort_order>270</sort_order>
322
+ <show_in_default>1</show_in_default>
323
+ <show_in_website>1</show_in_website>
324
+ <show_in_store>0</show_in_store>
325
+ <comment><![CDATA[bpost uses Google Geocoding API to calculate GEO location based on the shipping address. <strong>
Note:</strong> This is optional if you will not meet the usage limits. Visit Google’s online documentation for more information.]]></comment>
326
+ </server_api_key>
327
+ </fields>
328
+ </bpost_shm>
329
+ </groups>
330
+ </shipping>
331
+
332
+ <carriers>
333
+ <groups>
334
+ <bpost_homedelivery translate="label" module="bpost_shm">
335
+ <label>bpost Home delivery</label>
336
+ <frontend_type>text</frontend_type>
337
+ <sort_order>50</sort_order>
338
+ <show_in_default>1</show_in_default>
339
+ <show_in_website>1</show_in_website>
340
+ <show_in_store>1</show_in_store>
341
+ <fields>
342
+ <logo translate="label">
343
+ <label>Logoo</label>
344
+ <frontend_type>text</frontend_type>
345
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_logo</frontend_model>
346
+ <sort_order>0</sort_order>
347
+ <show_in_default>1</show_in_default>
348
+ <show_in_website>1</show_in_website>
349
+ <show_in_store>1</show_in_store>
350
+ </logo>
351
+
352
+
353
+ <subheader_general translate="label">
354
+ <label>General</label>
355
+ <frontend_type>text</frontend_type>
356
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
357
+ <sort_order>0</sort_order>
358
+ <show_in_default>1</show_in_default>
359
+ <show_in_website>1</show_in_website>
360
+ <show_in_store>1</show_in_store>
361
+ </subheader_general>
362
+
363
+ <active translate="label,comment">
364
+ <label>Enabled</label>
365
+ <frontend_type>select</frontend_type>
366
+ <source_model>adminhtml/system_config_source_yesno</source_model>
367
+ <sort_order>1</sort_order>
368
+ <show_in_default>1</show_in_default>
369
+ <show_in_website>1</show_in_website>
370
+ <show_in_store>1</show_in_store>
371
+ <comment><![CDATA[Delivery at your doorstep or at your office? bpack@home is the most convenient option for you!]]></comment>
372
+ </active>
373
+
374
+ <subheader_rates translate="label">
375
+ <label>Rates</label>
376
+ <frontend_type>text</frontend_type>
377
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
378
+ <sort_order>5</sort_order>
379
+ <show_in_default>1</show_in_default>
380
+ <show_in_website>1</show_in_website>
381
+ <show_in_store>1</show_in_store>
382
+ </subheader_rates>
383
+
384
+ <free_shipping translate="label,comment">
385
+ <label>Free shipping</label>
386
+ <frontend_type>select</frontend_type>
387
+ <source_model>adminhtml/system_config_source_yesno</source_model>
388
+ <sort_order>10</sort_order>
389
+ <show_in_default>1</show_in_default>
390
+ <show_in_website>1</show_in_website>
391
+ <show_in_store>1</show_in_store>
392
+ <comment><![CDATA[Allow free shipping]]></comment>
393
+ </free_shipping>
394
+
395
+ <free_shipping_from translate="label,comment">
396
+ <label>.. as of</label>
397
+ <frontend_type>text</frontend_type>
398
+ <sort_order>20</sort_order>
399
+ <depends>
400
+ <free_shipping>1</free_shipping>
401
+ </depends>
402
+ <show_in_default>1</show_in_default>
403
+ <show_in_website>1</show_in_website>
404
+ <show_in_store>1</show_in_store>
405
+ <comment><![CDATA[Free shipping will be applied as from a minimum amount]]></comment>
406
+ </free_shipping_from>
407
+
408
+ <rate_type translate="label,comment,tooltip">
409
+ <label>Rate type</label>
410
+ <frontend_type>select</frontend_type>
411
+ <source_model>bpost_shm/system_config_source_ratetypes</source_model>
412
+ <sort_order>30</sort_order>
413
+ <show_in_default>1</show_in_default>
414
+ <show_in_website>1</show_in_website>
415
+ <show_in_store>1</show_in_store>
416
+ <comment><![CDATA[Choose your rate type (Flat rate or Table rate)]]></comment>
417
+ <tooltip>Importing and exporting table rates only possible on website scope. View the documentation for more information.</tooltip>
418
+ </rate_type>
419
+
420
+ <flat_rate_price translate="label,comment">
421
+ <label>Flat rate price</label>
422
+ <frontend_type>text</frontend_type>
423
+ <sort_order>40</sort_order>
424
+ <depends>
425
+ <rate_type>0</rate_type>
426
+ </depends>
427
+ <show_in_default>1</show_in_default>
428
+ <show_in_website>1</show_in_website>
429
+ <show_in_store>1</show_in_store>
430
+ <comment><![CDATA[Fixed fee for bpost Home delivery shipments, e.g.: 4.95.]]></comment>
431
+ </flat_rate_price>
432
+
433
+ <condition_name translate="label">
434
+ <label>Table rates condition</label>
435
+ <frontend_type>select</frontend_type>
436
+ <source_model>adminhtml/system_config_source_shipping_tablerate</source_model>
437
+ <sort_order>50</sort_order>
438
+ <depends>
439
+ <rate_type>1</rate_type>
440
+ </depends>
441
+ <show_in_default>1</show_in_default>
442
+ <show_in_website>1</show_in_website>
443
+ <show_in_store>0</show_in_store>
444
+ </condition_name>
445
+
446
+ <export translate="label,comment">
447
+ <label>Export table rates file</label>
448
+ <frontend_type>button</frontend_type>
449
+ <frontend_model>bpost_shm/adminhtml_system_config_form_tablerates_export_homedelivery</frontend_model>
450
+ <sort_order>60</sort_order>
451
+ <depends>
452
+ <rate_type>1</rate_type>
453
+ </depends>
454
+ <show_in_default>0</show_in_default>
455
+ <show_in_website>1</show_in_website>
456
+ <show_in_store>0</show_in_store>
457
+ <comment><![CDATA[Export your table rates configuration here.]]></comment>
458
+ </export>
459
+
460
+ <import_homedelivery translate="label,comment">
461
+ <label>Import table rates file</label>
462
+ <frontend_type>import</frontend_type>
463
+ <sort_order>70</sort_order>
464
+ <backend_model>bpost_shm/adminhtml_system_config_backend_shipping_tablerates_homedelivery</backend_model>
465
+ <depends>
466
+ <rate_type>1</rate_type>
467
+ </depends>
468
+ <show_in_default>0</show_in_default>
469
+ <show_in_website>1</show_in_website>
470
+ <show_in_store>0</show_in_store>
471
+ <comment><![CDATA[Upload your table rates configuration here. Refer to the manual for more information.]]></comment>
472
+ </import_homedelivery>
473
+
474
+ <subheader_options translate="label">
475
+ <label>Options</label>
476
+ <frontend_type>text</frontend_type>
477
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
478
+ <sort_order>75</sort_order>
479
+ <show_in_default>1</show_in_default>
480
+ <show_in_website>1</show_in_website>
481
+ <show_in_store>1</show_in_store>
482
+ </subheader_options>
483
+
484
+ <second_presentation translate="label,comment">
485
+ <label>2nd presentation</label>
486
+ <frontend_type>select</frontend_type>
487
+ <source_model>adminhtml/system_config_source_yesno</source_model>
488
+ <sort_order>80</sort_order>
489
+ <show_in_default>1</show_in_default>
490
+ <show_in_website>1</show_in_website>
491
+ <show_in_store>1</show_in_store>
492
+ <comment><![CDATA[This options provides automatically a second presentation at the receiver's address should he be absent upon first presentation.]]></comment>
493
+ </second_presentation>
494
+
495
+ <second_presentation_from translate="label">
496
+ <label>.. as from</label>
497
+ <frontend_type>text</frontend_type>
498
+ <sort_order>90</sort_order>
499
+ <depends>
500
+ <second_presentation>1</second_presentation>
501
+ </depends>
502
+ <show_in_default>1</show_in_default>
503
+ <show_in_website>1</show_in_website>
504
+ <show_in_store>1</show_in_store>
505
+ </second_presentation_from>
506
+
507
+ <insurance translate="label,comment">
508
+ <label>Insurance</label>
509
+ <frontend_type>select</frontend_type>
510
+ <source_model>adminhtml/system_config_source_yesno</source_model>
511
+ <sort_order>100</sort_order>
512
+ <show_in_default>1</show_in_default>
513
+ <show_in_website>1</show_in_website>
514
+ <show_in_store>1</show_in_store>
515
+ <comment><![CDATA[Insurance to insure your goods to a maximum of 500,00 euro.]]></comment>
516
+ </insurance>
517
+
518
+ <insurance_from translate="label">
519
+ <label>.. as from</label>
520
+ <frontend_type>text</frontend_type>
521
+ <sort_order>110</sort_order>
522
+ <depends>
523
+ <insurance>1</insurance>
524
+ </depends>
525
+ <show_in_default>1</show_in_default>
526
+ <show_in_website>1</show_in_website>
527
+ <show_in_store>1</show_in_store>
528
+ </insurance_from>
529
+
530
+ <signature translate="label,comment">
531
+ <label>Signature</label>
532
+ <frontend_type>select</frontend_type>
533
+ <source_model>adminhtml/system_config_source_yesno</source_model>
534
+ <sort_order>120</sort_order>
535
+ <show_in_default>1</show_in_default>
536
+ <show_in_website>1</show_in_website>
537
+ <show_in_store>1</show_in_store>
538
+ <comment><![CDATA[The delivery happens against signature by the receiver.]]></comment>
539
+ </signature>
540
+
541
+ <signature_from translate="label">
542
+ <label>.. as from</label>
543
+ <frontend_type>text</frontend_type>
544
+ <sort_order>130</sort_order>
545
+ <depends>
546
+ <signature>1</signature>
547
+ </depends>
548
+ <show_in_default>1</show_in_default>
549
+ <show_in_website>1</show_in_website>
550
+ <show_in_store>1</show_in_store>
551
+ </signature_from>
552
+
553
+ <saturday_delivery translate="label,comment">
554
+ <label>Saturday delivery</label>
555
+ <frontend_type>select</frontend_type>
556
+ <source_model>adminhtml/system_config_source_yesno</source_model>
557
+ <sort_order>140</sort_order>
558
+ <show_in_default>1</show_in_default>
559
+ <show_in_website>1</show_in_website>
560
+ <show_in_store>1</show_in_store>
561
+ <comment><![CDATA[The parcel is delivered on Saturday if it is timely dropped in the bpost network.]]></comment>
562
+ </saturday_delivery>
563
+
564
+ <saturday_delivery_from translate="label">
565
+ <label>.. as from</label>
566
+ <frontend_type>text</frontend_type>
567
+ <sort_order>150</sort_order>
568
+ <depends>
569
+ <saturday_delivery>1</saturday_delivery>
570
+ </depends>
571
+ <show_in_default>1</show_in_default>
572
+ <show_in_website>1</show_in_website>
573
+ <show_in_store>1</show_in_store>
574
+ </saturday_delivery_from>
575
+ </fields>
576
+ </bpost_homedelivery>
577
+ <bpost_international translate="label" module="bpost_shm">
578
+ <label>bpost Home delivery international</label>
579
+ <frontend_type>text</frontend_type>
580
+ <sort_order>60</sort_order>
581
+ <show_in_default>1</show_in_default>
582
+ <show_in_website>1</show_in_website>
583
+ <show_in_store>1</show_in_store>
584
+ <fields>
585
+ <logo translate="label">
586
+ <label>Logoo</label>
587
+ <frontend_type>text</frontend_type>
588
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_logo</frontend_model>
589
+ <sort_order>0</sort_order>
590
+ <show_in_default>1</show_in_default>
591
+ <show_in_website>1</show_in_website>
592
+ <show_in_store>1</show_in_store>
593
+ </logo>
594
+
595
+ <subheader_general translate="label">
596
+ <label>General</label>
597
+ <frontend_type>text</frontend_type>
598
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
599
+ <sort_order>10</sort_order>
600
+ <show_in_default>1</show_in_default>
601
+ <show_in_website>1</show_in_website>
602
+ <show_in_store>1</show_in_store>
603
+ </subheader_general>
604
+
605
+ <active translate="label,comment">
606
+ <label>Enabled</label>
607
+ <frontend_type>select</frontend_type>
608
+ <source_model>adminhtml/system_config_source_yesno</source_model>
609
+ <sort_order>20</sort_order>
610
+ <show_in_default>1</show_in_default>
611
+ <show_in_website>1</show_in_website>
612
+ <show_in_store>1</show_in_store>
613
+ <comment><![CDATA[Delivery at your doorstep or at your office outside Belgium? bpack@international is the most convenient option for you!]]></comment>
614
+ </active>
615
+
616
+ <product translate="label,comment">
617
+ <label>Product</label>
618
+ <frontend_type>select</frontend_type>
619
+ <source_model>bpost_shm/system_config_source_product</source_model>
620
+ <sort_order>30</sort_order>
621
+ <show_in_default>1</show_in_default>
622
+ <show_in_website>1</show_in_website>
623
+ <show_in_store>1</show_in_store>
624
+ <comment><![CDATA[Select which product to use for international shipments]]></comment>
625
+ </product>
626
+
627
+ <subheader_rates translate="label">
628
+ <label>Rates</label>
629
+ <frontend_type>text</frontend_type>
630
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
631
+ <sort_order>40</sort_order>
632
+ <show_in_default>1</show_in_default>
633
+ <show_in_website>1</show_in_website>
634
+ <show_in_store>1</show_in_store>
635
+ </subheader_rates>
636
+
637
+ <free_shipping translate="label,comment">
638
+ <label>Free shipping</label>
639
+ <frontend_type>select</frontend_type>
640
+ <source_model>adminhtml/system_config_source_yesno</source_model>
641
+ <sort_order>50</sort_order>
642
+ <show_in_default>1</show_in_default>
643
+ <show_in_website>1</show_in_website>
644
+ <show_in_store>1</show_in_store>
645
+ <comment><![CDATA[Allow free shipping]]></comment>
646
+ </free_shipping>
647
+
648
+ <free_shipping_from translate="label,comment">
649
+ <label>.. as of</label>
650
+ <frontend_type>text</frontend_type>
651
+ <sort_order>60</sort_order>
652
+ <depends>
653
+ <free_shipping>1</free_shipping>
654
+ </depends>
655
+ <show_in_default>1</show_in_default>
656
+ <show_in_website>1</show_in_website>
657
+ <show_in_store>1</show_in_store>
658
+ <comment><![CDATA[Free shipping will be applied as from a minimum amount]]></comment>
659
+ </free_shipping_from>
660
+
661
+ <rate_type translate="label,comment,tooltip">
662
+ <label>Rate type</label>
663
+ <frontend_type>select</frontend_type>
664
+ <source_model>bpost_shm/system_config_source_ratetypes</source_model>
665
+ <sort_order>70</sort_order>
666
+ <show_in_default>1</show_in_default>
667
+ <show_in_website>1</show_in_website>
668
+ <show_in_store>1</show_in_store>
669
+ <comment><![CDATA[Choose your rate type (Flat rate or Table rate)]]></comment>
670
+ <tooltip>Importing and exporting table rates only possible on website scope. View the documentation for more information.</tooltip>
671
+ </rate_type>
672
+
673
+ <flat_rate_price translate="label,comment">
674
+ <label>Flat rate price</label>
675
+ <frontend_type>text</frontend_type>
676
+ <sort_order>80</sort_order>
677
+ <depends>
678
+ <rate_type>0</rate_type>
679
+ </depends>
680
+ <show_in_default>1</show_in_default>
681
+ <show_in_website>1</show_in_website>
682
+ <show_in_store>1</show_in_store>
683
+ <comment><![CDATA[Fixed fee for bpost Home delivery international shipments, e.g.: 4.95.]]></comment>
684
+ </flat_rate_price>
685
+
686
+ <condition_name translate="label">
687
+ <label>Table rates condition</label>
688
+ <frontend_type>select</frontend_type>
689
+ <source_model>adminhtml/system_config_source_shipping_tablerate</source_model>
690
+ <sort_order>90</sort_order>
691
+ <depends>
692
+ <rate_type>1</rate_type>
693
+ </depends>
694
+ <show_in_default>1</show_in_default>
695
+ <show_in_website>1</show_in_website>
696
+ <show_in_store>0</show_in_store>
697
+ </condition_name>
698
+
699
+ <export translate="label,comment">
700
+ <label>Export table rates file</label>
701
+ <frontend_type>button</frontend_type>
702
+ <frontend_model>bpost_shm/adminhtml_system_config_form_tablerates_export_international</frontend_model>
703
+ <sort_order>100</sort_order>
704
+ <depends>
705
+ <rate_type>1</rate_type>
706
+ </depends>
707
+ <show_in_default>0</show_in_default>
708
+ <show_in_website>1</show_in_website>
709
+ <show_in_store>0</show_in_store>
710
+ <comment><![CDATA[Export your table rates configuration here.]]></comment>
711
+ </export>
712
+
713
+ <import_international translate="label,comment">
714
+ <label>Import table rates file</label>
715
+ <frontend_type>import</frontend_type>
716
+ <sort_order>110</sort_order>
717
+ <backend_model>bpost_shm/adminhtml_system_config_backend_shipping_tablerates_international</backend_model>
718
+ <depends>
719
+ <rate_type>1</rate_type>
720
+ </depends>
721
+ <show_in_default>0</show_in_default>
722
+ <show_in_website>1</show_in_website>
723
+ <show_in_store>0</show_in_store>
724
+ <comment><![CDATA[Upload your table rates configuration here. Refer to the manual for more information.]]></comment>
725
+ </import_international>
726
+
727
+ <subheader_options translate="label">
728
+ <label>Options</label>
729
+ <frontend_type>text</frontend_type>
730
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
731
+ <sort_order>120</sort_order>
732
+ <show_in_default>1</show_in_default>
733
+ <show_in_website>1</show_in_website>
734
+ <show_in_store>1</show_in_store>
735
+ </subheader_options>
736
+
737
+ <import_countries translate="label,comment">
738
+ <label>Import countries</label>
739
+ <frontend_type>button</frontend_type>
740
+ <frontend_model>bpost_shm/adminhtml_system_config_form_api_import_countries</frontend_model>
741
+ <sort_order>125</sort_order>
742
+ <show_in_default>1</show_in_default>
743
+ <show_in_website>1</show_in_website>
744
+ <show_in_store>1</show_in_store>
745
+ <comment><![CDATA[Import your bpost configured countries here.]]></comment>
746
+ </import_countries>
747
+
748
+ <specificcountry translate="label,comment">
749
+ <label>Allowed countries</label>
750
+ <frontend_type>multiselect</frontend_type>
751
+ <sort_order>125</sort_order>
752
+ <source_model>bpost_shm/system_config_source_country</source_model>
753
+ <show_in_default>1</show_in_default>
754
+ <show_in_website>1</show_in_website>
755
+ <show_in_store>0</show_in_store>
756
+ <can_be_empty>0</can_be_empty>
757
+ <comment><![CDATA[Select one or more countries where bpost Home delivery international should be available for. Make sure your bpost shipping manager is configured properly. Otherwise no countries will be shown in this list after saving the 'Shipping Settings' configuration.]]></comment>
758
+ </specificcountry>
759
+
760
+ <insurance translate="label,comment">
761
+ <label>International insurance</label>
762
+ <frontend_type>select</frontend_type>
763
+ <source_model>adminhtml/system_config_source_yesno</source_model>
764
+ <sort_order>130</sort_order>
765
+ <show_in_default>1</show_in_default>
766
+ <show_in_website>1</show_in_website>
767
+ <show_in_store>1</show_in_store>
768
+ <comment><![CDATA[Insurance to insure your goods to a maximum of 500,00 euro.]]></comment>
769
+ </insurance>
770
+
771
+ <insurance_from translate="label">
772
+ <label>.. as from</label>
773
+ <frontend_type>text</frontend_type>
774
+ <sort_order>140</sort_order>
775
+ <depends>
776
+ <insurance>1</insurance>
777
+ </depends>
778
+ <show_in_default>1</show_in_default>
779
+ <show_in_website>1</show_in_website>
780
+ <show_in_store>1</show_in_store>
781
+ </insurance_from>
782
+ </fields>
783
+ </bpost_international>
784
+ <bpost_pickuppoint translate="label" module="bpost_shm">
785
+ <label>bpost Pick-up point</label>
786
+ <frontend_type>text</frontend_type>
787
+ <sort_order>70</sort_order>
788
+ <show_in_default>1</show_in_default>
789
+ <show_in_website>1</show_in_website>
790
+ <show_in_store>1</show_in_store>
791
+ <fields>
792
+ <logo translate="label">
793
+ <label>Logo</label>
794
+ <frontend_type>text</frontend_type>
795
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_logo</frontend_model>
796
+ <sort_order>0</sort_order>
797
+ <show_in_default>1</show_in_default>
798
+ <show_in_website>1</show_in_website>
799
+ <show_in_store>1</show_in_store>
800
+ </logo>
801
+
802
+ <subheader_general translate="label">
803
+ <label>General</label>
804
+ <frontend_type>text</frontend_type>
805
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
806
+ <sort_order>5</sort_order>
807
+ <show_in_default>1</show_in_default>
808
+ <show_in_website>1</show_in_website>
809
+ <show_in_store>1</show_in_store>
810
+ </subheader_general>
811
+
812
+ <active translate="label,comment">
813
+ <label>Enabled</label>
814
+ <frontend_type>select</frontend_type>
815
+ <source_model>adminhtml/system_config_source_yesno</source_model>
816
+ <sort_order>10</sort_order>
817
+ <show_in_default>1</show_in_default>
818
+ <show_in_website>1</show_in_website>
819
+ <show_in_store>1</show_in_store>
820
+ <comment><![CDATA[Get your parcel delivered in one of our 1.250 pick-up points.]]></comment>
821
+ </active>
822
+
823
+ <subheader_rates translate="label">
824
+ <label>Rates</label>
825
+ <frontend_type>text</frontend_type>
826
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
827
+ <sort_order>15</sort_order>
828
+ <show_in_default>1</show_in_default>
829
+ <show_in_website>1</show_in_website>
830
+ <show_in_store>1</show_in_store>
831
+ </subheader_rates>
832
+
833
+ <free_shipping translate="label,comment">
834
+ <label>Free shipping</label>
835
+ <frontend_type>select</frontend_type>
836
+ <source_model>adminhtml/system_config_source_yesno</source_model>
837
+ <sort_order>20</sort_order>
838
+ <show_in_default>1</show_in_default>
839
+ <show_in_website>1</show_in_website>
840
+ <show_in_store>1</show_in_store>
841
+ <comment><![CDATA[Allow free shipping]]></comment>
842
+ </free_shipping>
843
+
844
+ <free_shipping_from translate="label,comment">
845
+ <label>.. as of</label>
846
+ <frontend_type>text</frontend_type>
847
+ <sort_order>30</sort_order>
848
+ <depends>
849
+ <free_shipping>1</free_shipping>
850
+ </depends>
851
+ <show_in_default>1</show_in_default>
852
+ <show_in_website>1</show_in_website>
853
+ <show_in_store>1</show_in_store>
854
+ <comment><![CDATA[Free shipping will be applied as from a minimum amount]]></comment>
855
+ </free_shipping_from>
856
+
857
+ <rate_type translate="label,comment,tooltip">
858
+ <label>Rate type</label>
859
+ <frontend_type>select</frontend_type>
860
+ <source_model>bpost_shm/system_config_source_ratetypes</source_model>
861
+ <sort_order>40</sort_order>
862
+ <show_in_default>1</show_in_default>
863
+ <show_in_website>1</show_in_website>
864
+ <show_in_store>1</show_in_store>
865
+ <comment><![CDATA[Choose your rate type (Flat rate or Table rate)]]></comment>
866
+ <tooltip>Importing and exporting table rates only possible on website scope. View the documentation for more information.</tooltip>
867
+ </rate_type>
868
+
869
+ <flat_rate_price translate="label,comment">
870
+ <label>Flat rate price</label>
871
+ <frontend_type>text</frontend_type>
872
+ <sort_order>50</sort_order>
873
+ <depends>
874
+ <rate_type>0</rate_type>
875
+ </depends>
876
+ <show_in_default>1</show_in_default>
877
+ <show_in_website>1</show_in_website>
878
+ <show_in_store>1</show_in_store>
879
+ <comment><![CDATA[Fixed fee for bpost Pick-up point shipments, e.g.: 4.95.]]></comment>
880
+ </flat_rate_price>
881
+
882
+ <condition_name translate="label">
883
+ <label>Table rates condition</label>
884
+ <frontend_type>select</frontend_type>
885
+ <source_model>adminhtml/system_config_source_shipping_tablerate</source_model>
886
+ <sort_order>60</sort_order>
887
+ <depends>
888
+ <rate_type>1</rate_type>
889
+ </depends>
890
+ <show_in_default>1</show_in_default>
891
+ <show_in_website>1</show_in_website>
892
+ <show_in_store>0</show_in_store>
893
+ </condition_name>
894
+
895
+ <export translate="label,comment">
896
+ <label>Export table rates file</label>
897
+ <frontend_type>button</frontend_type>
898
+ <frontend_model>bpost_shm/adminhtml_system_config_form_tablerates_export_pickuppoint</frontend_model>
899
+ <sort_order>70</sort_order>
900
+ <depends>
901
+ <rate_type>1</rate_type>
902
+ </depends>
903
+ <show_in_default>0</show_in_default>
904
+ <show_in_website>1</show_in_website>
905
+ <show_in_store>0</show_in_store>
906
+ <comment><![CDATA[Export your table rates configuration here.]]></comment>
907
+ </export>
908
+
909
+ <import_pickuppoint translate="label,comment">
910
+ <label>Import table rates file</label>
911
+ <frontend_type>import</frontend_type>
912
+ <sort_order>80</sort_order>
913
+ <backend_model>bpost_shm/adminhtml_system_config_backend_shipping_tablerates_pickuppoint</backend_model>
914
+ <depends>
915
+ <rate_type>1</rate_type>
916
+ </depends>
917
+ <show_in_default>0</show_in_default>
918
+ <show_in_website>1</show_in_website>
919
+ <show_in_store>0</show_in_store>
920
+ <comment><![CDATA[Upload your table rates configuration here. Refer to the manual for more information.]]></comment>
921
+ </import_pickuppoint>
922
+
923
+ <subheader_options translate="label">
924
+ <label>Options</label>
925
+ <frontend_type>text</frontend_type>
926
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
927
+ <sort_order>85</sort_order>
928
+ <show_in_default>1</show_in_default>
929
+ <show_in_website>1</show_in_website>
930
+ <show_in_store>1</show_in_store>
931
+ </subheader_options>
932
+
933
+ <insurance translate="label,comment">
934
+ <label>Insurance</label>
935
+ <frontend_type>select</frontend_type>
936
+ <source_model>adminhtml/system_config_source_yesno</source_model>
937
+ <sort_order>90</sort_order>
938
+ <show_in_default>1</show_in_default>
939
+ <show_in_website>1</show_in_website>
940
+ <show_in_store>1</show_in_store>
941
+ <comment><![CDATA[Insurance to insure your goods to a maximum of 500,00 euro.]]></comment>
942
+ </insurance>
943
+
944
+ <insurance_from translate="label">
945
+ <label>.. as from</label>
946
+ <frontend_type>text</frontend_type>
947
+ <sort_order>100</sort_order>
948
+ <depends>
949
+ <insurance>1</insurance>
950
+ </depends>
951
+ <show_in_default>1</show_in_default>
952
+ <show_in_website>1</show_in_website>
953
+ <show_in_store>1</show_in_store>
954
+ </insurance_from>
955
+
956
+ <saturday_delivery translate="label,comment">
957
+ <label>Saturday delivery</label>
958
+ <frontend_type>select</frontend_type>
959
+ <source_model>adminhtml/system_config_source_yesno</source_model>
960
+ <sort_order>110</sort_order>
961
+ <show_in_default>1</show_in_default>
962
+ <show_in_website>1</show_in_website>
963
+ <show_in_store>1</show_in_store>
964
+ <comment><![CDATA[The parcel is delivered on Saturday if it is timely dropped in the bpost network.]]></comment>
965
+ </saturday_delivery>
966
+
967
+ <saturday_delivery_from translate="label">
968
+ <label>.. as from</label>
969
+ <frontend_type>text</frontend_type>
970
+ <sort_order>120</sort_order>
971
+ <depends>
972
+ <saturday_delivery>1</saturday_delivery>
973
+ </depends>
974
+ <show_in_default>1</show_in_default>
975
+ <show_in_website>1</show_in_website>
976
+ <show_in_store>1</show_in_store>
977
+ </saturday_delivery_from>
978
+ </fields>
979
+ </bpost_pickuppoint>
980
+ <bpost_parcellocker translate="label" module="bpost_shm">
981
+ <label>bpost Parcel locker</label>
982
+ <frontend_type>text</frontend_type>
983
+ <sort_order>80</sort_order>
984
+ <show_in_default>1</show_in_default>
985
+ <show_in_website>1</show_in_website>
986
+ <show_in_store>1</show_in_store>
987
+ <fields>
988
+ <logo translate="label">
989
+ <label>Logoo</label>
990
+ <frontend_type>text</frontend_type>
991
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_logo</frontend_model>
992
+ <sort_order>0</sort_order>
993
+ <show_in_default>1</show_in_default>
994
+ <show_in_website>1</show_in_website>
995
+ <show_in_store>1</show_in_store>
996
+ </logo>
997
+
998
+ <subheader_general translate="label">
999
+ <label>General</label>
1000
+ <frontend_type>text</frontend_type>
1001
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
1002
+ <sort_order>5</sort_order>
1003
+ <show_in_default>1</show_in_default>
1004
+ <show_in_website>1</show_in_website>
1005
+ <show_in_store>1</show_in_store>
1006
+ </subheader_general>
1007
+
1008
+ <active translate="label,comment">
1009
+ <label>Enabled</label>
1010
+ <frontend_type>select</frontend_type>
1011
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1012
+ <sort_order>10</sort_order>
1013
+ <show_in_default>1</show_in_default>
1014
+ <show_in_website>1</show_in_website>
1015
+ <show_in_store>1</show_in_store>
1016
+ <comment><![CDATA[Have your parcels delivered in one of our parcel lockers. Very convenient, centrally located, always open, 24/7!]]></comment>
1017
+ </active>
1018
+
1019
+ <subheader_rates translate="label">
1020
+ <label>Rates</label>
1021
+ <frontend_type>text</frontend_type>
1022
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
1023
+ <sort_order>15</sort_order>
1024
+ <show_in_default>1</show_in_default>
1025
+ <show_in_website>1</show_in_website>
1026
+ <show_in_store>1</show_in_store>
1027
+ </subheader_rates>
1028
+
1029
+ <free_shipping translate="label,comment">
1030
+ <label>Free shipping</label>
1031
+ <frontend_type>select</frontend_type>
1032
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1033
+ <sort_order>20</sort_order>
1034
+ <show_in_default>1</show_in_default>
1035
+ <show_in_website>1</show_in_website>
1036
+ <show_in_store>1</show_in_store>
1037
+ <comment><![CDATA[Allow free shipping.]]></comment>
1038
+ </free_shipping>
1039
+
1040
+ <free_shipping_from translate="label,comment">
1041
+ <label>.. as of</label>
1042
+ <frontend_type>text</frontend_type>
1043
+ <sort_order>30</sort_order>
1044
+ <depends>
1045
+ <free_shipping>1</free_shipping>
1046
+ </depends>
1047
+ <show_in_default>1</show_in_default>
1048
+ <show_in_website>1</show_in_website>
1049
+ <show_in_store>1</show_in_store>
1050
+ <comment><![CDATA[Free shipping will be applied as from a minimum amount]]></comment>
1051
+ </free_shipping_from>
1052
+
1053
+ <rate_type translate="label,comment,tooltip">
1054
+ <label>Rate type</label>
1055
+ <frontend_type>select</frontend_type>
1056
+ <source_model>bpost_shm/system_config_source_ratetypes</source_model>
1057
+ <sort_order>40</sort_order>
1058
+ <show_in_default>1</show_in_default>
1059
+ <show_in_website>1</show_in_website>
1060
+ <show_in_store>1</show_in_store>
1061
+ <comment><![CDATA[Choose your rate type (Flat rate or Table rate)]]></comment>
1062
+ <tooltip>Importing and exporting table rates only possible on website scope. View the documentation for more information.</tooltip>
1063
+ </rate_type>
1064
+
1065
+ <flat_rate_price translate="label">
1066
+ <label>Flat rate price</label>
1067
+ <frontend_type>text</frontend_type>
1068
+ <sort_order>50</sort_order>
1069
+ <depends>
1070
+ <rate_type>0</rate_type>
1071
+ </depends>
1072
+ <show_in_default>1</show_in_default>
1073
+ <show_in_website>1</show_in_website>
1074
+ <show_in_store>1</show_in_store>
1075
+ <comment><![CDATA[Fixed fee for bpost Pick-up point shipments, e.g.: 4.95.]]></comment>
1076
+ </flat_rate_price>
1077
+
1078
+ <condition_name translate="label">
1079
+ <label>Table rates condition</label>
1080
+ <frontend_type>select</frontend_type>
1081
+ <source_model>adminhtml/system_config_source_shipping_tablerate</source_model>
1082
+ <sort_order>60</sort_order>
1083
+ <depends>
1084
+ <rate_type>1</rate_type>
1085
+ </depends>
1086
+ <show_in_default>1</show_in_default>
1087
+ <show_in_website>1</show_in_website>
1088
+ <show_in_store>0</show_in_store>
1089
+ </condition_name>
1090
+
1091
+ <export translate="label,comment">
1092
+ <label>Export table rates file</label>
1093
+ <frontend_type>button</frontend_type>
1094
+ <frontend_model>bpost_shm/adminhtml_system_config_form_tablerates_export_parcellocker</frontend_model>
1095
+ <sort_order>70</sort_order>
1096
+ <depends>
1097
+ <rate_type>1</rate_type>
1098
+ </depends>
1099
+ <show_in_default>0</show_in_default>
1100
+ <show_in_website>1</show_in_website>
1101
+ <show_in_store>0</show_in_store>
1102
+ <comment><![CDATA[Export your table rates configuration here.]]></comment>
1103
+ </export>
1104
+
1105
+ <import_parcellocker translate="label,comment">
1106
+ <label>Import table rates file</label>
1107
+ <frontend_type>import</frontend_type>
1108
+ <sort_order>80</sort_order>
1109
+ <backend_model>bpost_shm/adminhtml_system_config_backend_shipping_tablerates_parcellocker</backend_model>
1110
+ <depends>
1111
+ <rate_type>1</rate_type>
1112
+ </depends>
1113
+ <show_in_default>0</show_in_default>
1114
+ <show_in_website>1</show_in_website>
1115
+ <show_in_store>0</show_in_store>
1116
+ <comment><![CDATA[Upload your table rates configuration here. Refer to the manual for more information.]]></comment>
1117
+ </import_parcellocker>
1118
+
1119
+ <subheader_options translate="label">
1120
+ <label>Options</label>
1121
+ <frontend_type>text</frontend_type>
1122
+ <frontend_model>bpost_shm/adminhtml_system_config_form_field_subheader</frontend_model>
1123
+ <sort_order>85</sort_order>
1124
+ <show_in_default>1</show_in_default>
1125
+ <show_in_website>1</show_in_website>
1126
+ <show_in_store>1</show_in_store>
1127
+ </subheader_options>
1128
+
1129
+ <insurance translate="label,comment">
1130
+ <label>Insurance</label>
1131
+ <frontend_type>select</frontend_type>
1132
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1133
+ <sort_order>90</sort_order>
1134
+ <show_in_default>1</show_in_default>
1135
+ <show_in_website>1</show_in_website>
1136
+ <show_in_store>1</show_in_store>
1137
+ <comment><![CDATA[Insurance to insure your goods to a maximum of 500,00 euro.]]></comment>
1138
+ </insurance>
1139
+
1140
+ <insurance_from translate="label">
1141
+ <label>.. as from</label>
1142
+ <frontend_type>text</frontend_type>
1143
+ <sort_order>100</sort_order>
1144
+ <depends>
1145
+ <insurance>1</insurance>
1146
+ </depends>
1147
+ <show_in_default>1</show_in_default>
1148
+ <show_in_website>1</show_in_website>
1149
+ <show_in_store>1</show_in_store>
1150
+ </insurance_from>
1151
+
1152
+ <saturday_delivery translate="label,comment">
1153
+ <label>Saturday delivery</label>
1154
+ <frontend_type>select</frontend_type>
1155
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1156
+ <sort_order>110</sort_order>
1157
+ <show_in_default>1</show_in_default>
1158
+ <show_in_website>1</show_in_website>
1159
+ <show_in_store>1</show_in_store>
1160
+ <comment><![CDATA[The parcel is delivered on Saturday if it is timely dropped in the bpost network.]]></comment>
1161
+ </saturday_delivery>
1162
+
1163
+ <saturday_delivery_from translate="label">
1164
+ <label>.. as from</label>
1165
+ <frontend_type>text</frontend_type>
1166
+ <sort_order>120</sort_order>
1167
+ <depends>
1168
+ <saturday_delivery>1</saturday_delivery>
1169
+ </depends>
1170
+ <show_in_default>1</show_in_default>
1171
+ <show_in_website>1</show_in_website>
1172
+ <show_in_store>1</show_in_store>
1173
+ </saturday_delivery_from>
1174
+ </fields>
1175
+ </bpost_parcellocker>
1176
+ </groups>
1177
+ </carriers>
1178
+ </sections>
1179
+ </config>
app/code/community/Bpost/ShM/sql/.DS_Store ADDED
Binary file
app/code/community/Bpost/ShM/sql/bpost_shm_setup/install-0.0.1.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @category Checkout
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+
11
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ $installer->run("CREATE TABLE IF NOT EXISTS {$installer->getTable('bpost_tablerates_homedelivery')} (
16
+ `pk` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
17
+ `website_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Website Id',
18
+ `dest_country_id` varchar(4) NOT NULL DEFAULT '0' COMMENT 'Destination coutry ISO/2 or ISO/3 code',
19
+ `dest_region_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Destination Region Id',
20
+ `dest_zip` varchar(10) NOT NULL DEFAULT '*' COMMENT 'Destination Post Code (Zip)',
21
+ `condition_name` varchar(20) NOT NULL COMMENT 'Rate Condition name',
22
+ `condition_value` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Rate condition value',
23
+ `price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Price',
24
+ `cost` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Cost',
25
+ PRIMARY KEY (`pk`),
26
+ UNIQUE KEY `1sSnI1YRZBOJVxazlZlG4UQOe9JFMNOcz9b` (`website_id`,`dest_country_id`,`dest_region_id`,`dest_zip`,`condition_name`,`condition_value`)
27
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bpost Homedelivery Tablerate'");
28
+
29
+ $installer->endSetup();
30
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.1-0.0.2.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @category Checkout
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ $installer = $this;
12
+ $installer->startSetup();
13
+ $installer->run("CREATE TABLE IF NOT EXISTS {$installer->getTable('bpost_tablerates_international')} (
14
+ `pk` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
15
+ `website_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Website Id',
16
+ `dest_country_id` varchar(4) NOT NULL DEFAULT '0' COMMENT 'Destination coutry ISO/2 or ISO/3 code',
17
+ `dest_region_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Destination Region Id',
18
+ `dest_zip` varchar(10) NOT NULL DEFAULT '*' COMMENT 'Destination Post Code (Zip)',
19
+ `condition_name` varchar(20) NOT NULL COMMENT 'Rate Condition name',
20
+ `condition_value` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Rate condition value',
21
+ `price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Price',
22
+ `cost` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Cost',
23
+ PRIMARY KEY (`pk`),
24
+ UNIQUE KEY `Ig6Km9sdgz94pqcZJIn6S8mQWTIdQ3O3E01` (`website_id`,`dest_country_id`,`dest_region_id`,`dest_zip`,`condition_name`,`condition_value`)
25
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bpost International Tablerate'");
26
+ $installer->endSetup();
27
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.10-0.1.0.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @subpackage Shipping
6
+ * @category Checkout
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ /* @var $installer Mage_Core_Model_Resource_Setup */
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment_grid'), 'bpost_status', "varchar(255) null default ''");
16
+
17
+ $installer->endSetup();
18
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.2-0.0.3.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @category Checkout
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ $installer = $this;
12
+ $installer->startSetup();
13
+ $installer->run("CREATE TABLE IF NOT EXISTS {$installer->getTable('bpost_tablerates_pickuppoint')} (
14
+ `pk` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
15
+ `website_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Website Id',
16
+ `dest_country_id` varchar(4) NOT NULL DEFAULT '0' COMMENT 'Destination coutry ISO/2 or ISO/3 code',
17
+ `dest_region_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Destination Region Id',
18
+ `dest_zip` varchar(10) NOT NULL DEFAULT '*' COMMENT 'Destination Post Code (Zip)',
19
+ `condition_name` varchar(20) NOT NULL COMMENT 'Rate Condition name',
20
+ `condition_value` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Rate condition value',
21
+ `price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Price',
22
+ `cost` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Cost',
23
+ PRIMARY KEY (`pk`),
24
+ UNIQUE KEY `QIMuM8yoQUkmjsNM6FmJFjBrOZHNJAEu8kP` (`website_id`,`dest_country_id`,`dest_region_id`,`dest_zip`,`condition_name`,`condition_value`)
25
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bpost Pickuppoint Tablerate'");
26
+ $installer->endSetup();
27
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.3-0.0.4.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @category Checkout
8
+ * @author PHPro (info@phpro.be)
9
+ */
10
+ if(!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')){
11
+ $installer = $this;
12
+ $installer->startSetup();
13
+ $installer->run("CREATE TABLE IF NOT EXISTS {$installer->getTable('bpost_tablerates_parcellocker')} (
14
+ `pk` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
15
+ `website_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Website Id',
16
+ `dest_country_id` varchar(4) NOT NULL DEFAULT '0' COMMENT 'Destination coutry ISO/2 or ISO/3 code',
17
+ `dest_region_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Destination Region Id',
18
+ `dest_zip` varchar(10) NOT NULL DEFAULT '*' COMMENT 'Destination Post Code (Zip)',
19
+ `condition_name` varchar(20) NOT NULL COMMENT 'Rate Condition name',
20
+ `condition_value` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Rate condition value',
21
+ `price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Price',
22
+ `cost` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Cost',
23
+ PRIMARY KEY (`pk`),
24
+ UNIQUE KEY `pnHi2GLMpOEktcG4ZpVdrOImXhJkq3bwjKd` (`website_id`,`dest_country_id`,`dest_region_id`,`dest_zip`,`condition_name`,`condition_value`)
25
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bpost Parcel Locker Tablerate'");
26
+ $installer->endSetup();
27
+ }
28
+ else{
29
+ $popupTitle = Mage::helper('bpost_shm')->__('A previous version of the bpost extension was detected!');
30
+ $popupMessage = Mage::helper('bpost_shm')->__('Please remove or disable the old bpost extension prior to the installation of the new one.');
31
+ Mage::getModel('adminnotification/inbox')->add('4', $popupTitle . ' ' . $popupMessage, '', '', true);
32
+ $installer = $this;
33
+ $installer->startSetup();
34
+ $installer->run("DELETE from {$installer->getTable('core_resource')} where code='bpost_shm_setup';");
35
+ $installer->endSetup();
36
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.4-0.0.5.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'), 'bpost_label_exported', "int(11) null");
13
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'), 'bpost_label_path', "varchar(255) null default ''");
14
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'), 'bpost_tracking_url', "varchar(255) null default ''");
15
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_label_exported', "bool null default 0");
16
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_label_exists', "bool null default 0");
17
+
18
+ $installer->endSetup();
19
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.5-0.0.6.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'bpost_drop_date', "date null");
14
+
15
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'), 'bpost_status', "varchar(255) null default ''");
16
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'), 'bpost_shipment_automated', "bool null default 0");
17
+
18
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_drop_date', "date null");
19
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_status', "varchar(255) null default ''");
20
+
21
+
22
+ $installer->endSetup();
23
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.6-0.0.7.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ $installer = $this;
12
+ $installer->startSetup();
13
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_return_label_exists', "bool null default 0");
14
+
15
+ $installer->endSetup();
16
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.7-0.0.8.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ //create the return label table
16
+ $table_returnLabel = $installer->getConnection()->newTable($installer->getTable('bpost_shm/returnlabel'))
17
+ ->addColumn('label_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
18
+ 'unsigned' => true,
19
+ 'nullable' => false,
20
+ 'primary' => true,
21
+ 'identity' => true,
22
+ ), 'Label unique ID')
23
+ ->addColumn('label_barcode', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
24
+ 'nullable' => false,
25
+ 'default' => "",
26
+ ), "Barcode of the Label")
27
+ ->addColumn('label_pdf_path', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
28
+ 'nullable' => false,
29
+ ), "Local path of the pdf file")
30
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
31
+ 'nullable' => false,
32
+ ), "Id of the order")
33
+ ->addColumn('date_created', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(), 'Creation Date')
34
+ ->setComment('bpost Shipping Return Labels');
35
+ $installer->getConnection()->createTable($table_returnLabel);
36
+
37
+ $installer->endSetup();
38
+
39
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.8-0.0.9.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @subpackage Shipping
6
+ * @category Checkout
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ /* @var $installer Mage_Core_Model_Resource_Setup */
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'), 'bpost_return_barcode', "varchar(255) null default ''");
16
+
17
+ $installer->endSetup();
18
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.0.9-0.0.10.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ //create the return label table
16
+ $table_returnLabel = $installer->getConnection()->newTable($installer->getTable('bpost_shm/bpost_country'))
17
+ ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
18
+ 'unsigned' => true,
19
+ 'nullable' => false,
20
+ 'primary' => true,
21
+ 'identity' => true,
22
+ ), 'country unique ID')
23
+ ->addColumn('country_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, 2, array(
24
+ 'nullable' => false,
25
+ 'default' => "",
26
+ ), "country code")
27
+ ->setComment('bpost country code');
28
+ $installer->getConnection()->createTable($table_returnLabel);
29
+ $installer->endSetup();
30
+
31
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.0-0.1.1.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @subpackage Shipping
6
+ * @category Checkout
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ /* @var $installer Mage_Core_Model_Resource_Setup */
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_reference', "varchar(20) null default ''");
16
+
17
+ $installer->endSetup();
18
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.1-0.1.2.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @subpackage Shipping
6
+ * @category Checkout
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ /* @var $installer Mage_Core_Model_Resource_Setup */
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_grid'), 'bpost_reference', "varchar(20) null default ''");
16
+
17
+ $installer->endSetup();
18
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.2-0.1.3.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @subpackage Shipping
6
+ * @category Checkout
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ /* @var $installer Mage_Core_Model_Resource_Setup */
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'bpost_pickuplocation_id', "varchar(255) null");
16
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_pickuplocation_id', "varchar(255) null");
17
+
18
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_notification_sms', "varchar(255) null");
19
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_notification_email', "varchar(255) null");
20
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'bpost_notification_sms', "varchar(255) null");
21
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'bpost_notification_email', "varchar(255) null");
22
+
23
+ $installer->endSetup();
24
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.3-0.1.4.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ //create the return label table
16
+ $table_holidays = $installer->getConnection()->newTable($installer->getTable('bpost_shm/bpost_holidays'))
17
+ ->addColumn('holiday_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
18
+ 'unsigned' => true,
19
+ 'nullable' => false,
20
+ 'primary' => true,
21
+ 'identity' => true,
22
+ ), 'holiday unique ID')
23
+ ->addColumn('date', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
24
+ 'nullable' => true,
25
+ 'default' => null,
26
+ ), "date")
27
+ ->setComment('bpost holiday list');
28
+ $installer->getConnection()->createTable($table_holidays);
29
+
30
+ //import 2015 holidays
31
+ $installer->run("
32
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-01-01');
33
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-04-06');
34
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-05-01');
35
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-05-14');
36
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-05-25');
37
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-07-21');
38
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-08-15');
39
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-11-01');
40
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-01-11');
41
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2015-12-25');
42
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-01-01');
43
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-03-28');
44
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-05-01');
45
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-05-05');
46
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-05-16');
47
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-07-21');
48
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-08-15');
49
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-11-01');
50
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-01-11');
51
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2016-01-25');
52
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-01-01');
53
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-04-17');
54
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-05-01');
55
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-05-25');
56
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-06-05');
57
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-07-21');
58
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-08-15');
59
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-11-01');
60
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-01-11');
61
+ INSERT INTO {$installer->getTable('bpost_shm/bpost_holidays')} (date) values ('2017-01-25');
62
+ ");
63
+
64
+ $installer->endSetup();
65
+
66
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.4-0.1.5.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ /* @var $installer Mage_Core_Model_Resource_Setup */
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'bpost_reduced_mobility', "bool null default 0");
16
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_reduced_mobility', "bool null default 0");
17
+
18
+ $installer->endSetup();
19
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.5-0.1.6.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+
10
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
11
+ /* @var $installer Mage_Core_Model_Resource_Setup */
12
+ $installer = $this;
13
+ $installer->startSetup();
14
+
15
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'bpost_disable_saturday_delivery', "bool null");
16
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_disable_saturday_delivery', "bool null");
17
+
18
+ $installer->endSetup();
19
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.6-0.1.7.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'bpost_delivery_date', "date null");
14
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'bpost_delivery_date', "date null");
15
+
16
+ $installer->endSetup();
17
+ }
app/code/community/Bpost/ShM/sql/bpost_shm_setup/upgrade-0.1.7-0.1.8.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PHPro
4
+ *
5
+ * @package Bpost
6
+ * @subpackage ShM
7
+ * @author PHPro (info@phpro.be)
8
+ */
9
+ if (!Mage::helper('core')->isModuleEnabled('Bpost_ShippingManager')) {
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'bpost_saturday_cost_applied', "bool null");
13
+ $installer->endSetup();
14
+ }
app/design/adminhtml/default/default/layout/bpost/shm.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+
4
+ <popup_handle>
5
+ <reference name="head">
6
+ <action method="addJS">
7
+ <script>bpost/shm/adminhtml/informationpopup.js</script>
8
+ </action>
9
+ <action method="addItem">
10
+ <type>js_css</type>
11
+ <name>prototype/windows/themes/default.css</name>
12
+ </action>
13
+ <action method="addItem">
14
+ <type helper="bpost_shm/data/getMagentoWindowCssItemType" />
15
+ <name helper="bpost_shm/data/getMageWindowCss" />
16
+ </action>
17
+ <action method="addCss">
18
+ <name>css/bpost/informationpopup.css</name>
19
+ </action>
20
+ </reference>
21
+ </popup_handle>
22
+
23
+ <adminhtml_bpost_shm_config_popup>
24
+ <reference name="root">
25
+ <action method="setTemplate">
26
+ <template>bpost/empty.phtml</template>
27
+ </action>
28
+ </reference>
29
+ <reference name="head">
30
+ <action method="addCss">
31
+ <name>css/bpost/informationpopup.css</name>
32
+ </action>
33
+ </reference>
34
+ </adminhtml_bpost_shm_config_popup>
35
+
36
+ <adminhtml_system_config_edit>
37
+ <update handle="popup_handle" />
38
+ </adminhtml_system_config_edit>
39
+
40
+ <adminhtml_bpost_shm_config_informationpopup>
41
+ <update handle="adminhtml_bpost_shm_config_popup"/>
42
+ <reference name="content">
43
+ <block type="core/template" name="informationPopup" template="bpost/informationpopup.phtml"/>
44
+ </reference>
45
+ </adminhtml_bpost_shm_config_informationpopup>
46
+
47
+ <adminhtml_bpost_shm_config_screenshotpopup>
48
+ <update handle="adminhtml_bpost_shm_config_popup"/>
49
+
50
+ <reference name="content">
51
+ <block type="core/template" name="screenshot.popup" template="bpost/screenshotpopup.phtml"/>
52
+ </reference>
53
+ </adminhtml_bpost_shm_config_screenshotpopup>
54
+
55
+ <adminhtml_sales_order_view>
56
+ <reference name="sales_order_tabs">
57
+ <action method="addTab">
58
+ <name>order_view_tab_bpostreturnlabeltab</name>
59
+ <block>bpost_shm/adminhtml_sales_order_view_tab_returnlabels</block>
60
+ </action>
61
+ </reference>
62
+ </adminhtml_sales_order_view>
63
+
64
+ <adminhtml_bpost_shm_allorders_index>
65
+ <update handle="popup_handle" />
66
+ </adminhtml_bpost_shm_allorders_index>
67
+
68
+ <adminhtml_bpost_shm_pendingorders_index>
69
+ <update handle="popup_handle" />
70
+ </adminhtml_bpost_shm_pendingorders_index>
71
+ </layout>
app/design/adminhtml/default/default/template/bpost/empty.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
3
+ <head>
4
+ <?php echo $this->getChildHtml('head') ?>
5
+ </head>
6
+ <body class="page-empty <?php echo $this->getBodyClass()?$this->getBodyClass():'' ?>">
7
+ <div>
8
+ <?php echo $this->getChildHtml('after_body_start') ?>
9
+ <?php echo $this->getChildHtml('global_messages') ?>
10
+ <?php echo $this->getChildHtml('content') ?>
11
+ <?php echo $this->getChildHtml('before_body_end') ?>
12
+ <?php echo $this->getAbsoluteFooter() ?>
13
+ </div>
14
+ </body>
15
+ </html>
app/design/adminhtml/default/default/template/bpost/informationpopup.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $helper = Mage::helper('bpost_shm') ?>
2
+ <p><?php echo $helper->__('Bpost Shipping Manager is a service offered by Bpost,
3
+ Allowing your customer to chose their preferred delivery method when ordering in your webshop.') ?></p>
4
+ <p><?php echo $helper->__('The following delivery methods are currently supported:') ?></p>
5
+ <ul>
6
+ <li><?php echo $helper->__('Receive your parcel at home or at the office.') ?></li>
7
+ <li><?php echo $helper->__('Over 1.250 locations nearby home or the office.') ?></li>
8
+ <li><?php echo $helper->__('Pick-up your parcel whenever you want, thanks to the 24/7 service of bpost.') ?></li>
9
+ </ul>
10
+ <p><?php echo $helper->__('When activated and correctly installed,
11
+ this module also allows you to completely integrate the bpost administration into your webshop.') ?></p>
12
+ <p><?php echo $helper->__('This means that orders are automatically added to the bpost portal.') ?></p>
13
+ <p><?php echo $helper->__('Furthermore, if enabled, it is possible to generate your labels and trakcing codes directly from the Magento order admin page.') ?></p>
14
+ <p><?php echo $helper->__('No more hassle and 100% transparent!') ?></p>
15
+ <p><?php echo $helper->__('<a target="_blank" href="%s">Documentation</a>: links to the bpost freshdesk for Magento',"http://bpost.freshdesk.com/solution/categories/99521/folders/4000013305");?></p>
app/design/adminhtml/default/default/template/bpost/screenshotpopup.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <img class="example-screenshot" src="<?php echo $this->getImagePath();?>" alt="<?php echo Mage::helper('bpost_shm')->__("Example screenshot of the bpost module.");?>" />
app/design/adminhtml/default/default/template/bpost/widget/grid/massaction.phtml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <div id="<?php echo $this->getHtmlId() ?>">
28
+ <table cellspacing="0" cellpadding="0" class="massaction">
29
+ <tr>
30
+ <td><?php if ($this->getUseSelectAll()):?>
31
+ <a href="#" onclick="return <?php echo $this->getJsObjectName() ?>.selectAll()"><?php echo $this->__('Select All') ?></a>
32
+ <span class="separator">|</span>
33
+ <a href="#" onclick="return <?php echo $this->getJsObjectName() ?>.unselectAll()"><?php echo $this->__('Unselect All') ?></a>
34
+ <span class="separator">|</span>
35
+ <?php endif; ?>
36
+ <a href="#" onclick="return <?php echo $this->getJsObjectName() ?>.selectVisible()"><?php echo $this->__('Select Visible') ?></a>
37
+ <span class="separator">|</span>
38
+ <a href="#" onclick="return <?php echo $this->getJsObjectName() ?>.unselectVisible()"><?php echo $this->__('Unselect Visible') ?></a>
39
+ <span class="separator">|</span>
40
+ <strong id="<?php echo $this->getHtmlId() ?>-count">0</strong> <?php echo $this->__('items selected') ?>
41
+ </td>
42
+ <td>
43
+ <div class="right">
44
+ <div class="entry-edit">
45
+ <?php if ($this->getHideFormElement() !== true):?>
46
+ <form action="" id="<?php echo $this->getHtmlId() ?>-form" method="post">
47
+ <?php endif ?>
48
+ <?php echo $this->getBlockHtml('formkey')?>
49
+ <fieldset>
50
+ <span class="field-row">
51
+ <label><?php echo $this->__('Actions') ?></label>
52
+ <select id="<?php echo $this->getHtmlId() ?>-select" class="required-entry select absolute-advice local-validation">
53
+ <option value=""></option>
54
+ <?php foreach($this->getItems() as $_item): ?>
55
+ <option value="<?php echo $_item->getId() ?>"<?php echo ($_item->getSelected() ? ' selected="selected"' : '')?>><?php echo $_item->getLabel() ?></option>
56
+ <?php endforeach; ?>
57
+ </select>
58
+ </span>
59
+ <span class="outer-span" id="<?php echo $this->getHtmlId() ?>-form-hiddens"></span>
60
+ <span class="outer-span" id="<?php echo $this->getHtmlId() ?>-form-additional"></span>
61
+ <span class="field-row">
62
+ <?php echo $this->getSubmitButtonHtml() ?>
63
+ </span>
64
+ </fieldset>
65
+ <?php if ($this->getHideFormElement() !== true):?>
66
+ </form>
67
+ <?php endif ?>
68
+ </div>
69
+
70
+ <div class="no-display">
71
+ <?php foreach($this->getItems() as $_item): ?>
72
+ <div id="<?php echo $this->getHtmlId() ?>-item-<?php echo $_item->getId() ?>-block">
73
+ <?php echo $_item->getAdditionalActionBlockHtml() ?>
74
+ </div>
75
+ <?php endforeach; ?>
76
+ </div>
77
+ </div>
78
+ </td>
79
+ </tr>
80
+ </table>
81
+ <?php if(!$this->getParentBlock()->canDisplayContainer()): ?>
82
+ <script type="text/javascript">
83
+ <?php echo $this->getJsObjectName() ?>.setGridIds('<?php echo $this->getGridIdsJson() ?>');
84
+ </script>
85
+ <?php endif; ?>
86
+ </div>
app/design/frontend/base/default/layout/bpost/shm.xml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <checkout_header>
4
+ <reference name="head">
5
+ <action method="addJs">
6
+ <script>bpost/shm/checkout.js</script>
7
+ </action>
8
+
9
+ <action method="addCss">
10
+ <name>css/bpost/checkout.css</name>
11
+ </action>
12
+
13
+ <block type="core/template" name="gmapsapi" template="bpost/shm/gmapsapi.phtml"/>
14
+ </reference>
15
+ </checkout_header>
16
+
17
+ <checkout_onepage_index>
18
+ <update handle="checkout_header"/>
19
+ </checkout_onepage_index>
20
+
21
+ <onestepcheckout_index_index>
22
+ <update handle="checkout_header"/>
23
+
24
+ <reference name="head">
25
+ <action method="addJs">
26
+ <script>bpost/shm/onestepcheckout_shipping.js</script>
27
+ </action>
28
+
29
+ <action method="addItem">
30
+ <type>skin_js</type><name>js/bpost/onestepcheckout.js</name>
31
+ </action>
32
+ </reference>
33
+ </onestepcheckout_index_index>
34
+ </layout>
app/design/frontend/base/default/template/bpost/shm/append_bpost_shippingmethod.phtml ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $settings = $this->getSettings() ?>
2
+ <?php $bpostHelper = Mage::helper("bpost_shm");?>
3
+
4
+ <div id="bpostShm" class="bpostspotswrapper">
5
+ <?php if($bpostHelper->getIsOnestepCheckout()){ ?>
6
+ <div id="bpost-info-wrapper">
7
+ <div id="bpostinfo"></div>
8
+ </div>
9
+ <?php }else{ ?>
10
+ <div id="bpostinfo"></div>
11
+ <?php } ?>
12
+
13
+ <div id="bpostresult"></div>
14
+
15
+ <?php if($this->getCurrentShippingMethod() == "bpostshm_bpost_pickuppoint"){ ?>
16
+ <a href="#" id="selectPickupPoint" type="3"><?php echo $settings['select_text'] ?></a>
17
+ <?php }else{ ?>
18
+ <a href="#" id="selectPickupPoint" type="4"><?php echo $settings['select_text_parcel_locker'] ?></a>
19
+ <?php } ?>
20
+
21
+ <input id="bpost-id" type="hidden" name="bpost[id]" class="validate-bpostspot validate-parcel"/>
22
+ <input type="hidden" name="bpost[street]"/>
23
+ <input type="hidden" name="bpost[city]"/>
24
+ <input type="hidden" name="bpost[postcode]"/>
25
+ <input type="hidden" name="bpost[name]"/>
26
+
27
+ <div class="notifications" id="notifications-pick-up-point">
28
+ <h5><?php echo $settings['notifications_text_pickup_point'] ?></h5>
29
+ <label for="pickup-point-notification-sms"<?php echo !$this->getBpostNotificationSms() || $this->getBpostNotificationSms() == "-" ? ' class="disabled"' : ''; ?>><input id="pickup-point-notification-sms" type="radio" value="sms" name="notification"<?php echo !$this->getBpostNotificationSms() || $this->getBpostNotificationSms() == "-" ? ' disabled="disabled"' : ''; ?>/> <?php echo $settings['notifications_sms_pickup_point'] ?> (<?php echo ($this->getBpostNotificationSms() ?: '<span class="error">'.$settings['no_telephone_number'].'</span>'); ?>)</label>
30
+ <label for="pickup-point-notification-email"><input type="radio" id="pickup-point-notification-email" name="notification" value="email"/> <?php echo $settings['notifications_email'] ?> (<?php echo $this->getBpostNotificationEmail(); ?>)</label>
31
+ </div>
32
+
33
+ <div class="notifications" id="notifications-parcel-locker">
34
+ <h5><?php echo $settings['notifications_text_parcel_locker'] ?></h5>
35
+ <label for="notification-sms"<?php echo !$this->getBpostNotificationSms() || $this->getBpostNotificationSms() == "-" ? ' class="disabled"' : ''; ?>><input type="checkbox" id="notification-sms" value="sms" name="parcel-notification"<?php echo !$this->getBpostNotificationSms() || $this->getBpostNotificationSms() == "-" ? ' disabled="disabled"' : ''; ?>/> <?php echo $settings['notifications_sms_parcel_locker'] ?> (<?php echo ($this->getBpostNotificationSms() ?: '<span class="error">'.$settings['no_telephone_number'].'</span>'); ?>)</label>
36
+ <br/>
37
+ <div id="reduced-mobility-wrapper">
38
+ <label for="reduced-mobility"><input type="checkbox" id="reduced-mobility" name="reduced-mobility"/> <?php echo $bpostHelper->__("I wish to use the reduced mobility zone"); ?></label>
39
+ <div class="reduced-mobility-tooltip"><?php echo $bpostHelper->__("By using this option, customers with reduced mobility can use the lockers of the machine easiest to reach.");?></div>
40
+ </div>
41
+ </div>
42
+ </div>
43
+
44
+ <div id="bpostDelivery">
45
+ <div class="bpost-deliverydate-wrapper">
46
+ <h5><?php echo $settings['datepicker_delivery_date_text'] ?></h5>
47
+ <div class="bpost-display-deliverydate"></div>
48
+ </div>
49
+ <div class="bpost-choose-deliverydate"></div>
50
+ <div class="cf"></div>
51
+ <div class="bpost-saturday-delivery">
52
+ <label for="bpost-saturday">
53
+ <input type="checkbox" <?php if($bpostHelper->getIsOnestepCheckout()){ echo 'onclick="get_methods_separate();"';}?> name="bpost_saturday_delivery" id="bpost-saturday" value="1" <?php if($this->getQuote()->getBpostDisableSaturdayDelivery() || is_null($this->getQuote()->getBpostDisableSaturdayDelivery())){echo 'checked="checked"';}?>/>
54
+ <div class="bpost-label-text"><?php echo $settings['datepicker_saturday_delivery_text'] ?><?php if($this->getSaturdayDeliveryCost()) { ?><br /><small><?php echo sprintf($settings['datepicker_saturday_delivery_cost'], $this->getSaturdayDeliveryCost()) ?></small><?php } ?></div>
55
+ </label>
56
+ </div>
57
+ <input type="hidden" name="bpost[deliverydate]" class="required-entry"/>
58
+ </div>
59
+
60
+ <script type="text/javascript">
61
+ window.onestepcheckout_set_methods_separate = '<?php echo $this->getUrl('onestepcheckout/ajax/set_methods_separate', array('_secure'=>true));?>';
62
+ window.bpostShM = new Bpost.ShM(<?php echo json_encode($settings); ?>, "<?php echo $this->getCurrentShippingMethod(); ?>");
63
+
64
+ Validation.add('validate-bpostspot', "<?php echo Mage::helper('bpost_shm')->__('Please select a bpost pick-up point'); ?>", function (v) {
65
+ return !($('s_method_bpostshm_bpost_pickuppoint').checked && Validation.get('IsEmpty').test(v))
66
+ });
67
+
68
+ Validation.add('validate-parcel', "<?php echo Mage::helper('bpost_shm')->__('Please select a bpost parcel locker'); ?>", function (v) {
69
+ return !($('s_method_bpostshm_bpost_parcellocker').checked && Validation.get('IsEmpty').test(v))
70
+ });
71
+
72
+ Validation.add('validate-multiple-delivery-dates', "<?php echo Mage::helper('bpost_shm')->__('Please select a delivery date'); ?>", function (v,elm) {
73
+ var inputs = $$('input[name="' + elm.name.replace(/([\\"])/g, '\\$1') + '"]');
74
+
75
+ var error = 1;
76
+ for(var i=0;i<inputs.length;i++) {
77
+ if((inputs[i].type == 'checkbox' || inputs[i].type == 'radio') && inputs[i].checked == true) {
78
+ error = 0;
79
+ }
80
+
81
+ if(Validation.isOnChange && (inputs[i].type == 'checkbox' || inputs[i].type == 'radio')) {
82
+ Validation.reset(inputs[i]);
83
+ }
84
+ }
85
+
86
+ if( error == 0 ) {
87
+ return true;
88
+ } else {
89
+ return false;
90
+ }
91
+ });
92
+
93
+ </script>
app/design/frontend/base/default/template/bpost/shm/gmapsapi.phtml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php $_configHelper = Mage::helper('bpost_shm/system_config') ?>
2
+ <?php if ($_configHelper->getBpostShippingConfig('browser_api_key') != "") { ?>
3
+ <script src="https://maps.googleapis.com/maps/api/js?key=<?php echo $_configHelper->getBpostShippingConfig('browser_api_key') ?>&sensor=false&v=3.17&sensor=false&libraries=geometry,places" type="text/javascript"></script>
4
+ <?php } else { ?>
5
+ <script src="https://maps.googleapis.com/maps/api/js?sensor=false&v=3.17&sensor=false&libraries=geometry,places" type="text/javascript"></script>
6
+ <?php } ?>
7
+ <script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
app/etc/modules/zBpost_ShM.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Bpost_ShM>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Bpost_ShM>
8
+ </modules>
9
+ </config>
app/locale/en_US/Bpost_ShM.csv ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Monday","Monday"
2
+ "Tuesday","Tuesday"
3
+ "Wednesday","Wednesday"
4
+ "Thursday","Thursday"
5
+ "Friday","Friday"
6
+ "Saturday","Saturday"
7
+ "Sunday","Sunday"
8
+ "January","January"
9
+ "February","February"
10
+ "March","March"
11
+ "April","April"
12
+ "May","May"
13
+ "June","June"
14
+ "July","July"
15
+ "August","August"
16
+ "September","September"
17
+ "October","October"
18
+ "November","November"
19
+ "December","December"
20
+ "# of Items","# of Items"
21
+ "%s label(s) have been generated and statuses have been changed.","%s label(s) have been generated and statuses have been changed."
22
+ "%s orders already had downloaded labels.","%s orders already had downloaded labels."
23
+ "(extra cost Saturday delivery: %s EUR)","(extra cost Saturday delivery: %s EUR)"
24
+ "A previous version of the bpost extension was detected!","A previous version of the bpost extension was detected!"
25
+ "Action","Action"
26
+ "Actions","Actions"
27
+ "All bposts orders","All bpost orders"
28
+ "An error occurred while importing table rates.","An error occurred while importing table rates."
29
+ "Barcode #","Barcode #"
30
+ "Bill to Name","Bill to"
31
+ "Bpost Shipping Manager is a service offered by Bpost","bpost Shipping Manager is a service offered by bpost"
32
+ "By using this option","By using this option"
33
+ "Click here for more information","Click here for more information"
34
+ "Click here to change the bpost parcel locker point.","Click here to change the bpost parcel locker."
35
+ "Click here to change the bpost pick-up point.","Click here to change the bpost pick-up point."
36
+ "Click here to choose a bpost parcel locker point.","Click here to choose a bpost parcel locker."
37
+ "Click here to choose a bpost pick-up point.","Click here to choose a bpost pick-up point."
38
+ "Click here to track your bpost shipments.","Click here to track your bpost shipments."
39
+ "Closed","Closed"
40
+ "Country","Country"
41
+ "Date Created","Creation date"
42
+ "Delivery Date","Delivery Date"
43
+ "Delivery at home or at the office","Delivery at home or at the office"
44
+ "Delivery in a parcel locker","Delivery in a parcel locker"
45
+ "Delivery in a pick-up point or postal office","Delivery in a pick-up point"
46
+ "Displays calculated delivery date in the frontend:","Displays calculated delivery date in the frontend:"
47
+ "Download","Download"
48
+ "Download all undownloaded","Download labels"
49
+ "Download bpost label","Download bpost label"
50
+ "Drop date","Drop date"
51
+ "Duplicate Row #%s (Country ","Duplicate Row #%s (Country "
52
+ "Email","Email"
53
+ "Error creating bpost order","Error creating bpost order"
54
+ "Error while creating a bpost order for Magento order #%s. Please check your API log.","Error while creating a bpost order for Magento order #%s. Please check your API log."
55
+ "Example","Example"
56
+ "Example screenshot of the bpost module.","Example screen of the bpost module."
57
+ "Export CSV","Export CSV"
58
+ "File has not been imported. See the following list of errors: %s","File has not been imported. See the following list of errors: %s"
59
+ "Filepath","Filepath"
60
+ "Filter","Search"
61
+ "Flat Rate","Flat Rate"
62
+ "Friday","Friday"
63
+ "Furthermore","Furthermore"
64
+ "G.T. (Purchased)","Order amount"
65
+ "Generate Label and Complete","Generate shipping label"
66
+ "How do you want to be notified when your parcel is available in the parcel locker?","Optional services"
67
+ "How do you want to be notified when your parcel is available in the pick-up point?","How do you want to be notified when your parcel is available in the pick-up point?"
68
+ "I don","I don"
69
+ "I wish to use the reduced mobility zone","Use the reduced mobility zone"
70
+ "Import","Import"
71
+ "Invalid %s ","Invalid %s "
72
+ "Invalid Country ","Invalid Country "
73
+ "Invalid Region/State ","Invalid Region/State "
74
+ "Invalid Shipping Price ","Invalid Shipping Price "
75
+ "Invalid Table Rates File Format","Invalid Table Rates File Format"
76
+ "Invalid Table Rates format in the Row #%s","Invalid Table Rates format in the Row #%s"
77
+ "Label Barcode #","Label Barcode #"
78
+ "Label download","Label download"
79
+ "Monday","Monday"
80
+ "No","No"
81
+ "No bpost product configuration found for %s. Please check your bpost shipping manager for international delivery.","No bpost product configuration found for %s. Please check your bpost shipping manager for international delivery."
82
+ "No label generated yet - please perform the ‘Generate Label and Complete’ action from the overview.","No label generated yet - please perform the ‘Generate shipping label’ action from the overview."
83
+ "No label response received for Magento order #%s.","No label response received for Magento order #%s."
84
+ "No more hassle and 100% transparent!","No more hassle and 100% transparent!"
85
+ "No points could be found. Please use the filter above or drag the map to get a better result.","No points could be found. Please use the search functionality above or drag the map to get a better result."
86
+ "No undownloaded labels found.","No undownloaded labels found."
87
+ "Order #","Order #"
88
+ "Pending bpost orders","Pending bpost orders"
89
+ "Please remove or disable the old bpost extension prior to the installation of the new one.","Please remove or disable the old bpost extension prior to the installation of the new one."
90
+ "Please select a bpost parcel locker","Please select a bpost parcel locker"
91
+ "Please select a bpost pick-up point","Please select a bpost pick-up point"
92
+ "Please select a delivery date","Please select a delivery date"
93
+ "Please select a postcode or city first.","Please select a postal code or city first."
94
+ "Please wait. Loading bpost map based on your address","Please wait. Loading bpost map based on your address"
95
+ "Purchased From (Store)","Purchased From (Store)"
96
+ "Purchased On","Purchased On"
97
+ "Region/State","Region/State"
98
+ "Saturday","Saturday"
99
+ "Select","Select"
100
+ "Select All","Select All"
101
+ "Select Visible","Select Visible"
102
+ "Select your preferred delivery date","Select your preferred delivery date"
103
+ "Send Email","Send Email"
104
+ "Ship to Name","Ship to"
105
+ "Shipment","Shipment"
106
+ "Shipped with bpost generateLabelAndComplete","Shipped with bpost generateLabelAndComplete"
107
+ "Shipping Price","Shipping Price"
108
+ "Some of the selected orders are not ready to be shipped or have already been shipped","Some of the selected orders are not ready to be shipped or have already been shipped"
109
+ "Something went wrong while processing order #%s","Something went wrong while processing order #%s"
110
+ "Sorry","Sorry"
111
+ "Status","Status"
112
+ "Submit","Submit"
113
+ "Successfully authenticated with bpost.","Successfully authenticated with bpost."
114
+ "Successfully exported order(s). Download the file here: %s","Successfully exported order(s). Download the file here: %s"
115
+ "Sunday","Sunday"
116
+ "Table Rates","Table Rates"
117
+ "The Bpost shipping method ","The bpost delivery method "
118
+ "The email with return label has been sent to %s.","The email with return label has been sent to %s."
119
+ "The file(s) could not be downloaded","The file(s) could not be downloaded"
120
+ "The following delivery methods are currently supported:","The following delivery methods are currently supported:"
121
+ "The order with id %s is not ready to be shipped or has already been shipped.","The order with id %s is not ready to be shipped or has already been shipped."
122
+ "The order with id %s only has non-bpost shipments.","The order with id %s only has non-bpost shipments."
123
+ "The requested file does not exist","The requested file does not exist"
124
+ "This means that orders are automatically added to the bpost portal.","This means that orders are automatically added to the bpost portal."
125
+ "Thursday","Thursday"
126
+ "Track this shipment","Track this shipment"
127
+ "Tuesday","Tuesday"
128
+ "Type in a location","Type in a location"
129
+ "Unselect All","Unselect All"
130
+ "Unselect Visible","Unselect Visible"
131
+ "View","View"
132
+ "Wednesday","Wednesday"
133
+ "When activated and correctly installed","When activated and correctly installed"
134
+ "World Business","World Business"
135
+ "World Express Pro","World Express Pro"
136
+ "Your label has been generated and statuses have been changed.","Your label has been generated and statuses have been changed."
137
+ "Your return has been generated and is available under -bpost Return labels- in this order.","Your return has been generated and is available under -bpost Return labels- in this order."
138
+ "Your selected order is not ready to be shipped or has already been shipped","Your selected order is not ready to be shipped or has already been shipped"
139
+ "Zip/Postal Code","Zip/Postal Code"
140
+ "bpost","bpost"
141
+ "bpost Return Barcodes","bpost Return Barcodes"
142
+ "bpost Return Label","bpost Return Label"
143
+ "bpost Return Labels","bpost Return Labels"
144
+ "bpost status","bpost status"
145
+ "items selected","items selected"
146
+ "no telephone number found","no telephone number found"
147
+ "send additional SMS notification","additional SMS next to standard email notification"
148
+ "via E-mail","via E-mail"
149
+ "via SMS","via SMS"
150
+ "bpost Shipping Manager","bpost Shipping Manager"
151
+ "Info text","Info text"
152
+ "Logo","Logo"
153
+ "Account id","Account id"
154
+ "Passphrase","Passphrase"
155
+ "The passphrase you entered in bpost Shipping Manager back-office application. This is not the password used to access bpost portal.","The passphrase you entered in bpost Shipping Manager back-office application. This is not the password used to access bpost portal."
156
+ "API url","API url"
157
+ "Do not modify this setting if you are not 100% sure of what you are doing.","Do not modify this setting if you are not 100% sure of what you are doing."
158
+ "Sender name","Sender name"
159
+ "Used in the webservice calls.","Used in the webservice calls."
160
+ "Sender company","Sender company"
161
+ "Sender streetname","Sender streetname"
162
+ "Sender streetnumber","Sender streetnumber"
163
+ "Sender boxnumber","Sender boxnumber"
164
+ "Sender postal code","Sender postal code"
165
+ "Sender city","Sender city"
166
+ "Sender country","Sender country"
167
+ "Sender email","Sender email"
168
+ "Sender phonenumber","Sender phonenumber"
169
+ "Use Magento to manage labels","Use Magento to manage labels"
170
+ "If you enable this option","If you enable this option"
171
+ "Label format","Label format"
172
+ "Automatic retour labels","Automatic retour labels"
173
+ "Automatic track and trace information","Automatic track and trace information"
174
+ "Display delivery date","Display delivery date"
175
+ "Displays calculated delivery date","Displays calculated delivery date"
176
+ "Days between order and shipment","Days between order and shipment"
177
+ "Choose delivery date","Choose delivery date"
178
+ "Number of delivery days shown","Number of delivery days shown"
179
+ "Next day delivery allowed till","Next day delivery allowed till"
180
+ "Saturday delivery cost","Saturday delivery cost"
181
+ "Google browser API key","Google browser API key"
182
+ "Google server API key","Google server API key"
183
+ "bpost Home delivery","bpost Home delivery"
184
+ "General","General"
185
+ "Enabled","Enabled"
186
+ "Rates","Rates"
187
+ "Free shipping","Free shipping"
188
+ ".. as of",".. as of"
189
+ "Rate type","Rate type"
190
+ "You can use flat rate or calculated table rates.","You can use flat rate or calculated table rates."
191
+ "Flat rate price","Flat rate price"
192
+ "Importing and exporting table rates only possible on website scope. View the documentation for more information.","Importing and exporting table rates is only possible on website scope. View the documentation for more information."
193
+ "Fixed fee for bpost Home delivery shipments","Fixed fee for bpost Home delivery shipments"
194
+ "Table rates condition","Table rates condition"
195
+ "Export table rates file","Export table rates file"
196
+ "Export your table rates configuration here.","Export your table rates configuration here."
197
+ "Import table rates file","Import table rates file"
198
+ "Upload your table rates configuration here. Refer to the manual for more information.","Upload your table rates configuration here. Refer to the manual for more information."
199
+ "Options","Options"
200
+ "2nd presentation","2nd presentation"
201
+ "The delivery happens against signature by the receiver. The parcel is delivered on Saturday if it is timely dropped in the bpost network.","The delivery happens against signature by the receiver. The parcel is delivered on Saturday if it is timely dropped in the bpost network."
202
+ "Insurance","Insurance"
203
+ "Insurance to insure your goods to a maximum of 500","Insurance to insure your goods to a maximum of 500 euro"
204
+ "Signature","Signature"
205
+ "The delivery happens against signature by the receiver.","The delivery happens against signature by the receiver."
206
+ "Saturday delivery","Saturday delivery"
207
+ "The parcel is delivered on Saturday if it is timely dropped in the bpost network.","The parcel is delivered on Saturday if it is timely dropped in the bpost network."
208
+ "bpost Home delivery international","bpost Home delivery international"
209
+ "Product","Product"
210
+ "Import countries","Import countries"
211
+ "Allowed countries","Allowed countries"
212
+ "International insurance","International insurance"
213
+ "Import your bpost configured countries here.","Import your bpost configured countries here."
214
+
215
+ "Your 6 digits bpost account ID used for the Shipping Manager.<br/><a target='_blank' href='http://bpost.freshdesk.com/solution/articles/4000061189'>http://bpost.freshdesk.com/solution/articles/4000061189</a>","Your 6 digits bpost account ID used for the Shipping Manager.<br/><a target='_blank' href='http://bpost.freshdesk.com/solution/articles/4000061189'>http://bpost.freshdesk.com/solution/articles/4000061189</a>"
216
+ "You need a user account from bpost to use this module. Call %s for more information.","You need a user account from bpost to use this module. Call %s for more information."
217
+ "bpost uses Google Maps API to display the map in the frontend. <strong>
Note:</strong> This is optional if you will not meet the usage limits. Visit Google’s online documentation for more information.","bpost uses Google Maps API to display the map in the frontend. <strong>
Note:</strong> This is optional if you will not meet the usage limits. Visit Google’s online documentation for more information."
218
+ "bpost uses Google Geocoding API to calculate GEO location based on the shipping address. <strong>
Note:</strong> This is optional if you will not meet the usage limits. Visit Google’s online documentation for more information.","bpost uses Google Geocoding API to calculate GEO location based on the shipping address. <strong>
Note:</strong> This is optional if you will not meet the usage limits. Visit Google’s online documentation for more information."
219
+ "Additional fee when using saturday delivery option, e.g.: 4.95.","Additional fee when using saturday delivery option, e.g.: 4.95."
220
+ "If the order is placed after this cut-off time, an extra day is added to the displayed date. Order placed = end of checkout.","If the order is placed after this cut-off time, this impacts the displayed delivery date(s). Order placed = end of checkout."
221
+ "Allow customer to choose their delivery date","Allow customer to choose their delivery date"
222
+ "If you enable this option, the bpost Track & Trace link will be added in the Magento mail templates. It is always possible to manually send these emails.<br/><a href='http://bpost.freshdesk.com/solution/articles/4000061636' target='_blank'>http://bpost.freshdesk.com/solution/articles/4000061636</a>","If you enable this option, the bpost Track & Trace link will be added in the Magento mail templates. It is always possible to manually send these emails.<br/><a href='http://bpost.freshdesk.com/solution/articles/4000061636' target='_blank'>http://bpost.freshdesk.com/solution/articles/4000061636</a>"
223
+ "If you enable this option, a retour label is automatically added and printed when generating labels. If disabled, you are able to manually create retour labels.","If you enable this option, a retour label is automatically added and printed when generating labels. If disabled, you are able to manually create retour labels."
224
+ Choose between A6 or A4 format;Choose between A6 or A4 format
225
+ "If you enable this option, labels are generated directly within Magento. It is not needed to use the bpost Shipping Manager for these tasks.","If you enable this option, labels are generated directly within Magento. It is not needed to use the bpost Shipping Manager for these tasks."
226
+ "Select one or more countries where bpost Home delivery international should be available for. Make sure your bpost shipping manager is configured properly. Otherwise no countries will be shown in this list after saving the 'Shipping Settings' configuration.","Select one or more countries where bpost Home delivery international should be available for. Make sure your bpost shipping manager is configured properly."
227
+ "Belgium","Belgium"
228
+ "Used to calculate the weight before sending it to bpost","Used to calculate the weight before sending it to bpost"
app/locale/en_US/template/email/bpost/errorhandling_create_order.html ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
2
+ <div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
3
+ <table bgcolor="#FFFFFF" cellspacing="0" cellpadding="0" border="0" width="640">
4
+ <tr>
5
+ <td valign="top" style="color: #000000; font-size: 12px; font-family: Arial, Helvetica, sans-serif; line-height:18px; margin: 0;">
6
+ Hello{{var receiver_name}},
7
+
8
+ There was an error when calling the bpost API for order #{{var order_id}}. The order was succesfully created in Magento, but please check the logs en create the order in the bpost Shipping Manager manually if needed.
9
+
10
+ Error message:
11
+
12
+ {{var error_message}}
13
+ </td>
14
+ </tr>
15
+ </table>
16
+ </div>
17
+ </body>
app/locale/en_US/template/email/bpost/returnlabel.html ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--@subject {{var store.getFrontendName()}}: New returnlabel #{{var returnlabel.label_barcode}} @-->
2
+ <!--@vars
3
+ {"store url=\"\"":"Store Url",
4
+ "var logo_url":"Email Logo Image Url",
5
+ "var logo_alt":"Email Logo Image Alt",
6
+ "htmlescape var=$order.getCustomerName()":"Customer Name",
7
+ "var order":"order object",
8
+ "var returnlabel":"return label object"}
9
+
10
+ @-->
11
+ <!--@styles
12
+ body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
13
+ @-->
14
+
15
+ <body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
16
+ <div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
17
+ <table cellspacing="0" cellpadding="0" border="0" width="100%">
18
+ <tr>
19
+ <td align="center" valign="top" style="padding:20px 0 20px 0">
20
+ <table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
21
+ <!-- [ header starts here] -->
22
+ <tr>
23
+ <td valign="top"><a href='{{store url=""}}'><img src="{{var logo_url}}" alt="{{var logo_alt}}" style="margin-bottom:10px;" border="0"/></a></td>
24
+ </tr>
25
+ <!-- [ middle starts here] -->
26
+ <tr>
27
+ <td valign="top">
28
+ <h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;">Hello, {{htmlescape var=$order.getCustomerName()}}</h1>
29
+ <p style="font-size:12px; line-height:16px; margin:0;">
30
+ You can find your returnlabel in the attachments of this email.
31
+ </p>
32
+ </td>
33
+ </tr>
34
+ <tr>
35
+ <td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;"><center><p style="font-size:12px; margin:0;">Thank you, <strong>{{var store.getFrontendName()}}</strong></p></center></td>
36
+ </tr>
37
+ </table>
38
+ </td>
39
+ </tr>
40
+ </table>
41
+ </div>
42
+ </body>
app/locale/nl_NL/Bpost_ShM.csv ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Monday","Maandag"
2
+ "Tuesday","Dinsdag"
3
+ "Wednesday","Woensdag"
4
+ "Thursday","Donderdag"
5
+ "Friday","Vrijdag"
6
+ "Saturday","Zaterdag"
7
+ "Sunday","Zondag"
8
+ "January","Januari"
9
+ "February","Februari"
10
+ "March","Maart"
11
+ "April","April"
12
+ "May","Mei"
13
+ "June","Juni"
14
+ "July","Juli"
15
+ "August","Augustus"
16
+ "September","September"
17
+ "October","Oktober"
18
+ "November","November"
19
+ "December","December"
20
+ "# of Items","# Items"
21
+ "%s label(s) have been generated and statuses have been changed.","%s label(s) gegenereerd en statussen gewijzigd."
22
+ "%s orders already had downloaded labels.","Voor %s order(s) zijn de labels reeds gedownload."
23
+ "(extra cost Saturday delivery: %s EUR)","(extra kost zaterdaglevering: %s EUR)"
24
+ "A previous version of the bpost extension was detected!","Een oudere versie van de bpost extensie werd gedetecteerd!"
25
+ "Action","Actie"
26
+ "Actions","Acties"
27
+ "All bposts orders","Alle bpost orders"
28
+ "An error occurred while importing table rates.","Er heeft zich een fout voorgedaan bij het importeren van de prijzen."
29
+ "Barcode #","Barcode #"
30
+ "Bill to Name","Facturatie aan"
31
+ "Bpost Shipping Manager is a service offered by Bpost","bpost Shipping Manager is een dienst aangeboden door bpost"
32
+ "By using this option","Door deze optie te gebruiken"
33
+ "Click here for more information","Klik hier voor meer informatie"
34
+ "Click here to change the bpost parcel locker point.","Klik hier om de pakjesautomaat te wijzigen."
35
+ "Click here to change the bpost pick-up point.","Klik hier om het afhaalpunt te wijzigen."
36
+ "Click here to choose a bpost parcel locker point.","Klik hier om een bpost pakjesautomaat te kiezen."
37
+ "Click here to choose a bpost pick-up point.","Klik hier om een bpost afhaalpunt te kiezen."
38
+ "Click here to track your bpost shipments.","Klik hier om uw bpost zendingen te volgen."
39
+ "Closed","Gesloten"
40
+ "Country","Land"
41
+ "Date Created","Creatiedatum"
42
+ "Delivery Date","Leveringsdatum"
43
+ "Delivery at home or at the office","Levering thuis of op kantoor"
44
+ "Delivery in a parcel locker","Levering in een pakjesautomaat"
45
+ "Delivery in a pick-up point or postal office","Levering in een afhaalpunt"
46
+ "Displays calculated delivery date in the frontend:","De berekende leveringsdatum wordt getoond in de frontend:"
47
+ "Download","Download"
48
+ "Download all undownloaded","Download verzendetiketten"
49
+ "Download bpost label","Download bpost verzendetiket"
50
+ "Drop date","Dropdatum"
51
+ "Duplicate Row #%s (Country ","Duplicate rij #%s (Land "
52
+ "Email","Email"
53
+ "Error creating bpost order","Fout bij het aanmaken van bpost order"
54
+ "Error while creating a bpost order for Magento order #%s. Please check your API log.","Fout bij aanmaken bpost order voor Magento order #%s. Gelieve de API log na te kijken."
55
+ "Example","Voorbeeld"
56
+ "Example screenshot of the bpost module.","Voorbeeldscherm van de bpost module."
57
+ "Export CSV","Export CSV"
58
+ "File has not been imported. See the following list of errors: %s","File werd niet geïmporteerd. Zie errorlijst: %s"
59
+ "Filepath","Filepad"
60
+ "Filter","Zoek"
61
+ "Flat Rate","Flat Rate"
62
+ "Friday","Vrijdag"
63
+ "Furthermore","Bovendien"
64
+ "G.T. (Purchased)","Orderbedrag"
65
+ "Generate Label and Complete","Verzendetiket genereren"
66
+ "How do you want to be notified when your parcel is available in the parcel locker?","Optionele services"
67
+ "How do you want to be notified when your parcel is available in the pick-up point?","Hoe wilt u verwittigd worden wanneer uw pakje beschikbaar is in het afhaalpunt?"
68
+ "I don","Ik niet"
69
+ "I wish to use the reduced mobility zone","Gebruik de beperkte mobiliteitszone"
70
+ "Import","Importeren"
71
+ "Invalid %s ","Ongeldig %s "
72
+ "Invalid Country ","Ongeldig land "
73
+ "Invalid Region/State ","Ongeldige regio "
74
+ "Invalid Shipping Price ","Verzendingskost ongeldig "
75
+ "Invalid Table Rates File Format","Ongeldig fileformaat tablerates"
76
+ "Invalid Table Rates format in the Row #%s","Ongeldig formaat table rates in rij #%s"
77
+ "Label Barcode #","Barcode verzendetiket #"
78
+ "Label download","Download verzendetiket"
79
+ "Monday","Maandag"
80
+ "No","Neen"
81
+ "No bpost product configuration found for %s. Please check your bpost shipping manager for international delivery.","Geen bpost productconfiguratie gevonden voor %s. Gelieve de instellingen voor internationale zendingen te verifiëren in uw bpost Shipping Manager."
82
+ "No label generated yet - please perform the ‘Generate Label and Complete’ action from the overview.","Nog geen verzendetiket gegenereerd - Gelieve eerst de actie ‘Verzendetiket genereren’ uit te voeren."
83
+ "No label response received for Magento order #%s.","Geen antwoord ontvangen voor Magento order #%s."
84
+ "No more hassle and 100% transparent!","Supereenvoudig en 100% transparent!"
85
+ "No points could be found. Please use the filter above or drag the map to get a better result.","Er werden geen punten gevonden. Gebruik de zoekfunctionaliteit bovenaan of sleep de map naar de gewenste positie."
86
+ "No undownloaded labels found.","Geen verzendetiketten gevonden die nog niet zijn gedownload."
87
+ "Order #","Order #"
88
+ "Pending bpost orders","bpost orders in behandeling"
89
+ "Please remove or disable the old bpost extension prior to the installation of the new one.","Gelieve de oude bpost extensie te verwijderen of deactiveren vooraleer de nieuwe te installeren."
90
+ "Please select a bpost parcel locker","Gelieve een pakjesautomaat te kiezen"
91
+ "Please select a bpost pick-up point","Gelieve een afhaalpunt te kiezeen"
92
+ "Please select a delivery date","Gelieve een leveringsdatum te kiezen"
93
+ "Please select a postcode or city first.","Gelieve eerst een postcode of stad te kiezen."
94
+ "Please wait. Loading bpost map based on your address","Gelieve te wachten. De bpost map wordt geladen voor uw adres"
95
+ "Purchased From (Store)","Aangekocht vanuit (Winkel)"
96
+ "Purchased On","Aangekocht op"
97
+ "Region/State","Regio"
98
+ "Saturday","Zaterdag"
99
+ "Select","Selecteer"
100
+ "Select All","Selecteer alle"
101
+ "Select Visible","Selecteer zichtbare"
102
+ "Select your preferred delivery date","Kies gewenste leveringsdatum"
103
+ "Send Email","Verstuur email"
104
+ "Ship to Name","Verzenden naar"
105
+ "Shipment","Zending"
106
+ "Shipped with bpost generateLabelAndComplete","Verzending via bpost genereer verzendetiket"
107
+ "Shipping Price","Verzendkost"
108
+ "Some of the selected orders are not ready to be shipped or have already been shipped","Eén of meerdere van de geselecteerde orders zijn niet klaar om te verzenden of zijn reeds verzonden"
109
+ "Something went wrong while processing order #%s","Er is iets misgegaan bij de verwerking van order #%s"
110
+ "Sorry","Sorry"
111
+ "Status","Status"
112
+ "Submit","Bevestig"
113
+ "Successfully authenticated with bpost.","Succesvol geconnecteerd met bpost."
114
+ "Successfully exported order(s). Download the file here: %s","Order(s) succesvol geëxporteerd. Download bestand hier: %s"
115
+ "Sunday","Zondag"
116
+ "Table Rates","Table Rates"
117
+ "The Bpost shipping method ","bpost verzendmethode "
118
+ "The email with return label has been sent to %s.","Email met retouretiket werd verstuurd naar %s."
119
+ "The file(s) could not be downloaded","Het bestand/de bestanden konden niet worden gedownload"
120
+ "The following delivery methods are currently supported:","Volgende leveringsmethoden worden momenteel ondersteund:"
121
+ "The order with id %s is not ready to be shipped or has already been shipped.","Order %s is niet klaar om verzonden te worden of werd reeds verzonden."
122
+ "The order with id %s only has non-bpost shipments.","Order %s bevat enkel niet-bpost zendingen."
123
+ "The requested file does not exist","Het gevraagde bestand bestaat niet"
124
+ "This means that orders are automatically added to the bpost portal.","Orders worden automatisch toegevoegd in het bpost portaal."
125
+ "Thursday","Donderdag"
126
+ "Track this shipment","Volg deze zending"
127
+ "Tuesday","Dinsdag"
128
+ "Type in a location","Voer een locatie in"
129
+ "Unselect All","Deselecteer alle"
130
+ "Unselect Visible","Deselecteer zichtbare"
131
+ "View","Detail"
132
+ "Wednesday","Woensdag"
133
+ "When activated and correctly installed","Indien geactiveerd en correct geïnstalleerd"
134
+ "World Business","World Business"
135
+ "World Express Pro","World Express Pro"
136
+ "Your label has been generated and statuses have been changed.","Verzendetiket gegenereerd en statussen aangepast."
137
+ "Your return has been generated and is available under -bpost Return labels- in this order.","Retouretiket is gegenereerdand en beschikbaar onder -bpost retouretiketten- van dit order."
138
+ "Your selected order is not ready to be shipped or has already been shipped","Dit order is niet klaar om te verzenden of werd reeds verzonden."
139
+ "Zip/Postal Code","Postcode"
140
+ "bpost","bpost"
141
+ "bpost Return Barcodes","bpost retouretiketten"
142
+ "bpost Return Label","bpost retouretiket"
143
+ "bpost Return Labels","bpost retouretiketten"
144
+ "bpost status","bpost status"
145
+ "items selected","geselecteerde items"
146
+ "no telephone number found","geen telefoonnummer gevonden"
147
+ "send additional SMS notification","extra SMS naast de standaard E-mail notificatie"
148
+ "via E-mail","via E-mail"
149
+ "via SMS","via SMS"
150
+ "bpost Shipping Manager","bpost Shipping Manager"
151
+ "Info text","Infotekst"
152
+ "Logo","Logo"
153
+ "Account id","Account id"
154
+ "Passphrase","Passphrase"
155
+ "The passphrase you entered in bpost Shipping Manager back-office application. This is not the password used to access bpost portal.","De passphrase die u heeft ingegeven in de Shipping Manager applicatie. Dit is niet het paswoord om in te loggen in het bpost portaal."
156
+ "API url","API url"
157
+ "Do not modify this setting if you are not 100% sure of what you are doing.","wijzig deze setting niet als u niet 100% zeker bent van de implicties"
158
+ "Sender name","Naam afzender"
159
+ "Used in the webservice calls.","Gebruikt in de webservice calls."
160
+ "Sender company","Bedrijf afzender"
161
+ "Sender streetname","Straatnaam afzender"
162
+ "Sender streetnumber","Straatnummer afzender"
163
+ "Sender boxnumber","Busnummer afzender"
164
+ "Sender postal code","Postcode afzender"
165
+ "Sender city","Stad afzender"
166
+ "Sender country","Land afzender"
167
+ "Sender email","E-mail afzender"
168
+ "Sender phonenumber","Telefoonnummer afzender"
169
+ "Use Magento to manage labels","Verzendetiketten beheren in Magento"
170
+ "If you enable this option","Indien u deze optie activeert"
171
+ "Label format","Formaat verzendetiket"
172
+ "Automatic retour labels","Automatische retouretiketten"
173
+ "Automatic track and trace information","Automatische track & trace informatie"
174
+ "Display delivery date","Leveringsdatum tonen"
175
+ "Displays calculated delivery date","Toont de leveringsdatum berekend door het systeem obv parameters door u ingegeven"
176
+ "Days between order and shipment","Aantal dagen tussen order en verzending"
177
+ "Choose delivery date","Kies leveringsdatum"
178
+ "Number of delivery days shown","Aantal getoonde leveringsdagen"
179
+ "Next day delivery allowed till","Levering volgende dag mogelijk tot"
180
+ "Saturday delivery cost","Kost zaterdaglevering"
181
+ "Google browser API key","Google browser API key"
182
+ "Google server API key","Google server API key"
183
+ "bpost Home delivery","bpost thuislevering"
184
+ "General","Algemeen"
185
+ "Enabled","Geactiveerd"
186
+ "Rates","Rates"
187
+ "Free shipping","Gratis verzendingFree shipping"
188
+ ".. as of",".. vanaf"
189
+ "Rate type","Rate type"
190
+ "You can use flat rate or calculated table rates.","U kan een flat rate of table rates gebruiken."
191
+ "Flat rate price","Flat rate prijs"
192
+ "Importing and exporting table rates only possible on website scope. View the documentation for more information.","Table rates importeren en exporteren is enkel mogelijk op websiteniveau. Bekijk de documentatie voor meer info."
193
+ "Fixed fee for bpost Home delivery shipments","Vaste prijs voor bpost thuislevering"
194
+ "Table rates condition","Table rates condities"
195
+ "Export table rates file","Exporeer table rates bestand"
196
+ "Export your table rates configuration here.","Exporteer table rates configuratie."
197
+ "Import table rates file","Importeer table rates bestand"
198
+ "Upload your table rates configuration here. Refer to the manual for more information.","Upload table rates configuratie. Bekijk de handleiding voor meer info."
199
+ "Options","Opties"
200
+ "2nd presentation","2e aanbieding"
201
+ "The delivery happens against signature by the receiver. The parcel is delivered on Saturday if it is timely dropped in the bpost network.","Levering na handtekening van de ontvanger. Het pakje wordt geleverd op zaterdag indien het tijdig wordt afgegeven in het bpost netwerk."
202
+ "Insurance","Verzekering"
203
+ "Insurance to insure your goods to a maximum of 500","Verzeker uw goederen tot een maximum van 500 euro"
204
+ "Signature","Handtekening"
205
+ "The delivery happens against signature by the receiver.","Levering na handtekening van de ontvanger."
206
+ "Saturday delivery","Zaterdaglevering"
207
+ "The parcel is delivered on Saturday if it is timely dropped in the bpost network.","Het pakje wordt geleverd op zaterdag indien het tijd wordt afgegeven in het bpost netwerk."
208
+ "bpost Home delivery international","bpost internationale thuislevering"
209
+ "Product","Product"
210
+ "Import countries","Importeer landen"
211
+ "Allowed countries","Toegelaten landen"
212
+ "International insurance","Internationale verzekering"
213
+ "Import your bpost configured countries here.","Importeer landen geconfigureerd in bpost Shipping Manager."
214
+
215
+ "Your 6 digits bpost account ID used for the Shipping Manager.<br/><a target='_blank' href='http://bpost.freshdesk.com/solution/articles/4000061189'>http://bpost.freshdesk.com/solution/articles/4000061189</a>","Uw bpost Shipping Manager account ID bestaande uit 6 karakters.<br/><a target='_blank' href='http://bpost.freshdesk.com/solution/articles/4000061189'>http://bpost.freshdesk.com/solution/articles/4000061189</a>"
216
+ "You need a user account from bpost to use this module. Call %s for more information.","U heeft een bpost account nodig om deze module te gebruiken. Bel %s voor meer informatie."
217
+ "bpost uses Google Maps API to display the map in the frontend. <strong>
Note:</strong> This is optional if you will not meet the usage limits. Visit Google’s online documentation for more information.","bpost gebruikt de Google Maps API om de map in de frontend weer te geven. <strong>Opmerking:</strong> Dit is optioneel indien u de gebruikslimiet niet overschrijdt. Bekijk de online documentatie van Google voor meer informatie."
218
+ "bpost uses Google Geocoding API to calculate GEO location based on the shipping address. <strong>
Note:</strong> This is optional if you will not meet the usage limits. Visit Google’s online documentation for more information.","bpost gebruikt de Google Geocoding API om de geolocatie te berekenen op basis van het verzendadres. <strong>Opmerking:</strong> Dit is optioneel indien u de gebruikslimiet niet overschrijdt. Bekijk de online documentatie van Google voor meer informatie."
219
+ "Additional fee when using saturday delivery option, e.g.: 4.95.","Additionale kost voor zaterdaglevering, e.g.: 4.95."
220
+ "If the order is placed after this cut-off time, an extra day is added to the displayed date. Order placed = end of checkout.","Indien het order bevestigd wordt na deze cut-off tijd, heeft dit een impact op de weergegeven leveringsdag(en). Order geplaatst = einde checkout."
221
+ "Allow customer to choose their delivery date","Uw klant toelaten om de leveringsdatum te kiezen"
222
+ "If you enable this option, the bpost Track & Trace link will be added in the Magento mail templates. It is always possible to manually send these emails.<br/><a href='http://bpost.freshdesk.com/solution/articles/4000061636' target='_blank'>http://bpost.freshdesk.com/solution/articles/4000061636</a>","Indien u deze optie activeert,zal er automatisch een bpost Track & Trace link toegevoegd worden aan de Magento mailtemplates. Het is dan ook nog steeds mogelijk deze mails manueel te verzenden.<br/><a href='http://bpost.freshdesk.com/solution/articles/4000061636' target='_blank'>http://bpost.freshdesk.com/solution/articles/4000061636</a>"
223
+ "If you enable this option, a retour label is automatically added and printed when generating labels. If disabled, you are able to manually create retour labels.","If you enable this option, a retour label is automatically added and printed when generating labels. If disabled, you are able to manually create retour labels."
224
+ "Choose between A6 or A4 format","Kies tussen A6 of A4 formaat voor het afdrukken van uw verzendetiketten"
225
+ "If you enable this option, labels are generated directly within Magento. It is not needed to use the bpost Shipping Manager for these tasks.","Indien u deze optie activeert, worden verzendetiketten direct gegenereerd in Magento. Het is dan niet nodig om hiervoor de bpost Shipping Manager te gebruiken."
226
+
227
+ "Delivery at your doorstep or at your office? bpack@home is the most convenient option for you!","Levering bij u thuis of op kantoor? Dan is bpost thuislevering de handigste leveringsmethode voor u!"
228
+ "Allow free shipping","Gratis verzending toelaten"
229
+ "Choose your rate type (Flat rate or Table rate)","Kies uw rate type (Flat rate of Table rate)"
230
+ "Fixed fee for bpost Home delivery shipments, e.g.: 4.95.","Vaste prijs voor bpost thuislevering, ex: 4.95."
231
+ "This options provides automatically a second presentation at the receiver's address should he be absent upon first presentation.","Automatische tweede aanbieding op het adres van de ontvanger indien deze afwezig is bij de levering."
232
+ "Insurance to insure your goods to a maximum of 500,00 euro.","Verzekering voor uw goederen voor een maximumbedrag van 500 euro."
233
+ "The parcel is delivered on Saturday if it is timely dropped in the bpost network.","Het pakje wordt geleverd op zaterdag indien het tijd wordt afgegeven in het bpost netwerk."
234
+ "Delivery at your doorstep or at your office outside Belgium? bpack@international is the most convenient option for you!","Levering buiten België? Dan is bpack international de gepaste leveringsmethode!"
235
+ "Select which product to use for international shipments","Selecteer het te gebruiken product voor internationale zendingen"
236
+ "Fixed fee for bpost Home delivery international shipments, e.g.: 4.95.","Vaste prijs voor bpost internationale thuislevering, bv.: 4.95."
237
+ "Select one or more countries where bpost Home delivery international should be available for. Make sure your bpost shipping manager is configured properly. Otherwise no countries will be shown in this list after saving the 'Shipping Settings' configuration.","Selecteer de landen voor dewelke bpost thuislevering internationaal beschikbaar dient te zijn. Verifieer ook dat uw bpost shipping manager correct geconfigureerd is, zoniet zullen er geen landen getoond worden in deze lijst"
238
+ "Get your parcel delivered in one of our 1.250 pick-up points.","Laat uw pakje leveren in één van onze 1.250 afhaalpunten."
239
+ "The parcel is delivered on Saturday if it is timely dropped in the bpost network.","Levering na handtekening van de ontvanger. Het pakje wordt geleverd op zaterdag indien het tijdig wordt afgegeven in het bpost netwerk."
240
+ "Have your parcels delivered in one of our parcel lockers. Very convenient, centrally located, always open, 24/7!","Laat uw pakjes leveren in een pakjesautomaat. U vindt de automaten op handige plaatsen en ze zijn altijd open, 24/7!"
241
+ "Belgium","België"
242
+ "If you enable this option, a retour label is automatically added and printed when generating labels. If disabled, you are able to manually create retour labels.","Indien u deze optie activeert, wordt er automatisch een retouretiket gegenereerd en geprint bij het genereren van etiketten. Indien niet geactiveerd kan u nog steeds manueel retouretiketten genereren."
243
+ "If you enable this option, labels are generated directly within Magento. It is not needed to use the bpost Shipping Manager for these tasks. Pop-ups must be enabled in your browser, in order to view the printed labels. Click <a href='http://bpost.freshdesk.com/solution/articles/4000061188' target='_blank'>here</a> to learn more about this option.","Indien u deze optie activeert, worden verzendetiketten direct gegenereerd in Magento. Het is dan niet nodig om de bpost Shipping Manager hiervoor te gebruiken. Let erop dat pop-ups gedeactiveerd dienen te zijn in uw browser om de geprinte labels te zien. Klik <a href='http://bpost.freshdesk.com/solution/articles/4000061188' target='_blank'>hier</a> om meer te weten over deze optie."
244
+ "Used to calculate the weight before sending it to bpost","Gebruikt om het gewicht te berekenen voordat het naar bpost wordt gestuurd"
js/bpost/.DS_Store ADDED
Binary file
js/bpost/shm/adminhtml/informationpopup.js ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function openPopup(url, popupWidth, popupHeight) {
2
+ if ($('bpost_info_window') && typeof(Windows) != 'undefined') {
3
+ Windows.focus('bpost_info_window');
4
+ return;
5
+ }
6
+
7
+ Dialog.info(null, {
8
+ closable: true,
9
+ resizable: false,
10
+ draggable: false,
11
+ className: 'magento',
12
+ windowClassName: 'popup-window',
13
+ title: 'Bpost Shipping Manager',
14
+ width: popupWidth,
15
+ height: popupHeight,
16
+ zIndex: 1000,
17
+ recenterAuto: true,
18
+ hideEffect: Element.hide,
19
+ showEffect: Element.show,
20
+ id: 'bpost_info_window',
21
+ url: url
22
+ });
23
+ }
24
+
25
+ function generateAndComplete(massActionObjectName, gridObjectName) {
26
+ if ($('bpost_info_window') && typeof(Windows) != 'undefined') {
27
+ Windows.focus('bpost_info_window');
28
+ return;
29
+ }
30
+
31
+ massActionObjectName = window[massActionObjectName];
32
+ gridObjectName = window[gridObjectName];
33
+
34
+ var item = massActionObjectName.getSelectedItem();
35
+ var url = item.url;
36
+ var fieldName = (item.field ? item.field : massActionObjectName.formFieldName);
37
+
38
+ if (url == "undefined") {
39
+ return;
40
+ }
41
+
42
+ if(varienStringArray.count(massActionObjectName.checkedString) == 0) {
43
+ alert(massActionObjectName.errorText);
44
+ return;
45
+ }
46
+
47
+ massActionObjectName.formHiddens.update('');
48
+ new Insertion.Bottom(massActionObjectName.formHiddens, massActionObjectName.fieldTemplate.evaluate({name: fieldName, value: massActionObjectName.checkedString}));
49
+ new Insertion.Bottom(massActionObjectName.formHiddens, massActionObjectName.fieldTemplate.evaluate({name: 'massaction_prepare_key', value: fieldName}));
50
+
51
+ if(massActionObjectName.select.value != "generateAndComplete"){
52
+ //check for action
53
+ massActionObjectName.form.action = item.url;
54
+ massActionObjectName.form.submit();
55
+ }else{
56
+ if(!massActionObjectName.validator.validate()) {
57
+ return;
58
+ }
59
+
60
+ new Ajax.Request(url, {
61
+ 'method': 'post',
62
+ 'parameters': massActionObjectName.form.serialize(true),
63
+ onCreate: function(request) {
64
+ //Ajax.Responders.unregister(varienLoaderHandler.handler);
65
+ },
66
+ onSuccess: function(transport){
67
+ massActionObjectName.unselectAll();
68
+ gridObjectName.reload();
69
+
70
+ var responseArray = transport.responseText.evalJSON();
71
+ var messageHtml = "";
72
+
73
+ messageHtml = '<ul class="messages">';
74
+
75
+ if (typeof responseArray["messages"]["error"] !== 'undefined' && responseArray["messages"]["error"].length > 0) {
76
+ messageHtml += '<li class="error-msg">';
77
+ for (var i = 0; i < responseArray["messages"]["error"].length; i++) {
78
+ messageHtml += responseArray["messages"]["error"][i]+"<br/>";
79
+ }
80
+ messageHtml += '</li>';
81
+ }
82
+
83
+ if (typeof responseArray["messages"]["success"] !== 'undefined' && responseArray["messages"]["success"].length > 0) {
84
+ messageHtml += '<li class="success-msg">';
85
+ for (var i = 0; i < responseArray["messages"]["success"].length; i++) {
86
+ messageHtml += responseArray["messages"]["success"][i]+"<br/>";
87
+ }
88
+ messageHtml += '</li>';
89
+ }
90
+
91
+ if (typeof responseArray["messages"]["notice"] !== 'undefined' && responseArray["messages"]["notice"].length > 0) {
92
+ messageHtml += '<li class="notice-msg">';
93
+ for (var i = 0; i < responseArray["messages"]["notice"].length; i++) {
94
+ messageHtml += responseArray["messages"]["notice"][i]+"<br/>";
95
+ }
96
+ messageHtml += '</li>';
97
+ }
98
+
99
+ messageHtml += '</ul>';
100
+
101
+ //fist empty the messages box
102
+ $("messages").innerHTML = "";
103
+ //fill back again
104
+ $("messages").insert(messageHtml);
105
+ }
106
+ });
107
+ }
108
+ }
109
+
110
+
js/bpost/shm/checkout.js ADDED
@@ -0,0 +1,956 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ if (!window.Bpost) {
2
+ window.Bpost = {};
3
+ };
4
+
5
+ var initialized = false;
6
+ var activeOption = "";
7
+ var carrier = "bpostshm";
8
+
9
+ Bpost.ShM = Class.create({
10
+ initialize: function(settings, currentShippingMethod){
11
+ this.settings = settings;
12
+ this.container = $$('.sp-methods')[0];
13
+ this.markers = {};
14
+
15
+ this.selectPickupPointLinkClick = this.selectPickupPointLinkClick.bind(this);
16
+ this.resolveSettings = this.resolveSettings.bind(this);
17
+ this.openInline = this.openInline.bind(this);
18
+ this.showDates = this.showDates.bind(this);
19
+ this.deliveryDate = this.deliveryDate.bind(this);
20
+ this.drawMap = this.drawMap.bind(this);
21
+ this.showExtraInfo = this.showExtraInfo.bind(this);
22
+ this.insertAutocomplete = this.insertAutocomplete.bind(this);
23
+ this.pinMarkers = this.pinMarkers.bind(this);
24
+ this.clearMarkers = this.clearMarkers.bind(this);
25
+ this.filterMarkers = this.filterMarkers.bind(this);
26
+ this.reloadMarkers = this.reloadMarkers.bind(this);
27
+ this.selectSpot = this.selectSpot.bind(this);
28
+ this.clickSpot = this.clickSpot.bind(this);
29
+ this.closeInfobox = this.closeInfobox.bind(this);
30
+ this.bpostClose = this.bpostClose.bind(this);
31
+
32
+ this.imageOpenPostOffice = {
33
+ url: this.settings.base_url + 'skin/frontend/base/default/images/bpost/location_postoffice_default.png',
34
+ size: new google.maps.Size(24, 24),
35
+ origin: new google.maps.Point(0, 0),
36
+ anchor: new google.maps.Point(24, 36)
37
+ };
38
+ this.imageOpenPostPoint = {
39
+ url: this.settings.base_url + 'skin/frontend/base/default/images/bpost/location_postpoint_default.png',
40
+ size: new google.maps.Size(24, 24),
41
+ origin: new google.maps.Point(0, 0),
42
+ anchor: new google.maps.Point(24, 36)
43
+ };
44
+ this.imageOpenParcelLocker = {
45
+ url: this.settings.base_url + 'skin/frontend/base/default/images/bpost/location_parcellocker_default.png',
46
+ size: new google.maps.Size(24, 24),
47
+ origin: new google.maps.Point(0, 0),
48
+ anchor: new google.maps.Point(24, 36)
49
+ };
50
+ this.mapOptions = {
51
+ zoom: 13,
52
+ panControl: false,
53
+ zoomControl: true,
54
+ zoomControlOptions: {
55
+ style: google.maps.ZoomControlStyle.SMALL,
56
+ position: google.maps.ControlPosition.TOP_RIGHT
57
+ },
58
+ mapTypeControl: false,
59
+ scaleControl: false,
60
+ streetViewControl: false,
61
+ overviewMapControl: false,
62
+ center: new google.maps.LatLng(51, 4),
63
+ styles: [
64
+ {"featureType": "all", "elementType": "all", "stylers": [
65
+ {"saturation": -93},
66
+ {"lightness": 8}
67
+ ]},
68
+ {featureType: "poi", stylers: [
69
+ {visibility: "off"}
70
+ ]}
71
+ ]
72
+ };
73
+ this.infoboxOptions = {
74
+ content: document.createElement("div"),
75
+ disableAutoPan: false,
76
+ maxWidth: 0,
77
+ pixelOffset: new google.maps.Size(0, -10),
78
+ zIndex: null,
79
+ boxStyle: {
80
+ width: "235px"
81
+ },
82
+ closeBoxURL: "",
83
+ infoBoxClearance: new google.maps.Size(20, 20),
84
+ isHidden: false,
85
+ pane: "floatPane",
86
+ enableEventPropagation: true
87
+ };
88
+ this.shape = {
89
+ coord: [1, 1, 1, 45, 45, 45, 45, 1],
90
+ type: 'poly'
91
+ };
92
+
93
+ if (typeof $(document).eventsBinded == "undefined" && initialized == false) {
94
+ this.bindEvents();
95
+ }
96
+
97
+ //init map if bpost carrier is selected
98
+ if(currentShippingMethod == carrier+"_bpost_parcellocker" || currentShippingMethod == carrier+"_bpost_pickuppoint"){
99
+ this.container.down('label[for="s_method_'+currentShippingMethod+'"]').insert({'after': $("bpostShm")});
100
+ activeOption = "s_method_"+currentShippingMethod;
101
+ $('selectPickupPoint').style.display = 'inline';
102
+ }
103
+
104
+ //init datepicker if bpost carrier is selected
105
+ if(currentShippingMethod == carrier+"_bpost_homedelivery") {
106
+ if(this.settings.datepicker_display) {
107
+ this.container.down('label[for="s_method_' + currentShippingMethod + '"]').insert({'after': $("bpostDelivery")});
108
+ $("bpostDelivery").style.display = 'block';
109
+
110
+ var currMethod = currentShippingMethod.replace(carrier+'_', '');
111
+ this.placeDates(this.settings.datepicker_days, currMethod);
112
+ }
113
+ }
114
+
115
+ //set initial selected spot to false
116
+ this.selectedspot = false;
117
+
118
+ initialized = true;
119
+ },
120
+ bindEvents: function () {
121
+ //click to open map
122
+ $(document).on('click', "#selectPickupPoint", function (event) {
123
+ event.preventDefault();
124
+ this.selectPickupPointLinkClick();
125
+ }.bind(this));
126
+
127
+ //click on the little icon to see more information
128
+ $(document).on('click', ".infobtn", function (event) {
129
+ event.preventDefault();
130
+ this.showExtraInfo();
131
+ }.bind(this));
132
+
133
+ $(document).on('click', ".info", function (event) {
134
+ event.preventDefault();
135
+ this.showExtraInfo();
136
+ }.bind(this));
137
+
138
+ //click on spot in list
139
+ $(document).on('click', '.shoplistitem', function (event) {
140
+ if (!event.target.hasClassName("selectspot")) {
141
+ this.clickSpot((event.target.up('.shoplistitem') || event.target).id);
142
+ }
143
+ }.bind(this));
144
+
145
+ //click on the filter submit
146
+ $(document).on('click', "#filter_submit", function (event) {
147
+ event.preventDefault();
148
+ this.filterMarkers();
149
+ }.bind(this));
150
+
151
+ $(document).on('keypress', ".bpostfilter", function (event) {
152
+ if (event.keyCode == Event.KEY_RETURN || event.which == Event.KEY_RETURN) {
153
+ this.filterMarkers();
154
+ Event.stop(event);
155
+ }
156
+ }.bind(this));
157
+
158
+ $(document).on('click', '.selectspot', function (event) {
159
+ this.selectSpot(this.markers[Event.element(event).readAttribute("data-shopid")].json);
160
+ event.preventDefault();
161
+
162
+ if(this.settings.onestepcheckout_active == true){
163
+ $("bpost-info-wrapper").removeClassName("active");
164
+ this.googleMapsPopup.close();
165
+ }
166
+ }.bind(this));
167
+
168
+ $(document).on('click', '.close-infoBox', function (event) {
169
+ this.closeInfobox();
170
+ event.preventDefault();
171
+ }.bind(this));
172
+
173
+ $(document).on('click', '.bpost-close', function (event) {
174
+ this.bpostClose();
175
+ event.preventDefault();
176
+ }.bind(this));
177
+
178
+ $(document).on('change', 'input[type=radio][name=shipping_method]', function (event) {
179
+ //move map to correct shipping method
180
+ var target = event.target;
181
+ this.rePosition(target);
182
+ //show delivery date option
183
+ this.deliveryDate(target);
184
+
185
+ //reset saturday selection
186
+ $('bpost-saturday').checked = false;
187
+
188
+ //remove error messages when switching
189
+ this.removeErrors();
190
+
191
+ event.preventDefault();
192
+ }.bind(this));
193
+
194
+
195
+ $(document).on('click', '#bpost-saturday', function () {
196
+ var currMethod = $$('input:checked[type="radio"][name="shipping_method"]').pluck('value');
197
+ currMethod = currMethod[0].replace('bpostshm_', '');
198
+
199
+ this.placeDates(this.settings.datepicker_days, currMethod);
200
+
201
+ }.bind(this));
202
+
203
+ //remove map if view gets too small
204
+ Event.observe(((document.onresize) ? document : window), "resize", function() {
205
+ if($('bpostShm') !== null && $('bpostShm') !== undefined && ($('bpost-info-wrapper') === undefined || $('bpost-info-wrapper') === null)) {
206
+ var dimensions = $('bpostShm').getDimensions();
207
+ if ($('map-canvas') !== null && $('map-canvas') !== undefined) {
208
+ var mapDimensions = $('map-canvas').getDimensions();
209
+
210
+ if(mapDimensions != null && mapDimensions.width != dimensions.width) {
211
+
212
+ var mapwidth = dimensions.width + 'px';
213
+ var inlinemapwidth = dimensions.width - 220 + 'px';
214
+
215
+ $('mapcontainer').setStyle({
216
+ width: mapwidth
217
+ });
218
+
219
+ $('map-canvas').setStyle({
220
+ width: inlinemapwidth
221
+ });
222
+ }
223
+ }
224
+ }
225
+ });
226
+ },
227
+ bpostClose: function () {
228
+ this.clearMarkers();
229
+
230
+ if(this.settings.onestepcheckout_active == true){
231
+ $("bpost-info-wrapper").removeClassName("active");
232
+ this.googleMapsPopup.close();
233
+ }
234
+
235
+ $("bpostinfo").update("").setStyle({
236
+ width: 'auto',
237
+ height: 'auto'
238
+ });
239
+
240
+ if($('selectPickupPoint')) {
241
+ $('selectPickupPoint').style.display = 'inline';
242
+ }
243
+
244
+ if (this.selectedspot === false) {
245
+ $("bpostresult").style.display = "none";
246
+ } else {
247
+ $("bpostresult").style.display = "block";
248
+ }
249
+
250
+ this.map = null;
251
+ },
252
+ rePosition: function (target){
253
+ activeOption = target.id;
254
+
255
+ if(activeOption == "s_method_"+carrier+"_bpost_parcellocker" || activeOption == "s_method_"+carrier+"_bpost_pickuppoint"){
256
+ //hide notifications window
257
+ $("notifications-pick-up-point").style.display = "none";
258
+ $("notifications-parcel-locker").style.display = "none";
259
+
260
+ //first we close the map
261
+ this.bpostClose();
262
+
263
+ $(target).up().insert({'after': $("bpostShm")});
264
+ $("bpostShm").insert({'after': $("bpostDelivery")});
265
+
266
+ var selectPickupPointElement = document.getElementById("selectPickupPoint");
267
+
268
+ if(activeOption == "s_method_"+carrier+"_bpost_parcellocker"){
269
+ selectPickupPointElement.innerHTML = this.settings.select_text_parcel_locker;
270
+ //we set point type to 4
271
+ selectPickupPointElement.setAttribute("type", "4");
272
+ }else{
273
+ selectPickupPointElement.innerHTML = this.settings.select_text;
274
+ //we set point type to 3
275
+ selectPickupPointElement.setAttribute("type", "3");
276
+ }
277
+
278
+ $("bpostresult").setStyle({
279
+ display: 'none'
280
+ });
281
+
282
+ // reset the selected spot
283
+ $("bpost-id").value = "";
284
+ this.selectedspot = false;
285
+
286
+ $("bpostShm").show();
287
+ }else{
288
+ if($("bpostShm")){
289
+ $("bpostShm").hide();
290
+ }
291
+ }
292
+ },
293
+ showDates: function (target) {
294
+ if(target.id == 's_method_'+carrier+'_bpost_homedelivery') {
295
+ $(target).up().insert({'after': $("bpostDelivery")});
296
+ $("bpostDelivery").style.display = 'block';
297
+ } else if(target.id == 's_method_'+carrier+'_bpost_parcellocker' || target.id == 's_method_'+carrier+'_bpost_pickuppoint') {
298
+ if(this.selectedspot !== false) {
299
+ $(target).up().insert({'after': $("bpostDelivery")});
300
+ $("bpostDelivery").style.display = 'block';
301
+ }
302
+ } else {
303
+ if(this.selectedspot !== false) {
304
+ $("bpostShm").insert({'after': $("bpostDelivery")});
305
+ $("bpostDelivery").style.display = 'block';
306
+ }
307
+ }
308
+ },
309
+ placeDates: function (dates, currMethod) {
310
+ $$('.bpost-saturday-delivery')[0].style.display = 'none';
311
+
312
+ if(this.settings.datepicker_display && this.settings.datepicker_choose) {
313
+ $$('input[name="bpost[deliverydate]"]')[0].remove();
314
+
315
+ var pickDates = '<ul>';
316
+ var datepickArray = dates;
317
+ var dates = datepickArray[currMethod];
318
+ var addClass = '';
319
+
320
+ for (var i = 0; i < dates.length; i++) {
321
+ pickDates += '<li><label for="bpost-datepicker-'+i+'"><input type="radio" name="bpost[deliverydate]" id="bpost-datepicker-'+i+'" value="'+dates[i]['date']+'" /> '+dates[i]['date_format']+'</label></li>';
322
+ }
323
+ //add hidden input for validation message position
324
+ pickDates += '<li><input type="radio" name="bpost[deliverydate]" class="validate-multiple-delivery-dates" id="bpost-datepicker-advice" style="display: none;" /></li>';
325
+ pickDates += '</ul>';
326
+
327
+ var chooseDate = $$('.bpost-choose-deliverydate')[0];
328
+ chooseDate.innerHTML = pickDates;
329
+ chooseDate.style.display = 'block';
330
+
331
+ } else if(this.settings.datepicker_display && !this.settings.datepicker_choose) {
332
+ var displayDate = $$('.bpost-display-deliverydate')[0];
333
+ var datepickArray = dates;
334
+
335
+ displayDate.innerHTML = datepickArray[currMethod]['date_format'];
336
+ displayDate.style.display = 'block';
337
+
338
+ //var inputElement = '<input type="hidden" name="bpost[deliverydate]" vale="'+datepickArray[currMethod]['date']+'"/>';
339
+ $$('input[name="bpost[deliverydate]"]')[0].value = datepickArray[currMethod]['date'];
340
+
341
+ if($('bpost-saturday-hidden') != undefined) {
342
+ $('bpost-saturday-hidden').remove();
343
+ }
344
+
345
+ //saturday delivery option
346
+ if(datepickArray[currMethod]['is_saturday']) {
347
+ $$('.bpost-saturday-delivery')[0].style.display = 'block';
348
+
349
+ if($('bpost-saturday').checked) {
350
+ displayDate.innerHTML = datepickArray[currMethod]['next_date_format'];
351
+ displayDate.style.display = 'block';
352
+ $$('input[name="bpost[deliverydate]"]')[0].value = datepickArray[currMethod]['next_date'];
353
+ } else {
354
+ //create hidden input if not checked but a saturday
355
+ $('bpost-saturday').insert({before: '<input type="hidden" name="bpost_saturday_delivery" id="bpost-saturday-hidden" value="" />'})
356
+ }
357
+ }
358
+ }
359
+ },
360
+ deliveryDate: function (target) {
361
+ $("bpostDelivery").hide();
362
+
363
+ if(this.settings.datepicker_display) {
364
+ var currMethod = activeOption.replace('s_method_'+carrier+'_', '');
365
+
366
+ if(currMethod == 'bpost_homedelivery' || currMethod == 'bpost_pickuppoint' || currMethod == 'bpost_parcellocker') {
367
+ this.showDates(target);
368
+ this.placeDates(this.settings.datepicker_days, currMethod);
369
+ }
370
+ }
371
+ },
372
+ selectPickupPointLinkClick: function () {
373
+ //hide button & current selected spot
374
+ $("selectPickupPoint").style.display = "none";
375
+
376
+ //start resolving setings
377
+ this.resolveSettings();
378
+
379
+ //open the bpost map inline
380
+ this.openInline();
381
+
382
+ //hide notifications window
383
+ $("notifications-pick-up-point").style.display = "none";
384
+ $("notifications-parcel-locker").style.display = "none";
385
+
386
+
387
+ //place loader and show it
388
+ $('map-canvas').update(this.html_loading);
389
+
390
+ var parameters = {};
391
+ parameters["pointType"] = $("selectPickupPoint").getAttribute("type");
392
+ this.triggerWindowAjaxRequest(parameters);
393
+ },
394
+ generateDeliveryDates: function (id, type) {
395
+ var parameters = {};
396
+ parameters['id'] = id;
397
+ parameters['type'] = type;
398
+
399
+ new Ajax.Request(this.settings.base_url + 'bpost/ajax/getdates', {
400
+ method: 'post',
401
+ parameters: parameters,
402
+ requestHeaders: {Accept: 'application/json'},
403
+ onSuccess: function (transport) {
404
+ var json = transport.responseText.evalJSON(true);
405
+ if (json.error.length == 0) {
406
+ //this method only applies to the pick-up points (nothing else can be closed on saturday)
407
+ var currMethod = 'bpost_pickuppoint';
408
+ this.placeDates(json.dates, currMethod);
409
+
410
+ } else {
411
+ alert(json.error);
412
+ }
413
+ }.bind(this),
414
+ onFailure: function () {
415
+ alert("Could not contact the server, please try again");
416
+ this.bpostClose();
417
+ }
418
+ });
419
+
420
+ return '';
421
+ },
422
+ triggerWindowAjaxRequest: function(parameters){
423
+ //AJAX!
424
+ // type:
425
+ // Type 1 = Post Office
426
+ // Type 2 = Post Point
427
+ // Type 4 = bpack 24/7
428
+ // for example type 3 = type1 & type2
429
+ new Ajax.Request(this.settings.base_url + 'bpost/ajax/getwindow', {
430
+ method: 'get',
431
+ parameters: parameters,
432
+ requestHeaders: {Accept: 'application/json'},
433
+ onSuccess: function (transport) {
434
+ this.json = transport.responseText.evalJSON(true);
435
+
436
+ if (this.json.error.length == 0) {
437
+ this.drawMap();
438
+ this.pinMarkers();
439
+ if(typeof this.json.poilist.Poi != 'undefined' && this.json.poilist.Poi.length > 0) {
440
+ this.panToLocation(this.json.poilist.Poi[0].Record.Latitude, this.json.poilist.Poi[0].Record.Longitude);
441
+ } else {
442
+ this.panToLocation();
443
+ }
444
+ this.reloadMarkers();
445
+ } else {
446
+ alert(this.json.error);
447
+ this.bpostClose();
448
+ }
449
+ }.bind(this),
450
+ onFailure: function () {
451
+ alert("Could not contact the server, please try again");
452
+ this.topClose();
453
+ },
454
+ onComplete: function () {
455
+ $("bpost_loading").style.display = "none";
456
+ }.bind(this)
457
+ });
458
+ },
459
+ panToLocation: function (latitude, longitude) {
460
+ if(latitude && longitude) {
461
+ var latLng = new google.maps.LatLng(latitude, longitude);
462
+ } else {
463
+ var latLng = new google.maps.LatLng(this.json.coordinates.lat, this.json.coordinates.lng);
464
+ }
465
+ this.map.panTo(latLng);
466
+ },
467
+ selectSpot: function (json) {
468
+ //spot selected
469
+ var image;
470
+
471
+ //fill form
472
+ $$('input[name^=bpost[id]]').first().value = json.Id;
473
+ $$('input[name^=bpost[street]]').first().value = json.Street + " " + json.Number;
474
+ $$('input[name^=bpost[city]]').first().value = json.City;
475
+ $$('input[name^=bpost[postcode]]').first().value = json.Zip;
476
+ $$('input[name^=bpost[name]]').first().value = json.Name;
477
+ this.selectedspot = json.Id;
478
+
479
+ // create notification html
480
+ if(activeOption == "s_method_"+carrier+"_bpost_pickuppoint"){
481
+ $("notifications-pick-up-point").style.display = "block";
482
+ $("pickup-point-notification-email").checked = true;
483
+ $("pickup-point-notification-sms").checked = false;
484
+
485
+ //create the infobox html
486
+ var bpostresult = '<p><a href="#" class="info"><b>' + json.Name + '</b></a><a href="#" class="infobtn">?</a>' +
487
+ '<br />' + json.Street + ' ' + json.Number + '<br />' + json.Zip + ' ' + json.City + '</p>' +
488
+ '<ul class="infobtnvw" id="bpost-opening-hours-selected"></ul>';
489
+
490
+ //get delivery hours based on spot's opening hour
491
+ this.generateDeliveryDates(json.Id, json.Type);
492
+ }else{
493
+ $("notifications-parcel-locker").style.display = "block";
494
+ $("notification-sms").checked = false;
495
+
496
+ //create the infobox html
497
+ var bpostresult = '<p><b class="no-info-btn">' + json.Name + '</b>' +
498
+ '<br />' + json.Street + ' ' + json.Number + '<br />' + json.Zip + ' ' + json.City + '</p>';
499
+ }
500
+
501
+ // generate opening hours
502
+ this.generateHours(json.Id, json.Type, false, false);
503
+
504
+ $("bpostresult").update(bpostresult)
505
+ .setStyle({
506
+ display: 'block'
507
+ });
508
+
509
+ //if this is not true , it means that there was already a spot suggested.
510
+ if (this.json) {
511
+ if(activeOption == "s_method_"+carrier+"_bpost_pickuppoint"){
512
+ //change link text
513
+ $("selectPickupPoint").setAttribute("type", 3)
514
+ $("selectPickupPoint").update(this.settings.change_text);
515
+
516
+ }else{
517
+ //change link text
518
+ $("selectPickupPoint").setAttribute("type", 4)
519
+ $("selectPickupPoint").update(this.settings.change_text_parcel_locker);
520
+ }
521
+ //add delivery date option
522
+ this.deliveryDate(false);
523
+
524
+ //close everything
525
+ this.bpostClose();
526
+
527
+ //remove error advice if it exists
528
+ this.removeErrors();
529
+ }
530
+
531
+ //reset
532
+ this.active_info = null;
533
+ },
534
+ removeErrors: function () {
535
+ if($('advice-validate-bpostspot-bpost-id') != undefined) {
536
+ $('advice-validate-bpostspot-bpost-id').remove();
537
+ }
538
+ if($('advice-validate-parcel-bpost-id') != undefined) {
539
+ $('advice-validate-parcel-bpost-id').remove();
540
+ }
541
+ if($('advice-required-entry-bpost[deliverydate]') != undefined) {
542
+ $('advice-required-entry-bpost[deliverydate]').remove();
543
+ }
544
+ },
545
+ resolveSettings: function () {
546
+ //set dimensions
547
+ var dimensions = $('bpostShm').getDimensions();
548
+
549
+ this.dimensions = dimensions;
550
+ this.mapwidth = dimensions.width + 'px';
551
+ this.mapheight = 'auto';
552
+ this.inlinemapwidth = dimensions.width - 220 + 'px';
553
+
554
+ this.filterLoading = false;
555
+
556
+ //add html
557
+ this.html_filter = '<div class="filter"><form action="' + this.settings.base_url + 'bpost/ajax/filterspots" method="post" id="bpostspotsfilterform">' +
558
+ '<div class="bpost-input-box">' +
559
+ '<div class="input"><input type="text" id="bpost-gmaps-filter" class="bpostfilter input-text" name="bpost-gmaps-filter" placeholder="' + this.settings.label_postcode + '"/></div>' +
560
+ '<div class="action"><input type="submit" class="btn-bpost" value="' + this.settings.label_filter + '" id="filter_submit" /></div>' +
561
+ '</div>' +
562
+ '</form></div>';
563
+ this.html_clear = '<div style="clear:both;"></div>';
564
+ this.html_close = '<div class="bpost-close-wrapper"><a class="bpost-close btn-bpost">Close</a></div>';
565
+ this.html_list = '<ul class="list" id="bpostlist"></ul>';
566
+ this.html_map = '<div id="map-canvas" class="map"></div>';
567
+ this.html_loading = '<div class="bpost_loading"><span class="ajaxloading"></span><div class="image"></div><span class="bpost-please-wait">' + this.settings.label_loading + '</span></div>';
568
+
569
+ this.iecompat = Prototype.Browser.IE6 || Prototype.Browser.IE7 || Prototype.Browser.IE8 || Prototype.Browser.IE9;
570
+ },
571
+ openInline: function () {
572
+ var mapcontainer = new Element('div', { 'id': 'mapcontainer', 'class': 'mapcontainer inline', style: 'width:'+this.mapwidth+';height:'+this.mapheight+';clear:both;' })
573
+ .insert(this.html_filter)
574
+ .insert(this.html_list)
575
+ .insert(this.html_map)
576
+ .insert(this.html_clear);
577
+
578
+ $$('.bpostspotswrapper').first().addClassName('inline');
579
+
580
+ $("bpostinfo").update(mapcontainer.insert(this.html_close))
581
+ .down(".filter", 0)
582
+ .addClassName("response");
583
+
584
+ //hide the link and result
585
+ $("selectPickupPoint").setStyle({
586
+ display: 'none'
587
+ });
588
+
589
+ $("bpostresult").setStyle({
590
+ display: 'none'
591
+ });
592
+
593
+ if (this.iecompat) {
594
+ $('bpost-gmaps-filter').value = this.settings.label_postcode;
595
+ }
596
+
597
+ this.insertAutocomplete();
598
+ },
599
+ drawMap: function () {
600
+ $('bpostlist').setStyle({
601
+ width: '220px'
602
+ })
603
+
604
+ $('map-canvas').setStyle({
605
+ width: this.inlinemapwidth
606
+ })
607
+
608
+ this.map = null; //reset
609
+ this.map = new google.maps.Map($('map-canvas'), this.mapOptions);
610
+ },
611
+ insertAutocomplete: function () {
612
+ var inputEl = $('bpost-gmaps-filter');
613
+
614
+ new google.maps.places.Autocomplete(inputEl);
615
+ },
616
+ generateHours: function (id, type, map, spots) {
617
+ var parameters = {};
618
+ parameters['id'] = id;
619
+ parameters['type'] = type;
620
+ parameters['spots'] = spots;
621
+
622
+ new Ajax.Request(this.settings.base_url + 'bpost/ajax/gethours', {
623
+ method: 'post',
624
+ parameters: parameters,
625
+ requestHeaders: {Accept: 'application/json'},
626
+ onSuccess: function (transport) {
627
+ var json = transport.responseText.evalJSON(true);
628
+
629
+ //if only a single point is queried
630
+ if(json.hours) {
631
+ if (json.error.length == 0) {
632
+ var openingHours = this.formatOpeningHours(json);
633
+
634
+ if(map) {
635
+ var currentInfobox = this.infowindows[id];
636
+ var currentInfoboxContent = currentInfobox.getContent()
637
+ var newContent = currentInfoboxContent.replace('<ul class="hours"></ul>', '<ul class="hours">'+openingHours+'</ul>');
638
+ currentInfobox.setContent(newContent);
639
+ } else {
640
+ //add openinghours to '?' information button
641
+ $('bpost-opening-hours-selected').update(openingHours);
642
+ }
643
+ } else {
644
+ alert(json.error);
645
+ }
646
+ } else { //multiple points queried at once
647
+ for (var key in json) {
648
+ var openingHours = this.formatOpeningHours(json[key]);
649
+
650
+ //multiple points only get added to the map
651
+ if(map) {
652
+ var currentInfobox = this.infowindows[key];
653
+ var currentInfoboxContent = currentInfobox.getContent()
654
+ var newContent = currentInfoboxContent.replace('<ul class="hours"></ul>', '<ul class="hours">'+openingHours+'</ul>');
655
+ currentInfobox.setContent(newContent);
656
+ }
657
+ }
658
+ }
659
+ }.bind(this),
660
+ onFailure: function () {
661
+ alert("Could not contact the server, please try again");
662
+ this.bpostClose();
663
+ }
664
+ });
665
+
666
+ return '';
667
+ },
668
+ formatOpeningHours: function (json) {
669
+ var days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
670
+ var daysLength = days.length;
671
+ var currentDay = '';
672
+ var openingHours = '';
673
+
674
+ for (var i = 0; i < daysLength; i++) {
675
+ currentDay = days[i].toLowerCase();
676
+
677
+ openingHours = openingHours + "<li><span class='day'>" + this.settings[currentDay] + "</span>";
678
+ //if no opening hours are given for a specific day we'll assume the point is closed
679
+ if(typeof json.hours[days[i]].AMOpen === 'object' &&
680
+ typeof json.hours[days[i]].AMClose === 'object' &&
681
+ typeof json.hours[days[i]].PMOpen === 'object' &&
682
+ typeof json.hours[days[i]].PMClose === 'object') {
683
+ openingHours = openingHours + this.settings.closed;
684
+ } else {
685
+ //morning hours
686
+ openingHours = openingHours + "<span class='large'>";
687
+ //if no morning opening hour given assume closed
688
+ if(typeof json.hours[days[i]].AMOpen !== 'object') {
689
+ //if a morning closing hour is given we assume they have a break at noon else just show the opening hour
690
+ if(typeof json.hours[days[i]].AMClose !== 'object') {
691
+ openingHours = openingHours + json.hours[days[i]].AMOpen + ' - ' + json.hours[days[i]].AMClose;
692
+ } else {
693
+ openingHours = openingHours + json.hours[days[i]].AMOpen;
694
+ }
695
+ } else {
696
+ openingHours = openingHours + this.settings.closed;
697
+ }
698
+ openingHours = openingHours + "</span>";
699
+
700
+ //breaktime
701
+ if(typeof json.hours[days[i]].AMOpen === 'object' && typeof json.hours[days[i]].AMClose === 'object' && (typeof json.hours[days[i]].PMOpen !== 'object' || typeof json.hours[days[i]].PMClose !== 'object')) {
702
+ openingHours = openingHours + "<span class='small'>/</span>";
703
+ } else if(typeof json.hours[days[i]].AMOpen !== 'object' && typeof json.hours[days[i]].AMClose !== 'object' && (typeof json.hours[days[i]].PMClose === 'object' || typeof json.hours[days[i]].PMClose !== 'object')) {
704
+ openingHours = openingHours + "<span class='small'>/</span>";
705
+ }
706
+
707
+ //afternoon
708
+ openingHours = openingHours + "<span class='large'>";
709
+ //if no morning opening hour given assume closed
710
+ if(typeof json.hours[days[i]].PMClose !== 'object') {
711
+ //if a morning closing hour is given we assume they have a break at noon else just show the opening hour
712
+ if(typeof json.hours[days[i]].PMOpen !== 'object') {
713
+ openingHours = openingHours + json.hours[days[i]].PMOpen + ' - ' + json.hours[days[i]].PMClose;
714
+ } else {
715
+ openingHours = openingHours + '&nbsp;- ' + json.hours[days[i]].PMClose;
716
+ }
717
+ } else {
718
+ openingHours = openingHours + this.settings.closed;
719
+ }
720
+ openingHours = openingHours + "</span>";
721
+ }
722
+ openingHours = openingHours + "</span></li>";
723
+ }
724
+
725
+ return openingHours;
726
+ },
727
+ pinMarkers: function () {
728
+ this.infowindows = {};
729
+ this.markers = {};
730
+
731
+ //loop trough shops
732
+ if(typeof this.json.poilist.Poi !== 'undefined') {
733
+ var spots = [];
734
+
735
+ //we check for array
736
+ //if we have just one element, we force this element as array
737
+ if( Object.prototype.toString.call(this.json.poilist.Poi) !== '[object Array]' ) {
738
+ this.json.poilist.Poi = [this.json.poilist.Poi];
739
+ }
740
+
741
+ for (var i = 0, poiList = this.json.poilist.Poi.length; i < poiList; i++) {
742
+ //google maps infobox
743
+ this.infowindows[this.json.poilist.Poi[i].Record.Id] = new InfoBox(this.infoboxOptions);
744
+ this.infowindows[this.json.poilist.Poi[i].Record.Id].setContent('<div class="infobox-arrow"></div><a href="#" class="close close-infoBox"></a>' +
745
+ '<h3>' + this.json.poilist.Poi[i].Record.Name + '</h3>' +
746
+ '<p>' + this.json.poilist.Poi[i].Record.Street + ' ' + this.json.poilist.Poi[i].Record.Number +
747
+ '<br />' + this.json.poilist.Poi[i].Record.Zip + ' ' + this.json.poilist.Poi[i].Record.City +
748
+ '</p><ul class="hours"></ul>' +
749
+ '<a href="#" data-shopid="' + this.json.poilist.Poi[i].Record.Id + '" class="selectspot">Select &raquo;</a>');
750
+
751
+ //add opening hours
752
+ spots.push({
753
+ id: this.json.poilist.Poi[i].Record.Id,
754
+ type: this.json.poilist.Poi[i].Record.Type
755
+ });
756
+
757
+ //set icons depending on spot type
758
+ var mapIcon = {
759
+ 1 : this.imageOpenPostOffice,
760
+ 2 : this.imageOpenPostPoint,
761
+ 3 : this.imageOpenPostOffice, //bpost should never return 3
762
+ 4 : this.imageOpenParcelLocker
763
+ }
764
+
765
+ //google maps marker
766
+ this.markers[this.json.poilist.Poi[i].Record.Id] = new google.maps.Marker({
767
+ position: new google.maps.LatLng(this.json.poilist.Poi[i].Record.Latitude, this.json.poilist.Poi[i].Record.Longitude),
768
+ map: this.map,
769
+ icon: mapIcon[this.json.poilist.Poi[i].Record.Type],
770
+ shape: this.shape,
771
+ zIndex: 1,
772
+ json: this.json.poilist.Poi[i].Record
773
+ });
774
+
775
+ google.maps.event.addListener(this.markers[this.json.poilist.Poi[i].Record.Id], 'click', (function (marker) {
776
+ return function () {
777
+ this.clickSpot(marker.json.Id);
778
+ }.bind(this)
779
+ }.bind(this))(this.markers[this.json.poilist.Poi[i].Record.Id]));
780
+
781
+ //insert points in list
782
+ $$('ul.list').first().insert("<li class='shoplistitem' id='" + this.json.poilist.Poi[i].Record.Id + "'>" + "<span class='title'>" + this.json.poilist.Poi[i].Record.Name + "</span>" + "<span class='address'>" + this.json.poilist.Poi[i].Record.Street + " " + this.json.poilist.Poi[i].Record.Number + "</span>" + "<span class='city'>" + this.json.poilist.Poi[i].Record.Zip + " " + this.json.poilist.Poi[i].Record.City + "</span><a href='#' data-shopid='" + this.json.poilist.Poi[i].Record.Id + "' class='selectspot' >" + this.settings.label_select + " &raquo;</a></li>");
783
+ }
784
+ var pointType = $("selectPickupPoint").getAttribute("type");
785
+ if(spots.length > 0 && pointType == 3) {
786
+ spots = JSON.stringify(spots);
787
+ this.generateHours(false, false, true, spots);
788
+ }
789
+ } else {
790
+ //add error to list
791
+ $$('ul.list').first().insert("<li class='shoplistitem bpost-spots-error' id='bpost-spots-error'><span class='error'>" + this.settings.no_points_found + "</span></li>");
792
+ }
793
+ },
794
+ closeInfobox: function () {
795
+ if (this.active_info != null && this.infowindows[this.active_info])
796
+ this.infowindows[this.active_info].close();
797
+
798
+ this.active_info = null;
799
+ },
800
+ showExtraInfo: function () {
801
+ if ($$(".infobtnvw").first().style.visibility == "visible") {
802
+ $$(".infobtnvw").first().style.visibility = "hidden";
803
+ } else {
804
+ $$(".infobtnvw").first().setStyle({
805
+ left: ($$(".infobtn").first().offsetLeft + $$(".infobtn").first().getDimensions().width) + "px",
806
+ visibility: "visible"
807
+ });
808
+ }
809
+ },
810
+ clearMarkers: function () {
811
+ //Remove boundaries error from spotlist
812
+ if ($('bpost-spots-error') != undefined) {
813
+ $('bpost-spots-error').remove();
814
+ }
815
+
816
+ for (var key in this.markers) {
817
+ //remove marker from map
818
+ this.markers[key].setMap(null);
819
+ //remove infowindow
820
+ this.infowindows[key].close();
821
+ //remove item from list
822
+ if (key != null && typeof key != "undefined" && $(key) != undefined) {
823
+ $(key).remove();
824
+ }
825
+ }
826
+ this.markers = {};
827
+ this.active_info = null;
828
+ this.infowindows = {};
829
+ },
830
+ reloadMarkers: function () {
831
+ google.maps.event.addListener(this.map, 'dragend', function () {
832
+ //load new points based on latitude and longitude values
833
+ if (this.filterLoading != true) {
834
+ this.filterLoading = true;
835
+
836
+ var mapCenter = this.map.getCenter();
837
+ var parameters = {};
838
+ parameters['lat'] = mapCenter.lat();
839
+ parameters['lng'] = mapCenter.lng();
840
+ parameters["pointType"] = $("selectPickupPoint").getAttribute("type");
841
+
842
+ new Ajax.Request(this.settings.base_url + 'bpost/ajax/getwindow', {
843
+ method: 'post',
844
+ parameters: parameters,
845
+ requestHeaders: {Accept: 'application/json'},
846
+ onSuccess: function (transport) {
847
+ var json = transport.responseText.evalJSON(true);
848
+
849
+ if (json.error.length == 0) {
850
+ this.clearMarkers();
851
+ this.json = json;
852
+ this.pinMarkers();
853
+ } else {
854
+ alert(json.error);
855
+ this.bpostClose();
856
+ }
857
+ }.bind(this),
858
+ onFailure: function () {
859
+ alert("Could not contact the server, please try again");
860
+ this.bpostClose();
861
+ },
862
+ onComplete: function () {
863
+ //reset the click
864
+ this.filterLoading = false;
865
+ }.bind(this)
866
+ });
867
+ }
868
+ }.bind(this));
869
+ },
870
+ clickSpot: function (spotid) {
871
+ //move map to center of this marker
872
+ if(this.markers[spotid] !== undefined) {
873
+ this.map.panTo(this.markers[spotid].getPosition());
874
+
875
+ //update the list (if enabled)
876
+ var expanded = $$(".expanded").first();
877
+ if (expanded != undefined) {
878
+ expanded.removeClassName("expanded");
879
+ }
880
+
881
+ $(spotid).addClassName("expanded");
882
+
883
+ $$(".list").first().scrollTop = $(spotid).addClassName("expanded").offsetTop;
884
+
885
+ //open the infobubble
886
+ if (this.active_info != null) {
887
+ this.infowindows[this.active_info].close();
888
+ }
889
+ this.infowindows[spotid].open(this.map, this.markers[spotid]);
890
+
891
+ //active marker is this one
892
+ this.active_info = spotid;
893
+ }
894
+ },
895
+ filterMarkers: function () {
896
+ //disable a second click
897
+ if (this.filterLoading != true && $("bpost-gmaps-filter").value.trim() != "") {
898
+ this.filterLoading = true;
899
+ $("filter_submit").addClassName("busy");
900
+
901
+ if ($("bpost-gmaps-filter").value == this.settings.label_postcode) {
902
+ $("bpost-gmaps-filter").value = "";
903
+ }
904
+
905
+ var parameters = {};
906
+ parameters["pointType"] = $("selectPickupPoint").getAttribute("type");
907
+ parameters["bpost-gmaps-filter"] = $("bpost-gmaps-filter").value;
908
+
909
+ //place loader and show it
910
+ if(this.settings.onestepcheckout_active == true) {
911
+ var dimensions = $('mapcontainer').getDimensions();
912
+ } else {
913
+ var dimensions = $('bpostShm').getDimensions();
914
+ }
915
+ $('map-canvas').previous('ul').hide();
916
+ $('map-canvas').setStyle({'width': dimensions.width + 'px', backgroundColor: 'inherit'});
917
+ $('map-canvas').update(this.html_loading);
918
+
919
+ new Ajax.Request(this.settings.base_url + 'bpost/ajax/getwindow', {
920
+ method: 'post',
921
+ parameters: parameters,
922
+ requestHeaders: {Accept: 'application/json'},
923
+ onSuccess: function (transport) {
924
+ var json = transport.responseText.evalJSON(true);
925
+ if (json.error.length == 0) {
926
+ this.drawMap();
927
+ $('map-canvas').previous('ul').show();
928
+ this.reloadMarkers();
929
+ this.clearMarkers();
930
+ this.json = json;
931
+ this.pinMarkers();
932
+ this.panToLocation();
933
+ } else {
934
+ if(this.settings.onestepcheckout_active == true){
935
+ $("bpost-info-wrapper").removeClassName("active");
936
+ this.googleMapsPopup.close();
937
+ }
938
+
939
+ alert(json.error);
940
+ this.bpostClose();
941
+ }
942
+ }.bind(this),
943
+ onFailure: function () {
944
+ alert("Could not contact the server, please try again.");
945
+ this.bpostClose();
946
+ },
947
+ onComplete: function () {
948
+ //enable the button and reset the click
949
+ this.filterLoading = false;
950
+ $("filter_submit").removeClassName("busy");
951
+ this.postalCodeBlur();
952
+ }.bind(this)
953
+ });
954
+ }
955
+ }
956
+ });
js/bpost/shm/onestepcheckout_shipping.js ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var shippingParameters = {};
2
+
3
+ Bpost.ShM.addMethods({
4
+ initialize: function (settings, currentShippingMethod) {
5
+ this.settings = settings;
6
+ this.container = $$('.shipment-methods')[0];
7
+
8
+ $$(".page")[0].insert({'before': $("bpost-info-wrapper")});
9
+
10
+ this.googleMapsPopupContainer = $('bpost-info-wrapper');
11
+ this.googleMapsPopup = new Control.Modal(this.googleMapsPopupContainer, {
12
+ overlayOpacity: 0.65,
13
+ fade: true,
14
+ fadeDuration: 0.3,
15
+ position: 'center_once'
16
+ });
17
+
18
+
19
+ if(currentShippingMethod.substring(0,14) == "bpostshm_bpost"){
20
+ var hook = 'label[for="s_method_'+currentShippingMethod+'"]';
21
+ this.container.down(hook).insert({'after': $("bpostDelivery")});
22
+ }
23
+
24
+ if(currentShippingMethod == carrier+"_bpost_parcellocker"){
25
+ this.container.down('label[for="s_method_'+carrier+'_bpost_parcellocker"]').insert({'after': $("bpostShm")});
26
+ activeOption = "s_method_"+carrier+"_bpost_parcellocker";
27
+ $('selectPickupPoint').style.display = 'inline';
28
+ }
29
+
30
+ if(currentShippingMethod == carrier+"_bpost_pickuppoint"){
31
+ this.container.down('label[for="s_method_'+carrier+'_bpost_pickuppoint"]').insert({'after': $("bpostShm")});
32
+ activeOption = "s_method_"+carrier+"_bpost_pickuppoint";
33
+ $('selectPickupPoint').style.display = 'inline';
34
+ }
35
+
36
+ //init datepicker if bpost carrier is selected
37
+ if(currentShippingMethod == carrier+"_bpost_homedelivery" || currentShippingMethod == carrier+"_bpost_international")
38
+ {
39
+ if(this.settings.datepicker_display) {
40
+ this.container.down('label[for="s_method_' + currentShippingMethod + '"]').insert({'after': $("bpostDelivery")});
41
+ $("bpostDelivery").style.display = 'block';
42
+
43
+ var currMethod = currentShippingMethod.replace(carrier+'_', '');
44
+ this.placeDates(this.settings.datepicker_days, currMethod);
45
+ }
46
+ }
47
+
48
+ this.selectPickupPointLinkClick = this.selectPickupPointLinkClick.bind(this);
49
+ this.resolveSettings = this.resolveSettings.bind(this);
50
+ this.openInline = this.openInline.bind(this);
51
+ this.showDates = this.showDates.bind(this);
52
+ this.deliveryDate = this.deliveryDate.bind(this);
53
+ this.drawMap = this.drawMap.bind(this);
54
+ this.showExtraInfo = this.showExtraInfo.bind(this);
55
+ this.insertAutocomplete = this.insertAutocomplete.bind(this);
56
+ this.pinMarkers = this.pinMarkers.bind(this);
57
+ this.clearMarkers = this.clearMarkers.bind(this);
58
+ this.filterMarkers = this.filterMarkers.bind(this);
59
+ this.reloadMarkers = this.reloadMarkers.bind(this);
60
+ this.selectSpot = this.selectSpot.bind(this);
61
+ this.clickSpot = this.clickSpot.bind(this);
62
+ this.closeInfobox = this.closeInfobox.bind(this);
63
+ this.bpostClose = this.bpostClose.bind(this);
64
+
65
+ this.imageOpenPostOffice = {
66
+ url: this.settings.base_url + 'skin/frontend/base/default/images/bpost/location_postoffice_default.png',
67
+ size: new google.maps.Size(24, 24),
68
+ origin: new google.maps.Point(0, 0),
69
+ anchor: new google.maps.Point(24, 36)
70
+ };
71
+ this.imageOpenPostPoint = {
72
+ url: this.settings.base_url + 'skin/frontend/base/default/images/bpost/location_postpoint_default.png',
73
+ size: new google.maps.Size(24, 24),
74
+ origin: new google.maps.Point(0, 0),
75
+ anchor: new google.maps.Point(24, 36)
76
+ };
77
+ this.imageOpenParcelLocker = {
78
+ url: this.settings.base_url + 'skin/frontend/base/default/images/bpost/location_parcellocker_default.png',
79
+ size: new google.maps.Size(24, 24),
80
+ origin: new google.maps.Point(0, 0),
81
+ anchor: new google.maps.Point(24, 36)
82
+ };
83
+ this.mapOptions = {
84
+ zoom: 11,
85
+ panControl: false,
86
+ zoomControl: true,
87
+ zoomControlOptions: {
88
+ style: google.maps.ZoomControlStyle.SMALL,
89
+ position: google.maps.ControlPosition.TOP_RIGHT
90
+ },
91
+ mapTypeControl: false,
92
+ scaleControl: false,
93
+ streetViewControl: false,
94
+ overviewMapControl: false,
95
+ center: new google.maps.LatLng(51, 4),
96
+ styles: [
97
+ {"featureType": "all", "elementType": "all", "stylers": [
98
+ {"saturation": -93},
99
+ {"lightness": 8}
100
+ ]},
101
+ {featureType: "poi", stylers: [
102
+ {visibility: "off"}
103
+ ]}
104
+ ]
105
+ };
106
+ this.infoboxOptions = {
107
+ content: document.createElement("div"),
108
+ disableAutoPan: false,
109
+ maxWidth: 0,
110
+ pixelOffset: new google.maps.Size(0, -10),
111
+ zIndex: null,
112
+ boxStyle: {
113
+ width: "235px"
114
+ },
115
+ closeBoxURL: "",
116
+ infoBoxClearance: new google.maps.Size(20, 20),
117
+ isHidden: false,
118
+ pane: "floatPane",
119
+ enableEventPropagation: true
120
+ };
121
+ this.shape = {
122
+ coord: [1, 1, 1, 45, 45, 45, 45, 1],
123
+ type: 'poly'
124
+ };
125
+
126
+ if (typeof $(document).eventsBinded == "undefined" && initialized == false) {
127
+ this.bindEvents();
128
+ }
129
+
130
+ initialized = true;
131
+ },
132
+ selectPickupPointLinkClick: function () {
133
+ //set shipping parameters
134
+ this.setShippingParameters();
135
+
136
+ //first check if all necessary parameters are set
137
+ if(shippingParameters["address_id"] == null && shippingParameters["postcode"] == "" && shippingParameters["city"] == ""){
138
+ alert(this.settings.onestepcheckout_shipping_address_error);
139
+ return false;
140
+ }
141
+
142
+ //start resolving setings
143
+ this.resolveSettings();
144
+
145
+ var mapcontainer = new Element('div', { 'id': 'mapcontainer', 'class': 'mapcontainer'})
146
+ .insert(this.html_filter)
147
+ .insert(this.html_list)
148
+ .insert(this.html_map)
149
+ .insert(this.html_clear);
150
+
151
+ if(this.settings.onestepcheckout_active == true){
152
+ $("bpost-info-wrapper").addClassName("active");
153
+ }
154
+
155
+ this.googleMapsPopup.open();
156
+
157
+ $("bpostinfo").update(mapcontainer).down(".filter", 0);
158
+
159
+ if (this.iecompat) {
160
+ $('bpost-gmaps-filter').value = this.settings.label_postcode;
161
+ }
162
+
163
+ //place loader and show it
164
+ $('map-canvas').update(this.html_loading);
165
+
166
+ //call AJAX functionality
167
+ this.triggerWindowAjaxRequest(shippingParameters);
168
+
169
+ this.insertAutocomplete();
170
+ },
171
+ insertAutocomplete: function () {
172
+ var inputEl = $('bpost-gmaps-filter');
173
+
174
+ new google.maps.places.Autocomplete(inputEl);
175
+ },
176
+ drawMap: function () {
177
+ $('bpostlist').setStyle({
178
+ width: '220px'
179
+ })
180
+
181
+ $('map-canvas').setStyle({
182
+ width: '515px'
183
+ })
184
+
185
+ this.map = null;
186
+ this.map = new google.maps.Map($('map-canvas'), this.mapOptions);
187
+ },
188
+ setShippingParameters: function () {
189
+
190
+ //add extra parameters
191
+ //we get the selected shipping address data
192
+ //first check if use billing for shipping is enabled
193
+ shippingParameters = {};
194
+ shippingParameters["pointType"] = $("selectPickupPoint").getAttribute("type");
195
+
196
+ var indexMapping = {
197
+ "billing:city": "city",
198
+ "shipping:city": "city",
199
+ "billing:postcode": "postcode",
200
+ "shipping:postcode": "postcode",
201
+ "billing:street1": "street",
202
+ "shipping:street1": "street"
203
+ };
204
+
205
+ if($('billing:use_for_shipping_yes').checked){
206
+ var savedBillingItems = $('billing-address-select');
207
+ if(savedBillingItems && savedBillingItems.getValue()){
208
+ shippingParameters["address_id"] = savedBillingItems.getValue();
209
+ } else {
210
+ shippingParameters["address_id"] = null;
211
+ var items = $$('input[name^=billing]').concat($$('select[name^=billing]'));
212
+ items.each(function(s) {
213
+ if(s.getStyle('display') != 'none' && s.id == "billing:city" || s.id == "billing:postcode" || s.id == "billing:street1"){
214
+ shippingParameters[indexMapping[s.id]] = s.getValue();
215
+ }
216
+ });
217
+ }
218
+ }else{
219
+ var savedShippingItems = $('shipping-address-select');
220
+ if(savedShippingItems && savedShippingItems.getValue()){
221
+ shippingParameters["address_id"] = savedShippingItems.getValue();
222
+ } else {
223
+ shippingParameters["address_id"] = null;
224
+ var items = $$('input[name^=shipping]').concat($$('select[name^=shipping]'));
225
+ items.each(function(s) {
226
+ if(s.getStyle('display') != 'none' && s.id == "shipping:city" || s.id == "shipping:postcode" || s.id == "shipping:street1"){
227
+ shippingParameters[indexMapping[s.id]] = s.getValue();
228
+ }
229
+ });
230
+ }
231
+ }
232
+ }
233
+ })
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>bpost</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>bpost shipping manager 2015</summary>
10
+ <description>bpost shipping manager By PHPro</description>
11
+ <notes>Added translate Files and Emails</notes>
12
+ <authors><author><name>PHPro</name><user>heremke</user><email>info@phpro.be</email></author></authors>
13
+ <date>2015-09-08</date>
14
+ <time>12:13:00</time>
15
+ <contents><target name="magecommunity"><dir name="Bpost"><dir name="ShM"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="AllOrders"><file name="Grid.php" hash="e6c3e54711425d46a791a96b52d79a48"/></dir><file name="AllOrders.php" hash="c9bed128109004f6007a2c51c0b13687"/><dir name="Grid"><dir name="Renderer"><dir name="Dropdate"><file name="Dateformat.php" hash="dc59c761bbc587cf9d9c3b46881cd5a2"/></dir><dir name="Label"><file name="Download.php" hash="6848a41d5eb1bad1e9da43937e279468"/></dir></dir></dir><file name="Grid.php" hash="a1fbaee1e57a9a4dba925580658cbaf3"/><dir name="Order"><dir name="View"><dir name="Tab"><file name="Returnbarcode.php" hash="d271b69bca3b77dc0a5a624d56628a1d"/><file name="Returnlabels.php" hash="3a281c4942cf722ab58523e9869113eb"/></dir></dir></dir><dir name="PendingOrders"><file name="Grid.php" hash="5d0634a86abf898610004f73d7ed5453"/></dir><file name="PendingOrders.php" hash="584198acc69c0fad60ac793238ca6c8f"/></dir><dir name="Shipping"><dir name="Carrier"><dir name="Bpost"><dir name="Tablerate"><dir name="Homedelivery"><file name="Grid.php" hash="edc472d70d53b81685e0f861a50cd4fd"/></dir><dir name="International"><file name="Grid.php" hash="c76e5042c0f6ff9ed96d978f45336c2c"/></dir><dir name="Parcellocker"><file name="Grid.php" hash="f5de661468fc82c0b0a51baad560ebb4"/></dir><dir name="Pickuppoint"><file name="Grid.php" hash="23151dff9b96415cd8648429260481c9"/></dir></dir></dir></dir></dir><dir name="System"><dir name="Config"><dir name="Form"><dir name="Api"><dir name="Import"><file name="Countries.php" hash="1f2d94c2ffb8f43d81050b7b9da42a42"/></dir></dir><dir name="Field"><file name="Choose.php" hash="ef813927a3ba26302cd8e4c7c5fb62a8"/><file name="Hour.php" hash="763b955bff596cddf2ceabd4ce85816d"/><file name="Info.php" hash="421631d66f10176e4cca80d30df625eb"/><file name="Logo.php" hash="30d8127ce79649b4cbe228a05fa4205f"/><file name="Subheader.php" hash="1af7b5ce235f4f422ab53e281db3cf6f"/></dir><dir name="Tablerates"><dir name="Export"><file name="Homedelivery.php" hash="beb4c5c59ef77d06a425a31d90893255"/><file name="International.php" hash="7806c48c000e996b707e87e58ac1f166"/><file name="Parcellocker.php" hash="e32815fa7846b08318a87c02a7374990"/><file name="Pickuppoint.php" hash="8cb4911d631d257332ce542db49c3672"/></dir></dir></dir></dir></dir></dir><dir name="Carrier"><file name="Bpost.php" hash="a196d872fecee3f7c827d0d7da376d70"/></dir></dir><dir name="Controller"><dir name="ShM"><file name="Order.php" hash="43e2745bb676dbf8c1dedf14e00ecc20"/></dir><file name=".DS_Store" hash="3e624abbe850356dc518e8d865bb05a8"/></dir><dir name="Helper"><file name="Data.php" hash="6ff03d18bda4b66d52d2f2e029004b29"/><file name="Returnlabel.php" hash="8b27e238d29e7b577389231433167141"/><dir name="System"><file name="Config.php" hash="393353ca26ef2b398769ecbb59fdcbf9"/></dir></dir><dir name="Model"><dir name="Adminhtml"><file name="Bpostgrid.php" hash="2e7dea3d2bca7bd82de70f3e6105bb82"/><file name="Observer.php" hash="e40fbb7a4ad7338f88084eed36f59cc1"/><dir name="System"><dir name="Config"><dir name="Backend"><dir name="Shipping"><dir name="Tablerates"><file name="Homedelivery.php" hash="26758346e7e09d2b3075cb0613a00b79"/><file name="International.php" hash="c6ba9e8b7e42893a7faf31392e0d647f"/><file name="Parcellocker.php" hash="2fa265b0623de5740b15ea27284a3b47"/><file name="Pickuppoint.php" hash="84ccd80c14f33de89b8164e396ef3241"/></dir></dir></dir><dir name="Source"><file name="Datecomment.php" hash="e2f0cd25ed8a1bb1e12171269f1ba6d9"/><file name="Shipping.php" hash="a19f622f5f64ee64c8f8e6667d6d9323"/></dir></dir></dir></dir><dir name="Api"><file name="Abstract.php" hash="1c174f96ada592113660356946094fa1"/><file name="Domcreator.php" hash="5491fa04ddc57c285a80857e6b7010e5"/></dir><file name="Api.php" hash="604467308efa121de1fbcd0a31894411"/><file name="Country.php" hash="7ca2d7fee06b4672ee8679dcc0d437cf"/><file name="Holidays.php" hash="85d3ad2c06516d3bd42d6cf25b6c1c1b"/><file name="Observer.php" hash="d99af84f32e787428703159d40081773"/><dir name="Resource"><dir name="Country"><file name="Collection.php" hash="173cb7acd05ead3fa4bb29f1a2200188"/></dir><file name="Country.php" hash="3ed62dc4bae568879a781400724e2b31"/><dir name="Holidays"><file name="Collection.php" hash="b39c602b1b6c7802a8e298ccabd3b88d"/></dir><file name="Holidays.php" hash="8410fabf516cce95e6e6a69e52abb6ec"/><dir name="Returnlabel"><file name="Collection.php" hash="d34adb537d24116270238ae1fa377a05"/></dir><file name="Returnlabel.php" hash="419fda598a2630ccc773ce0b0eacbd79"/><dir name="Tablerates"><dir name="Homedelivery"><file name="Collection.php" hash="7a34c249b5015ecda8ad26cbf42c6280"/></dir><file name="Homedelivery.php" hash="a94baf3909962e162813d8003583cc77"/><dir name="International"><file name="Collection.php" hash="6ba99077f1625a8c81990ea3afcb14b8"/></dir><file name="International.php" hash="ca3e45f29f9ef44f00ff41b509e0f0a1"/><dir name="Parcellocker"><file name="Collection.php" hash="9aa78e0bc7d389e93e958472a0fc40b6"/></dir><file name="Parcellocker.php" hash="66bb509267844a48ff5b054c82a47254"/><dir name="Pickuppoint"><file name="Collection.php" hash="1f9db3d5ff7f1a9e9d2eccddf6860513"/></dir><file name="Pickuppoint.php" hash="33e26bc93dcea5aabbee59343043413d"/></dir></dir><file name="Returnlabel.php" hash="72e3631e3106cc8710270092c7f23ed1"/><dir name="Shipping"><dir name="Carrier"><file name="BpostShM.php" hash="e2ea2a1a71bf4dd21b497cdfc7cd0637"/></dir><file name="Geocode.php" hash="fe2273974154557204395f79c688be52"/><dir name="Rate"><file name="Result.php" hash="77e9fc98f15441edfdc478fd589e41a8"/></dir></dir><dir name="System"><dir name="Config"><dir name="Source"><file name="Country.php" hash="f49cbe30d05cffb6f516a3df6ddc1b7b"/><file name="Product.php" hash="cb74b0fc8d3f661d0be4ac9f9c5b840d"/><file name="Ratetypes.php" hash="42f1f3f8dc000ea5e5336ca1ad7ab85c"/><file name="Weightunit.php" hash="e0c0a9975395245c4d16d975c0334c31"/></dir></dir></dir><dir name="Tablerates"><file name="Homedelivery.php" hash="d60385de528eb957a2874af6306d4aae"/><file name="International.php" hash="d02e02a7cddbda576530d6acbd6d02e8"/><file name="Parcellocker.php" hash="805a9669f9d024a4c018d611e5c71afd"/><file name="Pickuppoint.php" hash="49dff9f40e26163b8d0c6b8be9f6ee51"/></dir><file name=".DS_Store" hash="0047fe0bc161a58c6088a4e959de43a4"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Bpost"><dir name="ShM"><file name="AllOrdersController.php" hash="01d0f8d2ec4180d854f18f913c8c164b"/><file name="ConfigController.php" hash="4162396a6ba56e940420fd9fe2c6ec5e"/><file name="DownloadController.php" hash="922f7565761811017a51882fb81d5669"/><file name="PendingOrdersController.php" hash="4589f63b6bf06850fe32c0b2160dab5a"/></dir></dir></dir><file name="AjaxController.php" hash="5319019be27bb45d40d536d086e74dec"/></dir><dir name="etc"><file name="adminhtml.xml" hash="cba525a2c3c394cb15c144f887e081cc"/><file name="config.xml" hash="f1f88eee1c4de171aa7bec7eb6150265"/><file name="system.xml" hash="e19af914361223c8c62c2b33542d7fb0"/></dir><dir name="sql"><dir name="bpost_shm_setup"><file name="install-0.0.1.php" hash="441ce29ddd9b04c052f03699e8ecc704"/><file name="upgrade-0.0.1-0.0.2.php" hash="7c5bb7a9609d6bec38a927e07eaad066"/><file name="upgrade-0.0.10-0.1.0.php" hash="c1523f2fd829372143c4686376512b37"/><file name="upgrade-0.0.2-0.0.3.php" hash="7e441f96e071efaa42d629815be8379c"/><file name="upgrade-0.0.3-0.0.4.php" hash="e2009ca70b9b268024433be7ac74ba19"/><file name="upgrade-0.0.4-0.0.5.php" hash="a51391f3bf810a5c6ae5c0bdbc5d9603"/><file name="upgrade-0.0.5-0.0.6.php" hash="2d8d624be7f829029b3e9fceb6d6c3b8"/><file name="upgrade-0.0.6-0.0.7.php" hash="82a7a64e3234c8b6e20367fcc80e1049"/><file name="upgrade-0.0.7-0.0.8.php" hash="3366e57552fa19433772709a557d2ed3"/><file name="upgrade-0.0.8-0.0.9.php" hash="20a344294274390515a891a89facfcb3"/><file name="upgrade-0.0.9-0.0.10.php" hash="064df8d78b82bc05d44041af93ca1bff"/><file name="upgrade-0.1.0-0.1.1.php" hash="ed824736e9cd0f8e98a4dc62c41ecf96"/><file name="upgrade-0.1.1-0.1.2.php" hash="bb7cf544bc07ef2209b82753ac2b950d"/><file name="upgrade-0.1.2-0.1.3.php" hash="04f9ab295e48b018e80da482bdf23132"/><file name="upgrade-0.1.3-0.1.4.php" hash="e9f9ecec20e2f5e05e44db2dc153bd56"/><file name="upgrade-0.1.4-0.1.5.php" hash="16333b0f3faa92e98d6bb6f75b4273cd"/><file name="upgrade-0.1.5-0.1.6.php" hash="f2f1f169a5ad2fbd0650ffbef3217b08"/><file name="upgrade-0.1.6-0.1.7.php" hash="95eebc7f870fa36c0a0997a06cb47076"/><file name="upgrade-0.1.7-0.1.8.php" hash="56a4bc5320b56309c943a90df00464e8"/></dir><file name=".DS_Store" hash="247fda627329429624d4c2a70ecd2548"/></dir><file name=".DS_Store" hash="4af56bbb3c9888516482dd6c916f7f0e"/></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="bpost"><file name="shm.xml" hash="8a5ceb93674efcbd6e8063437877d9d5"/></dir></dir><dir name="template"><dir name="bpost"><file name="empty.phtml" hash="45a92398f5adc3dd6dda9527f95ef4d5"/><file name="informationpopup.phtml" hash="42432ed861bb8b5b34a39d879c164979"/><file name="screenshotpopup.phtml" hash="5ad6a05c55ea41e550262ceed28626ae"/><dir name="widget"><dir name="grid"><file name="massaction.phtml" hash="f9b9aa54fe683d66fd535f95afb07dfe"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="bpost"><file name="shm.xml" hash="7950f7c44cc1b2a10846611251a37501"/></dir></dir><dir name="template"><dir name="bpost"><dir name="shm"><file name="append_bpost_shippingmethod.phtml" hash="1cfb8adf326ab846a01ad0de4215c42c"/><file name="gmapsapi.phtml" hash="8a5119f27b9537f9ede57ead12403a32"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="zBpost_ShM.xml" hash="791aeaa9ddf185a0b053728b20b06ea0"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Bpost_ShM.csv" hash="6df815c54e85758ff196e1da7cf529ff"/><dir name="template"><dir name="email"><dir name="bpost"><file name="returnlabel.html" hash="c006eca772b567c6eefddbe04238eef7"/><file name="errorhandling_create_order.html" hash="5458114b6bfee6f66841f4fe19e13675"/></dir></dir></dir></dir><dir name="fr_DR"><file name="Bpost_ShM.csv" hash=""/></dir><dir name="nl_NL"><file name="Bpost_ShM.csv" hash="b1598134c8742456df3a3e66450d5ccf"/></dir></target><target name="mageweb"><dir name="js"><dir name="bpost"><dir name="shm"><dir name="adminhtml"><file name="informationpopup.js" hash="dd25216084d43f70b7de4beaf1ef23c5"/></dir><file name="checkout.js" hash="eec1d106f5e3a0bd91e6ab14809646a9"/><file name="onestepcheckout_shipping.js" hash="29903124602caaf62ad16cdcf7661239"/></dir><file name=".DS_Store" hash="9cb5eec7f2c81769f587e6bea95ca5e7"/></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><dir name="bpost"><file name="checkout.css" hash="cca98b2e3ab7dbbb223ab269ab4b3001"/></dir></dir><dir name="images"><dir name="bpost"><file name="ajax-loader-button.gif" hash="cbdad94ec5d22b17d7aae4c6d245069a"/><file name="ajax-loader-wheel.gif" hash="faa74e8c61fc64d5edb11613c7eead2c"/><file name="bpost_logo_RGB72_L.png" hash="ca8a5de3a37cfbbdac7c0fec6e4f9f28"/><file name="bpost_logo_RGB72_M.png" hash="feb4bb3bb7c9c4100612b62cde7037e5"/><file name="bpost_sym_RGB72_S.png" hash="18e774a968be600664d11a9e0691a424"/><file name="btn_close.png" hash="d6ecac0a01a600ef15efc9004ccc9fb7"/><file name="icon-close.png" hash="54d0827f50c1d294c61e88e316e61059"/><file name="icon-info.png" hash="e4de51e3c12327403a9b966aac98a9d6"/><file name="location_parcellocker_default.png" hash="8906b0e09067eab6f31b712d54ecf547"/><file name="location_postoffice_default.png" hash="ea147b38b01449e8a1cff3ebff6b2741"/><file name="location_postpoint_default.png" hash="c53f598daafbec4d042b165d21116719"/></dir></dir><dir name="js"><dir name="bpost"><file name="onestepcheckout.js" hash="ae2876b7d0d3daf156ec55f3772fab8d"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="css"><dir name="bpost"><file name="informationpopup.css" hash="ce01062469cdb18ba03c76c129912c00"/></dir></dir><dir name="images"><dir name="bpost"><file name="ajax-loader-red.gif" hash="7bf0fa0e5a55c6a7cd122a9bb461006d"/><file name="bpost_logo_RGB72_L.png" hash="ca8a5de3a37cfbbdac7c0fec6e4f9f28"/><file name="bpost_logo_RGB72_M.png" hash="feb4bb3bb7c9c4100612b62cde7037e5"/><file name="btn_close.png" hash="d6ecac0a01a600ef15efc9004ccc9fb7"/><file name="ce-screenshot.png" hash="ff6f4a630cd17efc1abbe8eca6e015a5"/><file name="ee-screenshot.png" hash="ff6f4a630cd17efc1abbe8eca6e015a5"/><file name="pdf_icon.png" hash="95b561422892384337eb2eabb968a558"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/adminhtml/default/default/css/bpost/informationpopup.css ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .bpostInfo{background:url('../../images/bpost/bpost_logo_RGB72_M.png') left/75px no-repeat; margin-bottom:10px; display:block;height:50px;}
2
+ .bpostInfo span{padding-top: 30px;display: block;padding-left: 80px;}
3
+ #bpost_info_window {background: white;display: block;position: absolute;border-radius: 5px;border-width: 3px;}
4
+ #bpost_info_window_close {width: 30px;height: 30px;background-image: url('../../images/bpost/btn_close.png');position: absolute;top: -10px;right: -10px; cursor: pointer;z-index: 2000;display: block;}
5
+ #bpost_info_window .top.table_window {display: none;}
6
+ #bpost_info_window .magento_w, .magento_e, .magento_content{background:none !important;}
7
+ .adminhtml-bpost-shm-config-informationpopup:before{content: " ";position: absolute;top: 0;left: 0;width: 570px;height: 360px;opacity: .2;z-index: -1; background: url('../../images/bpost/bpost_logo_RGB72_L.png') center no-repeat;}
8
+ .adminhtml-bpost-shm-config-informationpopup{background:none; font-size:14px; padding:20px;}
9
+ .adminhtml-bpost-shm-config-informationpopup ul{ margin-left: 40px; margin-bottom: 20px;}
10
+ .adminhtml-bpost-shm-config-informationpopup ul li{list-style-type:disc;}
11
+
12
+ #bpost_info_window_content{background: white}
13
+
14
+ td.subheader{
15
+ font-size: 14pt;
16
+ padding-bottom: 10px;
17
+ }
18
+
19
+ td.subheader.value{
20
+ padding:8px 5px 8px 0!important;
21
+ }
22
+
23
+ .adminhtml-bpost-shm-config-gridinformationpopup{width: 100%;height: 240px; background: url('../../images/bpost/ajax-loader-red.gif') center no-repeat white;}
24
+ .adminhtml-bpost-shm-config-gridinformationpopup .text-wrapper{position: absolute; bottom: 35px; text-align: center;}
25
+ .adminhtml-bpost-shm-config-screenshotpopup{overflow: hidden}
26
+ .adminhtml-bpost-shm-config-screenshotpopup .example-screenshot{width: 100%}
skin/adminhtml/default/default/images/bpost/ajax-loader-red.gif ADDED
Binary file
skin/adminhtml/default/default/images/bpost/bpost_logo_RGB72_L.png ADDED
Binary file
skin/adminhtml/default/default/images/bpost/bpost_logo_RGB72_M.png ADDED
Binary file
skin/adminhtml/default/default/images/bpost/btn_close.png ADDED
Binary file
skin/adminhtml/default/default/images/bpost/ce-screenshot.png ADDED
Binary file
skin/adminhtml/default/default/images/bpost/ee-screenshot.png ADDED
Binary file
skin/adminhtml/default/default/images/bpost/pdf_icon.png ADDED
Binary file
skin/frontend/base/default/css/bpost/checkout.css ADDED
@@ -0,0 +1,575 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .mapcontainer {
2
+ margin: 0;
3
+ height: 430px;
4
+ }
5
+
6
+ #bpostShm .mapcontainer {
7
+ margin: 10px 0;
8
+ }
9
+
10
+ .mapcontainer .bpost-close-wrapper {
11
+ height: 33px;
12
+ }
13
+
14
+ .mapcontainer .filter #filter_submit.busy {
15
+ text-indent: -9999px;
16
+ background: url(../../images/bpost/ajax-loader-button.gif) no-repeat center #DC002E;
17
+ }
18
+
19
+ .mapcontainer .filter #filter_submit.busy:hover {
20
+ color: #FFFFFF;
21
+ cursor: not-allowed;
22
+ }
23
+
24
+ .mapcontainer #map-canvas {
25
+ width: 100%;
26
+ height: 400px;
27
+ float: left;
28
+ background-color: #fff !important;
29
+ }
30
+
31
+ #bpostShm {
32
+ border-left: 3px solid #DC002E;
33
+ padding-left: 15px;
34
+ }
35
+
36
+ .pac-container {
37
+ z-index: 2000000 !important;
38
+ }
39
+
40
+ .btn-bpost {
41
+ background: #DC002E;
42
+ border: none;
43
+ color: #fff;
44
+ text-decoration: none;
45
+ cursor: pointer;
46
+ display: inline-block;
47
+ padding: 7px 15px;
48
+ font-size: 13px;
49
+ text-transform: uppercase;
50
+ }
51
+
52
+ .bpost-input-box {
53
+ display: table;
54
+ width: 100%;
55
+ }
56
+
57
+ .bpost-input-box .input {
58
+ display: table-cell;
59
+ width: 85%;
60
+ padding-right: 3px;
61
+ vertical-align: top;
62
+ }
63
+
64
+ .bpost-input-box .input input {
65
+ width: 100%;
66
+ vertical-align: top;
67
+ line-height: 23px;
68
+ padding-left: 7px;
69
+ padding-right: 7px;
70
+ }
71
+
72
+ .bpost-input-box .action {
73
+ display: table-cell;
74
+ width: 100%;
75
+ }
76
+
77
+ .bpost-input-box .action input {
78
+ width: 100%;
79
+
80
+ }
81
+
82
+ .bpost-close-wrapper {
83
+ width: 100%;
84
+ display: block;
85
+ }
86
+
87
+ .bpost-close {
88
+ float: right;
89
+ }
90
+
91
+ .infoBox {
92
+ display: block;
93
+ /*overflow: hidden;*/
94
+ margin-top: 8px;
95
+ background: #fff;
96
+ text-align: left;
97
+ border-radius: 0 6px 6px;
98
+ /*font: lighter 13px/16px "marselispro","Lucida Grande",Lucida,Verdana,sans-serif;*/
99
+ }
100
+
101
+ .infoBox .infobox-arrow {
102
+ position: absolute;
103
+ top: -30px;
104
+ left: -18px;
105
+ width: 0;
106
+ height: 0;
107
+ text-indent: -9999px;
108
+ border-right: 50px solid transparent;
109
+ border-bottom: 125px solid #fff;
110
+ border-left: 50px solid transparent;
111
+ -ms-transform: rotate(-40deg); /* IE 9 */
112
+ -webkit-transform: rotate(-40deg); /* Chrome, Safari, Opera */
113
+ transform: rotate(-40deg);
114
+ z-index: 1;
115
+ }
116
+
117
+ .infoBox .close {
118
+ top: 6px;
119
+ right: 6px;
120
+ background: url(../../images/bpost/icon-close.png) no-repeat center;
121
+ position: absolute;
122
+ height: 14px;
123
+ text-indent: -9999px;
124
+ width: 14px;
125
+ z-index: 3;
126
+ }
127
+
128
+ .infoBox h3 {
129
+ margin: 0;
130
+ font-weight: bold;
131
+ padding: 15px 15px 5px;
132
+ color: #DC002E;
133
+ font-size: 19px;
134
+ line-height: 19px;
135
+ position: relative;
136
+ z-index: 2;
137
+ }
138
+
139
+ .infoBox p {
140
+ margin: 0;
141
+ font-size: 12px;
142
+ padding: 5px 15px 0px;
143
+ position: relative;
144
+ z-index: 2;
145
+ }
146
+
147
+ .infoBox ul.hours {
148
+ margin: 0;
149
+ padding: 5px 15px 10px;
150
+ border-radius: 0 0 6px 6px;
151
+ display: block;
152
+ position: relative;
153
+ z-index: 2;
154
+ }
155
+
156
+ .infoBox ul.hours li {
157
+ display: inline-block;
158
+ clear: both;
159
+ margin: 0;
160
+ font-size: 11px;
161
+ line-height: 1em;
162
+ width: 100%;
163
+ height: 9px;
164
+ }
165
+
166
+ .infoBox ul.hours li span.day {
167
+ width: 65px;
168
+ display: block;
169
+ float: left;
170
+ text-align: left;
171
+ color: #5a5a5f;
172
+ font-weight: bold;
173
+ }
174
+
175
+ .infoBox ul.hours li span.small {
176
+ width: 10px;
177
+ display: block;
178
+ float: left;
179
+ text-align: center;
180
+ }
181
+
182
+ .infoBox ul.hours li span.large {
183
+ display: block;
184
+ float: left;
185
+ text-align: center;
186
+ }
187
+
188
+ .infoBox .selectspot {
189
+ color: #fff;
190
+ display: block;
191
+ padding: 8px 15px;
192
+ text-decoration: none;
193
+ font-weight: bold;
194
+ background: #DC002E;
195
+ border-radius: 0 0 6px 6px;
196
+ position: relative;
197
+ z-index: 2;
198
+ }
199
+
200
+ .infoBox .selectspot:hover {
201
+ color: #fff;
202
+
203
+ }
204
+
205
+ ul#bpostlist {
206
+ background-color: #FFFFFF;
207
+ display: block;
208
+ height: 400px;
209
+ overflow-y: auto;
210
+ overflow-x: hidden;
211
+ float: left;
212
+ position: relative;
213
+ }
214
+
215
+ ul#bpostlist li {
216
+ margin: 0;
217
+ padding: 10px 0 10px 10px;
218
+ border-bottom: 1px solid #DC002E;
219
+ cursor: pointer;
220
+ box-sizing: border-box;
221
+ }
222
+
223
+ ul#bpostlist li:last-child {
224
+ border-bottom: none;
225
+ }
226
+
227
+ ul#bpostlist li.expanded {
228
+ background-color: #f0f0f0;
229
+ display: inline-block;
230
+ width: 100%;
231
+ padding-bottom: 0;
232
+ cursor: default;
233
+ }
234
+
235
+ ul#bpostlist li .selectspot {
236
+ display: none;
237
+ }
238
+
239
+ ul#bpostlist li.expanded .selectspot {
240
+ display: block;
241
+ background-color: #DC002E;
242
+ color: #FFFFFF;
243
+ float: right;
244
+ text-align: center;
245
+ border-radius: 5px 0 0;
246
+ font-size: 12px;
247
+ padding: 2px 15px;
248
+ text-decoration: none;
249
+ }
250
+
251
+ ul#bpostlist li .title {
252
+ display: block;
253
+ clear: both;
254
+ color: #DC002E;
255
+ }
256
+
257
+ ul#bpostlist li .address {
258
+ display: block;
259
+ clear: both;
260
+ color: #000;
261
+ font-size: 12px;
262
+ text-transform: lowercase;
263
+ }
264
+
265
+ ul#bpostlist li .address:first-letter {
266
+ text-transform: uppercase;
267
+ }
268
+
269
+ ul#bpostlist li .city {
270
+ display: block;
271
+ clear: both;
272
+ color: #000;
273
+ font-size: 12px;
274
+ }
275
+
276
+ .bpost_loading {
277
+ text-align: center;
278
+ width: 360px;
279
+ margin: 100px auto 0;
280
+ }
281
+
282
+ .bpost_loading span.bpost-please-wait {
283
+ width: 100%;
284
+ display: block;
285
+ margin-bottom: 10px;
286
+ }
287
+
288
+ .bpost_loading span.ajaxloading {
289
+ background: url(../../images/bpost/ajax-loader-wheel.gif) no-repeat center;
290
+ width: 100%;
291
+ display: block;
292
+ height: 24px;
293
+ margin-bottom: 20px;
294
+ }
295
+
296
+ .bpost_loading .image {
297
+ background: url(../../images/bpost/bpost_logo_RGB72_M.png) no-repeat center;
298
+ display: block;
299
+ height: 80px;
300
+ width: 150px;
301
+ text-indent: -9999px;
302
+ margin: 0 auto 10px;
303
+ }
304
+
305
+ #bpostresult {
306
+ clear: both;
307
+ width: 100%;
308
+ height: auto;
309
+ display: none;
310
+ }
311
+
312
+ #bpostresult:after {
313
+ clear: both;
314
+ content: " ";
315
+ display: block;
316
+ }
317
+
318
+ #bpostresult img {
319
+ display: block;
320
+ float: left;
321
+ max-width: 115px;
322
+ margin: 3px 20px 3px 0;
323
+ }
324
+
325
+ #bpostresult p {
326
+ display: block;
327
+ float: left;
328
+ line-height: inherit;
329
+ margin: 3px 0 3px 0;
330
+ }
331
+
332
+ #bpostresult b {
333
+ float: left;
334
+ }
335
+
336
+ #bpostresult a {
337
+ color: #DC002E;
338
+ }
339
+
340
+ #bpostresult a.infobtn {
341
+ background: url(../../images/bpost/icon-info.png) no-repeat center;
342
+ display: inline-block;
343
+ float: left;
344
+ height: 14px;
345
+ width: 14px;
346
+ margin: 3px 5px 0;
347
+ text-indent: -9999px;
348
+ }
349
+
350
+ #bpostresult b.no-info-btn {
351
+ color: #DC002E;
352
+ }
353
+
354
+ #bpostresult ul {
355
+ background-color: #f4f4f4;
356
+ display: inline-block;
357
+ visibility: hidden;
358
+ font-size: 13px;
359
+ padding: 4px 10px;
360
+ line-height: 13px;
361
+ border-left: 3px solid #DC002E;
362
+ border-radius: 5px;
363
+ position: absolute;
364
+ margin-top: 10px;
365
+ z-index: 10;
366
+ }
367
+
368
+ #bpostresult ul li span.day {
369
+ width: 85px;
370
+ display: inline-block;
371
+ color: #5a5a5f;
372
+ font-weight: bold;
373
+ }
374
+ #bpostresult ul li span.small {
375
+ margin: 0 3px;
376
+ }
377
+
378
+ .notifications {
379
+ margin: 1em 0;
380
+ margin: 1em 0 0;
381
+ display: none;
382
+ }
383
+
384
+ .notifications h5 {
385
+ margin-bottom: 0;
386
+ }
387
+
388
+ .notifications label {
389
+ background-color: inherit !important;
390
+ display: inline-block;
391
+ width: auto;
392
+ max-width: none;
393
+ min-width: 250px;
394
+ float: none;
395
+ padding: 6px 10px !important;
396
+ cursor: pointer !important;
397
+ }
398
+
399
+ .notifications label.disabled {
400
+ cursor: default !important;
401
+ }
402
+
403
+ #selectPickupPoint {
404
+ display: none;
405
+ color: black;
406
+ font-size: 12px;
407
+ }
408
+
409
+ @media only screen and (max-width: 667px) {
410
+ #map-canvas {
411
+ display: none;
412
+ }
413
+ #bpostlist {
414
+ width: 100% !important;
415
+ }
416
+
417
+ .bpost-input-box .input {
418
+ width: 80%;
419
+ }
420
+ }
421
+
422
+ #bpostDelivery {
423
+ display: none;
424
+ width: 100%;
425
+ border-left: 3px solid #DC002E;
426
+ padding: 10px 0 10px 15px;
427
+ }
428
+
429
+ #bpostDelivery h5 {
430
+ float: left;
431
+ margin: 1px 0;
432
+ }
433
+
434
+ #bpostDelivery .bpost-display-deliverydate {
435
+ display: none;
436
+ float: left;
437
+ margin-left: 20px;
438
+ color: black;
439
+ }
440
+
441
+ #bpostDelivery .bpost-choose-deliverydate {
442
+ display: none;
443
+ width: 100%;
444
+ margin: 7px 0 3px;
445
+ float: left;
446
+ }
447
+
448
+ #bpostDelivery .bpost-choose-deliverydate ul li {
449
+ display: inline-block;
450
+ margin-right: 5px;
451
+ margin-bottom: 0px;
452
+ }
453
+
454
+ #bpostDelivery .bpost-choose-deliverydate ul li:last-child {
455
+ margin-right: 0;
456
+ }
457
+
458
+ #bpostDelivery .bpost-choose-deliverydate ul li label {
459
+ position: relative;
460
+ display: block;
461
+ color: #636363 !important;
462
+ background: #f4f4f4;
463
+ -moz-border-radius: 4px;
464
+ -webkit-border-radius: 4px;
465
+ border-radius: 4px;
466
+ color: #636363;
467
+ padding: 6px 10px;
468
+ cursor: pointer;
469
+ min-width: unset !important;
470
+ font-weight: bold !important;
471
+ }
472
+
473
+ #bpostDelivery .bpost-choose-deliverydate ul li label input {
474
+ margin-right: 3px;
475
+ cursor: pointer;
476
+ }
477
+
478
+ #bpostDelivery .bpost-choose-deliverydate ul li label span {
479
+ display: block;
480
+ font-weight: normal;
481
+ }
482
+
483
+ #bpostDelivery .bpost-saturday-delivery {
484
+ display: none;
485
+ margin-top: 10px;
486
+ }
487
+
488
+ #bpostDelivery .bpost-saturday-delivery label {
489
+ background: #f4f4f4;
490
+ cursor: pointer;
491
+ padding: 6px 10px !important;
492
+ -moz-border-radius: 4px;
493
+ -webkit-border-radius: 4px;
494
+ border-radius: 4px;
495
+ color: #636363 !important;
496
+ }
497
+
498
+ #bpostDelivery .bpost-saturday-delivery input {
499
+ display: inline-block;
500
+ vertical-align: top;
501
+ margin-right: 3px;
502
+ cursor: pointer;
503
+ }
504
+
505
+ #bpostDelivery .bpost-label-text {
506
+ display: inline-block;
507
+ vertical-align: top;
508
+ line-height: 1.1em;
509
+ }
510
+
511
+ .bpost-carrier-logo {
512
+ width: 37px;
513
+ height: 27px;
514
+ vertical-align: middle;
515
+ display: inline-block;
516
+ margin-right: 5px;
517
+ }
518
+
519
+ /* ********************* */
520
+ /* ***onestepcheckout*** */
521
+ /* ********************* */
522
+ .onestepcheckout-index-index #bpost-info-wrapper{
523
+ background:white;
524
+ width: 760px;
525
+ padding:10px;
526
+ display: none;
527
+ }
528
+
529
+ .onestepcheckout-index-index #bpost-info-wrapper.active{
530
+ border: 2px solid #DC002E;
531
+ display: block;
532
+ }
533
+
534
+ .onestepcheckout-index-index #bpostDelivery .bpost-saturday-delivery input,
535
+ .onestepcheckout-index-index #bpostDelivery .bpost-label-text{
536
+ display: inline;
537
+ }
538
+
539
+ #bpostShm #notifications-parcel-locker,
540
+ #bpostShm #notifications-pick-up-point{
541
+ position: relative;
542
+ }
543
+
544
+ #bpostShm #reduced-mobility-wrapper .reduced-mobility-tooltip{
545
+ display: none;
546
+ position: absolute;
547
+ z-index: 100;
548
+ padding: 2px 4px;
549
+ background: white none repeat scroll 0 0;
550
+ border: 1px solid #dc002e;
551
+ color: #dc002e;
552
+ margin-left: 15px;
553
+ }
554
+
555
+ #bpostShm #reduced-mobility-wrapper:hover .reduced-mobility-tooltip, #reduced-mobility-wrapper:active .reduced-mobility-tooltip {
556
+ display: block;
557
+ }
558
+
559
+ .cf:before,
560
+ .cf:after {
561
+ content: " "; /* 1 */
562
+ display: table; /* 2 */
563
+ }
564
+
565
+ .cf:after {
566
+ clear: both;
567
+ }
568
+
569
+ .cf {
570
+ *zoom: 1;
571
+ }
572
+
573
+ #bpostShm #notifications-parcel-locker h5, #bpostShm #notifications-pick-up-point h5, #bpostDelivery h5{
574
+ color:#dc002e;
575
+ }
skin/frontend/base/default/images/bpost/ajax-loader-button.gif ADDED
Binary file
skin/frontend/base/default/images/bpost/ajax-loader-wheel.gif ADDED
Binary file
skin/frontend/base/default/images/bpost/bpost_logo_RGB72_L.png ADDED
Binary file
skin/frontend/base/default/images/bpost/bpost_logo_RGB72_M.png ADDED
Binary file
skin/frontend/base/default/images/bpost/bpost_sym_RGB72_S.png ADDED
Binary file
skin/frontend/base/default/images/bpost/btn_close.png ADDED
Binary file
skin/frontend/base/default/images/bpost/icon-close.png ADDED
Binary file
skin/frontend/base/default/images/bpost/icon-info.png ADDED
Binary file
skin/frontend/base/default/images/bpost/location_parcellocker_default.png ADDED
Binary file
skin/frontend/base/default/images/bpost/location_postoffice_default.png ADDED
Binary file
skin/frontend/base/default/images/bpost/location_postpoint_default.png ADDED
Binary file
skin/frontend/base/default/js/bpost/onestepcheckout.js ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ get_separate_save_methods_function = function get_separate_save_methods_function_bpost(url, update_payments)
2
+ {
3
+ if(typeof update_payments == 'undefined') {
4
+ var update_payments = false;
5
+ }
6
+
7
+ return function(e) {
8
+ triggerAjaxCallGetSeparateSaveMethods(url, update_payments);
9
+ }
10
+ }
11
+
12
+ triggerAjaxCallGetSeparateSaveMethods = function (url, update_payments){
13
+ var saturdayDelivery = 0;
14
+
15
+ //if undefined, page load
16
+ if($('bpost-saturday')){
17
+ if($('bpost-saturday').checked ){
18
+ saturdayDelivery = 1;
19
+ }
20
+ }
21
+
22
+ if(typeof e != 'undefined') {
23
+ var element = e.element();
24
+
25
+ if(element.name != 'shipping_method') {
26
+ update_payments = false;
27
+ }
28
+ }
29
+
30
+ var form = $('onestepcheckout-form');
31
+ var shipping_method = $RF(form, 'shipping_method');
32
+ var payment_method = $RF(form, 'payment[method]');
33
+ var totals = get_totals_element();
34
+
35
+ var freeMethod = $('p_method_free');
36
+ if(freeMethod){
37
+ payment.reloadcallback = true;
38
+ payment.countreload = 1;
39
+ }
40
+
41
+ totals.update('<div class="loading-ajax">&nbsp;</div>');
42
+
43
+ if(update_payments) {
44
+ var payment_methods = $$('div.payment-methods')[0];
45
+ payment_methods.update('<div class="loading-ajax">&nbsp;</div>');
46
+ }
47
+
48
+
49
+ var parameters = {
50
+ shipping_method: shipping_method,
51
+ payment_method: payment_method,
52
+ disable_saturday_delivery:saturdayDelivery
53
+ }
54
+
55
+ /* Find payment parameters and include */
56
+ var items = $$('input[name^=payment]').concat($$('select[name^=payment]'));
57
+ var names = items.pluck('name');
58
+ var values = items.pluck('value');
59
+
60
+ for(var x=0; x < names.length; x++) {
61
+ if(names[x] != 'payment[method]') {
62
+ parameters[names[x]] = values[x];
63
+ }
64
+ }
65
+
66
+ new Ajax.Request(url, {
67
+ method: 'post',
68
+ onSuccess: function(transport) {
69
+ if(transport.status == 200) {
70
+ var data = transport.responseText.evalJSON();
71
+ var form = $('onestepcheckout-form');
72
+
73
+ totals.update(data.summary);
74
+
75
+ if(update_payments) {
76
+
77
+ payment_methods.replace(data.payment_method);
78
+
79
+ $$('div.payment-methods input[name="payment\[method\]"]').invoke('observe', 'click', get_separate_save_methods_function(url));
80
+ $$('div.payment-methods input[name="payment\[method\]"]').invoke('observe', 'click', function() {
81
+ $$('div.onestepcheckout-payment-method-error').each(function(item) {
82
+ new Effect.Fade(item);
83
+ });
84
+ });
85
+
86
+ if($RF($('onestepcheckout-form'), 'payment[method]') != null) {
87
+ try {
88
+ var payment_method = $RF(form, 'payment[method]');
89
+ $('container_payment_method_' + payment_method).show();
90
+ $('payment_form_' + payment_method).show();
91
+ } catch(err) {
92
+
93
+ }
94
+ }
95
+ }
96
+ }
97
+ },
98
+ parameters: parameters
99
+ });
100
+ }
101
+
102
+ get_methods_separate = function () {
103
+ if($('bpost-saturday').getStorage().get('prototype_event_registry') == undefined){
104
+ triggerAjaxCallGetSeparateSaveMethods(window.onestepcheckout_set_methods_separate, false);
105
+ }
106
+ }