shipping_manager_by_bpost - Version 1.0.0

Version Notes

Release version 1.0.0 - Magento Connect 1.0 compatible

Download this release

Release Info

Developer Magento Core Team
Extension shipping_manager_by_bpost
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (102) hide show
  1. app/code/community/Bpost/ShippingManager/Block/Abstract.php +25 -0
  2. app/code/community/Bpost/ShippingManager/Block/Adminhtml/Javascript.php +23 -0
  3. app/code/community/Bpost/ShippingManager/Block/Confirm.php +28 -0
  4. app/code/community/Bpost/ShippingManager/Block/Javascript.php +53 -0
  5. app/code/community/Bpost/ShippingManager/Block/Onepage/Shipping/Method/Available.php +43 -0
  6. app/code/community/Bpost/ShippingManager/Block/Platformstub.php +53 -0
  7. app/code/community/Bpost/ShippingManager/Block/Startform.php +115 -0
  8. app/code/community/Bpost/ShippingManager/Block/Tracking.php +11 -0
  9. app/code/community/Bpost/ShippingManager/Helper/Data.php +173 -0
  10. app/code/community/Bpost/ShippingManager/Model/Api.php +330 -0
  11. app/code/community/Bpost/ShippingManager/Model/Carrier/Bpost.php +181 -0
  12. app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Abstract.php +205 -0
  13. app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Bpackbusiness.php +19 -0
  14. app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Bpackexpress.php +19 -0
  15. app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Parcelsdepot.php +19 -0
  16. app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Pugo.php +19 -0
  17. app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Regular.php +19 -0
  18. app/code/community/Bpost/ShippingManager/Model/Carrier/System/Config/Source/Method.php +188 -0
  19. app/code/community/Bpost/ShippingManager/Model/Entity/Setup.php +8 -0
  20. app/code/community/Bpost/ShippingManager/Model/Observer.php +30 -0
  21. app/code/community/Bpost/ShippingManager/Model/Postback.php +14 -0
  22. app/code/community/Bpost/ShippingManager/Model/ShippingManager.php +328 -0
  23. app/code/community/Bpost/ShippingManager/Test/Block/Onepage/Shipping/Method/Available.php +38 -0
  24. app/code/community/Bpost/ShippingManager/Test/Block/Onepage/Shipping/Method/Available/fixtures/bpostModuleConfig.yaml +11 -0
  25. app/code/community/Bpost/ShippingManager/Test/Controller/ApiController.php +89 -0
  26. app/code/community/Bpost/ShippingManager/Test/Controller/PostbackController.php +65 -0
  27. app/code/community/Bpost/ShippingManager/Test/Controller/PostbackController/fixtures/startformAction.yaml +8 -0
  28. app/code/community/Bpost/ShippingManager/Test/Helper/Data.php +269 -0
  29. app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/allowedShippingMethodsIsNotSet.yaml +2 -0
  30. app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/bpostModuleConfig.yaml +11 -0
  31. app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/getApiUriReturnsConcatOfApiuriAndAccountid.yaml +3 -0
  32. app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/getApiUriReturnsEmptyStringWhenAccountIdIsNotSet.yaml +2 -0
  33. app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/getApiUriReturnsEmptyStringWhenApiUriIsNotSet.yaml +3 -0
  34. app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/onlyOneAllowedShippingMethodsIsSet.yaml +2 -0
  35. app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/rateTableIsEmpty.yaml +2 -0
  36. app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/rateTableIsInvalidJasonStringRaisesException.yaml +2 -0
  37. app/code/community/Bpost/ShippingManager/Test/Model/Api.php +421 -0
  38. app/code/community/Bpost/ShippingManager/Test/Model/Api/fixtures/bpostModuleConfig.yaml +12 -0
  39. app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Bpost.php +256 -0
  40. app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Bpost/fixtures/bpostModuleConfig.yaml +12 -0
  41. app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Bpost/fixtures/carrierDeactivated.yaml +11 -0
  42. app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Shippingmethod/Abstract.php +322 -0
  43. app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Shippingmethod/Abstract/fixtures/bpostModuleConfig.yaml +11 -0
  44. app/code/community/Bpost/ShippingManager/Test/Model/Carrier/System/Config/Source/Method.php +170 -0
  45. app/code/community/Bpost/ShippingManager/Test/Model/Carrier/System/Config/Source/Method/fixtures/bpostModuleConfig.yaml +11 -0
  46. app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager.php +536 -0
  47. app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/accountIdNotFilledIn.yaml +4 -0
  48. app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/bpostModuleConfig.yaml +11 -0
  49. app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/bpostOrderSetup.yaml +47 -0
  50. app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/carrierDeactivated.yaml +11 -0
  51. app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/passphraseNotFilledIn.yaml +4 -0
  52. app/code/community/Bpost/ShippingManager/controllers/ApiController.php +52 -0
  53. app/code/community/Bpost/ShippingManager/controllers/PostbackController.php +83 -0
  54. app/code/community/Bpost/ShippingManager/etc/adminhtml.xml +10 -0
  55. app/code/community/Bpost/ShippingManager/etc/api.xml +14 -0
  56. app/code/community/Bpost/ShippingManager/etc/config.xml +159 -0
  57. app/code/community/Bpost/ShippingManager/etc/system.xml +153 -0
  58. app/code/community/Bpost/ShippingManager/etc/wsdl.xml +23 -0
  59. app/code/community/Bpost/ShippingManager/sql/bpost_shippingmanager_setup/mysql4-install-0.1.0.php +23 -0
  60. app/design/adminhtml/default/default/layout/bpost_shippingmanager.xml +48 -0
  61. app/design/adminhtml/default/default/template/bpost/shippingmanager/dynamic/jsforordershipment.phtml +10 -0
  62. app/design/frontend/base/default/layout/bpost_shippingmanager.xml +102 -0
  63. app/design/frontend/base/default/template/bpost/shippingmanager/cancel.phtml +5 -0
  64. app/design/frontend/base/default/template/bpost/shippingmanager/confirm.phtml +15 -0
  65. app/design/frontend/base/default/template/bpost/shippingmanager/createtrackingcode.phtml +1 -0
  66. app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforcheckoutcart.phtml +16 -0
  67. app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforgreybox.phtml +8 -0
  68. app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforonepagecheckout.phtml +20 -0
  69. app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforonestepcheckout.phtml +24 -0
  70. app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforordershipment.phtml +6 -0
  71. app/design/frontend/base/default/template/bpost/shippingmanager/error.phtml +5 -0
  72. app/design/frontend/base/default/template/bpost/shippingmanager/platformstub.phtml +37 -0
  73. app/design/frontend/base/default/template/bpost/shippingmanager/startform.phtml +32 -0
  74. app/etc/modules/Bpost_ShippingManager.xml +11 -0
  75. app/locale/en_US/Bpost_ShippingManager.csv +13 -0
  76. app/locale/fr_FR/Bpost_ShippingManager.csv +13 -0
  77. app/locale/nl_NL/Bpost_ShippingManager.csv +13 -0
  78. package.xml +18 -0
  79. skin/adminhtml/base/default/css/bpost/shippingmanager/bpost.css +6 -0
  80. skin/adminhtml/base/default/js/bpost/shippingmanager/base.js +107 -0
  81. skin/adminhtml/base/default/js/bpost/shippingmanager/sales_order_shipment_view.js +25 -0
  82. skin/frontend/base/default/greybox/AJS.js +514 -0
  83. skin/frontend/base/default/greybox/AJS_fx.js +138 -0
  84. skin/frontend/base/default/greybox/content-bottom-bg.gif +0 -0
  85. skin/frontend/base/default/greybox/custom-integration-onestepcheckout.js +133 -0
  86. skin/frontend/base/default/greybox/g_close.gif +0 -0
  87. skin/frontend/base/default/greybox/gb_scripts.js +443 -0
  88. skin/frontend/base/default/greybox/gb_styles.css +153 -0
  89. skin/frontend/base/default/greybox/gb_styles_orig.css +148 -0
  90. skin/frontend/base/default/greybox/header_bg.gif +0 -0
  91. skin/frontend/base/default/greybox/indicator.gif +0 -0
  92. skin/frontend/base/default/greybox/loader_frame.html +104 -0
  93. skin/frontend/base/default/greybox/next.gif +0 -0
  94. skin/frontend/base/default/greybox/prev.gif +0 -0
  95. skin/frontend/base/default/greybox/w_close.gif +0 -0
  96. skin/frontend/base/default/greybox/w_close1.gif +0 -0
  97. skin/frontend/base/default/images/bpost/shippingmanager/logo_bpost.jpg +0 -0
  98. skin/frontend/base/default/images/bpost/shippingmanager/track_and_trace.jpg +0 -0
  99. skin/frontend/base/default/js/bpost/shippingmanager/bpost_shippingmanager_base.js +255 -0
  100. skin/frontend/base/default/js/bpost/shippingmanager/checkout_cart.js +56 -0
  101. skin/frontend/base/default/js/bpost/shippingmanager/onepage_checkout.js +14 -0
  102. skin/frontend/base/default/js/bpost/shippingmanager/onestep_checkout.js +110 -0
app/code/community/Bpost/ShippingManager/Block/Abstract.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Block_Abstract extends Mage_Core_Block_Template {
10
+
11
+ protected $_shmHelper;
12
+ /**
13
+ * @codeCoverageIgnore
14
+ */
15
+ protected function shmHelper()
16
+ {
17
+
18
+ if (is_null($this->_shmHelper)) {
19
+ $this->_shmHelper = Mage::helper('shippingmanager');
20
+ }
21
+ return $this->_shmHelper;
22
+
23
+ }
24
+
25
+ }
app/code/community/Bpost/ShippingManager/Block/Adminhtml/Javascript.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_ShippingManager_Block_Adminhtml_Javascript
3
+ extends Mage_Adminhtml_Block_Sales_Order_Abstract{
4
+
5
+ public function getOrder()
6
+ {
7
+ try{
8
+ return parent::getOrder();
9
+ } catch (Exception $e) {
10
+ if(Mage::registry('current_shipment')){
11
+ $shipment = Mage::registry('current_shipment');
12
+ $order = Mage::getModel('sales/order')->load($shipment->getOrderId());
13
+ return $order;
14
+ }
15
+ if(Mage::registry('current_invoice')){
16
+ $invoice = Mage::registry('current_invoice');
17
+ $order = Mage::getModel('sales/order')->load($invoice->getOrderId());
18
+ return $order;
19
+ }
20
+ }
21
+ }
22
+
23
+ }
app/code/community/Bpost/ShippingManager/Block/Confirm.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Bpost_ShippingManager
5
+ *
6
+ * @package Bpost_ShippingManager
7
+ * @copyright Copyright (c) 2011 bpost
8
+ * @author Phpro (http://www.phpro.be)
9
+ */
10
+ class Bpost_ShippingManager_Block_Confirm extends Bpost_ShippingManager_Block_Abstract {
11
+
12
+ /**
13
+ * This method captures the bpost ShippingMethod from the postback,
14
+ * formats it to a known Magento code
15
+ *
16
+ * @return string magento_code
17
+ */
18
+ public function deliveryMethod()
19
+ {
20
+ $shippingManager = Mage::getSingleton('shippingmanager/shippingManager');
21
+ return $shippingManager->getDeliveryMethodMagentoCode();
22
+ }
23
+
24
+ public function ShippingAddress(){
25
+ $shippingManager = Mage::getSingleton('shippingmanager/shippingManager');
26
+ return $shippingManager->getShippingAddress();
27
+ }
28
+ }
app/code/community/Bpost/ShippingManager/Block/Javascript.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Block_Javascript extends Bpost_ShippingManager_Block_Abstract {
10
+
11
+
12
+ public function shmEnabled()
13
+ {
14
+ return Mage::getSingleton('shippingmanager/shippingManager')->enabled();
15
+ }
16
+
17
+ public function isOneStepCheckoutConfigurationOk()
18
+ {
19
+ return Mage::getStoreConfig('onestepcheckout/ajax_update/enable_ajax_save_billing') == 1 &&
20
+ in_array("country", explode(",", Mage::getStoreConfig('onestepcheckout/ajax_update/ajax_save_billing_fields'))) &&
21
+ // Mage::getStoreConfig('onestepcheckout/general/enable_different_shipping') == 1 &&
22
+ Mage::getStoreConfig('onestepcheckout/general/hide_shipping_method') == 0 &&
23
+ Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links') == 1;
24
+ }
25
+
26
+ /**
27
+ * Returns the path to the bpost logo
28
+ * @codeCoverageIgnore
29
+ * @return string BpostLogoUrl
30
+ */
31
+ public function getBpostLogoUrl()
32
+ {
33
+ return $this->getSkinUrl($this->shmHelper()->getBpostLogoPath());
34
+ }
35
+
36
+ /**
37
+ * @codeCoverageIgnore
38
+ *
39
+ */
40
+ public function getBpostLogoHeight()
41
+ {
42
+ return $this->shmHelper()->getBpostLogoHeight();
43
+ }
44
+
45
+ /**
46
+ *
47
+ * @codeCoverageIgnore
48
+ */
49
+ public function getBpostLogoText()
50
+ {
51
+ return $this->__("Open bpost shippingmanager");
52
+ }
53
+ }
app/code/community/Bpost/ShippingManager/Block/Onepage/Shipping/Method/Available.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Block_Onepage_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available
10
+ {
11
+
12
+ protected $_shmHelper;
13
+
14
+ /**
15
+ * @codeCoverageIgnore
16
+ */
17
+ protected function shmHelper()
18
+ {
19
+ if (is_null($this->_shmHelper)) {
20
+ $this->_shmHelper = Mage::helper('shippingmanager');
21
+ }
22
+ return $this->_shmHelper;
23
+ }
24
+
25
+ /*
26
+ * When the carrier is bpost, a link is return to open the bpost platform.
27
+ * The name of the carrier is replaced by an image
28
+ * @return string carriername
29
+ */
30
+ public function getCarrierName($carrierCode)
31
+ {
32
+
33
+ if($carrierCode == "bpost"){
34
+ return '<a id="start_bpost_shippingmanager" href="javascript:shm.show();" title="'. $this->__("Open bpost shippingmanager") .'" ><img id="bpost_logo" alt="'. $this->__("Open bpost shippingmanager") .'" src="' . $this->getSkinUrl($this->shmHelper()->getBpostLogoPath()) . '" /></a>';
35
+ }
36
+
37
+ if ($name = Mage::getStoreConfig('carriers/'.$carrierCode.'/title')) {
38
+ return $name;
39
+ }
40
+ return $carrierCode;
41
+ }
42
+
43
+ }
app/code/community/Bpost/ShippingManager/Block/Platformstub.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Block_Platformstub
10
+ extends Mage_Checkout_Block_Onepage_Shipping_Method_Available {
11
+
12
+ protected $_shmHelper;
13
+
14
+ protected function shmHelper()
15
+ {
16
+
17
+ if (is_null($this->_shmHelper)) {
18
+ $this->_shmHelper = Mage::helper('shippingmanager');
19
+ }
20
+ return $this->_shmHelper;
21
+
22
+ }
23
+
24
+ public function getDeliveryMethodOverrides()
25
+ {
26
+ $shippingManager = Mage::getSingleton('shippingmanager/shippingManager');
27
+ return $shippingManager->getDeliveryMethodOverrides($this->getShippingRates());
28
+ }
29
+
30
+ public function getFieldsForForm()
31
+ {
32
+ $fields = array(
33
+ "customerFirstName" => null,
34
+ "customerLastName" => null,
35
+ "customerStreet" => null,
36
+ "customerStreetNumber" => null,
37
+ "customerCity" => null,
38
+ "customerPostalCode" => null,
39
+ "customerCountry" => null,
40
+ "customerPhoneNumber" => null,
41
+ "deliveryMethodPriceTotal" => null,
42
+ "deliveryMethod" => null
43
+ );
44
+ foreach($fields as $fieldName => $fieldValue){
45
+ if (isset($_POST[$fieldName])){
46
+ $fields[$fieldName] = $_POST[$fieldName];
47
+ }
48
+ }
49
+ return $fields;
50
+ }
51
+
52
+
53
+ }
app/code/community/Bpost/ShippingManager/Block/Startform.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Block_Startform
10
+ extends Mage_Checkout_Block_Onepage_Shipping_Method_Available {
11
+
12
+ protected $_shmHelper;
13
+
14
+ /**
15
+ * @codeCoverageIgnore
16
+ */
17
+ protected function shmHelper()
18
+ {
19
+
20
+ if (is_null($this->_shmHelper)) {
21
+ $this->_shmHelper = Mage::helper('shippingmanager');
22
+ }
23
+ return $this->_shmHelper;
24
+
25
+ }
26
+
27
+ /**
28
+ *
29
+ * This method fetches all the products in the magento cart and transforms them in an array of bpost orderlines.
30
+ * This is a string containing productdescription|quantity
31
+ * The productsnames are formatted as sku - name of product
32
+ *
33
+ * @return array $orderLines
34
+ */
35
+ public function getOrderLines()
36
+ {
37
+ $orderLines = array();
38
+ foreach ($this->_quote->getAllItems() as $item) {
39
+ if($item->getParentItemId() == null){
40
+ $orderLines[] = $item->getSku() . ' - ' . $item->getName() . '|' . $item->getQty();
41
+ }
42
+ }
43
+ $this->shmHelper()->log("orderlines:\n" . print_r($orderLines, true), __FILE__, __LINE__);
44
+ return $orderLines;
45
+ }
46
+
47
+ /**
48
+ *
49
+ * This returns the order reference used to make the link between the bpost order and the magento order
50
+ *
51
+ * @returns string $reservedOrderId
52
+ */
53
+ public function orderReference()
54
+ {
55
+ if($this->_quote->getReservedOrderId() == ""){
56
+ $this->shmHelper()->log('reserveOrderId does not exists, creating....', __FILE__, __LINE__);
57
+ $this->_quote->reserveOrderId();
58
+ $this->_quote->save();
59
+
60
+ }
61
+ $reservedOrderId = $this->_quote->getReservedOrderId();
62
+ $this->shmHelper()->log("reserveOrderId is: [$reservedOrderId]", __FILE__, __LINE__);
63
+ return $reservedOrderId;
64
+ }
65
+
66
+ /**
67
+ *
68
+ * gets the url to the bpost module
69
+ *
70
+ * @codeCoverageIgnore
71
+ * @return string frontEndUrl
72
+ */
73
+ public function getFrontendUrl()
74
+ {
75
+ return $this->shmHelper()->getFrontendUrl();
76
+ }
77
+
78
+ /**
79
+ *
80
+ * gets the data for the fields
81
+ *
82
+ * @return array $fields
83
+ */
84
+ public function getFieldsForForm()
85
+ {
86
+ $shippingManager = Mage::getSingleton('shippingmanager/shippingManager');
87
+ $shippingaddress = $this->getAddress();
88
+ $deliveryMethodOverrides = $shippingManager->getDeliveryMethodOverrides($this->getShippingRates());
89
+ $languageCode = explode('_',Mage::app()->getLocale()->getLocaleCode());
90
+ $totals = $this->_quote->getTotals();
91
+
92
+ $weight = $shippingaddress->getWeight();
93
+
94
+ $checksumParameters = $shippingManager->getChecksumParameters("START", $this->orderReference(), $shippingaddress->getCountryId(), $deliveryMethodOverrides);
95
+ $fields = $checksumParameters;
96
+ $fields['lang'] = strtoupper($languageCode[0]);
97
+ $fields['orderLine'] = $this->getOrderLines();
98
+ //$fields['orderWeight'] = $weight * 100;
99
+ $fields['orderTotalPrice'] = $totals['subtotal']->getValue() * 100;
100
+ $fields['customerFirstName'] = $shippingaddress->getFirstname();
101
+ $fields['customerLastName'] = $shippingaddress->getLastname();
102
+ if (Mage::getStoreConfigFlag('checkout/betteraddress/onepage_checkout_enabled')) {
103
+ $fields['customerStreet'] = $shippingaddress->getStreet(1);
104
+ $fields['customerStreetNumber'] = $shippingaddress->getStreet(2);
105
+ $fields['customerBox'] = $shippingaddress->getStreet(3);
106
+ }
107
+ $fields['customerCity'] = $shippingaddress->getCity();
108
+ $fields['customerPostalCode'] = $shippingaddress->getPostcode();
109
+ $fields['customerEmail'] = $shippingaddress->getEmail();
110
+ $fields['customerPhoneNumber'] = $shippingaddress->getTelephone();
111
+ $this->shmHelper()->log("formfields:\n" . print_r($fields, true), __FILE__, __LINE__);
112
+ return $fields;
113
+ }
114
+
115
+ }
app/code/community/Bpost/ShippingManager/Block/Tracking.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Block_Tracking extends Bpost_ShippingManager_Block_Abstract {
10
+
11
+ }
app/code/community/Bpost/ShippingManager/Helper/Data.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Helper_Data
10
+ extends Mage_Core_Helper_Abstract{
11
+
12
+ /**
13
+ * gets active status from carrier configuration
14
+ * @return boolean active
15
+ */
16
+ public function getActiveStatus()
17
+ {
18
+ return Mage::getStoreConfig('carriers/bpost/active');
19
+ }
20
+
21
+ /**
22
+ * gets account_id from carrier configuration
23
+ * @return string account_id
24
+ */
25
+ public function getAccountId()
26
+ {
27
+ return Mage::getStoreConfig('carriers/bpost/account_id');
28
+ }
29
+
30
+ /**
31
+ * gets passphrase from carrier configuration
32
+ * @return string passphrase
33
+ */
34
+ public function getPassphrase()
35
+ {
36
+ return Mage::getStoreConfig('carriers/bpost/passphrase');
37
+ }
38
+
39
+ /**
40
+ * gets frontend from carrier configuration
41
+ * @return string frontend_url
42
+ */
43
+ public function getFrontendUrl()
44
+ {
45
+ return Mage::getStoreConfig('carriers/bpost/frontend_url');
46
+ }
47
+
48
+ /**
49
+ * gets uri to bpost shippingmanager api from carrier configuration
50
+ * @return string frontend_url
51
+ */
52
+ public function getApiUri()
53
+ {
54
+ if ($this->getAccountId() == "") {
55
+ return "";
56
+ }
57
+
58
+ $apiUri = Mage::getStoreConfig('carriers/bpost/api_uri');
59
+
60
+ if ($apiUri == "") {
61
+ return $apiUri;
62
+ }
63
+
64
+ if ($apiUri[strlen($apiUri)-1] != "/") {
65
+ $apiUri .= "/";
66
+ }
67
+
68
+ return $apiUri . $this->getAccountId() . "/";
69
+
70
+ }
71
+ /**
72
+ * returns proxyhost
73
+ * @return string ProxyHost
74
+ */
75
+ public function getProxyHost()
76
+ {
77
+ return Mage::getStoreConfig('carriers/bpost/proxy_host');
78
+ }
79
+
80
+ /**
81
+ * returns proxyhost
82
+ * @return string ProxyHost
83
+ */
84
+ public function getProxyPort()
85
+ {
86
+ return Mage::getStoreConfig('carriers/bpost/proxy_port');
87
+ }
88
+
89
+ /**
90
+ * gets free_delivery_when_cart_value_bigger_then from bpost configuration
91
+ * @return string free_delivery_when_cart_value_bigger_then
92
+ */
93
+ public function getFreeDeliveryWhenCartValueBiggerThen()
94
+ {
95
+ return Mage::getStoreConfig('carriers/bpost/free_delivery_when_cart_value_bigger_then');
96
+ }
97
+
98
+ /**
99
+ * returns path to image of the bpost logo
100
+ * @return string path
101
+ */
102
+ public function getBpostLogoPath()
103
+ {
104
+ return 'images/bpost/shippingmanager/logo_bpost.jpg';
105
+ }
106
+
107
+ /**
108
+ *
109
+ * returns height of bpost logo
110
+ *
111
+ * @return integer height
112
+ */
113
+
114
+ public function getBpostLogoHeight(){
115
+ return 200;
116
+ }
117
+
118
+ /**
119
+ * gets rate_table from bpost configuration
120
+ * @return string rate_table
121
+ */
122
+ public function getRateTable($deliverymethodIdentifier = null)
123
+ {
124
+
125
+ $rateTable = json_decode(Mage::getStoreConfig('carriers/bpost/rate_table'), true);
126
+
127
+ if (is_null($rateTable)) {
128
+ if (Mage::getStoreConfig('carriers/bpost/rate_table') == "") {
129
+ return null;
130
+ }
131
+ throw new Exception('Bpost: Configuration parameter "RateTable" is not the correct format. Check the configuration page or manual for correct syntax.');
132
+ }
133
+
134
+ if (is_null($deliverymethodIdentifier)) {
135
+ return $rateTable;
136
+ }
137
+
138
+ if (array_key_exists($deliverymethodIdentifier, $rateTable)) {
139
+ return $rateTable[$deliverymethodIdentifier];
140
+ }
141
+
142
+ return null;
143
+ }
144
+
145
+ /**
146
+ * gets allowed shipping methods
147
+ * @return string rate_table
148
+ */
149
+ public function getEnabledShippingMethods()
150
+ {
151
+ $allowedMethods = Mage::getStoreConfig('carriers/bpost/allowed_methods');
152
+ if($allowedMethods == ""){
153
+ return array();
154
+ }
155
+ return explode(',', $allowedMethods);
156
+ }
157
+
158
+ public function getTitle()
159
+ {
160
+ return Mage::getStoreConfig('carriers/bpost/title');
161
+ }
162
+
163
+ /**
164
+ * Log messages when in developer mode
165
+ * @codeCoverageIgnore
166
+ *
167
+ */
168
+ public function log($message, $file, $lineNumber, $loglevel= Zend_Log::DEBUG)
169
+ {
170
+ Mage::Log("Bpost Shm:\tfile: $file\tline: $lineNumber\tmessage:$message", $loglevel);
171
+ }
172
+ }
173
+
app/code/community/Bpost/ShippingManager/Model/Api.php ADDED
@@ -0,0 +1,330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_Api extends Mage_Core_Model_Abstract
10
+ {
11
+ protected $_shmHelper;
12
+
13
+ private $apiUri;
14
+ private $proxyHost;
15
+ private $proxyPort;
16
+ private $httpClient;
17
+
18
+ /**
19
+ * @codeCoverageIgnore
20
+ */
21
+ protected function shmHelper()
22
+ {
23
+ if (is_null($this->_shmHelper)) {
24
+ $this->_shmHelper = Mage::helper('shippingmanager');
25
+ }
26
+ return $this->_shmHelper;
27
+
28
+ }
29
+
30
+ /**
31
+ * @codeCoverageIgnore
32
+ */
33
+ public function _construct()
34
+ {
35
+ parent::_construct();
36
+ $this->apiUri = $this->shmHelper()->getApiUri();
37
+ $this->proxyHost = $this->shmHelper()->getProxyHost();
38
+ $this->proxyPort = $this->shmHelper()->getProxyPort();
39
+ $this->httpClient = new Zend_Http_Client(null, $this->getProxyConfig());
40
+ }
41
+
42
+ /**
43
+ *
44
+ * Set a http client
45
+ * @codeCoverageIgnore
46
+ * @param Zend_Http_Client $newClient
47
+ */
48
+ public function setHttpClient(Zend_Http_Client $newClient)
49
+ {
50
+ $this->httpClient = $newClient;
51
+ }
52
+
53
+ /**
54
+ * This function assembles the proxy config for the http request
55
+ * @return array proxySettings
56
+ */
57
+ public function getProxyConfig()
58
+ {
59
+ $proxyHost = $this->proxyHost;
60
+
61
+ // Only use the custom proxy params if they are available
62
+ if( empty( $proxyHost ) ) {return array();}
63
+
64
+ // Set the configuration parameters
65
+ return array(
66
+ 'adapter' => 'Zend_Http_Client_Adapter_Proxy',
67
+ 'proxy_host' => $proxyHost,
68
+ 'proxy_port' => $this->proxyPort
69
+ );
70
+ }
71
+
72
+ /**
73
+ *
74
+ * returns the apiuri + requestname
75
+ * @param string $requestName
76
+ */
77
+ public function getHttpRequestUri($requestName) {
78
+ return $this->apiUri . $requestName;
79
+ }
80
+
81
+ /**
82
+ * This function sends $requestXml as a http_request to $request_path
83
+ * @param string $requestName, string $requestXml
84
+ * @return array string code, simpleXml data
85
+ */
86
+ public function request($requestType, $requestName, $requestXml, $requestHeaders)
87
+ {
88
+ $response = new Zend_Http_Response(403, array());
89
+
90
+ // get the response object
91
+ try {
92
+ $uri = $this->getHttpRequestUri($requestName);
93
+ $client = $this->httpClient;
94
+ $client->setAuth($this->shmHelper()->getAccountId(), $this->shmHelper()->getPassphrase());
95
+ $client->setHeaders($requestHeaders);
96
+ if(!is_null($requestXml)){
97
+ $client->setRawData($requestXml);
98
+ }
99
+ $client->setUri($uri);
100
+ $response = $client->request($requestType);
101
+ } catch (Exception $e) {
102
+ $this->shmHelper()->log('Zend_Http_Client Error: Could not connect to service at: [' . $this->getHttpRequestUri($requestName) . '] with message: ' . $e->getMessage(), __FILE__, __LINE__, Zend_Log::ERR);
103
+ }
104
+
105
+ if($response->isError()) {
106
+ $this->shmHelper()->log('Response error: Status: '. $response->getStatus() .' - Message:' . $response->getMessage(), __FILE__, __LINE__, Zend_Log::ERR);
107
+ throw new Exception($response->getMessage(), 20);
108
+ }
109
+
110
+ // Process the xml
111
+ return $response;
112
+
113
+ }
114
+
115
+ /**
116
+ *
117
+ * Api is enabled when api url is set
118
+ *
119
+ * @return boolean enabled
120
+ */
121
+ public function enabled() {
122
+ if($this->apiUri == '') {
123
+ return false;
124
+ }
125
+
126
+ return true;
127
+ }
128
+
129
+ /**
130
+ *
131
+ * Confirms order to bpost
132
+ * @param sales/order $order
133
+ */
134
+ public function statusTo(Mage_Sales_Model_Order $order, $status='OPEN')
135
+ {
136
+ if ($order->getShippingCarrier()->getCarrierCode() != 'bpost') {
137
+ return true;
138
+ }
139
+ if (!$this->enabled()) {
140
+ return true;
141
+ }
142
+
143
+ $xml = <<<XML
144
+ <?xml version="1.0" encoding="UTF-8"?>
145
+ <orderStatusMap xmlns="http://schema.post.be/shm/deepintegration/v1/">
146
+ <entry>
147
+ <orderReference>{$order->getRealOrderId()}</orderReference>
148
+ <status>$status</status>
149
+ </entry>
150
+ </orderStatusMap>
151
+ XML;
152
+ $requestHeaders = array(
153
+ 'Content-type' => 'application/vnd.bpost.shm-order-status-v1+XML',
154
+ 'X-HTTP-Method-Override'=> 'PATCH'
155
+ );
156
+ try{
157
+ $response = $this->request('PUT', 'orders/status', $xml, $requestHeaders);
158
+ if($response->isSuccessful()) {
159
+ return true;
160
+ }
161
+ } catch (Exception $e){
162
+ return false;
163
+ }
164
+
165
+ return false;
166
+ }
167
+
168
+ /**
169
+ *
170
+ * returns the orderRefLabelAmountMap xml
171
+ * @param string $orderReference
172
+ */
173
+ public function getOrderRefLabelAmountMapXml($orderReference)
174
+ {
175
+ $OrderRefLabelAmountMapXml = <<<XML
176
+ <?xml version="1.0" encoding="UTF-8"?>
177
+ <orderRefLabelAmountMap xmlns="http://schema.post.be/shm/deepintegration/v1/">
178
+ <entry>
179
+ <orderReference>$orderReference</orderReference>
180
+ <labelAmount>1</labelAmount>
181
+ <withRetour>false</withRetour>
182
+ <returnLabels>1</returnLabels>
183
+ </entry>
184
+ </orderRefLabelAmountMap>
185
+ XML;
186
+ return $OrderRefLabelAmountMapXml;
187
+ }
188
+
189
+ /**
190
+ *
191
+ * Fetches barcode from the orderRefBarcodeMap xml
192
+ * @param xmlstring $orderRefBarcodeMapXml
193
+ */
194
+ public function getBarcodeFromOrderRefBarcodeMapXml($orderRefBarcodeMapXml) {
195
+ $barcode = "";
196
+ try{
197
+ $orderRefBarcodeMap = $this->parseXml($orderRefBarcodeMapXml);
198
+ foreach ($orderRefBarcodeMap->entry as $entry) {
199
+ $barcode = (string) $entry->barcode;
200
+ }
201
+ } catch (Exception $e){
202
+
203
+ }
204
+ return $barcode;
205
+ }
206
+
207
+ /**
208
+ *
209
+ * This method makes request to bpost platform and returns OrderRefLabelAmountMap xml
210
+ * @param string $orderReference
211
+ * @return xmlstring $OrderRefLabelAmountMap
212
+ */
213
+ public function fetchOrderRefBarcodeMapXml($orderReference)
214
+ {
215
+ $OrderRefLabelAmountMapXml = $this->getOrderRefLabelAmountMapXml($orderReference);
216
+ $requestHeaders = array('Content-type' => 'application/vnd.bpost.shm-label-v1+XML');
217
+ $response = $this->request('POST', 'labels', $OrderRefLabelAmountMapXml, $requestHeaders);
218
+
219
+ if($response->isSuccessful()) {
220
+ $this->shmHelper()->log('fetchOrderRefBarcodeMapXml ResponseBody:\n' . $response->getBody(), __FILE__, __LINE__, Zend_Log::DEBUG);
221
+ return $response->getBody();
222
+ }
223
+ }
224
+
225
+ /**
226
+ *
227
+ * Request OrderRefLabelAmountMap from bpost platform and extract barcode from the orderRefBarcodeMap xml
228
+ * @param string $orderReference
229
+ * @return string $barcode
230
+ */
231
+ public function createBarCodeForOrderReference($orderReference){
232
+ $orderRefBarcodeMapXml = $this->fetchOrderRefBarcodeMapXml($orderReference);
233
+ return $this->getBarcodeFromOrderRefBarcodeMapXml($orderRefBarcodeMapXml);
234
+ }
235
+
236
+ /**
237
+ *
238
+ * This method makes a http call to the bpost platform to retrieve the pdf content.
239
+ * @param string $type
240
+ * @param string $orderReference
241
+ * @return string $responsebody
242
+ * @throws Exception
243
+ */
244
+ public function fetchPdfXml($type ,$orderReference)
245
+ {
246
+ $requestHeaders = array('Content-type' => 'Content-type: application/vnd.bpost.shm-pdf-v1+XML');
247
+ $response = $this->request('GET', $type . '/' . $orderReference . '/pdf', null, $requestHeaders);
248
+
249
+ if($response->isSuccessful()) {
250
+ $this->shmHelper()->log('fetchPdfXml ResponseBody:\n' . $response->getBody(), __FILE__, __LINE__, Zend_Log::DEBUG);
251
+ return $response->getBody();
252
+ }
253
+ }
254
+
255
+ /**
256
+ *
257
+ * This method parses the xml and extracts the pdf content part
258
+ * @param xmlstring $pdfXml
259
+ * @return base64_encoded string $pdfContent
260
+ * @throws Exception
261
+ */
262
+ public function getPdfContentFromPdfXml($pdfXml)
263
+ {
264
+ $pdf = null;
265
+ try{
266
+ $pdfContent = $this->parseXml($pdfXml);
267
+ $pdf = (string) $pdfContent;
268
+ } catch(Exception $e){
269
+ }
270
+ return $pdf;
271
+ }
272
+
273
+ /**
274
+ *
275
+ * Returns the base_64_decoded pdf content
276
+ * @param string $orderReference
277
+ * @return string $pdfcontent
278
+ */
279
+ public function getPdfContentForOrderReference($orderReference){
280
+ return $this->getPdfContentFor("orders", $orderReference);
281
+ }
282
+
283
+ /**
284
+ *
285
+ * Returns the base_64_decoded pdf content for the given barcode
286
+ * @param string $barcode
287
+ * @return string $pdfcontent
288
+ */
289
+ public function getPdfContentForBarcode($barcode)
290
+ {
291
+ return $this->getPdfContentFor("labels", $barcode);
292
+ }
293
+
294
+ /**
295
+ *
296
+ * Returns the base_64_decoded pdf content
297
+ * @param string $type
298
+ * @param string $reference
299
+ */
300
+ private function getPdfContentFor($type, $reference){
301
+ try {
302
+ $pdfXml = $this->fetchPdfXml($type, $reference);
303
+ $pdfContent = $this->getPdfContentFromPdfXml($pdfXml);
304
+ return base64_decode($pdfContent);
305
+ } catch (Exception $e){
306
+ return null;
307
+ }
308
+ }
309
+
310
+ /**
311
+ *
312
+ * This methods tries to create a simplexml object from the given xmlstring
313
+ * @param stringxml $xml
314
+ * @throws Exception
315
+ */
316
+ private function parseXml($xmlString){
317
+ libxml_use_internal_errors(true);
318
+ $xmlObject = simplexml_load_string($xmlString);
319
+ if (!$xmlObject) {
320
+ $this->shmHelper()->log('Unable to parse xml. \n' . $xmlString, __FILE__, __LINE__, Zend_Log::ERR);
321
+ $this->shmHelper()->log('************ Errors ***************' , __FILE__, __LINE__, Zend_Log::ERR);
322
+ foreach(libxml_get_errors() as $error) {
323
+ $this->shmHelper()->log($error->message , __FILE__, __LINE__, Zend_Log::ERR);
324
+ }
325
+ $this->shmHelper()->log('***********************************' , __FILE__, __LINE__, Zend_Log::ERR);
326
+ throw new Exception("Unable to parse xml", 10);
327
+ }
328
+ return $xmlObject;
329
+ }
330
+ }
app/code/community/Bpost/ShippingManager/Model/Carrier/Bpost.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_Carrier_Bpost
10
+ extends Mage_Shipping_Model_Carrier_Abstract
11
+ implements Mage_Shipping_Model_Carrier_Interface
12
+ {
13
+ /**
14
+ * unique internal shipping method identifier
15
+ *
16
+ * @var string [a-z0-9_]
17
+ */
18
+ protected $_code = 'bpost';
19
+ protected $_shmHelper;
20
+
21
+ /**
22
+ * @codeCoverageIgnore
23
+ */
24
+ protected function shmHelper()
25
+ {
26
+
27
+ if (is_null($this->_shmHelper)) {
28
+ $this->_shmHelper = Mage::helper('shippingmanager');
29
+ }
30
+ return $this->_shmHelper;
31
+
32
+ }
33
+ /**
34
+ * Collect rates for this shipping method based on information in $request
35
+ *
36
+ * @param Mage_Shipping_Model_Rate_Request $data
37
+ * @return Mage_Shipping_Model_Rate_Result
38
+ */
39
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
40
+ {
41
+ // when the configuration is not active, do not show the shipping method
42
+ if (!Mage::getSingleton('shippingmanager/shippingManager')->enabled()) {
43
+ return false;
44
+ }
45
+
46
+ $quote = Mage::getSingleton('checkout/cart')->getQuote();
47
+ // When we are in multishipping address mode, bpost is not offered
48
+ if($quote->getData('is_multi_shipping')){
49
+ return false;
50
+ }
51
+
52
+ // The bpost platform only supports amounts in euro
53
+ if($quote->getQuoteCurrencyCode() != 'EUR'){
54
+ return false;
55
+ }
56
+
57
+ $allowedShippingMethods = $this->getAllowedMethods();
58
+ // There re no allowed shipping methods, so no need to process them
59
+ if (count($allowedShippingMethods) < 1) {
60
+ return false;
61
+ }
62
+
63
+ $result = Mage::getModel('shipping/rate_result');
64
+
65
+ foreach ($this->getAllowedMethods() as $shippingMethodIdenifier => $shippingMethodTitle) {
66
+ // Try to load the shippingmethod class
67
+ try {
68
+ $shippingMethodClass = 'shippingmanager/carrier_shippingmethod_' . $shippingMethodIdenifier;
69
+ $shippingMethod = Mage::getModel($shippingMethodClass);
70
+ } catch (Exception $e) {
71
+ // @codeCoverageIgnoreStart
72
+ // loading failed, write error in log and continue processing other methods
73
+ $this->shmHelper()->log("Could not load class [$shippingMethodClass] for shipping method [$shippingMethodTitle].", __FILE__, __LINE__);
74
+ continue;
75
+ // @codeCoverageIgnoreEnd
76
+ }
77
+
78
+ if($shippingMethod == ""){
79
+ continue;
80
+ }
81
+
82
+ $method = Mage::getModel('shipping/rate_result_method');
83
+
84
+ // Set the carrier title / code
85
+ $method->setCarrier($this->_code);
86
+ $method->setCarrierTitle($this->shmHelper()->getTitle());
87
+
88
+ // Set the shippingmethod name and title
89
+ $method->setMethod($shippingMethodIdenifier);
90
+ $method->setMethodTitle($shippingMethodTitle);
91
+
92
+ // Let the shippingmethod itself calculate it's shipping cost
93
+ $price = $shippingMethod->getCost($request);
94
+ $method->setPrice($price);
95
+ $method->setCost($price);
96
+
97
+ $result->append($method);
98
+
99
+ }
100
+
101
+ return $result;
102
+ }
103
+
104
+ /**
105
+ *
106
+ * Returns all allowed methods which are set in the config
107
+ *
108
+ * @return array $allowedShippingMethods
109
+ * @codeCoverageIgnore
110
+ */
111
+ public function getAllowedMethods()
112
+ {
113
+ return Mage::getSingleton('shippingmanager/shippingManager')->getAllowedMethods();
114
+ }
115
+
116
+ /**
117
+ *
118
+ * Method to tell magento this shipping method uses tracking
119
+ *
120
+ * @return array $allowedShippingMethods
121
+ */
122
+ public function isTrackingAvailable()
123
+ {
124
+ return true;
125
+ }
126
+
127
+ /**
128
+ *
129
+ * Get tracking result object
130
+ * @param string $tracking_number
131
+ * @return Mage_Shipping_Model_Tracking_Result $tracking_result
132
+ */
133
+ public function getTrackingInfo($tracking_number)
134
+ {
135
+ $tracking_result = $this->getTracking($tracking_number);
136
+
137
+ if ($tracking_result instanceof Mage_Shipping_Model_Tracking_Result) {
138
+ $trackings = $tracking_result->getAllTrackings();
139
+ if (is_array($trackings) && count($trackings) > 0) {
140
+ return $trackings[0];
141
+ }
142
+ }
143
+ // @codeCoverageIgnoreStart
144
+ return false;
145
+ // @codeCoverageIgnoreEnd
146
+ }
147
+
148
+ /**
149
+ *
150
+ * Get track & trace url
151
+ * @param string $tracking_number
152
+ * @return Mage_Shipping_Model_Tracking_Result
153
+ */
154
+ public function getTracking($tracking_number)
155
+ {
156
+ $tracking_result = Mage::getModel('shipping/tracking_result');
157
+ $tracking_status = Mage::getModel('shipping/tracking_result_status');
158
+ $tracking_status->setCarrier($this->_code);
159
+ $tracking_status->setCarrierTitle('<img height="50" alt="bpost" src="' . Mage::getDesign()->getSkinUrl('images/bpost/shippingmanager/track_and_trace.jpg') . '" />');
160
+ $tracking_status->setTracking($tracking_number);
161
+ $tracking_status->addData(
162
+ array(
163
+ 'status'=>'<a target="_blank" href="'.str_replace('$1',$tracking_number,"http://www.bpost.be/etr/light/performSearch.do?searchByItemCode=true&itemCodes=$1&oss_language=nl").'">'.Mage::helper('shipping')->__('Track this Parcel').'</a>'
164
+ )
165
+ );
166
+ $tracking_result->append($tracking_status);
167
+
168
+ return $tracking_result;
169
+ }
170
+
171
+ /**
172
+ * Getter for carrier code
173
+ * needed for Magento version under 1.4
174
+ *
175
+ * @return string
176
+ */
177
+ public function getCarrierCode()
178
+ {
179
+ return $this->_code;
180
+ }
181
+ }
app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Abstract.php ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+
10
+ abstract class Bpost_ShippingManager_Model_Carrier_Shippingmethod_Abstract {
11
+
12
+ protected $_shmHelper;
13
+ protected $_checkout;
14
+ protected $_quote;
15
+ /**
16
+ * @codeCoverageIgnore
17
+ */
18
+ protected function shmHelper()
19
+ {
20
+
21
+ if (is_null($this->_shmHelper)) {
22
+ $this->_shmHelper = Mage::helper('shippingmanager');
23
+ }
24
+ return $this->_shmHelper;
25
+
26
+ }
27
+
28
+ /**
29
+ * Retrieve checkout session model
30
+ *
31
+ * @return Mage_Checkout_Model_Session
32
+ */
33
+ public function getCheckout()
34
+ {
35
+ if (empty($this->_checkout)) {
36
+ $this->_checkout = Mage::getSingleton('checkout/session');
37
+ }
38
+ return $this->_checkout;
39
+ }
40
+
41
+ /**
42
+ * Retrieve sales quote model
43
+ *
44
+ * @return Mage_Sales_Model_Quote
45
+ */
46
+ public function getQuote()
47
+ {
48
+ if (empty($this->_quote)) {
49
+ $this->_quote = $this->getCheckout()->getQuote();
50
+ }
51
+ return $this->_quote;
52
+ }
53
+ /**
54
+ *
55
+ * returns the rate table
56
+ * @codeCoverageIgnore
57
+ * @return array rateTable
58
+ */
59
+ public function getRateTable($deliverymethodIdentifier=null)
60
+ {
61
+ return $this->shmHelper()->getRateTable($deliverymethodIdentifier);
62
+ }
63
+
64
+ /**
65
+ *
66
+ * gets the shippingMethodTitle
67
+ *
68
+ * @codeCoverageIgnore
69
+ * @return string shippingMethodTitle
70
+ */
71
+ public function getShippingMethodTitle()
72
+ {
73
+ return Mage::getModel('shippingmanager/carrier_system_config_source_method')->getShippingMethodTitle($this->_code);
74
+ }
75
+
76
+ /**
77
+ *
78
+ * gets config value FreeDeliveryWhenCartValueBiggerThen
79
+ *
80
+ * @codeCoverageIgnore
81
+ * @return string FreeDeliveryWhenCartValueBiggerThen
82
+ */
83
+ public function getFreeDeliveryWhenCartValueBiggerThen()
84
+ {
85
+ return $this->shmHelper()->getFreeDeliveryWhenCartValueBiggerThen();
86
+ }
87
+
88
+ /**
89
+ *
90
+ * Determine if bpost platform decides the quotes or magento calculates and pushes the quotes to bpost
91
+ * If free delivery is activated and the cart meets the conditions for free delivery => false
92
+ * If Free delivery is not activated but table rates are provided for this shippingMethod => false
93
+ * If free delivery is not activated and the tables rates are provided => true
94
+ * If free delivery is activated and the cart does not meet the conditions for free delivery => rules table rates apply.
95
+ *
96
+ * @return boolean shippingManagerDecidesQuotes
97
+ */
98
+ public function shippingManagerDecidesQuotes()
99
+ {
100
+
101
+ // When we offer free delivery, we overwrite the shipping manager
102
+ if($this->hasFreeDelivery()){
103
+ $this->shmHelper()->log("Free shipping applicable, Magento decides quote for: " . $this->getShippingMethodTitle(), __FILE__, __LINE__);
104
+ return false;
105
+ }
106
+ // there are no rates specified, we can not give the shipping cost, shipping manager will determine costs
107
+ if(!is_null($this->getRateTable($this->getShippingMethodTitle()))){
108
+ $this->shmHelper()->log('Magento decides quote for: ' . $this->getShippingMethodTitle(), __FILE__, __LINE__);
109
+ return false;
110
+ }
111
+ $this->shmHelper()->log('Default behaviour, Shipping manager decides quote for ' . $this->getShippingMethodTitle(), __FILE__, __LINE__);
112
+ return true;
113
+ }
114
+ /**
115
+ *
116
+ * Calculates if the package has a free delivery
117
+ * if no value is entered => false
118
+ * if value is entered and is less then the total price of the cart => false
119
+ * if value is entered and equal or greater then the total price of the cart => true
120
+ *
121
+ * @return boolean hasFreeDelivery
122
+ */
123
+ public function hasFreeDelivery()
124
+ {
125
+ $totals = $this->getQuote()->getTotals();
126
+ $quotePriceWithDiscount = $totals['subtotal']->getValue();
127
+ // Check if cart is ellegible for free shipment
128
+ if ($this->getFreeDeliveryWhenCartValueBiggerThen() > 0 and $quotePriceWithDiscount >= $this->getFreeDeliveryWhenCartValueBiggerThen()) {
129
+ $this->shmHelper()->log("Free delivery because $quotePriceWithDiscount >= " . $this->getFreeDeliveryWhenCartValueBiggerThen(), __FILE__, __LINE__);
130
+ return true;
131
+ }
132
+ return false;
133
+ }
134
+
135
+ /**
136
+ *
137
+ * this method will calculate the cost for the shipping methods of bpost
138
+ *
139
+ * @params Mage_Shipping_Model_Rate_Request $request
140
+ * @return float price
141
+ */
142
+ public function getCost(Mage_Shipping_Model_Rate_Request $request)
143
+ {
144
+ if($this->getQuote()){
145
+ $shippingAddress = $this->getQuote()->getShippingAddress();
146
+ if($shippingAddress && $shippingAddress->getShippingMethod() == "bpost_" . $this->_code){
147
+ $this->shmHelper()->log("Bpost platform already gave quote, use this one", __FILE__, __LINE__);
148
+ return $shippingAddress->getBaseShippingInclTax();
149
+ }
150
+ }
151
+ return $this->getPrice();
152
+ }
153
+
154
+ public function getPrice(){
155
+ if($this->shippingManagerDecidesQuotes()){
156
+ return null;
157
+ }
158
+
159
+ $shippingMethodTitle = $this->getShippingMethodTitle();
160
+ $shippingCost = $this->getRateTable($shippingMethodTitle);
161
+
162
+ $this->shmHelper()->log("Rates for shippingmethod: [$shippingMethodTitle]: " . print_r($shippingCost, true), __FILE__, __LINE__);
163
+ if(is_array($shippingCost)){
164
+ $this->shmHelper()->log("Calcultating rates based on weight rules for shippingmethod: [$shippingMethodTitle]", __FILE__, __LINE__);
165
+ $packageWeight = 0;
166
+ if($this->getQuote()){
167
+ $packageWeight = $this->getQuote()->getShippingAddress()->getWeight();
168
+ }
169
+ return $this->getCostBasedOnWeight($packageWeight, $shippingCost);
170
+ } else{
171
+ $this->shmHelper()->log("Shippingmethod [$shippingMethodTitle] uses flat rate: [$shippingCost]", __FILE__, __LINE__);
172
+ return $shippingCost;
173
+ }
174
+ }
175
+
176
+ /**
177
+ *
178
+ * this method will calculate the cost for the shipping methods of bpost
179
+ *
180
+ * @params Mage_Shipping_Model_Rate_Request $request
181
+ * @return float price
182
+ */
183
+ public function getCostBasedOnWeight($packageWeight, $rateRules)
184
+ {
185
+
186
+ if(!is_array($rateRules)){
187
+ throw new Exception('Bpost: "'.$amountCalculation.'" is not the correct format, example: {"0":"2.90","0.5":"4.50","5":"8","10":"14"}');
188
+ }
189
+ //sort the weight descending
190
+ krsort($rateRules, SORT_NUMERIC);
191
+ //Get the total weight in kg
192
+ $this->shmHelper()->log('Total weight of cart:' . $packageWeight, __FILE__, __LINE__);
193
+ //find the correct price
194
+ $calculatedPrice = false;
195
+ foreach ($rateRules as $weight => $price) {
196
+ $calculatedPrice = $price;
197
+ if ($weight <= $packageWeight) {
198
+ break;
199
+ }
200
+ }
201
+ return $calculatedPrice;
202
+
203
+ }
204
+
205
+ }
app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Bpackbusiness.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_Carrier_Shippingmethod_Bpackbusiness
10
+ extends Bpost_ShippingManager_Model_Carrier_Shippingmethod_Abstract {
11
+
12
+ /**
13
+ * unique internal shipping method identifier
14
+ *
15
+ * @var string [a-z0-9_]
16
+ */
17
+ protected $_code = 'bpackbusiness';
18
+
19
+ }
app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Bpackexpress.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_Carrier_Shippingmethod_Bpackexpress
10
+ extends Bpost_ShippingManager_Model_Carrier_Shippingmethod_Abstract {
11
+
12
+ /**
13
+ * unique internal shipping method identifier
14
+ *
15
+ * @var string [a-z0-9_]
16
+ */
17
+ protected $_code = 'bpackexpress';
18
+
19
+ }
app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Parcelsdepot.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_Carrier_Shippingmethod_Parcelsdepot
10
+ extends Bpost_ShippingManager_Model_Carrier_Shippingmethod_Abstract {
11
+
12
+ /**
13
+ * unique internal shipping method identifier
14
+ *
15
+ * @var string [a-z0-9_]
16
+ */
17
+ protected $_code = 'parcelsdepot';
18
+
19
+ }
app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Pugo.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_Carrier_Shippingmethod_Pugo
10
+ extends Bpost_ShippingManager_Model_Carrier_Shippingmethod_Abstract {
11
+
12
+ /**
13
+ * unique internal shipping method identifier
14
+ *
15
+ * @var string [a-z0-9_]
16
+ */
17
+ protected $_code = 'pugo';
18
+
19
+ }
app/code/community/Bpost/ShippingManager/Model/Carrier/Shippingmethod/Regular.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_Carrier_Shippingmethod_Regular
10
+ extends Bpost_ShippingManager_Model_Carrier_Shippingmethod_Abstract {
11
+
12
+ /**
13
+ * unique internal shipping method identifier
14
+ *
15
+ * @var string [a-z0-9_]
16
+ */
17
+ protected $_code = 'regular';
18
+
19
+ }
app/code/community/Bpost/ShippingManager/Model/Carrier/System/Config/Source/Method.php ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_Carrier_System_config_Source_Method
10
+ extends Mage_Eav_Model_Entity_Attribute_Source_Table {
11
+ /**
12
+ *
13
+ * Initialize all available shipping methods.
14
+ * To add a new shippingmethod, you have to add it to this array and
15
+ * create a corresponding shippingmethod class in the shippingmethod directort
16
+ */
17
+ private $_shippingMethodsConfig = array(
18
+ array(
19
+ 'front_name' => 'BPACK@home',
20
+ 'magento_reference' => 'regular',
21
+ 'bpost_reference' => 'Regular',
22
+ 'order' => '1'
23
+ ),
24
+ array(
25
+ 'front_name' => 'BPACK@bpost',
26
+ 'magento_reference' => 'pugo',
27
+ 'bpost_reference' => 'Pugo',
28
+ 'order' => '2'
29
+ ),
30
+ array(
31
+ 'front_name' => 'BPACK 24/7',
32
+ 'magento_reference' => 'parcelsdepot',
33
+ 'bpost_reference' => 'Parcels depot',
34
+ 'order' => '3'
35
+ )/*,
36
+ array(
37
+ 'front_name' => 'BPACK WORLD EXPRESS',
38
+ 'magento_reference' => 'bpackexpress',
39
+ 'bpost_reference' => 'bpack EXPRESS',
40
+ 'order' => '4'
41
+ ),
42
+ array(
43
+ 'front_name' => 'BPACK WORLD',
44
+ 'magento_reference' => 'bpackbusiness',
45
+ 'bpost_reference' => 'bpack BUSINESS',
46
+ 'order' => '5'
47
+ )*/
48
+ );
49
+
50
+ private $_magentoShippingMethods = array();
51
+ private $_bpostMagentoLinks = array();
52
+ protected $_shmHelper;
53
+
54
+ /**
55
+ *
56
+ * Prepares easy access arrays for the available shippingmethods
57
+ */
58
+ public function __construct(){
59
+ foreach($this->_shippingMethodsConfig as $shippingmethod){
60
+ $this->_magentoShippingMethods[$shippingmethod['magento_reference']] = $shippingmethod['front_name'];
61
+ }
62
+
63
+ foreach($this->_shippingMethodsConfig as $shippingmethod){
64
+ $this->_bpostMagentoLinks[$shippingmethod['bpost_reference']] = $shippingmethod['magento_reference'];
65
+ }
66
+ }
67
+
68
+ /**
69
+ *
70
+ * @codeCoverageIgnore
71
+ */
72
+ protected function shmHelper()
73
+ {
74
+
75
+ if (is_null($this->_shmHelper)) {
76
+ $this->_shmHelper = Mage::helper('shippingmanager');
77
+ }
78
+ return $this->_shmHelper;
79
+
80
+ }
81
+
82
+
83
+ /**
84
+ *
85
+ * This method populates the dropdown box for the attribute excluded_bpost_shippingmethods on the product admin page
86
+ *
87
+ * @return array ['key', 'value']
88
+ */
89
+ public function getAllOptions()
90
+ {
91
+ return $this->transformToOptionArray($this->getEnabledShippingMethods());
92
+ }
93
+
94
+ /**
95
+ *
96
+ * returns an array which links bpost internal shipping codes to magento internal shipping method codes
97
+ *
98
+ */
99
+ public function getLinksBetweenShippingMethodsOfBpostAndMagento()
100
+ {
101
+ return $this->_bpostMagentoLinks;
102
+ }
103
+
104
+ /**
105
+ *
106
+ * returns magentoCode for given bpostCode
107
+ * @param string $bpostCode
108
+ */
109
+ public function translateBpostCodeToMagentoCode($bpostCode)
110
+ {
111
+ return (array_key_exists($bpostCode, $this->_bpostMagentoLinks) ? $this->_bpostMagentoLinks[$bpostCode] : null);
112
+ }
113
+
114
+ /**
115
+ *
116
+ * returns the shipping methods array
117
+ * @return array shippingMethods
118
+ */
119
+ public function getShippingMethods()
120
+ {
121
+ return $this->_magentoShippingMethods;
122
+ }
123
+
124
+ /**
125
+ *
126
+ * Enter description here ...
127
+ * @param string $shippingMethodIdenifier
128
+ * @return string ShippingMethodTitle
129
+ */
130
+ public function getShippingmethod($shippingMethodIdenifier)
131
+ {
132
+ if (isset($this->_magentoShippingMethods[$shippingMethodIdenifier])) {
133
+ return $this->_magentoShippingMethods[$shippingMethodIdenifier];
134
+ } else {
135
+ return null;
136
+ }
137
+ }
138
+
139
+ /**
140
+ *
141
+ * Enter description here ...
142
+ * @param string $shippingMethodIdenifier
143
+ * @return string ShippingMethodTitle
144
+ */
145
+ public function getShippingMethodTitle($shippingMethodIdenifier)
146
+ {
147
+ return $this->getShippingMethod($shippingMethodIdenifier);
148
+ }
149
+
150
+ /**
151
+ *
152
+ * Returns all shipping methods which are set in the config
153
+ * @return array $allowedShippingMethods
154
+ */
155
+ public function getEnabledShippingMethods()
156
+ {
157
+
158
+ $enabledShippingMethods = array();
159
+ $configuredShippingMethods = $this->shmHelper()->getEnabledShippingMethods();
160
+
161
+ foreach ($configuredShippingMethods as $shippingMethodIdenifier) {
162
+ $enabledShippingMethods[$shippingMethodIdenifier] = $this->getShippingMethodTitle($shippingMethodIdenifier);
163
+ }
164
+
165
+ return $enabledShippingMethods;
166
+ }
167
+
168
+ /**
169
+ *
170
+ * This methods transforms all the shippingmethods to an optionArray (array('key' => '', 'value' => '')
171
+ * @return array $optionArray
172
+ */
173
+
174
+ public function toOptionArray()
175
+ {
176
+ return $this->transformToOptionArray($this->getShippingMethods());
177
+ }
178
+
179
+ public function transformToOptionArray($keyValueArray){
180
+ $optionArray = array();
181
+
182
+ foreach ($keyValueArray as $k=>$v) {
183
+ $optionArray[] = array('value'=>$k, 'label'=>$v);
184
+ }
185
+
186
+ return $optionArray;
187
+ }
188
+ }
app/code/community/Bpost/ShippingManager/Model/Entity/Setup.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Bpost_ShippingManager_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup
4
+ {
5
+
6
+
7
+ }
8
+
app/code/community/Bpost/ShippingManager/Model/Observer.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Bpost_ShippingManager_Model_Observer
4
+ {
5
+ public function statustoopen($observer){
6
+ // Confirm the order to the bpost platform
7
+ $shippingManagerApi = Mage::getModel('shippingmanager/Api');
8
+ $order = $observer->getEvent()->getInvoice()->getOrder();
9
+ $shippingManagerApi->statusTo($order, 'OPEN');
10
+ }
11
+
12
+ public function statustocancel($observer){
13
+ // Confirm the order to the bpost platform
14
+ $shippingManagerApi = Mage::getModel('shippingmanager/Api');
15
+ $order = $observer->getEvent()->getOrder();
16
+ $shippingManagerApi->statusTo($order, 'CANCELLED');
17
+ }
18
+
19
+ public function invalidatequote($observer){
20
+ $shippingAddress = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
21
+ if(stristr($shippingAddress->getShippingMethod(),"bpost")){
22
+ $shippingAddress->setShippingMethod("");
23
+ $shippingAddress->setShippingDescription("");
24
+ $shippingAddress->setShippingAmount(0);
25
+ $shippingAddress->setBaseShippingAmount(0);
26
+ $shippingAddress->setSameAsBilling(true);
27
+ $shippingAddress->save();
28
+ }
29
+ }
30
+ }
app/code/community/Bpost/ShippingManager/Model/Postback.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_Postback extends Mage_Core_Model_Abstract
10
+ {
11
+
12
+
13
+ }
14
+
app/code/community/Bpost/ShippingManager/Model/ShippingManager.php ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_Model_ShippingManager extends Mage_Core_Model_Abstract
10
+ {
11
+ protected $_shmHelper;
12
+ protected $_excludedShippingMethods;
13
+ protected $_allowedShippingMethods;
14
+
15
+ /**
16
+ * @codeCoverageIgnore
17
+ */
18
+ protected function shmHelper()
19
+ {
20
+ if (is_null($this->_shmHelper)) {
21
+ $this->_shmHelper = Mage::helper('shippingmanager');
22
+ }
23
+ return $this->_shmHelper;
24
+
25
+ }
26
+
27
+ /**
28
+ *
29
+ * Check if ShippingManager is activated
30
+ *
31
+ * @return boolean ShippingManagerStatus
32
+ */
33
+ public function enabled()
34
+ {
35
+
36
+ return ($this->shmHelper()->getActiveStatus() &&
37
+ ($this->shmHelper()->getAccountId() != "" &&
38
+ $this->shmHelper()->getPassphrase() != ""));
39
+ }
40
+
41
+ /**
42
+ *
43
+ * Checks cart for products which are prohibited of using a bpost shipping method
44
+ *
45
+ * @return array ExcludedShippingMethods
46
+ */
47
+ public function getExcludedShippingMethods()
48
+ {
49
+
50
+ if (!$this->enabled()) {
51
+ return array();
52
+ }
53
+
54
+ if (is_null($this->_excludedShippingMethods)) {
55
+ $cart = Mage::getModel('checkout/cart');
56
+ $excludedShippingMethods = array();
57
+
58
+ $model = Mage::getModel('catalog/product');
59
+ foreach($cart->getProductIds() as $productid){
60
+ $_product = $model->load($productid);
61
+ $excludedShippingMethodsString = $_product->getExcludedBpostShippingmethods();
62
+ $this->shmHelper()->log('product [' . $productid . '] excludes ' . $excludedShippingMethodsString, __FILE__, __LINE__);
63
+ if($excludedShippingMethodsString != ""){
64
+ $excludedShippingMethods = array_merge($excludedShippingMethods, explode(",", $excludedShippingMethodsString));
65
+ }
66
+ }
67
+ $this->_excludedShippingMethods = array_unique($excludedShippingMethods);
68
+
69
+ $enabled_methods = $this->getEnabledShippingMethods();
70
+ foreach($this->_excludedShippingMethods as $key => $shippingMethodIdenifier){
71
+ if(!array_key_exists($shippingMethodIdenifier,$enabled_methods)){
72
+ unset($this->_excludedShippingMethods[$key]);
73
+ }
74
+ }
75
+
76
+ $this->shmHelper()->log('Excluded Shippingmethods: \n' . print_r($this->_excludedShippingMethods, true), __FILE__, __LINE__);
77
+ }
78
+ return $this->_excludedShippingMethods;
79
+
80
+ }
81
+
82
+ /**
83
+ *
84
+ * Enabled shipping methods minus excluded shipping methods
85
+ *
86
+ * @return array allowedShippingMethods
87
+ */
88
+ public function getAllowedMethods()
89
+ {
90
+ if (!$this->enabled()){
91
+ return array();
92
+ }
93
+
94
+ if (is_null($this->_allowedShippingMethods)) {
95
+ $this->_allowedShippingMethods = $this->getEnabledShippingMethods();
96
+ $excludedShippingMethods = $this->getExcludedShippingMethods();
97
+ foreach ($this->_allowedShippingMethods as $shippingMethodIdenifier => $shippingMethodTitle) {
98
+ if(in_array($shippingMethodIdenifier,$excludedShippingMethods)){
99
+ unset($this->_allowedShippingMethods[$shippingMethodIdenifier]);
100
+ }
101
+ }
102
+ $this->shmHelper()->log('Allowed Shippingmethods: \n' . print_r($this->_allowedShippingMethods, true), __FILE__, __LINE__);
103
+ }
104
+ return $this->_allowedShippingMethods;
105
+ }
106
+
107
+ /**
108
+ *
109
+ * Enabled shipping methods are the methods selected in the admin
110
+ * @codeCoverageIgnore
111
+ * @return array enabledShippingMethods
112
+ */
113
+ public function getEnabledShippingMethods()
114
+ {
115
+ return Mage::getModel('shippingmanager/carrier_system_config_source_method')->getEnabledShippingMethods();
116
+ }
117
+
118
+ /**
119
+ *
120
+ * returns the magento delivery method reference for a given bpost reference
121
+ * @codeCoverageIgnore
122
+ * @return string magento delivery method reference
123
+ */
124
+ public function getDeliveryMethodMagentoCode()
125
+ {
126
+ return Mage::getModel('shippingmanager/carrier_system_config_source_method')
127
+ ->translateBpostCodeToMagentoCode($this->getDeliverymethod());
128
+ }
129
+
130
+ /**
131
+ *
132
+ * Processes postback parameters and saves them to magento
133
+ *
134
+ * @param string $postbackParameters
135
+ */
136
+ public function processConfirmPostBack($postbackParameters)
137
+ {
138
+
139
+ $this->shmHelper()->log('Postback parameters:' . print_r($postbackParameters, true), __FILE__, __LINE__);
140
+ $shippingAddress = $this->getShippingAddress();
141
+ $this->shmHelper()->log('Updating sales_quote_address with id:' . $shippingAddress->getId(), __FILE__, __LINE__);
142
+ $this->setDeliverymethod($postbackParameters['deliveryMethod']);
143
+ $deliveryMethodMagentoCode = $this->getDeliveryMethodMagentoCode();
144
+ if ($shippingAddress){
145
+ $shippingAddress->setFirstname($postbackParameters['customerFirstName']);
146
+ $shippingAddress->setLastname($postbackParameters['customerLastName']);
147
+ if(isset($postbackParameters['customerPostalLocation'])){
148
+ $shippingAddress->setCompany($postbackParameters['customerPostalLocation']);
149
+ }
150
+ $shippingAddress->setStreet($postbackParameters['customerStreet'] . " " . $postbackParameters['customerStreetNumber']);
151
+ $shippingAddress->setCity($postbackParameters['customerCity']);
152
+ $shippingAddress->setPostcode($postbackParameters['customerPostalCode']);
153
+ $shippingAddress->setCountryId($postbackParameters['customerCountry']);
154
+ $shippingAddress->setTelephone($postbackParameters['customerPhoneNumber']);
155
+ $shippingAddress->setShippingMethod("bpost_" . $deliveryMethodMagentoCode);
156
+ $shippingAddress->setShippingDescription(Mage::getModel("shippingmanager/carrier_system_config_source_method")->getShippingMethodTitle($deliveryMethodMagentoCode));
157
+ $shippingAddress->setShippingAmount($postbackParameters['deliveryMethodPriceTotal']/100);
158
+ $shippingAddress->setBaseShippingAmount($postbackParameters['deliveryMethodPriceTotal']/100);
159
+ $shippingAddress->setBaseShippingInclTax($postbackParameters['deliveryMethodPriceTotal']/100);
160
+ $shippingAddress->setSameAsBilling(false);
161
+ $shippingAddress->save();
162
+ }
163
+
164
+ // internally store the delivery method for later use in the block
165
+ $shippingRates = $shippingAddress->getShippingRatesCollection();
166
+
167
+ foreach ($shippingRates as $key => $rate) {
168
+ if($rate->getMethod() == $deliveryMethodMagentoCode){
169
+ $price = $postbackParameters['deliveryMethodPriceTotal']/100;
170
+ $rate->setPrice($price);
171
+ $rate->save();
172
+ }
173
+ }
174
+ }
175
+
176
+ public function getShippingAddress()
177
+ {
178
+ $quote = Mage::getModel('checkout/cart')->getQuote();
179
+ $shippingAddress = $quote->getShippingAddress();
180
+ return $shippingAddress;
181
+ }
182
+
183
+
184
+ /*
185
+ *
186
+ * retuns the basic fields
187
+ *
188
+ * @return array fields
189
+ *
190
+ */
191
+ public function getChecksumParameters($action, $orderReference, $customerCountry, $deliveryMethodOverrides = null)
192
+ {
193
+ $checksumParameters = array();
194
+ $checksumParameters['accountId'] = $this->shmHelper()->getAccountId();
195
+ $checksumParameters['action'] = $action;
196
+ $checksumParameters['customerCountry'] = $customerCountry;
197
+ $checksumParameters['orderReference'] = $orderReference;
198
+
199
+ if(is_array($deliveryMethodOverrides)){
200
+ $checksumParameters['deliveryMethodOverrides'] = $deliveryMethodOverrides;
201
+ }
202
+
203
+ $checksumParameters['checksum'] = $this->getChecksum($checksumParameters);
204
+ $this->shmHelper()->log("Checksum parameters: \n" . print_r($checksumParameters, true), __FILE__, __LINE__);
205
+ return $checksumParameters;
206
+ }
207
+
208
+ /**
209
+ *
210
+ * calculates checksum for form
211
+ *
212
+ * @return string rate_table
213
+ */
214
+ public function getChecksum($checksumParameters)
215
+ {
216
+ $checksumQuerystring = "";
217
+
218
+ if(!is_array($checksumParameters) || count($checksumParameters) < 1) {
219
+ return $checksumQuerystring;
220
+ }
221
+
222
+ // parameters need to be sorted alphabetically
223
+ ksort($checksumParameters);
224
+
225
+ foreach ($checksumParameters as $fieldName => $fieldValue) {
226
+ if (is_array($fieldValue)) {
227
+ foreach($fieldValue as $rowId => $subFieldValue){
228
+ $checksumQuerystring .= $fieldName . "=" . $subFieldValue . "&";
229
+ }
230
+ } else {
231
+ $checksumQuerystring .= $fieldName . "=" . $fieldValue . "&";
232
+ }
233
+ }
234
+
235
+ // Hash the checksum
236
+ $hashedChecksum = hash('sha256',$checksumQuerystring . $this->shmHelper()->getPassphrase());
237
+ $this->shmHelper()->log("Hashed checksum: [$hashedChecksum]", __FILE__, __LINE__);
238
+
239
+ return $hashedChecksum;
240
+ }
241
+
242
+ /**
243
+ *
244
+ * This method collects all the available shipping methods for bpost,
245
+ * then calculates what their viewstates and costs are.
246
+ * These parameters are returned in an array, consisting of an element per shipping method
247
+ * and containing a string in the format of shippingMethodCode|viewstate|cost
248
+ *
249
+ * @return array deliveryMethodsOverrides
250
+ */
251
+ public function getDeliveryMethodOverrides($shippingRates)
252
+ {
253
+ $deliveryMethodsOverrides = $this->getDeliveryMethodOverridesAsArray($shippingRates);
254
+ $deliveryMethodsOverridesInOneLine = array();
255
+ foreach($deliveryMethodsOverrides as $parameters){
256
+ $parametersInOneLine = implode("|" , $parameters);
257
+ array_push($deliveryMethodsOverridesInOneLine, $parametersInOneLine);
258
+ }
259
+
260
+ // sort the array
261
+ sort($deliveryMethodsOverridesInOneLine);
262
+ $this->shmHelper()->log("DeliveryMethodsOverrides after processing:\n" . print_r($deliveryMethodsOverridesInOneLine, true), __FILE__, __LINE__);
263
+ return $deliveryMethodsOverridesInOneLine;
264
+ }
265
+
266
+ /**
267
+ *
268
+ * This method collects all the available shipping methods for bpost,
269
+ * then calculates what their viewstates and costs are.
270
+ * These parameters are returned in an array, consisting of an element per shipping method
271
+ * and containing a string in the format of shippingMethodCode|viewstate|cost
272
+ *
273
+ * @return array deliveryMethodsOverrides
274
+ */
275
+ public function getDeliveryMethodOverridesAsArray($shippingRates)
276
+ {
277
+ $deliveryMethodsOverrides = $this->getInitialDeliveryMethodsOverridesPerShippingMethod();
278
+ $this->shmHelper()->log('Initial delivery methods overrides:\n' . print_r($deliveryMethodsOverrides, true), __FILE__, __LINE__);
279
+
280
+ // bpost does not exists as carrier, do nothing
281
+ if(!array_key_exists('bpost', $shippingRates)){
282
+ return array();
283
+ }
284
+
285
+ $shippingMethods = $shippingRates['bpost'];
286
+
287
+ // run over all the shipping methods of bpost
288
+ foreach ($shippingMethods as $shippingMethodInfo) {
289
+
290
+ $shippingMethodIdenifier = str_replace('bpost_' , '', $shippingMethodInfo->getCode());
291
+ $shippingMethod = Mage::getModel('shippingmanager/carrier_shippingmethod_' . $shippingMethodIdenifier);
292
+ // Get price in eurocent
293
+ $deliveryMethodsOverrides[$shippingMethodIdenifier]['cost'] = $shippingMethod->getPrice() * 100;
294
+ // Shipping manager will decide the quote, so we do not pass it
295
+ if ($shippingMethod->shippingManagerDecidesQuotes()) {
296
+ unset($deliveryMethodsOverrides[$shippingMethodIdenifier]['cost']);
297
+ }
298
+ $deliveryMethodsOverrides[$shippingMethodIdenifier]['viewstate'] = 'VISIBLE';
299
+ }
300
+
301
+ foreach($this->getExcludedShippingMethods() as $shippingMethodIdenifier){
302
+ $deliveryMethodsOverrides[$shippingMethodIdenifier]['viewstate'] = 'GREYED_OUT';
303
+ }
304
+
305
+ return $deliveryMethodsOverrides;
306
+ }
307
+
308
+ /**
309
+ *
310
+ * Create initial array for deliveryMethodsOverrides
311
+ * @return array $deliveryMethodsOverrides
312
+ */
313
+ public function getInitialDeliveryMethodsOverridesPerShippingMethod()
314
+ {
315
+ $carrierBpost = Mage::getModel('shippingmanager/carrier_system_config_source_method');
316
+
317
+ // Get all the possible shipping methods
318
+ $allShippingMethods = $carrierBpost->getLinksBetweenShippingMethodsOfBpostAndMagento();
319
+
320
+ //Create an array where everything is invisible to start with
321
+ foreach ($allShippingMethods as $bpostCode => $magentoCode) {
322
+ $deliveryMethodsOverrides[$magentoCode] = array( 'code' => $bpostCode, 'viewstate' => 'INVISIBLE', 'cost' => 0);
323
+ }
324
+ return $deliveryMethodsOverrides;
325
+ }
326
+
327
+ }
328
+
app/code/community/Bpost/ShippingManager/Test/Block/Onepage/Shipping/Method/Available.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @group shippingManager
4
+ * @group blocks
5
+ */
6
+ class Bpost_ShippingManager_Test_Block_Onepage_Shipping_Method_Available
7
+ extends EcomDev_PHPUnit_Test_Case
8
+ {
9
+ /**
10
+ * Test getCarrierName
11
+ *
12
+ * @test
13
+ * @group ShippingMethodAvailable
14
+ * @doNotIndexAll
15
+ */
16
+ public function getCarrierName()
17
+ {
18
+ $className = Mage::getConfig()->getBlockClassName('shippingmanager/onepage_shipping_method_available');
19
+ $block = new $className();
20
+ $this->assertEquals('<a id="start_bpost_shippingmanager" href="javascript:shm.show();" title="Open bpost shippingmanager" ><img id="bpost_logo" alt="Open bpost shippingmanager" src="' . Mage::getDesign()->getSkinUrl('images/bpost/shippingmanager/logo_bpost.jpg') . '" /></a>', $block->getCarrierName("bpost"));
21
+ }
22
+
23
+ /**
24
+ * Test deliveryMethod returns Delivert Method magento code
25
+ *
26
+ * @test
27
+ * @group deliveryMethod
28
+ * @doNotIndexAll
29
+ */
30
+ public function deliveryMethodReturnsMagentoCode()
31
+ {
32
+ $className = Mage::getConfig()->getBlockClassName('shippingmanager/confirm');
33
+ $block = new $className();
34
+ $postback = Mage::getSingleton('shippingmanager/shippingManager');
35
+ $postback->setDeliverymethod("Pugo");
36
+ $this->assertEquals('pugo', $block->deliveryMethod());
37
+ }
38
+ }
app/code/community/Bpost/ShippingManager/Test/Block/Onepage/Shipping/Method/Available/fixtures/bpostModuleConfig.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/active: 1
3
+ default/carriers/bpost/account_id: 105704
4
+ default/carriers/bpost/passphrase: secret
5
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
6
+ default/carriers/bpost/title: bpost
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
9
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
10
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
11
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "0", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
app/code/community/Bpost/ShippingManager/Test/Controller/ApiController.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_Shippingmanager_test_Controller_PostbackController extends EcomDev_PHPUnit_Test_Case_Controller
3
+ {
4
+ /**
5
+ * @test
6
+ */
7
+ public function newtrackingcodeAction()
8
+ {
9
+ $barcode = "323212345659900000001030";
10
+ $responseXml = <<<XML
11
+ <?xml version="1.0" encoding="UTF-8"?>
12
+ <orderRefBarcodeMap xmlns="http://schema.post.be/shm/deepintegration/v2/">
13
+ <entry>
14
+ <orderReference>201106241506</orderReference>
15
+ <barcode>$barcode</barcode>
16
+ </entry>
17
+ </orderRefBarcodeMap>
18
+ XML;
19
+ $api = $this->getModelMock('shippingmanager/api',array('request'));
20
+ $api->expects($this->any())
21
+ ->method("request")
22
+ ->will($this->returnValue(new Zend_Http_Response(200, array(), $responseXml)));
23
+ $this->replaceByMock('model', 'shippingmanager/Api', $api);
24
+ $this->getRequest()->setMethod("POST");
25
+ $this->getRequest()->setParams(array('order' => "1000"));
26
+ $this->dispatch('shippingmanager/api/newtrackingcode');
27
+ $this->assertResponseBodyContains('{"barcode":"' . $barcode . '"}');
28
+ $this->assertLayoutNotLoaded();
29
+ $this->assertLayoutNotRendered();
30
+ //$this->assertEquals('{"barcode":"' . $barcode . '"}', $this->getResponse()->getOutputBody());
31
+ }
32
+
33
+ /**
34
+ * @test
35
+ */
36
+ function labelAction()
37
+ {
38
+ $orderReference = '1000';
39
+ $barcode = '323212345659900000001030';
40
+ $pdfBody = 'JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9GaWx0ZXIvRENURGVjb2RlL1R5cGUvWE9iamVjdC9MZW5ndGggMzAyMS9CaXRzUGVyQ29tcG9uZW50IDgvSGVpZ2h0IDMxL0NvbG9yU3BhY2UvRGV2aWNlUkdCL1N1YnR5cGUvSW1hZ2UvV2lkdGggMzk2Pj5zdHJlYW0K/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAfAYwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqD';
41
+ $responseXml = <<<XML
42
+ <?xml version="1.0" encoding="UTF-8"?>
43
+ <pdf xmlns="http://schema.post.be/shm/deepintegration/v1/">
44
+ $pdfBody
45
+ </pdf>
46
+ XML;
47
+ $api = $this->getModelMock('shippingmanager/api',array('request'));
48
+ $api->expects($this->any())
49
+ ->method("request")
50
+ ->will($this->returnValue(new Zend_Http_Response(200, array(), $responseXml)));
51
+ $this->replaceByMock('model', 'shippingmanager/Api', $api);
52
+ $this->getRequest()->setMethod("GET");
53
+ $this->getRequest()->setParams(array('orderReference' => $orderReference, "barcode" => $barcode));
54
+ $this->dispatch('shippingmanager/api/label');
55
+ $this->assertResponseBodyContains(base64_decode($pdfBody));
56
+ $this->assertLayoutNotLoaded();
57
+ $this->assertLayoutNotRendered();
58
+ $this->assertResponseHeaderContains('Content-type', 'application/pdf');
59
+ $this->assertResponseHeaderContains('Content-Disposition:', 'attachment; filename="' . $orderReference . '-' . $barcode . '.pdf"');
60
+ }
61
+
62
+ /**
63
+ * @test
64
+ */
65
+ function labelsAction()
66
+ {
67
+ $orderReference = '1000';
68
+ $pdfBody = 'JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9GaWx0ZXIvRENURGVjb2RlL1R5cGUvWE9iamVjdC9MZW5ndGggMzAyMS9CaXRzUGVyQ29tcG9uZW50IDgvSGVpZ2h0IDMxL0NvbG9yU3BhY2UvRGV2aWNlUkdCL1N1YnR5cGUvSW1hZ2UvV2lkdGggMzk2Pj5zdHJlYW0K/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAfAYwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqD';
69
+ $responseXml = <<<XML
70
+ <?xml version="1.0" encoding="UTF-8"?>
71
+ <pdf xmlns="http://schema.post.be/shm/deepintegration/v1/">
72
+ $pdfBody
73
+ </pdf>
74
+ XML;
75
+ $api = $this->getModelMock('shippingmanager/api',array('request'));
76
+ $api->expects($this->any())
77
+ ->method("request")
78
+ ->will($this->returnValue(new Zend_Http_Response(200, array(), $responseXml)));
79
+ $this->replaceByMock('model', 'shippingmanager/Api', $api);
80
+ $this->getRequest()->setMethod("GET");
81
+ $this->getRequest()->setParams(array('orderReference' => $orderReference));
82
+ $this->dispatch('shippingmanager/api/labels');
83
+ $this->assertResponseBodyContains(base64_decode($pdfBody));
84
+ $this->assertLayoutNotLoaded();
85
+ $this->assertLayoutNotRendered();
86
+ $this->assertResponseHeaderContains('Content-type', 'application/pdf');
87
+ $this->assertResponseHeaderContains('Content-Disposition:', 'attachment; filename="' . $orderReference . '.pdf"');
88
+ }
89
+ }
app/code/community/Bpost/ShippingManager/Test/Controller/PostbackController.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bpost_Shippingmanager_test_Controller_PostbackController extends EcomDev_PHPUnit_Test_Case_Controller
3
+ {
4
+ function testCancelAction(){
5
+ $this->dispatch('shippingmanager/postback/cancel');
6
+ $this->assertResponseBodyContains('window.parent.parent.parent.shm.postbackCancel();');
7
+ $this->assertRequestRoute('shippingmanager/postback/cancel');
8
+ $this->assertLayoutHandleLoaded('shippingmanager_postback_cancel');
9
+ }
10
+
11
+ function testErrorAction(){
12
+ $this->dispatch('shippingmanager/postback/error');
13
+ $this->assertResponseBodyContains('window.parent.parent.parent.shm.postbackError();');
14
+ $this->assertRequestRoute('shippingmanager/postback/error');
15
+ $this->assertLayoutHandleLoaded('shippingmanager_postback_error');
16
+ }
17
+
18
+ function testStartformAction(){
19
+ $this->dispatch('shippingmanager/postback/startform');
20
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "accountId");
21
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "action");
22
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerCountry");
23
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "lang");
24
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "orderTotalPrice");
25
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerFirstName");
26
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerLastName");
27
+ /*
28
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerStreet");
29
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerStreetNumber");
30
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerBox");
31
+ */
32
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerCity");
33
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerPostalCode");
34
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerEmail");
35
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "customerPhoneNumber");
36
+ $this->assertTagInStartForm($this->getResponse()->getSentResponse(), "checksum");
37
+ $this->assertRequestRoute('shippingmanager/postback/startform');
38
+ $this->assertLayoutHandleLoaded('shippingmanager_postback_startform');
39
+ }
40
+
41
+ private function assertTagInStartForm($html, $element_id){
42
+ $matcher = array(
43
+ 'tag' => 'input',
44
+ "attributes" => array(
45
+ "name" => "$element_id",
46
+ "id" => "$element_id"
47
+ )
48
+ );
49
+ $this->assertTag($matcher, $html);
50
+ }
51
+
52
+ function testJsforcheckoutcartAction(){
53
+ $this->dispatch('shippingmanager/postback/jsforcheckoutcart');
54
+ $this->assertRequestRoute('shippingmanager/postback/jsforcheckoutcart');
55
+ $this->assertLayoutHandleLoaded('shippingmanager_postback_jsforcheckoutcart');
56
+ }
57
+
58
+ function testJsforonestepcheckoutAction(){
59
+ $this->dispatch('shippingmanager/postback/jsforonestepcheckout');
60
+ $this->assertRequestRoute('shippingmanager/postback/jsforonestepcheckout');
61
+ $this->assertLayoutHandleLoaded('shippingmanager_postback_jsforonestepcheckout');
62
+ }
63
+
64
+
65
+ }
app/code/community/Bpost/ShippingManager/Test/Controller/PostbackController/fixtures/startformAction.yaml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/active: 1
3
+ default/carriers/bpost/account_id: 105704
4
+ default/carriers/bpost/passphrase: secret
5
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
6
+ default/carriers/bpost/title: bpost
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
app/code/community/Bpost/ShippingManager/Test/Helper/Data.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @group shippingManagerHelper
4
+ */
5
+ class Bpost_ShippingManager_Test_Helper_Data
6
+ extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ private $_helper;
9
+
10
+ public function setUp(){
11
+ parent::setUp();
12
+ $this->_helper = Mage::helper('shippingmanager');
13
+ }
14
+
15
+ /**
16
+ * Test getAccountId
17
+ *
18
+ * @test
19
+ * @loadFixture bpostModuleConfig.yaml
20
+ * @doNotIndexAll
21
+ */
22
+ public function getAccountId()
23
+ {
24
+ $this->assertEquals('105704', $this->_helper->getAccountId());
25
+ }
26
+
27
+ /**
28
+ * Test GetPassphrase
29
+ *
30
+ * @test
31
+ * @loadFixture bpostModuleConfig.yaml
32
+ * @doNotIndexAll
33
+ */
34
+ public function getPassphrase()
35
+ {
36
+ $this->assertEquals('secret', $this->_helper->getPassphrase());
37
+ }
38
+
39
+ /**
40
+ * Test GetFrontendUrl
41
+ *
42
+ * @test
43
+ * @loadFixture bpostModuleConfig.yaml
44
+ * @doNotIndexAll
45
+ */
46
+ public function getFrontendUrl()
47
+ {
48
+ $this->assertEquals('https://shippingmanager.bpost.be/ShmFrontEnd/start', $this->_helper->getFrontendUrl());
49
+ }
50
+
51
+ /**
52
+ * Test getApiUri
53
+ *
54
+ * @test
55
+ * @loadFixture
56
+ * @doNotIndexAll
57
+ */
58
+ public function getApiUriReturnsConcatOfApiuriAndAccountid()
59
+ {
60
+ $this->assertEquals('https://api.bpost.be/services/shm/105704/', $this->_helper->getApiUri());
61
+ }
62
+
63
+ /**
64
+ * Test getApiUri
65
+ *
66
+ * @test
67
+ * @loadFixture
68
+ * @doNotIndexAll
69
+ */
70
+ public function getApiUriReturnsEmptyStringWhenAccountIdIsNotSet()
71
+ {
72
+ $this->assertEquals("", $this->_helper->getApiUri());
73
+ }
74
+
75
+ /**
76
+ * Test getApiUri
77
+ *
78
+ * @test
79
+ * @loadFixture
80
+ * @doNotIndexAll
81
+ */
82
+ public function getApiUriReturnsEmptyStringWhenApiUriIsNotSet()
83
+ {
84
+ $this->assertEquals("", $this->_helper->getApiUri());
85
+ }
86
+
87
+ /**
88
+ * Test getProxyHost
89
+ *
90
+ * @test
91
+ * @loadFixture bpostModuleConfig.yaml
92
+ * @doNotIndexAll
93
+ */
94
+ public function getProxyHost()
95
+ {
96
+ $this->assertEquals('proxy.host.be', $this->_helper->getProxyHost());
97
+ }
98
+
99
+ /**
100
+ * Test getProxyPort
101
+ *
102
+ * @test
103
+ * @loadFixture bpostModuleConfig.yaml
104
+ * @doNotIndexAll
105
+ */
106
+ public function getProxyPort()
107
+ {
108
+ $this->assertEquals('8080', $this->_helper->getProxyPort());
109
+ }
110
+
111
+ /**
112
+ * Test getFreeDeliveryWhenCartValueBiggerThen
113
+ *
114
+ * @test
115
+ * @loadFixture bpostModuleConfig.yaml
116
+ * @doNotIndexAll
117
+ */
118
+ public function getFreeDeliveryWhenCartValueBiggerThen()
119
+ {
120
+ $this->assertEquals('100', $this->_helper->getFreeDeliveryWhenCartValueBiggerThen());
121
+ }
122
+
123
+ /**
124
+ * Test getBpostLogoPath
125
+ *
126
+ * @test
127
+ * @doNotIndexAll
128
+ */
129
+ public function getBpostLogoPath()
130
+ {
131
+ $this->assertEquals('images/bpost/shippingmanager/logo_bpost.jpg', $this->_helper->getBpostLogoPath());
132
+ }
133
+
134
+ /**
135
+ * Test rateTableIsEmpty
136
+ *
137
+ * @test
138
+ * @loadFixture
139
+ * @doNotIndexAll
140
+ */
141
+ public function rateTableIsEmpty()
142
+ {
143
+ $this->assertEquals(null, $this->_helper->getRateTable());
144
+ }
145
+
146
+ /**
147
+ * Test rateTableIsInvalidJasonString
148
+ *
149
+ * @test
150
+ * @expectedException Exception
151
+ * @loadFixture
152
+ * @doNotIndexAll
153
+ */
154
+ public function rateTableIsInvalidJasonStringRaisesException()
155
+ {
156
+ $this->_helper->getRateTable();
157
+ }
158
+
159
+ /**
160
+ * Test rateTableForAllDelivertMethods
161
+ *
162
+ * @test
163
+ * @loadFixture bpostModuleConfig.yaml
164
+ * @doNotIndexAll
165
+ */
166
+ public function rateTableForAllDelivertMethods()
167
+ {
168
+ $rateTableArray = array(
169
+ "BPACK@bpost" => "12",
170
+ "BPACK@home" => "0",
171
+ "BPACK 24/7" => array(
172
+ "0" => "2.90",
173
+ "0.5" => "4.50",
174
+ "5" => "8",
175
+ "10" => "14"
176
+ )
177
+ );
178
+ $this->assertEquals($rateTableArray, $this->_helper->getRateTable());
179
+ }
180
+
181
+ /**
182
+ * Test rateTableForSpecifiedDelivertMethod
183
+ *
184
+ * @test
185
+ * @loadFixture bpostModuleConfig.yaml
186
+ * @doNotIndexAll
187
+ */
188
+ public function rateTableForSpecifiedDelivertMethod()
189
+ {
190
+ $rateTableArray = array(
191
+ "BPACK@bpost" => "12",
192
+ "BPACK@home" => "0",
193
+ "BPACK 24/7" => array(
194
+ "0" => "2.90",
195
+ "0.5" => "4.50",
196
+ "5" => "8",
197
+ "10" => "14"
198
+ )
199
+ );
200
+ $this->assertEquals($rateTableArray["BPACK@bpost"], $this->_helper->getRateTable("BPACK@bpost"));
201
+ $this->assertEquals($rateTableArray["BPACK@home"], $this->_helper->getRateTable("BPACK@home"));
202
+ $this->assertEquals($rateTableArray["BPACK 24/7"], $this->_helper->getRateTable("BPACK 24/7"));
203
+ $this->assertEquals(null, $this->_helper->getRateTable("not specified method"));
204
+ }
205
+
206
+ /**
207
+ * Test getEnabledShippingMethods
208
+ *
209
+ * @test
210
+ * @loadFixture bpostModuleConfig.yaml
211
+ * @doNotIndexAll
212
+ */
213
+ public function getEnabledShippingMethods()
214
+ {
215
+ $shippingMethodsArray = array("regular","pugo", "parcelsdepot");
216
+ $this->assertEquals($shippingMethodsArray, $this->_helper->getEnabledShippingMethods());
217
+ }
218
+
219
+ /**
220
+ * Test When allowed shipping methods is empty, a empty array is returned
221
+ *
222
+ * @test
223
+ * @loadFixture
224
+ * @doNotIndexAll
225
+ */
226
+ public function allowedShippingMethodsIsNotSet()
227
+ {
228
+ $shippingMethodsArray = array();
229
+ $this->assertEquals($shippingMethodsArray, $this->_helper->getEnabledShippingMethods());
230
+ }
231
+
232
+ /**
233
+ * Test When allowed shipping methods is empty, a empty array is returned
234
+ *
235
+ * @test
236
+ * @loadFixture
237
+ * @doNotIndexAll
238
+ */
239
+ public function onlyOneAllowedShippingMethodsIsSet()
240
+ {
241
+ $shippingMethodsArray = array("regular");
242
+ $this->assertEquals($shippingMethodsArray, $this->_helper->getEnabledShippingMethods());
243
+ }
244
+
245
+ /**
246
+ * Test When allowed shipping methods is empty, a empty array is returned
247
+ *
248
+ * @test
249
+ * @loadFixture bpostModuleConfig.yaml
250
+ * @doNotIndexAll
251
+ */
252
+ public function getTitle()
253
+ {
254
+ $this->assertEquals("bpost", $this->_helper->getTitle());
255
+ }
256
+
257
+ /**
258
+ * Test getBpostLogoHeight
259
+ * @test
260
+ * @loadFixture bpostModuleConfig.yaml
261
+ * @doNotIndexAll
262
+ */
263
+ public function getBpostLogoHeight()
264
+ {
265
+ $this->assertEquals("200", $this->_helper->getBpostLogoHeight());
266
+ }
267
+
268
+
269
+ }
app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/allowedShippingMethodsIsNotSet.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/carriers/bpost/allowed_methods: ""
app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/bpostModuleConfig.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/account_id: 105704
3
+ default/carriers/bpost/passphrase: secret
4
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
5
+ default/carriers/bpost/title: bpost
6
+ default/carriers/bpost/active: 1
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
9
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
10
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
11
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "0", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/getApiUriReturnsConcatOfApiuriAndAccountid.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ config:
2
+ default/carriers/bpost/account_id: 105704
3
+ default/carriers/bpost/api_uri: "https://api.bpost.be/services/shm"
app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/getApiUriReturnsEmptyStringWhenAccountIdIsNotSet.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/carriers/bpost/api_uri: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/getApiUriReturnsEmptyStringWhenApiUriIsNotSet.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ config:
2
+ default/carriers/bpost/account_id: 105704
3
+ default/carriers/bpost/api_uri: ""
app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/onlyOneAllowedShippingMethodsIsSet.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/carriers/bpost/allowed_methods: "regular"
app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/rateTableIsEmpty.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/carriers/bpost/rate_table: ""
app/code/community/Bpost/ShippingManager/Test/Helper/Data/fixtures/rateTableIsInvalidJasonStringRaisesException.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/carriers/bpost/rate_table: "{ddd : 'daez}"
app/code/community/Bpost/ShippingManager/Test/Model/Api.php ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @group Api
4
+ */
5
+ class Bpost_ShippingManager_Test_Model_Api
6
+ extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+
9
+ private $_api;
10
+
11
+ public function setUp(){
12
+ parent::setUp();
13
+ $this->_api = Mage::getModel("shippingmanager/Api");
14
+ }
15
+
16
+ /**
17
+ *
18
+ * Helper function to create Helper mock
19
+ * @param array $optionalMethods
20
+ * @return Bpost_ShippingManager_Helper_Data shmHelper
21
+ */
22
+ private function getShmHelperMock(array $optionalMethods, string $proxyHost = null,$proxyPort = null, string $apiUri = null)
23
+ {
24
+ $methods = array_merge(array("log", 'getApiUri', 'getProxyHost', 'getProxyPort'), $optionalMethods);
25
+ $shmHelper = $this->getHelperMock('shippingmanager',$methods);
26
+ $shmHelper->expects($this->any())
27
+ ->method("log")
28
+ ->will($this->returnValue(null));
29
+ $shmHelper->expects($this->any())
30
+ ->method("getApiUri")
31
+ ->will($this->returnValue($apiUri));
32
+ $shmHelper->expects($this->any())
33
+ ->method("getProxyHost")
34
+ ->will($this->returnValue($proxyHost));
35
+ $shmHelper->expects($this->any())
36
+ ->method("getProxyPort")
37
+ ->will($this->returnValue($proxyPort));
38
+ return $shmHelper;
39
+ }
40
+
41
+ /**
42
+ *
43
+ * Helper method which returns value of shippingmanager/Api::enabled()
44
+ * @param boolean enabled
45
+ */
46
+ private function enabled($apiUri)
47
+ {
48
+ $shmHelper = $this->getShmHelperMock(array(), null, null, $apiUri);
49
+ $this->replaceByMock('helper', 'shippingmanager/data', $shmHelper);
50
+
51
+ $api = Mage::getModel("shippingmanager/Api");
52
+ return $api->enabled();
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @test
58
+ * @group enabled
59
+ * @doNotIndexAll
60
+ */
61
+ public function apiNotEnabledWhenApiUriIsBlank()
62
+ {
63
+ $this->assertFalse($this->enabled());
64
+ }
65
+
66
+ /**
67
+ *
68
+ * @test
69
+ * @group enabled
70
+ * @doNotIndexAll
71
+ */
72
+ public function apiEnabledWhenApiUriIsFilledIn()
73
+ {
74
+ $this->assertTrue($this->enabled("https://api.bpost.be/services/shm/105704/"));
75
+ }
76
+
77
+ /**
78
+ *
79
+ * Helper method to create ordermock
80
+ * @return sales/order mock
81
+ */
82
+ private function getOrderMock($orderId, $carrierClassAlias)
83
+ {
84
+ $order = $this->getModelMock('sales/order');
85
+ $order->expects($this->any())
86
+ ->method('getRealOrderId')
87
+ ->will($this->returnValue($orderId));
88
+ $order->expects($this->any())
89
+ ->method('getShippingCarrier')
90
+ ->will($this->returnValue(mage::getModel($carrierClassAlias)));
91
+ return $order;
92
+ }
93
+
94
+ /**
95
+ *
96
+ * Helper method to create Zend_Http_Client mock
97
+ * @return Zend_Http_Client mock
98
+ */
99
+ private function getHttpClientMock($responseCode, $responseBody = "")
100
+ {
101
+ $httpClient = $this->getMock('Zend_Http_Client');
102
+ $httpClient->expects($this->any())
103
+ ->method('request')
104
+ ->will($this->returnValue(new Zend_Http_Response($responseCode, array(), $responseBody)));
105
+ return $httpClient;
106
+ }
107
+
108
+ /**
109
+ *
110
+ * @test
111
+ * @group statusTo
112
+ * @loadFixture bpostModuleConfig.yaml
113
+ * @doNotIndexAll
114
+ */
115
+ public function statusToReturnsTrueWhenShippingCarrierIsNotBpost()
116
+ {
117
+ $this->_api->setHttpClient($this->getHttpClientMock(200));
118
+ $order = $this->getOrderMock("300000003","shipping/carrier_flatrate");
119
+ $this->assertTrue($this->_api->statusTo($order,'OPEN'));
120
+ }
121
+
122
+ /**
123
+ *
124
+ * @test
125
+ * @group statusTo
126
+ * @loadFixture bpostModuleConfig.yaml
127
+ * @doNotIndexAll
128
+ */
129
+ public function confirmOrderToBpostPlatformReturnsTrueWhenApiIsNotEnabled()
130
+ {
131
+ $order = $this->getOrderMock("300000003","shippingmanager/carrier_bpost");
132
+
133
+ $shmHelper = $this->getShmHelperMock(array(), null, null, $apiUri);
134
+ $this->replaceByMock('helper', 'shippingmanager/data', $shmHelper);
135
+
136
+ $api = Mage::getModel("shippingmanager/api");
137
+ $api->setHttpClient($this->getHttpClientMock(200));
138
+
139
+ $this->assertTrue($api->statusTo($order));
140
+ }
141
+
142
+ /**
143
+ *
144
+ * @test
145
+ * @group statusTo
146
+ * @loadFixture bpostModuleConfig.yaml
147
+ * @doNotIndexAll
148
+ */
149
+ public function confirmOrderToBpostPlatformReturnsTrueWhenResponseIsSuccessfull()
150
+ {
151
+ $this->_api->setHttpClient($this->getHttpClientMock(200));
152
+ $order = $this->getOrderMock("300000003","shippingmanager/carrier_bpost");
153
+ $this->assertTrue($this->_api->statusTo($order));
154
+ }
155
+
156
+ /**
157
+ *
158
+ * @test
159
+ * @group statusTo
160
+ * @loadFixture bpostModuleConfig.yaml
161
+ * @doNotIndexAll
162
+ */
163
+ public function confirmOrderToBpostPlatformReturnsFalseWhenResponseIsNotSuccessfull()
164
+ {
165
+ $this->_api->setHttpClient($this->getHttpClientMock(405));
166
+ $order = $this->getOrderMock("300000003","shippingmanager/carrier_bpost");
167
+ $this->assertFalse($this->_api->statusTo($order));
168
+ }
169
+
170
+ /**
171
+ *
172
+ * @test
173
+ * @group statusTo
174
+ * @loadFixture bpostModuleConfig.yaml
175
+ * @doNotIndexAll
176
+ */
177
+ public function confirmOrderToBpostPlatformReturnsFalseWhenHttpResponseThrowsException()
178
+ {
179
+ $httpClient = $this->getHttpClientMock(405);
180
+ $httpClient->expects($this->any())
181
+ ->method('request')
182
+ ->will($this->throwException(New Exception("http client failed")));
183
+ $this->_api->setHttpClient($httpClient);
184
+ $order = $this->getOrderMock("300000003","shippingmanager/carrier_bpost");
185
+ $this->assertFalse($this->_api->statusTo($order));
186
+ }
187
+
188
+ /**
189
+ *
190
+ * Helper function for getProxyConfig
191
+ * @param string $proxyHost
192
+ * @param int $proxyPort
193
+ * @return array proxyConfig
194
+ */
195
+ private function getProxyConfig(string $proxyHost,int $proxyPort){
196
+ $shmHelper = $this->getShmHelperMock(array(), $proxyHost, $proxyPort);
197
+ $this->replaceByMock('helper', 'shippingmanager/data', $shmHelper);
198
+ $api = Mage::getModel("shippingmanager/Api");
199
+ return $api->getProxyConfig();
200
+ }
201
+
202
+ /**
203
+ *
204
+ * @test
205
+ * @group getProxyConfig
206
+ * @doNotIndexAll
207
+ */
208
+ public function getProxyConfigReturnsExpectedArrayWhenProxyHostAndProxyPortAreSet()
209
+ {
210
+ $expectedArray = array(
211
+ 'adapter' => 'Zend_Http_Client_Adapter_Proxy',
212
+ 'proxy_host' => "proxy.host.com",
213
+ 'proxy_port' => 8020
214
+ );
215
+ $this->assertEquals($expectedArray, $this->getProxyConfig($expectedArray["proxy_host"], $expectedArray["proxy_port"]));
216
+ }
217
+
218
+ /**
219
+ *
220
+ * @test
221
+ * @group getProxyConfig
222
+ * @doNotIndexAll
223
+ */
224
+ public function getProxyConfigReturnsExpectedArrayWhenOnlyProxyHostAreSet()
225
+ {
226
+ $expectedArray = array(
227
+ 'adapter' => 'Zend_Http_Client_Adapter_Proxy',
228
+ 'proxy_host' => "proxy.host.com",
229
+ 'proxy_port' => null
230
+ );
231
+ $this->assertEquals($expectedArray, $this->getProxyConfig($expectedArray["proxy_host"], null));
232
+ }
233
+
234
+ /**
235
+ *
236
+ * @test
237
+ * @group getProxyConfig
238
+ * @doNotIndexAll
239
+ */
240
+ public function getProxyConfigReturnsEmptyArrayWhenOnlyProxyHostIsNotSet()
241
+ {
242
+ $this->assertEquals(array(), $this->getProxyConfig(null, null));
243
+ }
244
+
245
+ /**
246
+ *
247
+ * @test
248
+ * @group getHttpRequestUri
249
+ * @doNotIndexAll
250
+ */
251
+ public function getHttpRequestUri()
252
+ {
253
+ $shmHelper = $this->getShmHelperMock(array(), null, null, "https://api.host.be/");
254
+ $this->replaceByMock('helper', 'shippingmanager/data', $shmHelper);
255
+
256
+ $api = Mage::getModel("shippingmanager/Api");
257
+ $this->assertEquals("https://api.host.be/orders/status", $api->getHttpRequestUri("orders/status"));
258
+ }
259
+
260
+ /**
261
+ * @test
262
+ * @group labelcreation
263
+ * @doNotIndexAll
264
+ */
265
+ public function getOrderRefLabelAmountMapXml(){
266
+ $orderReference = "201106241506";
267
+ $expectedXml = <<<XML
268
+ <?xml version="1.0" encoding="UTF-8"?>
269
+ <orderRefLabelAmountMap xmlns="http://schema.post.be/shm/deepintegration/v1/">
270
+ <entry>
271
+ <orderReference>$orderReference</orderReference>
272
+ <labelAmount>1</labelAmount>
273
+ <withRetour>false</withRetour>
274
+ <returnLabels>1</returnLabels>
275
+ </entry>
276
+ </orderRefLabelAmountMap>
277
+ XML;
278
+ $this->assertEquals($expectedXml, $this->_api->getOrderRefLabelAmountMapXml($orderReference));
279
+ }
280
+
281
+ /**
282
+ * @test
283
+ * @group labelcreation
284
+ * @doNotIndexAll
285
+ */
286
+ public function getBarcodeFromOrderRefBarcodeMapXml(){
287
+ $barCode = "323212345659900000001030";
288
+ $orderRefBarcodeMapXml = <<<XML
289
+ <?xml version="1.0" encoding="UTF-8"?>
290
+ <orderRefBarcodeMap xmlns="http://schema.post.be/shm/deepintegration/v1/">
291
+ <entry>
292
+ <orderReference>201106241506</orderReference>
293
+ <barcode>$barCode</barcode>
294
+ </entry>
295
+ </orderRefBarcodeMap>
296
+ XML;
297
+ $this->assertEquals($barCode, $this->_api->getBarcodeFromOrderRefBarcodeMapXml($orderRefBarcodeMapXml));
298
+ }
299
+
300
+ /**
301
+ * @test
302
+ * @group labelcreation
303
+ * @doNotIndexAll
304
+ */
305
+ public function getBarcodeFromOrderRefBarcodeMapXmlReturnsEmptyStringWhenXmlCanNotBeParsed()
306
+ {
307
+ $this->assertEquals("", $this->_api->getBarcodeFromOrderRefBarcodeMapXml(""));
308
+ }
309
+
310
+ /**
311
+ * @test
312
+ * @group labelcreation
313
+ * @doNotIndexAll
314
+ */
315
+ public function fetchOrderRefBarcodeMapXml(){
316
+ $orderReference = "201106241506";
317
+ $barCode = "323212345659900000001030";
318
+ $orderRefBarcodeMapXml = <<<XML
319
+ <?xml version="1.0" encoding="UTF-8"?>
320
+ <orderRefBarcodeMap xmlns="http://schema.post.be/shm/deepintegration/v1/">
321
+ <entry>
322
+ <orderReference>$orderReference</orderReference>
323
+ <barcode>$barCode</barcode>
324
+ </entry>
325
+ </orderRefBarcodeMap>
326
+ XML;
327
+ $this->_api->setHttpClient($this->getHttpClientMock(200, $orderRefBarcodeMapXml));
328
+ $this->assertEquals($orderRefBarcodeMapXml, $this->_api->fetchOrderRefBarcodeMapXml($orderReference));
329
+ }
330
+
331
+ /**
332
+ * @test
333
+ * @group labelcreation
334
+ * @doNotIndexAll
335
+ */
336
+ function createBarCodeForOrderReference(){
337
+ $orderReference = "201106241506";
338
+ $barCode = "323212345659900000001030";
339
+ $orderRefBarcodeMapXml = <<<XML
340
+ <?xml version="1.0" encoding="UTF-8"?>
341
+ <orderRefBarcodeMap xmlns="http://schema.post.be/shm/deepintegration/v1/">
342
+ <entry>
343
+ <orderReference>$orderReference</orderReference>
344
+ <barcode>$barCode</barcode>
345
+ </entry>
346
+ </orderRefBarcodeMap>
347
+ XML;
348
+ $this->_api->setHttpClient($this->getHttpClientMock(200, $orderRefBarcodeMapXml));
349
+ $this->assertEquals($barCode, $this->_api->createBarCodeForOrderReference($orderReference));
350
+ }
351
+
352
+ /**
353
+ *
354
+ * @test
355
+ * @group labelprinting
356
+ * @doNotIndexAll
357
+ */
358
+ function fetchPdfXml()
359
+ {
360
+ $pdfXml = <<<XML
361
+ <?xml version="1.0" encoding="UTF-8"?>
362
+ <pdf xmlns="http://schema.post.be/shm/deepintegration/v1/">
363
+ JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9GaWx0ZXIvRENURGVjb2RlL1R5cGUvWE9iamVjdC9MZW5ndGggMzAyMS9CaXRzUGVyQ29tcG9uZW50IDgvSGVpZ2h0IDMxL0NvbG9yU3BhY2UvRGV2aWNlUkdCL1N1YnR5cGUvSW1hZ2UvV2lkdGggMzk2Pj5zdHJlYW0K/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAfAYwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqD
364
+ </pdf>
365
+ XML;
366
+ $this->_api->setHttpClient($this->getHttpClientMock(200, $pdfXml));
367
+ $this->assertEquals($pdfXml, $this->_api->fetchPdfXml('order',$orderReference));
368
+ }
369
+
370
+ /**
371
+ * @test
372
+ * @group labelprinting
373
+ */
374
+ function getPdfContentFromPdfXml()
375
+ {
376
+ $pdfContent = "JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9GaWx0ZXIvRENURGVjb2RlL1R5cGUvWE9iamVjdC9MZW5ndGggMzAyMS9CaXRzUGVyQ29tcG9uZW50IDgvSGVpZ2h0IDMxL0NvbG9yU3BhY2UvRGV2aWNlUkdCL1N1YnR5cGUvSW1hZ2UvV2lkdGggMzk2Pj5zdHJlYW0K/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAfAYwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqD";
377
+ $pdfXml = <<<XML
378
+ <?xml version="1.0" encoding="UTF-8"?>
379
+ <pdf xmlns="http://schema.post.be/shm/deepintegration/v1/">$pdfContent</pdf>
380
+ XML;
381
+ $this->_api->setHttpClient($this->getHttpClientMock(200, $pdfXml));
382
+ $this->assertEquals($pdfContent, $this->_api->getPdfContentFromPdfXml($pdfXml));
383
+ }
384
+
385
+ /**
386
+ * @test
387
+ * @group labelprinting
388
+ * @doNotIndexAll
389
+ */
390
+ function getPdfContentForOrderReference()
391
+ {
392
+ $orderReference = "000001";
393
+ $pdfContent = "JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9GaWx0ZXIvRENURGVjb2RlL1R5cGUvWE9iamVjdC9MZW5ndGggMzAyMS9CaXRzUGVyQ29tcG9uZW50IDgvSGVpZ2h0IDMxL0NvbG9yU3BhY2UvRGV2aWNlUkdCL1N1YnR5cGUvSW1hZ2UvV2lkdGggMzk2Pj5zdHJlYW0K/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAfAYwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqD";
394
+ $pdfContentEncoded = base64_encode($pdfContent);
395
+ $pdfXml = <<<XML
396
+ <?xml version="1.0" encoding="UTF-8"?>
397
+ <pdf xmlns="http://schema.post.be/shm/deepintegration/v1/">$pdfContentEncoded</pdf>
398
+ XML;
399
+ $this->_api->setHttpClient($this->getHttpClientMock(200, $pdfXml));
400
+ $this->assertEquals($pdfContent, $this->_api->getPdfContentForOrderReference($orderReference));
401
+ }
402
+
403
+ /**
404
+ * @test
405
+ * @group labelprinting
406
+ * @doNotIndexAll
407
+ */
408
+ public function getPdfContentForBarcode()
409
+ {
410
+ $barcode = "000001";
411
+ $pdfContent = "JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9GaWx0ZXIvRENURGVjb2RlL1R5cGUvWE9iamVjdC9MZW5ndGggMzAyMS9CaXRzUGVyQ29tcG9uZW50IDgvSGVpZ2h0IDMxL0NvbG9yU3BhY2UvRGV2aWNlUkdCL1N1YnR5cGUvSW1hZ2UvV2lkdGggMzk2Pj5zdHJlYW0K/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAfAYwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqD";
412
+ $pdfContentEncoded = base64_encode($pdfContent);
413
+ $pdfXml = <<<XML
414
+ <?xml version="1.0" encoding="UTF-8"?>
415
+ <pdf xmlns="http://schema.post.be/shm/deepintegration/v1/">$pdfContentEncoded</pdf>
416
+ XML;
417
+ $this->_api->setHttpClient($this->getHttpClientMock(200, $pdfXml));
418
+ $this->assertEquals($pdfContent, $this->_api->getPdfContentForBarcode($barcode));
419
+ }
420
+
421
+ }
app/code/community/Bpost/ShippingManager/Test/Model/Api/fixtures/bpostModuleConfig.yaml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/account_id: 105704
3
+ default/carriers/bpost/passphrase: secret
4
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
5
+ default/carriers/bpost/api_uri: https://api.bpost.be/services/shm/
6
+ default/carriers/bpost/title: bpost
7
+ default/carriers/bpost/active: 1
8
+ default/carriers/bpost/proxy_host: proxy.iconos.be
9
+ default/carriers/bpost/proxy_port: 8080
10
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
11
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
12
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "0", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Bpost.php ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @group carrierBpost
5
+ *
6
+ */
7
+ class Bpost_ShippingManager_Test_Model_Carrier_Bpost
8
+ extends EcomDev_PHPUnit_Test_Case
9
+ {
10
+ private $_carrier;
11
+
12
+ public function setUp(){
13
+ parent::setUp();
14
+ $this->_carrier = Mage::getModel("shippingmanager/carrier_bpost");
15
+ }
16
+
17
+ private function setCheckoutCartMock($subtotal, $multishipping = false, $currencyCode = "EUR")
18
+ {
19
+ $shippingAddress = $this->getModelMock('sales/quote_address',array('getWeight'));
20
+ $shippingAddress->expects($this->any())
21
+ ->method("getWeight")
22
+ ->will($this->returnValue(0));
23
+
24
+ $total = $this->getModelMock('sales/quote_address_total_abstract',array('getValue'));
25
+ $total->expects($this->any())
26
+ ->method("getValue")
27
+ ->will($this->returnValue($subtotal));
28
+
29
+ $quote = $this->getModelMock('sales/quote',array('getTotals', 'getData', 'getQuoteCurrencyCode', 'getShippingAddress'));
30
+ $quote->expects($this->any())
31
+ ->method("getTotals")
32
+ ->will($this->returnValue(array("subtotal" => $total)));
33
+ if($multishipping != null){
34
+ $quote->expects($this->any())
35
+ ->method("getdata")
36
+ ->with($this->equalTo('is_multi_shipping'))
37
+ ->will($this->returnValue($multishipping));
38
+ }
39
+ $quote->expects($this->any())
40
+ ->method("getQuoteCurrencyCode")
41
+ ->will($this->returnValue($currencyCode));
42
+ $quote->expects($this->any())
43
+ ->method("getShippingAddress")
44
+ ->will($this->returnValue($shippingAddress));
45
+
46
+ $checkoutCart = $this->getModelMock('checkout/cart',array('getQuote'));
47
+ $checkoutCart->expects($this->any())
48
+ ->method("getQuote")
49
+ ->will($this->returnValue($quote));
50
+
51
+ $checkoutSession = $this->getModelMock('checkout/session',array('getQuote'));
52
+ $checkoutSession->expects($this->any())
53
+ ->method("getQuote")
54
+ ->will($this->returnValue($quote));
55
+
56
+ $this->replaceByMock('model', 'checkout/session', $checkoutSession);
57
+
58
+ $this->replaceByMock('model', 'checkout/cart', $checkoutCart);
59
+ return $checkoutCart;
60
+ }
61
+ /**
62
+ *
63
+ * @test
64
+ * @loadFixture bpostModuleConfig.yaml
65
+ * @group isTrackingAvailable
66
+ * @group getTracking
67
+ * @doNotIndexAll
68
+ */
69
+ public function isTrackingAvailableIsAlwaysTrue()
70
+ {
71
+ $this->assertTrue($this->_carrier->isTrackingAvailable());
72
+ }
73
+
74
+ /**
75
+ *
76
+ * @test
77
+ * @loadFixture bpostModuleConfig.yaml
78
+ * @group isTrackingAvailable
79
+ * @doNotIndexAll
80
+ */
81
+ public function getCarrierCodeReturnsStringBpost()
82
+ {
83
+ $this->assertEquals("bpost", $this->_carrier->getCarrierCode());
84
+ }
85
+
86
+ /**
87
+ *
88
+ * returns request mock object.
89
+ * @param integer $packageWeight
90
+ * @return ModelMock shipping_rate_request
91
+ */
92
+ private function getShippingRateRequestMock($packageWeight)
93
+ {
94
+ $request = $this->getModelMock('sales/shipping_rate_request',array('getPackageWeight'));
95
+ $request->expects($this->any())
96
+ ->method("getPackageWeight")
97
+ ->will($this->returnValue($packageWeight));
98
+ return $request;
99
+ }
100
+
101
+
102
+ /**
103
+ *
104
+ * Helper function to test collect rates
105
+ */
106
+ private function collectRates($enabled, array $allowedMethods = array(), $multishipping = false, $currencyCode = "EUR"){
107
+ $this->setCheckoutCartMock(null, $multishipping, $currencyCode);
108
+ $shippingManagerMock =$this->getModelMock("shippingmanager/shippingManager");
109
+ $shippingManagerMock->expects($this->any())
110
+ ->method("enabled")
111
+ ->will($this->returnValue($enabled));
112
+ $shippingManagerMock->expects($this->any())
113
+ ->method("getAllowedMethods")
114
+ ->will($this->returnValue($allowedMethods));
115
+ $this->replaceByMock("singleton", "shippingmanager/shippingManager", $shippingManagerMock);
116
+ $carrier = Mage::getModel("shippingmanager/carrier_bpost");
117
+ return $carrier->collectRates($request);
118
+ }
119
+
120
+ /**
121
+ *
122
+ * @test
123
+ * @loadFixture bpostModuleConfig.yaml
124
+ * @group collectRates
125
+ * @doNotIndexAll
126
+ */
127
+ public function collectRatesReturnsFalseWhenShippingManagerIsNotEnabled()
128
+ {
129
+ $this->assertFalse($this->collectRates(false, array(), null));
130
+ }
131
+
132
+ /**
133
+ *
134
+ * @test
135
+ * @loadFixture bpostModuleConfig.yaml
136
+ * @group collectRates
137
+ * @doNotIndexAll
138
+ */
139
+ public function collectRatesReturnsFalseWhenThereAreNoAllowedMethods()
140
+ {
141
+ $this->assertFalse($this->collectRates(true, array()));
142
+ }
143
+
144
+ /**
145
+ *
146
+ * @test
147
+ * @loadFixture bpostModuleConfig.yaml
148
+ * @group collectRates
149
+ * @doNotIndexAll
150
+ */
151
+ public function collectRatesReturnsFalseWhenQuoteIsMultiShipping()
152
+ {
153
+ $allowedShippingMethods = array("pugo" => "BPACK@bpost", "regular" => "BPACK@home");
154
+ $this->assertFalse($this->collectRates(true, $allowedShippingMethods, true));
155
+ }
156
+
157
+ /**
158
+ *
159
+ * @test
160
+ * @loadFixture bpostModuleConfig.yaml
161
+ * @group collectRates
162
+ * @doNotIndexAll
163
+ */
164
+ public function collectRatesReturnsFalseWhenQuoteCurrencyIsNotEuro()
165
+ {
166
+ $allowedShippingMethods = array("pugo" => "BPACK@bpost", "regular" => "BPACK@home");
167
+ $this->assertFalse($this->collectRates(true, $allowedShippingMethods, false, "USD"));
168
+ }
169
+
170
+ /**
171
+ *
172
+ * @test
173
+ * @loadFixture bpostModuleConfig.yaml
174
+ * @group collectRates
175
+ * @doNotIndexAll
176
+ */
177
+ public function collectRatesReturnsRateResultObject()
178
+ {
179
+ $allowedShippingMethods = array("pugo" => "BPACK@bpost", "regular" => "BPACK@home");
180
+ $rateResult = $this->collectRates(true, $allowedShippingMethods);
181
+ $this->assertInstanceOf("Mage_Shipping_Model_Rate_Result", $rateResult);
182
+ $rates = $rateResult->getAllRates();
183
+ $this->assertEquals(count($allowedShippingMethods), count($rates));
184
+ foreach($rates as $rate){
185
+ $this->assertEquals("bpost", $rate->getCarrierTitle());
186
+ $this->assertEquals("bpost", $rate->getCarrier());
187
+ $this->assertTrue(array_key_exists($rate->getMethod(), $allowedShippingMethods));
188
+ if($rate->getMethod() == "pugo"){
189
+ $this->assertEquals("BPACK@bpost" , $rate->getmethodTitle());
190
+ $this->assertEquals(12, $rate->getPrice());
191
+ $this->assertEquals(12, $rate->getCost());
192
+ }
193
+ if($rate->getMethod() == "regular"){
194
+ $this->assertEquals("BPACK@home" , $rate->getmethodTitle());
195
+ $this->assertEquals(0, $rate->getPrice());
196
+ $this->assertEquals(0, $rate->getCost());
197
+ }
198
+ }
199
+ }
200
+
201
+ /**
202
+ *
203
+ * @test
204
+ * @loadFixture bpostModuleConfig.yaml
205
+ * @group collectRates
206
+ * @doNotIndexAll
207
+ */
208
+ public function collectRatesReturnsRateIgnoresUnknownShippingMethod()
209
+ {
210
+ $allowedShippingMethods = array("unknown" => "BPACK@bpost", "regular" => "BPACK@home");
211
+ $rateResult = $this->collectRates(true, $allowedShippingMethods);
212
+ $this->assertInstanceOf("Mage_Shipping_Model_Rate_Result", $rateResult);
213
+ }
214
+
215
+ /**
216
+ *
217
+ * @test
218
+ * @loadFixture bpostModuleConfig.yaml
219
+ * @group getTracking
220
+ * @doNotIndexAll
221
+ */
222
+ public function getTracking()
223
+ {
224
+ $carrier = Mage::getModel("shippingmanager/carrier_bpost");
225
+ $trackingResult = $carrier->getTracking("112233445566");
226
+ $this->assertInstanceOf("Mage_Shipping_Model_Tracking_Result", $trackingResult);
227
+ $trackingResultStatus = $trackingResult->getAllTrackings();
228
+ $this->assertEquals(1, count($trackingResultStatus));
229
+ $trackingResultStatus = $trackingResultStatus[0];
230
+ $this->assertInstanceOf("Mage_Shipping_Model_Tracking_Result_Status", $trackingResultStatus);
231
+ $this->assertEquals("bpost", $trackingResultStatus->getCarrier());
232
+ $this->assertEquals('<img height="50" alt="bpost" src="' . Mage::getDesign()->getSkinUrl('images/bpost/shippingmanager/track_and_trace.jpg') . '" />', $trackingResultStatus->getCarrierTitle());
233
+ $this->assertEquals("112233445566", $trackingResultStatus->getTracking());
234
+ $this->assertEquals('<a target="_blank" href="http://www.bpost.be/etr/light/performSearch.do?searchByItemCode=true&itemCodes=112233445566&oss_language=nl">Track this Parcel</a>', $trackingResultStatus->getStatus());
235
+ }
236
+
237
+ /**
238
+ *
239
+ * @test
240
+ * @loadFixture bpostModuleConfig.yaml
241
+ * @group getTrackingInfo
242
+ * @group getTracking
243
+ * @doNotIndexAll
244
+ */
245
+ public function getTrackingInfo()
246
+ {
247
+ $carrier = Mage::getModel("shippingmanager/carrier_bpost");
248
+ $trackingResultStatus = $carrier->getTrackingInfo("112233445566");
249
+ $this->assertInstanceOf("Mage_Shipping_Model_Tracking_Result_Status", $trackingResultStatus);
250
+ $this->assertEquals("bpost", $trackingResultStatus->getCarrier());
251
+ $this->assertEquals('<img height="50" alt="bpost" src="' . Mage::getDesign()->getSkinUrl('images/bpost/shippingmanager/track_and_trace.jpg') . '" />', $trackingResultStatus->getCarrierTitle());
252
+ $this->assertEquals("112233445566", $trackingResultStatus->getTracking());
253
+ $this->assertEquals('<a target="_blank" href="http://www.bpost.be/etr/light/performSearch.do?searchByItemCode=true&itemCodes=112233445566&oss_language=nl">Track this Parcel</a>', $trackingResultStatus->getStatus());
254
+ }
255
+
256
+ }
app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Bpost/fixtures/bpostModuleConfig.yaml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/account_id: 105704
3
+ default/carriers/bpost/passphrase: secret
4
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
5
+ default/carriers/bpost/title: bpost
6
+ default/carriers/bpost/active: 1
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
9
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
10
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
11
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
12
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "0", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Bpost/fixtures/carrierDeactivated.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/active: 0
3
+ default/carriers/bpost/account_id: 105704
4
+ default/carriers/bpost/passphrase: secret
5
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
6
+ default/carriers/bpost/title: bpost
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
9
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
10
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
11
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "0", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Shippingmethod/Abstract.php ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php /**
2
+ *
3
+ * @group shippingmethod
4
+ *
5
+ */
6
+ class Bpost_ShippingManager_Test_Model_Carrier_Shippingmethod_Abstract
7
+ extends EcomDev_PHPUnit_Test_Case {
8
+
9
+ private $_method;
10
+ private $_tableRates = '{"@shop" : "12","@home" : "0", "BPACK24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}';
11
+
12
+ public function setUp(){
13
+ parent::setUp();
14
+
15
+ //because we can not test an abstract class we will test with Regular
16
+ $this->_method = Mage::getModel("shippingmanager/Carrier_Shippingmethod_Regular");
17
+ }
18
+
19
+ private function setCheckoutCartMock($subtotal, $weight = 0)
20
+ {
21
+ $shippingAddress = $this->getModelMock('sales/quote_address',array('getWeight'));
22
+ $shippingAddress->expects($this->any())
23
+ ->method("getWeight")
24
+ ->will($this->returnValue($weight));
25
+ $total = $this->getModelMock('sales/quote_address_total_abstract',array('getValue'));
26
+ $total->expects($this->any())
27
+ ->method("getValue")
28
+ ->will($this->returnValue($subtotal));
29
+
30
+ $quote = $this->getModelMock('sales/quote',array('getTotals', 'getShippingAddress'));
31
+ $quote->expects($this->any())
32
+ ->method("getTotals")
33
+ ->will($this->returnValue(array("subtotal" => $total)));
34
+ $quote->expects($this->any())
35
+ ->method("getShippingAddress")
36
+ ->will($this->returnValue($shippingAddress));
37
+
38
+ $checkoutCart = $this->getModelMock('checkout/cart',array('getQuote'));
39
+ $checkoutCart->expects($this->any())
40
+ ->method("getQuote")
41
+ ->will($this->returnValue($quote));
42
+
43
+ $checkoutSession = $this->getModelMock('checkout/session',array('getQuote'));
44
+ $checkoutSession->expects($this->any())
45
+ ->method("getQuote")
46
+ ->will($this->returnValue($quote));
47
+
48
+ $this->replaceByMock('model', 'checkout/session', $checkoutSession);
49
+ $this->replaceByMock('model', 'checkout/cart', $checkoutCart);
50
+ return $checkoutCart;
51
+ }
52
+
53
+ private function getShmHelperMock($optionalMethods)
54
+ {
55
+ $methods = array_merge(array("log"), $optionalMethods);
56
+ $shmHelper = $this->getHelperMock('shippingmanager/data',$methods);
57
+ $shmHelper->expects($this->any())
58
+ ->method("log")
59
+ ->will($this->returnValue(null));
60
+ return $shmHelper;
61
+ }
62
+
63
+ /**
64
+ *
65
+ * Helper function to test hasFreeDelivery
66
+ * @param unknown_type $quoteAmount
67
+ * @param unknown_type $configuredAmount
68
+ */
69
+
70
+ private function hasFreeDelivery($quoteAmount, $configuredAmount)
71
+ {
72
+
73
+ $this->setCheckoutCartMock($quoteAmount);
74
+
75
+ $shmHelper = $this->getShmHelperMock(array('getFreeDeliveryWhenCartValueBiggerThen'));
76
+ $shmHelper->expects($this->any())
77
+ ->method("getFreeDeliveryWhenCartValueBiggerThen")
78
+ ->will($this->returnValue($configuredAmount));
79
+ $this->replaceByMock('helper', 'shippingmanager/data', $shmHelper);
80
+
81
+ return $this->_method->hasFreeDelivery();
82
+ }
83
+
84
+ /**
85
+ *
86
+ * @test
87
+ * @group hasFreeDelivery
88
+ * @loadFixture bpostModuleConfig.yaml
89
+ * @doNotIndexAll
90
+ */
91
+ public function FreeDeliveryWhenQuotePriceBiggerThenConfigParameterFreeDeliveryWhenCartValueBiggerThen()
92
+ {
93
+ $this->assertTrue($this->hasFreeDelivery(200, 100));
94
+ }
95
+
96
+ /**
97
+ *
98
+ * @test
99
+ * @group hasFreeDelivery
100
+ * @doNotIndexAll
101
+ */
102
+ public function noFreeDeliveryWhenQuotePriceLessThenConfigParameterFreeDeliveryWhenCartValueBiggerThen()
103
+ {
104
+ $this->assertFalse($this->hasFreeDelivery(50, 100));
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @test
110
+ * @group hasFreeDelivery
111
+ * @doNotIndexAll
112
+ */
113
+ public function noFreeDeliveryWhenQuotePriceEqualsConfigParameterFreeDeliveryWhenCartValueBiggerThen()
114
+ {
115
+ $this->assertTrue($this->hasFreeDelivery(100, 100));
116
+ }
117
+
118
+ /**
119
+ *
120
+ * @test
121
+ * @group hasFreeDelivery
122
+ * @doNotIndexAll
123
+ */
124
+ public function noFreeDeliveryWhenNotSetInConfigParameterFreeDeliveryWhenCartValueBiggerThen()
125
+ {
126
+ $this->assertFalse($this->hasFreeDelivery(50, null));
127
+ }
128
+
129
+ /**
130
+ *
131
+ * Helper function to prepare shippingManagerDecidesQuotes test
132
+ * @param integer $FreeDeliveryWhenCartValueBiggerThen
133
+ * @param jsonstring $rateTable
134
+ */
135
+ private function shippingManagerDecidesQuotes($FreeDeliveryWhenCartValueBiggerThen, $rateTable){
136
+ $shmHelper = $this->getShmHelperMock(array('getFreeDeliveryWhenCartValueBiggerThen', 'getRateTable'));
137
+ $shmHelper->expects($this->any())
138
+ ->method("getFreeDeliveryWhenCartValueBiggerThen")
139
+ ->will($this->returnValue($FreeDeliveryWhenCartValueBiggerThen));
140
+
141
+ $shmHelper->expects($this->any())
142
+ ->method("getRateTable")
143
+ ->will($this->returnValue($rateTable));
144
+ $this->replaceByMock('helper', 'shippingmanager/data', $shmHelper);
145
+
146
+ $this->setCheckoutCartMock(100);
147
+
148
+ return $this->_method->shippingManagerDecidesQuotes();
149
+ }
150
+
151
+ /**
152
+ *
153
+ * @test
154
+ * @group shippingManagerDecidesQuotes
155
+ * @doNotIndexAll
156
+ */
157
+ public function shippingManagerDecidesQuotesWhenTableRatesIsNotSetAndFreeDeliveryIsNotSet()
158
+ {
159
+ $this->assertTrue($this->shippingManagerDecidesQuotes(null, null));
160
+ }
161
+
162
+ /**
163
+ *
164
+ * @test
165
+ * @group shippingManagerDecidesQuotes
166
+ * @doNotIndexAll
167
+ */
168
+ public function shippingManagerDoesNotDecidesQuotesWhenTableRatesAreNotSpecifiedAndFreeDeliveryIsApplicable()
169
+ {
170
+ $this->assertFalse($this->shippingManagerDecidesQuotes(50, null));
171
+ }
172
+
173
+ /**
174
+ *
175
+ * @test
176
+ * @group shippingManagerDecidesQuotes
177
+ * @doNotIndexAll
178
+ */
179
+ public function shippingManagerDecidesQuotesWhenTableRatesAreNotSpecifiedAndFreeDeliveryNotIsApplicable()
180
+ {
181
+ $this->assertTrue($this->shippingManagerDecidesQuotes(150, null));
182
+ }
183
+
184
+ /**
185
+ *
186
+ * @test
187
+ * @group shippingManagerDecidesQuotes
188
+ * @doNotIndexAll
189
+ */
190
+ public function shippingManagerDoesNotDecidesQuotesWhenTableRatesAreSpecifiedAndFreeDeliveryIsNotSet()
191
+ {
192
+ $this->assertFalse($this->shippingManagerDecidesQuotes(null, $this->_tableRates));
193
+ }
194
+
195
+ /**
196
+ *
197
+ * @test
198
+ * @group shippingManagerDecidesQuotes
199
+ * @doNotIndexAll
200
+ */
201
+ public function shippingManagerDoesNotDecidesQuotesWhenTableRatesAreSpecifiedAndFreeDeliveryNotIsApplicable()
202
+ {
203
+ $this->assertFalse($this->shippingManagerDecidesQuotes(150, $this->_tableRates));
204
+ }
205
+
206
+ /**
207
+ *
208
+ * @test
209
+ * @group shippingManagerDecidesQuotes
210
+ * @doNotIndexAll
211
+ */
212
+ public function shippingManagerDoesNotDecidesQuotesWhenTableRatesAreSpecifiedAndFreeDeliveryIsApplicable()
213
+ {
214
+ $this->assertFalse($this->shippingManagerDecidesQuotes(50, $this->_tableRates));
215
+ }
216
+
217
+ /**
218
+ *
219
+ * returns request mock object.
220
+ * @param integer $packageWeight
221
+ * @return ModelMock shipping_rate_request
222
+ */
223
+ private function getShippingRateRequestMock($packageWeight)
224
+ {
225
+ $request = $this->getModelMock('sales/shipping_rate_request',array('getPackageWeight'));
226
+ $request->expects($this->any())
227
+ ->method("getPackageWeight")
228
+ ->will($this->returnValue($packageWeight));
229
+ return $request;
230
+ }
231
+
232
+ /**
233
+ *
234
+ * Helper function to prepare getCost tests
235
+ * @param integer $FreeDeliveryWhenCartValueBiggerThen
236
+ * @param jsonstring $rateTable
237
+ * @return returnvalue getcost method
238
+ */
239
+ private function getCost($FreeDeliveryWhenCartValueBiggerThen, $rateTable, $packageWeight)
240
+ {
241
+
242
+ $this->shippingManagerDecidesQuotes($FreeDeliveryWhenCartValueBiggerThen, $rateTable);
243
+ $this->setCheckoutCartMock(100,$packageWeight);
244
+
245
+ return Mage::getModel("shippingmanager/Carrier_Shippingmethod_Regular")->getCost($this->getShippingRateRequestMock($packageWeight));
246
+ }
247
+
248
+ /**
249
+ *
250
+ * @test
251
+ * @group getCost
252
+ * @doNotIndexAll
253
+ */
254
+ public function getCostReturnsNullWhenShippingManagerDecidesQuote()
255
+ {
256
+ $this->assertNull($this->getCost(null, null, 20));
257
+ }
258
+
259
+ /**
260
+ *
261
+ * @test
262
+ * @group getCost
263
+ * @doNotIndexAll
264
+ */
265
+ public function getCostReturnsNullWhenFreeDeliveryIsApplicable()
266
+ {
267
+ $this->assertNull($this->getCost(50, null, 20));
268
+ }
269
+
270
+ /**
271
+ *
272
+ * @test
273
+ * @group getCost
274
+ * @doNotIndexAll
275
+ */
276
+ public function getCostReturnsPriceNotBasedOnWeightSetInRateTable()
277
+ {
278
+ $this->assertEquals(66, $this->getCost(null, "66", 20));
279
+ }
280
+
281
+ /**
282
+ *
283
+ * @test
284
+ * @group getCost
285
+ * @doNotIndexAll
286
+ */
287
+ public function getCostReturnsPriceBasedOnWeightWhenSetInRateTable()
288
+ {
289
+ $this->assertEquals(30, $this->getCost(30, array("10" => '20', "20" => "30", "30" => "40"), 20));
290
+ }
291
+
292
+ /**
293
+ *
294
+ * @test
295
+ * @group getCostBasedOnWeight
296
+ * @doNotIndexAll
297
+ */
298
+ public function getCostBasedOnWeight()
299
+ {
300
+ $rateRules = array("0" => '2.90', "0.5" => "4.5", "5" => "8", "10" => "14");
301
+ $this->assertEquals(2.90, $this->_method->getCostBasedOnWeight(0, $rateRules));
302
+ $this->assertEquals(4.5, $this->_method->getCostBasedOnWeight(4.9, $rateRules));
303
+ $this->assertEquals(8, $this->_method->getCostBasedOnWeight(5.0, $rateRules));
304
+ $this->assertEquals(8, $this->_method->getCostBasedOnWeight(5.1, $rateRules));
305
+ $this->assertEquals(14, $this->_method->getCostBasedOnWeight(20, $rateRules));
306
+ }
307
+
308
+ /**
309
+ *
310
+ * @test
311
+ * @group getCostBasedOnWeight
312
+ * @expectedException Exception
313
+ * @doNotIndexAll
314
+ */
315
+ public function getCostBasedOnWeightThrowsExceptionWhenRateRulesAreInvalid()
316
+ {
317
+ $rateRules = null;
318
+ $this->_method->getCostBasedOnWeight($this->getShippingRateRequestMock(0), $rateRules);
319
+ }
320
+
321
+
322
+ }
app/code/community/Bpost/ShippingManager/Test/Model/Carrier/Shippingmethod/Abstract/fixtures/bpostModuleConfig.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/account_id: 105704
3
+ default/carriers/bpost/passphrase: secret
4
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
5
+ default/carriers/bpost/title: bpost
6
+ default/carriers/bpost/active: 1
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
9
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
10
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
11
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "0", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
app/code/community/Bpost/ShippingManager/Test/Model/Carrier/System/Config/Source/Method.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @group method
5
+ *
6
+ */
7
+ class Bpost_ShippingManager_Test_Model_Carrier_System_config_Source_Method
8
+ extends EcomDev_PHPUnit_Test_Case
9
+ {
10
+ private $_method;
11
+
12
+ public function setUp(){
13
+ parent::setUp();
14
+ $this->_method = Mage::getModel("shippingmanager/Carrier_System_config_Source_Method");
15
+ }
16
+
17
+ /**
18
+ * Test getAllOptions returns an array key, value for all methods selected in admin
19
+ *
20
+ * @test
21
+ * @loadFixture bpostModuleConfig.yaml
22
+ * @doNotIndexAll
23
+ */
24
+ public function getAllOptions()
25
+ {
26
+ $allOptions = array(
27
+ array("value" => "regular", "label" => "BPACK@home"),
28
+ array("value" => "pugo", "label" => "BPACK@bpost"),
29
+ array("value" => "parcelsdepot", "label" => "BPACK 24/7")
30
+ );
31
+ $this->assertEquals($allOptions, $this->_method->getAllOptions());
32
+ }
33
+
34
+ /**
35
+ * Test return array for getLinksBetweenShippingMethodsOfBpostAndMagento
36
+ *
37
+ * @test
38
+ * @doNotIndexAll
39
+ */
40
+ public function getLinksBetweenShippingMethodsOfBpostAndMagento()
41
+ {
42
+ $linksBetweenShippingMethodsOfBpostAndMagento = array(
43
+ "Parcels depot" => "parcelsdepot",
44
+ "Pugo" => "pugo",
45
+ "Regular" => "regular"/*,
46
+ "bpack BUSINESS" => "bpackbusiness",
47
+ "bpack EXPRESS" => "bpackexpress",*/
48
+ );
49
+
50
+ $this->assertEquals($linksBetweenShippingMethodsOfBpostAndMagento, $this->_method->getLinksBetweenShippingMethodsOfBpostAndMagento());
51
+ }
52
+
53
+ /**
54
+ * Test return array for getLinksBetweenShippingMethodsOfBpostAndMagento
55
+ *
56
+ * @depends getLinksBetweenShippingMethodsOfBpostAndMagento
57
+ * @test
58
+ * @doNotIndexAll
59
+ */
60
+ public function translateBpostCodeToMagentoCode()
61
+ {
62
+ $linksBetweenShippingMethodsOfBpostAndMagento = $this->_method->getLinksBetweenShippingMethodsOfBpostAndMagento();
63
+ foreach($linksBetweenShippingMethodsOfBpostAndMagento as $bpostCode => $MagentoCode){
64
+ $this->assertEquals($MagentoCode, $this->_method->translateBpostCodeToMagentoCode($bpostCode));
65
+ }
66
+
67
+ $this->assertEquals(null, $this->_method->translateBpostCodeToMagentoCode("unknown"));
68
+ }
69
+
70
+ /**
71
+ * Test return array for getLinksBetweenShippingMethodsOfBpostAndMagento
72
+ *
73
+ * @test
74
+ * @doNotIndexAll
75
+ */
76
+ public function getShippingMethods()
77
+ {
78
+ $magentoShippingMethods = array(
79
+ "parcelsdepot" => "BPACK 24/7",
80
+ "pugo" => "BPACK@bpost",
81
+ "regular" => "BPACK@home"/*,
82
+ "bpackbusiness" => "BPACK WORLD",
83
+ "bpackexpress" => "BPACK WORLD EXPRESS",*/
84
+ );
85
+ $this->assertEquals($magentoShippingMethods, $this->_method->getShippingMethods());
86
+ }
87
+
88
+ /**
89
+ * Test return array for getLinksBetweenShippingMethodsOfBpostAndMagento
90
+ *
91
+ * @depends getShippingMethods
92
+ * @test
93
+ * @doNotIndexAll
94
+ */
95
+ public function getShippingmethod()
96
+ {
97
+ $magentoShippingMethods = $this->_method->getShippingmethods();
98
+ foreach($magentoShippingMethods as $shippingMethodIdenifier => $shippingMethodTitle){
99
+ $this->assertEquals($shippingMethodTitle, $this->_method->getShippingmethod($shippingMethodIdenifier));
100
+ }
101
+
102
+ $this->assertEquals(null, $this->_method->getShippingmethod("unknown"));
103
+ }
104
+
105
+ /**
106
+ * Test return array for getLinksBetweenShippingMethodsOfBpostAndMagento
107
+ *
108
+ * @depends getShippingMethods
109
+ * @test
110
+ * @doNotIndexAll
111
+ */
112
+ public function getShippingMethodTitle()
113
+ {
114
+ $magentoShippingMethods = $this->_method->getShippingmethods();
115
+ foreach($magentoShippingMethods as $shippingMethodIdenifier => $shippingMethodTitle){
116
+ $this->assertEquals($shippingMethodTitle, $this->_method->getShippingMethodTitle($shippingMethodIdenifier));
117
+ }
118
+
119
+ $this->assertEquals(null, $this->_method->getShippingMethodTitle("unknown"));
120
+ }
121
+
122
+ /**
123
+ * Test return array for getEnabledShippingMethods
124
+ * @test
125
+ * @loadFixture bpostModuleConfig.yaml
126
+ * @doNotIndexAll
127
+ */
128
+ public function getEnabledShippingMethods()
129
+ {
130
+ $enabledShippingMethods = array(
131
+ "parcelsdepot" => "BPACK 24/7",
132
+ "pugo" => "BPACK@bpost",
133
+ "regular" => "BPACK@home"
134
+ );
135
+
136
+ $this->assertEquals($enabledShippingMethods, $this->_method->getEnabledShippingMethods());
137
+ }
138
+
139
+ /**
140
+ * Test return array for transformToOptionArray
141
+ * @test
142
+ * @loadFixture bpostModuleConfig.yaml
143
+ * @doNotIndexAll
144
+ */
145
+ public function transformToOptionArray()
146
+ {
147
+ $keyValueArray = array("shippingMethodIdentifier" => "shippingMethodTitle");
148
+ $this->assertEquals(array(array("value" => "shippingMethodIdentifier", "label" => "shippingMethodTitle")), $this->_method->transformToOptionArray($keyValueArray));
149
+ }
150
+
151
+ /**
152
+ * Test return array for toOptionArray
153
+ * @depends transformToOptionArray
154
+ * @test
155
+ * @loadFixture bpostModuleConfig.yaml
156
+ * @doNotIndexAll
157
+ */
158
+ public function toOptionArray()
159
+ {
160
+ $optionArray = array(
161
+ array("value" => "regular", "label" => "BPACK@home"),
162
+ array("value" => "pugo", "label" => "BPACK@bpost"),
163
+ array("value" => "parcelsdepot", "label" => "BPACK 24/7")/*,
164
+ array("value" => "bpackexpress", "label" => "BPACK WORLD EXPRESS"),
165
+ array("value" => "bpackbusiness", "label" => "BPACK WORLD")*/
166
+ );
167
+ $this->assertEquals($optionArray, $this->_method->toOptionArray());
168
+ }
169
+
170
+ }
app/code/community/Bpost/ShippingManager/Test/Model/Carrier/System/Config/Source/Method/fixtures/bpostModuleConfig.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/account_id: 105704
3
+ default/carriers/bpost/passphrase: secret
4
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
5
+ default/carriers/bpost/title: bpost
6
+ default/carriers/bpost/active: 1
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
9
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
10
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
11
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "0", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager.php ADDED
@@ -0,0 +1,536 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @group shippingManager
4
+ */
5
+ class Bpost_ShippingManager_Test_Model_ShippingManager
6
+ extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+
9
+ private $_shippingManager;
10
+
11
+ private $_checksumParameters = array(
12
+ "customerCountry" => "BE",
13
+ "accountId" => "105704",
14
+ "action" => "START",
15
+ "orderReference" => "reference_001"
16
+ );
17
+
18
+ public function setUp(){
19
+ parent::setUp();
20
+ $this->_shippingManager = Mage::getModel("shippingmanager/shippingManager");
21
+ }
22
+
23
+ /**
24
+ *
25
+ * Test helper to create a product mock object
26
+ * @param array $excludedBpostShippingmethods
27
+ * @return ModelMock $product
28
+ */
29
+ private function getProductMock($excludedBpostShippingmethods){
30
+ $product = $this->getModelMock('catalog/product',array('getExcludedBpostShippingmethods'));
31
+ $product->expects($this->any())
32
+ ->method("getExcludedBpostShippingmethods")
33
+ ->will($this->returnValue($excludedBpostShippingmethods));
34
+ return $product;
35
+ }
36
+
37
+ /**
38
+ * Test shipping manager is activated when passphrase and accountId are filled in
39
+ *
40
+ * @test
41
+ * @loadFixture bpostModuleConfig.yaml
42
+ * @doNotIndexAll
43
+ */
44
+ public function shippingManagerIsEnabledWhenPassphraseAccountidAndActiveAreSet()
45
+ {
46
+ $this->assertTrue($this->_shippingManager->enabled());
47
+ }
48
+
49
+ /**
50
+ * Test shipping manager is not activated when passphrase is not filled in
51
+ *
52
+ * @test
53
+ * @loadFixture passphraseNotFilledIn.yaml
54
+ * @doNotIndexAll
55
+ */
56
+ public function shippingManagerIsnotEnabledWhenPassphraseIsNotFilledIn()
57
+ {
58
+ $this->assertFalse($this->_shippingManager->enabled());
59
+ }
60
+
61
+ /**
62
+ * Test shipping manager is not activated when accountId is not filled in
63
+ *
64
+ * @test
65
+ * @loadFixture accountIdNotFilledIn.yaml
66
+ * @doNotIndexAll
67
+ */
68
+ public function shippingManagerIsnotEnabledWhenAccountIdIsNotFilledIn()
69
+ {
70
+ $this->assertFalse($this->_shippingManager->enabled());
71
+ }
72
+
73
+ /**
74
+ * Test shipping manager is not activated when active is not 0
75
+ *
76
+ * @test
77
+ * @loadFixture carrierDeactivated.yaml
78
+ * @doNotIndexAll
79
+ */
80
+ public function shippingManagerIsnotEnabledWhenActiveStatusIsFalse()
81
+ {
82
+ $this->assertFalse($this->_shippingManager->enabled());
83
+ }
84
+
85
+ /**
86
+ * Test checksum parameter array without deliverymethodOverides
87
+ *
88
+ * @test
89
+ * @loadFixture bpostModuleConfig.yaml
90
+ * @doNotIndexAll
91
+ */
92
+ public function getChecksumParametersWithoutDeliveryMethodsOverrides(){
93
+ $checksumParameters = $this->_checksumParameters + array("checksum" => "37b1542b729bc4d8e05071c034acbde53b4ce15e2b92d78c24d848b4b2ccd63a");
94
+ $this->assertEquals($checksumParameters, $this->_shippingManager->getChecksumParameters($checksumParameters["action"], $checksumParameters["orderReference"], $checksumParameters["customerCountry"]));
95
+ }
96
+
97
+ /**
98
+ * Test checksum parameter array with deliverymethodOverides
99
+ *
100
+ * @test
101
+ * @loadFixture bpostModuleConfig.yaml
102
+ * @doNotIndexAll
103
+ */
104
+ public function getChecksumParametersWithDeliveryMethodsOverrides(){
105
+ $checksumParameters = $this->_checksumParameters + array(
106
+ "deliveryMethodOverrides" => array("pugo" => "15", "regular" => "0"),
107
+ "checksum" => "b78920efe950bb72702385884ab61a29497f2cc5e0d6737b5045005f11137126"
108
+ );
109
+ $this->assertEquals($checksumParameters, $this->_shippingManager->getChecksumParameters($checksumParameters["action"], $checksumParameters["orderReference"], $checksumParameters["customerCountry"], $checksumParameters["deliveryMethodOverrides"]));
110
+ }
111
+
112
+ /**
113
+ * Test checksum
114
+ *
115
+ * @test
116
+ * @loadFixture bpostModuleConfig.yaml
117
+ * @doNotIndexAll
118
+ */
119
+ public function ChecksumIsGeneratedCorrect(){
120
+ $checksumParameters = $this->_checksumParameters + array("deliveryMethodOverrides" => array("pugo" => "15", "regular" => "0"));
121
+ $checksum = "b78920efe950bb72702385884ab61a29497f2cc5e0d6737b5045005f11137126";
122
+ $this->assertEquals($checksum, $this->_shippingManager->getChecksum($checksumParameters));
123
+
124
+ $this->assertEquals("", $this->_shippingManager->getChecksum(array()));
125
+ $this->assertEquals("", $this->_shippingManager->getChecksum(null));
126
+ }
127
+
128
+ /**
129
+ *
130
+ * @test
131
+ * @group getAllowedMethods
132
+ * @loadFixture bpostModuleConfig.yaml
133
+ * @doNotIndexAll
134
+ */
135
+ public function AllEnabledShippingMethodsAreReturnedWhenThereAreNoExcludedShippingMethodsInCart(){
136
+ $this->assertEquals(array("parcelsdepot" => "BPACK 24/7", "pugo" => "BPACK@bpost", "regular" => "BPACK@home"), $this->_shippingManager->getAllowedMethods());
137
+ }
138
+
139
+ /**
140
+ *
141
+ * @test
142
+ * @group getAllowedMethods
143
+ * @doNotIndexAll
144
+ */
145
+ public function getAllowedMethodsReturnsEmptyArrayWhenModuleIsNotactive(){
146
+ $this->assertEquals(array(), $this->_shippingManager->getAllowedMethods());
147
+ }
148
+
149
+
150
+ /**
151
+ *
152
+ * @test
153
+ * @group getAllowedMethods
154
+ * @loadFixture bpostModuleConfig.yaml
155
+ * @doNotIndexAll
156
+ */
157
+ public function excludedShippingMethodsAreRemovedFromAllowedMethods(){
158
+ $productIds = array(1, 2);
159
+ $excludedBpostShippingmethods = array("1" => "regular", "2" => "pugo");
160
+
161
+ $this->assertEquals(array("regular", "pugo"), $this->getExcludedShippingMethods($productIds, $excludedBpostShippingmethods));
162
+ $this->assertEquals(array("parcelsdepot" => "BPACK 24/7"), $this->_shippingManager->getAllowedMethods());
163
+ }
164
+
165
+ /**
166
+ *
167
+ * test helper to test getExcludedShippingMethods
168
+ * @param array $productIdsArray
169
+ * @param array $excludedBpostShippingmethods
170
+ * @return returnvalue getExcludedShippingMethods
171
+ */
172
+ private function getExcludedShippingMethods($productIdsArray, $excludedBpostShippingmethods){
173
+ $this->setCheckoutCartMock($productIdsArray);
174
+
175
+ $product = $this->getModelMock('catalog/product',array('load', 'getExcludedBpostShippingmethods'));
176
+
177
+ $productMocks = array();
178
+ foreach($productIdsArray as $productId){
179
+ $productMocks[$productId] = $this->getProductMock($excludedBpostShippingmethods[$productId]);
180
+ }
181
+
182
+ $product->expects($this->any())
183
+ ->method('load')
184
+ ->with($this->logicalOr(
185
+ $this->equalTo(1),
186
+ $this->equalTo(2)
187
+ ))
188
+ ->will($this->returnCallback(
189
+ function($param) use ($productMocks) {
190
+ return $productMocks[$param];
191
+ }
192
+ ));
193
+
194
+ $this->replaceByMock('model', 'catalog/product', $product);
195
+
196
+ return $this->_shippingManager->getExcludedShippingMethods();
197
+ }
198
+
199
+ /**
200
+ *
201
+ * test helper to create checkoutCart mock
202
+ * @param array $productIdsArray
203
+ * @return ModelMock $checkoutCart
204
+ */
205
+ private function setCheckoutCartMock($productIdsArray)
206
+ {
207
+
208
+ $checkoutCart = $this->getModelMock('checkout/cart',array('getProductIds'));
209
+ $checkoutCart->expects($this->any())
210
+ ->method("getProductIds")
211
+ ->will($this->returnValue($productIdsArray));
212
+ $this->replaceByMock('model', 'checkout/cart', $checkoutCart);
213
+ return $checkoutCart;
214
+ }
215
+
216
+ /**
217
+ *
218
+ * @test
219
+ * @group getExcludedShippingMethods
220
+ * @doNotIndexAll
221
+ */
222
+ public function getExcludedShippingMethodsReturnsEmptyArrayWhenModuleIsNotactive(){
223
+ $this->assertEquals(array(), $this->_shippingManager->getExcludedShippingMethods());
224
+ }
225
+
226
+ /**
227
+ *
228
+ * @test
229
+ * @group getExcludedShippingMethods
230
+ * @loadFixture bpostModuleConfig.yaml
231
+ * @doNotIndexAll
232
+ */
233
+ public function oneExcludedShippingMethodDefinedInCartWithOneProduct(){
234
+
235
+ $productIds = array(1);
236
+ $excludedBpostShippingmethods = array("1" => "regular");
237
+
238
+ $this->assertEquals(array("regular"), $this->getExcludedShippingMethods($productIds, $excludedBpostShippingmethods));
239
+ }
240
+
241
+ /**
242
+ *
243
+ * @test
244
+ * @group getExcludedShippingMethods
245
+ * @loadFixture bpostModuleConfig.yaml
246
+ * @doNotIndexAll
247
+ */
248
+ public function excludedShippingMethodDefinedInCartWhichIsNoLongerEnabledIsIgnored(){
249
+
250
+ $productIds = array(1);
251
+ $excludedBpostShippingmethods = array("1" => "regular, bpackexpress");
252
+
253
+ $this->assertEquals(array("regular"), $this->getExcludedShippingMethods($productIds, $excludedBpostShippingmethods));
254
+ }
255
+ /**
256
+ *
257
+ * @test
258
+ * @group getExcludedShippingMethods
259
+ * @loadFixture bpostModuleConfig.yaml
260
+ * @doNotIndexAll
261
+ */
262
+ public function moreThenOneExcludedShippingMethodDefinedInCartWithOneProduct(){
263
+
264
+ $productIds = array(1);
265
+ $excludedBpostShippingmethods = array("1" => "regular,pugo");
266
+
267
+ $this->assertEquals(array("regular", "pugo"), $this->getExcludedShippingMethods($productIds, $excludedBpostShippingmethods));
268
+ }
269
+
270
+ /**
271
+ *
272
+ * @test
273
+ * @group getExcludedShippingMethods
274
+ * @loadFixture bpostModuleConfig.yaml
275
+ * @doNotIndexAll
276
+ */
277
+ public function sameExcludedShippingMethodDefinedontwoProductInCart(){
278
+
279
+ $productIds = array(1, 2);
280
+ $excludedBpostShippingmethods = array("1" => "regular,pugo", "2" => "regular");
281
+
282
+ $this->assertEquals(array("regular","pugo"), $this->getExcludedShippingMethods($productIds, $excludedBpostShippingmethods));
283
+
284
+ }
285
+
286
+ /**
287
+ *
288
+ * @test
289
+ * @group getExcludedShippingMethods
290
+ * @loadFixture bpostModuleConfig.yaml
291
+ * @doNotIndexAll
292
+ */
293
+ public function differentExcludedShippingMethodDefinedontwoProductInCart(){
294
+
295
+ $productIds = array(1, 2);
296
+ $excludedBpostShippingmethods = array("1" => "regular", "2" => "pugo");
297
+
298
+ $this->assertEquals(array("regular", "pugo"), $this->getExcludedShippingMethods($productIds, $excludedBpostShippingmethods));
299
+ }
300
+
301
+ /**
302
+ *
303
+ * @test
304
+ * @group processConfirmPostBack
305
+ * @loadFixture bpostOrderSetup.yaml
306
+ * @doNotIndexAll
307
+ */
308
+ public function processConfirmPostBack(){
309
+ $this->setShippingMethodMock(false);
310
+
311
+ $rateMock = $this->getModelMock('sales/quote_address_rate', array("getMethod","save","setPrice"));
312
+ $rateMock->expects($this->any())
313
+ ->method('getMethod')
314
+ ->will($this->returnValue("pugo"));
315
+
316
+ $addressMock = $this->getModelMock('sales/quote_address', array("getShippingRatesCollection"));
317
+ $addressMock->expects($this->any())
318
+ ->method('getShippingRatesCollection')
319
+ ->will($this->returnValue(array("1" => $rateMock)));
320
+
321
+ $this->replaceByMock("model", "sales/quote_address", $addressMock);
322
+
323
+ // Create a quote with a shipping address
324
+ $quote = Mage::getModel('sales/quote')
325
+ ->setStoreId(Mage::app()->getStore()->getId())
326
+ ->load(1);
327
+
328
+ $shippingAddress = $quote->getShippingAddress();
329
+ $shippingAddress->setFirstname("Homer");
330
+ $shippingAddress->setLastname("Simpson");
331
+ $shippingAddress->setStreet("Evergreen Terrace 742");
332
+ $shippingAddress->setCity("Springfield");
333
+ $shippingAddress->setPostcode("192005");
334
+ $shippingAddress->setCountryId("BE");
335
+ $shippingAddress->setTelephone("+3211223344");
336
+ $shippingAddress->setSameAsBilling(true);
337
+ $shippingAddress->save();
338
+
339
+ $checkoutCart = $this->getModelMock('checkout/cart');
340
+ $checkoutCart->expects($this->any())
341
+ ->method('getQuote')
342
+ ->will($this->returnValue($quote));
343
+
344
+ $this->replaceByMock("model", "checkout/cart", $checkoutCart);
345
+
346
+ $request = array(
347
+ "customerFirstName"=> "Ned",
348
+ "customerLastName"=> "Flanders",
349
+ "customerStreet"=> "Evergreen Terrace",
350
+ "customerStreetNumber"=> "740",
351
+ "customerCity"=> "Springfield",
352
+ "customerPostalCode"=> "192005",
353
+ "customerCountry"=> "BE",
354
+ "customerPhoneNumber"=> "+3244332211",
355
+ "deliveryMethodPriceTotal"=> "12045",
356
+ "deliveryMethod"=> "Pugo"
357
+ );
358
+
359
+ $this->_shippingManager->processConfirmPostBack($request);
360
+
361
+ // reload the quote
362
+ $quote = Mage::getModel('sales/quote')
363
+ ->setStoreId(Mage::app()->getStore()->getId())
364
+ ->load(1);
365
+ $shippingAddress = $quote->getShippingAddress();
366
+
367
+ $this->assertEquals($request["customerFirstName"], $shippingAddress->getFirstname());
368
+ $this->assertEquals($request["customerLastName"], $shippingAddress->getLastname());
369
+ $this->assertEquals($request["customerStreet"] . " " . $request["customerStreetNumber"], implode("\n",$shippingAddress->getStreet()));
370
+ $this->assertEquals($request["customerCity"], $shippingAddress->getCity());
371
+ $this->assertEquals($request["customerPostalCode"], $shippingAddress->getPostcode());
372
+ $this->assertEquals($request["customerCountry"], $shippingAddress->getCountryId());
373
+ $this->assertEquals($request["customerPhoneNumber"], $shippingAddress->getTelephone());
374
+ $this->assertEquals($request["deliveryMethod"], $this->_shippingManager->getDeliverymethod());
375
+ }
376
+
377
+ /**
378
+ *
379
+ * @test
380
+ * @group DeliveryMethodsOverrides
381
+ * @loadFixture bpostOrderSetup.yaml
382
+ * @doNotIndexAll
383
+ */
384
+ public function getInitialDeliveryMethodsOverridesPerShippingMethod(){
385
+ $overrides = array(
386
+ "regular" => array("code" => "Regular", "viewstate" => "INVISIBLE", "cost" => "0"),
387
+ "pugo" => array("code" => "Pugo", "viewstate" => "INVISIBLE", "cost" => "0"),
388
+ "parcelsdepot" => array("code" => "Parcels depot", "viewstate" => "INVISIBLE", "cost" => "0")/*,
389
+ "bpackexpress" => array("code" => "bpack EXPRESS", "viewstate" => "INVISIBLE", "cost" => "0"),
390
+ "bpackbusiness" => array("code" => "bpack BUSINESS", "viewstate" => "INVISIBLE", "cost" => "0")*/
391
+ );
392
+ $this->assertEquals($overrides, $this->_shippingManager->getInitialDeliveryMethodsOverridesPerShippingMethod());
393
+ }
394
+
395
+ /**
396
+ *
397
+ * @test
398
+ * @group DeliveryMethodsOverrides
399
+ * @loadFixture bpostOrderSetup.yaml
400
+ * @doNotIndexAll
401
+ */
402
+ public function getDeliveryMethodOverridesAsArrayReturnsEmptyArrayWHenShippingMethodUnknownInShippingRatesArray(){
403
+
404
+ $shippingRates = array("flatfee" => array("bpost_regular" => Mage::getModel('shippingmanager/carrier_shippingmethod_regular')));
405
+ $this->assertEquals(array(), $this->_shippingManager->getDeliveryMethodOverridesAsArray($shippingRates));
406
+ }
407
+
408
+ /**
409
+ *
410
+ * @test
411
+ * @group DeliveryMethodsOverrides
412
+ * @loadFixture bpostOrderSetup.yaml
413
+ * @doNotIndexAll
414
+ */
415
+ public function getDeliveryMethodOverridesAsArrayReturnsGreyedOutWHenShippingmethodIsExcludedByProduct(){
416
+ $overrides = array(
417
+ "regular" => array("code" => "Regular", "viewstate" => "GREYED_OUT", "cost" => "12500"),
418
+ "pugo" => array("code" => "Pugo", "viewstate" => "INVISIBLE", "cost" => "0"),
419
+ "parcelsdepot" => array("code" => "Parcels depot", "viewstate" => "INVISIBLE", "cost" => "0")/*,
420
+ "bpackexpress" => array("code" => "bpack EXPRESS", "viewstate" => "INVISIBLE", "cost" => "0"),
421
+ "bpackbusiness" => array("code" => "bpack BUSINESS", "viewstate" => "INVISIBLE", "cost" => "0")*/
422
+ );
423
+
424
+ $shippingRates = array("bpost" => array($this->getSalesQuoteAddressRateMock()));
425
+ $this->setShippingMethodMock(false);
426
+
427
+ $productIds = array(1);
428
+ $excludedBpostShippingmethods = array("1" => "regular");
429
+ $this->assertEquals(array("regular"), $this->getExcludedShippingMethods($productIds, $excludedBpostShippingmethods));
430
+
431
+ $this->_shippingManager = Mage::getModel("shippingmanager/shippingManager");
432
+ $deliveryMethodOverridesAsArray = $this->_shippingManager->getDeliveryMethodOverridesAsArray($shippingRates);
433
+ foreach($overrides as $method => $methodInfo) {
434
+ $this->assertEquals($methodInfo, $deliveryMethodOverridesAsArray[$method]);
435
+ }
436
+
437
+ }
438
+ /**
439
+ *
440
+ * @test
441
+ * @group DeliveryMethodsOverrides
442
+ * @loadFixture bpostOrderSetup.yaml
443
+ * @doNotIndexAll
444
+ */
445
+ public function getDeliveryMethodOverridesAsArrayReturnsCostAndVisibleWhenShippingManagerDoesNotDecidesQuote(){
446
+ $overrides = array(
447
+ "regular" => array("code" => "Regular", "viewstate" => "VISIBLE", "cost" => "12500"),
448
+ "pugo" => array("code" => "Pugo", "viewstate" => "INVISIBLE", "cost" => "0"),
449
+ "parcelsdepot" => array("code" => "Parcels depot", "viewstate" => "INVISIBLE", "cost" => "0")/*,
450
+ "bpackexpress" => array("code" => "bpack EXPRESS", "viewstate" => "INVISIBLE", "cost" => "0"),
451
+ "bpackbusiness" => array("code" => "bpack BUSINESS", "viewstate" => "INVISIBLE", "cost" => "0")*/
452
+ );
453
+
454
+ $shippingRates = array("bpost" => array($this->getSalesQuoteAddressRateMock()));
455
+ $this->setShippingMethodMock(false);
456
+
457
+ $this->_shippingManager = Mage::getModel("shippingmanager/shippingManager");
458
+ $deliveryMethodOverridesAsArray = $this->_shippingManager->getDeliveryMethodOverridesAsArray($shippingRates);
459
+ foreach($overrides as $method => $methodInfo) {
460
+ $this->assertEquals($methodInfo, $deliveryMethodOverridesAsArray[$method]);
461
+ }
462
+
463
+ }
464
+
465
+ /**
466
+ *
467
+ * @test
468
+ * @group DeliveryMethodsOverrides
469
+ * @loadFixture bpostOrderSetup.yaml
470
+ * @doNotIndexAll
471
+ */
472
+ public function getDeliveryMethodOverridesAsArrayReturnsDoesNotIncludesCostWhenShippingManagerDecidesQuote(){
473
+ $overrides = array(
474
+ "regular" => array("code" => "Regular", "viewstate" => "VISIBLE"),
475
+ "pugo" => array("code" => "Pugo", "viewstate" => "INVISIBLE", "cost" => "0"),
476
+ "parcelsdepot" => array("code" => "Parcels depot", "viewstate" => "INVISIBLE", "cost" => "0")/*,
477
+ "bpackexpress" => array("code" => "bpack EXPRESS", "viewstate" => "INVISIBLE", "cost" => "0"),
478
+ "bpackbusiness" => array("code" => "bpack BUSINESS", "viewstate" => "INVISIBLE", "cost" => "0")*/
479
+ );
480
+
481
+ $shippingRates = array("bpost" => array($this->getSalesQuoteAddressRateMock()));
482
+ $this->setShippingMethodMock(true);
483
+
484
+ $this->_shippingManager = Mage::getModel("shippingmanager/shippingManager");
485
+ $deliveryMethodOverridesAsArray = $this->_shippingManager->getDeliveryMethodOverridesAsArray($shippingRates);
486
+ foreach($overrides as $method => $methodInfo) {
487
+ $this->assertEquals($methodInfo, $deliveryMethodOverridesAsArray[$method]);
488
+ }
489
+
490
+ }
491
+
492
+ /**
493
+ *
494
+ * @test
495
+ * @group DeliveryMethodsOverrides
496
+ * @loadFixture bpostOrderSetup.yaml
497
+ * @doNotIndexAll
498
+ */
499
+ public function getDeliveryMethodOverrides(){
500
+
501
+
502
+ $shippingRates = array("bpost" => array($this->getSalesQuoteAddressRateMock()));
503
+ $this->setShippingMethodMock(false);
504
+
505
+ $this->_shippingManager = Mage::getModel("shippingmanager/shippingManager");
506
+ $deliveryMethodsOverrides = array( "Parcels depot|INVISIBLE|0",
507
+ "Pugo|INVISIBLE|0",
508
+ "Regular|VISIBLE|12500"/*,
509
+ "bpack BUSINESS|INVISIBLE|0",
510
+ "bpack EXPRESS|INVISIBLE|0"*/
511
+ );
512
+ $this->assertEquals($deliveryMethodsOverrides, $this->_shippingManager->getDeliveryMethodOverrides($shippingRates));
513
+
514
+ }
515
+
516
+ private function getSalesQuoteAddressRateMock(){
517
+ $shippingMethodInfoRegular = $this->getModelMock('sales/quote_address_rate', array("getCode", "getPrice"));
518
+ $shippingMethodInfoRegular->expects($this->any())
519
+ ->method('getCode')
520
+ ->will($this->returnValue("bpost_regular"));
521
+ $shippingMethodInfoRegular->expects($this->any())
522
+ ->method('getPrice')
523
+ ->will($this->returnValue(125));
524
+ return $shippingMethodInfoRegular;
525
+ }
526
+
527
+ private function setShippingMethodMock($decidesQuote){
528
+ $methodRegular = $this->getModelMock('shippingmanager/carrier_shippingmethod_regular',array("shippingManagerDecidesQuotes"));
529
+ $methodRegular->expects($this->any())
530
+ ->method('shippingManagerDecidesQuotes')
531
+ ->will($this->returnValue($decidesQuote));
532
+ $this->replaceByMock("model", "shippingmanager/carrier_shippingmethod_regular", $methodRegular);
533
+ }
534
+
535
+
536
+ }
app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/accountIdNotFilledIn.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/active: 1
3
+ default/carriers/bpost/account_id: 105704
4
+ default/carriers/bpost/passphrase: ""
app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/bpostModuleConfig.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/active: 1
3
+ default/carriers/bpost/account_id: 105704
4
+ default/carriers/bpost/passphrase: secret
5
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
6
+ default/carriers/bpost/title: bpost
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
9
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
10
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
11
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "0", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/bpostOrderSetup.yaml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/active: 1
3
+ default/carriers/bpost/account_id: 105704
4
+ default/carriers/bpost/passphrase: secret
5
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
6
+ default/carriers/bpost/title: bpost
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
9
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
10
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
11
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "125", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
12
+ tables:
13
+ sales/quote:
14
+ - store_id: 0
15
+ entity_id: 1
16
+ created_at: 2011-01-01
17
+ updated_at: 2011-01-01
18
+ is_active: 1
19
+ is_virtual: 0
20
+ is_multi_shipping: 0
21
+ items_count: 1
22
+ items_qty: 1
23
+ orig_order_id: 0
24
+ store_to_base_rate: 1
25
+ store_to_quote_rate: 1
26
+ base_to_global_rate: 1
27
+ base_to_quote_rate: 1
28
+ global_currency_code: EUR
29
+ base_currency_code: EUR
30
+ store_currency_code: EUR
31
+ quote_currency_code: EUR
32
+ grand_total: 34
33
+ base_grand_total: 1
34
+ customer_tax_class_id: 3
35
+ customer_group_id: 1
36
+ customer_email: homer@nuclearplant.com
37
+ customer_prefix: 1
38
+ customer_firstname: Homer
39
+ customer_lastname: Simpson
40
+ customer_is_guest: 1
41
+ remote_ip: 192.168.2.1
42
+ subtotal: 34
43
+ base_subtotal: 34
44
+ subtotal_with_discount: 34
45
+ base_subtotal_with_discount: 34
46
+ is_changed: 1
47
+ trigger_recollect: 0
app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/carrierDeactivated.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/active: 0
3
+ default/carriers/bpost/account_id: 105704
4
+ default/carriers/bpost/passphrase: secret
5
+ default/carriers/bpost/frontend_url: "https://shippingmanager.bpost.be/ShmFrontEnd/start"
6
+ default/carriers/bpost/title: bpost
7
+ default/carriers/bpost/proxy_host: proxy.host.be
8
+ default/carriers/bpost/proxy_port: 8080
9
+ default/carriers/bpost/free_delivery_when_cart_value_bigger_then: 100
10
+ default/carriers/bpost/allowed_methods: regular,pugo,parcelsdepot
11
+ default/carriers/bpost/rate_table: "{"BPACK@bpost" : "12","BPACK@home" : "0", "BPACK 24/7" : {"0":"2.90","0.5":"4.50","5":"8","10":"14"}}"
app/code/community/Bpost/ShippingManager/Test/Model/ShippingManager/fixtures/passphraseNotFilledIn.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ config:
2
+ default/carriers/bpost/active: 1
3
+ default/carriers/bpost/account_id: 105704
4
+ default/carriers/bpost/passphrase: ""
app/code/community/Bpost/ShippingManager/controllers/ApiController.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_ApiController
10
+ extends Mage_Core_Controller_Front_Action{
11
+
12
+ /**
13
+ * Controller action which requests a new barcode for an order
14
+ * @return jsonstring barcode
15
+ */
16
+ public function newtrackingcodeAction(){
17
+ if($this->getRequest()->isPost() && $this->getRequest()->getParam('order')) {
18
+ $orderReference = $this->getRequest()->getParam('order');
19
+ $api = Mage::getModel("shippingmanager/Api");
20
+ $result["barcode"] = $api->createBarCodeForOrderReference($orderReference);
21
+ }
22
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
23
+ return;
24
+ }
25
+ /**
26
+ * outputs pdf file with label for the barcode
27
+ */
28
+ public function labelAction(){
29
+ // We'll be outputting a PDF
30
+ $orderReference = $this->getRequest()->getParam('orderReference');
31
+ $barcode = $this->getRequest()->getParam('barcode');
32
+ if($barcode != "" && $orderReference != ""){
33
+ $this->getResponse()->setHeader('Content-type', 'application/pdf');
34
+ $this->getResponse()->setHeader('Content-Disposition:', 'attachment; filename="' . $orderReference . '-' . $barcode . '.pdf"');
35
+ $api = Mage::getModel("shippingmanager/Api");
36
+ $this->getResponse()->setBody( $api->getPdfContentForBarcode($barcode));
37
+ }
38
+ return;
39
+ }
40
+
41
+ public function labelsAction(){
42
+ // We'll be outputting a PDF
43
+ $orderReference = $this->getRequest()->getParam('orderReference');
44
+ if($orderReference != ""){
45
+ $this->getResponse()->setHeader('Content-type', 'application/pdf');
46
+ $this->getResponse()->setHeader('Content-Disposition:', 'attachment; filename="' . $orderReference . '.pdf"');
47
+ $api = Mage::getModel("shippingmanager/Api");
48
+ $this->getResponse()->setBody( $api->getPdfContentForOrderReference($orderReference));
49
+ }
50
+ return;
51
+ }
52
+ }
app/code/community/Bpost/ShippingManager/controllers/PostbackController.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bpost_ShippingManager
4
+ *
5
+ * @package Bpost_ShippingManager
6
+ * @copyright Copyright (c) 2011 bpost
7
+ * @author Phpro (http://www.phpro.be)
8
+ */
9
+ class Bpost_ShippingManager_PostbackController
10
+ extends Mage_Core_Controller_Front_Action{
11
+
12
+ /**
13
+ *
14
+ * Confirm action
15
+ * Handles successfull postback from the bpost platform
16
+ */
17
+ public function confirmAction()
18
+ {
19
+ $shm = Mage::getSingleton('shippingmanager/shippingManager');
20
+ if($this->getRequest()->isPost()){
21
+ $shm->processConfirmPostBack($this->getRequest()->getPost());
22
+ }
23
+ $this->loadLayout();
24
+ $this->renderLayout();
25
+ }
26
+
27
+ public function cancelAction()
28
+ {
29
+ $this->loadLayout();
30
+ $this->renderLayout();
31
+ }
32
+
33
+ public function errorAction()
34
+ {
35
+ $this->loadLayout();
36
+ $this->renderLayout();
37
+ }
38
+
39
+
40
+ public function platformstubAction()
41
+ {
42
+ $this->loadLayout();
43
+ $this->renderLayout();
44
+ }
45
+
46
+ /**
47
+ *
48
+ * iframe action
49
+ * Handles rendering of iframe
50
+ */
51
+ public function jsforonepagecheckoutAction(){
52
+ $this->loadLayout();
53
+ $this->renderLayout();
54
+ }
55
+
56
+ /**
57
+ *
58
+ * iframe action
59
+ * Handles rendering of iframe
60
+ */
61
+ public function jsforonestepcheckoutAction(){
62
+ $this->loadLayout();
63
+ $this->renderLayout();
64
+ }
65
+ /**
66
+ *
67
+ * iframe action
68
+ * Handles rendering of iframe
69
+ */
70
+ public function jsforcheckoutcartAction(){
71
+ $this->loadLayout();
72
+ $this->renderLayout();
73
+ }
74
+ /**
75
+ *
76
+ * ajax action
77
+ * Handles rendering of start form
78
+ */
79
+ public function startformAction(){
80
+ $this->loadLayout();
81
+ $this->renderLayout();
82
+ }
83
+ }
app/code/community/Bpost/ShippingManager/etc/adminhtml.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!-- Remove this file if your module does not have an admin interface -->
3
+ <config>
4
+ <menu>
5
+ </menu>
6
+ <acl>
7
+ <resources>
8
+ </resources>
9
+ </acl>
10
+ </config>
app/code/community/Bpost/ShippingManager/etc/api.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!-- Remove this file if your module does not have profide an api -->
3
+ <config>
4
+ <api>
5
+ <resources>
6
+ </resources>
7
+ <v2>
8
+ </v2>
9
+ <acl>
10
+ <resources>
11
+ </resources>
12
+ </acl>
13
+ </api>
14
+ </config>
app/code/community/Bpost/ShippingManager/etc/config.xml ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Bpost_ShippingManager>
5
+ <version>1.0.0</version>
6
+ </Bpost_ShippingManager>
7
+ </modules>
8
+ <phpunit>
9
+ <suite>
10
+ <modules>
11
+ <Bpost_ShippingManager />
12
+ </modules>
13
+ </suite>
14
+ </phpunit>
15
+ <admin>
16
+ <routers>
17
+ <shippingmanager>
18
+ <use>admin</use>
19
+ <args>
20
+ <module>Bpost_ShippingManager</module>
21
+ <frontName>shippingmanager</frontName>
22
+ </args>
23
+ </shippingmanager>
24
+ </routers>
25
+ </admin>
26
+ <global>
27
+ <models>
28
+ <shippingmanager>
29
+ <class>Bpost_ShippingManager_Model</class>
30
+ <resourceModel>shippingmanager_mysql4</resourceModel>
31
+ </shippingmanager>
32
+ </models>
33
+ <blocks>
34
+ <shippingmanager>
35
+ <class>Bpost_ShippingManager_Block</class>
36
+ </shippingmanager>
37
+ <checkout>
38
+ <rewrite>
39
+ <onepage_shipping_method_available>Bpost_ShippingManager_Block_Onepage_Shipping_Method_Available</onepage_shipping_method_available>
40
+ </rewrite>
41
+ </checkout>
42
+ </blocks>
43
+ <helpers>
44
+ <shippingmanager>
45
+ <class>Bpost_ShippingManager_Helper</class>
46
+ </shippingmanager>
47
+ </helpers>
48
+ <resources>
49
+ <bpost_shippingmanager_setup>
50
+ <setup>
51
+ <module>Bpost_ShippingManager</module>
52
+ <class>Bpost_ShippingManager_Model_Entity_Setup</class>
53
+ </setup>
54
+ </bpost_shippingmanager_setup>
55
+ </resources>
56
+ <events>
57
+ <sales_order_invoice_pay>
58
+ <observers>
59
+ <bpost_shippingmanager_observer>
60
+ <type>singleton</type>
61
+ <class>shippingmanager/observer</class>
62
+ <method>statustoopen</method>
63
+ </bpost_shippingmanager_observer>
64
+ </observers>
65
+ </sales_order_invoice_pay>
66
+ <order_cancel_after>
67
+ <observers>
68
+ <bpost_shippingmanager_observer>
69
+ <type>singleton</type>
70
+ <class>shippingmanager/observer</class>
71
+ <method>statustocancel</method>
72
+ </bpost_shippingmanager_observer>
73
+ </observers>
74
+ </order_cancel_after>
75
+ <checkout_cart_add_product_complete>
76
+ <observers>
77
+ <bpost_shippingmanager_observer>
78
+ <type>singleton</type>
79
+ <class>shippingmanager/observer</class>
80
+ <method>invalidatequote</method>
81
+ </bpost_shippingmanager_observer>
82
+ </observers>
83
+ </checkout_cart_add_product_complete>
84
+ </events>
85
+ </global>
86
+ <adminhtml>
87
+ <routers>
88
+ <shippingmanager>
89
+ <use>standard</use>
90
+ <args>
91
+ <module>Bpost_ShippingManager</module>
92
+ <frontName>shippingmanager</frontName>
93
+ </args>
94
+ </shippingmanager>
95
+ </routers>
96
+ <layout>
97
+ <updates>
98
+ <shippingmanager module="Bpost_ShippingManager">
99
+ <file>bpost_shippingmanager.xml</file>
100
+ </shippingmanager>
101
+ </updates>
102
+ </layout>
103
+ <translate>
104
+ <modules>
105
+ <Bpost_ShippingManager>
106
+ <files>
107
+ <default>Bpost_ShippingManager.csv</default>
108
+ </files>
109
+ </Bpost_ShippingManager>
110
+ </modules>
111
+ </translate>
112
+ </adminhtml>
113
+ <frontend>
114
+ <routers>
115
+ <shippingmanager>
116
+ <use>standard</use>
117
+ <args>
118
+ <module>Bpost_ShippingManager</module>
119
+ <frontName>shippingmanager</frontName>
120
+ </args>
121
+ </shippingmanager>
122
+ </routers>
123
+
124
+ <translate>
125
+ <modules>
126
+ <Bpost_ShippingManager>
127
+ <files>
128
+ <default>Bpost_ShippingManager.csv</default>
129
+ </files>
130
+ </Bpost_ShippingManager>
131
+ </modules>
132
+ </translate>
133
+
134
+ <layout>
135
+ <updates>
136
+ <shippingmanager module="Bpost_ShippingManager">
137
+ <file>bpost_shippingmanager.xml</file>
138
+ </shippingmanager>
139
+ </updates>
140
+ </layout>
141
+
142
+ </frontend>
143
+ <default>
144
+ <carriers>
145
+ <bpost>
146
+ <active>1</active>
147
+ <sallowspecific>0</sallowspecific>
148
+ <account></account>
149
+ <encryption_key></encryption_key>
150
+ <frontend_url><![CDATA[https://shippingmanager.bpost.be/ShmFrontEnd/start]]></frontend_url>
151
+ <api_uri><![CDATA[https://api.bpost.be/services/shm/]]></api_uri>
152
+ <model>Bpost_ShippingManager_Model_Carrier_Bpost</model>
153
+ <title>bpost</title>
154
+ </bpost>
155
+ </carriers>
156
+ <shippingmanager>
157
+ </shippingmanager>
158
+ </default>
159
+ </config>
app/code/community/Bpost/ShippingManager/etc/system.xml ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Bpost_ShippingManager
5
+ *
6
+ * @category Bpost
7
+ * @package Bpost_ShippingManager
8
+ * @copyright Copyright (c) 2011 Bpost
9
+ * @author PHPro (http://www.phpro.be)
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ -->
13
+ <config>
14
+ <tabs>
15
+ </tabs>
16
+ <sections>
17
+ <carriers>
18
+ <groups>
19
+ <bpost>
20
+ <label>bpost Shipping Manager</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>100</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <active translate="label">
28
+ <label>Enabled</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>10</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </active>
36
+ <account_id translate="label">
37
+ <label>bpost AccountId</label>
38
+ <sort_order>20</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>1</show_in_store>
42
+ </account_id>
43
+ <passphrase translate="label">
44
+ <label>bpost passphrase</label>
45
+ <frontend_type>password</frontend_type>
46
+ <sort_order>30</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>1</show_in_store>
50
+ </passphrase>
51
+ <allowed_methods translate="label">
52
+ <label>Allowed bpost shipping methods</label>
53
+ <frontend_type>multiselect</frontend_type>
54
+ <source_model>shippingmanager/carrier_system_config_source_method</source_model>
55
+ <sort_order>40</sort_order>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>1</show_in_website>
58
+ <show_in_store>1</show_in_store>
59
+ <comment>Allowed bpost shipping methods comment</comment>
60
+ <can_be_empty>1</can_be_empty>
61
+ </allowed_methods>
62
+ <rate_table translate="label">
63
+ <label>bpost shippingcost rules</label>
64
+ <frontend_type>textarea</frontend_type>
65
+ <sort_order>50</sort_order>
66
+ <show_in_default>1</show_in_default>
67
+ <show_in_website>1</show_in_website>
68
+ <show_in_store>1</show_in_store>
69
+ <comment>bpost shippingcost rules comment</comment>
70
+ </rate_table>
71
+ <free_delivery_when_cart_value_bigger_then translate="label">
72
+ <label>Free delivery from (in €)</label>
73
+ <sort_order>60</sort_order>
74
+ <show_in_default>1</show_in_default>
75
+ <show_in_website>1</show_in_website>
76
+ <show_in_store>1</show_in_store>
77
+ <comment>Leave blank to not offering free delivery</comment>
78
+ </free_delivery_when_cart_value_bigger_then>
79
+ <sallowspecific translate="label">
80
+ <label>Ship to Applicable Countries</label>
81
+ <frontend_type>select</frontend_type>
82
+ <sort_order>70</sort_order>
83
+ <frontend_class>shipping-applicable-country</frontend_class>
84
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries
85
+ </source_model>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>1</show_in_website>
88
+ <show_in_store>1</show_in_store>
89
+ </sallowspecific>
90
+ <specificcountry translate="label">
91
+ <label>Ship to Specific Countries</label>
92
+ <frontend_type>multiselect</frontend_type>
93
+ <sort_order>80</sort_order>
94
+ <source_model>adminhtml/system_config_source_country</source_model>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>1</show_in_store>
98
+ <can_be_empty>1</can_be_empty>
99
+ </specificcountry>
100
+ <sort_order translate="label">
101
+ <label>Sort Order</label>
102
+ <frontend_type>text</frontend_type>
103
+ <sort_order>90</sort_order>
104
+ <show_in_default>1</show_in_default>
105
+ <show_in_website>1</show_in_website>
106
+ <show_in_store>0</show_in_store>
107
+ <comment>This field should not be changed unless absolutely sure</comment>
108
+ </sort_order>
109
+ <frontend_url translate="label">
110
+ <label>Front end URL</label>
111
+ <sort_order>100</sort_order>
112
+ <show_in_default>1</show_in_default>
113
+ <show_in_website>1</show_in_website>
114
+ <show_in_store>1</show_in_store>
115
+ <comment>This field should not be changed unless absolutely sure</comment>
116
+ </frontend_url>
117
+ <api_uri translate="label">
118
+ <label>Api Uri</label>
119
+ <sort_order>120</sort_order>
120
+ <show_in_default>1</show_in_default>
121
+ <show_in_website>1</show_in_website>
122
+ <show_in_store>1</show_in_store>
123
+ <comment>This field should not be changed unless absolutely sure</comment>
124
+ </api_uri>
125
+ <proxy_host translate="label">
126
+ <label>Proxy host</label>
127
+ <sort_order>130</sort_order>
128
+ <show_in_default>1</show_in_default>
129
+ <show_in_website>1</show_in_website>
130
+ <show_in_store>1</show_in_store>
131
+ <comment>This field should not be changed unless absolutely sure</comment>
132
+ </proxy_host>
133
+ <proxy_port translate="label">
134
+ <label>Proxy port</label>
135
+ <sort_order>140</sort_order>
136
+ <show_in_default>1</show_in_default>
137
+ <show_in_website>1</show_in_website>
138
+ <show_in_store>1</show_in_store>
139
+ <comment>This field should not be changed unless absolutely sure</comment>
140
+ </proxy_port>
141
+ <title translate="label">
142
+ <label>Carrier name</label>
143
+ <sort_order>150</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>1</show_in_website>
146
+ <show_in_store>1</show_in_store>
147
+ </title>
148
+ </fields>
149
+ </bpost>
150
+ </groups>
151
+ </carriers>
152
+ </sections>
153
+ </config>
app/code/community/Bpost/ShippingManager/etc/wsdl.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!-- Remove this file if your module does not have profide an api -->
3
+ <definitions xmlns:typens="urn:{{var wsdl.name}}"
4
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
5
+ xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
6
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
7
+ name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
8
+ <types>
9
+ <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
10
+ <import namespace="http://schemas.xmlsoap.org/soap/encoding/"
11
+ schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
12
+ <!-- add complexType nodes here -->
13
+ </schema>
14
+ </types>
15
+ <!-- add message nodes here -->
16
+ <portType name="{{var wsdl.handler}}PortType">
17
+ <!-- add operation nodes here -->
18
+ </portType>
19
+ <binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
20
+ <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
21
+ <!-- add operation nodes here -->
22
+ </binding>
23
+ </definitions>
app/code/community/Bpost/ShippingManager/sql/bpost_shippingmanager_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
4
+ $installer->startSetup();
5
+ $setup->addAttribute('catalog_product', 'excluded_bpost_shippingmethods', array(
6
+ 'label' => 'Exclude bpost shippingmethod',
7
+ 'type' => 'varchar',
8
+ 'input' => 'multiselect',
9
+ 'backend' => 'eav/entity_attribute_backend_array',
10
+ 'frontend' => '',
11
+ 'source' => 'shippingmanager/carrier_system_config_source_method',
12
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
13
+ 'visible' => true,
14
+ 'required' => false,
15
+ 'user_defined' => true,
16
+ 'searchable' => false,
17
+ 'filterable' => false,
18
+ 'comparable' => false,
19
+ 'visible_on_front' => false,
20
+ 'visible_in_advanced_search' => false,
21
+ 'unique' => false
22
+ ));
23
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/bpost_shippingmanager.xml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Bpost_ShippingManager
5
+ *
6
+ * @category Bpost
7
+ * @package Bpost_ShippingManager
8
+ * @copyright Copyright (c) 2011 Bpost
9
+ * @author PHPro (http://www.phpro.be)
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+ -->
14
+
15
+ <layout version="0.1.0">
16
+ <!--
17
+ <adminhtml_sales_order_shipment_new>
18
+ <reference name="head">
19
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/base.js</name><params/></action>
20
+ <action method="addItem"><type>skin_css</type><name>css/bpost/shippingmanager/bpost.css</name><params/></action>
21
+ </reference>
22
+ <reference name="content">
23
+ <block type="shippingmanager/adminhtml_javascript" name="adminhtml.sales.order.shipping.new.jsforordershipment" before="-" template="bpost/shippingmanager/dynamic/jsforordershipment.phtml"></block>
24
+ </reference>
25
+ </adminhtml_sales_order_shipment_new>
26
+
27
+ <adminhtml_sales_order_shipment_view>
28
+ <reference name="head">
29
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/base.js</name><params/></action>
30
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/sales_order_shipment_view.js</name><params/></action>
31
+ <action method="addItem"><type>skin_css</type><name>css/bpost/shippingmanager/bpost.css</name><params/></action>
32
+ </reference>
33
+ <reference name="content">
34
+ <block type="shippingmanager/adminhtml_javascript" name="adminhtml.sales.order.shipping.view.jsforordershipment" before="-" template="bpost/shippingmanager/dynamic/jsforordershipment.phtml"></block>
35
+ </reference>
36
+ </adminhtml_sales_order_shipment_view>
37
+
38
+ <adminhtml_sales_order_invoice_new>
39
+ <reference name="head">
40
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/base.js</name><params/></action>
41
+ <action method="addItem"><type>skin_css</type><name>css/bpost/shippingmanager/bpost.css</name><params/></action>
42
+ </reference>
43
+ <reference name="content">
44
+ <block type="shippingmanager/adminhtml_javascript" name="adminhtml.sales.order.invoice.new.jsforordershipment" before="-" template="bpost/shippingmanager/dynamic/jsforordershipment.phtml"></block>
45
+ </reference>
46
+ </adminhtml_sales_order_invoice_new>
47
+ -->
48
+ </layout>
app/design/adminhtml/default/default/template/bpost/shippingmanager/dynamic/jsforordershipment.phtml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_order = $this->getOrder(); ?>
2
+ <script type="text/javascript">
3
+ <!--
4
+ var orderReference = '<?php echo $_order->getRealOrderId();?>';
5
+ var carrierCode = '<?php echo $_order->getShippingCarrier()->getCarrierCode();?>';
6
+ var requestNewTrackingCodeUrl = '<?php echo Mage::helper("adminhtml")->getUrl("shippingmanager/api/newtrackingcode/",array()); ?>';
7
+ var requestPrintAllLabelsUrl = '<?php echo Mage::helper("adminhtml")->getUrl("shippingmanager/api/labels/",array("_query"=> true,"orderReference" => $_order->getRealOrderId())); ?>';
8
+ var requestPrintLabelUrl = '<?php echo Mage::helper("adminhtml")->getUrl("shippingmanager/api/label/",array()); ?>';
9
+ //-->
10
+ </script>
app/design/frontend/base/default/layout/bpost_shippingmanager.xml ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Bpost_ShippingManager
5
+ *
6
+ * @category Bpost
7
+ * @package Bpost_ShippingManager
8
+ * @copyright Copyright (c) 2011 Bpost
9
+ * @author PHPro (http://www.phpro.be)
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+ -->
14
+ <layout version="0.1.0">
15
+
16
+ <shippingmanager_postback_confirm>
17
+ <reference name="root">
18
+ <action method="setTemplate"><template>page/empty.phtml</template></action>
19
+ </reference>
20
+ <reference name="content">
21
+ <block type="shippingmanager/confirm" name="bpost.shippingmanager.postback.confirm" template="bpost/shippingmanager/confirm.phtml"/>
22
+ </reference>
23
+ </shippingmanager_postback_confirm>
24
+
25
+ <shippingmanager_postback_cancel>
26
+ <reference name="root">
27
+ <action method="setTemplate"><template>page/empty.phtml</template></action>
28
+ </reference>
29
+ <reference name="content">
30
+ <block type="shippingmanager/confirm" name="bpost.shippingmanager.postback.cancel" template="bpost/shippingmanager/cancel.phtml"/>
31
+ </reference>
32
+ </shippingmanager_postback_cancel>
33
+
34
+ <shippingmanager_postback_error>
35
+ <reference name="root">
36
+ <action method="setTemplate"><template>page/empty.phtml</template></action>
37
+ </reference>
38
+ <reference name="content">
39
+ <block type="shippingmanager/confirm" name="bpost.shippingmanager.postback.error" template="bpost/shippingmanager/error.phtml"/>
40
+ </reference>
41
+ </shippingmanager_postback_error>
42
+
43
+ <shippingmanager_postback_jsforonepagecheckout>
44
+ <block type="shippingmanager/javascript" name="root" output="toHtml" template="bpost/shippingmanager/dynamic/jsforonepagecheckout.phtml"/>
45
+ </shippingmanager_postback_jsforonepagecheckout>
46
+
47
+ <shippingmanager_postback_jsforonestepcheckout>
48
+ <block type="shippingmanager/javascript" name="root" output="toHtml" template="bpost/shippingmanager/dynamic/jsforonestepcheckout.phtml"/>
49
+ </shippingmanager_postback_jsforonestepcheckout>
50
+
51
+ <shippingmanager_postback_jsforcheckoutcart>
52
+ <block type="shippingmanager/javascript" name="root" output="toHtml" template="bpost/shippingmanager/dynamic/jsforcheckoutcart.phtml"/>
53
+ </shippingmanager_postback_jsforcheckoutcart>
54
+
55
+ <shippingmanager_postback_startform>
56
+ <reference name="root">
57
+ <action method="setTemplate"><template>page/empty.phtml</template></action>
58
+ </reference>
59
+ <reference name="content">
60
+ <block type="shippingmanager/startform" name="bpost.shippingmanager.postback.startform" template="bpost/shippingmanager/startform.phtml"/>
61
+ </reference>
62
+ </shippingmanager_postback_startform>
63
+
64
+ <shippingmanager_postback_platformstub>
65
+ <block type="shippingmanager/platformstub" name="root" output="toHtml" template="bpost/shippingmanager/platformstub.phtml"/>
66
+ </shippingmanager_postback_platformstub>
67
+
68
+ <shippingmanager_api_newtrackingcode>
69
+ <block type="shippingmanager/tracking" name="root" output="toHtml" template="bpost/shippingmanager/createtrackingcode.phtml"/>
70
+ </shippingmanager_api_newtrackingcode>
71
+
72
+ <checkout_onepage_index translate="label">
73
+ <reference name="head">
74
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/bpost_shippingmanager_base.js</name><params/></action>
75
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/onepage_checkout.js</name><params/></action>
76
+ <block type="shippingmanager/javascript" name="shippingmanager.jsforgreybox" template="bpost/shippingmanager/dynamic/jsforgreybox.phtml"/>
77
+ <block type="shippingmanager/javascript" name="shippingmanager.jsforonepagecheckout" template="bpost/shippingmanager/dynamic/jsforonepagecheckout.phtml"/>
78
+ <action method="addCss"><stylesheet>greybox/gb_styles.css</stylesheet></action>
79
+ </reference>
80
+ </checkout_onepage_index>
81
+
82
+ <checkout_cart_index translate="label">
83
+ <reference name="head">
84
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/bpost_shippingmanager_base.js</name><params/></action>
85
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/checkout_cart.js</name><params/></action>
86
+ <block type="shippingmanager/javascript" name="shippingmanager.jsforgreybox" template="bpost/shippingmanager/dynamic/jsforgreybox.phtml"/>
87
+ <block type="shippingmanager/javascript" name="shippingmanager.jsforcheckoutcart" template="bpost/shippingmanager/dynamic/jsforcheckoutcart.phtml"/>
88
+ <action method="addCss"><stylesheet>greybox/gb_styles.css</stylesheet></action>
89
+ </reference>
90
+ </checkout_cart_index>
91
+ <!--
92
+ <onestepcheckout_index_index>
93
+ <reference name="head">
94
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/bpost_shippingmanager_base.js</name><params/></action>
95
+ <action method="addItem"><type>skin_js</type><name>js/bpost/shippingmanager/onestep_checkout.js</name><params/></action>
96
+ <block type="shippingmanager/javascript" name="shippingmanager.jsforgreybox" template="bpost/shippingmanager/dynamic/jsforgreybox.phtml"/>
97
+ <block type="shippingmanager/javascript" name="shippingmanager.jsforonestepcheckout" template="bpost/shippingmanager/dynamic/jsforonestepcheckout.phtml"/>
98
+ <action method="addCss"><stylesheet>greybox/gb_styles.css</stylesheet></action>
99
+ </reference>
100
+ </onestepcheckout_index_index>
101
+ -->
102
+ </layout>
app/design/frontend/base/default/template/bpost/shippingmanager/cancel.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ //<![CDATA[
3
+ window.parent.parent.parent.shm.postbackCancel();
4
+ //]]>
5
+ </script>
app/design/frontend/base/default/template/bpost/shippingmanager/confirm.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ <?php $shippingAddress = $this->ShippingAddress(); ?>
3
+ //<![CDATA[
4
+ var parentWindow = window.parent.parent.parent;
5
+ parentWindow.shd.firstname = "<?php echo $shippingAddress->getFirstname(); ?>";
6
+ parentWindow.shd.lastname = "<?php echo $shippingAddress->getLastname(); ?>";
7
+ parentWindow.shd.street = "<?php echo $shippingAddress->getStreet(1); ?>";
8
+ parentWindow.shd.zipcode = "<?php echo $shippingAddress->getPostcode(); ?>";
9
+ parentWindow.shd.city = "<?php echo $shippingAddress->getCity(); ?>";
10
+ parentWindow.shd.company = "<?php echo $shippingAddress->getCompany(); ?>";
11
+ parentWindow.shd.country_id = "<?php echo $shippingAddress->getCountryId(); ?>";
12
+ parentWindow.shd.telephone = "<?php echo $shippingAddress->getTelephone(); ?>";
13
+ parentWindow.shm.postbackSuccess('<?php echo $this->deliveryMethod(); ?>', parentWindow.shd);
14
+ //]]>
15
+ </script>
app/design/frontend/base/default/template/bpost/shippingmanager/createtrackingcode.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <?php print json_encode(array("barcode" => $this->createBarCodeForOrderReference())); ?>
app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforcheckoutcart.phtml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ <!--
3
+ var shmEnabled = <?php echo ($this->shmEnabled() ? "true" : "false"); ?>;
4
+ var shm = null;
5
+ var shd = null;
6
+ document.observe("dom:loaded", function() {
7
+ shd = new shippingDetails();
8
+ shm = new bpostShippingManager();
9
+ shm.shippingMethodListId = "shipment-methods";
10
+ shm.logoUrl = '<?php echo $this->getBpostLogoUrl();?>';
11
+ shm.logoText = '<?php echo $this->getBpostLogoText();?>';
12
+ shm.baseUrl = '<?php echo $this->getBaseUrl(); ?>';
13
+ shm.reloadShippingMethods();
14
+ });
15
+ //-->
16
+ </script>
app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforgreybox.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ <!--
3
+ var GB_ROOT_DIR = "<?php echo str_replace("AJS.js", "", $this->getSkinUrl('greybox/AJS.js'));?>";
4
+ //-->
5
+ </script>
6
+ <script type="text/javascript" src="<?php echo $this->getSkinUrl('greybox/AJS.js');?>" ></script>
7
+ <script type="text/javascript" src="<?php echo $this->getSkinUrl('greybox/AJS_fx.js');?>" ></script>
8
+ <script type="text/javascript" src="<?php echo $this->getSkinUrl('greybox/gb_scripts.js');?>" ></script>
app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforonepagecheckout.phtml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ <!--
3
+ var shmEnabled = <?php echo ($this->shmEnabled() ? "true" : "false"); ?>;
4
+ var shm = null;
5
+ var shd = null;
6
+ document.observe("dom:loaded", function() {
7
+ if(shmEnabled){
8
+ shd = new shippingDetails();
9
+ shm = new bpostShippingManager();
10
+ shm.shippingMethodListId = "sp-methods";
11
+ shm.logoUrl = '<?php echo $this->getBpostLogoUrl();?>';
12
+ shm.logoText = '<?php echo $this->getBpostLogoText();?>';
13
+ shm.baseUrl = '<?php echo $this->getBaseUrl(); ?>';
14
+ shm.reloadShippingMethods();
15
+ shm.injectBpostInBillingInformation();
16
+ shm.initiateTimers();
17
+ }
18
+ });
19
+ //-->
20
+ </script>
app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforonestepcheckout.phtml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ <!--
3
+ var shmEnabled = <?php echo ($this->shmEnabled() ? "true" : "false"); ?>;
4
+ var shm = null;
5
+ var shd = null;
6
+ document.observe("dom:loaded", function() {
7
+ if(shmEnabled){
8
+ shd = new shippingDetails();
9
+ shm = new bpostShippingManager();
10
+ shm.OSCConfigOk = <?php echo ($this->isOneStepCheckoutConfigurationOk() ? "true" : "false"); ?>;
11
+ if(!shm.OSCConfigOk ){
12
+ alert("The current configuration of the OneStepCheckout extension does not allow the bpost Shippingmanager extension to work correctly. Please check following settings:\n\n* Activate OneStepCheckout = yes\n* Hide shipping method = no\n* Enable AJAX save billing = yes\N* Enable different shipping address = yes\n* AJAX save billing fields = at least Country selected\n\n Please consult the manual to configure the oneStepCheckout extension correctly.");
13
+ }
14
+ shm.shippingMethodListId = "shipment-methods";
15
+ shm.logoUrl = '<?php echo $this->getBpostLogoUrl();?>';
16
+ shm.logoText = '<?php echo $this->getBpostLogoText();?>';
17
+ shm.baseUrl = '<?php echo $this->getBaseUrl(); ?>';
18
+ shm.reloadShippingMethods();
19
+ shm.injectBpostInBillingInformation();
20
+ shm.initiateTimers();
21
+ }
22
+ });
23
+ //-->
24
+ </script>
app/design/frontend/base/default/template/bpost/shippingmanager/dynamic/jsforordershipment.phtml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ <!--
3
+ var requestNewTrackingCodeUrl = "http://magento.ce.1.5.1.0.local/french/shippingmanager/postback/newtrackingcode";
4
+ var orderReference = '100000018';
5
+ //-->
6
+ </script>
app/design/frontend/base/default/template/bpost/shippingmanager/error.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ //<![CDATA[
3
+ window.parent.parent.parent.shm.postbackError();
4
+ //]]>
5
+ </script>
app/design/frontend/base/default/template/bpost/shippingmanager/platformstub.phtml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <table width="100%">
2
+ <tr><th colspan="3">Delivery method overrides</th></tr>
3
+ <?php
4
+ print_r($this->getDeliveryMethodOverrides());
5
+ ?>
6
+ <?php foreach ($this->getDeliveryMethodOverrides() as $key => $overrideString) : ?>
7
+ <?php
8
+ $overrideParams = explode("|", $overrideString);
9
+ ?>
10
+ <tr>
11
+ <td id="<?php print $overrideParams[0];?>_bpostcode"><?php print $overrideParams[0];?></td>
12
+ <td id="<?php print $overrideParams[0];?>_viewstate"><?php print $overrideParams[1];?></td>
13
+ <td id="<?php print $overrideParams[0];?>_price"><?php if(isset($overrideParams[2])){ print $overrideParams[2];} ?></td>
14
+ </tr>
15
+ <?php endforeach; ?>
16
+ </table>
17
+ <table width="100%">
18
+ <tr><th colspan="2">Post params</th></tr>
19
+ <?php foreach ($_POST as $fieldName => $fieldValue) : ?>
20
+ <tr>
21
+ <td id="<?php print $fieldName?>_name"><?php print $fieldName?></td>
22
+ <td id="<?php print $fieldName?>_value"><?php print $fieldValue?></td>
23
+ </tr>
24
+ <?php endforeach; ?>
25
+ </table>
26
+ <form id="bpostShmForm" method="POST" action="<?php $this->getBaseUrl(); ?>/shippingmanager/postback/confirm">
27
+ <?php foreach($this->getFieldsForForm() as $fieldName => $fieldValue) : ?>
28
+ <?php if (is_array($fieldValue)) : ?>
29
+ <?php foreach($fieldValue as $key => $subFieldValue) :?>
30
+ <?php echo $fieldName?>:<input type="text" id="<?php echo $fieldName?>" name="<?php echo $fieldName?>" value="<?php echo htmlspecialchars($subFieldValue); ?>" /><br />
31
+ <?php endforeach; ?>
32
+ <?php else : ?>
33
+ <?php echo $fieldName?>:<input type="text" id="<?php echo $fieldName?>" name="<?php echo $fieldName?>" value="<?php echo htmlspecialchars($fieldValue); ?>" /><br />
34
+ <?php endif; ?>
35
+ <?php endforeach; ?>
36
+ <input type="submit" id="confirm" value="Continue to confirm" />
37
+ </form>
app/design/frontend/base/default/template/bpost/shippingmanager/startform.phtml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <form id="bpostShmForm" method="POST" action="<?php echo $this->getFrontendUrl();?>">
2
+ <?php foreach($this->getFieldsForForm() as $fieldName => $fieldValue) : ?>
3
+ <?php if (is_array($fieldValue)) : ?>
4
+ <?php foreach($fieldValue as $key => $subFieldValue) :?>
5
+ <input type="hidden" name="<?php echo $fieldName?>" value="<?php echo htmlspecialchars($subFieldValue); ?>" />
6
+ <?php endforeach; ?>
7
+ <?php else : ?>
8
+ <input type="hidden" id="<?php echo $fieldName?>" name="<?php echo $fieldName?>" value="<?php echo htmlspecialchars($fieldValue); ?>" />
9
+ <?php endif; ?>
10
+ <?php endforeach; ?>
11
+ </form>
12
+ <script type="text/javascript">
13
+ //<![CDATA[
14
+ document.observe("dom:loaded", function() {
15
+ $('bpostShmForm').submit();
16
+ });
17
+ var shm = window.parent.parent.shm;
18
+
19
+ function fetchVariable(toFieldId, fromFieldId){
20
+ shm.updateStartFormField(document.getElementById(toFieldId), fromFieldId);
21
+ }
22
+
23
+ fetchVariable("customerFirstName", "firstname");
24
+ fetchVariable("customerLastName", "lastname");
25
+ fetchVariable("customerLastName", "lastname");
26
+ fetchVariable("customerPhoneNumber", "telephone");
27
+ fetchVariable("customerEmail", "email");
28
+ fetchVariable("customerPostalCode", "postcode");
29
+ fetchVariable("customerCity", "city");
30
+ //fetchVariable("customerCountry", "country_id");
31
+ //]]>
32
+ </script>
app/etc/modules/Bpost_ShippingManager.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Bpost_ShippingManager>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ </depends>
9
+ </Bpost_ShippingManager>
10
+ </modules>
11
+ </config>
app/locale/en_US/Bpost_ShippingManager.csv ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Allowed bpost shipping methods comment", "Please select the delivery methods that are available for your customers."
2
+ "Allowed bpost shipping methods", "Allowed delivery methods"
3
+ "bpost shippingcost rules", "Delivery cost rules"
4
+ "bpost shippingcost rules comment", "Please specify a price rule for every delivery method (more info in manual)"
5
+ "Free delivery from (in €)", "Free delivery from (amount in €)"
6
+ "Leave blank to not offering free delivery", "Leave empty if you do not wish to offer free delivery"
7
+ "Sort Order", "Sort order"
8
+ "Front end URL", "Front end URL"
9
+ "bpost AccountId", "bpost Account ID"
10
+ "bpost passphrase", "bpost passphrase"
11
+ "Carrier name", "Carrier name"
12
+ "This field should not be changed unless absolutely sure", "This field should not be changed unless absolutely sure"
13
+ "Open bpost shippingmanager", "Click here to ship with bpost"
app/locale/fr_FR/Bpost_ShippingManager.csv ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Allowed bpost shipping methods comment", "Veuillez sélectionner les méthodes de livraison disponibles pour vos clients."
2
+ "Allowed bpost shipping methods", "Méthodes de livraison supportées"
3
+ "bpost shippingcost rules", "Règles relatives aux de frais de livraison"
4
+ "bpost shippingcost rules comment", "Lorsque ce champ est laissé vide, la configuration du Shipping Manager de bpost contrôle les paramétrages relatifs au prix. Veuillez spécifier une règle de prix pour chaque méthode de livraison (plus d'info dans le manuel)"
5
+ "Free delivery from (in €)", "Livraison gratuite à partir de (montant en €)"
6
+ "Leave blank to not offering free delivery", "Laissez vide si vous ne souhaitez pas offrir la livraison gratuite"
7
+ "Sort Order", "L'ordre de tri"
8
+ "Front end URL", "Front end URL"
9
+ "bpost AccountId", "bpost Account ID"
10
+ "bpost passphrase", "bpost passphrase"
11
+ "Carrier name", "Carrier name"
12
+ "This field should not be changed unless absolutely sure", "Ce champ ne doit pas être changé, sauf si vous en êtes absolument sûr"
13
+ "Open bpost shippingmanager", "Cliquer ici pour envoyer avec bpost"
app/locale/nl_NL/Bpost_ShippingManager.csv ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Allowed bpost shipping methods comment", "Selecteer de leveringsmethodes die je wenst beschikbaar te maken voor de klanten."
2
+ "Allowed bpost shipping methods", "Toegestane leveringsmethodes"
3
+ "bpost shippingcost rules", "Verzendingskost regels"
4
+ "bpost shippingcost rules comment", "Wanneer dit veld leeg is, zal de bpost shipping manager de verzendingskosten zelf bepalen. Specifieer per leveringsmethode een prijsregel (zie manual voor meer info)"
5
+ "Free delivery from (in €)", "Gratis levering vanaf (bedrag in €)"
6
+ "Leave blank to not offering free delivery", "Leeg laten om geen gratis levering aan te bieden"
7
+ "Sort Order", "Sorteer volgorde"
8
+ "Front end URL", "Front end URL"
9
+ "bpost AccountId", "bpost Account ID"
10
+ "bpost passphrase", "bpost wachtwoord"
11
+ "Carrier name", "Carrier name"
12
+ "This field should not be changed unless absolutely sure", "Dit veld niet wijzigen indien u niet 100% zeker bent!"
13
+ "Open bpost shippingmanager", "Klik hier om te verzenden met bpost"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>shipping_manager_by_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>Integrate your webshop with the Bpost Shipping Manager</summary>
10
+ <description>Integrate your webshop with the Bpost Shipping Manager</description>
11
+ <notes>Release version 1.0.0 - Magento Connect 1.0 compatible</notes>
12
+ <authors><author><name>Bpost Shipping Manager</name><user>auto-converted</user><email>shippingmanager@bpost.be</email></author></authors>
13
+ <date>2011-11-14</date>
14
+ <time>09:38:54</time>
15
+ <contents><target name="magecommunity"><dir name="Bpost"><dir name="ShippingManager"><dir name="Block"><dir name="Adminhtml"><file name="Javascript.php" hash="0ab946175f3362d100261bbb36fcf4b0"/></dir><dir name="Onepage"><dir name="Shipping"><dir name="Method"><file name="Available.php" hash="9302f31605b85947cabf951fb68f0c53"/></dir></dir></dir><file name="Abstract.php" hash="8d5f9030dd6842dca9bd7843ea297007"/><file name="Confirm.php" hash="b65ef586816919f04cecfa1953cd0a83"/><file name="Javascript.php" hash="9b2b69a9c3674482dc9492c071ea10da"/><file name="Platformstub.php" hash="e866b6d29b2b60cfb781f27914987718"/><file name="Startform.php" hash="edeab0cdbfae4c5f8a3ca925e7bc7485"/><file name="Tracking.php" hash="e4853967b47b8301f6b07a92b6a9f5a5"/></dir><dir name="Helper"><file name="Data.php" hash="60c0d30811197af84d85dba9d8aab96c"/></dir><dir name="Model"><dir name="Carrier"><dir name="Shippingmethod"><file name="Abstract.php" hash="3f8118091c5069dcfbca605224a75adc"/><file name="Bpackbusiness.php" hash="bb6ef42367bdc9cd570cbef205f56f12"/><file name="Bpackexpress.php" hash="627117ffd6f63b7b269d1acfd90effc1"/><file name="Parcelsdepot.php" hash="2eee630c1a23fd102193b32dfa43442f"/><file name="Pugo.php" hash="2381c89fef74a38790eb14545889e605"/><file name="Regular.php" hash="4b389f98ee23f80e45885e75d2880c64"/></dir><dir name="System"><dir name="Config"><dir name="Source"><file name="Method.php" hash="5dfbcba9683aeab80c70c7934e14c0b6"/></dir></dir></dir><file name="Bpost.php" hash="fd91f1065a51d5ca03ba21ec85f5eb3b"/></dir><dir name="Entity"><file name="Setup.php" hash="c8692103c51b36752176a521228cd5b9"/></dir><file name="Api.php" hash="aafce765c482daf342d51d8e6abec2d2"/><file name="Observer.php" hash="57b2cc240ac357525b5c331627055896"/><file name="Postback.php" hash="26ca9fdc2b742f262f6daf5d582d42ee"/><file name="ShippingManager.php" hash="179d14fb2b82f2221613296d07b30b72"/></dir><dir name="Test"><dir name="Block"><dir name="Onepage"><dir name="Shipping"><dir name="Method"><dir name="Available"><dir name="fixtures"><file name="bpostModuleConfig.yaml" hash="6d289581f8f7aa3393bfbc5cbeb7b526"/></dir></dir><file name="Available.php" hash="70a6f000dddd3c6f081f1087379bb15f"/></dir></dir></dir></dir><dir name="Controller"><dir name="PostbackController"><dir name="fixtures"><file name="startformAction.yaml" hash="1b416588a9fdc6dfaafa08028b700dcd"/></dir></dir><file name="ApiController.php" hash="acd26e9faabbcc7f9ff29a2d663a83eb"/><file name="PostbackController.php" hash="d956d8d25c4c7fd8242fadf8cb479a50"/></dir><dir name="Helper"><dir name="Data"><dir name="fixtures"><file name="allowedShippingMethodsIsNotSet.yaml" hash="2404a1d3412fe059ec3074e73083d8cd"/><file name="bpostModuleConfig.yaml" hash="184253d6e01fba38dd4215925798bc2e"/><file name="getApiUriReturnsConcatOfApiuriAndAccountid.yaml" hash="8b690459fa829151afd1d3c406716a85"/><file name="getApiUriReturnsEmptyStringWhenAccountIdIsNotSet.yaml" hash="7d78fda7839a5b5b9fb6ddde7ce05782"/><file name="getApiUriReturnsEmptyStringWhenApiUriIsNotSet.yaml" hash="aad34afc48d44b97bdc1efef523f0825"/><file name="onlyOneAllowedShippingMethodsIsSet.yaml" hash="46b75caea1e4c55907b455cbc92aa9cd"/><file name="rateTableIsEmpty.yaml" hash="31e08e45c74083babbdc7593e4634b44"/><file name="rateTableIsInvalidJasonStringRaisesException.yaml" hash="317e2e102bb5fb8a4634982267cd58df"/></dir></dir><file name="Data.php" hash="6d71e6bf8b85c108722bd86868386df7"/></dir><dir name="Model"><dir name="Api"><dir name="fixtures"><file name="bpostModuleConfig.yaml" hash="fe634cde1912094294ab1ebb249cbaf2"/></dir></dir><dir name="Carrier"><dir name="Bpost"><dir name="fixtures"><file name="bpostModuleConfig.yaml" hash="65cb892ddb2dc546f61e8086ceed0165"/><file name="carrierDeactivated.yaml" hash="b68bdb4508ae59d082d979bfc5b9ace3"/></dir></dir><dir name="Shippingmethod"><dir name="Abstract"><dir name="fixtures"><file name="bpostModuleConfig.yaml" hash="184253d6e01fba38dd4215925798bc2e"/></dir></dir><file name="Abstract.php" hash="2a09764bfae5813b5c0f167e25c4ee1c"/></dir><dir name="System"><dir name="Config"><dir name="Source"><dir name="Method"><dir name="fixtures"><file name="bpostModuleConfig.yaml" hash="184253d6e01fba38dd4215925798bc2e"/></dir></dir><file name="Method.php" hash="18a40b6f7a7c1027bfece6710ad49c6a"/></dir></dir></dir><file name="Bpost.php" hash="1faef88fd7bd65c313446fe7ffd173fc"/></dir><dir name="ShippingManager"><dir name="fixtures"><file name="accountIdNotFilledIn.yaml" hash="fec4942ecd2594ff1cf56eaf2640a4d5"/><file name="bpostModuleConfig.yaml" hash="6d289581f8f7aa3393bfbc5cbeb7b526"/><file name="bpostOrderSetup.yaml" hash="5e27423a3e158b179ac35c8a0962ea64"/><file name="carrierDeactivated.yaml" hash="6d28e9989a3ee1c54545d9cabb5ee19f"/><file name="passphraseNotFilledIn.yaml" hash="fec4942ecd2594ff1cf56eaf2640a4d5"/></dir></dir><file name="Api.php" hash="8358bbaa7e33ab1d3ea0ca3918e2ac79"/><file name="ShippingManager.php" hash="fe6eb25550cf7c4c7e85e770f529f1f5"/></dir></dir><dir name="controllers"><file name="ApiController.php" hash="77a049fc6940ba2308f3b8891e59c60e"/><file name="PostbackController.php" hash="5a2e842b70a33e3704023ff9f1290680"/></dir><dir name="etc"><file name="adminhtml.xml" hash="d9c5e6f543a9af0ebb92dac1a2b42006"/><file name="api.xml" hash="0f48f95522f099f50d109e42dedbc424"/><file name="config.xml" hash="582cccf932244c1bd0af7765b64f2a12"/><file name="system.xml" hash="1311c2591d46b815f96bf988ac43e278"/><file name="wsdl.xml" hash="e42540773987c7b835eb2f72cc01ed67"/></dir><dir name="sql"><dir name="bpost_shippingmanager_setup"><file name="mysql4-install-0.1.0.php" hash="c30cab84063872770115cc569e24a480"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="bpost_shippingmanager.xml" hash="88403d37b604ef4d7f0d7e8f76146f5a"/></dir><dir name="template"><dir name="bpost"><dir name="shippingmanager"><dir name="dynamic"><file name="jsforcheckoutcart.phtml" hash="5ff98ca86b9fa6993fe3a65183e67c15"/><file name="jsforgreybox.phtml" hash="e2bf3e6ff7825f6a3b4ab33199fad271"/><file name="jsforonepagecheckout.phtml" hash="47a76eed4225adda990809b95ae25d22"/><file name="jsforonestepcheckout.phtml" hash="468f8fd21d7888c24cdae5a8a4975abd"/><file name="jsforordershipment.phtml" hash="00f39f15e4fed4f2c597d8c89aff4f13"/></dir><file name="cancel.phtml" hash="cc3e8c898eef36fdc277ffc1032e77ba"/><file name="confirm.phtml" hash="f6c4c7174314cf4c75638e149d7e9baa"/><file name="createtrackingcode.phtml" hash="4a8780e0fca9c9f4957a2b0880196c9d"/><file name="error.phtml" hash="0cd68ef85f387d166898aadc5ea25eaf"/><file name="platformstub.phtml" hash="dec726718470c2c54d8b9953e4a13a92"/><file name="startform.phtml" hash="aebe90935c7e942da9b4a7a0fb095c9c"/></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="bpost_shippingmanager.xml" hash="88ea1feb1643b7f0a9322fd3977b5cdd"/></dir><dir name="template"><dir name="bpost"><dir name="shippingmanager"><dir name="dynamic"><file name="jsforordershipment.phtml" hash="4ae569e71b74c94c310c8da8747ffd83"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><dir name="bpost"><dir name="shippingmanager"><file name="bpost_shippingmanager_base.js" hash="40bbea88b41ccd4e8170fb347141a975"/><file name="checkout_cart.js" hash="8afb34c57f9f8342d17bee04cec03e71"/><file name="onepage_checkout.js" hash="df29762f43da54315050e85471553c4a"/><file name="onestep_checkout.js" hash="cc062a8796979ed9204076663ed59a92"/></dir></dir></dir><dir name="images"><dir name="bpost"><dir name="shippingmanager"><file name="logo_bpost.jpg" hash="2b0e2d47018154ba1c935dd80355e771"/><file name="track_and_trace.jpg" hash="7ca6ee455d53dbc1dfa358b9641d22c3"/></dir></dir></dir><dir name="greybox"><file name="AJS.js" hash="886ccc135b9c203048ce6b134732d95b"/><file name="AJS_fx.js" hash="d867777d90af5222f45e3774a99a033f"/><file name="content-bottom-bg.gif" hash="ae5d41b464b83b22deb82ca80b445571"/><file name="custom-integration-onestepcheckout.js" hash="2eec6d61664af27f298511c14a83645f"/><file name="g_close.gif" hash="ae7187edec916ea7b4aa2f77dff1b091"/><file name="gb_scripts.js" hash="cbf4debce2381db6269c1f7e01694aaf"/><file name="gb_styles.css" hash="b974251a4046f57713e8782646dc4dc7"/><file name="gb_styles_orig.css" hash="c4fca7c3950c3eae4c534198edb2affc"/><file name="header_bg.gif" hash="1bd8490d1995e4fa776a50a9543ad729"/><file name="indicator.gif" hash="dca3c5a14c66fb17a718cde2a7626539"/><file name="loader_frame.html" hash="e0e5eb184825877a77095bf6c81c955f"/><file name="next.gif" hash="9f86b6cc8b8548bcaace895b886c1348"/><file name="prev.gif" hash="05eb53ece32e907f467d456253ef2c2c"/><file name="w_close.gif" hash="f2aace763cfcc4d6f3427a8a0842e55c"/><file name="w_close1.gif" hash="ed3b8e3a5b9deab62af477787044ca89"/></dir></dir></dir></dir><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="js"><dir name="bpost"><dir name="shippingmanager"><file name="base.js" hash="1ed0c843b314106fd38a447cd2873eb4"/><file name="sales_order_shipment_view.js" hash="0a7df228471e6114fe7c7e1762f539b4"/></dir></dir></dir><dir name="css"><dir name="bpost"><dir name="shippingmanager"><file name="bpost.css" hash="8109845fc6010afeb9649f41d89254f6"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bpost_ShippingManager.xml" hash="bd605f69c3b123533bf43d5769da0fe7"/></dir></target><target name="magelocale"><dir name="nl_NL"><file name="Bpost_ShippingManager.csv" hash="0e28619a1903faa047f1463f17b01b5c"/></dir><dir name="en_US"><file name="Bpost_ShippingManager.csv" hash="e4feb6d378fec388b0db16543fcf9900"/></dir><dir name="fr_FR"><file name="Bpost_ShippingManager.csv" hash="3c7a3539c933ba33c519ddafbcc206d5"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>
skin/adminhtml/base/default/css/bpost/shippingmanager/bpost.css ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ button.bpost{
2
+ background : none;
3
+ background-color: #FF0000;
4
+ margin : 0 0 0 5px;
5
+ }
6
+
skin/adminhtml/base/default/js/bpost/shippingmanager/base.js ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var BpostTrackingControlsCreator = Class.create();
2
+
3
+ BpostTrackingControlsCreator.prototype = {
4
+ initialize: function(){
5
+
6
+ },
7
+
8
+ log : function (message, level){
9
+ if (this.logging) {
10
+ if(level == ""){
11
+ level = "log";
12
+ }
13
+ eval("console." + level + "(message)");
14
+ }
15
+ },
16
+
17
+ createPrintLabelbutton : function(){
18
+ var printLabelButton = new Element('button',{'id' : 'print_labels', 'type' : 'button'});
19
+ var labelButton = new Element('span');
20
+ labelButton.update("Print all labels");
21
+ printLabelButton.appendChild(labelButton);
22
+ printLabelButton.addClassName('scalable bpost');
23
+ printLabelButton.observe('click', function() {
24
+ window.location = requestPrintAllLabelsUrl + orderReference;
25
+ });
26
+ return printLabelButton;
27
+ },
28
+
29
+ addPrintLabelButton : function(parentElement){
30
+ parentElement.appendChild(this.createPrintLabelbutton());
31
+ },
32
+
33
+ hideAddTrackingCodeRow : function() {
34
+ $$("div#shipment_tracking_info tfoot tr").first().hide();
35
+ },
36
+
37
+ getTrackingCodeTable : function() {
38
+ return $('tracking_numbers_table').select("tfoot").first();
39
+ },
40
+
41
+ getCreateNewLabelButton : function(){
42
+ var createNewLabelButton = new Element('button',{'id' : 'create_label', 'type' : 'button'});
43
+ var labelButton = new Element('span');
44
+ labelButton.update("Create new label");
45
+ createNewLabelButton.appendChild(labelButton);
46
+ createNewLabelButton.addClassName('scalable bpost');
47
+ createNewLabelButton.observe('click', function() {
48
+ bpostTrackingControls.requestNewlabel();
49
+ });
50
+ return createNewLabelButton;
51
+ },
52
+
53
+ requestNewlabel : function (){
54
+ bpostTrackingControls.log("Starting request for a new label.","debug");
55
+ new Ajax.Request(requestNewTrackingCodeUrl,
56
+ {
57
+ method:'post',
58
+ parameters: {order: orderReference},
59
+ onSuccess: function(transport){
60
+ bpostTrackingControls.log("New label created successfull.","debug");
61
+ bpostTrackingControls.insertNewTrackingCodeData(transport);
62
+ },
63
+ onFailure: function(){ this.log("Could not retrieve new TrackingCode","error"); }
64
+ });
65
+ },
66
+
67
+ updateFields : function(parcel) {
68
+ trackingControl.add();
69
+ var trackingNumberIndex = $$('tbody#track_row_container tr').length - 1;
70
+ $('trackingC' + trackingNumberIndex).value= 'bpost';
71
+ $('trackingT' + trackingNumberIndex).value = 'bpost';
72
+ $('trackingN' + trackingNumberIndex).value = parcel.barcode;
73
+ },
74
+
75
+ insertNewTrackingCodeData : function (transport){
76
+ if(transport.responseText.isJSON()){
77
+ var parcel = transport.responseText.evalJSON()
78
+ window.location = requestPrintLabelUrl + '?orderReference=' + orderReference + '&barcode=' + parcel.barcode;
79
+ this.updateFields(parcel);
80
+ }
81
+ },
82
+
83
+ getCreateNewLabelButtonCell : function(){
84
+ var cell = new Element('td',{'colspan' : '4', 'style' : 'padding: 8px; background-color: #FFFFFF;'});
85
+ cell.addClassName('a-center last');
86
+ cell.appendChild(this.getCreateNewLabelButton());
87
+ cell.appendChild(this.createPrintLabelbutton());
88
+ return cell;
89
+ },
90
+
91
+ add : function() {
92
+ var tableFooter = this.getTrackingCodeTable();
93
+ var row = new Element('tr', {'id' : 'bpost_tracking_controls'});
94
+ row.appendChild(this.getCreateNewLabelButtonCell());
95
+ tableFooter.appendChild(row);
96
+ }
97
+
98
+ }
99
+
100
+ var bpostTrackingControls = new BpostTrackingControlsCreator();
101
+
102
+ document.observe('dom:loaded', function() {
103
+ if(carrierCode == "bpost"){
104
+ bpostTrackingControls.add();
105
+ }
106
+ });
107
+
skin/adminhtml/base/default/js/bpost/shippingmanager/sales_order_shipment_view.js ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BpostTrackingControlsCreator.prototype = Object.extend(new BpostTrackingControlsCreator(), {
2
+
3
+ getTrackingCodeTable : function() {
4
+ return $('shipment_tracking_info').select("tfoot").first();
5
+ },
6
+
7
+ updateFields : function(parcel) {
8
+ $('tracking_number').value = parcel.barcode;
9
+ $$('div#shipment_tracking_info select[name="carrier"]').first().value= 'bpost';
10
+ $('tracking_title').value = 'bpost';
11
+ detectTrackingInformationReload();
12
+ $('shipment_tracking_info').select("tfoot td.last button").first().click();
13
+ },
14
+
15
+ });
16
+
17
+ var bpostTrackingControls = new BpostTrackingControlsCreator();
18
+
19
+ function detectTrackingInformationReload(){
20
+ if($('bpost_tracking_controls') == null){
21
+ bpostTrackingControls.add();
22
+ } else{
23
+ setTimeout(detectTrackingInformationReload, 10);
24
+ }
25
+ }
skin/frontend/base/default/greybox/AJS.js ADDED
@@ -0,0 +1,514 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ AJS={BASE_URL:"",drag_obj:null,drag_elm:null,_drop_zones:[],_cur_pos:null,getScrollTop:function(){
2
+ var t;
3
+ if(document.documentElement&&document.documentElement.scrollTop){
4
+ t=document.documentElement.scrollTop;
5
+ }else{
6
+ if(document.body){
7
+ t=document.body.scrollTop;
8
+ }
9
+ }
10
+ return t;
11
+ },addClass:function(){
12
+ var _2=AJS.forceArray(arguments);
13
+ var _3=_2.pop();
14
+ var _4=function(o){
15
+ if(!new RegExp("(^|\\s)"+_3+"(\\s|$)").test(o.className)){
16
+ o.className+=(o.className?" ":"")+_3;
17
+ }
18
+ };
19
+ AJS.map(_2,function(_6){
20
+ _4(_6);
21
+ });
22
+ },setStyle:function(){
23
+ var _7=AJS.forceArray(arguments);
24
+ var _8=_7.pop();
25
+ var _9=_7.pop();
26
+ AJS.map(_7,function(_a){
27
+ _a.style[_9]=AJS.getCssDim(_8);
28
+ });
29
+ },extend:function(_b){
30
+ var _c=new this("no_init");
31
+ for(k in _b){
32
+ var _d=_c[k];
33
+ var _e=_b[k];
34
+ if(_d&&_d!=_e&&typeof _e=="function"){
35
+ _e=this._parentize(_e,_d);
36
+ }
37
+ _c[k]=_e;
38
+ }
39
+ return new AJS.Class(_c);
40
+ },log:function(o){
41
+ if(window.console){
42
+ console.log(o);
43
+ }else{
44
+ var div=AJS.$("ajs_logger");
45
+ if(!div){
46
+ div=AJS.DIV({id:"ajs_logger","style":"color: green; position: absolute; left: 0"});
47
+ div.style.top=AJS.getScrollTop()+"px";
48
+ AJS.ACN(AJS.getBody(),div);
49
+ }
50
+ AJS.setHTML(div,""+o);
51
+ }
52
+ },setHeight:function(){
53
+ var _11=AJS.forceArray(arguments);
54
+ _11.splice(_11.length-1,0,"height");
55
+ AJS.setStyle.apply(null,_11);
56
+ },_getRealScope:function(fn,_13){
57
+ _13=AJS.$A(_13);
58
+ var _14=fn._cscope||window;
59
+ return function(){
60
+ var _15=AJS.$FA(arguments).concat(_13);
61
+ return fn.apply(_14,_15);
62
+ };
63
+ },documentInsert:function(elm){
64
+ if(typeof (elm)=="string"){
65
+ elm=AJS.HTML2DOM(elm);
66
+ }
67
+ document.write("<span id=\"dummy_holder\"></span>");
68
+ AJS.swapDOM(AJS.$("dummy_holder"),elm);
69
+ },getWindowSize:function(doc){
70
+ doc=doc||document;
71
+ var _18,_19;
72
+ if(self.innerHeight){
73
+ _18=self.innerWidth;
74
+ _19=self.innerHeight;
75
+ }else{
76
+ if(doc.documentElement&&doc.documentElement.clientHeight){
77
+ _18=doc.documentElement.clientWidth;
78
+ _19=doc.documentElement.clientHeight;
79
+ }else{
80
+ if(doc.body){
81
+ _18=doc.body.clientWidth;
82
+ _19=doc.body.clientHeight;
83
+ }
84
+ }
85
+ }
86
+ return {"w":_18,"h":_19};
87
+ },flattenList:function(_1a){
88
+ var r=[];
89
+ var _1c=function(r,l){
90
+ AJS.map(l,function(o){
91
+ if(o==null){
92
+ }else{
93
+ if(AJS.isArray(o)){
94
+ _1c(r,o);
95
+ }else{
96
+ r.push(o);
97
+ }
98
+ }
99
+ });
100
+ };
101
+ _1c(r,_1a);
102
+ return r;
103
+ },isFunction:function(obj){
104
+ return (typeof obj=="function");
105
+ },setEventKey:function(e){
106
+ e.key=e.keyCode?e.keyCode:e.charCode;
107
+ if(window.event){
108
+ e.ctrl=window.event.ctrlKey;
109
+ e.shift=window.event.shiftKey;
110
+ }else{
111
+ e.ctrl=e.ctrlKey;
112
+ e.shift=e.shiftKey;
113
+ }
114
+ switch(e.key){
115
+ case 63232:
116
+ e.key=38;
117
+ break;
118
+ case 63233:
119
+ e.key=40;
120
+ break;
121
+ case 63235:
122
+ e.key=39;
123
+ break;
124
+ case 63234:
125
+ e.key=37;
126
+ break;
127
+ }
128
+ },removeElement:function(){
129
+ var _22=AJS.forceArray(arguments);
130
+ AJS.map(_22,function(elm){
131
+ AJS.swapDOM(elm,null);
132
+ });
133
+ },_unloadListeners:function(){
134
+ if(AJS.listeners){
135
+ AJS.map(AJS.listeners,function(elm,_25,fn){
136
+ AJS.REV(elm,_25,fn);
137
+ });
138
+ }
139
+ AJS.listeners=[];
140
+ },join:function(_27,_28){
141
+ try{
142
+ return _28.join(_27);
143
+ }
144
+ catch(e){
145
+ var r=_28[0]||"";
146
+ AJS.map(_28,function(elm){
147
+ r+=_27+elm;
148
+ },1);
149
+ return r+"";
150
+ }
151
+ },getIndex:function(elm,_2c,_2d){
152
+ for(var i=0;i<_2c.length;i++){
153
+ if(_2d&&_2d(_2c[i])||elm==_2c[i]){
154
+ return i;
155
+ }
156
+ }
157
+ return -1;
158
+ },isIn:function(elm,_30){
159
+ var i=AJS.getIndex(elm,_30);
160
+ if(i!=-1){
161
+ return true;
162
+ }else{
163
+ return false;
164
+ }
165
+ },isArray:function(obj){
166
+ return obj instanceof Array;
167
+ },setLeft:function(){
168
+ var _33=AJS.forceArray(arguments);
169
+ _33.splice(_33.length-1,0,"left");
170
+ AJS.setStyle.apply(null,_33);
171
+ },appendChildNodes:function(elm){
172
+ if(arguments.length>=2){
173
+ AJS.map(arguments,function(n){
174
+ if(AJS.isString(n)){
175
+ n=AJS.TN(n);
176
+ }
177
+ if(AJS.isDefined(n)){
178
+ elm.appendChild(n);
179
+ }
180
+ },1);
181
+ }
182
+ return elm;
183
+ },getElementsByTagAndClassName:function(_36,_37,_38,_39){
184
+ var _3a=[];
185
+ if(!AJS.isDefined(_38)){
186
+ _38=document;
187
+ }
188
+ if(!AJS.isDefined(_36)){
189
+ _36="*";
190
+ }
191
+ var els=_38.getElementsByTagName(_36);
192
+ var _3c=els.length;
193
+ var _3d=new RegExp("(^|\\s)"+_37+"(\\s|$)");
194
+ for(i=0,j=0;i<_3c;i++){
195
+ if(_3d.test(els[i].className)||_37==null){
196
+ _3a[j]=els[i];
197
+ j++;
198
+ }
199
+ }
200
+ if(_39){
201
+ return _3a[0];
202
+ }else{
203
+ return _3a;
204
+ }
205
+ },isOpera:function(){
206
+ return (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
207
+ },isString:function(obj){
208
+ return (typeof obj=="string");
209
+ },hideElement:function(elm){
210
+ var _40=AJS.forceArray(arguments);
211
+ AJS.map(_40,function(elm){
212
+ elm.style.display="none";
213
+ });
214
+ },setOpacity:function(elm,p){
215
+ elm.style.opacity=p;
216
+ elm.style.filter="alpha(opacity="+p*100+")";
217
+ },insertBefore:function(elm,_45){
218
+ _45.parentNode.insertBefore(elm,_45);
219
+ return elm;
220
+ },setWidth:function(){
221
+ var _46=AJS.forceArray(arguments);
222
+ _46.splice(_46.length-1,0,"width");
223
+ AJS.setStyle.apply(null,_46);
224
+ },createArray:function(v){
225
+ if(AJS.isArray(v)&&!AJS.isString(v)){
226
+ return v;
227
+ }else{
228
+ if(!v){
229
+ return [];
230
+ }else{
231
+ return [v];
232
+ }
233
+ }
234
+ },isDict:function(o){
235
+ var _49=String(o);
236
+ return _49.indexOf(" Object")!=-1;
237
+ },isMozilla:function(){
238
+ return (navigator.userAgent.toLowerCase().indexOf("gecko")!=-1&&navigator.productSub>=20030210);
239
+ },removeEventListener:function(elm,_4b,fn,_4d){
240
+ var _4e="ajsl_"+_4b+fn;
241
+ if(!_4d){
242
+ _4d=false;
243
+ }
244
+ fn=elm[_4e]||fn;
245
+ if(elm["on"+_4b]==fn){
246
+ elm["on"+_4b]=elm[_4e+"old"];
247
+ }
248
+ if(elm.removeEventListener){
249
+ elm.removeEventListener(_4b,fn,_4d);
250
+ if(AJS.isOpera()){
251
+ elm.removeEventListener(_4b,fn,!_4d);
252
+ }
253
+ }else{
254
+ if(elm.detachEvent){
255
+ elm.detachEvent("on"+_4b,fn);
256
+ }
257
+ }
258
+ },callLater:function(fn,_50){
259
+ var _51=function(){
260
+ fn();
261
+ };
262
+ window.setTimeout(_51,_50);
263
+ },setTop:function(){
264
+ var _52=AJS.forceArray(arguments);
265
+ _52.splice(_52.length-1,0,"top");
266
+ AJS.setStyle.apply(null,_52);
267
+ },_createDomShortcuts:function(){
268
+ var _53=["ul","li","td","tr","th","tbody","table","input","span","b","a","div","img","button","h1","h2","h3","h4","h5","h6","br","textarea","form","p","select","option","optgroup","iframe","script","center","dl","dt","dd","small","pre","i"];
269
+ var _54=function(elm){
270
+ AJS[elm.toUpperCase()]=function(){
271
+ return AJS.createDOM.apply(null,[elm,arguments]);
272
+ };
273
+ };
274
+ AJS.map(_53,_54);
275
+ AJS.TN=function(_56){
276
+ return document.createTextNode(_56);
277
+ };
278
+ },addCallback:function(fn){
279
+ this.callbacks.unshift(fn);
280
+ },bindMethods:function(_58){
281
+ for(var k in _58){
282
+ var _5a=_58[k];
283
+ if(typeof (_5a)=="function"){
284
+ _58[k]=AJS.$b(_5a,_58);
285
+ }
286
+ }
287
+ },partial:function(fn){
288
+ var _5c=AJS.$FA(arguments);
289
+ _5c.shift();
290
+ return function(){
291
+ _5c=_5c.concat(AJS.$FA(arguments));
292
+ return fn.apply(window,_5c);
293
+ };
294
+ },isNumber:function(obj){
295
+ return (typeof obj=="number");
296
+ },getCssDim:function(dim){
297
+ if(AJS.isString(dim)){
298
+ return dim;
299
+ }else{
300
+ return dim+"px";
301
+ }
302
+ },isIe:function(){
303
+ return (navigator.userAgent.toLowerCase().indexOf("msie")!=-1&&navigator.userAgent.toLowerCase().indexOf("opera")==-1);
304
+ },removeClass:function(){
305
+ var _5f=AJS.forceArray(arguments);
306
+ var cls=_5f.pop();
307
+ var _61=function(o){
308
+ o.className=o.className.replace(new RegExp("\\s?"+cls,"g"),"");
309
+ };
310
+ AJS.map(_5f,function(elm){
311
+ _61(elm);
312
+ });
313
+ },setHTML:function(elm,_65){
314
+ elm.innerHTML=_65;
315
+ return elm;
316
+ },map:function(_66,fn,_68,_69){
317
+ var i=0,l=_66.length;
318
+ if(_68){
319
+ i=_68;
320
+ }
321
+ if(_69){
322
+ l=_69;
323
+ }
324
+ for(i;i<l;i++){
325
+ var val=fn(_66[i],i);
326
+ if(val!=undefined){
327
+ return val;
328
+ }
329
+ }
330
+ },addEventListener:function(elm,_6e,fn,_70,_71){
331
+ var _72="ajsl_"+_6e+fn;
332
+ if(!_71){
333
+ _71=false;
334
+ }
335
+ AJS.listeners=AJS.$A(AJS.listeners);
336
+ if(AJS.isIn(_6e,["keypress","keydown","keyup","click"])){
337
+ var _73=fn;
338
+ fn=function(e){
339
+ AJS.setEventKey(e);
340
+ return _73.apply(window,arguments);
341
+ };
342
+ }
343
+ var _75=AJS.isIn(_6e,["submit","load","scroll","resize"]);
344
+ var _76=AJS.$A(elm);
345
+ AJS.map(_76,function(_77){
346
+ if(_70){
347
+ var _78=fn;
348
+ fn=function(e){
349
+ AJS.REV(_77,_6e,fn);
350
+ return _78.apply(window,arguments);
351
+ };
352
+ }
353
+ if(_75){
354
+ var _7a=_77["on"+_6e];
355
+ var _7b=function(){
356
+ if(_7a){
357
+ fn(arguments);
358
+ return _7a(arguments);
359
+ }else{
360
+ return fn(arguments);
361
+ }
362
+ };
363
+ _77[_72]=_7b;
364
+ _77[_72+"old"]=_7a;
365
+ elm["on"+_6e]=_7b;
366
+ }else{
367
+ _77[_72]=fn;
368
+ if(_77.attachEvent){
369
+ _77.attachEvent("on"+_6e,fn);
370
+ }else{
371
+ if(_77.addEventListener){
372
+ _77.addEventListener(_6e,fn,_71);
373
+ }
374
+ }
375
+ AJS.listeners.push([_77,_6e,fn]);
376
+ }
377
+ });
378
+ },preloadImages:function(){
379
+ AJS.AEV(window,"load",AJS.$p(function(_7c){
380
+ AJS.map(_7c,function(src){
381
+ var pic=new Image();
382
+ pic.src=src;
383
+ });
384
+ },arguments));
385
+ },forceArray:function(_7f){
386
+ var r=[];
387
+ AJS.map(_7f,function(elm){
388
+ r.push(elm);
389
+ });
390
+ return r;
391
+ },update:function(l1,l2){
392
+ for(var i in l2){
393
+ l1[i]=l2[i];
394
+ }
395
+ return l1;
396
+ },getBody:function(){
397
+ return AJS.$bytc("body")[0];
398
+ },HTML2DOM:function(_85,_86){
399
+ var d=AJS.DIV();
400
+ d.innerHTML=_85;
401
+ if(_86){
402
+ return d.childNodes[0];
403
+ }else{
404
+ return d;
405
+ }
406
+ },getElement:function(id){
407
+ if(AJS.isString(id)||AJS.isNumber(id)){
408
+ return document.getElementById(id);
409
+ }else{
410
+ return id;
411
+ }
412
+ },showElement:function(){
413
+ var _89=AJS.forceArray(arguments);
414
+ AJS.map(_89,function(elm){
415
+ elm.style.display="";
416
+ });
417
+ },bind:function(fn,_8c,_8d){
418
+ fn._cscope=_8c;
419
+ return AJS._getRealScope(fn,_8d);
420
+ },createDOM:function(_8e,_8f){
421
+ var i=0,_91;
422
+ var elm=document.createElement(_8e);
423
+ var _93=_8f[0];
424
+ if(AJS.isDict(_8f[i])){
425
+ for(k in _93){
426
+ _91=_93[k];
427
+ if(k=="style"||k=="s"){
428
+ elm.style.cssText=_91;
429
+ }else{
430
+ if(k=="c"||k=="class"||k=="className"){
431
+ elm.className=_91;
432
+ }else{
433
+ elm.setAttribute(k,_91);
434
+ }
435
+ }
436
+ }
437
+ i++;
438
+ }
439
+ if(_93==null){
440
+ i=1;
441
+ }
442
+ for(var j=i;j<_8f.length;j++){
443
+ var _91=_8f[j];
444
+ if(_91){
445
+ var _95=typeof (_91);
446
+ if(_95=="string"||_95=="number"){
447
+ _91=AJS.TN(_91);
448
+ }
449
+ elm.appendChild(_91);
450
+ }
451
+ }
452
+ return elm;
453
+ },swapDOM:function(_96,src){
454
+ _96=AJS.getElement(_96);
455
+ var _98=_96.parentNode;
456
+ if(src){
457
+ src=AJS.getElement(src);
458
+ _98.replaceChild(src,_96);
459
+ }else{
460
+ _98.removeChild(_96);
461
+ }
462
+ return src;
463
+ },isDefined:function(o){
464
+ return (o!="undefined"&&o!=null);
465
+ }};
466
+ AJS.$=AJS.getElement;
467
+ AJS.$$=AJS.getElements;
468
+ AJS.$f=AJS.getFormElement;
469
+ AJS.$p=AJS.partial;
470
+ AJS.$b=AJS.bind;
471
+ AJS.$A=AJS.createArray;
472
+ AJS.DI=AJS.documentInsert;
473
+ AJS.ACN=AJS.appendChildNodes;
474
+ AJS.RCN=AJS.replaceChildNodes;
475
+ AJS.AEV=AJS.addEventListener;
476
+ AJS.REV=AJS.removeEventListener;
477
+ AJS.$bytc=AJS.getElementsByTagAndClassName;
478
+ AJS.$AP=AJS.absolutePosition;
479
+ AJS.$FA=AJS.forceArray;
480
+ AJS.addEventListener(window,"unload",AJS._unloadListeners);
481
+ AJS._createDomShortcuts();
482
+ AJS.Class=function(_9a){
483
+ var fn=function(){
484
+ if(arguments[0]!="no_init"){
485
+ return this.init.apply(this,arguments);
486
+ }
487
+ };
488
+ fn.prototype=_9a;
489
+ AJS.update(fn,AJS.Class.prototype);
490
+ return fn;
491
+ };
492
+ AJS.Class.prototype={extend:function(_9c){
493
+ var _9d=new this("no_init");
494
+ for(k in _9c){
495
+ var _9e=_9d[k];
496
+ var cur=_9c[k];
497
+ if(_9e&&_9e!=cur&&typeof cur=="function"){
498
+ cur=this._parentize(cur,_9e);
499
+ }
500
+ _9d[k]=cur;
501
+ }
502
+ return new AJS.Class(_9d);
503
+ },implement:function(_a0){
504
+ AJS.update(this.prototype,_a0);
505
+ },_parentize:function(cur,_a2){
506
+ return function(){
507
+ this.parent=_a2;
508
+ return cur.apply(this,arguments);
509
+ };
510
+ }};
511
+ script_loaded=true;
512
+
513
+
514
+ script_loaded=true;
skin/frontend/base/default/greybox/AJS_fx.js ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ AJS.fx={_shades:{0:"ffffff",1:"ffffee",2:"ffffdd",3:"ffffcc",4:"ffffbb",5:"ffffaa",6:"ffff99"},highlight:function(_1,_2){
2
+ var _3=new AJS.fx.Base();
3
+ _3.elm=AJS.$(_1);
4
+ _3.options.duration=600;
5
+ _3.setOptions(_2);
6
+ AJS.update(_3,{increase:function(){
7
+ if(this.now==7){
8
+ _1.style.backgroundColor="#fff";
9
+ }else{
10
+ _1.style.backgroundColor="#"+AJS.fx._shades[Math.floor(this.now)];
11
+ }
12
+ }});
13
+ return _3.custom(6,0);
14
+ },fadeIn:function(_4,_5){
15
+ _5=_5||{};
16
+ if(!_5.from){
17
+ _5.from=0;
18
+ AJS.setOpacity(_4,0);
19
+ }
20
+ if(!_5.to){
21
+ _5.to=1;
22
+ }
23
+ var s=new AJS.fx.Style(_4,"opacity",_5);
24
+ return s.custom(_5.from,_5.to);
25
+ },fadeOut:function(_7,_8){
26
+ _8=_8||{};
27
+ if(!_8.from){
28
+ _8.from=1;
29
+ }
30
+ if(!_8.to){
31
+ _8.to=0;
32
+ }
33
+ _8.duration=300;
34
+ var s=new AJS.fx.Style(_7,"opacity",_8);
35
+ return s.custom(_8.from,_8.to);
36
+ },setWidth:function(_a,_b){
37
+ var s=new AJS.fx.Style(_a,"width",_b);
38
+ return s.custom(_b.from,_b.to);
39
+ },setHeight:function(_d,_e){
40
+ var s=new AJS.fx.Style(_d,"height",_e);
41
+ return s.custom(_e.from,_e.to);
42
+ }};
43
+ AJS.fx.Base=new AJS.Class({init:function(_10){
44
+ this.options={onStart:function(){
45
+ },onComplete:function(){
46
+ },transition:AJS.fx.Transitions.sineInOut,duration:500,wait:true,fps:50};
47
+ AJS.update(this.options,_10);
48
+ AJS.bindMethods(this);
49
+ },setOptions:function(_11){
50
+ AJS.update(this.options,_11);
51
+ },step:function(){
52
+ var _12=new Date().getTime();
53
+ if(_12<this.time+this.options.duration){
54
+ this.cTime=_12-this.time;
55
+ this.setNow();
56
+ }else{
57
+ setTimeout(AJS.$b(this.options.onComplete,this,[this.elm]),10);
58
+ this.clearTimer();
59
+ this.now=this.to;
60
+ }
61
+ this.increase();
62
+ },setNow:function(){
63
+ this.now=this.compute(this.from,this.to);
64
+ },compute:function(_13,to){
65
+ var _15=to-_13;
66
+ return this.options.transition(this.cTime,_13,_15,this.options.duration);
67
+ },clearTimer:function(){
68
+ clearInterval(this.timer);
69
+ this.timer=null;
70
+ return this;
71
+ },_start:function(_16,to){
72
+ if(!this.options.wait){
73
+ this.clearTimer();
74
+ }
75
+ if(this.timer){
76
+ return;
77
+ }
78
+ setTimeout(AJS.$p(this.options.onStart,this.elm),10);
79
+ this.from=_16;
80
+ this.to=to;
81
+ this.time=new Date().getTime();
82
+ this.timer=setInterval(this.step,Math.round(1000/this.options.fps));
83
+ return this;
84
+ },custom:function(_18,to){
85
+ return this._start(_18,to);
86
+ },set:function(to){
87
+ this.now=to;
88
+ this.increase();
89
+ return this;
90
+ },setStyle:function(elm,_1c,val){
91
+ if(this.property=="opacity"){
92
+ AJS.setOpacity(elm,val);
93
+ }else{
94
+ AJS.setStyle(elm,_1c,val);
95
+ }
96
+ }});
97
+ AJS.fx.Style=AJS.fx.Base.extend({init:function(elm,_1f,_20){
98
+ this.parent();
99
+ this.elm=elm;
100
+ this.setOptions(_20);
101
+ this.property=_1f;
102
+ },increase:function(){
103
+ this.setStyle(this.elm,this.property,this.now);
104
+ }});
105
+ AJS.fx.Styles=AJS.fx.Base.extend({init:function(elm,_22){
106
+ this.parent();
107
+ this.elm=AJS.$(elm);
108
+ this.setOptions(_22);
109
+ this.now={};
110
+ },setNow:function(){
111
+ for(p in this.from){
112
+ this.now[p]=this.compute(this.from[p],this.to[p]);
113
+ }
114
+ },custom:function(obj){
115
+ if(this.timer&&this.options.wait){
116
+ return;
117
+ }
118
+ var _24={};
119
+ var to={};
120
+ for(p in obj){
121
+ _24[p]=obj[p][0];
122
+ to[p]=obj[p][1];
123
+ }
124
+ return this._start(_24,to);
125
+ },increase:function(){
126
+ for(var p in this.now){
127
+ this.setStyle(this.elm,p,this.now[p]);
128
+ }
129
+ }});
130
+ AJS.fx.Transitions={linear:function(t,b,c,d){
131
+ return c*t/d+b;
132
+ },sineInOut:function(t,b,c,d){
133
+ return -c/2*(Math.cos(Math.PI*t/d)-1)+b;
134
+ }};
135
+ script_loaded=true;
136
+
137
+
138
+ script_loaded=true;
skin/frontend/base/default/greybox/content-bottom-bg.gif ADDED
Binary file
skin/frontend/base/default/greybox/custom-integration-onestepcheckout.js ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var kiala = new function() {
2
+ this.notEnoughInfoErrorMsg = 'Gelieve uw stad en postcode rechts in te vullen, zodat we een Kialapunt in uw buurt kunnen zoeken.';
3
+
4
+ this.hasEnoughInfo = function() {
5
+ var city = $("billing:city").value;
6
+ var postcode = $('billing:postcode').value;
7
+
8
+ return Boolean(postcode && city);
9
+ }
10
+
11
+ //controls when to enable/disable the kiala radio button, and show an errormsg
12
+ this.controlOptionInput = function() {
13
+ if(!kiala.hasEnoughInfo()) {
14
+ $('s_method_kiala_kiala').disable();
15
+ $('chose_kiala_address').disabled = true;
16
+ if(!$('kialawarning')) {//error not yet printed
17
+ $('s_method_kiala_kiala').up('dt').insert('<p id="kialawarning">'+ kiala.notEnoughInfoErrorMsg +'</p>');
18
+ }
19
+ }
20
+ else {
21
+ $('s_method_kiala_kiala').enable();
22
+ $('chose_kiala_address').disabled = false;
23
+ if($('kialawarning')) {
24
+ $('kialawarning').remove();
25
+ }
26
+ }
27
+ }
28
+
29
+ this.controlMapButton = function() {
30
+ if($('s_method_kiala_kiala').checked) {
31
+ return $('chose_kiala_address').disabled = false;
32
+ } else {
33
+ return $('chose_kiala_address').disabled = true;
34
+ }
35
+ }
36
+
37
+ //save location by overwriting normal shipping fields
38
+ this.save = function() {
39
+ if($('billing:kiala_trace').value == 1) {
40
+ $('billing:street1').value = $('billing:kiala_kpname').value + ", " + $('billing:kiala_street').value;
41
+ $('billing:street2').value = 'Kiala kpid: '+ $('billing:kiala_kpid').value;
42
+ $('billing:city').value = $('billing:kiala_city').value;
43
+ $('billing:postcode').value = $('billing:kiala_zip').value;
44
+ return true;
45
+ }
46
+ return false;
47
+ }
48
+
49
+ this.showChosenAddress = function() {
50
+ if($('billing:kiala_trace').value == 1 && !$('kiala_address')) {
51
+ var country = document.getElementById("billing:country_id").value;
52
+ var city = $('billing:kiala_city').value;
53
+ var postcode = $('billing:kiala_zip').value;
54
+ var street = $('billing:kiala_kpname').value + "<br>" + $('billing:kiala_street').value;
55
+
56
+ var adres = street + "<br>" + postcode + " " + city;
57
+
58
+ $('s_method_kiala_kiala').up('dt').insert('<p id="kiala_address">'+ adres +'</p>');
59
+
60
+ return true;
61
+ }
62
+ return false;
63
+ }
64
+
65
+ this.showSelector = function() {
66
+ if(!kiala.hasEnoughInfo()) {
67
+ return;
68
+ }
69
+
70
+ var KialaAccountNumber='32699996';
71
+ var KialaAccountNumberNetherlands='';
72
+ var KialaAccountNumberBelgium='32699996';
73
+ var KialaAccountNumberLuxembourg='';
74
+ var KialaAccountNumberFrance='';
75
+ var KialaAccountNumberSpain='';
76
+ document.getElementById("billing:kiala_reset").value=1;
77
+
78
+ var countryCode=document.getElementById("billing:country_id").value;
79
+ var kialaACNumber="";
80
+ if(countryCode=='BE'){
81
+ kialaACNumber=KialaAccountNumberBelgium;
82
+ }else if(countryCode=='FR'){
83
+ kialaACNumber=KialaAccountNumberFrance;
84
+ }else if(countryCode=='LU'){
85
+ kialaACNumber=KialaAccountNumberLuxembourg;
86
+ }else if(countryCode=='NL'){
87
+ kialaACNumber=KialaAccountNumberNetherlands;
88
+ }else if(countryCode=='ES'){
89
+ kialaACNumber=KialaAccountNumberSpain;
90
+ }else{
91
+ kialaACNumber=KialaAccountNumber;
92
+ }
93
+
94
+ var country = escape(document.getElementById("billing:country_id").value);
95
+ var city = escape(document.getElementById("billing:city").value);
96
+ var postcode = escape(document.getElementById('billing:postcode').value);
97
+ var street = escape(document.getElementById('billing:street1').value + ' '+ document.getElementById('billing:street2').value);
98
+
99
+ var bckUrl = escape(GB_ROOT_DIR + 'kiala.php?');
100
+
101
+ var url = "https://locateandselect.kiala.com/search?countryid="+ country +"&bckUrl="+ bckUrl +"&dspid="+kialaACNumber+"&language=NL&city="+ city + "&zip="+postcode+"&street="+street;
102
+
103
+ GB_show('Kiala', url, 600, 1000);
104
+ }
105
+
106
+ return this;
107
+ }
108
+
109
+ Event.observe(window, 'load', function() {
110
+ if(!$('s_method_kiala_kiala')) return;//als de kiala plugin niet bestaat, voer dan niet uit.
111
+
112
+ //create the button that shows the kiala map
113
+ $('s_method_kiala_kiala').next('label').insert('<button id="chose_kiala_address" type="button">Kies uw Kiala aflever adres</button>');
114
+ $('chose_kiala_address').observe('click', kiala.showSelector);
115
+
116
+ //dis-enable the kiala map button
117
+ setTimeout(function(){
118
+ kiala.controlMapButton();
119
+ }, 1000);
120
+
121
+ $$('dl.shipment-methods').each(function(element){
122
+ element.observe('change', kiala.controlMapButton);
123
+ });
124
+
125
+ //dis-enable the control radio option
126
+ kiala.controlOptionInput();
127
+ $('billing:city').observe('change', kiala.controlOptionInput);
128
+ $('billing:postcode').observe('change', kiala.controlOptionInput);
129
+
130
+ setInterval(function() {
131
+ kiala.showChosenAddress();
132
+ }, 1000);
133
+ });
skin/frontend/base/default/greybox/g_close.gif ADDED
Binary file
skin/frontend/base/default/greybox/gb_scripts.js ADDED
@@ -0,0 +1,443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var GB_CURRENT=null;
2
+ GB_hide=function(cb){
3
+ GB_CURRENT.hide(cb);
4
+ };
5
+ GreyBox=new AJS.Class({init:function(_2){
6
+ this.use_fx=AJS.fx;
7
+ this.type="page";
8
+ this.overlay_click_close=false;
9
+ this.salt=0;
10
+ this.root_dir=GB_ROOT_DIR;
11
+ this.callback_fns=[];
12
+ this.reload_on_close=false;
13
+ this.src_loader=this.root_dir+"loader_frame.html";
14
+ var _3=window.location.hostname.indexOf("www");
15
+ var _4=this.src_loader.indexOf("www");
16
+ if(_3!=-1&&_4==-1){
17
+ this.src_loader=this.src_loader.replace("://","://www.");
18
+ }
19
+ if(_3==-1&&_4!=-1){
20
+ this.src_loader=this.src_loader.replace("://www.","://");
21
+ }
22
+ this.show_loading=true;
23
+ AJS.update(this,_2);
24
+ },addCallback:function(fn){
25
+ if(fn){
26
+ this.callback_fns.push(fn);
27
+ }
28
+ },show:function(_6){
29
+ GB_CURRENT=this;
30
+ this.url=_6;
31
+ var _7=[AJS.$bytc("object"),AJS.$bytc("select")];
32
+ AJS.map(AJS.flattenList(_7),function(_8){
33
+ _8.style.visibility="hidden";
34
+ });
35
+ this.createElements();
36
+ return false;
37
+ },hide:function(cb){
38
+ var me=this;
39
+ AJS.callLater(function(){
40
+ var _b=me.callback_fns;
41
+ if(_b!=[]){
42
+ AJS.map(_b,function(fn){
43
+ fn();
44
+ });
45
+ }
46
+ me.onHide();
47
+ if(me.use_fx){
48
+ var _d=me.overlay;
49
+ AJS.fx.fadeOut(me.overlay,{onComplete:function(){
50
+ AJS.removeElement(_d);
51
+ _d=null;
52
+ },duration:300});
53
+ AJS.removeElement(me.g_window);
54
+ }else{
55
+ AJS.removeElement(me.g_window,me.overlay);
56
+ }
57
+ me.removeFrame();
58
+ AJS.REV(window,"scroll",_GB_setOverlayDimension);
59
+ AJS.REV(window,"resize",_GB_update);
60
+ var _e=[AJS.$bytc("object"),AJS.$bytc("select")];
61
+ AJS.map(AJS.flattenList(_e),function(_f){
62
+ _f.style.visibility="visible";
63
+ });
64
+ GB_CURRENT=null;
65
+ if(me.reload_on_close){
66
+ window.location.reload();
67
+ }
68
+ if(AJS.isFunction(cb)){
69
+ cb();
70
+ }
71
+ },10);
72
+ },update:function(){
73
+ this.setOverlayDimension();
74
+ this.setFrameSize();
75
+ this.setWindowPosition();
76
+ },createElements:function(){
77
+ this.initOverlay();
78
+ this.g_window=AJS.DIV({"id":"GB_window"});
79
+ AJS.hideElement(this.g_window);
80
+ AJS.getBody().insertBefore(this.g_window,this.overlay.nextSibling);
81
+ this.initFrame();
82
+ this.initHook();
83
+ this.update();
84
+ var me=this;
85
+ if(this.use_fx){
86
+ AJS.fx.fadeIn(this.overlay,{duration:300,to:0.7,onComplete:function(){
87
+ me.onShow();
88
+ AJS.showElement(me.g_window);
89
+ me.startLoading();
90
+ }});
91
+ }else{
92
+ AJS.setOpacity(this.overlay,0.7);
93
+ AJS.showElement(this.g_window);
94
+ this.onShow();
95
+ this.startLoading();
96
+ }
97
+ AJS.AEV(window,"scroll",_GB_setOverlayDimension);
98
+ AJS.AEV(window,"resize",_GB_update);
99
+ },removeFrame:function(){
100
+ try{
101
+ AJS.removeElement(this.iframe);
102
+ }
103
+ catch(e){
104
+ }
105
+ this.iframe=null;
106
+ },startLoading:function(){
107
+ this.iframe.src=this.src_loader+"?s="+this.salt++;
108
+ AJS.showElement(this.iframe);
109
+ },setOverlayDimension:function(){
110
+ var _11=AJS.getWindowSize();
111
+ if(AJS.isMozilla()||AJS.isOpera()){
112
+ AJS.setWidth(this.overlay,"100%");
113
+ }else{
114
+ AJS.setWidth(this.overlay,_11.w);
115
+ }
116
+ var _12=Math.max(AJS.getScrollTop()+_11.h,AJS.getScrollTop()+this.height);
117
+ if(_12<AJS.getScrollTop()){
118
+ AJS.setHeight(this.overlay,_12);
119
+ }else{
120
+ AJS.setHeight(this.overlay,AJS.getScrollTop()+_11.h);
121
+ }
122
+ },initOverlay:function(){
123
+ this.overlay=AJS.DIV({"id":"GB_overlay"});
124
+ if(this.overlay_click_close){
125
+ AJS.AEV(this.overlay,"click",GB_hide);
126
+ }
127
+ AJS.setOpacity(this.overlay,0);
128
+ AJS.getBody().insertBefore(this.overlay,AJS.getBody().firstChild);
129
+ },initFrame:function(){
130
+ if(!this.iframe){
131
+ var d={"name":"GB_frame","class":"GB_frame","frameBorder":0};
132
+ if(AJS.isIe()){
133
+ d.src="javascript:false;document.write(\"\");";
134
+ }
135
+ this.iframe=AJS.IFRAME(d);
136
+ this.middle_cnt=AJS.DIV({"class":"content"},this.iframe);
137
+ this.top_cnt=AJS.DIV();
138
+ this.bottom_cnt=AJS.DIV();
139
+ AJS.ACN(this.g_window,this.top_cnt,this.middle_cnt,this.bottom_cnt);
140
+ }
141
+ },onHide:function(){
142
+ },onShow:function(){
143
+ },setFrameSize:function(){
144
+ },setWindowPosition:function(){
145
+ },initHook:function(){
146
+ }});
147
+ _GB_update=function(){
148
+ if(GB_CURRENT){
149
+ GB_CURRENT.update();
150
+ }
151
+ };
152
+ _GB_setOverlayDimension=function(){
153
+ if(GB_CURRENT){
154
+ GB_CURRENT.setOverlayDimension();
155
+ }
156
+ };
157
+ AJS.preloadImages(GB_ROOT_DIR+"indicator.gif");
158
+ script_loaded=true;
159
+ var GB_SETS={};
160
+ function decoGreyboxLinks(){
161
+ var as=AJS.$bytc("a");
162
+ AJS.map(as,function(a){
163
+ if(a.getAttribute("href")&&a.getAttribute("rel")){
164
+ var rel=a.getAttribute("rel");
165
+ if(rel.indexOf("gb_")==0){
166
+ var _17=rel.match(/\w+/)[0];
167
+ var _18=rel.match(/\[(.*)\]/)[1];
168
+ var _19=0;
169
+ if(_17=="gb_pageset"||_17=="gb_imageset"){
170
+ if(!GB_SETS[_18]){
171
+ GB_SETS[_18]=[];
172
+ }
173
+ GB_SETS[_18].push(_1a);
174
+ _19=GB_SETS[_18].length;
175
+ }
176
+ if(_17=="gb_pageset"){
177
+ a.onclick=function(){
178
+ GB_showFullScreenSet(GB_SETS[_18],_19);
179
+ return false;
180
+ };
181
+ }
182
+ if(_17=="gb_imageset"){
183
+ a.onclick=function(){
184
+ GB_showImageSet(GB_SETS[_18],_19);
185
+ return false;
186
+ };
187
+ }
188
+ if(_17=="gb_image"){
189
+ a.onclick=function(){
190
+ GB_showImage(_1a.caption,_1a.url);
191
+ return false;
192
+ };
193
+ }
194
+ if(_17=="gb_page"){
195
+ a.onclick=function(){
196
+ var sp=_18.split(/, ?/);
197
+ GB_show(_1a.caption,_1a.url,parseInt(sp[1]),parseInt(sp[0]));
198
+ return false;
199
+ };
200
+ }
201
+ if(_17=="gb_page_fs"){
202
+ a.onclick=function(){
203
+ GB_showFullScreen(_1a.caption,_1a.url);
204
+ return false;
205
+ };
206
+ }
207
+ if(_17=="gb_page_center"){
208
+ a.onclick=function(){
209
+ var sp=_18.split(/, ?/);
210
+ GB_showCenter(_1a.caption,_1a.url,parseInt(sp[1]),parseInt(sp[0]));
211
+ return false;
212
+ };
213
+ }
214
+ }
215
+ }
216
+ });
217
+ }
218
+ AJS.AEV(window,"load",decoGreyboxLinks);
219
+ GB_showImage=function(_1d,url,_1f){
220
+ var _20={width:300,height:300,type:"image",fullscreen:false,center_win:true,caption:_1d,callback_fn:_1f};
221
+ var win=new GB_Gallery(_20);
222
+ return win.show(url);
223
+ };
224
+ GB_showPage=function(_22,url,_24){
225
+ var _25={type:"page",caption:_22,callback_fn:_24,fullscreen:true,center_win:false};
226
+ var win=new GB_Gallery(_25);
227
+ return win.show(url);
228
+ };
229
+ GB_Gallery=GreyBox.extend({init:function(_27){
230
+ this.parent({});
231
+ this.img_close=this.root_dir+"g_close.gif";
232
+ AJS.update(this,_27);
233
+ this.addCallback(this.callback_fn);
234
+ },initHook:function(){
235
+ AJS.addClass(this.g_window,"GB_Gallery");
236
+ var _28=AJS.DIV({"class":"inner"});
237
+ AJS.setOpacity(this.header,0);
238
+ AJS.getBody().insertBefore(this.header,this.overlay.nextSibling);
239
+ var _29=AJS.TD({"id":"GB_caption","class":"caption","width":"40%"},this.caption);
240
+ var _2a=AJS.TD({"id":"GB_middle","class":"middle","width":"20%"});
241
+ var _2b=AJS.IMG({"src":this.img_close});
242
+ AJS.AEV(_2b,"click",GB_hide);
243
+ var _2c=AJS.TD({"class":"close","width":"40%"},_2b);
244
+ var _2d=AJS.TBODY(AJS.TR(_29,_2a,_2c));
245
+ var _2e=AJS.TABLE({"cellspacing":"0","cellpadding":0,"border":0},_2d);
246
+ AJS.ACN(_28,_2e);
247
+ if(this.fullscreen){
248
+ AJS.AEV(window,"scroll",AJS.$b(this.setWindowPosition,this));
249
+ }else{
250
+ AJS.AEV(window,"scroll",AJS.$b(this._setHeaderPos,this));
251
+ }
252
+ },setFrameSize:function(){
253
+ var _2f=this.overlay.offsetWidth;
254
+ var _30=AJS.getWindowSize();
255
+ if(this.fullscreen){
256
+ this.width=_2f-40;
257
+ this.height=_30.h-80;
258
+ }
259
+ AJS.setWidth(this.iframe,this.width);
260
+ AJS.setHeight(this.iframe,this.height);
261
+ AJS.setWidth(this.header,_2f);
262
+ },_setHeaderPos:function(){
263
+ AJS.setTop(this.header,AJS.getScrollTop()+10);
264
+ },setWindowPosition:function(){
265
+ var _31=this.overlay.offsetWidth;
266
+ var _32=AJS.getWindowSize();
267
+ AJS.setLeft(this.g_window,((_31-50-this.width)/2));
268
+ var _33=AJS.getScrollTop()+55;
269
+ if(!this.center_win){
270
+ AJS.setTop(this.g_window,_33);
271
+ }else{
272
+ var fl=((_32.h-this.height)/2)+20+AJS.getScrollTop();
273
+ if(fl<0){
274
+ fl=0;
275
+ }
276
+ if(_33>fl){
277
+ fl=_33;
278
+ }
279
+ AJS.setTop(this.g_window,fl);
280
+ }
281
+ this._setHeaderPos();
282
+ },onHide:function(){
283
+ AJS.removeElement(this.header);
284
+ AJS.removeClass(this.g_window,"GB_Gallery");
285
+ },onShow:function(){
286
+ if(this.use_fx){
287
+ AJS.fx.fadeIn(this.header,{to:1});
288
+ }else{
289
+ AJS.setOpacity(this.header,1);
290
+ }
291
+ }});
292
+ AJS.preloadImages(GB_ROOT_DIR+"g_close.gif");
293
+ GB_showFullScreenSet=function(set,_36,_37){
294
+ var _38={type:"page",fullscreen:true,center_win:false};
295
+ var _39=new GB_Sets(_38,set);
296
+ _39.addCallback(_37);
297
+ _39.showSet(_36-1);
298
+ return false;
299
+ };
300
+ GB_showImageSet=function(set,_3b,_3c){
301
+ var _3d={type:"image",fullscreen:false,center_win:true,width:300,height:300};
302
+ var _3e=new GB_Sets(_3d,set);
303
+ _3e.addCallback(_3c);
304
+ _3e.showSet(_3b-1);
305
+ return false;
306
+ };
307
+ GB_Sets=GB_Gallery.extend({init:function(_3f,set){
308
+ this.parent(_3f);
309
+ if(!this.img_next){
310
+ this.img_next=this.root_dir+"next.gif";
311
+ }
312
+ if(!this.img_prev){
313
+ this.img_prev=this.root_dir+"prev.gif";
314
+ }
315
+ this.current_set=set;
316
+ },showSet:function(_41){
317
+ this.current_index=_41;
318
+ var _42=this.current_set[this.current_index];
319
+ this.show(_42.url);
320
+ this._setCaption(_42.caption);
321
+ this.btn_prev=AJS.IMG({"class":"left",src:this.img_prev});
322
+ this.btn_next=AJS.IMG({"class":"right",src:this.img_next});
323
+ AJS.AEV(this.btn_prev,"click",AJS.$b(this.switchPrev,this));
324
+ AJS.AEV(this.btn_next,"click",AJS.$b(this.switchNext,this));
325
+ GB_STATUS=AJS.SPAN({"class":"GB_navStatus"});
326
+ AJS.ACN(AJS.$("GB_middle"),this.btn_prev,GB_STATUS,this.btn_next);
327
+ this.updateStatus();
328
+ },updateStatus:function(){
329
+ AJS.setHTML(GB_STATUS,(this.current_index+1)+" / "+this.current_set.length);
330
+ if(this.current_index==0){
331
+ AJS.addClass(this.btn_prev,"disabled");
332
+ }else{
333
+ AJS.removeClass(this.btn_prev,"disabled");
334
+ }
335
+ if(this.current_index==this.current_set.length-1){
336
+ AJS.addClass(this.btn_next,"disabled");
337
+ }else{
338
+ AJS.removeClass(this.btn_next,"disabled");
339
+ }
340
+ },_setCaption:function(_43){
341
+ AJS.setHTML(AJS.$("GB_caption"),_43);
342
+ },updateFrame:function(){
343
+ var _44=this.current_set[this.current_index];
344
+ this._setCaption(_44.caption);
345
+ this.url=_44.url;
346
+ this.startLoading();
347
+ },switchPrev:function(){
348
+ if(this.current_index!=0){
349
+ this.current_index--;
350
+ this.updateFrame();
351
+ this.updateStatus();
352
+ }
353
+ },switchNext:function(){
354
+ if(this.current_index!=this.current_set.length-1){
355
+ this.current_index++;
356
+ this.updateFrame();
357
+ this.updateStatus();
358
+ }
359
+ }});
360
+ AJS.AEV(window,"load",function(){
361
+ AJS.preloadImages(GB_ROOT_DIR+"next.gif",GB_ROOT_DIR+"prev.gif");
362
+ });
363
+ GB_show=function(_45,url,_47,_48,_49){
364
+ var _4a={caption:_45,height:_47||500,width:_48||500,fullscreen:false,callback_fn:_49};
365
+ var win=new GB_Window(_4a);
366
+ return win.show(url);
367
+ };
368
+ GB_showCenter=function(_4c,url,_4e,_4f,_50){
369
+ var _51={caption:_4c,center_win:true,height:_4e||500,width:_4f||500,fullscreen:false,callback_fn:_50};
370
+ var win=new GB_Window(_51);
371
+ return win.show(url);
372
+ };
373
+ GB_showFullScreen=function(_53,url,_55){
374
+ var _56={caption:_53,fullscreen:true,callback_fn:_55};
375
+ var win=new GB_Window(_56);
376
+ return win.show(url);
377
+ };
378
+ GB_Window=GreyBox.extend({init:function(_58){
379
+ this.parent({});
380
+ this.img_close=this.root_dir+"w_close.gif";
381
+ this.show_close_img=true;
382
+ AJS.update(this,_58);
383
+ this.addCallback(this.callback_fn);
384
+ },initHook:function(){
385
+ AJS.addClass(this.g_window,"GB_Window");
386
+ this.header=AJS.TABLE({"class":"header"});
387
+ this.header.style.backgroundImage="url("+this.img_header+")";
388
+ var _59=AJS.TD({"class":"caption"},this.caption);
389
+ var _5a=AJS.TD({"class":"close"});
390
+ if(this.show_close_img){
391
+ var _5b=AJS.IMG({"src":this.img_close,"class":"close","style":"position:absolute;margin:-10px -10px 0 0;right:0;"});
392
+ var _5c=AJS.SPAN("Close");
393
+ var btn=AJS.DIV(_5b,_5c);
394
+ AJS.AEV([_5b,_5c],"mouseover",function(){
395
+ AJS.addClass(_5c,"on");
396
+ });
397
+ AJS.AEV([_5b,_5c],"mouseout",function(){
398
+ AJS.removeClass(_5c,"on");
399
+ });
400
+ AJS.AEV([_5b,_5c],"mousedown",function(){
401
+ AJS.addClass(_5c,"click");
402
+ });
403
+ AJS.AEV([_5b,_5c],"mouseup",function(){
404
+ AJS.removeClass(_5c,"click");
405
+ });
406
+ AJS.AEV([_5b,_5c],"click",GB_hide);
407
+ AJS.ACN(_5a,btn);
408
+ }
409
+ tbody_header=AJS.TBODY();
410
+ AJS.ACN(tbody_header,AJS.TR(_59,_5a));
411
+ AJS.ACN(this.header,tbody_header);
412
+ //AJS.ACN(this.top_cnt,this.header);
413
+ AJS.ACN(this.top_cnt,_5b);
414
+ if(this.fullscreen){
415
+ AJS.AEV(window,"scroll",AJS.$b(this.setWindowPosition,this));
416
+ }
417
+ },setFrameSize:function(){
418
+ if(this.fullscreen){
419
+ var _5e=AJS.getWindowSize();
420
+ overlay_h=_5e.h;
421
+ this.width=Math.round(this.overlay.offsetWidth-(this.overlay.offsetWidth/100)*10);
422
+ this.height=Math.round(overlay_h-(overlay_h/100)*10);
423
+ }
424
+ AJS.setWidth(this.header,this.width+6);
425
+ AJS.setWidth(this.iframe,this.width);
426
+ AJS.setHeight(this.iframe,this.height);
427
+ },setWindowPosition:function(){
428
+ var _5f=AJS.getWindowSize();
429
+ AJS.setLeft(this.g_window,((_5f.w-this.width)/2)-13);
430
+ if(!this.center_win){
431
+ AJS.setTop(this.g_window,AJS.getScrollTop());
432
+ }else{
433
+ var fl=((_5f.h-this.height)/2)-20+AJS.getScrollTop();
434
+ if(fl<0){
435
+ fl=0;
436
+ }
437
+ AJS.setTop(this.g_window,fl);
438
+ }
439
+ }});
440
+ AJS.preloadImages(GB_ROOT_DIR+"w_close.gif");
441
+
442
+
443
+ script_loaded=true;
skin/frontend/base/default/greybox/gb_styles.css ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Last-Modified: 28/06/06 00:08:22 */
2
+ #GB_overlay {
3
+ background-color: #000;
4
+ position: absolute;
5
+ margin: auto;
6
+ top: 0;
7
+ left: 0;
8
+ z-index: 100;
9
+ }
10
+
11
+ #GB_window {
12
+ left: 0;
13
+ top: 0;
14
+ font-size: 1px;
15
+ position: absolute;
16
+ overflow: visible;
17
+ z-index: 150;
18
+ }
19
+
20
+ #GB_window .content {
21
+ width: auto;
22
+ margin: 0;
23
+ padding: 0;
24
+ }
25
+
26
+ #GB_frame {
27
+ border: 0;
28
+ margin: 0;
29
+ padding: 0;
30
+ overflow: auto;
31
+ white-space: nowrap;
32
+ }
33
+
34
+
35
+ .GB_Gallery {
36
+ margin: 0 22px 0 22px;
37
+ }
38
+
39
+ .GB_Gallery .content {
40
+ background-color: #fff;
41
+ border: 3px solid #ddd;
42
+ }
43
+
44
+ .GB_header {
45
+ top: 10px;
46
+ left: 0;
47
+ margin: 0;
48
+ z-index: 500;
49
+ position: absolute;
50
+ border-bottom: 5px solid #FFF;
51
+ border-top: 5px solid #FFF;
52
+ }
53
+
54
+ .GB_header .inner {
55
+ background-color: #333;
56
+ font-family: Arial, Verdana, sans-serif;
57
+ padding: 2px 20px 2px 20px;
58
+ }
59
+
60
+ .GB_header table {
61
+ margin: 0;
62
+ width: 100%;
63
+ border-collapse: collapse;
64
+ }
65
+
66
+ .GB_header .caption {
67
+ text-align: left;
68
+ color: #eee;
69
+ white-space: nowrap;
70
+ font-size: 20px;
71
+ }
72
+
73
+ .GB_header .close {
74
+ text-align: right;
75
+ cursor:pointer;
76
+ }
77
+
78
+ .GB_header .close img {
79
+ z-index: 500;
80
+ cursor: pointer;
81
+ }
82
+
83
+ .GB_header .middle {
84
+ white-space: nowrap;
85
+ text-align: center;
86
+ }
87
+
88
+
89
+ #GB_middle {
90
+ color: #eee;
91
+ }
92
+
93
+ #GB_middle img {
94
+ cursor: pointer;
95
+ vertical-align: middle;
96
+ }
97
+
98
+ #GB_middle .disabled {
99
+ cursor: default;
100
+ }
101
+
102
+ #GB_middle .left {
103
+ padding-right: 10px;
104
+ }
105
+
106
+ #GB_middle .right {
107
+ padding-left: 10px;
108
+ }
109
+
110
+
111
+ .GB_Window .content {
112
+ background-color: #fff;
113
+ /* border: 3px solid #ccc;
114
+ border-top: none;*/
115
+ }
116
+
117
+ .GB_Window .header {
118
+ border-bottom: 1px solid #aaa;
119
+ border-top: 5px solid #FFF;
120
+ border-left: 5px solid #FFF;
121
+ border-right: 3px solid #FFF;
122
+ margin: 0;
123
+ height: 22px;
124
+ font-size: 12px;
125
+ padding: 3px 0;
126
+ color: #333;
127
+ }
128
+
129
+ .GB_Window .caption {
130
+ font-size: 12px;
131
+ text-align: left;
132
+ font-weight: bold;
133
+ white-space: nowrap;
134
+ padding-right: 20px;
135
+ }
136
+
137
+ .GB_Window .close { text-align: right; }
138
+ .GB_Window .close span {
139
+ font-size: 12px;
140
+ cursor: pointer;
141
+ }
142
+ .GB_Window .close img {
143
+ cursor: pointer;
144
+ padding: 0 3px 0 0;
145
+ }
146
+
147
+ .GB_Window .on { border-bottom: 1px solid #DA5C00; }
148
+ .GB_Window .click { border-bottom: 1px solid red; }
149
+
150
+
151
+ .GB_Window {padding-top:20px;}
152
+
153
+
skin/frontend/base/default/greybox/gb_styles_orig.css ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Last-Modified: 28/06/06 00:08:22 */
2
+ #GB_overlay {
3
+ background-color: #000;
4
+ position: absolute;
5
+ margin: auto;
6
+ top: 0;
7
+ left: 0;
8
+ z-index: 100;
9
+ }
10
+
11
+ #GB_window {
12
+ left: 0;
13
+ top: 0;
14
+ font-size: 1px;
15
+ position: absolute;
16
+ overflow: visible;
17
+ z-index: 150;
18
+ }
19
+
20
+ #GB_window .content {
21
+ width: auto;
22
+ margin: 0;
23
+ padding: 0;
24
+ }
25
+
26
+ #GB_frame {
27
+ border: 0;
28
+ margin: 0;
29
+ padding: 0;
30
+ overflow: auto;
31
+ white-space: nowrap;
32
+ }
33
+
34
+
35
+ .GB_Gallery {
36
+ margin: 0 22px 0 22px;
37
+ }
38
+
39
+ .GB_Gallery .content {
40
+ background-color: #fff;
41
+ border: 3px solid #ddd;
42
+ }
43
+
44
+ .GB_header {
45
+ top: 10px;
46
+ left: 0;
47
+ margin: 0;
48
+ z-index: 500;
49
+ position: absolute;
50
+ border-bottom: 2px solid #555;
51
+ border-top: 2px solid #555;
52
+ }
53
+
54
+ .GB_header .inner {
55
+ background-color: #333;
56
+ font-family: Arial, Verdana, sans-serif;
57
+ padding: 2px 20px 2px 20px;
58
+ }
59
+
60
+ .GB_header table {
61
+ margin: 0;
62
+ width: 100%;
63
+ border-collapse: collapse;
64
+ }
65
+
66
+ .GB_header .caption {
67
+ text-align: left;
68
+ color: #eee;
69
+ white-space: nowrap;
70
+ font-size: 20px;
71
+ }
72
+
73
+ .GB_header .close {
74
+ text-align: right;
75
+ }
76
+
77
+ .GB_header .close img {
78
+ z-index: 500;
79
+ cursor: pointer;
80
+ }
81
+
82
+ .GB_header .middle {
83
+ white-space: nowrap;
84
+ text-align: center;
85
+ }
86
+
87
+
88
+ #GB_middle {
89
+ color: #eee;
90
+ }
91
+
92
+ #GB_middle img {
93
+ cursor: pointer;
94
+ vertical-align: middle;
95
+ }
96
+
97
+ #GB_middle .disabled {
98
+ cursor: default;
99
+ }
100
+
101
+ #GB_middle .left {
102
+ padding-right: 10px;
103
+ }
104
+
105
+ #GB_middle .right {
106
+ padding-left: 10px;
107
+ }
108
+
109
+
110
+ .GB_Window .content {
111
+ background-color: #fff;
112
+ border: 3px solid #ccc;
113
+ border-top: none;
114
+ }
115
+
116
+ .GB_Window .header {
117
+ border-bottom: 1px solid #aaa;
118
+ border-top: 1px solid #999;
119
+ border-left: 3px solid #ccc;
120
+ border-right: 3px solid #ccc;
121
+ margin: 0;
122
+
123
+ height: 22px;
124
+ font-size: 12px;
125
+ padding: 3px 0;
126
+ color: #333;
127
+ }
128
+
129
+ .GB_Window .caption {
130
+ font-size: 12px;
131
+ text-align: left;
132
+ font-weight: bold;
133
+ white-space: nowrap;
134
+ padding-right: 20px;
135
+ }
136
+
137
+ .GB_Window .close { text-align: right; }
138
+ .GB_Window .close span {
139
+ font-size: 12px;
140
+ cursor: pointer;
141
+ }
142
+ .GB_Window .close img {
143
+ cursor: pointer;
144
+ padding: 0 3px 0 0;
145
+ }
146
+
147
+ .GB_Window .on { border-bottom: 1px solid #333; }
148
+ .GB_Window .click { border-bottom: 1px solid red; }
skin/frontend/base/default/greybox/header_bg.gif ADDED
Binary file
skin/frontend/base/default/greybox/indicator.gif ADDED
Binary file
skin/frontend/base/default/greybox/loader_frame.html ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ Notice: I feel so dirty doing this, but its the only way to make it cross browser.
3
+ -->
4
+ <html>
5
+ <head>
6
+ <script>
7
+ var GB = parent.GB_CURRENT;
8
+ document.write('<script type="text/javascript" src="AJS.js"><\/script>');
9
+ if(GB.use_fx) {
10
+ document.write('<script type="text/javascript" src="AJS_fx.js"><\/script>');
11
+ }
12
+ </script>
13
+ <style>
14
+ body {
15
+ padding: 0;
16
+ margin: 0;
17
+ overflow: hidden;
18
+ }
19
+
20
+ #GB_frame {
21
+ visibility: hidden;
22
+ width: 100%;
23
+ height: 100%;
24
+ }
25
+
26
+ #loading {
27
+ padding-top: 150px;
28
+ position: absolute;
29
+ width: 100%;
30
+ top: 0;
31
+ text-align: center;
32
+ vertical-align: middle;
33
+ }
34
+ </style>
35
+ </head>
36
+ <body>
37
+
38
+ <div id="loading">
39
+ <img src="indicator.gif">
40
+ </div>
41
+
42
+ <script>
43
+ var loading = AJS.$('loading');
44
+ var gb_type = GB.type;
45
+ var gb_url = GB.url;
46
+
47
+ //Start loading in the iframe
48
+ if(gb_type == "page") {
49
+ document.write('<iframe id="GB_frame" src="' + gb_url + '" frameborder="0"></iframe>');
50
+ }
51
+ else {
52
+ var img_holder = new Image();
53
+ img_holder.src = gb_url;
54
+ document.write('<img id="GB_frame" src="' + gb_url + '">');
55
+ }
56
+ var frame = AJS.$('GB_frame');
57
+ </script>
58
+
59
+ </body>
60
+ <script>
61
+ function setupOuterGB() {
62
+ frame.style.visibility = 'visible';
63
+ GB.setFrameSize();
64
+ GB.setWindowPosition();
65
+ }
66
+
67
+ function loaded() {
68
+ AJS.removeElement(loading);
69
+
70
+ GB.overlay.innerHTML += "&nbsp;"; //Safari bugfix
71
+
72
+ if(gb_type == "image") {
73
+ if(img_holder.width != 0 && img_holder.height != 0) {
74
+ var width = img_holder.width;
75
+ var height = img_holder.height;
76
+
77
+ GB.width = width;
78
+ GB.height = height;
79
+
80
+ setupOuterGB();
81
+
82
+ if(GB.use_fx) {
83
+ AJS.setOpacity(frame, 0);
84
+ AJS.fx.fadeIn(frame);
85
+ }
86
+ }
87
+ }
88
+ else {
89
+ GB.width = frame.offsetWidth;
90
+ GB.height = frame.offsetHeight;
91
+ setupOuterGB();
92
+ }
93
+ }
94
+
95
+ if(GB.show_loading) {
96
+ AJS.AEV(window, 'load', function(e) {
97
+ loaded();
98
+ });
99
+ }
100
+ else {
101
+ loaded();
102
+ }
103
+ </script>
104
+ </html>
skin/frontend/base/default/greybox/next.gif ADDED
Binary file
skin/frontend/base/default/greybox/prev.gif ADDED
Binary file
skin/frontend/base/default/greybox/w_close.gif ADDED
Binary file
skin/frontend/base/default/greybox/w_close1.gif ADDED
Binary file
skin/frontend/base/default/images/bpost/shippingmanager/logo_bpost.jpg ADDED
Binary file
skin/frontend/base/default/images/bpost/shippingmanager/track_and_trace.jpg ADDED
Binary file
skin/frontend/base/default/js/bpost/shippingmanager/bpost_shippingmanager_base.js ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var shippingDetails = Class.create();
2
+
3
+ shippingDetails.prototype = {
4
+ initialize: function(){
5
+ this.firstname = "";
6
+ this.lastname = "";
7
+ this.street = "";
8
+ this.zipcode = "";
9
+ this.city = "";
10
+ this.country_id = "";
11
+ this.company = "";
12
+ this.telephone = "";
13
+ }
14
+ }
15
+
16
+ var bpostShippingManagerBase = Class.create();
17
+
18
+ bpostShippingManagerBase.prototype = {
19
+ initialize: function(){
20
+ this.OSCConfigOk = true;
21
+ this.baseUrl = "";
22
+ this.shippingMethodListId = "";
23
+ this.logoUrl = "";
24
+ this.logoText = "";
25
+ this.logoHeight = 50;
26
+ this.logging = true;
27
+ if (console === undefined) {
28
+ this.logging = false;
29
+ }
30
+ },
31
+
32
+ log : function (message, level){
33
+ if (this.logging) {
34
+ if(level == ""){
35
+ level = "log";
36
+ }
37
+ eval("console." + level + "(message)");
38
+ }
39
+ },
40
+
41
+ show : function(){
42
+ var url = this.baseUrl + 'shippingmanager/postback/startform';
43
+ GB_show('bpost', url, 522, 800);
44
+ },
45
+
46
+ updateStartFormField : function(element, fromFieldId){
47
+ },
48
+
49
+ hideBpostShippingMethods : function(){
50
+ var me = this;
51
+ if($$("div#checkout-shipping-method-load dl." + me.shippingMethodListId).length == 0){
52
+ this.log("No shipping methods found, creating shipping method container.", "debug");
53
+ var dl = new Element('dl',{});
54
+ dl.addClassName("sp-methods");
55
+ try{
56
+ $("checkout-shipping-method-load").appendChild(dl);
57
+ }catch(err){
58
+ this.log("Failed to identify div#checkout-shipping-method-load","error");
59
+ alert("bpost module can not function properly with this layout because there is no div#checkout-shipping-method-load on the page.");
60
+ return;
61
+ }
62
+ }
63
+ $$("div#checkout-shipping-method-load dl." + me.shippingMethodListId)[0].addClassName("bpost_shippingmanager_loaded");
64
+ $("checkout-shipping-method-load").getElementsBySelector('[name="shipping_method"]').each(function(elmt) {
65
+ if(elmt.id.startsWith('s_method_bpost')){
66
+ elmt.addClassName("bpost-shipping-method");
67
+ me.log("hiding " + elmt.id, "debug");
68
+ elmt.up().hide();
69
+ }
70
+ });
71
+ },
72
+
73
+ createShipWithBpostCheckbox : function (){
74
+ var me = this;
75
+ var checkbox = new Element('input',{'id' : 'ship_with_bpost', 'type' : 'checkbox'})
76
+ checkbox.addClassName('radio');
77
+ $$("input.bpost-shipping-method").each(function(elmt) {
78
+ if(elmt.checked){
79
+ checkbox.checked = true;
80
+ }
81
+ });
82
+ var image = new Element('img', {'src' : this.logoUrl, 'title' : this.logoText, 'alt' : this.logoText, 'id' : 'ship_with_bpost_logo'});
83
+ var label = new Element('label', {'for' : 'ship_with_bpost'});
84
+ label.appendChild(checkbox);
85
+ label.update("");
86
+ label.appendChild(image);
87
+ var listitem = new Element('li');
88
+ listitem.addClassName('control');
89
+ listitem.appendChild(checkbox);
90
+ listitem.appendChild(label);
91
+ return listitem;
92
+ },
93
+
94
+ injectBpostInBillingInformation : function () {
95
+ var listitem = this.createShipWithBpostCheckbox();
96
+ if($('billing:use_for_shipping_no') == null){
97
+ var list = $('billing:use_for_shipping_yes').up();
98
+ list.appendChild(listitem);
99
+ } else{
100
+ var list = $('billing:use_for_shipping_no').up();
101
+ list.appendChild(listitem);
102
+ }
103
+ },
104
+
105
+ initiateTimers : function () {
106
+ this.log("initiating timers", "debug");
107
+ var continueButton = $('billing-buttons-container').down("button");
108
+ continueButton.onclick = function() {
109
+ setTimeout(detectShippingMethodsReload, 10);
110
+ billing.save();
111
+ };
112
+ },
113
+
114
+ postbackError : function (){
115
+ GB_hide();
116
+ },
117
+
118
+ postbackCancel : function (){
119
+ GB_hide();
120
+ },
121
+
122
+ postbackSuccess : function (deliveryMethod, shippingDetails){
123
+ GB_hide();
124
+ try{
125
+ $('s_method_bpost_' + deliveryMethod).checked = true;
126
+ } catch(err){
127
+ this.log("could not select shipping method: " + deliveryMethod, "error");
128
+ }
129
+ try{
130
+ this.updateShippingAddress(shippingDetails);
131
+ this.saveShippingMethod(deliveryMethod);
132
+ } catch(err){
133
+ this.log(err, "error");
134
+ }
135
+ },
136
+
137
+ updateShippingAddress : function (shippingDetails){
138
+
139
+ $('billing:use_for_shipping_yes').checked = false;
140
+ if($('shipping:firstname') != null){
141
+ $('shipping:firstname').value = shippingDetails.firstname;
142
+ }
143
+ if($('shipping:lastname') != null){
144
+ $('shipping:lastname').value = shippingDetails.lastname;
145
+ }
146
+ if($('shipping:telephone') != null){
147
+ $('shipping:telephone').value = shippingDetails.telephone;
148
+ }
149
+ if($('shipping:street1') != null){
150
+ $('shipping:street1').value = shippingDetails.street;
151
+ $('shipping:street1').readOnly = true;
152
+ }
153
+ if($('shipping:postcode') != null){
154
+ $('shipping:postcode').value = shippingDetails.zipcode;
155
+ $('shipping:postcode').readOnly = true;
156
+ }
157
+ if($('shipping:city') != null){
158
+ $('shipping:city').value = shippingDetails.city;
159
+ $('shipping:city').readOnly = true;
160
+ }
161
+ if($('shipping:company') != null){
162
+ $('shipping:company').value = shippingDetails.company;
163
+ $('shipping:company').readOnly = true;
164
+ }
165
+ if($('shipping:telephone') != null){
166
+ $('shipping:telephone').value = shippingDetails.telephone;
167
+ $('shipping:telephone').readOnly = true;
168
+ }
169
+ if($('shipping:country_id') != null){
170
+ $('shipping:country_id').value = shippingDetails.country_id;
171
+ $('shipping:country_id').readOnly = true;
172
+ }
173
+
174
+ if($('billing:firstname').value.blank()) $('billing:firstname').value = shippingDetails.firstname;
175
+ if($('billing:lastname').value.blank()) $('billing:lastname').value = shippingDetails.lastname;
176
+ if($('billing:telephone').value.blank()) $('billing:telephone').value = shippingDetails.telephone;
177
+ if($('billing:street1').value.blank()) $('billing:street1').value = shippingDetails.street;
178
+ if($('billing:postcode').value.blank()) $('billing:postcode').value = shippingDetails.zipcode;
179
+ if($('billing:city').value.blank()) $('billing:city').value = shippingDetails.city;
180
+ if($('billing:telephone').value.blank()) $('billing:telephone').value = shippingDetails.telephone;
181
+ },
182
+
183
+ releaseShippingAddress : function (){
184
+ var me = this;
185
+ me.log("releasing shipping address", "debug");
186
+ if($('shipping:telephone') != null) $('shipping:telephone').readOnly = false;
187
+ if($('shipping:street1') != null) $('shipping:street1').readOnly = false;
188
+ if($('shipping:postcode') != null) $('shipping:postcode').readOnly = false;
189
+ if($('shipping:city') != null) $('shipping:city').readOnly = false;
190
+ if($('shipping:company') != null) $('shipping:company').readOnly = false;
191
+ if($('shipping:country_id') != null) $('shipping:country_id').readOnly = false;
192
+ $$("input.bpost-shipping-method").each(function(elmt){
193
+ $(elmt.id).checked = false;
194
+ });
195
+ },
196
+
197
+ saveShippingMethod : function (deliveryMethod){
198
+ shippingMethod.save();
199
+ },
200
+
201
+ reloadShippingMethods : function (){
202
+ this.hideBpostShippingMethods();
203
+ this.replaceBpostTextByBpostLogo();
204
+ },
205
+
206
+ bpostLogoElement : function (){
207
+ var image = new Element('img', {'src' : this.logoUrl, 'alt' : this.logoText, 'id' : 'bpost_logo'});
208
+ image.addClassName("start_timers");
209
+ var link = new Element('a',{'id' : 'load_bpost_shippingmanager', 'href' : 'javascript:shm.show();', 'title' : this.logoText})
210
+ link.appendChild(image);
211
+ return link;
212
+ },
213
+
214
+ arebpostShippingMethodsAvailable : function (){
215
+ var bpostMethodsAvailable = false;
216
+ $("checkout-shipping-method-load").getElementsBySelector('[name="shipping_method"]').each(function(elmt) {
217
+ if(elmt.id.startsWith('s_method_bpost')){
218
+ bpostMethodsAvailable = true;
219
+ return false;
220
+ }
221
+ });
222
+ return bpostMethodsAvailable;
223
+ },
224
+
225
+ shippingMethodElements : function (logo){
226
+ return $$("div#checkout-shipping-method-load dt");
227
+ },
228
+
229
+ replaceBpostTextByBpostLogo : function (){
230
+ // have to save the this because it gets overwritten by the each
231
+ var me = this;
232
+ if(me.arebpostShippingMethodsAvailable()){
233
+ if($('start_bpost_shippingmanager') == null){
234
+ me.log("Logo not found. adding it via javascript", "debug");
235
+ var replaceDone = false
236
+ var bpostLogoElement = me.bpostLogoElement();
237
+ me.shippingMethodElements().each(function(elmt) {
238
+ if(elmt.innerHTML == "bpost"){
239
+ me.log("bpost text found. Changing it to image", "debug");
240
+ elmt.update(bpostLogoElement);
241
+ replaceDone = true;
242
+ return false;
243
+ }
244
+ });
245
+ if(!replaceDone){
246
+ me.log("Insert logo", "debug");
247
+ $("checkout-shipping-method-load").appendChild(bpostLogoElement);
248
+ }
249
+ }
250
+ if(!this.OSCConfigOk){
251
+ $("bpost_logo").up("dd").hide();
252
+ }
253
+ }
254
+ }
255
+ }
skin/frontend/base/default/js/bpost/shippingmanager/checkout_cart.js ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var bpostShippingManager = Class.create();
2
+ bpostShippingManager.prototype = Object.extend(new bpostShippingManagerBase(), {
3
+ postbackSuccess : function (deliveryMethod){
4
+ GB_hide();
5
+ try{
6
+ this.log('Processing postback success', "info");
7
+ $('s_method_bpost_' + deliveryMethod).checked = true;
8
+ $('co-shipping-method-form').submit();
9
+ } catch(err){
10
+ //Handle errors here
11
+ this.log("could not select shipping method: " + deliveryMethod, "error");
12
+ }
13
+
14
+ },
15
+
16
+ shippingMethodElements : function (){
17
+ return $$("dl.sp-methods dt");
18
+ },
19
+
20
+ arebpostShippingMethodsAvailable : function (){
21
+ var bpostMethodsAvailable = false;
22
+ $("co-shipping-method-form").getElementsBySelector('[name="estimate_method"]').each(function(elmt) {
23
+ if(elmt.id.startsWith('s_method_bpost')){
24
+ bpostMethodsAvailable = true;
25
+ return false;
26
+ }
27
+ });
28
+ return bpostMethodsAvailable;
29
+ },
30
+
31
+ initiateTimers : function () {},
32
+
33
+ injectBpostInBillingInformation : function () {},
34
+
35
+ bpostLogoElement : function (){
36
+ var image = new Element('img', {'src' : this.logoUrl, 'width': '90', 'height' : this.logoHeight, 'class' : 'start_timers', 'alt' : this.logoText, 'id' : 'bpost_logo'});
37
+ var link = new Element('a',{'id' : 'load_bpost_shippingmanager', 'href' : 'javascript:shm.show();', 'title' : this.logoText})
38
+ link.appendChild(image);
39
+ return link;
40
+ },
41
+
42
+ hideBpostShippingMethods : function(){
43
+ var me = this;
44
+ $("co-shipping-method-form").getElementsBySelector('[name="estimate_method"]').each(function(elmt) {
45
+ if(elmt.id.startsWith('s_method_bpost')){
46
+ elmt.addClassName("bpost-shipping-method");
47
+ me.log("hiding " + elmt.id, "info");
48
+ elmt.up().hide();
49
+ }
50
+ });
51
+ }
52
+
53
+ });
54
+
55
+
56
+
skin/frontend/base/default/js/bpost/shippingmanager/onepage_checkout.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var bpostShippingManager = Class.create();
2
+ bpostShippingManager.prototype = Object.extend(new bpostShippingManagerBase(), {});
3
+
4
+ function detectShippingMethodsReload(){
5
+ if($$("dl.bpost_shippingmanager_loaded").length == 1){
6
+ setTimeout(detectShippingMethodsReload, 10);
7
+ } else{
8
+ shm.reloadShippingMethods();
9
+ var chkShipWithBpost = $("ship_with_bpost");
10
+ if(chkShipWithBpost && chkShipWithBpost.checked){
11
+ shm.show();
12
+ }
13
+ }
14
+ }
skin/frontend/base/default/js/bpost/shippingmanager/onestep_checkout.js ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var bpostShippingManager = Class.create();
2
+ var NumberOfReloadTries = 0;
3
+ bpostShippingManager.prototype = Object.extend(new bpostShippingManagerBase(), {
4
+ updateStartFormField : function(element, fromFieldId){
5
+ if(!this.OSCConfigOk){
6
+ return;
7
+ }
8
+ element.value = $('billing:' + fromFieldId).value;
9
+ if($('shipping:use_for_shipping_yes') != null && $('billing:use_for_shipping_yes').checked){
10
+ element.value = $('shipping:' + fromFieldId).value;
11
+ }
12
+ },
13
+
14
+ initiateTimers : function () {
15
+ this.log("initiating timers", "debug");
16
+
17
+ $('billing:postcode').onchange = function() {
18
+ detectShippingMethodsReload();
19
+ }
20
+
21
+ $('billing:city').onchange = function() {
22
+ detectShippingMethodsReload();
23
+ }
24
+ $('billing:country_id').onchange = function() {
25
+ detectShippingMethodsReload();
26
+ }
27
+ $('billing:use_for_shipping_yes').onchange = function() {
28
+ detectShippingMethodsReload();
29
+ }
30
+ },
31
+
32
+ reloadShippingMethods : function (){
33
+ if($$("div.onestepcheckout-shipping-method-block").length > 0){
34
+ $$("div.onestepcheckout-shipping-method-block")[0].setAttribute('id', 'checkout-shipping-method-load');
35
+ this.hideBpostShippingMethods();
36
+ this.replaceBpostTextByBpostLogo();
37
+ } else{
38
+ $("start_bpost_shippingmanager").up("dd").hide();
39
+ $$("input").each(function(elmt) {
40
+ if(elmt.id.startsWith('s_method_bpost')){
41
+ elmt.addClassName("bpost-shipping-method");
42
+ elmt.up().hide();
43
+ }
44
+ });
45
+ }
46
+ },
47
+
48
+ injectBpostInBillingInformation : function () {
49
+ if(!this.OSCConfigOk){
50
+ return;
51
+ }
52
+ try{
53
+ // Add the checkbox
54
+ $$("div#billing_address ul")[0].appendChild(this.createShipWithBpostCheckbox());
55
+ $('ship_with_bpost').onclick = function() {
56
+ if ($('ship_with_bpost').checked){
57
+ if($('billing:country_id').value == ""){
58
+ alert("Please specifiy your country first.");
59
+ $('ship_with_bpost').checked = false;
60
+ } else{
61
+ shm.show();
62
+ }
63
+ }else{
64
+ shm.releaseShippingAddress();
65
+ }
66
+ };
67
+ }catch(err){
68
+ this.log("Failed adding bpost Shippingmanager in billing information","error");
69
+ }
70
+ },
71
+
72
+ saveShippingMethod : function (deliveryMethod){
73
+ if(!this.OSCConfigOk){
74
+ return;
75
+ }
76
+ try{
77
+ $('s_method_bpost_' + deliveryMethod).click();
78
+ if($("shipping_address") != null) $("shipping_address").show();
79
+ if($("shipping_address_list") != null) $("shipping_address_list").show();
80
+ }catch(err){
81
+ this.log(err, "error");
82
+ }
83
+ }
84
+ });
85
+
86
+ function detectShippingMethodsReload(){
87
+ NumberOfReloadTries++;
88
+ if(NumberOfReloadTries > 100 && Ajax.activeRequestCount == 0){
89
+ shm.log("Ending reload detection loop", "debug");
90
+ NumberOfReloadTries = 0;
91
+ return;
92
+ }
93
+ if($$("dl.bpost_shippingmanager_loaded").length == 1){
94
+ if(Ajax.activeRequestCount > 0){
95
+ NumberOfReloadTries = 0;
96
+ }
97
+ setTimeout(detectShippingMethodsReload, 20);
98
+ } else{
99
+ if(Ajax.activeRequestCount == 0){
100
+ shm.reloadShippingMethods();
101
+ var chkShipWithBpost = $("ship_with_bpost");
102
+ if(chkShipWithBpost && chkShipWithBpost.checked){
103
+ shm.show();
104
+ }
105
+ } else{
106
+ shm.log("Waiting for all ajax request to finish. Requests left:" + Ajax.activeRequestCount, "debug");
107
+ setTimeout(detectShippingMethodsReload, 20);
108
+ }
109
+ }
110
+ }