Tiramizoo_Shipping - Version 0.1.0

Version Notes

Initial module release.

Download this release

Release Info

Developer Tiramizoo GmbH
Extension Tiramizoo_Shipping
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

Files changed (72) hide show
  1. app/code/community/Tiramizoo/Shipping/Block/Adminhtml/Catalog/Product/Edit/Tab/Action.php +86 -0
  2. app/code/community/Tiramizoo/Shipping/Block/Adminhtml/Sales/Order/View/Tab/Tiramizoo.php +100 -0
  3. app/code/community/Tiramizoo/Shipping/Block/Button.php +47 -0
  4. app/code/community/Tiramizoo/Shipping/Block/Onepackagedimensions.php +43 -0
  5. app/code/community/Tiramizoo/Shipping/Block/Order/Email/Tracking.php +41 -0
  6. app/code/community/Tiramizoo/Shipping/Block/Productdimensions.php +43 -0
  7. app/code/community/Tiramizoo/Shipping/Helper/Build.php +451 -0
  8. app/code/community/Tiramizoo/Shipping/Helper/Data.php +103 -0
  9. app/code/community/Tiramizoo/Shipping/Helper/Package.php +55 -0
  10. app/code/community/Tiramizoo/Shipping/Model/Api.php +113 -0
  11. app/code/community/Tiramizoo/Shipping/Model/Attributes.php +59 -0
  12. app/code/community/Tiramizoo/Shipping/Model/Carrier/Tiramizoo.php +141 -0
  13. app/code/community/Tiramizoo/Shipping/Model/Cart.php +70 -0
  14. app/code/community/Tiramizoo/Shipping/Model/Category.php +192 -0
  15. app/code/community/Tiramizoo/Shipping/Model/Category/Attributes.php +106 -0
  16. app/code/community/Tiramizoo/Shipping/Model/Config/Apiurl.php +45 -0
  17. app/code/community/Tiramizoo/Shipping/Model/Config/Packingstrategy.php +49 -0
  18. app/code/community/Tiramizoo/Shipping/Model/Date.php +254 -0
  19. app/code/community/Tiramizoo/Shipping/Model/Debug.php +39 -0
  20. app/code/community/Tiramizoo/Shipping/Model/Default.php +51 -0
  21. app/code/community/Tiramizoo/Shipping/Model/Delivery/Type.php +166 -0
  22. app/code/community/Tiramizoo/Shipping/Model/Delivery/Type/Evening.php +134 -0
  23. app/code/community/Tiramizoo/Shipping/Model/Delivery/Type/Immediate.php +107 -0
  24. app/code/community/Tiramizoo/Shipping/Model/Entity/Attribute/Source/Enable.php +81 -0
  25. app/code/community/Tiramizoo/Shipping/Model/Entity/Attribute/Source/Packed.php +81 -0
  26. app/code/community/Tiramizoo/Shipping/Model/Mysql4/Order.php +35 -0
  27. app/code/community/Tiramizoo/Shipping/Model/Mysql4/Order/Collection.php +34 -0
  28. app/code/community/Tiramizoo/Shipping/Model/Observer.php +296 -0
  29. app/code/community/Tiramizoo/Shipping/Model/Order.php +35 -0
  30. app/code/community/Tiramizoo/Shipping/Model/Payment.php +77 -0
  31. app/code/community/Tiramizoo/Shipping/Model/Product.php +334 -0
  32. app/code/community/Tiramizoo/Shipping/Model/Product/Attributes.php +120 -0
  33. app/code/community/Tiramizoo/Shipping/Model/Resend.php +117 -0
  34. app/code/community/Tiramizoo/Shipping/Model/Response.php +89 -0
  35. app/code/community/Tiramizoo/Shipping/Model/Retaillocation.php +301 -0
  36. app/code/community/Tiramizoo/Shipping/Model/Retaillocations.php +59 -0
  37. app/code/community/Tiramizoo/Shipping/Model/TestObserver.php +80 -0
  38. app/code/community/Tiramizoo/Shipping/Model/Time/Window.php +272 -0
  39. app/code/community/Tiramizoo/Shipping/Model/Type/Onepage.php +39 -0
  40. app/code/community/Tiramizoo/Shipping/Test/Helper/Build.php +114 -0
  41. app/code/community/Tiramizoo/Shipping/Test/Helper/Build/fixtures/default.yaml +283 -0
  42. app/code/community/Tiramizoo/Shipping/Test/Helper/Build/providers/testBuildItems.yaml +39 -0
  43. app/code/community/Tiramizoo/Shipping/Test/Model/Category.php +89 -0
  44. app/code/community/Tiramizoo/Shipping/Test/Model/Category/fixtures/default.yaml +252 -0
  45. app/code/community/Tiramizoo/Shipping/Test/Model/Category/providers/testCart.yaml +38 -0
  46. app/code/community/Tiramizoo/Shipping/Test/Model/Category/providers/testGetDimensions.yaml +22 -0
  47. app/code/community/Tiramizoo/Shipping/Test/Model/Product.php +182 -0
  48. app/code/community/Tiramizoo/Shipping/Test/Model/Product/fixtures/default.yaml +372 -0
  49. app/code/community/Tiramizoo/Shipping/Test/Model/Product/providers/testCategoryGetNames.yaml +15 -0
  50. app/code/community/Tiramizoo/Shipping/Test/Model/Product/providers/testGetDimensions.yaml +27 -0
  51. app/code/community/Tiramizoo/Shipping/Test/Model/Product/providers/testProductIsAvailableToTiramizooDelivery.yaml +21 -0
  52. app/code/community/Tiramizoo/Shipping/Test/Model/Product/providers/testProductIsPackedIndividually.yaml +29 -0
  53. app/code/community/Tiramizoo/Shipping/controllers/Adminhtml/SynchronizeController.php +42 -0
  54. app/code/community/Tiramizoo/Shipping/controllers/IndexController.php +60 -0
  55. app/code/community/Tiramizoo/Shipping/controllers/WebhookController.php +68 -0
  56. app/code/community/Tiramizoo/Shipping/etc/config.xml +301 -0
  57. app/code/community/Tiramizoo/Shipping/etc/system.xml +563 -0
  58. app/code/community/Tiramizoo/Shipping/sql/tiramizoo_setup/mysql4-install-0.1.0.php +460 -0
  59. app/design/adminhtml/default/default/layout/tiramizoo.xml +27 -0
  60. app/design/adminhtml/default/default/template/tiramizoo/catalog/product/tab/action.phtml +131 -0
  61. app/design/adminhtml/default/default/template/tiramizoo/order/view/tab/tiramizoo.phtml +51 -0
  62. app/design/frontend/base/default/layout/tiramizoo/checkout.xml +6 -0
  63. app/design/frontend/base/default/layout/tiramizoo/sales.xml +7 -0
  64. app/design/frontend/base/default/template/tiramizoo/order/email/tracking.phtml +24 -0
  65. app/design/frontend/base/default/template/tiramizoo/shipping/method/action.phtml +69 -0
  66. app/etc/modules/Tiramizoo_Shipping.xml +9 -0
  67. app/locale/de_DE/Tiramizoo_Shipping.csv +63 -0
  68. app/locale/en_US/Tiramizoo_Shipping.csv +62 -0
  69. app/locale/en_US/template/email/sales/order_new.html.dist +110 -0
  70. app/locale/en_US/template/email/sales/order_new_guest.html.dist +109 -0
  71. lib/Tiramizoo/TiramizooApi.php +185 -0
  72. package.xml +24 -0
app/code/community/Tiramizoo/Shipping/Block/Adminhtml/Catalog/Product/Edit/Tab/Action.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo product's information tabs
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Block_Adminhtml_Catalog_Product_Edit_Tab_Action
24
+ extends Mage_Adminhtml_Block_Template
25
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
26
+ {
27
+ /**
28
+ * Construct. Set product and template.
29
+ *
30
+ * @return null
31
+ */
32
+ public function _construct()
33
+ {
34
+ parent::_construct();
35
+
36
+ $productId = (int) $this->getRequest()->getParam('id');
37
+ $product = Mage::getModel('catalog/product')
38
+ ->setStoreId($this->getRequest()->getParam('store', 0));
39
+ $product->load($productId);
40
+
41
+ $this->setProduct($product);
42
+ $this->setTemplate('tiramizoo/catalog/product/tab/action.phtml');
43
+ }
44
+
45
+ /**
46
+ * Retrieve the label used for the tab relating to this block
47
+ *
48
+ * @return string
49
+ */
50
+ public function getTabLabel()
51
+ {
52
+ return $this->__('Tiramizoo Options');
53
+ }
54
+
55
+ /**
56
+ * Retrieve the title used by this tab
57
+ *
58
+ * @return string
59
+ */
60
+ public function getTabTitle()
61
+ {
62
+ return $this->__('Click here to view Tiramizoo configuration');
63
+ }
64
+
65
+ /**
66
+ * Determines whether to display the tab
67
+ * Add logic here to decide whether you want the tab to display
68
+ *
69
+ * @return bool
70
+ */
71
+ public function canShowTab()
72
+ {
73
+ return Mage::helper('tiramizoo_shipping/data')->isActive();
74
+ }
75
+
76
+ /**
77
+ * Stops the tab being hidden
78
+ *
79
+ * @return bool
80
+ */
81
+ public function isHidden()
82
+ {
83
+ return false;
84
+ }
85
+
86
+ }
app/code/community/Tiramizoo/Shipping/Block/Adminhtml/Sales/Order/View/Tab/Tiramizoo.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo order's information tabs
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Block_Adminhtml_Sales_Order_View_Tab_Tiramizoo
24
+ extends Mage_Adminhtml_Block_Template
25
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
26
+ {
27
+ /**
28
+ * Construct. Set template
29
+ *
30
+ * @return null
31
+ */
32
+ public function _construct()
33
+ {
34
+ parent::_construct();
35
+ $this->setTemplate('tiramizoo/order/view/tab/tiramizoo.phtml');
36
+ }
37
+
38
+ /**
39
+ * Get tab's label
40
+ *
41
+ * @return string
42
+ */
43
+ public function getTabLabel()
44
+ {
45
+ return $this->__('Tiramizoo');
46
+ }
47
+
48
+ /**
49
+ * Get tab's title
50
+ *
51
+ * @return string
52
+ */
53
+ public function getTabTitle()
54
+ {
55
+ return $this->__('Tiramizoo');
56
+ }
57
+
58
+ /**
59
+ * Decide if tab should be visible
60
+ *
61
+ * @return bool
62
+ */
63
+ public function canShowTab()
64
+ {
65
+ $shipping_method_code = $this->getOrder()->getShippingMethod();
66
+ $rates = Mage::helper('tiramizoo_shipping/data')->getAvailableShippingRates();
67
+
68
+ return array_key_exists($shipping_method_code, $rates) && $this->getTiramizooOrder()->getId();
69
+ }
70
+
71
+ /**
72
+ * Tab is hidden
73
+ *
74
+ * @return boolean
75
+ */
76
+ public function isHidden()
77
+ {
78
+ return false;
79
+ }
80
+
81
+ /**
82
+ * Returns current order
83
+ *
84
+ * @return mixed
85
+ */
86
+ public function getOrder()
87
+ {
88
+ return Mage::registry('current_order');
89
+ }
90
+
91
+ /**
92
+ * Returns tiramizoo order object
93
+ *
94
+ * @return mixed
95
+ */
96
+ public function getTiramizooOrder()
97
+ {
98
+ return Mage::getModel('tiramizoo/order')->load($this->getOrder()->getId(), 'order_id');
99
+ }
100
+ }
app/code/community/Tiramizoo/Shipping/Block/Button.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Synchronize button form renderer
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Block_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
24
+ {
25
+ /**
26
+ * Get the button contents
27
+ *
28
+ * @param Varien_Data_Form_Element_Abstract $element
29
+ * @return string
30
+ */
31
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
32
+ {
33
+ $this->setElement($element);
34
+
35
+ //@TODO: change to secure adminhtml route
36
+ $url = $this->getUrl('tiramizoo/adminhtml_synchronize/index'); //
37
+
38
+ $html = $this->getLayout()->createBlock('adminhtml/widget_button')
39
+ ->setType('button')
40
+ ->setClass('scalable')
41
+ ->setLabel($this->__('Synchronize'))
42
+ ->setOnClick("setLocation('$url')")
43
+ ->toHtml();
44
+
45
+ return $html;
46
+ }
47
+ }
app/code/community/Tiramizoo/Shipping/Block/Onepackagedimensions.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Onepackagedimensions form fields renderer
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Block_Onepackagedimensions extends Mage_Adminhtml_Block_System_Config_Form_Field
24
+ {
25
+ /**
26
+ * Get the element contents
27
+ *
28
+ * @param Varien_Data_Form_Element_Abstract $element
29
+ * @return string
30
+ */
31
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
32
+ {
33
+ $this->setElement($element);
34
+
35
+ $html = '<label style="display:block; float:left; width:60px;">'.$this->__('Weight').': </label><input type="text" name="groups[api_config][fields][onepackage_weight][value]" value="' . Mage::getStoreConfig('tiramizoo_config/api_config/onepackage_weight', Mage::app()->getStore()) . '" style="width:30px;" /> kg <br />';
36
+ $html .= '<label style="display:block; float:left; width:60px;">'.$this->__('Width').': </label><input type="text" name="groups[api_config][fields][onepackage_width][value]" value="' . Mage::getStoreConfig('tiramizoo_config/api_config/onepackage_width', Mage::app()->getStore()) . '" style="width:30px;" /> cm <br />';
37
+ $html .= '<label style="display:block; float:left; width:60px;">'.$this->__('Height').': </label><input type="text" name="groups[api_config][fields][onepackage_height][value]" value="' . Mage::getStoreConfig('tiramizoo_config/api_config/onepackage_height', Mage::app()->getStore()) . '" style="width:30px;" /> cm <br />';
38
+ $html .= '<label style="display:block; float:left; width:60px;">'.$this->__('Length').': </label><input type="text" name="groups[api_config][fields][onepackage_length][value]" value="' . Mage::getStoreConfig('tiramizoo_config/api_config/onepackage_length', Mage::app()->getStore()) . '" style="width:30px;" /> cm <br />';
39
+ $html .= '<span id="' . $element->getId() . '"></span>';
40
+
41
+ return $html;
42
+ }
43
+ }
app/code/community/Tiramizoo/Shipping/Block/Order/Email/Tracking.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Email tracking block
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Block_Order_Email_Tracking extends Mage_Core_Block_Template {
24
+
25
+ /**
26
+ * Returns order's tracking url.
27
+ *
28
+ * @param object $order
29
+ * @return string tracking url
30
+ */
31
+ public function getTrackingUrl($order)
32
+ {
33
+ $returnUrl = false;
34
+ $tiramizooOrder = Mage::getModel('tiramizoo/order')->load($order->getId(), 'order_id');
35
+ if ($tiramizooOrder->getId()) {
36
+ $returnUrl = $tiramizooOrder->getTrackingUrl();
37
+ }
38
+ return $returnUrl;
39
+ }
40
+
41
+ }
app/code/community/Tiramizoo/Shipping/Block/Productdimensions.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Productdimensions form fields renderer
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Block_Productdimensions extends Mage_Adminhtml_Block_System_Config_Form_Field
24
+ {
25
+ /**
26
+ * Get the element contents
27
+ *
28
+ * @param Varien_Data_Form_Element_Abstract $element
29
+ * @return string
30
+ */
31
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
32
+ {
33
+ $this->setElement($element);
34
+
35
+ $html = '<label style="display:block; float:left; width:60px;">'.$this->__('Weight').': </label><input type="text" name="groups[api_config][fields][product_weight][value]" value="' . Mage::getStoreConfig('tiramizoo_config/api_config/product_weight', Mage::app()->getStore()) . '" style="width:30px;" /> kg <br />';
36
+ $html .= '<label style="display:block; float:left; width:60px;">'.$this->__('Width').': </label><input type="text" name="groups[api_config][fields][product_width][value]" value="' . Mage::getStoreConfig('tiramizoo_config/api_config/product_width', Mage::app()->getStore()) . '" style="width:30px;" /> cm <br />';
37
+ $html .= '<label style="display:block; float:left; width:60px;">'.$this->__('Height').': </label><input type="text" name="groups[api_config][fields][product_height][value]" value="' . Mage::getStoreConfig('tiramizoo_config/api_config/product_height', Mage::app()->getStore()) . '" style="width:30px;" /> cm <br />';
38
+ $html .= '<label style="display:block; float:left; width:60px;">'.$this->__('Length').': </label><input type="text" name="groups[api_config][fields][product_length][value]" value="' . Mage::getStoreConfig('tiramizoo_config/api_config/product_length', Mage::app()->getStore()) . '" style="width:30px;" /> cm <br />';
39
+ $html .= '<span id="' . $element->getId() . '"></span>';
40
+
41
+ return $html;
42
+ }
43
+ }
app/code/community/Tiramizoo/Shipping/Helper/Build.php ADDED
@@ -0,0 +1,451 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo API object build helper
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Helper_Build extends Mage_Core_Helper_Abstract
24
+ {
25
+
26
+ /**
27
+ * Salt thst used for generating external id
28
+ */
29
+ const TIRAMIZOO_SALT = 'mageTiramizoo';
30
+
31
+ /**
32
+ * Relative uri path to API endpoint
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_apiWebhookUrl = 'tiramizoo/webhook/render';
37
+
38
+ /**
39
+ * Tiramizoo Data
40
+ *
41
+ * @var stdClass
42
+ */
43
+ protected $_tiramizooData = null;
44
+
45
+ /**
46
+ * External id used for identify order
47
+ *
48
+ * @var string
49
+ */
50
+ protected $_externalId = '';
51
+
52
+ /**
53
+ * Pickup object
54
+ *
55
+ * @var stdClass
56
+ */
57
+ protected $_pickup = null;
58
+
59
+ /**
60
+ * Time Window object
61
+ *
62
+ * @var Tiramizoo_Shipping_Model_Time_Window
63
+ */
64
+ protected $_timeWindow = null;
65
+
66
+ /**
67
+ * Shipping Address object
68
+ *
69
+ * @var Mage_Sales_Model_Order_Address
70
+ */
71
+ protected $_shippingAddress = null;
72
+
73
+ /**
74
+ * Retail Location object
75
+ *
76
+ * @var Tiramizoo_Shipping_Model_Retaillocation
77
+ */
78
+ protected $_retailLocation = null;
79
+
80
+ /**
81
+ * Order items array
82
+ *
83
+ * @var array
84
+ */
85
+ protected $_orderItems = null;
86
+
87
+ /**
88
+ * Delivery object
89
+ *
90
+ * @var stdClass
91
+ */
92
+ protected $_delivery = null;
93
+
94
+ /**
95
+ * Information that standard package has been
96
+ * already added to items array
97
+ *
98
+ * @var bool
99
+ */
100
+ protected $_standardPackageAddedToItems = null;
101
+
102
+ /**
103
+ * Information that package strategy use
104
+ * one package to pack all items
105
+ *
106
+ * @var bool
107
+ */
108
+ protected $_useStandardPackage = false;
109
+
110
+ /**
111
+ * Array of packed items
112
+ *
113
+ * @var array
114
+ */
115
+ protected $_items = array();
116
+
117
+ /**
118
+ * Set Time Window
119
+ * @param Tiramizoo_Shipping_Model_Time_Window $timeWindow
120
+ */
121
+ public function setTimeWindow(Tiramizoo_Shipping_Model_Time_Window $timeWindow)
122
+ {
123
+ $this->_timeWindow = $timeWindow;
124
+ return $this;
125
+ }
126
+
127
+ /**
128
+ * Set Shipping Address
129
+ * @param Mage_Sales_Model_Order_Address $address
130
+ */
131
+ public function setAddress(Mage_Sales_Model_Order_Address $address)
132
+ {
133
+ $this->_shippingAddress = $address;
134
+ return $this;
135
+ }
136
+
137
+ /**
138
+ * Set Retail Location
139
+ * @param Tiramizoo_Shipping_Model_Retaillocation $address
140
+ */
141
+ public function setRetailLocation(Tiramizoo_Shipping_Model_Retaillocation $retailLocation)
142
+ {
143
+ $this->_retailLocation = $retailLocation;
144
+ return $this;
145
+ }
146
+
147
+ /**
148
+ * Set all order items
149
+ * @param Array $items
150
+ */
151
+ public function setItems(Array $items)
152
+ {
153
+ $this->_orderItems = $items;
154
+ return $this;
155
+ }
156
+
157
+ /**
158
+ * Returns webhook endpoint relative uri.
159
+ *
160
+ * @return string
161
+ */
162
+ public function getWebhookUrl()
163
+ {
164
+ return Mage::getUrl( $this->_apiWebhookUrl );
165
+ }
166
+
167
+ /**
168
+ * Generate and set external id. Uses salt to better fresult.
169
+ *
170
+ * @return null
171
+ */
172
+ public function generateExternalId()
173
+ {
174
+ $this->_externalId = md5(time() . self::TIRAMIZOO_SALT);
175
+ }
176
+
177
+ /**
178
+ * Returns external id. Genearate if not exists.
179
+ *
180
+ * @return string
181
+ */
182
+ public function getExternalId()
183
+ {
184
+ if (!$this->_externalId) {
185
+ $this->generateExternalId();
186
+ }
187
+
188
+ return $this->_externalId;
189
+ }
190
+
191
+ /**
192
+ * Returns TiramizooData Object. Create stdClass
193
+ * object and assign object properties with data
194
+ *
195
+ * @return stdClass
196
+ */
197
+ public function createTiramizooOrderDataObject()
198
+ {
199
+ $this->_tiramizooData = new stdClass();
200
+
201
+ $this->_tiramizooData->description = $this->getDescription();
202
+ $this->_tiramizooData->external_id = $this->getExternalId();
203
+ $this->_tiramizooData->web_hook_url = $this->getWebhookUrl();
204
+ $this->_tiramizooData->pickup = $this->buildPickup();
205
+ $this->_tiramizooData->delivery = $this->buildDelivery();
206
+ $this->_tiramizooData->packages = $this->buildItems();
207
+
208
+ return $this->_tiramizooData;
209
+ }
210
+
211
+ /**
212
+ * Build description from product's names. Used for build partial data to send order API request
213
+ *
214
+ * @return string description
215
+ */
216
+ public function getDescription()
217
+ {
218
+ // @todo
219
+ //string should be contains at least 255 chars
220
+ //return substr(implode($itemNames, ', '), 0, 255);
221
+ return __FUNCTION__;
222
+ }
223
+
224
+ /**
225
+ * Build delivery object from user data. Used for build partial data
226
+ * to send order API request
227
+ *
228
+ * @return stdClass Delivery object
229
+ */
230
+ public function buildDelivery()
231
+ {
232
+ $address = $this->_shippingAddress;
233
+
234
+ $this->_delivery = new stdClass();
235
+
236
+ $this->_delivery->email = $address->getEmail();
237
+ // @todo: Street line?
238
+ $this->_delivery->address_line = $address->getStreet(1);
239
+
240
+ // $this->_delivery->city = $address->getCity();
241
+ $this->_delivery->postal_code = $address->getPostcode();
242
+ $this->_delivery->country_code = strtolower($address->getCountryId());
243
+ $this->_delivery->phone_number = $address->getTelephone();
244
+
245
+ $this->_delivery->name = $address->getFirstname().' '.$address->getLastname();
246
+
247
+ if ($address->getCompany()) {
248
+ $this->_delivery->name = $address->getCompany().' / '.$this->_delivery->name;
249
+ }
250
+
251
+ $this->_delivery->after = $this->_timeWindow->getDeliveryFrom();
252
+ $this->_delivery->before = $this->_timeWindow->getDeliveryTo();
253
+
254
+ return $this->_delivery;
255
+ }
256
+
257
+ /**
258
+ * Build pickup object from tiramizoo config values. Used for build partial data
259
+ * to send order API request
260
+ *
261
+ * @return stdClass Pickup object
262
+ */
263
+ public function buildPickup()
264
+ {
265
+ $pickup = $this->_retailLocation->getParam('pickup_contact');
266
+
267
+ $this->_pickup = new stdClass();
268
+ $this->_pickup->address_line = $pickup['address_line'];
269
+ if (isset($pickup['city']) && !empty($pickup['city'])) {
270
+ $this->_pickup->city = $pickup['city'];
271
+ }
272
+ $this->_pickup->postal_code = $pickup['postal_code'];
273
+ $this->_pickup->country_code = strtolower($pickup['country_code']);
274
+ $this->_pickup->name = $pickup['name'];
275
+ $this->_pickup->phone_number = $pickup['phone_number'];
276
+
277
+ $this->_pickup->after = $this->_timeWindow->getPickupFrom();
278
+ $this->_pickup->before = $this->_timeWindow->getPickupTo();
279
+
280
+ return $this->_pickup;
281
+ }
282
+
283
+ /**
284
+ * Build items data used for sending order. Returns packages object
285
+ * or false if build item return false.
286
+ *
287
+ * @return mixed
288
+ */
289
+ public function buildItems()
290
+ {
291
+ $packageStrategy = $this->getPackingStrategy();
292
+ $itemWasBuilt = null;
293
+ $return = false;
294
+ $this->_useStandardPackage = false;
295
+ $onePackage = $this->getOnePackageDimensions();
296
+
297
+ if ($packageStrategy == 'onepackage') {
298
+ $this->_useStandardPackage = $this->_useStandardPackage(
299
+ $onePackage->width,
300
+ $onePackage->length,
301
+ $onePackage->height,
302
+ $onePackage->weight
303
+ );
304
+
305
+ $this->_standardPackageAddedToItems = 0;
306
+ }
307
+
308
+ $this->_items = array();
309
+
310
+ foreach ($this->_orderItems as $orderItem) {
311
+ $itemWasBuilt = $this->_buildItem($orderItem);
312
+
313
+ if (!$itemWasBuilt) {
314
+ $return = false;
315
+ break;
316
+ }
317
+ }
318
+
319
+ if ($itemWasBuilt) {
320
+ $return = $this->_items;
321
+ }
322
+
323
+ return $return;
324
+ }
325
+
326
+ /**
327
+ * Build item based on article. If product has no specified params
328
+ * e.g. enable, weight, dimensions it inherits from main category
329
+ *
330
+ * @param Mage_Sales_Model_Order_Item $orderItem
331
+ *
332
+ * @return bool
333
+ */
334
+ protected function _buildItem(Mage_Sales_Model_Order_Item $orderItem)
335
+ {
336
+ $return = true;
337
+
338
+ //initialize standard class
339
+ $item = new stdClass();
340
+ $item->weight = null;
341
+ $item->width = null;
342
+ $item->height = null;
343
+ $item->length = null;
344
+
345
+ $item->quantity = floatval($orderItem->getQtyOrdered());
346
+
347
+ $product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
348
+ $tiramizooProduct = Mage::getModel('tiramizoo/product', $product);
349
+
350
+ $attr = $tiramizooProduct->getDimensions();
351
+ $isPackedIndividually = $tiramizooProduct->isPackedIndividually();
352
+
353
+ if (!($attr)) {
354
+ $return = false;
355
+ } else {
356
+ $item->weight = floatval($attr['weight']);
357
+ $item->width = floatval($attr['width']);
358
+ $item->height = floatval($attr['height']);
359
+ $item->length = floatval($attr['length']);
360
+
361
+ $item->description = $orderItem->getName();
362
+
363
+ //insert item to container
364
+ $this->_insertItem($item, $isPackedIndividually);
365
+ }
366
+
367
+ return $return;
368
+ }
369
+
370
+ /**
371
+ * Insert item to container. Uses package strategy to define how
372
+ * item should be packed.
373
+ *
374
+ * @return null
375
+ */
376
+ protected function _insertItem($item, $isPackedIndividually)
377
+ {
378
+ $packingStrategy = $this->getPackingStrategy();
379
+
380
+ // @todo
381
+ if ($this->_useStandardPackage && !$isPackedIndividually) { // && !$oArticleExtended->hasIndividualPackage()
382
+
383
+ if (!$this->_standardPackageAddedToItems) {
384
+ $this->_standardPackageAddedToItems = 1;
385
+
386
+ $onePackage = $this->getOnePackageDimensions();
387
+
388
+ $item->weight = floatval($onePackage->weight);
389
+ $item->width = floatval($onePackage->width);
390
+ $item->length = floatval($onePackage->length);
391
+ $item->height = floatval($onePackage->height);
392
+ $item->quantity = 1;
393
+
394
+ $this->_items[] = $item;
395
+ }
396
+ }
397
+ //@todo individual package && !$oArticleExtended->hasIndividualPackage()
398
+ elseif (($packingStrategy == 'packages') && !$isPackedIndividually) {
399
+ $item->bundle = true;
400
+ $this->_items[] = $item;
401
+ } else {
402
+ $this->_items[] = $item;
403
+ }
404
+
405
+ // exit;
406
+ }
407
+
408
+ /**
409
+ * Check if standard dimensions and weight are set properly
410
+ *
411
+ * @param int $stdPackageWidth
412
+ * @param int $stdPackageLength
413
+ * @param int $stdPackageHeight
414
+ * @param int $stdPackageWeight
415
+ *
416
+ * @return bool
417
+ */
418
+ protected function _useStandardPackage($stdPackageWidth, $stdPackageLength, $stdPackageHeight, $stdPackageWeight)
419
+ {
420
+ return $stdPackageWidth
421
+ && $stdPackageLength
422
+ && $stdPackageHeight
423
+ && $stdPackageWeight;
424
+ }
425
+
426
+ /**
427
+ * Get one package dimensions as object
428
+ *
429
+ * @return stdClass dimensions
430
+ */
431
+ public function getOnePackageDimensions()
432
+ {
433
+ $item = new stdClass();
434
+ $item->weight = Mage::getStoreConfig('tiramizoo_config/api_config/onepackage_weight');
435
+ $item->width = Mage::getStoreConfig('tiramizoo_config/api_config/onepackage_width');
436
+ $item->length = Mage::getStoreConfig('tiramizoo_config/api_config/onepackage_length');
437
+ $item->height = Mage::getStoreConfig('tiramizoo_config/api_config/onepackage_height');
438
+
439
+ return $item;
440
+ }
441
+
442
+ /**
443
+ * Get packing strategy
444
+ *
445
+ * @return string packing strategy
446
+ */
447
+ public function getPackingStrategy()
448
+ {
449
+ return Mage::getStoreConfig('tiramizoo_config/api_config/packing_strategy');
450
+ }
451
+ }
app/code/community/Tiramizoo/Shipping/Helper/Data.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo helper Data
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Helper_Data extends Mage_Core_Helper_Abstract
24
+ {
25
+ /**
26
+ * Get available rates codes
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_shippingRates = array(
31
+ 'tiramizoo_immediate' => 'immediate',
32
+ 'tiramizoo_evening' => 'evening'
33
+ );
34
+
35
+ /**
36
+ * Return config data from path
37
+ *
38
+ * @param string $path
39
+ * @return string
40
+ */
41
+ public function getConfigData($path)
42
+ {
43
+ $store_id = Mage::app()->getStore()->getId();
44
+ if ($store_id) {
45
+ return Mage::getStoreConfig($path, $store_id);
46
+ } else {
47
+ $store = Mage::app()->getFrontController()->getRequest()->getParam('store');
48
+ if ($store) {
49
+ return Mage::getStoreConfig($path, $store);
50
+ }
51
+ $website = Mage::app()->getFrontController()->getRequest()->getParam('website');
52
+ if ($website) {
53
+ return Mage::app()->getWebsite($website)->getConfig($path);
54
+ }
55
+ return Mage::getStoreConfig($path);
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Get if tiramizoo is active
61
+ *
62
+ * @return int
63
+ */
64
+ public function isActive()
65
+ {
66
+ return Mage::getStoreConfig('tiramizoo_config/api_config/is_active');
67
+ }
68
+
69
+ /**
70
+ * Get abailable shipping rates
71
+ *
72
+ * @return array
73
+ */
74
+ public function getAvailableShippingRates()
75
+ {
76
+ return $this->_shippingRates;
77
+ }
78
+
79
+ /**
80
+ * Match postal code with service area coverage. Returns Api token
81
+ *
82
+ * @param string $code Postal code
83
+ * @return mixed
84
+ */
85
+ public function getApiTokenByPostalCode($code)
86
+ {
87
+ $apiToken = null;
88
+ for ($i = 1; $i <= 10; $i++) {
89
+ $areas = Mage::getStoreConfig('tiramizoo_config/tiramizoo_location_'.$i.'/api_service_areas');
90
+ $key = Mage::getStoreConfig('tiramizoo_config/tiramizoo_location_'.$i.'/api_key');
91
+ if ($areas && $key) {
92
+ $areas = json_decode($areas, true);
93
+ if (isset($areas['postal_codes']) && is_array($areas['postal_codes'])) {
94
+ if (in_array($code, $areas['postal_codes'])) {
95
+ $apiToken = $key;
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ return $apiToken;
102
+ }
103
+ }
app/code/community/Tiramizoo/Shipping/Helper/Package.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizohelper Package
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Helper_Package extends Mage_Core_Helper_Abstract
24
+ {
25
+
26
+ /**
27
+ * Check if dimensions not exceed by package size limit
28
+ *
29
+ * @param array $dimensions
30
+ * @param array $packageSizes
31
+ * @return boolean
32
+ */
33
+ public function checkDimensions($dimensions, $packageSizes)
34
+ {
35
+ // Biggest package
36
+ $packageSizes = end($packageSizes);
37
+
38
+ $return = true;
39
+
40
+ if (
41
+ (floatval($dimensions['size']) > floatval($packageSizes['size'])) ||
42
+ (floatval($dimensions['weight']) > floatval($packageSizes['max_weight']))
43
+ ) {
44
+ $return = false;
45
+ }
46
+
47
+ Mage::getModel('tiramizoo/debug')->log('packageSizes: ' . var_export(array(
48
+ $return,
49
+ $packageSizes
50
+ ), true));
51
+
52
+ return $return;
53
+ }
54
+
55
+ }
app/code/community/Tiramizoo/Shipping/Model/Api.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ include_once 'Tiramizoo/TiramizooApi.php';
17
+
18
+ /**
19
+ * Api model
20
+ *
21
+ * @category module
22
+ * @package Tiramizoo_Shipping
23
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
24
+ */
25
+ class Tiramizoo_Shipping_Model_Api extends TiramizooApi
26
+ {
27
+
28
+ protected $_apiToken = null;
29
+
30
+ /**
31
+ * Array of remote configuration used for lazy loading
32
+ *
33
+ * @var mixed
34
+ */
35
+ protected $_remoteConfiguration = null;
36
+
37
+ /**
38
+ * Create the API object with API token and url
39
+ * executes parent::_construct()
40
+ *
41
+ * @extend TiramizooApi::_construct()
42
+ *
43
+ * @param Array $args
44
+ *
45
+ * @return null
46
+ */
47
+ public function __construct($args = array())
48
+ {
49
+ if (isset($args['api_token'])) {
50
+ $this->_apiToken = $args['api_token'];
51
+ } else {
52
+ $this->_apiToken = null;
53
+ }
54
+
55
+ $tiramizooApiUrl = Mage::getStoreConfig('tiramizoo_config/api_config/api_url');
56
+
57
+ parent::__construct($tiramizooApiUrl, $this->_apiToken);
58
+ }
59
+
60
+ /**
61
+ * Send order to the API
62
+ *
63
+ * @param mixed $data pickup, delivery and items data
64
+ *
65
+ * @return mixed Array with status code of request and response data
66
+ */
67
+ public function sendOrder($data)
68
+ {
69
+ $result = null;
70
+ $this->request('orders', $data, $result);
71
+ return $result;
72
+ }
73
+
74
+ /**
75
+ * Get remote configuration
76
+ *
77
+ * @throws oxTiramizoo_ApiException if status not equal 200
78
+ *
79
+ * @return mixed Array with status code of request and response data
80
+ */
81
+ public function getRemoteConfiguration()
82
+ {
83
+ $data = array();
84
+
85
+ if ($this->_remoteConfiguration === null) {
86
+ $result = null;
87
+ $this->requestGet('configuration', $data, $this->_remoteConfiguration);
88
+ }
89
+
90
+ if ($this->_remoteConfiguration['http_status'] != 200) {
91
+ throw new Exception("Can't connect to Tiramizoo API");
92
+ }
93
+
94
+ return $this->_remoteConfiguration;
95
+ }
96
+
97
+ /**
98
+ * Get service areas
99
+ *
100
+ * @param string $postalCode postal code
101
+ * @param string $rangeDates range dates
102
+ *
103
+ * @return mixed Array with status code of request and response data
104
+ */
105
+ public function getAvailableServiceAreas($postalCode, $rangeDates = array())
106
+ {
107
+ $response = null;
108
+ $this->requestGet('service_areas/' . $postalCode, $rangeDates, $response);
109
+
110
+ return $response;
111
+ }
112
+
113
+ }
app/code/community/Tiramizoo/Shipping/Model/Attributes.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo shipping attributes
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Attributes
24
+ {
25
+
26
+ /**
27
+ * Get product eav attributes
28
+ *
29
+ * @return array
30
+ */
31
+ public function getProductEavAttributes()
32
+ {
33
+ $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
34
+ ->getItems();
35
+
36
+ $attributesArray = array(array('label' => Mage::helper('tiramizoo_shipping')->__('-- select one --')));
37
+
38
+ foreach ($attributes as $attribute)
39
+ {
40
+ $attributesArray[$attribute->getAttributecode()] = array(
41
+ 'label' => $attribute->getFrontendLabel() ? $attribute->getFrontendLabel() : $attribute->getAttributecode(),
42
+ 'value' => $attribute->getAttributecode(),
43
+ );
44
+ }
45
+
46
+ return $attributesArray;
47
+ }
48
+
49
+ /**
50
+ * Convert to array
51
+ *
52
+ * @return array
53
+ */
54
+ public function toOptionArray()
55
+ {
56
+ return $this->getProductEavAttributes();
57
+ }
58
+
59
+ }
app/code/community/Tiramizoo/Shipping/Model/Carrier/Tiramizoo.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo shipping carrier
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Carrier_Tiramizoo extends Mage_Shipping_Model_Carrier_Abstract
24
+ {
25
+ /**
26
+ * unique internal shipping method identifier
27
+ *
28
+ * @var string [a-z0-9_]
29
+ */
30
+ protected $_code = 'tiramizoo';
31
+
32
+ /**
33
+ * Collect rates for this shipping method based on information in $request
34
+ *
35
+ * @param Mage_Shipping_Model_Rate_Request $data
36
+ * @return Mage_Shipping_Model_Rate_Result
37
+ */
38
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
39
+ {
40
+ Mage::getModel('tiramizoo/debug')->log('-------------------------------');
41
+ Mage::getModel('tiramizoo/debug')->log('[START] Collecting rates');
42
+
43
+ // skip for multishipping
44
+ if (Mage::app()->getRequest()->getControllerName() === 'multishipping')
45
+ return false;
46
+
47
+ // skip if not enabled
48
+ if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active'))
49
+ return false;
50
+
51
+ // If Tiramizoo Shipping is active
52
+ if (Mage::helper('tiramizoo_shipping/data')->isActive()) {
53
+
54
+ $rates = Mage::helper('tiramizoo_shipping/data')->getAvailableShippingRates();
55
+
56
+ $price = array();
57
+ $amounts = array();
58
+ // Clear session values
59
+ foreach($rates as $rate) {
60
+ Mage::getSingleton('checkout/session')->unsetData('tiramizoo_'.$rate.'_time_window');
61
+
62
+ $amounts[$rate] = Mage::getStoreConfig('carriers/'.$this->_code.'/'.$rate.'_price');
63
+ $price[$rate] = &$amounts[$rate];
64
+ }
65
+ Mage::dispatchEvent('tiramizoo_shipping_modify_rates_price', $price);
66
+
67
+ // this object will be returned as result of this method
68
+ // containing all the shipping rates of this method
69
+ $result = Mage::getModel('shipping/rate_result');
70
+
71
+ // get Post Code from Shipping Address
72
+ $postCode = $request->getDestPostcode();
73
+ $apiToken = Mage::helper('tiramizoo_shipping/data')->getApiTokenByPostalCode($postCode);
74
+ if ($apiToken) {
75
+ $retailLocation = Mage::getModel('tiramizoo/retaillocation', array('api_token' => $apiToken));
76
+ Mage::getSingleton('checkout/session')->setData('tiramizoo_api_token', $apiToken);
77
+ }
78
+
79
+ if ($retailLocation) {
80
+ // $rates is an array that we have
81
+ foreach ($rates as $rate) {
82
+
83
+ $rateModel = Mage::getModel('tiramizoo/delivery_type_' . $rate, $retailLocation);
84
+
85
+ if ($rateModel->isAvailable()) {
86
+
87
+ $timeWindow = $rateModel->getDefaultTimeWindow();
88
+
89
+ if ($timeWindow instanceof Tiramizoo_Shipping_Model_Time_Window) {
90
+
91
+ Mage::getSingleton('checkout/session')->setData('tiramizoo_'.$rate.'_time_window', $timeWindow);
92
+
93
+ $rateData = array(
94
+ 'code' => $rate,
95
+ // @todo: Title
96
+ 'title' => $rateModel->getName() .' '. $timeWindow->getDeliveryHoursFormated(),
97
+ 'amount' => $amounts[$rate],
98
+ );
99
+
100
+ // create new instance of method rate
101
+ $method = Mage::getModel('shipping/rate_result_method');
102
+
103
+ // record carrier information
104
+ $method->setCarrier($this->_code);
105
+ $method->setCarrierTitle(Mage::getStoreConfig('carriers/'.$this->_code.'/title'));
106
+
107
+ // record method information
108
+ $method->setMethod($rateData['code']);
109
+ $method->setMethodTitle($rateData['title']);
110
+
111
+ // rate cost is optional property to record how much it costs to vendor to ship
112
+ $method->setCost($rateData['amount']);
113
+
114
+ $method->setPrice($rateData['amount']);
115
+
116
+ // add this rate to the result
117
+ $result->append($method);
118
+ }
119
+ }
120
+ }
121
+ }
122
+ } else {
123
+ Mage::getModel('tiramizoo/debug')->log('Tiramizoo Shipping is not active');
124
+ }
125
+
126
+ Mage::getModel('tiramizoo/debug')->log('[END] Collecting rates');
127
+ Mage::getModel('tiramizoo/debug')->log('-------------------------------');
128
+
129
+
130
+ return $result;
131
+ }
132
+
133
+ /**
134
+ * This method is used when viewing / listing Shipping Methods with Codes programmatically
135
+ *
136
+ * @return array
137
+ */
138
+ public function getAllowedMethods() {
139
+ return array($this->_code => $this->getConfigData('name'));
140
+ }
141
+ }
app/code/community/Tiramizoo/Shipping/Model/Cart.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo shipping cart
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Cart
24
+ {
25
+ /**
26
+ * Check cart if is available to tiramizoo
27
+ *
28
+ * @param array $packageSizes
29
+ * @return bool
30
+ */
31
+ public function checkCart($packageSizes = array())
32
+ {
33
+ $cartItems = $this->getQuoteItems();
34
+
35
+ $return = true;
36
+
37
+ foreach ($cartItems as $item) {
38
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
39
+ $tiramizooProduct = Mage::getModel('tiramizoo/product', $product);
40
+ $dimensions = $tiramizooProduct->getDimensions();
41
+ $isAvailable = $tiramizooProduct->isAvailable();
42
+
43
+ $fit = Mage::helper('tiramizoo_shipping/package')->checkDimensions($dimensions, $packageSizes);
44
+
45
+ if (!$isAvailable || !$fit) {
46
+ $return = false;
47
+ }
48
+ }
49
+
50
+ if (count($cartItems) == 0) {
51
+ $return = false;
52
+ }
53
+
54
+ return $return;
55
+ }
56
+
57
+ /**
58
+ * Returns quote items
59
+ * @return array
60
+ */
61
+ public function getQuoteItems()
62
+ {
63
+ if (Mage::app()->getStore()->isAdmin()) {
64
+ return Mage::getSingleton('adminhtml/session_quote')->getQuote()->getAllItems();
65
+ } else {
66
+ return Mage::getModel('checkout/cart')->getQuote()->getAllItems();
67
+ }
68
+ }
69
+ }
70
+
app/code/community/Tiramizoo/Shipping/Model/Category.php ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo category model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Category
24
+ {
25
+ /**
26
+ * Attributes parent category data
27
+ *
28
+ * @var mixed
29
+ */
30
+ protected $_data = null;
31
+
32
+ /**
33
+ * Tirmiazoo product attributes model
34
+ *
35
+ * @var Tiramizoo_Shipping_Model_Product_Attributes
36
+ */
37
+ protected $_attributes = array();
38
+
39
+ /**
40
+ * Category model
41
+ *
42
+ * @var Mage_Catalog_Model_Category
43
+ */
44
+ protected $_category = null;
45
+
46
+ /**
47
+ * Construct. Initialize model
48
+ *
49
+ * @param Mage_Catalog_Model_Category $category
50
+ */
51
+ public function __construct(Mage_Catalog_Model_Category $category)
52
+ {
53
+ $this->_category = $category;
54
+ }
55
+
56
+ /**
57
+ * Initialize and returns tirmiazoo category attributes model
58
+ *
59
+ * @param Mage_Catalog_Model_Category $category
60
+ * @return Tiramizoo_Shipping_Model_Product_Attributes
61
+ */
62
+ public function getAttributes(Mage_Catalog_Model_Category $category)
63
+ {
64
+ $id = $category->getId();
65
+ if (!isset($this->_attributes[$id])) {
66
+ $this->_attributes[$id] = Mage::getModel('tiramizoo/category_attributes', $category);
67
+ }
68
+ return $this->_attributes[$id];
69
+ }
70
+
71
+ /**
72
+ * Initialize and returns parent category data
73
+ *
74
+ * @return [type] [description]
75
+ */
76
+ private function getParent()
77
+ {
78
+ if (!$this->_data) {
79
+ $this->_data = $this->_getParent($this->_category);
80
+ }
81
+ return $this->_data;
82
+ }
83
+
84
+ /**
85
+ * Returns attribute data from parent category
86
+ *
87
+ * @param Mage_Catalog_Model_Category $category
88
+ * @return mixed
89
+ */
90
+ private function _getParent(Mage_Catalog_Model_Category $category)
91
+ {
92
+ $return = array();
93
+ $categoryData = array('dimensions' => null, 'enable' => null, 'packed' => null);
94
+ $attributes = $this->getAttributes($category);
95
+
96
+ if ($tmp = $attributes->getDimensions()) {
97
+ $categoryData['dimensions'] = $tmp;
98
+ }
99
+
100
+ $categoryData['enable'] = $attributes->getEnable();
101
+ $categoryData['packed'] = $attributes->getPackedIndividually();
102
+
103
+ $return[$category->getId()] = $categoryData;
104
+
105
+ if ($id = $category->getParentId()) {
106
+ $category = Mage::getModel('catalog/category')->load($id);
107
+
108
+ $data = $this->_getParent($category);
109
+
110
+ foreach ($data as $id => $catData) {
111
+ $return[$id] = $catData;
112
+ }
113
+ }
114
+
115
+ return $return;
116
+ }
117
+
118
+ /**
119
+ * Get effective dimensions for all products in this category
120
+ *
121
+ * @return array
122
+ */
123
+ public function getDimensions()
124
+ {
125
+ $return = false;
126
+ $data = $this->getParent();
127
+ $maxSize = array('id' => 0, 'value' => 0);
128
+
129
+ $dimensions = array();
130
+ foreach ($data as $id => $catData) {
131
+ if ($tmp = $catData['dimensions']) {
132
+ $dimensions[$id] = $tmp;
133
+ if ($maxSize['value'] < $tmp['size']) {
134
+ $maxSize['value'] = $tmp['size'];
135
+ $maxSize['id'] = $id;
136
+ }
137
+ }
138
+ }
139
+
140
+ if (count($dimensions) == 0) {
141
+ $return = Mage::getModel('tiramizoo/default')->getDimensions();
142
+ } else {
143
+ $return = $dimensions[$maxSize['id']];
144
+ }
145
+
146
+ return $return;
147
+ }
148
+
149
+ /**
150
+ * Get effective value of is packed individually attribute for all products in this category
151
+ *
152
+ * @return array
153
+ */
154
+ public function isPackedIndividually()
155
+ {
156
+ $data = $this->getParent();
157
+
158
+ $return = null;
159
+
160
+ foreach ($data as $id => $catData) {
161
+ if ($catData['packed'] == -1) {
162
+ $return = false;
163
+ break;
164
+ }
165
+
166
+ if ($catData['packed'] == 1) {
167
+ $return = true;
168
+ }
169
+ }
170
+
171
+ return $return;
172
+ }
173
+
174
+ /**
175
+ * Get disable ids of category
176
+ *
177
+ * @return array
178
+ */
179
+ public function getDisableIds()
180
+ {
181
+ $data = $this->getParent();
182
+
183
+ $disableIds = array();
184
+ foreach ($data as $id => $catData) {
185
+ if ($catData['enable'] == -1) {
186
+ $disableIds[] = $id;
187
+ }
188
+ }
189
+
190
+ return $disableIds;
191
+ }
192
+ }
app/code/community/Tiramizoo/Shipping/Model/Category/Attributes.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo category attributes
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Category_Attributes
24
+ {
25
+ /**
26
+ * Category
27
+ *
28
+ * @var Mage_Catalog_Model_Category
29
+ */
30
+ protected $_category = null;
31
+
32
+ /**
33
+ * Initialize
34
+ *
35
+ * @param Mage_Catalog_Model_Category $category
36
+ */
37
+ public function __construct(Mage_Catalog_Model_Category $category)
38
+ {
39
+ $this->_category = $category;
40
+ }
41
+
42
+ /**
43
+ * Get category dimensions
44
+ *
45
+ * @return mixed
46
+ */
47
+ public function getDimensions()
48
+ {
49
+ $result = array();
50
+
51
+ if (
52
+ ($result['width'] = $this->_category->getCategoryProductsWidth()) &&
53
+ ($result['weight'] = $this->_category->getCategoryProductsWeight()) &&
54
+ ($result['height'] = $this->_category->getCategoryProductsHeight()) &&
55
+ ($result['length'] = $this->_category->getCategoryProductsLength())
56
+ ) {
57
+ $result['destination_type'] = 'category';
58
+ $result['destination_id'] = $this->_category->getId();
59
+
60
+ Mage::dispatchEvent('tiramizoo_shipping_convert_category_dimensions', array(
61
+ 'weight' => &$result['weight'],
62
+ 'width' => &$result['width'],
63
+ 'height' => &$result['height'],
64
+ 'length' => &$result['length'],
65
+ ));
66
+
67
+ $dim = array($result['width'], $result['height'], $result['length']);
68
+ $result['size'] = min($dim) + max($dim);
69
+ } else {
70
+ $result = false;
71
+ }
72
+
73
+ return $result;
74
+ }
75
+
76
+ /**
77
+ * Check if category is enable
78
+ *
79
+ * @return boolean
80
+ */
81
+ public function isEnable()
82
+ {
83
+ // @todo
84
+ return (bool) $this->_category->getData('tiramizoo_category_enable');
85
+ }
86
+
87
+ /**
88
+ * Get category's is enable property
89
+ *
90
+ * @return boolean
91
+ */
92
+ public function getEnable()
93
+ {
94
+ return (int) $this->_category->getData('tiramizoo_category_enable');
95
+ }
96
+
97
+ /**
98
+ * Get category's is packed individually property
99
+ *
100
+ * @return boolean
101
+ */
102
+ public function getPackedIndividually()
103
+ {
104
+ return (int) $this->_category->getData('trmz_cat_packed_individually');
105
+ }
106
+ }
app/code/community/Tiramizoo/Shipping/Model/Config/Apiurl.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Option values for Apiurl select
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Config_Apiurl
24
+ {
25
+ /**
26
+ * Get options for captcha mode selection field
27
+ *
28
+ * @return array
29
+ */
30
+ public function toOptionArray()
31
+ {
32
+ return array(
33
+ array(
34
+ 'label' => 'Sandbox - https://sandbox.tiramizoo.com/api/v1',
35
+ 'value' => 'https://sandbox.tiramizoo.com/api/v1'
36
+ ),
37
+ array(
38
+ 'label' => 'Production - https://www.tiramizoo.com/api/v1',
39
+ 'value' => 'https://www.tiramizoo.com/api/v1'
40
+ ),
41
+ );
42
+ }
43
+ }
44
+
45
+
app/code/community/Tiramizoo/Shipping/Model/Config/Packingstrategy.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Option values for Packingstrategy select
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Config_Packingstrategy
24
+ {
25
+ /**
26
+ * Get options for captcha mode selection field
27
+ *
28
+ * @return array
29
+ */
30
+ public function toOptionArray()
31
+ {
32
+ return array(
33
+ array(
34
+ 'label' => Mage::helper('tiramizoo_shipping')->__('All products have individual dimensions'),
35
+ 'value' => 'individual'
36
+ ),
37
+ array(
38
+ 'label' => Mage::helper('tiramizoo_shipping')->__('Specific dimensions of packages (specified from tiramizoo dashboard)'),
39
+ 'value' => 'packages'
40
+ ),
41
+ array(
42
+ 'label' => Mage::helper('tiramizoo_shipping')->__('All products should fit to one package'),
43
+ 'value' => 'onepackage'
44
+ ),
45
+ );
46
+ }
47
+ }
48
+
49
+
app/code/community/Tiramizoo/Shipping/Model/Date.php ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Date object
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Date
24
+ {
25
+ /**
26
+ * Date as a string
27
+ *
28
+ * @var string
29
+ */
30
+ protected $_date;
31
+
32
+ /**
33
+ * Current "Real" time, all of comparisions based rely on this date
34
+ *
35
+ * @var string
36
+ */
37
+ protected static $_currentTime = 'now';
38
+
39
+ /**
40
+ * Default date format
41
+ *
42
+ * @var string
43
+ */
44
+ protected static $_format = 'Y-m-d H:i:s';
45
+
46
+ /**
47
+ * Class constructor. Convert and assign date from string.
48
+ *
49
+ * @param string $date string
50
+ *
51
+ * @return null
52
+ */
53
+ public function __construct($date = null)
54
+ {
55
+ if ($date) {
56
+ $this->_date = Mage::getModel('core/date')->timestamp(strtotime($date));
57
+ } else {
58
+ $this->_date = Mage::getModel('core/date')->timestamp(strtotime(self::$_currentTime));
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Change current date time for unit tests.
64
+ *
65
+ * @param string $currentTime real date time
66
+ *
67
+ * @return null
68
+ */
69
+ public static function changeCurrentTime($currentTime = 'now')
70
+ {
71
+ self::$_currentTime = $currentTime;
72
+ }
73
+
74
+ /**
75
+ * Reset current date time to real.
76
+ *
77
+ * @return null
78
+ */
79
+ public static function resetCurrentTime()
80
+ {
81
+ self::$_currentTime = 'now';
82
+ }
83
+
84
+ /**
85
+ * Retrieve date in specified format.
86
+ *
87
+ * @param string $format date format
88
+ *
89
+ * @return string
90
+ */
91
+ public static function date($format = null)
92
+ {
93
+ $date = new Tiramizoo_Shipping_Model_Date();
94
+ return $date->get($format);
95
+ }
96
+
97
+ /**
98
+ * Retrieve date in specified format.
99
+ *
100
+ * @param string $format date format
101
+ *
102
+ * @return string
103
+ */
104
+ public function get($format = null)
105
+ {
106
+ $format = $format ? $format : self::$_format;
107
+ return date($format, $this->_date);
108
+ }
109
+
110
+ /**
111
+ * Retrieve date in REST API format.
112
+ *
113
+ * @return string
114
+ */
115
+ public function getForRestApi()
116
+ {
117
+ $dateForApi = new Tiramizoo_Shipping_Model_Date($this->get());
118
+ $sign = strpos($dateForApi->get('P'), '+') == 0 ? '-' : '+';
119
+
120
+ $dateForApi->modify($sign . (intval($dateForApi->get('Z')) / 3600) . ' hours');
121
+
122
+ return $dateForApi->get('Y-m-d\TH:i:s\Z');
123
+ }
124
+
125
+ /**
126
+ * Returns timestamp.
127
+ *
128
+ * @return string
129
+ */
130
+ public function getTimestamp()
131
+ {
132
+ return $this->_date;
133
+ }
134
+
135
+ /**
136
+ * Check if is today.
137
+ *
138
+ * @return bool
139
+ */
140
+ public function isToday()
141
+ {
142
+ $today = new Tiramizoo_Shipping_Model_Date();
143
+ return $this->get('Y-m-d') == $today->get('Y-m-d');
144
+ }
145
+
146
+ /**
147
+ * Check if is today.
148
+ *
149
+ * @return bool
150
+ */
151
+ public function isTomorrow()
152
+ {
153
+ $tomorrow = new Tiramizoo_Shipping_Model_Date('+1 days');
154
+ return $this->get('Y-m-d') == $tomorrow->get('Y-m-d');
155
+ }
156
+
157
+ /**
158
+ * Check if is time is equal to passed.
159
+ *
160
+ * @param string $time time in format (H, H:i, H:i:s)
161
+ *
162
+ * @return bool
163
+ */
164
+ public function isOnTime($time)
165
+ {
166
+ $timeFormats = array('H', 'H:i', 'H:i:s');
167
+ $format = isset($timeFormats[substr_count($time, ':')])
168
+ ? $timeFormats[substr_count($time, ':')]
169
+ : 'H:i:s';
170
+
171
+ return $this->get($format) == $time;
172
+ }
173
+
174
+ /**
175
+ * Modiy current time with interval.
176
+ *
177
+ * @return Tiramizoo_Shipping_Model_Date
178
+ */
179
+ public function modify($modify)
180
+ {
181
+ $this->_date = strtotime($modify, $this->_date);
182
+ return $this;
183
+ }
184
+
185
+ /**
186
+ * Get date in output context
187
+ *
188
+ * @return string
189
+ */
190
+ public function __toString()
191
+ {
192
+ return $this->get();
193
+ }
194
+
195
+ /**
196
+ * Check if date is equal to.
197
+ *
198
+ * @param Tiramizoo_Shipping_Model_Date $date comparision date
199
+ *
200
+ * @return bool
201
+ */
202
+ public function isEqualTo(Tiramizoo_Shipping_Model_Date $date)
203
+ {
204
+ return $this->getTimestamp() == $date->getTimestamp();
205
+ }
206
+
207
+ /**
208
+ * Check if date is lather than.
209
+ *
210
+ * @param Tiramizoo_Shipping_Model_Date $date comparision date
211
+ *
212
+ * @return bool
213
+ */
214
+ public function isLaterThan(Tiramizoo_Shipping_Model_Date $date)
215
+ {
216
+ return $this->getTimestamp() > $date->getTimestamp();
217
+ }
218
+
219
+ /**
220
+ * Check if date is equal to.
221
+ *
222
+ * @param Tiramizoo_Shipping_Model_Date $date comparision date
223
+ *
224
+ * @return bool
225
+ */
226
+ public function isLaterOrEqualTo(Tiramizoo_Shipping_Model_Date $date)
227
+ {
228
+ return $this->isLaterThan($date) || $date->isEqualTo($date);
229
+ }
230
+
231
+ /**
232
+ * Check if date is earlier.
233
+ *
234
+ * @param Tiramizoo_Shipping_Model_Date $date comparision date
235
+ *
236
+ * @return bool
237
+ */
238
+ public function isEarlierThan(Tiramizoo_Shipping_Model_Date $date)
239
+ {
240
+ return $this->getTimestamp() < $date->getTimestamp();
241
+ }
242
+
243
+ /**
244
+ * Check if date is earlier or equal to.
245
+ *
246
+ * @param Tiramizoo_Shipping_Model_Date $date comparision date
247
+ *
248
+ * @return bool
249
+ */
250
+ public function isEarlierOrEqualTo(Tiramizoo_Shipping_Model_Date $date)
251
+ {
252
+ return $this->isEarlierThan($date) || $date->isEqualTo($date);
253
+ }
254
+ }
app/code/community/Tiramizoo/Shipping/Model/Debug.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Debug object. Save info to logs
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Debug
24
+ {
25
+ /**
26
+ * Log message to file
27
+ *
28
+ * @param string $message Log message
29
+ * @return null
30
+ */
31
+ public function log($message)
32
+ {
33
+ $debugLoggingIsEnabled = Mage::getStoreConfig('tiramizoo_config/advanced/debug_log', Mage::app()->getStore());
34
+
35
+ if ($debugLoggingIsEnabled) {
36
+ Mage::log($message, NULL, 'tiramizoo_debug.log');
37
+ }
38
+ }
39
+ }
app/code/community/Tiramizoo/Shipping/Model/Default.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo shipping defaults
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Default
24
+ {
25
+
26
+ /**
27
+ * Return defaults dimesnions of product
28
+ *
29
+ * @return mixed
30
+ */
31
+ public function getDimensions()
32
+ {
33
+ $result = array();
34
+
35
+ if (
36
+ ($result['weight'] = Mage::getStoreConfig('tiramizoo_config/api_config/product_weight')) &&
37
+ ($result['width'] = Mage::getStoreConfig('tiramizoo_config/api_config/product_width')) &&
38
+ ($result['height'] = Mage::getStoreConfig('tiramizoo_config/api_config/product_height')) &&
39
+ ($result['length'] = Mage::getStoreConfig('tiramizoo_config/api_config/product_length'))
40
+ ) {
41
+ $dim = array($result['width'], $result['height'], $result['length']);
42
+ $result['size'] = min($dim) + max($dim);
43
+ $result['destination_type'] = 'config';
44
+ $result['destination_id'] = null;
45
+ } else {
46
+ $result = false;
47
+ }
48
+
49
+ return $result;
50
+ }
51
+ }
app/code/community/Tiramizoo/Shipping/Model/Delivery/Type.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Delivery type abstract
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ abstract class Tiramizoo_Shipping_Model_Delivery_Type
24
+ {
25
+ /**
26
+ * Delivery type name
27
+ *
28
+ * @var string
29
+ */
30
+ protected $_type = null;
31
+
32
+ /**
33
+ * Array od available time windows in this type
34
+ *
35
+ * @var array
36
+ */
37
+ protected $_timeWindows = null;
38
+
39
+ /**
40
+ * Instance of Retail location object
41
+ *
42
+ * @var Tiramizoo_Shipping_Model_Retaillocation
43
+ */
44
+ protected $_retailLocation = null;
45
+
46
+ /**
47
+ * Class constructor, assign retail location object and available time windows.
48
+ *
49
+ * @param Tiramizoo_Shipping_Model_Retaillocation $retailLocation Retail Location object
50
+ */
51
+ public function __construct(Tiramizoo_Shipping_Model_Retaillocation $retailLocation)
52
+ {
53
+ $this->_timeWindows = $retailLocation->getAvailableTimeWindows();
54
+ $this->_retailLocation = $retailLocation;
55
+ }
56
+
57
+ /**
58
+ * Returns Retail location object
59
+ *
60
+ * @return Tiramizoo_Shipping_Model_Retaillocation
61
+ */
62
+ public function getRetailLocation()
63
+ {
64
+ return $this->_retailLocation;
65
+ }
66
+
67
+ /**
68
+ * Returns type
69
+ *
70
+ * @return string
71
+ */
72
+ public function getType()
73
+ {
74
+ return $this->_type;
75
+ }
76
+
77
+ /**
78
+ * Returns Tiramizoo delivery name
79
+ *
80
+ * @return string
81
+ */
82
+ public function getName()
83
+ {
84
+ // @todo: translate
85
+ return $this->_type;
86
+ }
87
+
88
+ /**
89
+ * Returns available time windows
90
+ *
91
+ * @return array
92
+ */
93
+ public function getTimeWindows()
94
+ {
95
+ return $this->_timeWindows;
96
+ }
97
+
98
+ /**
99
+ * Returns default time window
100
+ *
101
+ * @return Tiramizoo_Shipping_Model_Time_Window | null
102
+ */
103
+ public function getDefaultTimeWindow()
104
+ {
105
+ $return = null;
106
+
107
+ if (count($this->_timeWindows)) {
108
+ $keys = array_keys($this->_timeWindows);
109
+ $return = Mage::getModel('tiramizoo/time_window', $this->_timeWindows[array_shift($keys)]);
110
+ }
111
+
112
+ return $return;
113
+ }
114
+
115
+ /**
116
+ * Basic checks if Tiramizoo delivery is available
117
+ *
118
+ * @return bool
119
+ */
120
+ public function isAvailable()
121
+ {
122
+ $pickupContact = $this->getRetailLocation()->getParam('pickup_contact');
123
+ $packageSizes = $this->getRetailLocation()->getParam('package_sizes');
124
+
125
+
126
+ $pickupContact = array_merge(
127
+ array(
128
+ 'address_line' => null,
129
+ 'postal_code' => null,
130
+ 'country_code' => null,
131
+ 'name' => null,
132
+ 'phone_number' => null
133
+ ),
134
+ (array) $pickupContact
135
+ );
136
+
137
+ $return = true;
138
+
139
+ if (!($pickupContact['address_line'])
140
+ || !$pickupContact['postal_code']
141
+ || !$pickupContact['country_code']
142
+ || !$pickupContact['name']
143
+ || !$pickupContact['phone_number']
144
+ ) {
145
+ Mage::getModel('tiramizoo/debug')->log('Tiramizoo is not available. Pickup contact is not exists.');
146
+ $return = false;
147
+ }
148
+
149
+ if (!Mage::getModel('tiramizoo/cart')->checkCart($packageSizes)) {
150
+ Mage::getModel('tiramizoo/debug')->log('Tiramizoo is not available. Items in cart are not valid');
151
+ $return = false;
152
+ }
153
+
154
+ return $return;
155
+ }
156
+
157
+ /**
158
+ * Checks if time window is in available time windows
159
+ *
160
+ * @return bool
161
+ */
162
+ public function hasTimeWindow($timeWindow)
163
+ {
164
+ return false;
165
+ }
166
+ }
app/code/community/Tiramizoo/Shipping/Model/Delivery/Type/Evening.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Delivery type evening
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Delivery_Type_Evening extends Tiramizoo_Shipping_Model_Delivery_Type
24
+ {
25
+ /**
26
+ * Delivery type name
27
+ *
28
+ * @var string
29
+ */
30
+ protected $_type = 'evening';
31
+
32
+ /**
33
+ * Checks if is available depends on current time
34
+ *
35
+ * @extend Tiramizoo_Shipping_Model_Delivery_Type::isAvailable()
36
+ *
37
+ * @return bool
38
+ */
39
+ public function isAvailable()
40
+ {
41
+ Mage::getModel('tiramizoo/debug')->log('Start validating Tiramizoo rate evening');
42
+
43
+ $return = true;
44
+
45
+ if (parent::isAvailable() == false) {
46
+ $return = false;
47
+ } else{
48
+ $timeWindow = $this->getEveningTimeWindow();
49
+
50
+ if ($timeWindow === null) {
51
+ Mage::getModel('tiramizoo/debug')->log('There are no valid time window');
52
+ $return = false;
53
+ }
54
+ }
55
+
56
+ Mage::getModel('tiramizoo/debug')->log('End validating Tiramizoo rate evening');
57
+
58
+ return $return;
59
+ }
60
+
61
+ /**
62
+ * Check if preset hours exists
63
+ *
64
+ * @return bool
65
+ */
66
+ public function hasPresetHours()
67
+ {
68
+ $presetHours = $this->getPresetHours();
69
+
70
+ return is_array($presetHours) && count($presetHours);
71
+ }
72
+
73
+ /**
74
+ * Returns time window preset
75
+ *
76
+ * @return string
77
+ */
78
+ public function getPresetHours()
79
+ {
80
+
81
+ return $this->getRetailLocation()->getParam('time_window_preset');
82
+ }
83
+
84
+ /**
85
+ * Retrieve first next Time window if is today and preset hours are equal
86
+ *
87
+ * @return Tiramizoo_Shipping_Model_Time_Window | null
88
+ */
89
+ public function getEveningTimeWindow()
90
+ {
91
+ $return = null;
92
+
93
+ if ($this->hasPresetHours()) {
94
+ $presetHours = $this->getPresetHours();
95
+
96
+ foreach ($this->_timeWindows as $_timeWindow)
97
+ {
98
+ $timeWindow = Mage::getModel('tiramizoo/time_window', $_timeWindow);
99
+
100
+ if ($timeWindow->isValid()
101
+ && $timeWindow->hasHours($presetHours)
102
+ && $timeWindow->isToday()
103
+ ) {
104
+ $return = $timeWindow;
105
+ break;
106
+ }
107
+ }
108
+ }
109
+
110
+ return $return;
111
+ }
112
+
113
+ /**
114
+ * Returns default (evening) time window
115
+ *
116
+ * @return Tiramizoo_Shipping_Model_Time_Window | null
117
+ */
118
+ public function getDefaultTimeWindow()
119
+ {
120
+ return $this->getEveningTimeWindow();
121
+ }
122
+
123
+ /**
124
+ * Checks if time window is in available time windows
125
+ *
126
+ * @return bool
127
+ */
128
+ public function hasTimeWindow($timeWindow)
129
+ {
130
+ $eveningTimeWindow = $this->getEveningTimeWindow();
131
+
132
+ return $eveningTimeWindow->getHash() == $timeWindow;
133
+ }
134
+ }
app/code/community/Tiramizoo/Shipping/Model/Delivery/Type/Immediate.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Delivery type immediate
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Delivery_Type_Immediate extends Tiramizoo_Shipping_Model_Delivery_Type
24
+ {
25
+ /**
26
+ * Delivery type name
27
+ *
28
+ * @var string
29
+ */
30
+ protected $_type = 'immediate';
31
+
32
+ /**
33
+ * Checks if is available depends on configuration and current time
34
+ *
35
+ * @extend Tiramizoo_Shipping_Model_Delivery_Type::isAvailable()
36
+ *
37
+ * @return bool
38
+ */
39
+ public function isAvailable()
40
+ {
41
+ Mage::getModel('tiramizoo/debug')->log('Start validating Tiramizoo rate immediate');
42
+
43
+ $return = true;
44
+
45
+ if (parent::isAvailable() == false) {
46
+ $return = false;
47
+ } elseif (!$this->getRetailLocation()->getParam('immediate_time_window_enabled')) {
48
+ Mage::getModel('tiramizoo/debug')->log('Rate is not enabled');
49
+ $return = false;
50
+ } else {
51
+ $timeWindow = $this->getImmediateTimeWindow();
52
+
53
+ if ($timeWindow === null) {
54
+ Mage::getModel('tiramizoo/debug')->log('There are no valid time window');
55
+ $return = false;
56
+ }
57
+ }
58
+
59
+ Mage::getModel('tiramizoo/debug')->log('End validating Tiramizoo rate immediate');
60
+
61
+ return $return;
62
+ }
63
+
64
+ /**
65
+ * Retrieve first next Time window if is today
66
+ *
67
+ * @return Tiramizoo_Shipping_Model_Time_Window | null
68
+ */
69
+ public function getImmediateTimeWindow()
70
+ {
71
+ $return = null;
72
+
73
+ foreach ($this->_timeWindows as $_timeWindow)
74
+ {
75
+ $timeWindow = Mage::getModel('tiramizoo/time_window', $_timeWindow);
76
+
77
+ if ($timeWindow->isValid() && $timeWindow->isToday()) {
78
+ $return = $timeWindow;
79
+ break;
80
+ }
81
+ }
82
+
83
+ return $return;
84
+ }
85
+
86
+ /**
87
+ * Returns default (immediate) time window
88
+ *
89
+ * @return Tiramizoo_Shipping_Model_Time_Window | null
90
+ */
91
+ public function getDefaultTimeWindow()
92
+ {
93
+ return $this->getImmediateTimeWindow();
94
+ }
95
+
96
+ /**
97
+ * Checks if time window is in available time windows
98
+ *
99
+ * @return bool
100
+ */
101
+ public function hasTimeWindow($hash)
102
+ {
103
+ $immediateTimeWindow = $this->getImmediateTimeWindow();
104
+
105
+ return $immediateTimeWindow->getHash() == $hash;
106
+ }
107
+ }
app/code/community/Tiramizoo/Shipping/Model/Entity/Attribute/Source/Enable.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo order attribute enable source
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Entity_Attribute_Source_Enable extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
24
+ {
25
+ /**
26
+ * Enable options array
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_enableOptions = array();
31
+
32
+ /**
33
+ * Initialize options
34
+ *
35
+ * @return null
36
+ */
37
+ public function __construct()
38
+ {
39
+ $this->_enableOptions = array(
40
+ -1 => Mage::helper('tiramizoo_shipping')->__('Disable'),
41
+ 0 => Mage::helper('tiramizoo_shipping')->__('Inherit'),
42
+ 1 => Mage::helper('tiramizoo_shipping')->__('Enable'),
43
+ );
44
+ }
45
+
46
+ /**
47
+ * Get options
48
+ *
49
+ * @return array
50
+ */
51
+ public function getAllOptions()
52
+ {
53
+ if (!$this->_options) {
54
+ $this->_options = array();
55
+ foreach ($this->_enableOptions as $value => $label) {
56
+ $this->_options[] = array('value' => $value, 'label' => $label);
57
+ }
58
+ }
59
+ return $this->_options;
60
+ }
61
+
62
+ /**
63
+ * Get enable options
64
+ *
65
+ * @return array
66
+ */
67
+ public function getOptions()
68
+ {
69
+ return $this->_enableOptions;
70
+ }
71
+
72
+ /**
73
+ * If key exists in enable options array
74
+ *
75
+ * @return bool
76
+ */
77
+ public function optionExists($value)
78
+ {
79
+ return array_key_exists($value, $this->_enableOptions);
80
+ }
81
+ }
app/code/community/Tiramizoo/Shipping/Model/Entity/Attribute/Source/Packed.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo order attribute is packed individually source
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Entity_Attribute_Source_Packed extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
24
+ {
25
+ /**
26
+ * Packed options array
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_packedOptions = array();
31
+
32
+ /**
33
+ * Initialize options
34
+ *
35
+ * @return null
36
+ */
37
+ public function __construct()
38
+ {
39
+ $this->_packedOptions = array(
40
+ -1 => Mage::helper('tiramizoo_shipping')->__('No'),
41
+ 0 => Mage::helper('tiramizoo_shipping')->__('Inherit'),
42
+ 1 => Mage::helper('tiramizoo_shipping')->__('Yes'),
43
+ );
44
+ }
45
+
46
+ /**
47
+ * Get options
48
+ *
49
+ * @return array
50
+ */
51
+ public function getAllOptions()
52
+ {
53
+ if (!$this->_options) {
54
+ $this->_options = array();
55
+ foreach ($this->_packedOptions as $value => $label) {
56
+ $this->_options[] = array('value' => $value, 'label' => $label);
57
+ }
58
+ }
59
+ return $this->_options;
60
+ }
61
+
62
+ /**
63
+ * Get packed options
64
+ *
65
+ * @return array
66
+ */
67
+ public function getOptions()
68
+ {
69
+ return $this->_packedOptions;
70
+ }
71
+
72
+ /**
73
+ * If key exists in packed options array
74
+ *
75
+ * @return bool
76
+ */
77
+ public function optionExists($value)
78
+ {
79
+ return array_key_exists($value, $this->_packedOptions);
80
+ }
81
+ }
app/code/community/Tiramizoo/Shipping/Model/Mysql4/Order.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Resource model for Tiramizoo order
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Mysql4_Order extends Mage_Core_Model_Mysql4_Abstract
24
+ {
25
+
26
+ /**
27
+ * Consruct
28
+ *
29
+ * @return null
30
+ */
31
+ protected function _construct()
32
+ {
33
+ $this->_init('tiramizoo/order', 'id');
34
+ }
35
+ }
app/code/community/Tiramizoo/Shipping/Model/Mysql4/Order/Collection.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo order collection
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Mysql4_Order_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
24
+ {
25
+ /**
26
+ * Consruct
27
+ *
28
+ * @return null
29
+ */
30
+ protected function _construct()
31
+ {
32
+ $this->_init('tiramizoo/order', 'id');
33
+ }
34
+ }
app/code/community/Tiramizoo/Shipping/Model/Observer.php ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo shipping observer
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Observer
24
+ {
25
+ protected $allowedShippingMethods = array('tiramizoo_immediate', 'tiramizoo_evening');
26
+
27
+ /**
28
+ * Flag to stop observer executing more than once
29
+ *
30
+ * @var static bool
31
+ */
32
+ static protected $_singletonFlag = false;
33
+
34
+ /**
35
+ * Try to send order to API
36
+ *
37
+ * @param Object $event
38
+ * @return null
39
+ */
40
+ public function saveOrderSuccess(Varien_Event_Observer $event)
41
+ {
42
+
43
+ $quote = $event['quote'];
44
+ $order = $event['order'];
45
+
46
+ // Shipping Method Code
47
+ $shipping_method_code = $order->getShippingMethod();
48
+
49
+ $apiToken = Mage::getSingleton('checkout/session')->getData('tiramizoo_api_token');
50
+
51
+ if (in_array($shipping_method_code, $this->allowedShippingMethods) && $apiToken) {
52
+ // ShippingAddress Object
53
+ $orderAddress = $order->getShippingAddress();
54
+ $items = $order->getAllItems();
55
+
56
+ $timeWindow = Mage::getSingleton('checkout/session')->getData($shipping_method_code.'_time_window');
57
+ $retailLocation = Mage::getModel('tiramizoo/retaillocation', array('api_token' => $apiToken));
58
+
59
+ $buildData = Mage::helper('tiramizoo_shipping/build')
60
+ ->setTimeWindow($timeWindow)
61
+ ->setAddress($orderAddress)
62
+ ->setRetailLocation($retailLocation)
63
+ ->setItems($items)
64
+ ->createTiramizooOrderDataObject();
65
+
66
+ $response = Mage::getModel('tiramizoo/api', array('api_token' => $apiToken))
67
+ ->sendOrder($buildData);
68
+
69
+ // Response actions
70
+ Mage::getModel('tiramizoo/response', $response);
71
+
72
+ $trackingUrl = null;
73
+ $status = null;
74
+
75
+ if (isset($response['http_status']) && $response['http_status'] == '201') {
76
+ $trackingUrl = $response['response']->tracking_url;
77
+ $status = isset($response['response']->state) ? $response['response']->state : null;
78
+ }
79
+
80
+
81
+
82
+ $tiramizooOrder = Mage::getModel('tiramizoo/order')->load($quote->getId(), 'quote_id')
83
+ ->setSendAt(time())
84
+ ->setOrderId($order->getId())
85
+ ->setStatus($status)
86
+ ->setTrackingUrl($trackingUrl)
87
+ ->setExternalId($buildData->external_id)
88
+ ->setApiRequest(json_encode($buildData))
89
+ ->setApiResponse(json_encode($response))
90
+ ->save();
91
+ }
92
+
93
+ }
94
+
95
+ /**
96
+ * Save shipping method
97
+ *
98
+ * @param Varien_Event_Observer $event
99
+ * @return null
100
+ */
101
+ public function saveShippingMethod(Varien_Event_Observer $event)
102
+ {
103
+ $request = $event['request'];
104
+ $quote = $event['quote'];
105
+
106
+
107
+ if ($quote) {
108
+ $shipping_method = $request->getParam('shipping_method');
109
+
110
+ // Mage::log('Observer->saveShippingMethod(): ' . json_encode($shipping_method));
111
+ if (in_array($shipping_method, $this->allowedShippingMethods)) {
112
+
113
+ $timeWindowHash = $request->getParam($shipping_method.'_hash');
114
+
115
+ $tiramizooOrder = Mage::getModel('tiramizoo/order')->load($quote->getId(), 'quote_id')
116
+ ->setQuoteId($quote->getId())
117
+ // set time window hash
118
+ ->setTimeWindowHash($timeWindowHash)
119
+ ->save();
120
+
121
+ // Mage::lag('tiramizoo-delivery: ' . $request->getParam('tiramizoo-delivery'));
122
+
123
+ }
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Validate if selected time window is correct
129
+ *
130
+ * @param Varien_Event_Observer $event
131
+ * @return null
132
+ */
133
+ public function saveOrderBefore(Varien_Event_Observer $event)
134
+ {
135
+ $quote = $event['quote'];
136
+ $checkout = $event['checkout'];
137
+ $shippingMethod = $quote->getShippingAddress()->getShippingMethod();
138
+
139
+ $tiramizooOrder = Mage::getModel('tiramizoo/order')->load($quote->getId(), 'quote_id');
140
+
141
+ if ($tiramizooOrder->getId()) {
142
+
143
+ // get time window hash
144
+ $hash = $tiramizooOrder->getTimeWindowHash();
145
+
146
+ $apiToken = Mage::getSingleton('checkout/session')->getData('tiramizoo_api_token');
147
+ if ($apiToken) {
148
+
149
+ $retailLocation = Mage::getModel('tiramizoo/retaillocation', array('api_token' => $apiToken));
150
+ if ($retailLocation) {
151
+
152
+ $rates = Mage::helper('tiramizoo_shipping/data')->getAvailableShippingRates();
153
+ if (isset($rates[$shippingMethod])) {
154
+ $rateModel = Mage::getModel('tiramizoo/delivery_type_'.$rates[$shippingMethod], $retailLocation);
155
+
156
+ if (!$rateModel->hasTimeWindow($hash)) {
157
+ $checkout->setGotoSection('shipping_method');
158
+ $checkout->setUpdateSection('shipping-method');
159
+ throw new Mage_Core_Exception(Mage::helper('tiramizoo_shipping')->__('Tiramizoo time window is expired.'));
160
+ }
161
+ }
162
+
163
+ }
164
+ }
165
+ }
166
+
167
+ }
168
+
169
+ /**
170
+ * Runs afteer saving tiramizoo shipping config
171
+ *
172
+ * @param Varien_Event_Observer $event
173
+ * @return null
174
+ */
175
+ public function changeConfig(Varien_Event_Observer $event)
176
+ {
177
+ $rates = Mage::helper('tiramizoo_shipping/data')->getAvailableShippingRates();
178
+
179
+ $required = array(
180
+ 'tiramizoo_config/api_config/api_url',
181
+ 'tiramizoo_config/api_config/shop_url',
182
+ );
183
+
184
+ if (Mage::helper('tiramizoo_shipping/data')->isActive()) {
185
+
186
+ $requiredValid = true;
187
+ foreach ($required as $value) {
188
+ if (!Mage::getStoreConfig($value)) {
189
+ $requiredValid = false;
190
+ break;
191
+ }
192
+ }
193
+
194
+ $tiramizooShippingMethodValid = true;
195
+ foreach ($rates as $rate) {
196
+ if (!Mage::getStoreConfig('carriers/tiramizoo/'.$rate.'_price')) {
197
+ $tiramizooShippingMethodValid = false;
198
+ break;
199
+ }
200
+ }
201
+
202
+ if (!$requiredValid) {
203
+ $message = Mage::helper('tiramizoo_shipping')->__('Tiramizoo can not be set to active, minimal configuration is required!');
204
+ Mage::getSingleton('core/session')->addError($message);
205
+ }
206
+
207
+ if (!$tiramizooShippingMethodValid) {
208
+ $message = Mage::helper('tiramizoo_shipping')->__('Tiramizoo Shipping Method configuration is incomplete!');
209
+ Mage::getSingleton('core/session')->addError($message);
210
+ // $url = Mage::getUrl('adminhtml/system_config/edit', array('section'=>'carriers'));
211
+ }
212
+
213
+ if (!$tiramizooShippingMethodValid || !$requiredValid) {
214
+ Mage::getModel('core/config')->saveConfig('tiramizoo_config/api_config/is_active', false);
215
+ Mage::app()->getStore()->resetConfig();
216
+ }
217
+
218
+ }
219
+ }
220
+
221
+ /**
222
+ * If Tiramizoo shipping method is selected,
223
+ * this function checks available payment methods
224
+ *
225
+ * @param Varien_Event_Observer $observer
226
+ * @return null
227
+ */
228
+ public function paymentMethodIsActive(Varien_Event_Observer $observer)
229
+ {
230
+ $event = $observer->getEvent();
231
+ $method = $event->getMethodInstance();
232
+ $result = $event->getResult();
233
+ $quote = $event->getQuote();
234
+
235
+ if ($quote instanceof Mage_Sales_Model_Quote) {
236
+ $shipping_method = $quote->getShippingAddress()->getShippingMethod();
237
+
238
+ $rates = Mage::helper('tiramizoo_shipping/data')->getAvailableShippingRates();
239
+
240
+ if (array_key_exists($shipping_method, $rates)) {
241
+ $availablePayments = explode(',', Mage::getStoreConfig('tiramizoo_config/api_config/payment'));
242
+
243
+ if (!in_array($method->getCode(), $availablePayments)) {
244
+ $result->isAvailable = false;
245
+ }
246
+ }
247
+ }
248
+
249
+ }
250
+
251
+
252
+ /**
253
+ * This method will run when the product is saved from the Magento Admin
254
+ * Use this function to update the product model, process the
255
+ * data or anything you like
256
+ *
257
+ * @param Varien_Event_Observer $observer
258
+ * @return null
259
+ */
260
+ public function saveProductTabData(Varien_Event_Observer $observer)
261
+ {
262
+ if (!self::$_singletonFlag) {
263
+ self::$_singletonFlag = true;
264
+
265
+ $product = $observer->getEvent()->getProduct();
266
+
267
+ try {
268
+ $tiramizooIsEnable = $this->_getRequest()->getPost('tiramizoo_enable');
269
+
270
+ if (Mage::getModel('tiramizoo/entity_attribute_source_enable')->optionExists($tiramizooIsEnable)) {
271
+ $product->setData('tiramizoo_enable', $tiramizooIsEnable);
272
+ $product->getResource()->save($product);
273
+ }
274
+
275
+ $tiramizooPackedIndividually = $this->_getRequest()->getPost('tiramizoo_packed_individually');
276
+
277
+ if (Mage::getModel('tiramizoo/entity_attribute_source_packed')->optionExists($tiramizooPackedIndividually)) {
278
+ $product->setData('tiramizoo_packed_individually', $tiramizooPackedIndividually);
279
+ $product->getResource()->save($product);
280
+ }
281
+ } catch (Exception $e) {
282
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
283
+ }
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Shortcut to getRequest
289
+ *
290
+ * @return Mage_Core_Controller_Request_Http
291
+ */
292
+ protected function _getRequest()
293
+ {
294
+ return Mage::app()->getRequest();
295
+ }
296
+ }
app/code/community/Tiramizoo/Shipping/Model/Order.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo order model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Order extends Mage_Core_Model_Abstract
24
+ {
25
+ /**
26
+ * Initialize
27
+ *
28
+ * @return null
29
+ */
30
+ protected function _construct()
31
+ {
32
+ $this->_init('tiramizoo/order', 'id');
33
+ }
34
+
35
+ }
app/code/community/Tiramizoo/Shipping/Model/Payment.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo shipping payment information
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Payment
24
+ {
25
+ /**
26
+ * Geta all active payment method
27
+ *
28
+ * @return mixed
29
+ */
30
+ public function getActivePaymentMethods()
31
+ {
32
+ $payments = array();
33
+ $config = Mage::helper('tiramizoo_shipping')->getConfigData('payment');
34
+ foreach ($config as $code => $method_config)
35
+ {
36
+ if (is_array($method_config)) {
37
+ if (isset($method_config['active']) && $method_config['active']) {
38
+ if (isset($method_config['model'])) {
39
+ $method_model = Mage::getModel($method_config['model']);
40
+ if ($method_model) {
41
+ $payments[$code] = $method_config['title'];
42
+ }
43
+ }
44
+ }
45
+ } else {
46
+ if ($method_config->active != '0') {
47
+ if (isset($method_config->model)) {
48
+ $method_model = Mage::getModel($method_config->model);
49
+ if ($method_model) {
50
+ $payments[$code] = $method_config->title;
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ $methods = array();
58
+ foreach ($payments as $code => $title) {
59
+ $methods[$code] = array(
60
+ 'label' => $title,
61
+ 'value' => $code,
62
+ );
63
+ }
64
+ return $methods;
65
+ }
66
+
67
+ /**
68
+ * Convert to option array
69
+ *
70
+ * @return array
71
+ */
72
+ public function toOptionArray()
73
+ {
74
+ return $this->getActivePaymentMethods();
75
+ }
76
+
77
+ }
app/code/community/Tiramizoo/Shipping/Model/Product.php ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo product model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Product
24
+ {
25
+ /**
26
+ * Arrays of products and categories disabled ids
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_disableIds = array('product' => array(), 'category' => array());
31
+
32
+ /**
33
+ * Tirmiazoo product attributes model
34
+ *
35
+ * @var Tiramizoo_Shipping_Model_Product_Attributes
36
+ */
37
+ protected $_attributes = null;
38
+
39
+ /**
40
+ * Product model
41
+ *
42
+ * @var Mage_Catalog_Model_Product
43
+ */
44
+ protected $_product = null;
45
+
46
+ /**
47
+ * Product categories data
48
+ *
49
+ * @var array
50
+ */
51
+ protected $_categories = array();
52
+
53
+ /**
54
+ * Construct. Initialize product
55
+ *
56
+ * @param Mage_Catalog_Model_Product $product
57
+ * @return null
58
+ */
59
+ public function __construct(Mage_Catalog_Model_Product $product)
60
+ {
61
+ $this->_product = $product;
62
+ }
63
+
64
+ /**
65
+ * Initialize and returns tirmiazoo product attributes model
66
+ *
67
+ * @return Tiramizoo_Shipping_Model_Product_Attributes
68
+ */
69
+ public function getAttributes()
70
+ {
71
+ if (!$this->_attributes) {
72
+ $this->_attributes = Mage::getModel('tiramizoo/product_attributes', $this->_product);
73
+ }
74
+ return $this->_attributes;
75
+ }
76
+
77
+ /**
78
+ * Initialize and returns tiramizoo caegory model
79
+ *
80
+ * @param int $categoryId
81
+ * @return Tiramizoo_Shipping_Model_Category
82
+ */
83
+ public function getCategory($categoryId)
84
+ {
85
+ if (!isset($this->_categories[$categoryId])) {
86
+ $this->_categories[$categoryId] = Mage::getModel('tiramizoo/category', Mage::getModel('catalog/category')->load($categoryId));
87
+ }
88
+ return $this->_categories[$categoryId];
89
+ }
90
+
91
+ /**
92
+ * Get full category path with all parents node
93
+ *
94
+ * @param int $categoryId
95
+ * @return string
96
+ */
97
+ public function getCategoryPath($categoryId)
98
+ {
99
+ $category = Mage::getModel('catalog/category')->load($categoryId);
100
+ return $category->getPath();
101
+ }
102
+
103
+ /**
104
+ * Get all category subtree leafs ids
105
+ *
106
+ * @param array $categoryIds
107
+ * @return array
108
+ */
109
+ public function getSubtreeLeafsIds(array $categoryIds)
110
+ {
111
+ $paths = array();
112
+ foreach ($categoryIds as $id) {
113
+ $paths[$id] = $this->getCategoryPath($id).'/';
114
+ }
115
+ foreach ($paths as $path) {
116
+ foreach ($paths as $index => $searchPath) {
117
+ if (strpos($path, $searchPath) === 0 && $searchPath !== $path) {
118
+ unset($paths[$index]);
119
+ }
120
+ }
121
+ }
122
+ return array_keys($paths);
123
+ }
124
+
125
+ /**
126
+ * Get effective value of product dimensions attributes
127
+ *
128
+ * @return mixed
129
+ */
130
+ public function getDimensions()
131
+ {
132
+ $attributes = $this->getAttributes();
133
+ $dimensions = false;
134
+
135
+ if (!($dimensions = $attributes->getDimensions())) {
136
+
137
+ if (count($categoryIds = $this->_product->getCategoryIds()) > 0) {
138
+
139
+ $categories = array();
140
+ $maxSize = array('id' => 0, 'value' => 0);
141
+ $categoryIds = $this->getSubtreeLeafsIds($categoryIds);
142
+
143
+ foreach ($categoryIds as $categoryId) {
144
+ $category = $this->getCategory($categoryId);
145
+ $categoryDimensions = $category->getDimensions();
146
+
147
+ if ($categoryDimensions) {
148
+ if ($maxSize['value'] < $categoryDimensions['size']) {
149
+ $maxSize['value'] = $categoryDimensions['size'];
150
+ $maxSize['id'] = $categoryId;
151
+ }
152
+ $categories[$categoryId] = $categoryDimensions;
153
+ }
154
+ }
155
+
156
+ if (count($categories) == 0) {
157
+ $dimensions = Mage::getModel('tiramizoo/default')->getDimensions();
158
+ } else {
159
+ $dimensions = $categories[$maxSize['id']];
160
+ }
161
+ } else {
162
+ $dimensions = Mage::getModel('tiramizoo/default')->getDimensions();
163
+ }
164
+ }
165
+
166
+ return $dimensions;
167
+ }
168
+
169
+ /**
170
+ * Get effective value of is available attribute
171
+ *
172
+ * @return boolean
173
+ */
174
+ public function isAvailable()
175
+ {
176
+ Mage::getModel('tiramizoo/debug')->log('/----------------------------------------------------');
177
+ Mage::getModel('tiramizoo/debug')->log('Checking cart item. Name: ' . $this->_product->getName(). ', Dimensions: ' . var_export($this->getDimensions(), true));
178
+
179
+ $return = true;
180
+
181
+ $attributes = $this->getAttributes();
182
+
183
+ $allow = in_array($attributes->getEnable(), array(0, 1));
184
+
185
+ if ($allow) {
186
+
187
+ if (count($categoryIds = $this->_product->getCategoryIds()) > 0) {
188
+
189
+ $categoryIds = $this->getSubtreeLeafsIds($categoryIds);
190
+ $dimensions = array();
191
+ $disableIds = array();
192
+ foreach ($categoryIds as $categoryId) {
193
+ $category = $this->getCategory($categoryId);
194
+ if ($category->getDimensions()) {
195
+ $dimensions[] = true;
196
+ }
197
+ $disableIds = array_unique(array_merge($disableIds, $category->getDisableIds()));
198
+ }
199
+
200
+ if (count($disableIds) == 0) {
201
+ if (count($dimensions) == 0) {
202
+ $return = false;
203
+ Mage::getModel('tiramizoo/debug')->log('Product is not available, dimensions do not exist.');
204
+ }
205
+ } else {
206
+ $return = false;
207
+ Mage::getModel('tiramizoo/debug')->log('Product is not available, once or more of categories is disabled. ('.implode(', ', $disableIds).')');
208
+ }
209
+ } else {
210
+ // @todo: decide what should happen? Product does not have any category
211
+ // $return = false;
212
+ if (!$attributes->getDimensions()) {
213
+ if (Mage::getModel('tiramizoo/default')->getDimensions()) {
214
+ $return = true;
215
+ } else {
216
+ $return = false;
217
+ Mage::getModel('tiramizoo/debug')->log('Product is not available, dimensions is incomplete.');
218
+ }
219
+
220
+ }
221
+ Mage::getModel('tiramizoo/debug')->log('Product does not have any category.');
222
+ }
223
+
224
+
225
+ } else {
226
+ $return = false;
227
+ Mage::getModel('tiramizoo/debug')->log('Product is disabled.');
228
+ }
229
+
230
+ if ($return) {
231
+ Mage::getModel('tiramizoo/debug')->log('Product is available.');
232
+ }
233
+
234
+ return $return;
235
+ }
236
+
237
+ /**
238
+ * Get disable ids of objects
239
+ *
240
+ * @return array
241
+ */
242
+ public function getDisableIds()
243
+ {
244
+ return $this->_disableIds;
245
+ }
246
+
247
+ /**
248
+ * Returns true if product is disable
249
+ *
250
+ * @return boolean
251
+ */
252
+ public function isDisable()
253
+ {
254
+ $attributes = $this->getAttributes();
255
+
256
+ $allow = in_array($attributes->getEnable(), array(0, 1));
257
+
258
+ if ($allow) {
259
+ if (count($categoryIds = $this->_product->getCategoryIds()) > 0) {
260
+
261
+ $categoryIds = $this->getSubtreeLeafsIds($categoryIds);
262
+ foreach ($categoryIds as $categoryId) {
263
+ $category = $this->getCategory($categoryId);
264
+
265
+ if (count($disableIds = $category->getDisableIds()) > 0) {
266
+ $this->_disableIds['category'] = array_unique(array_merge($this->_disableIds['category'], $disableIds));
267
+ }
268
+ }
269
+ }
270
+ } else {
271
+ $this->_disableIds['product'][] = $this->_product->getId();
272
+ }
273
+
274
+ $return = false;
275
+ foreach ($this->_disableIds as $type) {
276
+ if (count($type) > 0) $return = true;
277
+ }
278
+
279
+ return $return;
280
+ }
281
+
282
+ /**
283
+ * Get effective value of is packed individually attribute
284
+ *
285
+ * @return boolean
286
+ */
287
+ public function isPackedIndividually()
288
+ {
289
+ $attributes = $this->getAttributes();
290
+
291
+ $packedIndividually = null;
292
+
293
+ //check value from product
294
+ if ($attributes->getPackedIndividually() == 1) {
295
+ $packedIndividually = true;
296
+ } else if ($attributes->getPackedIndividually() == -1) {
297
+ $packedIndividually = false;
298
+ }
299
+
300
+ //check from category
301
+ if ($packedIndividually === null && count($categoryIds = $this->_product->getCategoryIds()) > 0) {
302
+
303
+ $categoryIds = $this->getSubtreeLeafsIds($categoryIds);
304
+ foreach ($categoryIds as $categoryId) {
305
+ $category = $this->getCategory($categoryId);
306
+
307
+ $packed = $category->isPackedIndividually();
308
+ if ($packed === false) {
309
+ $packedIndividually = false;
310
+ break;
311
+ } elseif ($packed === true) {
312
+ $packedIndividually = true;
313
+ }
314
+ }
315
+ }
316
+
317
+ //check from config
318
+ if ($packedIndividually === null) {
319
+ $packedIndividually = $this->getPackingStrategy() == 'individual';
320
+ }
321
+
322
+ return $packedIndividually;
323
+ }
324
+
325
+ /**
326
+ * Get packing strategy value from config
327
+ *
328
+ * @return string
329
+ */
330
+ public function getPackingStrategy()
331
+ {
332
+ return Mage::getStoreConfig('tiramizoo_config/api_config/packing_strategy');
333
+ }
334
+ }
app/code/community/Tiramizoo/Shipping/Model/Product/Attributes.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo product attributes model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Product_Attributes
24
+ {
25
+ /**
26
+ * Product dimension attributest mapping
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_mapping = array();
31
+
32
+ /**
33
+ * Product model
34
+ *
35
+ * @var Mage_Catalog_Model_Product
36
+ */
37
+ protected $_product = null;
38
+
39
+ /**
40
+ * Clonstruct set product and dimensions mapping array
41
+ *
42
+ * @param Mage_Catalog_Model_Product $product
43
+ */
44
+ public function __construct(Mage_Catalog_Model_Product $product)
45
+ {
46
+ $this->_product = $product;
47
+
48
+ /* Product attributes with ids */
49
+ $this->_mapping['width'] = Mage::getStoreConfig('tiramizoo_config/api_config/product_width_mapping');
50
+ $this->_mapping['height'] = Mage::getStoreConfig('tiramizoo_config/api_config/product_height_mapping');
51
+ $this->_mapping['length'] = Mage::getStoreConfig('tiramizoo_config/api_config/product_length_mapping');
52
+ }
53
+
54
+ /**
55
+ * Get dimensions of product
56
+ *
57
+ * @return mixed
58
+ */
59
+ public function getDimensions()
60
+ {
61
+ $result = array();
62
+
63
+ if (
64
+ ($result['weight'] = $this->_product->getWeight()) &&
65
+ ($result['width'] = $this->_product->getData($this->_mapping['width'])) &&
66
+ ($result['height'] = $this->_product->getData($this->_mapping['height'])) &&
67
+ ($result['length'] = $this->_product->getData($this->_mapping['length']))
68
+ ) {
69
+ $result['destination_type'] = 'product';
70
+ $result['destination_id'] = $this->_product->getId();
71
+
72
+ Mage::dispatchEvent('tiramizoo_shipping_convert_product_dimensions', array(
73
+ 'weight' => &$result['weight'],
74
+ 'width' => &$result['width'],
75
+ 'height' => &$result['height'],
76
+ 'length' => &$result['length'],
77
+ ));
78
+
79
+ $dim = array($result['width'], $result['height'], $result['length']);
80
+ $result['size'] = min($dim) + max($dim);
81
+ } else {
82
+ $result = false;
83
+ }
84
+
85
+ return $result;
86
+
87
+ }
88
+
89
+ /**
90
+ * Check is enable attribute value
91
+ *
92
+ * @return boolean
93
+ */
94
+ public function isEnable()
95
+ {
96
+ // @todo
97
+ return (bool) $this->_product->getData('tiramizoo_enable');
98
+ }
99
+
100
+ /**
101
+ * Get is enable attribute value
102
+ *
103
+ * @return integer
104
+ */
105
+ public function getEnable()
106
+ {
107
+ return (int) $this->_product->getData('tiramizoo_enable');
108
+ }
109
+
110
+ /**
111
+ * Get is pacekd indiviually attribute value
112
+ *
113
+ * @return integer
114
+ */
115
+ public function getPackedIndividually()
116
+ {
117
+ return (int) $this->_product->getData('tiramizoo_packed_individually');
118
+ }
119
+
120
+ }
app/code/community/Tiramizoo/Shipping/Model/Resend.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Resend order to tiramizoo model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Resend
24
+ {
25
+ /**
26
+ * Check orders without state and try to resend or mark as error depends on send_at field
27
+ *
28
+ * @return null
29
+ */
30
+ public function check()
31
+ {
32
+ $resource = Mage::getSingleton('core/resource');
33
+ $readConnection = $resource->getConnection('core_read');
34
+
35
+ //get the newest orders wihout status
36
+ $select = $readConnection->select()
37
+ ->from($resource->getTableName('tiramizoo/order'), array('id'))
38
+ ->where('status IS NULL')
39
+ ->where('send_at >= DATE_ADD(\'' . Mage::getSingleton('core/date')->gmtDate() . '\', INTERVAL -30 HOUR_MINUTE)');
40
+
41
+ $results = $readConnection->fetchAll($select);
42
+
43
+ foreach ($results as $item) {
44
+ $tiramizooOrder = Mage::getModel('tiramizoo/order')->load($item['id']);
45
+ $this->resendOrder($tiramizooOrder);
46
+ }
47
+
48
+ //get older orders wihout status to mark as error
49
+ $select = $readConnection->select()
50
+ ->from($resource->getTableName('tiramizoo/order'), array('id'))
51
+ ->where('status IS NULL')
52
+ ->where('send_at < DATE_ADD(\'' . Mage::getSingleton('core/date')->gmtDate() . '\', INTERVAL -30 HOUR_MINUTE)');
53
+
54
+ $results = $readConnection->fetchAll($select);
55
+
56
+ foreach ($results as $item) {
57
+ $tiramizooOrder = Mage::getModel('tiramizoo/order')->load($item['id']);
58
+ $this->errorOrder($tiramizooOrder);
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Resend order to Tiramizoo API
64
+ *
65
+ * @param $tiramizooOrder
66
+ * @return null
67
+ */
68
+ public function resendOrder($tiramizooOrder)
69
+ {
70
+ $buildData = json_decode($tiramizooOrder->getApiRequest());
71
+
72
+ $apiToken = Mage::helper('tiramizoo_shipping/data')->getApiTokenByPostalCode($buildData->delivery->postal_code);
73
+
74
+ if ($apiToken) {
75
+ $response = Mage::getModel('tiramizoo/api', array('api_token' => $apiToken))
76
+ ->sendOrder($buildData);
77
+
78
+ // Response actions
79
+ Mage::getModel('tiramizoo/response', $response);
80
+
81
+ if (isset($response['http_status']) && $response['http_status'] == '201') {
82
+ $trackingUrl = $response['response']->tracking_url;
83
+ $status = isset($response['response']->state) ? $response['response']->state : null;
84
+
85
+ $tiramizooOrder->setStatus($status);
86
+ $tiramizooOrder->setTrackingUrl($trackingUrl);
87
+ $tiramizooOrder->setApiResponse(json_encode($response));
88
+ $tiramizooOrder->setRepeats($tiramizooOrder->getRepeats() + 1);
89
+ $tiramizooOrder->save();
90
+ } else {
91
+ $tiramizooOrder->setRepeats($tiramizooOrder->getRepeats() + 1);
92
+ $tiramizooOrder->save();
93
+ }
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Mark order as error
99
+ *
100
+ * @param $tiramizooOrder
101
+ * @return null
102
+ */
103
+ public function errorOrder($tiramizooOrder)
104
+ {
105
+ $tiramizooOrder->setStatus('error');
106
+ $tiramizooOrder->setRepeats($tiramizooOrder->getRepeats() + 1);
107
+ $tiramizooOrder->save();
108
+
109
+ //Add error to notification inbox
110
+ $notification = Mage::getModel('adminnotification/inbox');
111
+ $notification->setSeverity(2);
112
+ $notification->setTitle('Erorr with sending order to Tiramizoo, order: ' . $tiramizooOrder->getOrderId());
113
+ $notification->setDescription('Please contact to Tiramizoo Support support@tiramizoo.com');
114
+ $notification->setUrl(Mage::getUrl('adminhtml/sales_order/view/', array('order_id' => $tiramizooOrder->getOrderId())));
115
+ $notification->save();
116
+ }
117
+ }
app/code/community/Tiramizoo/Shipping/Model/Response.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo API response model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Response
24
+ {
25
+ /**
26
+ * Response
27
+ *
28
+ * @var mixed
29
+ */
30
+ protected $_response = null;
31
+
32
+ /**
33
+ * HTTP status code
34
+ *
35
+ * @var mixed
36
+ */
37
+ protected $_httpStatus = null;
38
+
39
+ /**
40
+ * Initialize
41
+ *
42
+ * @param Array $response
43
+ * @return null
44
+ */
45
+ public function __construct($response = array())
46
+ {
47
+ if (isset($response['http_status'])) {
48
+ $this->_httpStatus = $response['http_status'];
49
+ }
50
+
51
+ if (isset($response['response'])) {
52
+ $this->_response = $response['response'];
53
+ }
54
+
55
+ $this->checkResponse();
56
+ }
57
+
58
+ /**
59
+ * Proccess API response
60
+ *
61
+ * @return null
62
+ */
63
+ private function checkResponse()
64
+ {
65
+ Mage::getModel('tiramizoo/debug')->log('http_status: '.$this->_httpStatus);
66
+
67
+ switch($this->_httpStatus) {
68
+ // 201 Created
69
+ case 201:
70
+ Mage::getModel('tiramizoo/debug')->log('The resource was created.');
71
+ break;
72
+
73
+ // 400 Bad Request
74
+ case 400: break;
75
+
76
+ // 422 Unprocessable Entity
77
+ case 422: break;
78
+
79
+ // 500 Internal Server Error
80
+ case 500: break;
81
+
82
+ // 503 Service Unavailable
83
+ case 503: break;
84
+
85
+ default: break;
86
+ }
87
+ }
88
+
89
+ }
app/code/community/Tiramizoo/Shipping/Model/Retaillocation.php ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo retail locataion model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Retaillocation extends Mage_Core_Helper_Abstract
24
+ {
25
+
26
+ /**
27
+ * API token
28
+ *
29
+ * @var string
30
+ */
31
+ protected $_apiToken = null;
32
+
33
+ /**
34
+ * Location path
35
+ *
36
+ * @var string
37
+ */
38
+ protected $_locationPath = null;
39
+
40
+ /**
41
+ * Config path
42
+ *
43
+ * @var string
44
+ */
45
+ protected $_configPath = '/api_config';
46
+
47
+ /**
48
+ * Config values
49
+ *
50
+ * @var string
51
+ */
52
+ protected $_config = null;
53
+
54
+ /**
55
+ * Service area path
56
+ *
57
+ * @var string
58
+ */
59
+ protected $_serviceAreasPath = '/api_service_areas';
60
+
61
+ /**
62
+ * Config values
63
+ *
64
+ * @var string
65
+ */
66
+ protected $_serviceAreas = null;
67
+
68
+ /**
69
+ * Construct. Set API token.
70
+ *
71
+ * @param Array $args
72
+ * @return null
73
+ */
74
+ public function __construct($args = array())
75
+ {
76
+ if (isset($args['api_token'])) {
77
+ $this->_apiToken = $args['api_token'];
78
+ }
79
+
80
+ if ($this->_apiToken == null) {
81
+ throw new Exception('ApiToken must be defined.');
82
+ }
83
+
84
+ $this->_locationPath = $this->getLocationPath();
85
+ }
86
+
87
+ /**
88
+ * Get config location path
89
+ *
90
+ * @return string
91
+ */
92
+ public function getLocationPath()
93
+ {
94
+ if ($this->_locationPath == null) {
95
+
96
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
97
+ $result = $read->fetchOne("select `path` from `core_config_data` where `value` = '{$this->_apiToken}' and `path` like 'tiramizoo_config/%'");
98
+
99
+ $result = explode('/', $result);
100
+
101
+ if (count($result) != 3) {
102
+ throw new Exception('Api Token is not valid.');
103
+ }
104
+
105
+ $return = $result[0].'/'.$result[1];
106
+ } else {
107
+ $return = $this->_locationPath;
108
+ }
109
+
110
+ return $return;
111
+ }
112
+
113
+ /**
114
+ * Get full config path
115
+ *
116
+ * @return string
117
+ */
118
+ public function getConfigPath()
119
+ {
120
+ $this->_locationPath = $this->getLocationPath();
121
+ $path = $this->_locationPath.$this->_configPath;
122
+
123
+ return $path;
124
+ }
125
+
126
+ /**
127
+ * Get full service areas path
128
+ *
129
+ * @return string
130
+ */
131
+ public function getServiceAreasPath()
132
+ {
133
+ $this->_locationPath = $this->getLocationPath();
134
+ $path = $this->_locationPath.$this->_serviceAreasPath;
135
+
136
+ return $path;
137
+ }
138
+
139
+ /**
140
+ * Get full service areas
141
+ *
142
+ * @return mixed
143
+ */
144
+ public function getServiceAreas($name)
145
+ {
146
+ $return = false;
147
+
148
+ if (!$this->_serviceAreas) {
149
+ $this->_serviceAreas = Mage::getStoreConfig($this->getServiceAreasPath());
150
+ }
151
+
152
+ if ($this->_serviceAreas) {
153
+ $config = json_decode($this->_serviceAreas, true);
154
+
155
+ if (is_array($config) && isset($config[$name])) {
156
+ $return = $config[$name];
157
+ }
158
+ }
159
+
160
+ return $return;
161
+ }
162
+
163
+ /**
164
+ * Get param value
165
+ *
166
+ * @param string $name
167
+ * @return string value
168
+ */
169
+ public function getParam($name)
170
+ {
171
+ $return = false;
172
+
173
+ if (!$this->_config) {
174
+ $this->_config = Mage::getStoreConfig($this->getConfigPath());
175
+ }
176
+
177
+ if ($this->_config) {
178
+ $config = json_decode($this->_config, true);
179
+
180
+ if (is_array($config) && isset($config[$name])) {
181
+ $return = $config[$name];
182
+ }
183
+ }
184
+
185
+ return $return;
186
+ }
187
+
188
+ /**
189
+ * Get available time windows
190
+ *
191
+ * @return array
192
+ */
193
+ public function getAvailableTimeWindows()
194
+ {
195
+ if ($aTimeWindows = $this->getServiceAreas('time_windows')) {
196
+
197
+ //sort by delivery from date
198
+ foreach ($aTimeWindows as $oldKey => $aTimeWindow)
199
+ {
200
+ $oTimeWindow = Mage::getModel('tiramizoo/time_window', $aTimeWindow);
201
+
202
+ $aTimeWindows[$oTimeWindow->getDeliveryFromDate()->getTimestamp()] = $aTimeWindow;
203
+ unset($aTimeWindows[$oldKey]);
204
+ }
205
+
206
+ ksort($aTimeWindows);
207
+ }
208
+
209
+ return $aTimeWindows ? $aTimeWindows : array();
210
+ }
211
+
212
+ /**
213
+ * Get service areas from API and save to config
214
+ *
215
+ * @return object
216
+ */
217
+ public function saveServiceAreas()
218
+ {
219
+ $pickupContact = $this->getParam('pickup_contact');
220
+ $path = $this->getServiceAreasPath();
221
+
222
+ $oStartDate = new DateTime(date('Y-m-d'));
223
+ $oEndDate = new DateTime(date('Y-m-d'));
224
+ $oEndDate->modify('+2 days');
225
+
226
+ $startDate = $oStartDate->format('Y-m-d\TH:i:s\Z');
227
+ $endDate = $oEndDate->format('Y-m-d\TH:i:s\Z');
228
+
229
+ $rangeDates = array(
230
+ 'express_from' => $startDate,
231
+ 'express_to' => $endDate,
232
+ 'standard_from' => $startDate,
233
+ 'standard_to' => $endDate
234
+ );
235
+
236
+ $avaialbleServiceAreas = Mage::getModel('tiramizoo/api', array('api_token' => $this->_apiToken))
237
+ ->getAvailableServiceAreas($pickupContact['postal_code'], $rangeDates);
238
+
239
+
240
+ if ($avaialbleServiceAreas['http_status'] != 200) {
241
+ throw new Exception("Can't connect to Tiramizoo API", 1);
242
+ }
243
+
244
+ if (isset($avaialbleServiceAreas['response'])) {
245
+
246
+ // var_dump(array('Path' => $path, 'ServiceAreas' => $avaialbleServiceAreas['response']));
247
+ // $avaialbleServiceAreas['response'] = $this->objectToArray($avaialbleServiceAreas['response']);
248
+
249
+ Mage::getModel('core/config')->saveConfig($path, json_encode($avaialbleServiceAreas['response']));
250
+ }
251
+
252
+ return $this;
253
+ }
254
+
255
+ /**
256
+ * Get config from API and save to config
257
+ *
258
+ * @return object
259
+ */
260
+ public function saveRemoteConfig()
261
+ {
262
+ $path = $this->getConfigPath();
263
+
264
+ $result = Mage::getModel('tiramizoo/api', array('api_token' => $this->_apiToken))
265
+ ->getRemoteConfiguration();
266
+
267
+ if ($result['http_status'] != 200) {
268
+ throw new Exception("Can't connect to Tiramizoo API", 1);
269
+ }
270
+
271
+ if (isset($result['response'])) {
272
+ Mage::getModel('core/config')->saveConfig($path, json_encode($result['response']));
273
+ $this->_config = json_encode($result['response']);
274
+ }
275
+
276
+ return $this;
277
+ }
278
+
279
+ /**
280
+ * Convert recursively stdClass object into an array.
281
+ *
282
+ * @param mixed $data array or stdClass object
283
+ * @return mixed
284
+ */
285
+ public function objectToArray($data)
286
+ {
287
+ $return = $data;
288
+
289
+ if (is_array($data) || is_object($data))
290
+ {
291
+ $result = array();
292
+ foreach ($data as $key => $value)
293
+ {
294
+ $result[$key] = $this->objectToArray($value);
295
+ }
296
+ $return = $result;
297
+ }
298
+
299
+ return $return;
300
+ }
301
+ }
app/code/community/Tiramizoo/Shipping/Model/Retaillocations.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo retaillocataions model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Retaillocations
24
+ {
25
+
26
+ /**
27
+ * Synchronize all retail locations. Clear the cache.
28
+ *
29
+ * @return null
30
+ */
31
+ public function synchronize()
32
+ {
33
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
34
+
35
+ $query = "SELECT ccd1.value AS api_token
36
+ FROM core_config_data AS ccd1
37
+ WHERE ccd1.path IN (
38
+ SELECT REPLACE(path, 'is_enable', 'api_key')
39
+ FROM `core_config_data`
40
+ WHERE `value` = 1
41
+ AND `path` like 'tiramizoo_config/tiramizoo_location_%/is_enable'
42
+ );";
43
+
44
+ $result = $read->fetchAll($query);
45
+
46
+ foreach ($result as $key => $row)
47
+ {
48
+ try {
49
+ Mage::getModel('tiramizoo/retaillocation', array('api_token' => $row['api_token']))
50
+ ->saveRemoteConfig()
51
+ ->saveServiceAreas();
52
+ } catch(Exception $e) {
53
+ // echo $row['api_token'] . ' ' . $e->getMessage();
54
+ }
55
+ }
56
+
57
+ Mage::app()->cleanCache();
58
+ }
59
+ }
app/code/community/Tiramizoo/Shipping/Model/TestObserver.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Test observer
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_TestObserver
24
+ {
25
+ public function convertProductDimensions($observer)
26
+ {
27
+ $event = $observer->getEvent();
28
+ $weight = $event->getWeight();
29
+ $width = $event->getWidth();
30
+ $height = $event->getHeight();
31
+ $length = $event->getLength();
32
+
33
+ // Your code
34
+ // $weight = $weight / 10;
35
+ // $width = $width / 100;
36
+ // $height = $height * 10;
37
+ // $length = $length * 100;
38
+
39
+ // Dimensions in cm
40
+ $event->setWeight($weight);
41
+ $event->setWidth($width);
42
+ $event->setHeight($height);
43
+ $event->setLength($length);
44
+ }
45
+
46
+ public function convertCategoryDimensions($observer)
47
+ {
48
+ $event = $observer->getEvent();
49
+ $weight = $event->getWeight();
50
+ $width = $event->getWidth();
51
+ $height = $event->getHeight();
52
+ $length = $event->getLength();
53
+
54
+ // Your code
55
+ // $weight = $weight / 10;
56
+ // $width = $width / 100;
57
+ // $height = $height * 10;
58
+ // $length = $length * 100;
59
+
60
+ // Dimensions in cm
61
+ $event->setWeight($weight);
62
+ $event->setWidth($width);
63
+ $event->setHeight($height);
64
+ $event->setLength($length);
65
+ }
66
+
67
+ public function ratesPrice($observer)
68
+ {
69
+ $event = $observer->getEvent();
70
+ $immediatePrice = $event->getImmediate();
71
+ $eveningPrice = $event->getEvening();
72
+
73
+ // Your code
74
+ // $immediatePrice = $immediatePrice * 15;
75
+ // $eveningPrice = $eveningPrice * 12;
76
+
77
+ $event->setImmediate($immediatePrice);
78
+ $event->setEvening($eveningPrice);
79
+ }
80
+ }
app/code/community/Tiramizoo/Shipping/Model/Time/Window.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Time window model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Time_Window
24
+ {
25
+ /**
26
+ * Array where store time window data
27
+ *
28
+ * @var array
29
+ */
30
+ protected $_data = array();
31
+
32
+ /**
33
+ * @param Array $args
34
+ *
35
+ * @return null
36
+ */
37
+ public function __construct($data)
38
+ {
39
+ $this->_data = $data;
40
+ }
41
+
42
+ /**
43
+ * Returns delivery from
44
+ *
45
+ * @return string
46
+ */
47
+ public function getDeliveryFrom()
48
+ {
49
+ return $this->_data['delivery']['from'];
50
+ }
51
+
52
+ /**
53
+ * Returns delivery to
54
+ *
55
+ * @return string
56
+ */
57
+ public function getDeliveryTo()
58
+ {
59
+ return $this->_data['delivery']['to'];
60
+ }
61
+
62
+ /**
63
+ * Returns pickup from
64
+ *
65
+ * @return string
66
+ */
67
+ public function getPickupFrom()
68
+ {
69
+ return $this->_data['pickup']['from'];
70
+ }
71
+
72
+ /**
73
+ * Returns pickup to
74
+ *
75
+ * @return string
76
+ */
77
+ public function getPickupTo()
78
+ {
79
+ return $this->_data['pickup']['to'];
80
+ }
81
+
82
+ /**
83
+ * Returns delivery from as object
84
+ *
85
+ * @return Tiramizoo_Shipping_Model_Date
86
+ */
87
+ public function getDeliveryFromDate()
88
+ {
89
+ return Mage::getModel('tiramizoo/date', $this->_data['delivery']['from']);
90
+ }
91
+
92
+ /**
93
+ * Returns delivery to as object
94
+ *
95
+ * @return Tiramizoo_Shipping_Model_Date
96
+ */
97
+ public function getDeliveryToDate()
98
+ {
99
+ return Mage::getModel('tiramizoo/date', $this->_data['delivery']['to']);
100
+ }
101
+
102
+ /**
103
+ * Returns pickup from as object
104
+ *
105
+ * @return Tiramizoo_Shipping_Model_Date
106
+ */
107
+ public function getPickupFromDate()
108
+ {
109
+ return Mage::getModel('tiramizoo/date', $this->_data['pickup']['from']);
110
+ }
111
+
112
+ /**
113
+ * Returns pickup to as object
114
+ *
115
+ * @return Tiramizoo_Shipping_Model_Date
116
+ */
117
+ public function getPickupToDate()
118
+ {
119
+ return Mage::getModel('tiramizoo/date', $this->_data['pickup']['to']);
120
+ }
121
+
122
+ /**
123
+ * Returns cut off
124
+ *
125
+ * @return string
126
+ */
127
+ public function getCutOff()
128
+ {
129
+ return $this->_data['cut_off'];
130
+ }
131
+
132
+ /**
133
+ * Returns delivery type
134
+ *
135
+ * @return string
136
+ */
137
+ public function getDeliveryType()
138
+ {
139
+ return $this->_data['delivery_type'];
140
+ }
141
+
142
+ /**
143
+ * Returns all data
144
+ *
145
+ * @return array
146
+ */
147
+ public function getAsArray()
148
+ {
149
+ return $this->_data;
150
+ }
151
+
152
+ /**
153
+ * Generate and retrieve hash for instance
154
+ *
155
+ * @return string
156
+ */
157
+ public function getHash()
158
+ {
159
+ return md5(serialize($this->_data));
160
+ }
161
+
162
+ /**
163
+ * Get hash in output context
164
+ *
165
+ * @return string
166
+ */
167
+ public function __toString()
168
+ {
169
+ return $this->getHash();
170
+ }
171
+
172
+ /**
173
+ * Get formatted delivery time window using oxlang entries.
174
+ *
175
+ * @return string
176
+ */
177
+ // @todo
178
+ public function getFormattedDeliveryTimeWindow()
179
+ {
180
+ $sReturn = '';
181
+ $oLang = oxRegistry::getLang();
182
+
183
+ $sTplLangugage = oxRegistry::getLang()->getTplLanguage();
184
+
185
+ if ($this->isToday()) {
186
+ $sReturn = $oLang->translateString('oxTiramizoo_Today', $sTplLangugage, false);
187
+ $sReturn .= ' ' . $this->getDeliveryHoursFormated($this->_data);
188
+ } else if ($this->isTomorrow()){
189
+ $sReturn = $oLang->translateString('oxTiramizoo_Tomorrow', $sTplLangugage, false);
190
+ $sReturn .= ' ' . $this->getDeliveryHoursFormated($this->_data);
191
+ } else {
192
+ $sFormat = $oLang->translateString('oxTiramizoo_time_window_date_format', $sTplLangugage, false);
193
+ $sReturn = $this->getDeliveryFromDate()->get($sFormat);
194
+ $sReturn .= ' ' . $this->getDeliveryHoursFormated($this->_data);
195
+ }
196
+
197
+ return $sReturn;
198
+ }
199
+
200
+ /**
201
+ * Get formatted delivery time window hours.
202
+ *
203
+ * @return string
204
+ */
205
+ public function getDeliveryHoursFormated()
206
+ {
207
+ return '('.$this->getDeliveryFromDate()->get('H:i') . ' - ' . $this->getDeliveryToDate()->get('H:i').')';
208
+ }
209
+
210
+ /**
211
+ * Check if time window is valid according to current datetime.
212
+ *
213
+ * @return bool
214
+ */
215
+ public function isValid()
216
+ {
217
+ $return = false;
218
+ $dueDate = new Tiramizoo_Shipping_Model_Date();
219
+
220
+ if ($minutes = $this->_data['cut_off']) {
221
+ $dueDate->modify('+' . $minutes . ' minutes');
222
+ }
223
+
224
+ if ($this->getPickupFromDate()->isLaterThan($dueDate)
225
+ && $this->getDeliveryFromDate()->isLaterThan($dueDate)
226
+ ) {
227
+ $return = true;
228
+ }
229
+
230
+ return $return;
231
+ }
232
+
233
+ /**
234
+ * Check if time window is today according to current datetime.
235
+ *
236
+ * @return bool
237
+ */
238
+ public function isToday()
239
+ {
240
+ return $this->getPickupFromDate()->isToday()
241
+ && $this->getPickupToDate()->isToday()
242
+ && $this->getDeliveryFromDate()->isToday()
243
+ && $this->getDeliveryToDate()->isToday();
244
+ }
245
+
246
+ /**
247
+ * Check if time window is tommorow according to current datetime.
248
+ *
249
+ * @return bool
250
+ */
251
+ public function isTomorrow()
252
+ {
253
+ return $this->getPickupFromDate()->isTomorrow()
254
+ && $this->getPickupToDate()->isTomorrow()
255
+ && $this->getDeliveryFromDate()->isTomorrow()
256
+ && $this->getDeliveryToDate()->isTomorrow();
257
+ }
258
+
259
+ /**
260
+ * Check if time window has specified hours.
261
+ *
262
+ * @param array $hours array of hours
263
+ * @return bool
264
+ */
265
+ public function hasHours($hours)
266
+ {
267
+ return $this->getPickupFromDate()->isOnTime($hours['pickup_after'])
268
+ && $this->getPickupToDate()->isOnTime($hours['pickup_before'])
269
+ && $this->getDeliveryFromDate()->isOnTime($hours['delivery_after'])
270
+ && $this->getDeliveryToDate()->isOnTime($hours['delivery_before']);
271
+ }
272
+ }
app/code/community/Tiramizoo/Shipping/Model/Type/Onepage.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo one page checkout processing model
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
24
+ {
25
+
26
+ /**
27
+ * Add event and call parent method
28
+ *
29
+ * @return null
30
+ */
31
+ public function saveOrder()
32
+ {
33
+ Mage::getModel('tiramizoo/debug')->log('dispatchEvent: checkout_type_onepage_save_order_before');
34
+ Mage::dispatchEvent('checkout_type_onepage_save_order_before',
35
+ array('quote' => $this->getQuote(), 'checkout' => $this->getCheckout()));
36
+
37
+ parent::saveOrder();
38
+ }
39
+ }
app/code/community/Tiramizoo/Shipping/Test/Helper/Build.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ class Tiramizoo_Shipping_Test_Helper_Build extends EcomDev_PHPUnit_Test_Case
17
+ {
18
+
19
+ /**
20
+ * buildItems to API if package strategy = packages
21
+ *
22
+ * @test
23
+ * @loadFixture default
24
+ * @doNotIndexAll
25
+ * @dataProvider dataProvider
26
+ * */
27
+ public function testBuildItems($items, $packingStrategy, $expectedItems)
28
+ {
29
+ $build = $this->getHelperMock('tiramizoo_shipping/build', array('getPackingStrategy'));
30
+ $build->expects($this->any())
31
+ ->method('getPackingStrategy')
32
+ ->will($this->returnValue($packingStrategy));
33
+
34
+ $orderItems = $this->_createOrderItems($items);
35
+
36
+ $build->setItems($orderItems);
37
+
38
+ $tiramizooProduct = $this->getModelMock('tiramizoo/product', array(), false, array(), '', false );
39
+
40
+ foreach ($items as $key => $item) {
41
+ $tiramizooProduct->expects($this->at($key * 2))
42
+ ->method('getDimensions')
43
+ ->will($this->returnValue($item['dimensions']))
44
+ ;
45
+
46
+ $tiramizooProduct->expects($this->at($key * 2 + 1))
47
+ ->method('isPackedIndividually')
48
+ ->will($this->returnValue($item['packed_individually']))
49
+ ;
50
+ }
51
+
52
+ $this->replaceByMock('model', 'tiramizoo/product', $tiramizooProduct);
53
+
54
+ //convert multidimensional Array to Array of stdClass elements
55
+ array_walk($expectedItems, function(&$value, $index){
56
+ $item = new stdClass;
57
+ $item->weight = floatval($value['weight']);
58
+ $item->width = floatval($value['width']);
59
+ $item->height = floatval($value['height']);
60
+ $item->length = floatval($value['length']);
61
+ $item->quantity = $value['quantity'];
62
+ $item->description = $value['description'];
63
+
64
+ if (isset($value['bundle'])) {
65
+ $item->bundle = $value['bundle'];
66
+ }
67
+
68
+ $value = $item;
69
+ });
70
+
71
+ //if no items build should returns null
72
+ if (count($expectedItems) == 0) {
73
+ $expectedItems = null;
74
+ }
75
+
76
+ $this->assertEquals(
77
+ $expectedItems,
78
+ $build->buildItems()
79
+ );
80
+ }
81
+
82
+ protected function _createOrderItems($items)
83
+ {
84
+ $orderItems = array();
85
+
86
+ foreach ($items as $key => $item) {
87
+ $orderItem = $this->getModelMock('sales/order_item', array('getProductId', 'getQtyOrdered', 'getName'));
88
+ $orderItem->expects($this->any())
89
+ ->method('getProductId')
90
+ ->will($this->returnValue($item['id']));
91
+ $orderItem->expects($this->any())
92
+ ->method('getQtyOrdered')
93
+ ->will($this->returnValue($item['quantity']));
94
+ $orderItem->expects($this->any())
95
+ ->method('getName')
96
+ ->will($this->returnValue($item['description']));
97
+
98
+ $orderItems[] = $orderItem;
99
+ }
100
+
101
+ return $orderItems;
102
+ }
103
+
104
+ protected function _itemsValueMap($items)
105
+ {
106
+ $returnValueMap = array();
107
+
108
+ foreach ($items as $key => $item) {
109
+ $returnValueMap[] = array($item['id'], $item['dimensions']);
110
+ }
111
+
112
+ return $returnValueMap;
113
+ }
114
+ }
app/code/community/Tiramizoo/Shipping/Test/Helper/Build/fixtures/default.yaml ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Product Fixtures
2
+ scope:
3
+ website:
4
+ - website_id: 1
5
+ code: main
6
+ name: Main Website
7
+ default_group_id: 1
8
+ group:
9
+ - group_id: 1
10
+ website_id: 1
11
+ name: Main Website Store
12
+ root_category_id: 8
13
+ default_store_id: 1
14
+ store:
15
+ - store_id: 1
16
+ code: default
17
+ website_id: 1
18
+ group_id: 1
19
+ name: Default Store View
20
+ is_active: 1
21
+ config:
22
+ default/tiramizoo_config/api_config/api_url: https://sandbox.tiramizoo.com/api/v1
23
+ default/tiramizoo_config/api_config/product_width_mapping: width
24
+ default/tiramizoo_config/api_config/product_height_mapping: height
25
+ default/tiramizoo_config/api_config/product_length_mapping: length
26
+ default/tiramizoo_config/api_config/packing_strategy: 'onepackage'
27
+ default/tiramizoo_config/api_config/product_weight: 10
28
+ default/tiramizoo_config/api_config/product_width: 20
29
+ default/tiramizoo_config/api_config/product_height: 30
30
+ default/tiramizoo_config/api_config/product_length: 10
31
+ default/tiramizoo_config/advanced/debug_log: 1
32
+ default/tiramizoo_config/api_config/onepackage_weight: 2
33
+ default/tiramizoo_config/api_config/onepackage_width: 31
34
+ default/tiramizoo_config/api_config/onepackage_height: 21
35
+ default/tiramizoo_config/api_config/onepackage_length: 11
36
+ eav:
37
+ catalog_category:
38
+ # Root
39
+ - entity_id: 1
40
+ name: Root Category
41
+ attribute_set_id: 0
42
+ width: 77
43
+ path: 1
44
+ level: 0
45
+ position: 0
46
+ parent_id: 0
47
+ children_count: 1
48
+ is_active: 1
49
+ # category_products_width: 2
50
+ # category_products_height: 2
51
+ # category_products_length: 2
52
+ # Root > Watches
53
+ - entity_id: 2
54
+ name: Watches
55
+ width: 77
56
+ path: 1/2
57
+ level: 1
58
+ position: 1
59
+ parent_id: 1
60
+ children_count: 2
61
+ is_active: 1
62
+ tiramizoo_category_enable: 0
63
+ category_products_width: 12
64
+ category_products_weight: 13
65
+ category_products_height: 14
66
+ category_products_length: 15
67
+ # Root > Clothes
68
+ - entity_id: 3
69
+ name: Clothes
70
+ width: 77
71
+ path: 1/3
72
+ level: 1
73
+ position: 2
74
+ parent_id: 1
75
+ children_count: 1
76
+ is_active: 1
77
+ tiramizoo_category_enable: -1
78
+ category_products_width: 25
79
+ category_products_weight: 24
80
+ category_products_height: 23
81
+ category_products_length: 22
82
+ # Root > Watches > Analog
83
+ - entity_id: 4
84
+ name: Analog
85
+ width: 77
86
+ path: 1/2/4
87
+ level: 2
88
+ position: 1
89
+ parent_id: 2
90
+ children_count: 0
91
+ is_active: 1
92
+ # Root > Watches > Digital
93
+ - entity_id: 5
94
+ name: Digital
95
+ width: 77
96
+ path: 1/2/5
97
+ level: 2
98
+ position: 2
99
+ parent_id: 2
100
+ children_count: 0
101
+ is_active: 1
102
+ category_products_weight: 2
103
+ category_products_height: 2
104
+ category_products_length: 2
105
+ # Root > Clothes > Trausers
106
+ - entity_id: 6
107
+ name: Trousers
108
+ width: 77
109
+ path: 1/3/6
110
+ level: 2
111
+ position: 1
112
+ parent_id: 3
113
+ children_count: 1
114
+ is_active: 1
115
+ tiramizoo_category_enable: -1
116
+ # category_products_width: 20
117
+ # category_products_weight: 2
118
+ # category_products_height: 2
119
+ # category_products_length: 2
120
+ # Root > Clothes > Shirts
121
+ - entity_id: 7
122
+ name: Shirts
123
+ width: 77
124
+ path: 1/3/7
125
+ level: 2
126
+ position: 2
127
+ parent_id: 3
128
+ children_count: 1
129
+ is_active: 1
130
+ category_products_weight: 2
131
+ category_products_height: 2
132
+ category_products_length: 2
133
+ # Root > Clothes > Trousers > Jeans
134
+ - entity_id: 8
135
+ name: Jeans
136
+ width: 77
137
+ path: 1/3/6/8
138
+ level: 3
139
+ position: 1
140
+ parent_id: 6
141
+ children_count: 0
142
+ is_active: 1
143
+ # Root > Clothes > Shirts > V-Neck
144
+ - entity_id: 9
145
+ name: V-Neck
146
+ width: 77
147
+ path: 1/3/7/9
148
+ level: 3
149
+ position: 1
150
+ parent_id: 7
151
+ children_count: 0
152
+ is_active: 1
153
+ category_products_weight: 2
154
+ category_products_height: 2
155
+ category_products_length: 2
156
+ catalog_product:
157
+ - entity_id: 1
158
+ type_id: simple
159
+ sku: ampm
160
+ name: AM:PM
161
+ width: 5
162
+ # height: 7
163
+ # length: 6
164
+ # weight: 1
165
+ # tiramizoo_enable: 0
166
+ short_description: AM:PM
167
+ description: AM:PM
168
+ url_key: am-pm
169
+ stock: # product stock item
170
+ qty: 200.00
171
+ is_in_stock: 1
172
+ category_ids:
173
+ - 4    # Default Category
174
+ price: 129.99
175
+ tax_class_id: 2       # Taxable Goods
176
+ status: 1 # Enabled
177
+ visibility: 4         # Visible in Catalog & Search
178
+ - entity_id: 2
179
+ type_id: simple
180
+ sku: pc128g126
181
+ name: PC128-G126
182
+ # width: 6
183
+ # height: 5
184
+ # length: 8
185
+ # weight: 2
186
+ # tiramizoo_enable: 0
187
+ short_description: PC128-G126
188
+ description: PC128-G126
189
+ url_key: pc128-g126
190
+ stock: # product stock item
191
+ qty: 100.00
192
+ is_in_stock: 1
193
+ category_ids:
194
+ - 5    # Default Category
195
+ price: 109.99
196
+ tax_class_id: 2       # Taxable Goods
197
+ status: 1 # Enabled
198
+ visibility: 4         # Visible in Catalog & Search
199
+ - entity_id: 3
200
+ type_id: simple
201
+ sku: bigstar
202
+ name: Big Star 12
203
+ width: 30
204
+ height: 40
205
+ length: 20
206
+ weight: 17
207
+ tiramizoo_enable: 0
208
+ short_description: Big Star 12
209
+ description: Big Star 12
210
+ url_key: big-star-12
211
+ stock:
212
+ qty: 20.00
213
+ is_in_stock: 1
214
+ category_ids:
215
+ - 8
216
+ - 6
217
+ price: 59.99
218
+ tax_class_id: 2
219
+ status: 1 # Enabled
220
+ visibility: 4
221
+ - entity_id: 4
222
+ type_id: simple
223
+ sku: 123456
224
+ name: "H&M V-Neck shirt"
225
+ # width: 35
226
+ # height: 40
227
+ # length: 30
228
+ # weight: 29
229
+ tiramizoo_enable: 0
230
+ short_description: Shirt
231
+ description: Shirt
232
+ url_key: v-neck-shirt
233
+ stock:
234
+ qty: 20.00
235
+ is_in_stock: 1
236
+ category_ids:
237
+ - 9
238
+ price: 59.99
239
+ tax_class_id: 2
240
+ status: 1
241
+ visibility: 4
242
+ - entity_id: 5
243
+ type_id: simple
244
+ sku: 123456
245
+ name: Short Jeans
246
+ # width: 35
247
+ # height: 40
248
+ # length: 30
249
+ # weight: 29
250
+ tiramizoo_enable: -1
251
+ short_description: Short Jeans
252
+ description: Short Jeans
253
+ url_key: short-jeans
254
+ stock:
255
+ qty: 20.00
256
+ is_in_stock: 1
257
+ category_ids:
258
+ - 8
259
+ price: 59.99
260
+ tax_class_id: 2
261
+ status: 1
262
+ visibility: 4
263
+ - entity_id: 6
264
+ type_id: simple
265
+ sku: 1234567
266
+ name: New product
267
+ # width: 35
268
+ # height: 40
269
+ # length: 30
270
+ weight: 1
271
+ tiramizoo_enable: 0
272
+ short_description: New product
273
+ description: New product
274
+ url_key: url-1
275
+ stock:
276
+ qty: 210.00
277
+ is_in_stock: 1
278
+ # category_ids:
279
+ # - 8
280
+ price: 59.99
281
+ tax_class_id: 2
282
+ status: 1
283
+ visibility: 4
app/code/community/Tiramizoo/Shipping/Test/Helper/Build/providers/testBuildItems.yaml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -
2
+ -
3
+ 0: {id: 1, dimensions: {width: 20, height: 30, length: 20, weight: 4}, quantity: 1, description: null, packed_individually: false }
4
+ 1: {id: 2, dimensions: {width: 10, height: 31, length: 20, weight: 4}, quantity: 1, description: null, packed_individually: false }
5
+ - 'onepackage'
6
+ -
7
+ 0: {weight: 2, width: 31, height: 21, length: 11, quantity: 1, description: null }
8
+
9
+ -
10
+ -
11
+ 0: {id: 1, dimensions: {width: 20, height: 30, length: 20, weight: 4}, quantity: 1, description: null, packed_individually: false }
12
+ 1: {id: 4, dimensions: {width: 207, height: 360, length: 208, weight: 49}, quantity: 1, description: null, packed_individually: false }
13
+ 2: {id: 2, dimensions: {width: 20, height: 30, length: 20, weight: 2}, quantity: 1, description: null, packed_individually: false }
14
+ - 'onepackage'
15
+ -
16
+ 0: {weight: 2, width: 31, height: 21, length: 11, quantity: 1, description: null }
17
+
18
+ -
19
+ - []
20
+ - 'onepackage'
21
+ - []
22
+
23
+ -
24
+ -
25
+ 0: {id: 1, dimensions: {width: 22, height: 32, length: 42, weight: 4}, quantity: 1, description: 'some product 1', packed_individually: false }
26
+ 1: {id: 2, dimensions: {width: 33, height: 25, length: 27, weight: 1}, quantity: 2, description: 'some product 2', packed_individually: false }
27
+ - 'individual'
28
+ -
29
+ 0: {weight: 4, width: 22, height: 32, length: 42, quantity: 1, description: 'some product 1' }
30
+ 1: {weight: 1, width: 33, height: 25, length: 27, quantity: 2, description: 'some product 2' }
31
+
32
+ -
33
+ -
34
+ 0: {id: 1, dimensions: {width: 22, height: 32, length: 42, weight: 4}, quantity: 1, description: 'some product 1', packed_individually: false }
35
+ 1: {id: 2, dimensions: {width: 33, height: 25, length: 27, weight: 1}, quantity: 2, description: 'some product 2', packed_individually: false }
36
+ - 'packages'
37
+ -
38
+ 0: {weight: 4, width: 22, height: 32, length: 42, quantity: 1, description: 'some product 1', bundle: true }
39
+ 1: {weight: 1, width: 33, height: 25, length: 27, quantity: 2, description: 'some product 2', bundle: true }
app/code/community/Tiramizoo/Shipping/Test/Model/Category.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ class Tiramizoo_Shipping_Test_Model_Category extends EcomDev_PHPUnit_Test_Case
17
+ {
18
+ /**
19
+ * Product price calculation test *
20
+ * @test
21
+ * @loadFixture default
22
+ * @doNotIndexAll
23
+ * @dataProvider dataProvider
24
+ * */
25
+ public function testGetDimensions($categoryId, $params)
26
+ {
27
+ $storeId = Mage::app()->getStore(0)->getId();
28
+
29
+ $category = Mage::getModel('catalog/category')
30
+ ->setStoreId($storeId)
31
+ ->load($categoryId);
32
+
33
+ $dimensions = Mage::getModel('tiramizoo/category', $category)->getDimensions();
34
+
35
+ foreach($params as $key => $value) {
36
+ $this->assertEquals(
37
+ $dimensions[$key],
38
+ $value
39
+ );
40
+ }
41
+ }
42
+
43
+ /**
44
+ * @test
45
+ * @loadFixture default
46
+ * @doNotIndexAll
47
+ * */
48
+ public function test()
49
+ {
50
+ $this->assertEquals(
51
+ Mage::getStoreConfig('tiramizoo_config/api_config/product_length'),
52
+ 10
53
+ );
54
+ }
55
+
56
+ /**
57
+ * @test
58
+ * @loadFixture default
59
+ * @doNotIndexAll
60
+ * @dataProvider dataProvider
61
+ * */
62
+ public function testCart($productIds, $returnValue, $packageSizes)
63
+ {
64
+ $tiramizooCart = $this->getMock('Tiramizoo_Shipping_Model_Cart', array('getQuoteItems'));
65
+
66
+ $this->_productIds = $productIds;
67
+
68
+ $tiramizooCart->expects($this->any())
69
+ ->method('getQuoteItems')
70
+ ->will($this->returnCallback(
71
+ array($this, 'getAllItemsCallback')
72
+ ));
73
+
74
+ $this->assertEquals(
75
+ $tiramizooCart->checkCart($packageSizes),
76
+ $returnValue
77
+ );
78
+ }
79
+
80
+ public function getAllItemsCallback($productIds = array())
81
+ {
82
+ $items = array();
83
+ foreach ($this->_productIds as $productId) {
84
+ $product = Mage::getModel('catalog/product')->load($productId);
85
+ $items[] = Mage::getModel('sales/quote_item')->setProduct($product);
86
+ }
87
+ return $items;
88
+ }
89
+ }
app/code/community/Tiramizoo/Shipping/Test/Model/Category/fixtures/default.yaml ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Category Fixtures
2
+ scope:
3
+ website:
4
+ - website_id: 1
5
+ code: main
6
+ name: Main Website
7
+ default_group_id: 1
8
+ group:
9
+ - group_id: 1
10
+ website_id: 1
11
+ name: Main Website Store
12
+ root_category_id: 8
13
+ default_store_id: 1
14
+ store:
15
+ - store_id: 1
16
+ code: default
17
+ website_id: 1
18
+ group_id: 1
19
+ name: Default Store View
20
+ is_active: 1
21
+ config:
22
+ default/tiramizoo_config/api_config/api_url: https://sandbox.tiramizoo.com/api/v1
23
+ default/tiramizoo_config/api_config/product_width_mapping: width
24
+ default/tiramizoo_config/api_config/product_height_mapping: height
25
+ default/tiramizoo_config/api_config/product_length_mapping: length
26
+ default/tiramizoo_config/api_config/packing_strategy: individual
27
+ default/tiramizoo_config/api_config/product_weight: 10
28
+ default/tiramizoo_config/api_config/product_width: 20
29
+ default/tiramizoo_config/api_config/product_height: 30
30
+ default/tiramizoo_config/api_config/product_length: 10
31
+ default/tiramizoo_config/advanced/debug_log: 1
32
+ eav:
33
+ catalog_category:
34
+ # Root
35
+ - entity_id: 1
36
+ name: Root Category
37
+ attribute_set_id: 0
38
+ width: 77
39
+ path: 1
40
+ level: 0
41
+ position: 0
42
+ parent_id: 0
43
+ children_count: 1
44
+ is_active: 1
45
+ tiramizoo_category_enable: 0
46
+ # category_products_width: 20
47
+ category_products_weight: 2
48
+ category_products_height: 2
49
+ category_products_length: 2
50
+ # Root > Watches
51
+ - entity_id: 2
52
+ name: Watches
53
+ width: 77
54
+ path: 1/2
55
+ level: 1
56
+ position: 1
57
+ parent_id: 1
58
+ children_count: 2
59
+ is_active: 1
60
+ tiramizoo_category_enable: 0
61
+ category_products_width: 20
62
+ category_products_weight: 30
63
+ category_products_height: 40
64
+ category_products_length: 50
65
+ # Root > Clothes
66
+ - entity_id: 3
67
+ name: Clothes
68
+ width: 77
69
+ path: 1/3
70
+ level: 1
71
+ position: 2
72
+ parent_id: 1
73
+ children_count: 2
74
+ is_active: 1
75
+ tiramizoo_category_enable: 0
76
+ category_products_width: 30
77
+ category_products_weight: 40
78
+ category_products_height: 25
79
+ category_products_length: 10
80
+ # Root > Watches > Analog
81
+ - entity_id: 4
82
+ name: Analog
83
+ width: 77
84
+ path: 1/2/4
85
+ level: 2
86
+ position: 1
87
+ parent_id: 2
88
+ children_count: 0
89
+ is_active: 1
90
+ tiramizoo_category_enable: 0
91
+ # category_products_width: 20
92
+ category_products_weight: 2
93
+ category_products_height: 2
94
+ category_products_length: 2
95
+ # Root > Watches > Digital
96
+ - entity_id: 5
97
+ name: Digital
98
+ width: 77
99
+ path: 1/2/5
100
+ level: 2
101
+ position: 2
102
+ parent_id: 2
103
+ children_count: 0
104
+ is_active: 1
105
+ tiramizoo_category_enable: 0
106
+ # category_products_width: 20
107
+ category_products_weight: 2
108
+ category_products_height: 2
109
+ category_products_length: 2
110
+ # Root > Clothes > Trausers
111
+ - entity_id: 6
112
+ name: Trousers
113
+ width: 77
114
+ path: 1/3/6
115
+ level: 2
116
+ position: 1
117
+ parent_id: 3
118
+ children_count: 1
119
+ is_active: 1
120
+ # tiramizoo_category_enable: 0
121
+ # category_products_width: 20
122
+ # category_products_weight: 2
123
+ # category_products_height: 2
124
+ # category_products_length: 2
125
+ # Root > Clothes > Shirts
126
+ - entity_id: 7
127
+ name: Shirts
128
+ width: 77
129
+ path: 1/3/7
130
+ level: 2
131
+ position: 2
132
+ parent_id: 3
133
+ children_count: 1
134
+ is_active: 1
135
+ tiramizoo_category_enable: 0
136
+ # category_products_width: 20
137
+ category_products_weight: 2
138
+ category_products_height: 2
139
+ category_products_length: 2
140
+ # Root > Clothes > Trousers > Jeans
141
+ - entity_id: 8
142
+ name: Jeans
143
+ width: 77
144
+ path: 1/3/6/8
145
+ level: 3
146
+ position: 1
147
+ parent_id: 6
148
+ children_count: 0
149
+ is_active: 1
150
+ tiramizoo_category_enable: 0
151
+ category_products_width: 20
152
+ category_products_weight: 20
153
+ category_products_height: 20
154
+ category_products_length: 20
155
+ # Root > Clothes > Shirts > V-Neck
156
+ - entity_id: 9
157
+ name: V-Neck
158
+ width: 77
159
+ path: 1/3/7/9
160
+ level: 3
161
+ position: 1
162
+ parent_id: 7
163
+ children_count: 0
164
+ is_active: 1
165
+ tiramizoo_category_enable: 0
166
+ # category_products_width: 20
167
+ category_products_weight: 2
168
+ category_products_height: 2
169
+ category_products_length: 2
170
+ catalog_product:
171
+ - entity_id: 1
172
+ type_id: simple
173
+ sku: ampm
174
+ name: AM:PM
175
+ width: 5
176
+ # height: 7
177
+ length: 6
178
+ weight: 1
179
+ tiramizoo_enable: 0
180
+ short_description: AM:PM
181
+ description: AM:PM
182
+ url_key: am-pm
183
+ stock: # product stock item
184
+ qty: 200.00
185
+ is_in_stock: 1
186
+ category_ids:
187
+ - 4    # Default Category
188
+ price: 129.99
189
+ tax_class_id: 2       # Taxable Goods
190
+ status: 1 # Enabled
191
+ visibility: 4         # Visible in Catalog & Search
192
+ - entity_id: 2
193
+ type_id: simple
194
+ sku: pc128g126
195
+ name: PC128-G126
196
+ width: 6
197
+ height: 5
198
+ length: 8
199
+ weight: 2
200
+ tiramizoo_enable: 0
201
+ short_description: PC128-G126
202
+ description: PC128-G126
203
+ url_key: pc128-g126
204
+ stock: # product stock item
205
+ qty: 100.00
206
+ is_in_stock: 1
207
+ category_ids:
208
+ - 5    # Default Category
209
+ price: 109.99
210
+ tax_class_id: 2       # Taxable Goods
211
+ status: 1 # Enabled
212
+ visibility: 4         # Visible in Catalog & Search
213
+ - entity_id: 3
214
+ type_id: simple
215
+ sku: bigstar
216
+ name: Big Star 12
217
+ # width: 30
218
+ # height: 40
219
+ # length: 20
220
+ weight: 17
221
+ tiramizoo_enable: 0
222
+ short_description: Big Star 12
223
+ description: Big Star 12
224
+ url_key: big-star-12
225
+ stock:
226
+ qty: 20.00
227
+ is_in_stock: 1
228
+ category_ids:
229
+ - 8
230
+ - 6
231
+ price: 59.99
232
+ tax_class_id: 2
233
+ status: 1 # Enabled
234
+ visibility: 4
235
+ - entity_id: 4
236
+ type_id: simple
237
+ sku: 123456
238
+ name: "< Weight product"
239
+ width: 35
240
+ height: 40
241
+ length: 30
242
+ weight: 41
243
+ tiramizoo_enable: 0
244
+ - entity_id: 5
245
+ type_id: simple
246
+ sku: 123456
247
+ name: "Big product"
248
+ width: 100
249
+ height: 110
250
+ length: 220
251
+ weight: 30
252
+ tiramizoo_enable: 0
app/code/community/Tiramizoo/Shipping/Test/Model/Category/providers/testCart.yaml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # [ ProductIds, ... ]
2
+ # testCart: true/false
3
+ # [ PackageSizes ] //temporary
4
+ -
5
+ - []
6
+ - false
7
+ -
8
+ 0: { name: XXL, max_weight: 40, size: 310, express: true, standard_price: 1094, express_price: 1495 }
9
+
10
+ -
11
+ - [ 2 ]
12
+ - true
13
+ -
14
+ 0: { name: XXL, max_weight: 40, size: 310, express: true, standard_price: 1094, express_price: 1495 }
15
+
16
+ -
17
+ - [ 3 ]
18
+ - true
19
+ -
20
+ 0: { name: XXL, max_weight: 40, size: 310, express: true, standard_price: 1094, express_price: 1495 }
21
+
22
+ -
23
+ - [ 2, 3 ]
24
+ - true
25
+ -
26
+ 0: { name: XXL, max_weight: 40, size: 310, express: true, standard_price: 1094, express_price: 1495 }
27
+
28
+ -
29
+ - [ 4 ]
30
+ - false
31
+ -
32
+ 0: { name: XXL, max_weight: 40, size: 310, express: true, standard_price: 1094, express_price: 1495 }
33
+
34
+ -
35
+ - [ 5 ]
36
+ - false
37
+ -
38
+ 0: { name: XXL, max_weight: 40, size: 310, express: true, standard_price: 1094, express_price: 1495 }
app/code/community/Tiramizoo/Shipping/Test/Model/Category/providers/testGetDimensions.yaml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -
2
+ # - categoryId
3
+ # - { testParam: testValue, ... }
4
+ #
5
+ -
6
+ - 2
7
+ - { width: 20, height: 40 }
8
+ -
9
+ - 6
10
+ - { length: 10, weight: 40, destination_id: 3 }
11
+ -
12
+ - 8
13
+ - { width: 20, length: 20, size: 40, destination_type: category, destination_id: 8 }
14
+ -
15
+ - 9
16
+ - { size: 40, destination_type: category, destination_id: 3 }
17
+ -
18
+ - 5
19
+ - { size: 70, destination_type: category, destination_id: 2 }
20
+ -
21
+ - 1
22
+ - { size: 40, destination_type: config }
app/code/community/Tiramizoo/Shipping/Test/Model/Product.php ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ class Tiramizoo_Shipping_Test_Model_Product extends EcomDev_PHPUnit_Test_Case
17
+ {
18
+
19
+ /**
20
+ * Product getDimensions test
21
+ * @test
22
+ * @loadFixture default
23
+ * @doNotIndexAll
24
+ * @dataProvider dataProvider
25
+ * */
26
+ public function testGetDimensions($productId, $params)
27
+ {
28
+ $storeId = Mage::app()->getStore(0)->getId();
29
+
30
+ $product = Mage::getModel('catalog/product')->load($productId);
31
+ $dimensions = Mage::getModel('tiramizoo/product', $product)->getDimensions();
32
+
33
+ foreach($params as $key => $value) {
34
+ $this->assertEquals(
35
+ $dimensions[$key],
36
+ $value
37
+ );
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Product tests
43
+ *
44
+ * @test
45
+ * @loadFixture default
46
+ * @doNotIndexAll
47
+ */
48
+ public function testProduct()
49
+ {
50
+ $rootCat = Mage::getModel('catalog/category')->load(6);
51
+
52
+ $this->assertEquals(
53
+ $rootCat->getName(),
54
+ 'Trousers'
55
+ );
56
+
57
+ $this->assertEquals(
58
+ $rootCat->getChildren(),
59
+ '8'
60
+ );
61
+
62
+ $this->assertEquals(
63
+ $rootCat->getData('category_products_width'),
64
+ null
65
+ );
66
+
67
+ $apiUrl = Mage::getStoreConfig('tiramizoo_config/api_config/api_url');
68
+
69
+ $this->assertEquals(
70
+ $apiUrl,
71
+ 'https://sandbox.tiramizoo.com/api/v1'
72
+ );
73
+
74
+ $storeId = Mage::app()->getStore(0)->getId();
75
+ $product = Mage::getModel('catalog/product')
76
+ ->setStoreId($storeId)
77
+ ->load(1);
78
+
79
+
80
+ $category = Mage::getModel('catalog/category')
81
+ ->setStoreId($storeId)
82
+ ->load(5);
83
+
84
+ $this->assertEquals(
85
+ $category->getName(),
86
+ 'Digital'
87
+ );
88
+
89
+
90
+ $this->assertEquals(
91
+ $product->getName(),
92
+ 'AM:PM'
93
+ );
94
+
95
+ // var_dump($product->getData('tiramizoo_category_enable'));
96
+
97
+ $this->assertEquals(
98
+ $product->getWidth(),
99
+ 5
100
+ );
101
+
102
+ $category = Mage::getModel('tiramizoo/category_attributes', Mage::getModel('catalog/category')->load(8));
103
+
104
+ $this->assertEquals(
105
+ (bool) $category->getDimensions(),
106
+ false
107
+ );
108
+
109
+ }
110
+
111
+ /**
112
+ * Category names test
113
+ * @test
114
+ * @loadFixture default
115
+ * @doNotIndexAll
116
+ * @dataProvider dataProvider
117
+ * */
118
+ public function testCategoryGetNames($id, $name)
119
+ {
120
+ $storeId = Mage::app()->getStore(0)->getId();
121
+
122
+ $category = Mage::getModel('catalog/category')
123
+ ->setStoreId($storeId)
124
+ ->load($id);
125
+
126
+ $this->assertEquals(
127
+ $category->getName(),
128
+ $name
129
+ );
130
+ }
131
+
132
+ /**
133
+ * @test
134
+ * @loadFixture default
135
+ * @doNotIndexAll
136
+ * @dataProvider dataProvider
137
+ * */
138
+ public function testProductIsAvailableToTiramizooDelivery($productId, $value)
139
+ {
140
+ $storeId = Mage::app()->getStore(0)->getId();
141
+
142
+ $product = Mage::getModel('catalog/product')
143
+ ->setStoreId($storeId)
144
+ ->load($productId);
145
+
146
+ $tiramizooProduct = Mage::getModel('tiramizoo/product', $product);
147
+
148
+ $this->assertEquals(
149
+ $tiramizooProduct->isAvailable(),
150
+ $value
151
+ );
152
+ }
153
+
154
+ /**
155
+ * @test
156
+ * @loadFixture default
157
+ * @doNotIndexAll
158
+ * @dataProvider dataProvider
159
+ * */
160
+ public function testProductIsPackedIndividually($productId, $value, $packingStrategy = 'packages')
161
+ {
162
+ $storeId = Mage::app()->getStore(0)->getId();
163
+
164
+ $product = Mage::getModel('catalog/product')
165
+ ->setStoreId($storeId)
166
+ ->load($productId);
167
+
168
+ $tiramizooProduct = $this->getModelMock('tiramizoo/product', array('getPackingStrategy'), false, array($product));
169
+
170
+ $tiramizooProduct->expects($this->any())
171
+ ->method('getPackingStrategy')
172
+ ->will($this->returnValue($packingStrategy));
173
+
174
+ // $tiramizooProduct = Mage::getModel('tiramizoo/product', $product);
175
+
176
+ $this->assertEquals(
177
+ $tiramizooProduct->isPackedIndividually(),
178
+ $value
179
+ );
180
+ }
181
+
182
+ }
app/code/community/Tiramizoo/Shipping/Test/Model/Product/fixtures/default.yaml ADDED
@@ -0,0 +1,372 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Product Fixtures
2
+ scope:
3
+ website:
4
+ - website_id: 1
5
+ code: main
6
+ name: Main Website
7
+ default_group_id: 1
8
+ group:
9
+ - group_id: 1
10
+ website_id: 1
11
+ name: Main Website Store
12
+ root_category_id: 8
13
+ default_store_id: 1
14
+ store:
15
+ - store_id: 1
16
+ code: default
17
+ website_id: 1
18
+ group_id: 1
19
+ name: Default Store View
20
+ is_active: 1
21
+ config:
22
+ default/tiramizoo_config/api_config/api_url: https://sandbox.tiramizoo.com/api/v1
23
+ default/tiramizoo_config/api_config/product_width_mapping: width
24
+ default/tiramizoo_config/api_config/product_height_mapping: height
25
+ default/tiramizoo_config/api_config/product_length_mapping: length
26
+ default/tiramizoo_config/api_config/packing_strategy: onepackage
27
+ default/tiramizoo_config/api_config/product_weight: 10
28
+ default/tiramizoo_config/api_config/product_width: 20
29
+ default/tiramizoo_config/api_config/product_height: 30
30
+ default/tiramizoo_config/api_config/product_length: 10
31
+ default/tiramizoo_config/advanced/debug_log: 1
32
+ eav:
33
+ catalog_category:
34
+ # Root
35
+ - entity_id: 1
36
+ name: Root Category
37
+ attribute_set_id: 0
38
+ width: 77
39
+ path: 1
40
+ level: 0
41
+ position: 0
42
+ parent_id: 0
43
+ children_count: 1
44
+ is_active: 1
45
+ # category_products_width: 2
46
+ # category_products_height: 2
47
+ # category_products_length: 2
48
+ # Root > Watches
49
+ - entity_id: 2
50
+ name: Watches
51
+ width: 77
52
+ path: 1/2
53
+ level: 1
54
+ position: 1
55
+ parent_id: 1
56
+ children_count: 2
57
+ is_active: 1
58
+ tiramizoo_category_enable: 0
59
+ trmz_cat_packed_individually: 0
60
+ category_products_width: 12
61
+ category_products_weight: 13
62
+ category_products_height: 14
63
+ category_products_length: 15
64
+ # Root > Clothes
65
+ - entity_id: 3
66
+ name: Clothes
67
+ width: 77
68
+ path: 1/3
69
+ level: 1
70
+ position: 2
71
+ parent_id: 1
72
+ children_count: 1
73
+ is_active: 1
74
+ tiramizoo_category_enable: -1
75
+ category_products_width: 25
76
+ category_products_weight: 24
77
+ category_products_height: 23
78
+ category_products_length: 22
79
+ # Root > Watches > Analog
80
+ - entity_id: 4
81
+ name: Analog
82
+ width: 77
83
+ path: 1/2/4
84
+ level: 2
85
+ position: 1
86
+ parent_id: 2
87
+ children_count: 0
88
+ is_active: 1
89
+ # Root > Watches > Digital
90
+ - entity_id: 5
91
+ name: Digital
92
+ width: 77
93
+ path: 1/2/5
94
+ level: 2
95
+ position: 2
96
+ parent_id: 2
97
+ children_count: 0
98
+ is_active: 1
99
+ trmz_cat_packed_individually: 0
100
+ category_products_weight: 2
101
+ category_products_height: 2
102
+ category_products_length: 2
103
+ # Root > Clothes > Trausers
104
+ - entity_id: 6
105
+ name: Trousers
106
+ width: 77
107
+ path: 1/3/6
108
+ level: 2
109
+ position: 1
110
+ parent_id: 3
111
+ children_count: 1
112
+ is_active: 1
113
+ tiramizoo_category_enable: -1
114
+ trmz_cat_packed_individually: -1
115
+ # category_products_width: 20
116
+ # category_products_weight: 2
117
+ # category_products_height: 2
118
+ # category_products_length: 2
119
+ # Root > Clothes > Shirts
120
+ - entity_id: 7
121
+ name: Shirts
122
+ width: 77
123
+ path: 1/3/7
124
+ level: 2
125
+ position: 2
126
+ parent_id: 3
127
+ children_count: 1
128
+ is_active: 1
129
+ category_products_weight: 2
130
+ category_products_height: 2
131
+ category_products_length: 2
132
+ # Root > Clothes > Trousers > Jeans
133
+ - entity_id: 8
134
+ name: Jeans
135
+ width: 77
136
+ path: 1/3/6/8
137
+ level: 3
138
+ position: 1
139
+ parent_id: 6
140
+ children_count: 0
141
+ is_active: 1
142
+ trmz_cat_packed_individually: 1
143
+ # Root > Clothes > Shirts > V-Neck
144
+ - entity_id: 9
145
+ name: V-Neck
146
+ width: 77
147
+ path: 1/3/7/9
148
+ level: 3
149
+ position: 1
150
+ parent_id: 7
151
+ children_count: 0
152
+ is_active: 1
153
+ category_products_weight: 2
154
+ category_products_height: 2
155
+ category_products_length: 2
156
+ # Root > Computers
157
+ - entity_id: 10
158
+ name: Computers
159
+ width: 77
160
+ path: 1/10
161
+ level: 1
162
+ position: 1
163
+ parent_id: 1
164
+ children_count: 0
165
+ is_active: 1
166
+ trmz_cat_packed_individually: -1
167
+ # category_products_weight: 2
168
+ # category_products_height: 2
169
+ # category_products_length: 2
170
+ catalog_product:
171
+ - entity_id: 1
172
+ type_id: simple
173
+ sku: ampm
174
+ name: AM:PM
175
+ width: 5
176
+ # height: 7
177
+ # length: 6
178
+ # weight: 1
179
+ # tiramizoo_enable: 0
180
+ tiramizoo_packed_individually: 0
181
+ short_description: AM:PM
182
+ description: AM:PM
183
+ url_key: am-pm
184
+ stock: # product stock item
185
+ qty: 200.00
186
+ is_in_stock: 1
187
+ category_ids:
188
+ - 4    # Default Category
189
+ price: 129.99
190
+ tax_class_id: 2       # Taxable Goods
191
+ status: 1 # Enabled
192
+ visibility: 4         # Visible in Catalog & Search
193
+ - entity_id: 2
194
+ type_id: simple
195
+ sku: pc128g126
196
+ name: PC128-G126
197
+ # width: 6
198
+ # height: 5
199
+ # length: 8
200
+ # weight: 2
201
+ # tiramizoo_enable: 0
202
+ tiramizoo_packed_individually: 0
203
+ short_description: PC128-G126
204
+ description: PC128-G126
205
+ url_key: pc128-g126
206
+ stock: # product stock item
207
+ qty: 100.00
208
+ is_in_stock: 1
209
+ category_ids:
210
+ - 5    # Default Category
211
+ price: 109.99
212
+ tax_class_id: 2       # Taxable Goods
213
+ status: 1 # Enabled
214
+ visibility: 4         # Visible in Catalog & Search
215
+ - entity_id: 3
216
+ type_id: simple
217
+ sku: bigstar
218
+ name: Big Star 12
219
+ width: 30
220
+ height: 40
221
+ length: 20
222
+ weight: 17
223
+ tiramizoo_enable: 0
224
+ tiramizoo_packed_individually: 0
225
+ short_description: Big Star 12
226
+ description: Big Star 12
227
+ url_key: big-star-12
228
+ stock:
229
+ qty: 20.00
230
+ is_in_stock: 1
231
+ category_ids:
232
+ - 8
233
+ - 6
234
+ price: 59.99
235
+ tax_class_id: 2
236
+ status: 1 # Enabled
237
+ visibility: 4
238
+ - entity_id: 4
239
+ type_id: simple
240
+ sku: 123456
241
+ name: "H&M V-Neck shirt"
242
+ # width: 35
243
+ # height: 40
244
+ # length: 30
245
+ # weight: 29
246
+ tiramizoo_enable: 0
247
+ tiramizoo_packed_individually: 1
248
+ short_description: Shirt
249
+ description: Shirt
250
+ url_key: v-neck-shirt
251
+ stock:
252
+ qty: 20.00
253
+ is_in_stock: 1
254
+ category_ids:
255
+ - 9
256
+ price: 59.99
257
+ tax_class_id: 2
258
+ status: 1
259
+ visibility: 4
260
+ - entity_id: 5
261
+ type_id: simple
262
+ sku: 123456
263
+ name: Short Jeans
264
+ # width: 35
265
+ # height: 40
266
+ # length: 30
267
+ # weight: 29
268
+ tiramizoo_enable: -1
269
+ tiramizoo_packed_individually: 0
270
+ short_description: Short Jeans
271
+ description: Short Jeans
272
+ url_key: short-jeans
273
+ stock:
274
+ qty: 20.00
275
+ is_in_stock: 1
276
+ category_ids:
277
+ - 8
278
+ price: 59.99
279
+ tax_class_id: 2
280
+ status: 1
281
+ visibility: 4
282
+ - entity_id: 6
283
+ type_id: simple
284
+ sku: 1234567
285
+ name: New product
286
+ # width: 35
287
+ # height: 40
288
+ # length: 30
289
+ weight: 1
290
+ tiramizoo_enable: 0
291
+ tiramizoo_packed_individually: 1
292
+ short_description: New product
293
+ description: New product
294
+ url_key: url-1
295
+ stock:
296
+ qty: 210.00
297
+ is_in_stock: 1
298
+ # category_ids:
299
+ # - 8
300
+ price: 59.99
301
+ tax_class_id: 2
302
+ status: 1
303
+ visibility: 4
304
+ - entity_id: 7
305
+ type_id: simple
306
+ sku: 1234567
307
+ name: New product for test paths
308
+ # width: 35
309
+ # height: 40
310
+ # length: 30
311
+ weight: 1
312
+ tiramizoo_enable: 0
313
+ tiramizoo_packed_individually: 0
314
+ short_description: New product for test paths
315
+ description: New product for test paths
316
+ url_key: url-2
317
+ stock:
318
+ qty: 10.00
319
+ is_in_stock: 1
320
+ category_ids:
321
+ - 8
322
+ - 6
323
+ - 5
324
+ - 2
325
+ price: 59.99
326
+ tax_class_id: 2
327
+ status: 1
328
+ visibility: 4
329
+ - entity_id: 8
330
+ type_id: simple
331
+ sku: 1234567
332
+ name: New clean product
333
+ # width: 35
334
+ # height: 40
335
+ # length: 30
336
+ # weight: 1
337
+ tiramizoo_enable: 0
338
+ tiramizoo_packed_individually: 1
339
+ short_description: New clean product
340
+ description: New clean product
341
+ url_key: new-clean-product
342
+ stock:
343
+ qty: 100.00
344
+ is_in_stock: 1
345
+ category_ids:
346
+ - 10
347
+ price: 59.99
348
+ tax_class_id: 2
349
+ status: 1
350
+ visibility: 4
351
+ - entity_id: 9
352
+ type_id: simple
353
+ sku: 1234567
354
+ name: New product
355
+ # width: 35
356
+ # height: 40
357
+ # length: 30
358
+ weight: 1
359
+ tiramizoo_enable: 0
360
+ tiramizoo_packed_individually: 0
361
+ short_description: New product
362
+ description: New product
363
+ url_key: url-1
364
+ stock:
365
+ qty: 210.00
366
+ is_in_stock: 1
367
+ # category_ids:
368
+ # - 8
369
+ price: 59.99
370
+ tax_class_id: 2
371
+ status: 1
372
+ visibility: 4
app/code/community/Tiramizoo/Shipping/Test/Model/Product/providers/testCategoryGetNames.yaml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -
2
+ - 1
3
+ - Root Category
4
+ -
5
+ - 3
6
+ - Clothes
7
+ -
8
+ - 4
9
+ - Analog
10
+ -
11
+ - 7
12
+ - Shirts
13
+ -
14
+ - 9
15
+ - V-Neck
app/code/community/Tiramizoo/Shipping/Test/Model/Product/providers/testGetDimensions.yaml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -
2
+ # - ProductId
3
+ # - { testParam: testValue, ... }
4
+ #
5
+ -
6
+ - 1
7
+ - { width: 12, height: 14 }
8
+
9
+ -
10
+ - 2
11
+ - { length: 15, weight: 13, destination_id: 2 }
12
+
13
+ -
14
+ - 3
15
+ - { length: 20, destination_type: product }
16
+
17
+ -
18
+ - 6
19
+ - { length: 10, destination_type: config }
20
+
21
+ -
22
+ - 4
23
+ - { height: 23, destination_type: category, destination_id: 3 }
24
+
25
+ -
26
+ - 7
27
+ - { width: 25, length: 22, size: 47, destination_type: category, destination_id: 3 }
app/code/community/Tiramizoo/Shipping/Test/Model/Product/providers/testProductIsAvailableToTiramizooDelivery.yaml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -
2
+ - 1
3
+ - true
4
+ -
5
+ - 2
6
+ - true
7
+ -
8
+ - 4
9
+ - false
10
+ -
11
+ - 5
12
+ - false
13
+ -
14
+ - 6
15
+ - true
16
+ -
17
+ - 7
18
+ - false
19
+ -
20
+ - 8
21
+ - true
app/code/community/Tiramizoo/Shipping/Test/Model/Product/providers/testProductIsPackedIndividually.yaml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -
2
+ - 1
3
+ - false
4
+ -
5
+ - 2
6
+ - false
7
+ -
8
+ - 4
9
+ - true
10
+ -
11
+ - 5
12
+ - false
13
+ -
14
+ - 6
15
+ - true
16
+ -
17
+ - 7
18
+ - false
19
+ -
20
+ - 8 # product_id
21
+ - true # isPackedIndividually
22
+ - individual # packingStrategy
23
+ -
24
+ - 9
25
+ - true
26
+ - individual # packingStrategy
27
+ -
28
+ - 9
29
+ - false
app/code/community/Tiramizoo/Shipping/controllers/Adminhtml/SynchronizeController.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Synchronize configuration with all reatial locations
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_Adminhtml_SynchronizeController extends Mage_Adminhtml_Controller_Action
24
+ {
25
+ /**
26
+ * Run config synchronization for all retail locations
27
+ *
28
+ * @return null
29
+ */
30
+ public function indexAction()
31
+ {
32
+ Mage::getModel('tiramizoo/retaillocations')->synchronize();
33
+
34
+ $message = $this->__('Retail location configs were synchronised successfully');
35
+ Mage::getSingleton('core/session')->addSuccess($message);
36
+
37
+ //@todo: multistore enable
38
+ $url = $this->getUrl("adminhtml/system_config/edit", array('section'=>'tiramizoo_config'));
39
+ Mage::app()->getResponse()->setRedirect($url);
40
+ return;
41
+ }
42
+ }
app/code/community/Tiramizoo/Shipping/controllers/IndexController.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Base tiramizoo front end actions
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_IndexController extends Mage_Core_Controller_Front_Action
24
+ {
25
+ /**
26
+ * Check time window hash
27
+ *
28
+ * @return null
29
+ */
30
+ public function checkTimeWindowAction()
31
+ {
32
+ $post = $this->getRequest();
33
+
34
+ $json = array('valid' => false);
35
+
36
+ if ($post) {
37
+ $shippingMethod = $post->getParam('shippingMethod');
38
+ $hash = $post->getParam('hash');
39
+
40
+ $rates = Mage::helper('tiramizoo_shipping/data')->getAvailableShippingRates();
41
+
42
+ if (array_key_exists($shippingMethod, $rates)) {
43
+ $apiToken = Mage::getSingleton('checkout/session')->getData('tiramizoo_api_token');
44
+ if ($apiToken) {
45
+ $retailLocation = Mage::getModel('tiramizoo/retaillocation', array('api_token' => $apiToken));
46
+ $rateModel = Mage::getModel('tiramizoo/delivery_type_'.$rates[$shippingMethod], $retailLocation);
47
+
48
+ if ($rateModel->hasTimeWindow($hash)) {
49
+ $json = array('valid' => true);
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ $this->getResponse()
56
+ ->clearHeaders()
57
+ ->setHeader('Content-Type', 'application/json')
58
+ ->setBody(json_encode($json));
59
+ }
60
+ }
app/code/community/Tiramizoo/Shipping/controllers/WebhookController.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Webhook controller
18
+ *
19
+ * @category module
20
+ * @package Tiramizoo_Shipping
21
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
22
+ */
23
+ class Tiramizoo_Shipping_WebhookController extends Mage_Core_Controller_Front_Action
24
+ {
25
+
26
+ /**
27
+ * Retrieve webhook call data and handle with proper method.
28
+ *
29
+ * @return null
30
+ */
31
+ public function renderAction()
32
+ {
33
+ // get API data
34
+ $apiResponse = json_decode(file_get_contents('php://input'));
35
+
36
+ if ($apiResponse && isset($apiResponse->external_id)) {
37
+ $this->saveOrderStatus($apiResponse);
38
+ } else {
39
+ $response = Mage::app()->getResponse();
40
+ $response->setHttpResponseCode(500);
41
+ $response->setBody('FALSE');
42
+ }
43
+
44
+ }
45
+
46
+ /**
47
+ * Set order's status from API response
48
+ *
49
+ * @param stdObject $apiResponse Webhook call response data
50
+ * @return null
51
+ */
52
+ private function saveOrderStatus($apiResponse)
53
+ {
54
+
55
+ $tiramizooOrder = Mage::getModel('tiramizoo/order')
56
+ ->load($apiResponse->external_id, 'external_id')
57
+ ->setStatus($apiResponse->state)
58
+ ->setWebhookResponse(json_encode($apiResponse))
59
+ ->setWebhookUpdatedAt(time())
60
+ ->save();
61
+
62
+ $response = Mage::app()->getResponse();
63
+ $response->setHttpResponseCode(200);
64
+ $response->setBody('OK');
65
+
66
+ }
67
+
68
+ }
app/code/community/Tiramizoo/Shipping/etc/config.xml ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+
4
+ <modules>
5
+ <Tiramizoo_Shipping>
6
+ <version>0.1.0</version>
7
+ </Tiramizoo_Shipping>
8
+ </modules>
9
+
10
+ <default>
11
+ <carriers>
12
+ <tiramizoo>
13
+ <active>1</active>
14
+ <sallowspecific>0</sallowspecific>
15
+ <model>Tiramizoo_Shipping_Model_Carrier_Tiramizoo</model>
16
+ <name>Tiramizoo</name>
17
+ <title>Tiramizoo</title>
18
+ <specificerrmsg>
19
+ This shipping method is currently unavailable.
20
+ If you would like to ship using this shipping
21
+ method, please contact us.
22
+ </specificerrmsg>
23
+ <handling_type>F</handling_type>
24
+ </tiramizoo>
25
+ </carriers>
26
+ </default>
27
+
28
+
29
+ <global>
30
+ <models>
31
+ <tiramizoo>
32
+ <class>Tiramizoo_Shipping_Model</class>
33
+ <resourceModel>tiramizoo_mysql4</resourceModel>
34
+ </tiramizoo>
35
+
36
+ <tiramizoo_mysql4>
37
+ <class>Tiramizoo_Shipping_Model_Mysql4</class>
38
+ <entities>
39
+ <order>
40
+ <table>tiramizoo_order</table>
41
+ </order>
42
+ </entities>
43
+ </tiramizoo_mysql4>
44
+
45
+ <checkout>
46
+ <rewrite>
47
+ <type_onepage>Tiramizoo_Shipping_Model_Type_Onepage</type_onepage>
48
+ </rewrite>
49
+ </checkout>
50
+ </models>
51
+
52
+ <blocks>
53
+ <tiramizoo>
54
+ <class>Tiramizoo_Shipping_Block</class>
55
+ </tiramizoo>
56
+ </blocks>
57
+
58
+ <resources>
59
+ <tiramizoo_setup>
60
+ <setup>
61
+ <module>Tiramizoo_Shipping</module>
62
+ </setup>
63
+ <connection>
64
+ <use>core_setup</use>
65
+ </connection>
66
+ </tiramizoo_setup>
67
+ <tiramizoo_write>
68
+ <connection>
69
+ <use>core_write</use>
70
+ </connection>
71
+ </tiramizoo_write>
72
+ <tiramizoo_read>
73
+ <connection>
74
+ <use>core_read</use>
75
+ </connection>
76
+ </tiramizoo_read>
77
+ </resources>
78
+
79
+ <helpers>
80
+ <tiramizoo_shipping>
81
+ <class>Tiramizoo_Shipping_Helper</class>
82
+ </tiramizoo_shipping>
83
+ </helpers>
84
+
85
+ <events>
86
+ <admin_system_config_changed_section_tiramizoo_config>
87
+ <observers>
88
+ <tiramizoo_config_changed>
89
+ <type>singleton</type>
90
+ <class>Tiramizoo_Shipping_Model_Observer</class>
91
+ <method>changeConfig</method>
92
+ </tiramizoo_config_changed>
93
+ </observers>
94
+ </admin_system_config_changed_section_tiramizoo_config>
95
+
96
+ <sales_model_service_quote_submit_success>
97
+ <observers>
98
+ <tiramizoo_quote_submit_success>
99
+ <type>singleton</type>
100
+ <class>Tiramizoo_Shipping_Model_Observer</class>
101
+ <method>saveOrderSuccess</method>
102
+ </tiramizoo_quote_submit_success>
103
+ </observers>
104
+ </sales_model_service_quote_submit_success>
105
+
106
+ <checkout_type_onepage_save_order_before>
107
+ <observers>
108
+ <tiramizoo_checkout_type_onepage_save_order_before>
109
+ <type>singleton</type>
110
+ <class>Tiramizoo_Shipping_Model_Observer</class>
111
+ <method>saveOrderBefore</method>
112
+ </tiramizoo_checkout_type_onepage_save_order_before>
113
+ </observers>
114
+ </checkout_type_onepage_save_order_before>
115
+
116
+ <checkout_controller_onepage_save_shipping_method>
117
+ <observers>
118
+ <tiramizoo_save_shipping_method_data>
119
+ <type>singleton</type>
120
+ <class>Tiramizoo_Shipping_Model_Observer</class>
121
+ <method>saveShippingMethod</method>
122
+ </tiramizoo_save_shipping_method_data>
123
+ </observers>
124
+ </checkout_controller_onepage_save_shipping_method>
125
+
126
+ <payment_method_is_active>
127
+ <observers>
128
+ <tiramizoo_payment_methods>
129
+ <type>singleton</type>
130
+ <class>Tiramizoo_Shipping_Model_Observer</class>
131
+ <method>paymentMethodIsActive</method>
132
+ </tiramizoo_payment_methods>
133
+ </observers>
134
+ </payment_method_is_active>
135
+
136
+ <!-- START Test Events -->
137
+ <!-- <tiramizoo_shipping_convert_product_dimensions>
138
+ <observers>
139
+ <convert_product_dimensions>
140
+ <type>singleton</type>
141
+ <class>Tiramizoo_Shipping_Model_TestObserver</class>
142
+ <method>convertProductDimensions</method>
143
+ </convert_product_dimensions>
144
+ </observers>
145
+ </tiramizoo_shipping_convert_product_dimensions>
146
+
147
+ <tiramizoo_shipping_convert_category_dimensions>
148
+ <observers>
149
+ <convert_category_dimensions>
150
+ <type>singleton</type>
151
+ <class>Tiramizoo_Shipping_Model_TestObserver</class>
152
+ <method>convertCategoryDimensions</method>
153
+ </convert_category_dimensions>
154
+ </observers>
155
+ </tiramizoo_shipping_convert_category_dimensions>
156
+
157
+ <tiramizoo_shipping_modify_rates_price>
158
+ <observers>
159
+ <modify_rates_price>
160
+ <type>singleton</type>
161
+ <class>Tiramizoo_Shipping_Model_TestObserver</class>
162
+ <method>ratesPrice</method>
163
+ </modify_rates_price>
164
+ </observers>
165
+ </tiramizoo_shipping_modify_rates_price>
166
+ --> <!-- END Test Events -->
167
+
168
+ </events>
169
+
170
+
171
+ </global>
172
+
173
+ <adminhtml>
174
+ <layout>
175
+ <updates>
176
+ <tiramizoo>
177
+ <file>tiramizoo.xml</file>
178
+ </tiramizoo>
179
+ </updates>
180
+ </layout>
181
+ <translate>
182
+ <modules>
183
+ <Tiramizoo_Shipping>
184
+ <files>
185
+ <default>Tiramizoo_Shipping.csv</default>
186
+ </files>
187
+ </Tiramizoo_Shipping>
188
+ </modules>
189
+ </translate>
190
+ <events>
191
+ <catalog_product_save_after>
192
+ <observers>
193
+ <tiramizoo_save_product_data>
194
+ <type>singleton</type>
195
+ <class>Tiramizoo_Shipping_Model_Observer</class>
196
+ <method>saveProductTabData</method>
197
+ </tiramizoo_save_product_data>
198
+ </observers>
199
+ </catalog_product_save_after>
200
+ </events>
201
+ <acl>
202
+ <resources>
203
+ <all>
204
+ <title>Allow Everything</title>
205
+ </all>
206
+ <admin>
207
+ <children>
208
+ <system>
209
+ <children>
210
+ <config>
211
+ <children>
212
+ <tiramizoo_config>
213
+ <title>Tiramizoo</title>
214
+ </tiramizoo_config>
215
+ </children>
216
+ </config>
217
+ </children>
218
+ </system>
219
+ </children>
220
+ </admin>
221
+ </resources>
222
+ </acl>
223
+ </adminhtml>
224
+
225
+ <frontend>
226
+ <routers>
227
+ <tiramizoo>
228
+ <use>standard</use>
229
+ <args>
230
+ <module>Tiramizoo_Shipping</module>
231
+ <frontName>tiramizoo</frontName>
232
+ </args>
233
+ </tiramizoo>
234
+ </routers>
235
+
236
+ <layout>
237
+ <updates>
238
+ <tiramizoo>
239
+ <file>tiramizoo/checkout.xml</file>
240
+ </tiramizoo>
241
+ <tiramizoo_email>
242
+ <file>tiramizoo/sales.xml</file>
243
+ </tiramizoo_email>
244
+ </updates>
245
+ </layout>
246
+
247
+ <translate>
248
+ <modules>
249
+ <tiramizoo>
250
+ <files>
251
+ <default>Tiramizoo_Shipping.csv</default>
252
+ </files>
253
+ </tiramizoo>
254
+ </modules>
255
+ </translate>
256
+
257
+ </frontend>
258
+
259
+ <admin>
260
+ <routers>
261
+ <adminhtml>
262
+ <args>
263
+ <modules>
264
+ <tiramizoo before="Mage_Adminhtml">Tiramizoo_Shipping_Adminhtml</tiramizoo>
265
+ </modules>
266
+ </args>
267
+ </adminhtml>
268
+ </routers>
269
+ </admin>
270
+
271
+ <crontab>
272
+ <jobs>
273
+ <tiramizoo_synchronize>
274
+ <schedule>
275
+ <cron_expr>0 1,7,13,19 * * *</cron_expr>
276
+ </schedule>
277
+ <run>
278
+ <model>tiramizoo/retaillocations::synchronize</model>
279
+ </run>
280
+ </tiramizoo_synchronize>
281
+ <tiramizoo_resend>
282
+ <schedule>
283
+ <cron_expr>0,5,10,15,20,25,30,35,40,45,50,55 * * * *</cron_expr>
284
+ </schedule>
285
+ <run>
286
+ <model>tiramizoo/resend::check</model>
287
+ </run>
288
+ </tiramizoo_resend>
289
+ </jobs>
290
+ </crontab>
291
+
292
+ <phpunit>
293
+ <suite>
294
+ <modules>
295
+ <Tiramizoo_Shipping />
296
+ </modules>
297
+ </suite>
298
+ </phpunit>
299
+
300
+
301
+ </config>
app/code/community/Tiramizoo/Shipping/etc/system.xml ADDED
@@ -0,0 +1,563 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <sections>
5
+ <carriers>
6
+ <groups>
7
+ <tiramizoo translate="label" module="shipping">
8
+ <label>Tiramizoo</label>
9
+ <frontend_type>text</frontend_type>
10
+ <sort_order>13</sort_order>
11
+ <show_in_default>1</show_in_default>
12
+ <show_in_website>1</show_in_website>
13
+ <show_in_store>1</show_in_store>
14
+ <fields>
15
+ <active translate="label">
16
+ <label>Enabled</label>
17
+ <frontend_type>select</frontend_type>
18
+ <source_model>adminhtml/system_config_source_yesno</source_model>
19
+ <sort_order>1</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ </active>
24
+ <title translate="label">
25
+ <label>Title</label>
26
+ <frontend_type>text</frontend_type>
27
+ <sort_order>2</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>1</show_in_website>
30
+ <show_in_store>1</show_in_store>
31
+ </title>
32
+ <immediate_price translate="label">
33
+ <label>Immediate Price</label>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>3</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ <validate>required-entry</validate>
40
+ </immediate_price>
41
+ <evening_price translate="label">
42
+ <label>Evening Price</label>
43
+ <frontend_type>text</frontend_type>
44
+ <sort_order>4</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>1</show_in_store>
48
+ <validate>required-entry</validate>
49
+ </evening_price>
50
+ <specificerrmsg translate="label">
51
+ <label>Displayed Error Message</label>
52
+ <frontend_type>textarea</frontend_type>
53
+ <sort_order>80</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>1</show_in_website>
56
+ <show_in_store>1</show_in_store>
57
+ </specificerrmsg>
58
+ <sallowspecific translate="label">
59
+ <label>Ship to Applicable Countries</label>
60
+ <frontend_type>select</frontend_type>
61
+ <sort_order>90</sort_order>
62
+ <frontend_class>shipping-applicable-country</frontend_class>
63
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ <show_in_store>1</show_in_store>
67
+ </sallowspecific>
68
+ <specificcountry translate="label">
69
+ <label>Ship to Specific Countries</label>
70
+ <frontend_type>multiselect</frontend_type>
71
+ <sort_order>91</sort_order>
72
+ <source_model>adminhtml/system_config_source_country</source_model>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>1</show_in_store>
76
+ </specificcountry>
77
+ <showmethod translate="label">
78
+ <label>Show method if not applicable</label>
79
+ <frontend_type>select</frontend_type>
80
+ <sort_order>92</sort_order>
81
+ <source_model>adminhtml/system_config_source_yesno</source_model>
82
+ <show_in_default>1</show_in_default>
83
+ <show_in_website>1</show_in_website>
84
+ <show_in_store>1</show_in_store>
85
+ </showmethod>
86
+ <sort_order translate="label">
87
+ <label>Sort order</label>
88
+ <frontend_type>text</frontend_type>
89
+ <sort_order>100</sort_order>
90
+ <show_in_default>1</show_in_default>
91
+ <show_in_website>1</show_in_website>
92
+ <show_in_store>1</show_in_store>
93
+ </sort_order>
94
+ </fields>
95
+ </tiramizoo>
96
+ </groups>
97
+ </carriers>
98
+ <tiramizoo_config translate="label" module="tiramizoo_shipping">
99
+ <label>Tiramizoo</label>
100
+ <tab>sales</tab>
101
+ <frontend_type>text</frontend_type>
102
+ <sort_order>202</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>1</show_in_website>
105
+ <show_in_store>1</show_in_store>
106
+ <groups>
107
+ <api_config translate="label">
108
+ <label>Settings</label>
109
+ <frontend_type>text</frontend_type>
110
+ <sort_order>10</sort_order>
111
+ <show_in_default>1</show_in_default>
112
+ <show_in_website>1</show_in_website>
113
+ <show_in_store>1</show_in_store>
114
+ <fields>
115
+ <is_active translate="label">
116
+ <label>Is Active</label>
117
+ <frontend_type>select</frontend_type>
118
+ <source_model>adminhtml/system_config_source_yesno</source_model>
119
+ <sort_order>5</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
+ </is_active>
124
+ <api_url translate="label">
125
+ <label>API url</label>
126
+ <frontend_type>select</frontend_type>
127
+ <source_model>tiramizoo_shipping_model_config_apiurl</source_model>
128
+ <sort_order>10</sort_order>
129
+ <show_in_default>1</show_in_default>
130
+ <show_in_website>1</show_in_website>
131
+ <show_in_store>1</show_in_store>
132
+ </api_url>
133
+ <shop_url translate="label">
134
+ <label>Shop url</label>
135
+ <frontend_type>text</frontend_type>
136
+ <sort_order>20</sort_order>
137
+ <show_in_default>1</show_in_default>
138
+ <show_in_website>1</show_in_website>
139
+ <show_in_store>1</show_in_store>
140
+ <validate>required-entry</validate>
141
+ </shop_url>
142
+ <payment translate="label">
143
+ <label>Payment methods</label>
144
+ <comment>Payment methods available for Tiramizoo, Cash on delivery is not supported yet</comment>
145
+ <source_model>Tiramizoo_Shipping_Model_Payment</source_model>
146
+ <frontend_type>multiselect</frontend_type>
147
+ <sort_order>30</sort_order>
148
+ <show_in_default>1</show_in_default>
149
+ <show_in_website>1</show_in_website>
150
+ <show_in_store>1</show_in_store>
151
+ <validate>required-entry</validate>
152
+ </payment>
153
+ <packing_strategy translate="label">
154
+ <label>Packing strategy</label>
155
+ <frontend_type>select</frontend_type>
156
+ <source_model>tiramizoo_shipping_model_config_packingstrategy</source_model>
157
+ <sort_order>40</sort_order>
158
+ <show_in_default>1</show_in_default>
159
+ <show_in_website>1</show_in_website>
160
+ <show_in_store>1</show_in_store>
161
+ </packing_strategy>
162
+
163
+ <onepackage_dimensions translate="label">
164
+ <label>Standard Package size and weight</label>
165
+ <frontend_type>text</frontend_type>
166
+ <frontend_model>tiramizoo/onepackagedimensions</frontend_model>
167
+ <sort_order>50</sort_order>
168
+ <show_in_default>1</show_in_default>
169
+ <show_in_website>1</show_in_website>
170
+ <show_in_store>1</show_in_store>
171
+ <depends><packing_strategy>onepackage</packing_strategy></depends>
172
+ </onepackage_dimensions>
173
+
174
+ <product_dimensions translate="label">
175
+ <label>Default product dimensions and weight</label>
176
+ <frontend_type>text</frontend_type>
177
+ <frontend_model>tiramizoo/productdimensions</frontend_model>
178
+ <sort_order>60</sort_order>
179
+ <show_in_default>1</show_in_default>
180
+ <show_in_website>1</show_in_website>
181
+ <show_in_store>1</show_in_store>
182
+ </product_dimensions>
183
+
184
+
185
+
186
+ <product_width_mapping translate="label">
187
+ <label>Product width mapping</label>
188
+ <frontend_type>select</frontend_type>
189
+ <source_model>tiramizoo/attributes</source_model>
190
+ <sort_order>70</sort_order>
191
+ <show_in_default>1</show_in_default>
192
+ <show_in_website>1</show_in_website>
193
+ <show_in_store>1</show_in_store>
194
+ </product_width_mapping>
195
+
196
+
197
+ <product_height_mapping translate="label">
198
+ <label>Product height mapping</label>
199
+ <frontend_type>select</frontend_type>
200
+ <source_model>tiramizoo/attributes</source_model>
201
+ <sort_order>80</sort_order>
202
+ <show_in_default>1</show_in_default>
203
+ <show_in_website>1</show_in_website>
204
+ <show_in_store>1</show_in_store>
205
+ </product_height_mapping>
206
+
207
+
208
+ <product_length_mapping translate="label">
209
+ <label>Product length mapping</label>
210
+ <frontend_type>select</frontend_type>
211
+ <source_model>tiramizoo/attributes</source_model>
212
+ <sort_order>90</sort_order>
213
+ <show_in_default>1</show_in_default>
214
+ <show_in_website>1</show_in_website>
215
+ <show_in_store>1</show_in_store>
216
+ </product_length_mapping>
217
+
218
+
219
+ <synchronize translate="label">
220
+ <label>Synchronize all retail locations</label>
221
+ <frontend_type>button</frontend_type>
222
+ <frontend_model>tiramizoo/button</frontend_model>
223
+ <sort_order>100</sort_order>
224
+ <show_in_default>1</show_in_default>
225
+ <show_in_website>1</show_in_website>
226
+ <show_in_store>1</show_in_store>
227
+ </synchronize>
228
+ </fields>
229
+ </api_config>
230
+
231
+ <tiramizoo_location_1 translate="label">
232
+ <label>API Location 1</label>
233
+ <frontend_type>text</frontend_type>
234
+ <sort_order>20</sort_order>
235
+ <show_in_default>1</show_in_default>
236
+ <show_in_website>1</show_in_website>
237
+ <show_in_store>1</show_in_store>
238
+ <fields>
239
+ <is_enable translate="label">
240
+ <label>Is enable</label>
241
+ <frontend_type>select</frontend_type>
242
+ <source_model>adminhtml/system_config_source_yesno</source_model>
243
+ <sort_order>10</sort_order>
244
+ <show_in_default>1</show_in_default>
245
+ <show_in_website>1</show_in_website>
246
+ <show_in_store>1</show_in_store>
247
+ </is_enable>
248
+ <api_key translate="label">
249
+ <label>API key</label>
250
+ <frontend_type>text</frontend_type>
251
+ <sort_order>20</sort_order>
252
+ <show_in_default>1</show_in_default>
253
+ <show_in_website>1</show_in_website>
254
+ <show_in_store>1</show_in_store>
255
+ </api_key>
256
+ </fields>
257
+ </tiramizoo_location_1>
258
+
259
+ <tiramizoo_location_2 translate="label">
260
+ <label>API Location 2</label>
261
+ <frontend_type>text</frontend_type>
262
+ <sort_order>30</sort_order>
263
+ <show_in_default>1</show_in_default>
264
+ <show_in_website>1</show_in_website>
265
+ <show_in_store>1</show_in_store>
266
+ <fields>
267
+ <is_enable translate="label">
268
+ <label>Is enable</label>
269
+ <frontend_type>select</frontend_type>
270
+ <source_model>adminhtml/system_config_source_yesno</source_model>
271
+ <sort_order>10</sort_order>
272
+ <show_in_default>1</show_in_default>
273
+ <show_in_website>1</show_in_website>
274
+ <show_in_store>1</show_in_store>
275
+ </is_enable>
276
+ <api_key translate="label">
277
+ <label>API key</label>
278
+ <frontend_type>text</frontend_type>
279
+ <sort_order>20</sort_order>
280
+ <show_in_default>1</show_in_default>
281
+ <show_in_website>1</show_in_website>
282
+ <show_in_store>1</show_in_store>
283
+ </api_key>
284
+ </fields>
285
+ </tiramizoo_location_2>
286
+
287
+ <tiramizoo_location_3 translate="label">
288
+ <label>API Location 3</label>
289
+ <frontend_type>text</frontend_type>
290
+ <sort_order>40</sort_order>
291
+ <show_in_default>1</show_in_default>
292
+ <show_in_website>1</show_in_website>
293
+ <show_in_store>1</show_in_store>
294
+ <fields>
295
+ <is_enable translate="label">
296
+ <label>Is enable</label>
297
+ <frontend_type>select</frontend_type>
298
+ <source_model>adminhtml/system_config_source_yesno</source_model>
299
+ <sort_order>10</sort_order>
300
+ <show_in_default>1</show_in_default>
301
+ <show_in_website>1</show_in_website>
302
+ <show_in_store>1</show_in_store>
303
+ </is_enable>
304
+ <api_key translate="label">
305
+ <label>API key</label>
306
+ <frontend_type>text</frontend_type>
307
+ <sort_order>20</sort_order>
308
+ <show_in_default>1</show_in_default>
309
+ <show_in_website>1</show_in_website>
310
+ <show_in_store>1</show_in_store>
311
+ </api_key>
312
+ </fields>
313
+ </tiramizoo_location_3>
314
+
315
+ <tiramizoo_location_4 translate="label">
316
+ <label>API Location 4</label>
317
+ <frontend_type>text</frontend_type>
318
+ <sort_order>50</sort_order>
319
+ <show_in_default>1</show_in_default>
320
+ <show_in_website>1</show_in_website>
321
+ <show_in_store>1</show_in_store>
322
+ <fields>
323
+ <is_enable translate="label">
324
+ <label>Is enable</label>
325
+ <frontend_type>select</frontend_type>
326
+ <source_model>adminhtml/system_config_source_yesno</source_model>
327
+ <sort_order>10</sort_order>
328
+ <show_in_default>1</show_in_default>
329
+ <show_in_website>1</show_in_website>
330
+ <show_in_store>1</show_in_store>
331
+ </is_enable>
332
+ <api_key translate="label">
333
+ <label>API key</label>
334
+ <frontend_type>text</frontend_type>
335
+ <sort_order>20</sort_order>
336
+ <show_in_default>1</show_in_default>
337
+ <show_in_website>1</show_in_website>
338
+ <show_in_store>1</show_in_store>
339
+ </api_key>
340
+ </fields>
341
+ </tiramizoo_location_4>
342
+
343
+ <tiramizoo_location_4 translate="label">
344
+ <label>API Location 4</label>
345
+ <frontend_type>text</frontend_type>
346
+ <sort_order>50</sort_order>
347
+ <show_in_default>1</show_in_default>
348
+ <show_in_website>1</show_in_website>
349
+ <show_in_store>1</show_in_store>
350
+ <fields>
351
+ <is_enable translate="label">
352
+ <label>Is enable</label>
353
+ <frontend_type>select</frontend_type>
354
+ <source_model>adminhtml/system_config_source_yesno</source_model>
355
+ <sort_order>10</sort_order>
356
+ <show_in_default>1</show_in_default>
357
+ <show_in_website>1</show_in_website>
358
+ <show_in_store>1</show_in_store>
359
+ </is_enable>
360
+ <api_key translate="label">
361
+ <label>API key</label>
362
+ <frontend_type>text</frontend_type>
363
+ <sort_order>20</sort_order>
364
+ <show_in_default>1</show_in_default>
365
+ <show_in_website>1</show_in_website>
366
+ <show_in_store>1</show_in_store>
367
+ </api_key>
368
+ </fields>
369
+ </tiramizoo_location_4>
370
+
371
+ <tiramizoo_location_5 translate="label">
372
+ <label>API Location 5</label>
373
+ <frontend_type>text</frontend_type>
374
+ <sort_order>60</sort_order>
375
+ <show_in_default>1</show_in_default>
376
+ <show_in_website>1</show_in_website>
377
+ <show_in_store>1</show_in_store>
378
+ <fields>
379
+ <is_enable translate="label">
380
+ <label>Is enable</label>
381
+ <frontend_type>select</frontend_type>
382
+ <source_model>adminhtml/system_config_source_yesno</source_model>
383
+ <sort_order>10</sort_order>
384
+ <show_in_default>1</show_in_default>
385
+ <show_in_website>1</show_in_website>
386
+ <show_in_store>1</show_in_store>
387
+ </is_enable>
388
+ <api_key translate="label">
389
+ <label>API key</label>
390
+ <frontend_type>text</frontend_type>
391
+ <sort_order>20</sort_order>
392
+ <show_in_default>1</show_in_default>
393
+ <show_in_website>1</show_in_website>
394
+ <show_in_store>1</show_in_store>
395
+ </api_key>
396
+ </fields>
397
+ </tiramizoo_location_5>
398
+
399
+ <tiramizoo_location_6 translate="label">
400
+ <label>API Location 6</label>
401
+ <frontend_type>text</frontend_type>
402
+ <sort_order>70</sort_order>
403
+ <show_in_default>1</show_in_default>
404
+ <show_in_website>1</show_in_website>
405
+ <show_in_store>1</show_in_store>
406
+ <fields>
407
+ <is_enable translate="label">
408
+ <label>Is enable</label>
409
+ <frontend_type>select</frontend_type>
410
+ <source_model>adminhtml/system_config_source_yesno</source_model>
411
+ <sort_order>10</sort_order>
412
+ <show_in_default>1</show_in_default>
413
+ <show_in_website>1</show_in_website>
414
+ <show_in_store>1</show_in_store>
415
+ </is_enable>
416
+ <api_key translate="label">
417
+ <label>API key</label>
418
+ <frontend_type>text</frontend_type>
419
+ <sort_order>20</sort_order>
420
+ <show_in_default>1</show_in_default>
421
+ <show_in_website>1</show_in_website>
422
+ <show_in_store>1</show_in_store>
423
+ </api_key>
424
+ </fields>
425
+ </tiramizoo_location_6>
426
+
427
+ <tiramizoo_location_7 translate="label">
428
+ <label>API Location 7</label>
429
+ <frontend_type>text</frontend_type>
430
+ <sort_order>80</sort_order>
431
+ <show_in_default>1</show_in_default>
432
+ <show_in_website>1</show_in_website>
433
+ <show_in_store>1</show_in_store>
434
+ <fields>
435
+ <is_enable translate="label">
436
+ <label>Is enable</label>
437
+ <frontend_type>select</frontend_type>
438
+ <source_model>adminhtml/system_config_source_yesno</source_model>
439
+ <sort_order>10</sort_order>
440
+ <show_in_default>1</show_in_default>
441
+ <show_in_website>1</show_in_website>
442
+ <show_in_store>1</show_in_store>
443
+ </is_enable>
444
+ <api_key translate="label">
445
+ <label>API key</label>
446
+ <frontend_type>text</frontend_type>
447
+ <sort_order>20</sort_order>
448
+ <show_in_default>1</show_in_default>
449
+ <show_in_website>1</show_in_website>
450
+ <show_in_store>1</show_in_store>
451
+ </api_key>
452
+ </fields>
453
+ </tiramizoo_location_7>
454
+
455
+ <tiramizoo_location_8 translate="label">
456
+ <label>API Location 8</label>
457
+ <frontend_type>text</frontend_type>
458
+ <sort_order>90</sort_order>
459
+ <show_in_default>1</show_in_default>
460
+ <show_in_website>1</show_in_website>
461
+ <show_in_store>1</show_in_store>
462
+ <fields>
463
+ <is_enable translate="label">
464
+ <label>Is enable</label>
465
+ <frontend_type>select</frontend_type>
466
+ <source_model>adminhtml/system_config_source_yesno</source_model>
467
+ <sort_order>10</sort_order>
468
+ <show_in_default>1</show_in_default>
469
+ <show_in_website>1</show_in_website>
470
+ <show_in_store>1</show_in_store>
471
+ </is_enable>
472
+ <api_key translate="label">
473
+ <label>API key</label>
474
+ <frontend_type>text</frontend_type>
475
+ <sort_order>20</sort_order>
476
+ <show_in_default>1</show_in_default>
477
+ <show_in_website>1</show_in_website>
478
+ <show_in_store>1</show_in_store>
479
+ </api_key>
480
+ </fields>
481
+ </tiramizoo_location_8>
482
+
483
+ <tiramizoo_location_9 translate="label">
484
+ <label>API Location 9</label>
485
+ <frontend_type>text</frontend_type>
486
+ <sort_order>100</sort_order>
487
+ <show_in_default>1</show_in_default>
488
+ <show_in_website>1</show_in_website>
489
+ <show_in_store>1</show_in_store>
490
+ <fields>
491
+ <is_enable translate="label">
492
+ <label>Is enable</label>
493
+ <frontend_type>select</frontend_type>
494
+ <source_model>adminhtml/system_config_source_yesno</source_model>
495
+ <sort_order>10</sort_order>
496
+ <show_in_default>1</show_in_default>
497
+ <show_in_website>1</show_in_website>
498
+ <show_in_store>1</show_in_store>
499
+ </is_enable>
500
+ <api_key translate="label">
501
+ <label>API key</label>
502
+ <frontend_type>text</frontend_type>
503
+ <sort_order>20</sort_order>
504
+ <show_in_default>1</show_in_default>
505
+ <show_in_website>1</show_in_website>
506
+ <show_in_store>1</show_in_store>
507
+ </api_key>
508
+ </fields>
509
+ </tiramizoo_location_9>
510
+
511
+
512
+ <tiramizoo_location_10 translate="label">
513
+ <label>API Location 10</label>
514
+ <frontend_type>text</frontend_type>
515
+ <sort_order>110</sort_order>
516
+ <show_in_default>1</show_in_default>
517
+ <show_in_website>1</show_in_website>
518
+ <show_in_store>1</show_in_store>
519
+ <fields>
520
+ <is_enable translate="label">
521
+ <label>Is enable</label>
522
+ <frontend_type>select</frontend_type>
523
+ <source_model>adminhtml/system_config_source_yesno</source_model>
524
+ <sort_order>10</sort_order>
525
+ <show_in_default>1</show_in_default>
526
+ <show_in_website>1</show_in_website>
527
+ <show_in_store>1</show_in_store>
528
+ </is_enable>
529
+ <api_key translate="label">
530
+ <label>API key</label>
531
+ <frontend_type>text</frontend_type>
532
+ <sort_order>20</sort_order>
533
+ <show_in_default>1</show_in_default>
534
+ <show_in_website>1</show_in_website>
535
+ <show_in_store>1</show_in_store>
536
+ </api_key>
537
+ </fields>
538
+ </tiramizoo_location_10>
539
+
540
+ <advanced translate="label">
541
+ <label>Advanced</label>
542
+ <frontend_type>text</frontend_type>
543
+ <sort_order>2000</sort_order>
544
+ <show_in_default>1</show_in_default>
545
+ <show_in_website>1</show_in_website>
546
+ <show_in_store>1</show_in_store>
547
+ <fields>
548
+ <debug_log translate="label">
549
+ <label>Debug log</label>
550
+ <frontend_type>select</frontend_type>
551
+ <source_model>adminhtml/system_config_source_yesno</source_model>
552
+ <sort_order>10</sort_order>
553
+ <show_in_default>1</show_in_default>
554
+ <show_in_website>1</show_in_website>
555
+ <show_in_store>1</show_in_store>
556
+ </debug_log>
557
+ </fields>
558
+ </advanced>
559
+
560
+ </groups>
561
+ </tiramizoo_config>
562
+ </sections>
563
+ </config>
app/code/community/Tiramizoo/Shipping/sql/tiramizoo_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,460 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+
17
+ $installer = $this;
18
+
19
+ // throw new Exception("This is an exception to stop the installer from completing");
20
+
21
+ $installer->startSetup();
22
+
23
+ // Product attribute width
24
+ $attrCode = 'width';
25
+ $attrGroupName = 'General';
26
+ $attrLabel = 'Width';
27
+ $attrNote = 'Product width in cm';
28
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
29
+
30
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Product::ENTITY, $attrCode);
31
+
32
+ if ($attrIdTest === false) {
33
+ $setup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode, array(
34
+ 'group' => $attrGroupName,
35
+ 'sort_order' => 101,
36
+ 'type' => 'int',
37
+ 'backend' => '',
38
+ 'frontend' => '',
39
+ 'label' => $attrLabel,
40
+ 'note' => $attrNote,
41
+ 'input' => 'text',
42
+ 'class' => '',
43
+ 'source' => '',
44
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
45
+ 'visible' => true,
46
+ 'required' => false,
47
+ 'user_defined' => true,
48
+ 'default' => '',
49
+ 'visible_on_front' => false,
50
+ 'unique' => false,
51
+ 'is_configurable' => false,
52
+ 'used_for_promo_rules' => false
53
+ ));
54
+ }
55
+
56
+ // Product attribute height
57
+ $attrCode = 'height';
58
+ $attrGroupName = 'General';
59
+ $attrLabel = 'Height';
60
+ $attrNote = 'Product height in cm';
61
+
62
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Product::ENTITY, $attrCode);
63
+
64
+ if ($attrIdTest === false) {
65
+ $setup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode, array(
66
+ 'group' => $attrGroupName,
67
+ 'sort_order' => 102,
68
+ 'type' => 'int',
69
+ 'backend' => '',
70
+ 'frontend' => '',
71
+ 'label' => $attrLabel,
72
+ 'note' => $attrNote,
73
+ 'input' => 'text',
74
+ 'class' => '',
75
+ 'source' => '',
76
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
77
+ 'visible' => true,
78
+ 'required' => false,
79
+ 'user_defined' => true,
80
+ 'default' => '',
81
+ 'visible_on_front' => false,
82
+ 'unique' => false,
83
+ 'is_configurable' => false,
84
+ 'used_for_promo_rules' => false
85
+ ));
86
+ }
87
+
88
+ // Product attribute length
89
+ $attrCode = 'length';
90
+ $attrGroupName = 'General';
91
+ $attrLabel = 'Length';
92
+ $attrNote = 'Product length in cm';
93
+
94
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Product::ENTITY, $attrCode);
95
+
96
+ if ($attrIdTest === false) {
97
+ $setup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode, array(
98
+ 'group' => $attrGroupName,
99
+ 'sort_order' => 103,
100
+ 'type' => 'int',
101
+ 'backend' => '',
102
+ 'frontend' => '',
103
+ 'label' => $attrLabel,
104
+ 'note' => $attrNote,
105
+ 'input' => 'text',
106
+ 'class' => '',
107
+ 'source' => '',
108
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
109
+ 'visible' => true,
110
+ 'required' => false,
111
+ 'user_defined' => true,
112
+ 'default' => '',
113
+ 'visible_on_front' => false,
114
+ 'unique' => false,
115
+ 'is_configurable' => false,
116
+ 'used_for_promo_rules' => false
117
+ ));
118
+ }
119
+
120
+ // Category attribute width
121
+ $attrCode = 'category_products_width';
122
+ $attrGroupName = 'Tiramizoo';
123
+ $attrLabel = 'Width';
124
+ $attrNote = 'Product width in cm';
125
+
126
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Category::ENTITY, $attrCode);
127
+
128
+ if ($attrIdTest === false) {
129
+ $setup->addAttribute(Mage_Catalog_Model_Category::ENTITY, $attrCode, array(
130
+ 'group' => $attrGroupName,
131
+ 'sort_order' => 101,
132
+ 'type' => 'int',
133
+ 'backend' => '',
134
+ 'frontend' => '',
135
+ 'label' => $attrLabel,
136
+ 'note' => $attrNote,
137
+ 'input' => 'text',
138
+ 'class' => '',
139
+ 'source' => '',
140
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
141
+ 'visible' => true,
142
+ 'required' => false,
143
+ 'user_defined' => true,
144
+ 'default' => '',
145
+ 'visible_on_front' => false,
146
+ 'unique' => false,
147
+ 'is_configurable' => false,
148
+ 'used_for_promo_rules' => false
149
+ ));
150
+ }
151
+
152
+ // Category attribute height
153
+ $attrCode = 'category_products_height';
154
+ $attrGroupName = 'Tiramizoo';
155
+ $attrLabel = 'Height';
156
+ $attrNote = 'Product height in cm';
157
+
158
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Category::ENTITY, $attrCode);
159
+
160
+ if ($attrIdTest === false) {
161
+ $setup->addAttribute(Mage_Catalog_Model_Category::ENTITY, $attrCode, array(
162
+ 'group' => $attrGroupName,
163
+ 'sort_order' => 102,
164
+ 'type' => 'int',
165
+ 'backend' => '',
166
+ 'frontend' => '',
167
+ 'label' => $attrLabel,
168
+ 'note' => $attrNote,
169
+ 'input' => 'text',
170
+ 'class' => '',
171
+ 'source' => '',
172
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
173
+ 'visible' => true,
174
+ 'required' => false,
175
+ 'user_defined' => true,
176
+ 'default' => '',
177
+ 'visible_on_front' => false,
178
+ 'unique' => false,
179
+ 'is_configurable' => false,
180
+ 'used_for_promo_rules' => false
181
+ ));
182
+ }
183
+
184
+ // Category attribute length
185
+ $attrCode = 'category_products_length';
186
+ $attrGroupName = 'Tiramizoo';
187
+ $attrLabel = 'Length';
188
+ $attrNote = 'Product length in cm';
189
+
190
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Category::ENTITY, $attrCode);
191
+
192
+ if ($attrIdTest === false) {
193
+ $setup->addAttribute(Mage_Catalog_Model_Category::ENTITY, $attrCode, array(
194
+ 'group' => $attrGroupName,
195
+ 'sort_order' => 103,
196
+ 'type' => 'int',
197
+ 'backend' => '',
198
+ 'frontend' => '',
199
+ 'label' => $attrLabel,
200
+ 'note' => $attrNote,
201
+ 'input' => 'text',
202
+ 'class' => '',
203
+ 'source' => '',
204
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
205
+ 'visible' => true,
206
+ 'required' => false,
207
+ 'user_defined' => true,
208
+ 'default' => '',
209
+ 'visible_on_front' => false,
210
+ 'unique' => false,
211
+ 'is_configurable' => false,
212
+ 'used_for_promo_rules' => false
213
+ ));
214
+ }
215
+
216
+ // Category attribute weight
217
+ $attrCode = 'category_products_weight';
218
+ $attrGroupName = 'Tiramizoo';
219
+ $attrLabel = 'Weight';
220
+ $attrNote = '';
221
+
222
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Category::ENTITY, $attrCode);
223
+
224
+ if ($attrIdTest === false) {
225
+ $setup->addAttribute(Mage_Catalog_Model_Category::ENTITY, $attrCode, array(
226
+ 'group' => $attrGroupName,
227
+ 'sort_order' => 104,
228
+ 'type' => 'decimal',
229
+ 'backend' => '',
230
+ 'frontend' => '',
231
+ 'label' => $attrLabel,
232
+ 'note' => $attrNote,
233
+ 'input' => 'text',
234
+ 'class' => '',
235
+ 'source' => '',
236
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
237
+ 'visible' => true,
238
+ 'required' => false,
239
+ 'user_defined' => true,
240
+ 'default' => '',
241
+ 'visible_on_front' => false,
242
+ 'unique' => false,
243
+ 'is_configurable' => false,
244
+ 'used_for_promo_rules' => false
245
+ ));
246
+ }
247
+
248
+ // Product attribute enable
249
+ $attrCode = 'tiramizoo_enable';
250
+ $attrGroupName = 'Tiramizoo';
251
+ $attrLabel = 'Enable';
252
+ $attrNote = '';
253
+
254
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Product::ENTITY, $attrCode);
255
+
256
+ if ($attrIdTest === false) {
257
+ $setup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode, array(
258
+ 'group' => $attrGroupName,
259
+ 'sort_order' => 101,
260
+ 'type' => 'int',
261
+ 'backend' => '',
262
+ 'frontend' => '',
263
+ 'label' => $attrLabel,
264
+ 'note' => $attrNote,
265
+ 'input' => 'select',
266
+ 'class' => '',
267
+ 'source' => 'tiramizoo/entity_attribute_source_enable',
268
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
269
+ 'visible' => false,
270
+ 'required' => false,
271
+ 'user_defined' => true,
272
+ 'default' => 0,
273
+ 'visible_on_front' => false,
274
+ 'unique' => false,
275
+ 'is_configurable' => false,
276
+ 'used_for_promo_rules' => false
277
+ ));
278
+ $setup->updateAttribute('catalog_product', $attrCode, 'is_visible', false);
279
+ }
280
+
281
+ // Category attribute enable
282
+ $attrCode = 'tiramizoo_category_enable';
283
+ $attrGroupName = 'Tiramizoo';
284
+ $attrLabel = 'Enable';
285
+ $attrNote = '';
286
+
287
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Category::ENTITY, $attrCode);
288
+
289
+ if ($attrIdTest === false) {
290
+ $setup->addAttribute(Mage_Catalog_Model_Category::ENTITY, $attrCode, array(
291
+ 'group' => $attrGroupName,
292
+ 'sort_order' => 100,
293
+ 'type' => 'int',
294
+ 'backend' => '',
295
+ 'frontend' => '',
296
+ 'label' => $attrLabel,
297
+ 'note' => $attrNote,
298
+ 'input' => 'select',
299
+ 'class' => '',
300
+ 'source' => 'tiramizoo/entity_attribute_source_enable',
301
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
302
+ 'visible' => true,
303
+ 'required' => false,
304
+ 'user_defined' => true,
305
+ 'default' => 0,
306
+ 'visible_on_front' => false,
307
+ 'unique' => false,
308
+ 'is_configurable' => false,
309
+ 'used_for_promo_rules' => false
310
+ ));
311
+ }
312
+
313
+ // Product attribute packed_individually
314
+ $attrCode = 'tiramizoo_packed_individually';
315
+ $attrGroupName = 'Tiramizoo';
316
+ $attrLabel = 'Packed individually';
317
+ $attrNote = '';
318
+
319
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Product::ENTITY, $attrCode);
320
+
321
+ if ($attrIdTest === false) {
322
+ $setup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode, array(
323
+ 'group' => $attrGroupName,
324
+ 'sort_order' => 102,
325
+ 'type' => 'int',
326
+ 'backend' => '',
327
+ 'frontend' => '',
328
+ 'label' => $attrLabel,
329
+ 'note' => $attrNote,
330
+ 'input' => 'select',
331
+ 'class' => '',
332
+ 'source' => 'tiramizoo/entity_attribute_source_packed',
333
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
334
+ 'visible' => false,
335
+ 'required' => false,
336
+ 'user_defined' => true,
337
+ 'default' => 0,
338
+ 'visible_on_front' => false,
339
+ 'unique' => false,
340
+ 'is_configurable' => false,
341
+ 'used_for_promo_rules' => false
342
+ ));
343
+ $setup->updateAttribute('catalog_product', $attrCode, 'is_visible', false);
344
+ }
345
+
346
+ // Category attribute packed_individually
347
+ $attrCode = 'trmz_cat_packed_individually';
348
+ $attrGroupName = 'Tiramizoo';
349
+ $attrLabel = 'Packed individually';
350
+ $attrNote = '';
351
+
352
+ $attrIdTest = $setup->getAttributeId(Mage_Catalog_Model_Category::ENTITY, $attrCode);
353
+
354
+ if ($attrIdTest === false) {
355
+ $setup->addAttribute(Mage_Catalog_Model_Category::ENTITY, $attrCode, array(
356
+ 'group' => $attrGroupName,
357
+ 'sort_order' => 101,
358
+ 'type' => 'int',
359
+ 'backend' => '',
360
+ 'frontend' => '',
361
+ 'label' => $attrLabel,
362
+ 'note' => $attrNote,
363
+ 'input' => 'select',
364
+ 'class' => '',
365
+ 'source' => 'tiramizoo/entity_attribute_source_packed',
366
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
367
+ 'visible' => true,
368
+ 'required' => false,
369
+ 'user_defined' => true,
370
+ 'default' => 0,
371
+ 'visible_on_front' => false,
372
+ 'unique' => false,
373
+ 'is_configurable' => false,
374
+ 'used_for_promo_rules' => false
375
+ ));
376
+ }
377
+
378
+ // Tiramizoo order table
379
+ $table = $installer->getConnection()->newTable($installer->getTable('tiramizoo/order'))
380
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
381
+ 'unsigned' => true,
382
+ 'identity' => true,
383
+ 'nullable' => false,
384
+ 'primary' => true,
385
+ ), 'Entity id')
386
+ ->addColumn('time_window_hash', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array(
387
+ 'nullable' => true,
388
+ 'default' => null,
389
+ ), 'Time window hash using md5')
390
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
391
+ 'nullable' => true,
392
+ 'default' => null,
393
+ ), 'Quote entity id')
394
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
395
+ 'nullable' => true,
396
+ 'default' => null,
397
+ ), 'Order entity id')
398
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
399
+ 'nullable' => true,
400
+ 'default' => null,
401
+ ), 'Order status')
402
+ ->addColumn('tracking_url', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
403
+ 'nullable' => true,
404
+ 'default' => null,
405
+ ), 'Tiramizoo tracking url')
406
+ ->addColumn('external_id', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array(
407
+ 'nullable' => true,
408
+ 'default' => null,
409
+ ), 'External order id, send to API')
410
+ ->addColumn('api_request', Varien_Db_Ddl_Table::TYPE_TEXT, '4M', array(
411
+ 'nullable' => true,
412
+ 'default' => null,
413
+ ), 'API request data')
414
+ ->addColumn('api_response', Varien_Db_Ddl_Table::TYPE_TEXT, '4M', array(
415
+ 'nullable' => true,
416
+ 'default' => null,
417
+ ), 'API response data')
418
+ ->addColumn('webhook_response', Varien_Db_Ddl_Table::TYPE_TEXT, '4M', array(
419
+ 'nullable' => true,
420
+ 'default' => null,
421
+ ), 'Webhook response data')
422
+ ->addColumn('webhook_updated_at', Varien_Db_Ddl_Table::TYPE_DATE, null, array(
423
+ 'nullable' => true,
424
+ 'default' => null,
425
+ ), 'Webhook receive date')
426
+ ->addColumn('repeats', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
427
+ 'nullable' => false,
428
+ 'default' => 1,
429
+ ), 'Order sending repeats')
430
+ ->addColumn('send_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
431
+ 'nullable' => true,
432
+ 'default' => null,
433
+ ), 'Send date time')
434
+ ->addIndex(
435
+ $installer->getIdxName(
436
+ $installer->getTable('tiramizoo/order'), array('quote_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
437
+ ),
438
+ array('quote_id'),
439
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
440
+ )
441
+ ->addIndex(
442
+ $installer->getIdxName(
443
+ $installer->getTable('tiramizoo/order'), array('order_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
444
+ ),
445
+ array('order_id'),
446
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
447
+ )
448
+ ->addIndex(
449
+ $installer->getIdxName(
450
+ $installer->getTable('tiramizoo/order'), array('external_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
451
+ ),
452
+ array('external_id'),
453
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
454
+ )
455
+ ->setComment('Tiramizoo order');
456
+
457
+ $installer->getConnection()->createTable($table);
458
+
459
+
460
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/tiramizoo.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_catalog_product_new>
4
+ <reference name="product_tabs">
5
+ <action method="addTab">
6
+ <name>tiramizoo_shipping</name>
7
+ <block>tiramizoo/adminhtml_catalog_product_edit_tab_action</block>
8
+ </action>
9
+ </reference>
10
+ </adminhtml_catalog_product_new>
11
+ <adminhtml_catalog_product_edit>
12
+ <reference name="product_tabs">
13
+ <action method="addTab">
14
+ <name>tiramizoo_shipping</name>
15
+ <block>tiramizoo/adminhtml_catalog_product_edit_tab_action</block>
16
+ </action>
17
+ </reference>
18
+ </adminhtml_catalog_product_edit>
19
+ <adminhtml_sales_order_view>
20
+ <reference name="sales_order_tabs">
21
+ <action method="addTab">
22
+ <name>tiramizoo_shipping</name>
23
+ <block>tiramizoo/adminhtml_sales_order_view_tab_tiramizoo</block>
24
+ </action>
25
+ </reference>
26
+ </adminhtml_sales_order_view>
27
+ </layout>
app/design/adminhtml/default/default/template/tiramizoo/catalog/product/tab/action.phtml ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ $product = $this->getProduct();
17
+
18
+ ?>
19
+
20
+ <div class="entry-edit custom-options product-custom-options">
21
+ <div class="entry-edit-head">
22
+ <h4><?php echo $this->__('Tiramizoo') ?></h4>
23
+ </div>
24
+
25
+ <div class="fieldset fieldset-wide" id="tiramizoo_group">
26
+ <div class="hor-scroll">
27
+ <table cellspacing="0" class="form-list">
28
+ <tbody>
29
+ <tr>
30
+ <td class="label"><label for="tiramizoo_enable"><?php echo $this->__('Is enable') ?></label></td>
31
+ <td class="value">
32
+ <select id="tiramizoo_enable" name="tiramizoo_enable">
33
+ <?php
34
+ $options = Mage::getModel('tiramizoo/entity_attribute_source_enable')
35
+ ->getAllOptions();
36
+ foreach ($options as $option): ?>
37
+ <option value="<?php echo $option['value'] ?>" <?= ($product->getData('tiramizoo_enable') == $option['value']) ? 'selected="selected"' : null ?>><?php echo $option['label'] ?></option>
38
+ <?php endforeach; ?>
39
+ </select>
40
+ </td>
41
+ <td class="scope-label"><span class="nobr"></span></td>
42
+ </tr>
43
+
44
+ <tr>
45
+ <td class="label"><label for="tiramizoo_packed_individually"><?php echo $this->__('Packed individually') ?></label></td>
46
+ <td class="value">
47
+ <select id="tiramizoo_packed_individually" name="tiramizoo_packed_individually">
48
+ <?php
49
+ $options = Mage::getModel('tiramizoo/entity_attribute_source_packed')
50
+ ->getAllOptions();
51
+ foreach ($options as $option): ?>
52
+ <option value="<?php echo $option['value'] ?>" <?= ($product->getData('tiramizoo_packed_individually') == $option['value']) ? 'selected="selected"' : null ?>><?php echo $option['label'] ?></option>
53
+ <?php endforeach; ?>
54
+ </select>
55
+ </td>
56
+ <td class="scope-label"><span class="nobr"></span></td>
57
+ </tr>
58
+
59
+ <?php
60
+ $tiramizooProduct = Mage::getModel('tiramizoo/product', $product);
61
+ $dimensions = $tiramizooProduct->getDimensions();
62
+
63
+ if ($dimensions): ?>
64
+ <tr>
65
+ <td class="label"><label for="meta_keyword"><?php echo $this->__('Dimensions') ?></label></td>
66
+ <td class="value">
67
+ <table>
68
+ <tr>
69
+ <td><?php echo $this->__('From') ?>
70
+ <?php
71
+ switch($dimensions['destination_type']) {
72
+ case 'product':
73
+ echo $this->__('product');
74
+ break;
75
+ case 'category':
76
+ $category = Mage::getModel('catalog/category')->load($dimensions['destination_id']);
77
+ echo $this->__('category') . ': <strong>'.$category->getName().'</strong>';
78
+ break;
79
+ case 'config':
80
+ echo $this->__('configuration');
81
+ break;
82
+ }
83
+ ?>
84
+ </td>
85
+ </tr>
86
+ <?php
87
+ foreach(array('weight', 'width', 'height', 'length') as $var): ?>
88
+ <tr>
89
+ <td><strong><?= $this->__(ucwords($var)) ?></strong>: <?= $dimensions[$var] ?></td>
90
+ </tr>
91
+ <?php endforeach; ?>
92
+ </table>
93
+ </td>
94
+ <td class="scope-label"><span class="nobr"></span></td>
95
+ </tr>
96
+ <?php endif; ?>
97
+
98
+ <tr>
99
+ <td class="label"><label for="meta_keyword"><?php echo $this->__('Is available') ?></label></td>
100
+ <td class="value">
101
+ <?php if (!$tiramizooProduct->isAvailable()): ?>
102
+ <span style="color: #f00">
103
+ <?php echo __('Product is not available to Tiramizoo delivery.') ?><br>
104
+ <?php if($tiramizooProduct->isDisable()) foreach ($tiramizooProduct->getDisableIds() as $type => $ids): ?>
105
+ <?php if (count($ids)): ?>
106
+ <?= $type.': '.implode(', ', $ids).'<br>' ?>
107
+ <?php endif; ?>
108
+ <?php endforeach; ?>
109
+ </span>
110
+ <?php else: ?>
111
+ <span><?php echo __('Product is available to Tiramizoo delivery.') ?></span>
112
+ <?php endif; ?>
113
+ </td>
114
+ <td class="scope-label"><span class="nobr"></span></td>
115
+ </tr>
116
+
117
+ <tr>
118
+ <td class="label"><label for="meta_keyword"><?php echo $this->__('Is packed individually') ?></label></td>
119
+ <td class="value">
120
+ <span>
121
+ <?= !$tiramizooProduct->isPackedIndividually() ? $this->__('No') : $this->__('Yes') ?><br>
122
+ </span>
123
+ </td>
124
+ <td class="scope-label"><span class="nobr"></span></td>
125
+ </tr>
126
+
127
+ </tbody>
128
+ </table>
129
+ </div>
130
+ </div>
131
+ </div>
app/design/adminhtml/default/default/template/tiramizoo/order/view/tab/tiramizoo.phtml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ $tiramizoo = $this->getTiramizooOrder();
17
+
18
+ ?>
19
+ <div class="entry-edit">
20
+ <div class="entry-edit-head">
21
+ <h4><?php echo __('Details') ?></h4>
22
+ </div>
23
+ <div class="fieldset fieldset-wide">
24
+ <div class="hor-scroll">
25
+ <table cellspacing="0" class="form-list">
26
+ <tbody>
27
+ <tr>
28
+ <td class="label"><?php echo __('Tracking URL') ?></td>
29
+ <td class="value"><input type="text" class="input-text" value="<?php echo $tiramizoo->getTrackingUrl() ?>"/></td>
30
+ </tr>
31
+ <tr>
32
+ <td class="label"><?php echo __('Status') ?></td>
33
+ <td class="value"><input type="text" class="input-text" value="<?php echo $tiramizoo->getStatus() ?>"/></td>
34
+ </tr>
35
+ <tr>
36
+ <td class="label"><?php echo __('External ID') ?></td>
37
+ <td class="value"><input type="text" class="input-text" value="<?php echo $tiramizoo->getExternalId() ?>"/></td>
38
+ </tr>
39
+ <tr>
40
+ <td class="label"><?php echo __('API Request') ?></td>
41
+ <td class="value"><textarea><?php echo print_r(json_decode($tiramizoo->getApiRequest())) ?></textarea></td>
42
+ </tr>
43
+ <tr>
44
+ <td class="label"><?php echo __('API Response') ?></td>
45
+ <td class="value"><textarea><?php echo print_r(json_decode($tiramizoo->getApiResponse())) ?></textarea></td>
46
+ </tr>
47
+ </tbody>
48
+ </table>
49
+ </div>
50
+ </div>
51
+ </div>
app/design/frontend/base/default/layout/tiramizoo/checkout.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_additional translate="label">
4
+ <block type="checkout/onepage_shipping_method_additional" name="tiramizoo_action" output="toHtml" template="tiramizoo/shipping/method/action.phtml"/>
5
+ </checkout_onepage_additional>
6
+ </layout>
app/design/frontend/base/default/layout/tiramizoo/sales.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <layout version="1.0.0">
4
+ <sales_email_order_tiramizoo_tracking_url>
5
+ <block type="tiramizoo/order_email_tracking" name="tracking_url" template="tiramizoo/order/email/tracking.phtml" />
6
+ </sales_email_order_tiramizoo_tracking_url>
7
+ </layout>
app/design/frontend/base/default/template/tiramizoo/order/email/tracking.phtml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_order = $this->getOrder();
3
+ $trackingUrl = $this->getTrackingUrl($_order);
4
+
5
+ if ($trackingUrl):
6
+ ?>
7
+ <table cellspacing="0" cellpadding="0" border="0" width="650">
8
+ <thead>
9
+ <tr>
10
+ <th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">
11
+ <?php echo __('Tracking information'); ?>:
12
+ </th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <tr>
17
+ <td valign="top" style="font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
18
+ <a href="<?php echo $trackingUrl; ?>"><?php echo $trackingUrl; ?></a>
19
+ </td>
20
+ </tr>
21
+ </tbody>
22
+ </table>
23
+ <?php
24
+ endif;
app/design/frontend/base/default/template/tiramizoo/shipping/method/action.phtml ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $rates = Mage::helper('tiramizoo_shipping/data')->getAvailableShippingRates();
3
+
4
+ foreach($rates as $shippingMethod => $rate) {
5
+ $timeWindow = Mage::getSingleton('checkout/session')->getData('tiramizoo_'.$rate.'_time_window');
6
+ if ($timeWindow) {
7
+ echo '<input type="hidden" id="'.$shippingMethod.'" name="tiramizoo_'.$rate.'_hash" value="'.$timeWindow->getHash().'" class="validate-tiramizoo-hash">';
8
+ }
9
+ }
10
+ ?>
11
+
12
+ <script type="text/javascript">
13
+
14
+ if (window.tiramizoo_error === undefined) {
15
+ var tiramizoo_error = false;
16
+ }
17
+
18
+ if (window.tiramizoo_error) {
19
+ alert('Tiramizoo time window is not valid! Back to the previous step and try again.');
20
+ window.tiramizoo_error = false;
21
+ }
22
+
23
+ if (Validation) {
24
+ Validation.add('validate-tiramizoo-hash', null, function(hash, elem) {
25
+ var result = false;
26
+ var shipping_method = $('s_method_'+elem.id);
27
+
28
+ if (shipping_method.checked) {
29
+ shipping_method = shipping_method.value;
30
+
31
+ var availableShippingRates = <?= json_encode(array_keys($rates)) ?>;
32
+
33
+ if (availableShippingRates.indexOf(shipping_method) != -1) {
34
+ var url = "<?php echo Mage::getUrl('tiramizoo/index/checkTimeWindow') ?>";
35
+ new Ajax.Request(url, {
36
+ method: 'get',
37
+ asynchronous: false,
38
+ parameters: {
39
+ shippingMethod: shipping_method,
40
+ hash: hash
41
+ },
42
+ requestHeaders: {Accept: 'application/json'},
43
+ onSuccess: function(transport) {
44
+ if (!transport.responseJSON.valid) {
45
+ result = false;
46
+ window.tiramizoo_error = true;
47
+ shipping.save();
48
+ } else {
49
+ result = true;
50
+ }
51
+ },
52
+ onError: function() {
53
+ result = false;
54
+ window.tiramizoo_error = true;
55
+ shipping.save();
56
+ }
57
+ });
58
+ } else {
59
+ result = true;
60
+ }
61
+ } else {
62
+ result = true;
63
+ }
64
+ return result;
65
+ });
66
+ } else {
67
+ console.log('Validation is not defined');
68
+ }
69
+ </script>
app/etc/modules/Tiramizoo_Shipping.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Tiramizoo_Shipping>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Tiramizoo_Shipping>
8
+ </modules>
9
+ </config>
app/locale/de_DE/Tiramizoo_Shipping.csv ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Tiramizoo Options","Tiramizoo Optionen"
2
+ "Click here to view Tiramizoo configuration","Klicken Sie hier, um Tiramizoo Konfiguration anzeigen"
3
+ "Tiramizoo","Tiramizoo"
4
+ "Packed individually","Eigene Verpackung"
5
+ "Dimensions","Abmessungen"
6
+ "Is available","Ist verfügbar"
7
+ "Product is available to Tiramizoo delivery.","Produkt ist verfügbar für Tiramizoo."
8
+ "Product is not available to Tiramizoo delivery.","Product nicht verfügbar für Tiramizoo."
9
+ "Is packed individually","Wird einzeln verpackt"
10
+ "Inherit","Erben"
11
+ "Retail location configs were synchronised successfully","Filialadressenkonfiguration wurde synchronisiert"
12
+ "All products have individual dimensions","Alle Produkte haben eigene Abmessungen"
13
+ "Specific dimensions of packages (specified from tiramizoo dashboard)","Paketgrößen angeben"
14
+ "All products should fit to one package","Standardpaketgröße für alle Artikel"
15
+ "-- select one --","-- wählen sie eine --"
16
+ "Tiramizoo time window is expired.","Sie die gewünschte Lieferzeit ist abgelaufen."
17
+ "Tiramizoo can not be set to active, minimal configuration is required!","Tiramizoo kann nicht aktiv gesetzt werden kann, wird der Minimalkonfiguration erforderlich!"
18
+ "Tiramizoo Shipping Method configuration is incomplete!","Tiramizoo Lieferungmethode Konfiguration ist unvollständig!"
19
+ "Immediate Price","Sofortlieferung Preis"
20
+ "Evening Price","Abendzustellung Preis"
21
+ "Is Active","Ist Aktiv"
22
+ "API url","API url"
23
+ "Shop url","Shop url"
24
+ "Packing strategy","Verpackungsstrategie"
25
+ "Payment methods", "Zahlungsmethoden"
26
+ "Payment methods available for Tiramizoo, Cash on delivery is not supported yet", "Bezahlmethoden, die für den tiramizoo-Service verfügbar sind. Bezahlung per Nachnahme ist z.Zt. über tiramizoo nicht möglich"
27
+ "Default product dimensions and weight","Grundeinstellungen Maße und Gewichte"
28
+ "Standard Package size and weight","Standard-Paketgröße und -gewicht"
29
+ "Product width mapping","Produkt breite zuordnung"
30
+ "Product height mapping","Produkt höhe zuordnung"
31
+ "Product length mapping","Produkt länge zuordnung",
32
+ "Synchronize all retail locations","Synchronisieren der Konfigurationen der Filialadressen"
33
+ "Synchronize","Synchronisieren"
34
+ "API Location 1","API Filialadressen 1"
35
+ "API Location 2","API Filialadressen 2"
36
+ "API Location 3","API Filialadressen 3"
37
+ "API Location 4","API Filialadressen 4"
38
+ "API Location 5","API Filialadressen 5"
39
+ "API Location 6","API Filialadressen 6"
40
+ "API Location 7","API Filialadressen 7"
41
+ "API Location 8","API Filialadressen 8"
42
+ "API Location 9","API Filialadressen 9"
43
+ "API Location 10","API Filialadressen 10"
44
+ "Debug log","Debug-Protokoll"
45
+ "Is enable","Ist enable"
46
+ "API key","API key"
47
+ "Status","Status"
48
+ "Width", "Breite"
49
+ "Height", "Höhe"
50
+ "Length", "Länge"
51
+ "Settings", "Einstellungen"
52
+ "From", "Von der"
53
+ "product", "produkt"
54
+ "category", "kategorie"
55
+ "configuration", "konfiguration"
56
+ "Enable", "Ermöglichen"
57
+ "Disable", "Deaktivieren"
58
+ "Yes", "Ja"
59
+ "No", "Nein"
60
+ "Product width in cm", "Produkt Breite in cm"
61
+ "Product height in cm", "Produkt Höhe in cm"
62
+ "Product length in cm", "Produkt Länge in cm"
63
+
app/locale/en_US/Tiramizoo_Shipping.csv ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Tiramizoo Options","Tiramizoo Options"
2
+ "Click here to view Tiramizoo configuration","Click here to view Tiramizoo configuration"
3
+ "Tiramizoo","Tiramizoo"
4
+ "Packed individually","Packed individually"
5
+ "Dimensions","Dimensions"
6
+ "Is available","Is available"
7
+ "Product is available to Tiramizoo delivery.","Product is available to Tiramizoo delivery."
8
+ "Product is not available to Tiramizoo delivery.","Product is not available to Tiramizoo delivery."
9
+ "Is packed individually","Is packed individually"
10
+ "Inherit","Inherit"
11
+ "Retail location configs were synchronised successfully","Retail location configs were synchronised successfully"
12
+ "All products have individual dimensions","All products have individual dimensions"
13
+ "Specific dimensions of packages (specified from tiramizoo dashboard)","Specific dimensions of packages (specified from tiramizoo dashboard)"
14
+ "All products should fit to one package","All products should fit to one package"
15
+ "-- select one --","-- select one --"
16
+ "Tiramizoo time window is expired.","Tiramizoo time window is expired."
17
+ "Tiramizoo can not be set to active, minimal configuration is required!","Tiramizoo can not be set to active, minimal configuration is required!"
18
+ "Tiramizoo Shipping Method configuration is incomplete!","Tiramizoo Shipping Method configuration is incomplete!"
19
+ "Immediate Price","Immediate Price"
20
+ "Evening Price","Evening Price"
21
+ "Is Active","Is Active"
22
+ "API url","API url"
23
+ "Shop url","Shop url"
24
+ "Packing strategy","Packing strategy"
25
+ "Payment methods", "Payment methods"
26
+ "Payment methods available for Tiramizoo, Cash on delivery is not supported yet", "Payment methods available for Tiramizoo, Cash on delivery is not supported yet"
27
+ "Default product dimensions and weight","Default product dimensions and weight"
28
+ "Standard Package size and weight","Standard Package size and weight"
29
+ "Product width mapping","Product width mapping"
30
+ "Product height mapping","Product height mapping"
31
+ "Product length mapping","Product length mapping",
32
+ "Synchronize all retail locations","Synchronize all retail locations"
33
+ "Synchronize","Synchronize"
34
+ "API Location 1","API Location 1"
35
+ "API Location 2","API Location 2"
36
+ "API Location 3","API Location 3"
37
+ "API Location 4","API Location 4"
38
+ "API Location 5","API Location 5"
39
+ "API Location 6","API Location 6"
40
+ "API Location 7","API Location 7"
41
+ "API Location 8","API Location 8"
42
+ "API Location 9","API Location 9"
43
+ "API Location 10","API Location 10"
44
+ "Debug log","Debug log"
45
+ "Is enable","Is enable"
46
+ "API key","API key"
47
+ "Width", "Width"
48
+ "Height", "Height"
49
+ "Length", "Length"
50
+ "Settings", "Settings"
51
+ "From", "From"
52
+ "product", "product"
53
+ "category", "category"
54
+ "configuration", "configuration"
55
+ "Enable", "Enable"
56
+ "Disable", "Disable"
57
+ "Yes", "Yes"
58
+ "No", "No"
59
+ "Product width in cm", "Product width in cm"
60
+ "Product height in cm", "Product height in cm"
61
+ "Product length in cm", "Product length in cm"
62
+
app/locale/en_US/template/email/sales/order_new.html.dist ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--@subject {{var store.getFrontendName()}}: New Order # {{var order.increment_id}} @-->
2
+ <!--@vars
3
+ {"store url=\"\"":"Store Url",
4
+ "var logo_url":"Email Logo Image Url",
5
+ "var logo_alt":"Email Logo Image Alt",
6
+ "htmlescape var=$order.getCustomerName()":"Customer Name",
7
+ "var store.getFrontendName()":"Store Name",
8
+ "store url=\"customer/account/\"":"Customer Account Url",
9
+ "var order.increment_id":"Order Id",
10
+ "var order.getCreatedAtFormated('long')":"Order Created At (datetime)",
11
+ "var order.getBillingAddress().format('html')":"Billing Address",
12
+ "var payment_html":"Payment Details",
13
+ "var order.getShippingAddress().format('html')":"Shipping Address",
14
+ "var order.getShippingDescription()":"Shipping Description",
15
+ "layout handle=\"sales_email_order_items\" order=$order":"Order Items Grid",
16
+ "var order.getEmailCustomerNote()":"Email Order Note"}
17
+ @-->
18
+ <!--@styles
19
+ body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
20
+ @-->
21
+
22
+ <body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
23
+ <div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
24
+ <table cellspacing="0" cellpadding="0" border="0" width="100%">
25
+ <tr>
26
+ <td align="center" valign="top" style="padding:20px 0 20px 0">
27
+ <table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
28
+ <!-- [ header starts here] -->
29
+ <tr>
30
+ <td valign="top"><a href="{{store url=""}}"><img src="{{var logo_url}}" alt="{{var logo_alt}}" style="margin-bottom:10px;" border="0"/></a></td>
31
+ </tr>
32
+ <!-- [ middle starts here] -->
33
+ <tr>
34
+ <td valign="top">
35
+ <h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"">Hello, {{htmlescape var=$order.getCustomerName()}}</h1>
36
+ <p style="font-size:12px; line-height:16px; margin:0;">
37
+ Thank you for your order from {{var store.getFrontendName()}}.
38
+ Once your package ships we will send an email with a link to track your order.
39
+ You can check the status of your order by <a href="{{store url="customer/account/"}}" style="color:#1E7EC8;">logging into your account</a>.
40
+ If you have any questions about your order please contact us at <a href="mailto:{{config path='trans_email/ident_support/email'}}" style="color:#1E7EC8;">{{config path='trans_email/ident_support/email'}}</a> or call us at <span class="nobr">{{config path='general/store_information/phone'}}</span> Monday - Friday, 8am - 5pm PST.
41
+ </p>
42
+ <p style="font-size:12px; line-height:16px; margin:0;">Your order confirmation is below. Thank you again for your business.</p>
43
+ </tr>
44
+ <tr>
45
+ <td>
46
+ <h2 style="font-size:18px; font-weight:normal; margin:0;">Your Order #{{var order.increment_id}} <small>(placed on {{var order.getCreatedAtFormated('long')}})</small></h2>
47
+ </td>
48
+ </tr>
49
+ <tr>
50
+ <td>
51
+ <table cellspacing="0" cellpadding="0" border="0" width="650">
52
+ <thead>
53
+ <tr>
54
+ <th align="left" width="325" bgcolor="#EAEAEA" style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">Billing Information:</th>
55
+ <th width="10"></th>
56
+ <th align="left" width="325" bgcolor="#EAEAEA" style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">Payment Method:</th>
57
+ </tr>
58
+ </thead>
59
+ <tbody>
60
+ <tr>
61
+ <td valign="top" style="font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
62
+ {{var order.getBillingAddress().format('html')}}
63
+ </td>
64
+ <td>&nbsp;</td>
65
+ <td valign="top" style="font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
66
+ {{var payment_html}}
67
+ </td>
68
+ </tr>
69
+ </tbody>
70
+ </table>
71
+ <br/>
72
+ {{depend order.getIsNotVirtual()}}
73
+ <table cellspacing="0" cellpadding="0" border="0" width="650">
74
+ <thead>
75
+ <tr>
76
+ <th align="left" width="325" bgcolor="#EAEAEA" style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">Shipping Information:</th>
77
+ <th width="10"></th>
78
+ <th align="left" width="325" bgcolor="#EAEAEA" style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">Shipping Method:</th>
79
+ </tr>
80
+ </thead>
81
+ <tbody>
82
+ <tr>
83
+ <td valign="top" style="font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
84
+ {{var order.getShippingAddress().format('html')}}
85
+ &nbsp;
86
+ </td>
87
+ <td>&nbsp;</td>
88
+ <td valign="top" style="font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
89
+ {{var order.getShippingDescription()}}
90
+ &nbsp;
91
+ </td>
92
+ </tr>
93
+ </tbody>
94
+ </table>
95
+ <br/>
96
+ {{/depend}}
97
+ {{layout handle="sales_email_order_items" order=$order}}
98
+ <p style="font-size:12px; margin:0 0 10px 0">{{var order.getEmailCustomerNote()}}</p>
99
+ </td>
100
+ </tr>
101
+ <tr><td>{{layout area="frontend" handle="sales_email_order_tiramizoo_tracking_url" order=$order}}</td></tr>
102
+ <tr>
103
+ <td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;"><center><p style="font-size:12px; margin:0;">Thank you, <strong>{{var store.getFrontendName()}}</strong></p></center></td>
104
+ </tr>
105
+ </table>
106
+ </td>
107
+ </tr>
108
+ </table>
109
+ </div>
110
+ </body>
app/locale/en_US/template/email/sales/order_new_guest.html.dist ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--@subject {{var store.getFrontendName()}}: New Order # {{var order.increment_id}} @-->
2
+ <!--@vars
3
+ {"store url=\"\"":"Store Url",
4
+ "var logo_url":"Email Logo Image Url",
5
+ "var logo_alt":"Email Logo Image Alt",
6
+ "htmlescape var=$order.getBillingAddress().getName()":"Guest Customer Name",
7
+ "var store.getFrontendName()":"Store Name",
8
+ "var order.increment_id":"Order Id",
9
+ "var order.getCreatedAtFormated('long')":"Order Created At (datetime)",
10
+ "var order.getBillingAddress().format('html')":"Billing Address",
11
+ "var payment_html":"Payment Details",
12
+ "var order.getShippingAddress().format('html')":"Shipping Address",
13
+ "var order.getShippingDescription()":"Shipping Description",
14
+ "layout handle=\"sales_email_order_items\" order=$order":"Order Items Grid",
15
+ "var order.getEmailCustomerNote()":"Email Order Note"}
16
+ @-->
17
+ <!--@styles
18
+ body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
19
+ @-->
20
+
21
+ <body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
22
+ <div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
23
+ <table cellspacing="0" cellpadding="0" border="0" width="100%">
24
+ <tr>
25
+ <td align="center" valign="top" style="padding:20px 0 20px 0">
26
+ <!-- [ header starts here] -->
27
+ <table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
28
+ <tr>
29
+ <td valign="top"><a href="{{store url=""}}"><img src="{{var logo_url}}" alt="{{var logo_alt}}" style="margin-bottom:10px;" border="0"/></a></td>
30
+ </tr>
31
+ <!-- [ middle starts here] -->
32
+ <tr>
33
+ <td valign="top">
34
+ <h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;">Hello, {{htmlescape var=$order.getBillingAddress().getName()}}</h1>
35
+ <p style="font-size:12px; line-height:16px; margin:0 0 10px 0;">
36
+ Thank you for your order from {{var store.getFrontendName()}}.
37
+ Once your package ships we will send an email with a link to track your order.
38
+ If you have any questions about your order please contact us at <a href="mailto:{{config path='trans_email/ident_support/email'}}" style="color:#1E7EC8;">{{config path='trans_email/ident_support/email'}}</a> or call us at <span class="nobr">{{config path='general/store_information/phone'}}</span> Monday - Friday, 8am - 5pm PST.
39
+ </p>
40
+ <p style="font-size:12px; line-height:16px; margin:0;">Your order confirmation is below. Thank you again for your business.</p>
41
+ </td>
42
+ </tr>
43
+ <tr>
44
+ <td>
45
+ <h2 style="font-size:18px; font-weight:normal; margin:0;">Your Order #{{var order.increment_id}} <small>(placed on {{var order.getCreatedAtFormated('long')}})</small></h2>
46
+ </td>
47
+ </tr>
48
+ <tr>
49
+ <td>
50
+ <table cellspacing="0" cellpadding="0" border="0" width="650">
51
+ <thead>
52
+ <tr>
53
+ <th align="left" width="325" bgcolor="#EAEAEA" style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">Billing Information:</th>
54
+ <th width="10"></th>
55
+ <th align="left" width="325" bgcolor="#EAEAEA" style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">Payment Method:</th>
56
+ </tr>
57
+ </thead>
58
+ <tbody>
59
+ <tr>
60
+ <td valign="top" style="font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
61
+ {{var order.getBillingAddress().format('html')}}
62
+ </td>
63
+ <td>&nbsp;</td>
64
+ <td valign="top" style="font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
65
+ {{var payment_html}}
66
+ </td>
67
+ </tr>
68
+ </tbody>
69
+ </table>
70
+ <br/>
71
+ {{depend order.getIsNotVirtual()}}
72
+ <table cellspacing="0" cellpadding="0" border="0" width="100%">
73
+ <thead>
74
+ <tr>
75
+ <th align="left" width="325" bgcolor="#EAEAEA" style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">Shipping Information:</th>
76
+ <th width="10"></th>
77
+ <th align="left" width="325" bgcolor="#EAEAEA" style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">Shipping Method:</th>
78
+ </tr>
79
+ </thead>
80
+ <tbody>
81
+ <tr>
82
+ <td valign="top" style="font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
83
+ {{var order.getShippingAddress().format('html')}}
84
+ &nbsp;
85
+ </td>
86
+ <td>&nbsp;</td>
87
+ <td valign="top" style="font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
88
+ {{var order.getShippingDescription()}}
89
+ &nbsp;
90
+ </td>
91
+ </tr>
92
+ </tbody>
93
+ </table>
94
+ <br/>
95
+ {{/depend}}
96
+ {{layout handle="sales_email_order_items" order=$order}}
97
+ <p style="font-size:12px; margin:0 10px 10px 0">{{var order.getEmailCustomerNote()}}</p>
98
+ </td>
99
+ </tr>
100
+ <tr><td>{{layout area="frontend" handle="sales_email_order_tiramizoo_tracking_url" order=$order}}</td></tr>
101
+ <tr>
102
+ <td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;"><center><p style="font-size:12px; margin:0;">Thank you again, <strong>{{var store.getFrontendName()}}</strong></p></center></td>
103
+ </tr>
104
+ </table>
105
+ </td>
106
+ </tr>
107
+ </table>
108
+ </div>
109
+ </body>
lib/Tiramizoo/TiramizooApi.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of the Tiramizoo_Shipping magento plugin.
4
+ *
5
+ * LICENSE: This source file is subject to the MIT license that is available
6
+ * through the world-wide-web at the following URI:
7
+ * http://opensource.org/licenses/mit-license.php
8
+ *
9
+ * @category module
10
+ * @package Tiramizoo_Shipping
11
+ * @author Tiramizoo GmbH <support@tiramizoo.com>
12
+ * @copyright Tiramizoo GmbH
13
+ * @license http://opensource.org/licenses/mit-license.php MIT License
14
+ */
15
+
16
+ /**
17
+ * Tiramizoo API wrapper class used for sending requests to the API via cURL.
18
+ *
19
+ * @package oxTiramizoo
20
+ */
21
+ class TiramizooApi
22
+ {
23
+ /**
24
+ * API url
25
+ *
26
+ * @var string
27
+ */
28
+ protected $api_url = null;
29
+
30
+ /**
31
+ * API token
32
+ *
33
+ * @var string
34
+ */
35
+ protected $api_token = null;
36
+
37
+ /**
38
+ * Connection Time Out
39
+ *
40
+ * @var integer
41
+ */
42
+ protected static $_iConnectionTimeOut = 300;
43
+
44
+ /**
45
+ * Time Out
46
+ *
47
+ * @var integer
48
+ */
49
+ protected static $_iTimeOut = 60;
50
+
51
+ /**
52
+ * Time out curl error
53
+ *
54
+ */
55
+ const CURLE_OPERATION_TIMEDOUT = 28;
56
+
57
+ /**
58
+ * Construct the object with api key and url
59
+ *
60
+ * @param string $api_url API url
61
+ * @param string $api_token API token to authenticate
62
+ *
63
+ * @return null
64
+ */
65
+ protected function __construct($api_url, $api_token)
66
+ {
67
+ $this->api_url = $api_url;
68
+ $this->api_token = $api_token;
69
+ }
70
+
71
+ /**
72
+ * Build http connection to the API via cURL
73
+ *
74
+ * @param string $path API path
75
+ * @param array $data Data to send
76
+ * @param boolean $result result
77
+ *
78
+ * @return boolean Return true if success otherwise false
79
+ */
80
+ public function request($path, $data = array(), &$result = false)
81
+ {
82
+ $c = curl_init();
83
+
84
+ //@todo: set 1 before launch
85
+ curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
86
+ curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
87
+
88
+ curl_setopt($c, CURLOPT_URL, $this->api_url.'/'.$path.'?api_token='. $this->api_token);
89
+ curl_setopt($c, CURLOPT_POST, true);
90
+ curl_setopt($c, CURLOPT_POSTFIELDS, preg_replace_callback(
91
+ '/(\\\u[0-9a-f]{4})/',
92
+ array($this, "json_unescape"),
93
+ json_encode($data)
94
+ ));
95
+
96
+
97
+ curl_setopt($c, CURLOPT_HTTPHEADER, array(
98
+ "Content-Type: application/json",
99
+ "Accept: application/json"
100
+ ));
101
+
102
+ curl_setopt($c, CURLOPT_TIMEOUT, self::$_iTimeOut);
103
+ curl_setopt($c, CURLOPT_CONNECTTIMEOUT, self::$_iConnectionTimeOut);
104
+
105
+ curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
106
+ $response = curl_exec($c);
107
+
108
+ $errno = curl_errno($c);
109
+ $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
110
+
111
+ $result = array('http_status' => $status, 'response' => json_decode($response), 'errno' => $errno);
112
+
113
+ curl_close($c);
114
+ }
115
+
116
+ /**
117
+ * Build http connection to the API via cURL
118
+ *
119
+ * @param string $path API path
120
+ * @param array $data Data to send
121
+ * @param boolean $result result
122
+ *
123
+ * @return boolean Return true if success otherwise false
124
+ */
125
+ public function requestGet($path, $data = array(), &$result = false)
126
+ {
127
+ $c = curl_init();
128
+
129
+ //@todo: set 1 before launch
130
+ curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
131
+ curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
132
+
133
+ curl_setopt(
134
+ $c,
135
+ CURLOPT_URL,
136
+ $this->api_url . '/' . $path . '?api_token=' . $this->api_token . '&' . http_build_query($data)
137
+ );
138
+
139
+ curl_setopt($c, CURLOPT_TIMEOUT, self::$_iTimeOut);
140
+ curl_setopt($c, CURLOPT_CONNECTTIMEOUT, self::$_iConnectionTimeOut);
141
+
142
+ curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
143
+
144
+ $response = curl_exec($c);
145
+
146
+ $errno = curl_errno($c);
147
+ $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
148
+
149
+ $result = array('http_status' => $status, 'response' => json_decode($response), 'errno' => $errno);
150
+
151
+ curl_close($c);
152
+ }
153
+
154
+ /**
155
+ * Unescape json items
156
+ *
157
+ * @param string $m Element's value
158
+ *
159
+ * @return string unescaped value
160
+ */
161
+ protected function json_unescape($m)
162
+ {
163
+ return json_decode('"'.$m[1].'"');
164
+ }
165
+
166
+ /**
167
+ * Modify connection Timeout for unit tests
168
+ *
169
+ * @param integer $iTimeOut The maximum number of seconds to allow cURL functions to execute.
170
+ * @param integer $iConnectionTimeOut The number of seconds to wait while trying to connect
171
+ *
172
+ * @return null
173
+ **/
174
+ public static function setConnectionTimeout($iTimeOut, $iConnectionTimeOut)
175
+ {
176
+ // @codeCoverageIgnoreStart
177
+ // if ( !defined( 'OXID_PHP_UNIT' ) ) {
178
+ // return;
179
+ // }
180
+ // @codeCoverageIgnoreEnd
181
+
182
+ self::$_iTimeOut = $iTimeOut;
183
+ self::$_iConnectionTimeOut = $iConnectionTimeOut;
184
+ }
185
+ }
package.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Tiramizoo_Shipping</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>Massachusetts Institute of Technology License (MITL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Magento Tiramizoo plugin for integration with Tiramizoo API. </summary>
10
+ <description>Mit dem tiramizoo Modul liefern Sie Waren innerhalb von Minuten oder Stunden nach Eingang der Bestellung und dies bereits in 18 St&#xE4;dten deutschlandweit. Voraussetzung ist ein Account bei tiramizoo.com sowie die Verf&#xFC;gbarkeit der zu liefernden Ware in der selben Stadt wie die Lieferadresse. &#xD;
11
+ Mehr zum Thema Same-Day-Lieferung und tiramizoo finden Sie auf: https://www.tiramizoo.com&#xD;
12
+ &#xD;
13
+ English&#xD;
14
+ &#xD;
15
+ The tiramizoo Extension enables you to deliver within minutes or hours to your local customer in already 18 German cities. Simply set up an account on tiramzoo.com and ensure that the ordered goods are available in the same city as the delivery address.&#xD;
16
+ Please visit: https://www.tiramizoo.com and find out more about tiramizoo and SDD.</description>
17
+ <notes>Initial module release.</notes>
18
+ <authors><author><name>Tiramizoo GmbH</name><user>Tiramizoo</user><email>tech@tiramizoo.com</email></author></authors>
19
+ <date>2014-02-12</date>
20
+ <time>23:23:58</time>
21
+ <contents><target name="mageetc"><dir><dir name="modules"><file name="Tiramizoo_Shipping.xml" hash="cadfbe5af4cc7394562a1ff4682d07ed"/></dir></dir></target><target name="magecommunity"><dir><dir name="Tiramizoo"><dir name="Shipping"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><dir name="Tab"><file name="Action.php" hash="fb3e8e7a5a1b3315d7ece91074e55792"/></dir></dir></dir></dir><dir name="Sales"><dir name="Order"><dir name="View"><dir name="Tab"><file name="Tiramizoo.php" hash="3105ea90b4dee0d08f314113f7a59003"/></dir></dir></dir></dir></dir><file name="Button.php" hash="5722f5582b549673b73d2d853703b6fe"/><file name="Onepackagedimensions.php" hash="2036869aa171f7bb04aad556f5d9c1c6"/><dir name="Order"><dir name="Email"><file name="Tracking.php" hash="b25b185bbdb50692fd052c2fdf5b9c82"/></dir></dir><file name="Productdimensions.php" hash="85cace4916c3bf88622e549653facb26"/></dir><dir name="Helper"><file name="Build.php" hash="15664fb69556b51f07958b9419617286"/><file name="Data.php" hash="17570d161cdb6dcb610a7d734a376f07"/><file name="Package.php" hash="1608e5e96ce29fd57b32581332b06147"/></dir><dir name="Model"><file name="Api.php" hash="58f5c691db1ec094196af41d87e0bc4b"/><file name="Attributes.php" hash="7f455426f5c77cd19d34dd4a2361ee7e"/><dir name="Carrier"><file name="Tiramizoo.php" hash="5016f41b38fa3f8baed4cb17948f4a9b"/></dir><file name="Cart.php" hash="c550d89a07cc02ecc2c2d50b6c86d172"/><dir name="Category"><file name="Attributes.php" hash="378c5b5c225d7df7e3421c1266963ddb"/></dir><file name="Category.php" hash="cafd2bb73c29ddfdb43c2494c37b4a14"/><dir name="Config"><file name="Apiurl.php" hash="e6ab184665c052b116c9717726b242dd"/><file name="Packingstrategy.php" hash="a834930b8fec8c4f297cf956a8e52509"/></dir><file name="Date.php" hash="fbc669770849affec5d799055514f394"/><file name="Debug.php" hash="9b59062056c451d0a3e49f20cc22820b"/><file name="Default.php" hash="ebc833ca813746296209f8c28e55cf23"/><dir name="Delivery"><dir name="Type"><file name="Evening.php" hash="ddbc32f8a226ff619a79207cbe3b9195"/><file name="Immediate.php" hash="7bbb7a7f50ac5c0858c1162d91809a90"/></dir><file name="Type.php" hash="384e1385b51a9db4bd82d01be709c436"/></dir><dir name="Entity"><dir name="Attribute"><dir name="Source"><file name="Enable.php" hash="52487c9aa561182135c00efaac00f20e"/><file name="Packed.php" hash="4f37c50892afefd0d62aa20fb02952d0"/></dir></dir></dir><dir name="Mysql4"><dir name="Order"><file name="Collection.php" hash="53a6a2a33156f23ce6a4c4643f9e6625"/></dir><file name="Order.php" hash="1234a1222f47ff2b23b6eb3f7c59a881"/></dir><file name="Observer.php" hash="f56d80ca0ff7d4304136f29ba6d9f250"/><file name="Order.php" hash="fed5802a57efcb16c4a2f7406c74a278"/><file name="Payment.php" hash="9a3cfe022209a8311c3a26397d84d435"/><dir name="Product"><file name="Attributes.php" hash="08f9cf194b43dda28cd65e6b40e885c9"/></dir><file name="Product.php" hash="c635e7f4cbaf62180da434f726717368"/><file name="Resend.php" hash="54eece55707b41c53f2cd8dec1a2a344"/><file name="Response.php" hash="9bbaead77f9ba8f8372de8eb59e6c369"/><file name="Retaillocation.php" hash="6caa7ea85abfa676d81c84c5c653a3ef"/><file name="Retaillocations.php" hash="3fd21b89a3dee8e003c435b8ac685af9"/><file name="TestObserver.php" hash="e9f2651841843d0b847a8acb2058798f"/><dir name="Time"><file name="Window.php" hash="4d3198afb665a0fa9148c417f7b14e8e"/></dir><dir name="Type"><file name="Onepage.php" hash="e7a7c9b3541750707eaf98fc19f1ae60"/></dir></dir><dir name="Test"><dir name="Helper"><dir name="Build"><dir name="fixtures"><file name="default.yaml" hash="c7554e700bfabe023d6eff6f57765529"/></dir><dir name="providers"><file name="testBuildItems.yaml" hash="49b943a5993a5883ff7c60735ac44158"/></dir></dir><file name="Build.php" hash="6d54ef459d4d65cf59552ffb69cbb699"/></dir><dir name="Model"><dir name="Category"><dir name="fixtures"><file name="default.yaml" hash="6cc240988cb31d2a5a1a3e2b58950e26"/></dir><dir name="providers"><file name="testCart.yaml" hash="5670a7e800fa269a8fa01606b423a70b"/><file name="testGetDimensions.yaml" hash="0329905c9c1ae456f8b13ae4c74e838f"/></dir></dir><file name="Category.php" hash="134476f9cc3e1c60822e3421036e9aba"/><dir name="Product"><dir name="fixtures"><file name="default.yaml" hash="8de6bda1b1a06d9668396a015d568cdb"/></dir><dir name="providers"><file name="testCategoryGetNames.yaml" hash="b38fb3fd00a3c0e5a6b09864bc2db395"/><file name="testGetDimensions.yaml" hash="fce0d391d44f4e722d47162d99cd964f"/><file name="testProductIsAvailableToTiramizooDelivery.yaml" hash="21870c40b6d3fb9861ed32b629e42147"/><file name="testProductIsPackedIndividually.yaml" hash="0de3eeaf0445280a736d051fc8e03d41"/></dir></dir><file name="Product.php" hash="2d85023820b1cefbb18f0f1c85e29ce6"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="SynchronizeController.php" hash="7bd46b3329fcd5e5ffe75e62f4856593"/></dir><file name="IndexController.php" hash="eff7440b28a190a8c214a914c2bb56b7"/><file name="WebhookController.php" hash="ba94fc1c75fe3f6b8cc36a1f1a0dc18c"/></dir><dir name="etc"><file name="config.xml" hash="e53a93c70955c5f76d9ea2449ff00386"/><file name="system.xml" hash="b5ae218091627d8c9b38450d76aab4ec"/></dir><dir name="sql"><dir name="tiramizoo_setup"><file name="mysql4-install-0.1.0.php" hash="0098eb5881b7c2293a9373e868bf9e24"/></dir></dir></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="tiramizoo.xml" hash="f85c803d05471fa16d0343446e1fc5a4"/></dir><dir name="template"><dir name="tiramizoo"><dir name="catalog"><dir name="product"><dir name="tab"><file name="action.phtml" hash="4668ac9c6d9038c123d26f4895d5f709"/></dir></dir></dir><dir name="order"><dir name="view"><dir name="tab"><file name="tiramizoo.phtml" hash="edf5007d227f5493115d30550249bf74"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="tiramizoo"><file name="checkout.xml" hash="a1dac06e32fdad11b6aa44e62d94888b"/><file name="sales.xml" hash="25cc3981130cf5cd85ebca014cc142be"/></dir></dir><dir name="template"><dir name="tiramizoo"><dir name="order"><dir name="email"><file name="tracking.phtml" hash="81d3acddf1eaaa8e8554d23bd5a57d3c"/></dir></dir><dir name="shipping"><dir name="method"><file name="action.phtml" hash="a3c732807dc3930e673e585b1568aa4b"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="de_DE"><file name="Tiramizoo_Shipping.csv" hash="f43e6b38364ccc3f8385468115f5ead4"/></dir><dir name="en_US"><file name="Tiramizoo_Shipping.csv" hash="a2c76663d5de3bd9bc2dead1580dae5c"/><dir name="template"><dir name="email"><dir name="sales"><file name="order_new.html.dist" hash="96bdbeeed2e9176fd1c4e257f54dd97e"/><file name="order_new_guest.html.dist" hash="7697061acc9551a4f5c397568eae0d6d"/></dir></dir></dir></dir></dir></target><target name="magelib"><dir><dir name="Tiramizoo"><file name="TiramizooApi.php" hash="ef35cf9f80c9977623c6fc6dfeaa9a18"/></dir></dir></target></contents>
22
+ <compatible/>
23
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name/><channel>connect.magentocommerce.com/core</channel><min/><max/></package></required></dependencies>
24
+ </package>